Exemple #1
0
        /// <summary>
        /// Creates a new instance of <see cref="D3D10EffectPass"/>.
        /// </summary>
        /// <param name="renderer">The D3D10 renderer.</param>
        /// <param name="pass">The D3D10 pass.</param>
        /// <param name="map">The input layout map to share between passes that have the same effect origin.</param>
        internal D3D10EffectPass(D3D10Renderer renderer, D3D.EffectPass pass, InputLayoutMap map)
        {
            _pass     = pass;
            _renderer = renderer;

            D3D.EffectPassDescription desc = pass.Description;
            _name      = desc.Name;
            _layoutMap = map;

            //Fetch annotations
            int annoCount = desc.AnnotationCount;

            _annotations = new D3D10EffectAnnotationCollection();
            for (int i = 0; i < annoCount; i++)
            {
                D3D.EffectVariable            anno     = _pass.GetAnnotationByIndex(i);
                D3D.EffectVariableDescription annoDesc = anno.Description;
                D3D.EffectVariable            annoVar  = anno.AsString();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Object, EffectParameterType.String));
                }
                annoVar = anno.AsScalar();
                if (annoVar != null)
                {
                    //Need to find a way to get the param type...
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Scalar, EffectParameterType.Unknown));
                }
                annoVar = anno.AsMatrix();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Matrix, EffectParameterType.Single));
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// In a derived class, implements logic to flush all pending rendering commands.
        /// </summary>
        protected override void Flush()
        {
            Matrix offset = Matrix.Translation(-1.0f, 1.0f, 0.0f);
            Matrix scale  = Matrix.Scaling(1.0f / halfWidth, -1.0f / halfHeight, 1.0f);

            D3D.EffectVariable transform = effect.GetVariableBySemantic("MatrixWVP");
            transform.AsMatrix().SetMatrix(scale * offset);
            pass.Apply();

            lineBuffer.Commit();
            device.InputAssembler.SetInputLayout(inputLayout);
            device.InputAssembler.SetVertexBuffers(0, new D3D.VertexBufferBinding(lineBuffer.UnderlyingBuffer, lineBuffer.ElementSize, 0));
            device.InputAssembler.SetPrimitiveTopology(D3D.PrimitiveTopology.LineList);
            device.Draw(lineBuffer.Count, 0);
            lineBuffer.Clear();

            sprite.Begin(SlimDX.Direct3D10.SpriteFlags.SaveState);
            foreach (Text text in textBuffer)
            {
                font.Draw(sprite, text.String, new System.Drawing.Rectangle(text.X, text.Y, 100, 100), D3D.FontDrawFlags.SingleLine, text.Color);
            }
            sprite.End();

            textBuffer.Clear();
        }
Exemple #3
0
        /// <summary>
        /// Creates a new instance of <see cref="D3D10EffectAnnotation"/>.
        /// </summary>
        /// <param name="annotation">The D3D10 effect annotation.</param>
        /// <param name="name">The annotation's name.</param>
        /// <param name="semantic">The annotation's semantic.</param>
        /// <param name="paramClass">The annotation's parameter class.</param>
        /// <param name="paramType">The annotation's parameter type.</param>
        internal D3D10EffectAnnotation(D3D.EffectVariable annotation, String name, String semantic, EffectParameterClass paramClass, EffectParameterType paramType)
        {
            _name       = name;
            _annotation = annotation;
            _semantic   = semantic;
            _paramClass = paramClass;

            //Need to find a way to properly get these values!
            _paramType   = paramType;
            _columnCount = 0;
            _rowCount    = 0;
        }
Exemple #4
0
        /// <summary>
        /// Clones the collection using the new effect instance, used
        /// for when the implementation clones itself.
        /// </summary>
        /// <param name="effect">The D3D10 effect</param>
        /// <returns>Cloned collection</returns>
        internal D3D10EffectParameterCollection Clone(D3D.Effect effect)
        {
            D3D10EffectParameterCollection clone = new D3D10EffectParameterCollection();

            for (int i = 0; i < Count; i++)
            {
                D3D10EffectParameter paramToClone = _params[i];
                D3D.EffectVariable   eVar         = effect.GetVariableByName(paramToClone.Name);
                clone.Add(paramToClone.Clone(eVar));
            }
            return(clone);
        }
Exemple #5
0
        /// <summary>
        /// Creates a new instance of <see cref="D3D10EffectPass"/>.
        /// </summary>
        /// <param name="parent">The implementation parent.</param>
        /// <param name="effect">The D3D10 effect so we can query for variables.</param>
        /// <param name="pass">The D3D10 pass.</param>
        internal D3D10EffectPass(D3D10EffectImplementation parent, D3D.Effect effect, D3D.EffectPass pass)
        {
            _pass     = pass;
            _renderer = parent.Renderer;

            D3D.EffectPassDescription desc = pass.Description;
            _name      = desc.Name;
            _layoutMap = new InputLayoutMap(_renderer, desc.Signature);

            //Fetch annotations
            int annoCount = desc.AnnotationCount;

            _annotations = new D3D10EffectAnnotationCollection();
            for (int i = 0; i < annoCount; i++)
            {
                D3D.EffectVariable            anno     = _pass.GetAnnotationByIndex(i);
                D3D.EffectVariableDescription annoDesc = anno.Description;
                D3D.EffectVariable            annoVar  = anno.AsString();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Object, EffectParameterType.String));
                    continue;
                }
                annoVar = anno.AsScalar();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Scalar, EffectParameterType.Unknown));
                    continue;
                }
                annoVar = anno.AsMatrix();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Matrix, EffectParameterType.Unknown));
                    continue;
                }
                annoVar = anno.AsVector();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Vector, EffectParameterType.Unknown));
                }
            }

            //Now to reflect the parameters and start adding them to the shader
            D3D.EffectPassShaderDescription vertexShaderDesc = pass.VertexShaderDescription;
            D3D.EffectShaderVariable        vertexShaderVar  = vertexShaderDesc.Variable;
            ParseShader(parent, effect, vertexShaderVar);
            ParseShader(parent, effect, pass.PixelShaderDescription.Variable);

            //And the standard input layout
            CreateInputLayout(vertexShaderVar, vertexShaderDesc.Index);
        }
Exemple #6
0
        private static void ParseShaderParameters(D3D10EffectImplementation parent, D3D.Effect effect, D3DC.ShaderReflection reflect)
        {
            D3DC.ShaderDescription desc = reflect.Description;
            int constantBuffers         = desc.ConstantBuffers;
            int boundResources          = desc.BoundResources;

            //Grab parameters
            for (int i = 0; i < constantBuffers; i++)
            {
                D3DC.ConstantBuffer cb = reflect.GetConstantBuffer(i);
                for (int j = 0; j < cb.Description.Variables; j++)
                {
                    D3DC.ShaderReflectionVariable cbVar = cb.GetVariable(j);
                    String name = cbVar.Description.Name;
                    if (parent.Parameters[name] == null)
                    {
                        D3D.EffectVariable         param     = effect.GetVariableByName(name);
                        D3DC.ShaderReflectionType  paramType = cbVar.GetVariableType();
                        D3DC.ShaderTypeDescription typeDesc  = paramType.Description;
                        if (Want(typeDesc.Class, typeDesc.Type))
                        {
                            ((D3D10EffectParameterCollection)parent.Parameters).Add(new D3D10EffectParameter(param, paramType));
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            //Grab resources
            for (int i = 0; i < boundResources; i++)
            {
                D3DC.InputBindingDescription inputBinding = reflect.GetResourceBindingDescription(i);
                String name = inputBinding.Name;
                if (parent.Parameters[name] == null)
                {
                    D3D.EffectVariable param = effect.GetVariableByName(name);
                    if (Want(inputBinding.Type, inputBinding.Dimension))
                    {
                        ((D3D10EffectParameterCollection)parent.Parameters).Add(new D3D10EffectParameter(param, inputBinding));
                    }
                }
            }
        }
        /// <summary>
        /// Creates a new instance of <see cref="D3D10EffectTechnique"/>.
        /// </summary>
        /// <param name="parent">The implementation parent.</param>
        /// <param name="effect">The D3D10 effect.</param>
        /// <param name="tech">The D3D10 technique.</param>
        internal D3D10EffectTechnique(D3D10EffectImplementation parent, D3D.Effect effect, D3D.EffectTechnique tech)
        {
            _tech   = tech;
            _parent = parent;

            D3D.EffectTechniqueDescription desc = _tech.Description;
            _name = desc.Name;

            //Fetch annotations
            int annoCount = desc.AnnotationCount;

            _annotations = new D3D10EffectAnnotationCollection();
            for (int i = 0; i < annoCount; i++)
            {
                D3D.EffectVariable            anno     = _tech.GetAnnotationByIndex(i);
                D3D.EffectVariableDescription annoDesc = anno.Description;
                D3D.EffectVariable            annoVar  = anno.AsString();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Object, EffectParameterType.String));
                }
                annoVar = anno.AsScalar();
                if (annoVar != null)
                {
                    //Need to find a way to get the param type...
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Scalar, EffectParameterType.Unknown));
                }
                annoVar = anno.AsMatrix();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Matrix, EffectParameterType.Single));
                }
            }

            _passes = new D3D10EffectPassCollection();
            for (int i = 0; i < desc.PassCount; i++)
            {
                _passes.Add(new D3D10EffectPass(parent, effect, tech.GetPassByIndex(i)));
            }
        }
Exemple #8
0
        private static void ParseShader(D3D10EffectImplementation parent, D3D.Effect effect, D3D.EffectShaderVariable shaderVar)
        {
            D3D.EffectVariable testElem = shaderVar.GetElement(0);

            if (testElem == null)
            {
                if (shaderVar.IsValid)
                {
                    D3D.ShaderDescription shDesc;
                    shaderVar.GetShaderDescription(0, out shDesc);
                    D3DC.ShaderReflection reflect = new D3DC.ShaderReflection(shDesc.Bytecode);
                    ParseShaderParameters(parent, effect, reflect);

                    //Dispose of the reflection variable *and* the bytecode/signature of the shader desc...bytecode will reported as a leaked in ObjectTable
                    reflect.Dispose();
                    shDesc.Signature.Dispose();
                    shDesc.Bytecode.Dispose();
                }
            }
            else
            {
                int k = 1;
                while ((testElem = shaderVar.GetElement(k)) != null)
                {
                    if (testElem.IsValid)
                    {
                        D3D.ShaderDescription shDesc;
                        testElem.AsShader().GetShaderDescription(0, out shDesc);
                        D3DC.ShaderReflection reflect = new D3DC.ShaderReflection(shDesc.Bytecode);
                        ParseShaderParameters(parent, effect, reflect);

                        //Dispose of the reflection variable *and* the bytecode/signature of the shader desc...bytecode will reported as a leaked in ObjectTable
                        reflect.Dispose();
                        shDesc.Signature.Dispose();
                        shDesc.Bytecode.Dispose();
                    }
                    k++;
                }
            }
        }