internal Effect(GraphicsDevice device)
 {
     graphicsDevice   = device;
     Parameters       = new EffectParameterCollection();
     Techniques       = new EffectTechniqueCollection();
     CurrentTechnique = new EffectTechnique(this);
 }
Exemple #2
0
 internal EffectTechniqueCollection(Effect effect, EffectTechniqueCollection cloneSource)
 {
     foreach (EffectTechnique cloneSource1 in cloneSource)
     {
         this.Add(new EffectTechnique(effect, cloneSource1));
     }
 }
Exemple #3
0
 internal EffectTechniqueCollection(Effect effect, EffectTechniqueCollection cloneSource)
 {
     foreach (var technique in cloneSource)
     {
         Add(new EffectTechnique(effect, technique));
     }
 }
Exemple #4
0
        /// <summary>
        /// Clone the source into this existing object.
        /// </summary>
        /// <remarks>
        /// Note this is not overloaded in derived classes on purpose.  This is
        /// only a reason this exists is for caching effects.
        /// </remarks>
        /// <param name="cloneSource">The source effect to clone from.</param>
        private void Clone(Effect cloneSource)
        {
            Debug.Assert(_isClone, "Cannot clone into non-cloned effect!");

            // Copy the mutable members of the effect.
            Parameters = new EffectParameterCollection(cloneSource.Parameters);
            Techniques = new EffectTechniqueCollection(this, cloneSource.Techniques);

            // Make a copy of the immutable constant buffers.
            ConstantBuffers = new ConstantBuffer[cloneSource.ConstantBuffers.Length];
            for (var i = 0; i < cloneSource.ConstantBuffers.Length; i++)
            {
                ConstantBuffers[i] = new ConstantBuffer(cloneSource.ConstantBuffers[i]);
            }

            // Find and set the current technique.
            for (var i = 0; i < cloneSource.Techniques.Count; i++)
            {
                if (cloneSource.Techniques[i] == cloneSource.CurrentTechnique)
                {
                    CurrentTechnique = Techniques[i];
                    break;
                }
            }

            // Take a reference to the original shader list.
            _shaderList = cloneSource._shaderList;
        }
Exemple #5
0
        //
        // SetTechnique
        //

        void SetTechnique(string text)
        {
            string name;
            string search = "#technique ";
            int    idx    = text.IndexOf(search);

            if (idx != -1)
            {
                name = text.Substring(idx + search.Length).Trim();
            }
            else
            {
                name = "Default";
            }

            var passes = new List <EffectPass>();

            passes.Add(new EffectPass(name, null, this, IntPtr.Zero, 0));
            var list = new List <EffectTechnique>();

            technique = new EffectTechnique(name, IntPtr.Zero,
                                            new EffectPassCollection(passes), null);
            list.Add(technique);
            Techniques = new EffectTechniqueCollection(list);
        }
 /// <summary>
 /// Creates a new instance of <see cref="XNAEffectTechniqueCollection"/>.
 /// </summary>
 /// <param name="coll">The underlying XNA effect technique collection.</param>
 internal XNAEffectTechniqueCollection(XFG.EffectTechniqueCollection coll)
 {
     _techniques = new List <XNAEffectTechnique>(coll.Count);
     for (int i = 0; i < coll.Count; i++)
     {
         _techniques.Add(new XNAEffectTechnique(coll[i]));
     }
 }
Exemple #7
0
 protected Effect(Effect cloneSource) : this(cloneSource.GraphicsDevice)
 {
     this.CurrentTechnique = cloneSource.CurrentTechnique;
     this.Name             = cloneSource.Name;
     this.Parameters       = cloneSource.Parameters;
     this.Tag        = cloneSource.Tag;
     this.Techniques = cloneSource.Techniques;
 }
Exemple #8
0
 protected Effect(GraphicsDevice graphicsDevice)
 {
     if (graphicsDevice == null)
     {
         throw new ArgumentNullException("Graphics Device Cannot Be Null");
     }
     this.graphicsDevice = graphicsDevice;
     Techniques          = new EffectTechniqueCollection();
 }
        protected Effect(GraphicsDevice graphicsDevice, Effect cloneSource)
        {
            Parameters = new EffectParameterCollection();
            Techniques = new EffectTechniqueCollection();

            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("Graphics Device Cannot Be Null");
            }
            this.graphicsDevice = graphicsDevice;
        }
Exemple #10
0
        internal Effect(GraphicsDevice aGraphicsDevice)
        {
            if (aGraphicsDevice == null)
            {
                throw new ArgumentNullException("Graphics Device Cannot Be Null");
            }
            this.graphicsDevice = aGraphicsDevice;

            Parameters       = new EffectParameterCollection();
            Techniques       = new EffectTechniqueCollection();
            CurrentTechnique = new EffectTechnique(this);
        }
Exemple #11
0
        internal void ReadEffect(BinaryReader reader)
        {
            var effectPass = new EffectPass(this, "Pass", null, null, null, DepthStencilState.Default, RasterizerState.CullNone, EffectAnnotationCollection.Empty);

            effectPass._shaderProgram = new ShaderProgram(reader.ReadBytes((int)reader.BaseStream.Length));
            var shaderProgram = effectPass._shaderProgram;

            EffectParameter[] parametersArray = new EffectParameter[shaderProgram.UniformCount + 4];
            for (int i = 0; i < shaderProgram.UniformCount; i++)
            {
                parametersArray[i] = EffectParameterForUniform(shaderProgram, i);
            }

                        #warning Hacks for BasicEffect as we don't have these parameters yet
            parametersArray[shaderProgram.UniformCount] = new EffectParameter(
                EffectParameterClass.Vector, EffectParameterType.Single, "SpecularColor",
                3, 1, "float3", EffectAnnotationCollection.Empty, EffectParameterCollection.Empty, EffectParameterCollection.Empty, new float[3]);
            parametersArray[shaderProgram.UniformCount + 1] = new EffectParameter(
                EffectParameterClass.Scalar, EffectParameterType.Single, "SpecularPower",
                1, 1, "float", EffectAnnotationCollection.Empty, EffectParameterCollection.Empty, EffectParameterCollection.Empty, 0.0f);
            parametersArray[shaderProgram.UniformCount + 2] = new EffectParameter(
                EffectParameterClass.Vector, EffectParameterType.Single, "FogVector",
                4, 1, "float4", EffectAnnotationCollection.Empty, EffectParameterCollection.Empty, EffectParameterCollection.Empty, new float[4]);
            parametersArray[shaderProgram.UniformCount + 3] = new EffectParameter(
                EffectParameterClass.Vector, EffectParameterType.Single, "DiffuseColor",
                4, 1, "float4", EffectAnnotationCollection.Empty, EffectParameterCollection.Empty, EffectParameterCollection.Empty, new float[4]);

            Parameters = new EffectParameterCollection(parametersArray);

            EffectPass [] effectsPassArray = new EffectPass[1];
            effectsPassArray[0] = effectPass;
            var effectPassCollection = new EffectPassCollection(effectsPassArray);

            EffectTechnique [] effectTechniqueArray = new EffectTechnique[1];
            effectTechniqueArray[0] = new EffectTechnique(this, "Name", effectPassCollection, EffectAnnotationCollection.Empty);
            Techniques = new EffectTechniqueCollection(effectTechniqueArray);

            ConstantBuffers  = new ConstantBuffer[0];
            CurrentTechnique = Techniques[0];
        }
Exemple #12
0
        internal void ReadEffect(BinaryReader reader)
        {
            var effectPass = new EffectPass(this, "Pass", null, null, BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullNone, new EffectAnnotationCollection());

            effectPass._shaderProgram = new ShaderProgram(reader.ReadBytes((int)reader.BaseStream.Length));
            var shaderProgram = effectPass._shaderProgram;

            Parameters = new EffectParameterCollection();
            for (int i = 0; i < shaderProgram.UniformCount; i++)
            {
                Parameters.Add(EffectParameterForUniform(shaderProgram, i));
            }

                        #warning Hacks for BasicEffect as we don't have these parameters yet
            Parameters.Add(new EffectParameter(
                               EffectParameterClass.Vector, EffectParameterType.Single, "SpecularColor",
                               3, 1, "float3",
                               new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[3]));
            Parameters.Add(new EffectParameter(
                               EffectParameterClass.Scalar, EffectParameterType.Single, "SpecularPower",
                               1, 1, "float",
                               new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), 0.0f));
            Parameters.Add(new EffectParameter(
                               EffectParameterClass.Vector, EffectParameterType.Single, "FogVector",
                               4, 1, "float4",
                               new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]));
            Parameters.Add(new EffectParameter(
                               EffectParameterClass.Vector, EffectParameterType.Single, "DiffuseColor",
                               4, 1, "float4",
                               new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]));

            Techniques = new EffectTechniqueCollection();
            var effectPassCollection = new EffectPassCollection();
            effectPassCollection.Add(effectPass);
            Techniques.Add(new EffectTechnique(this, "Name", effectPassCollection, new EffectAnnotationCollection()));

            ConstantBuffers = new ConstantBuffer[0];

            CurrentTechnique = Techniques[0];
        }
Exemple #13
0
        private void ReadEffect(BinaryReader reader)
        {
            // TODO: Maybe we should be reading in a string
            // table here to save some bytes in the file.

            // Read in all the constant buffers.
            var buffers = (int)reader.ReadByte();

            ConstantBuffers = new ConstantBuffer[buffers];
            for (var c = 0; c < buffers; c++)
            {
                var name = reader.ReadString();

                // Create the backing system memory buffer.
                var sizeInBytes = (int)reader.ReadInt16();

                // Read the parameter index values.
                var parameters = new int[reader.ReadByte()];
                var offsets    = new int[parameters.Length];
                for (var i = 0; i < parameters.Length; i++)
                {
                    parameters[i] = (int)reader.ReadByte();
                    offsets[i]    = (int)reader.ReadUInt16();
                }

                var buffer = new ConstantBuffer(GraphicsDevice,
                                                sizeInBytes,
                                                parameters,
                                                offsets,
                                                name);
                ConstantBuffers[c] = buffer;
            }

            // Read in all the shader objects.
            var shaders = (int)reader.ReadByte();

            _shaders = new Shader[shaders];
            for (var s = 0; s < shaders; s++)
            {
                _shaders[s] = new Shader(GraphicsDevice, reader);
            }

            // Read in the parameters.
            Parameters = ReadParameters(reader);

            // Read the techniques.
            var techniqueCount = (int)reader.ReadByte();
            var techniques     = new EffectTechnique[techniqueCount];

            for (var t = 0; t < techniqueCount; t++)
            {
                var name = reader.ReadString();

                var annotations = ReadAnnotations(reader);

                var passes = ReadPasses(reader, this, _shaders);

                techniques[t] = new EffectTechnique(this, name, passes, annotations);
            }

            Techniques       = new EffectTechniqueCollection(techniques);
            CurrentTechnique = Techniques[0];
        }
Exemple #14
0
        private void ReadEffect(BinaryReader reader)
        {
            // Check the header to make sure the file and version is correct!
            var header  = new string (reader.ReadChars(MGFXHeader.Length));
            var version = (int)reader.ReadByte();

            if (header != MGFXHeader)
            {
                throw new Exception("The MGFX file is corrupt!");
            }
            if (version != MGFXVersion)
            {
                throw new Exception("Wrong MGFX file version!");
            }

            var profile = reader.ReadByte();

#if DIRECTX
            if (profile != 1)
#else
            if (profile != 0)
#endif
            { throw new Exception("The MGFX effect is the wrong profile for this platform!"); }

            // TODO: Maybe we should be reading in a string
            // table here to save some bytes in the file.

            // Read in all the constant buffers.
            var buffers = (int)reader.ReadByte();
            ConstantBuffers = new ConstantBuffer[buffers];
            for (var c = 0; c < buffers; c++)
            {
#if OPENGL
                string name = reader.ReadString();
#else
                string name = null;
#endif

                // Create the backing system memory buffer.
                var sizeInBytes = (int)reader.ReadInt16();

                // Read the parameter index values.
                var parameters = new int[reader.ReadByte()];
                var offsets    = new int[parameters.Length];
                for (var i = 0; i < parameters.Length; i++)
                {
                    parameters [i] = (int)reader.ReadByte();
                    offsets [i]    = (int)reader.ReadUInt16();
                }

                var buffer = new ConstantBuffer(GraphicsDevice,
                                                sizeInBytes,
                                                parameters,
                                                offsets,
                                                name);
                ConstantBuffers[c] = buffer;
            }

            // Read in all the shader objects.
            var shaders = (int)reader.ReadByte();
            _shaders = new Shader[shaders];
            for (var s = 0; s < shaders; s++)
            {
                _shaders[s] = new Shader(GraphicsDevice, reader);
            }

            // Read in the parameters.
            Parameters = ReadParameters(reader);

            // Read the techniques.
            var techniqueCount = (int)reader.ReadByte();
            var techniques     = new EffectTechnique[techniqueCount];
            for (var t = 0; t < techniqueCount; t++)
            {
                var name = reader.ReadString();

                var annotations = ReadAnnotations(reader);

                var passes = ReadPasses(reader, this, _shaders);

                techniques[t] = new EffectTechnique(this, name, passes, annotations);
            }

            Techniques       = new EffectTechniqueCollection(techniques);
            CurrentTechnique = Techniques[0];
        }
Exemple #15
0
        public bool IsDisposed = false; // GG TODO this should be hooked up along with the rest of the Disposable interface

        //GG EDIT
        private void Init(String assetName, String body, GraphicsDevice graphicsDevice)
        {
            _name = assetName;
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("Graphics Device Cannot Be Null");
            }
            this.graphicsDevice = graphicsDevice;

            program_handle = GL.CreateProgram();

            Parameters = new EffectParameterCollection();
            Techniques = new EffectTechniqueCollection();

            InitVertexShader("DEFAULT_VERTEX", GGShader.DEFAULT_VERTEX);
            InitFragmentShader(assetName, body);

            GL.AttachShader(program_handle, vertex_handle);
            GL.AttachShader(program_handle, fragment_handle);
            GL.LinkProgram(program_handle);

            int actUnis = 0;

            Parameters._parameters.Clear();
            List <int> texes = new List <int>();

            GL.GetProgram(program_handle, ProgramParameter.ActiveUniforms, out actUnis);
            for (int x = 0; x < actUnis; x++)
            {
                int length, size;
                ActiveUniformType type;
                StringBuilder     name = new StringBuilder(100);
                GL.GetActiveUniform(program_handle, x, 100, out length, out size, out type, name);
                String fixedName = name.ToString();

                int location = GL.GetUniformLocation(program_handle, fixedName);
                if (fixedName.EndsWith("[0]"))
                {
                    fixedName = fixedName.Substring(0, fixedName.Length - 3);
                }
                Console.WriteLine("{0}: {1} {2} {3}", location, fixedName, type, size);
                EffectParameter efp = new EffectParameter(this, fixedName, location, type.ToString(), length, size);
                if (type == ActiveUniformType.Sampler2D)
                {
                    texes.Add(location);
                }

                Parameters._parameters.Add(efp.Name, efp);

                List <EffectParameter> _textureMappings = new List <EffectParameter>();

                if (efp.ParameterType == EffectParameterType.Texture2D)
                {
                    _textureMappings.Add(efp);
                }
            }
            texes.Sort();
            texture_locations = texes.ToArray();

            position_index = GL.GetAttribLocation(program_handle, "a_Position");
            color_index    = GL.GetAttribLocation(program_handle, "a_Color");
            texCoord_index = GL.GetAttribLocation(program_handle, "a_TexCoord");

            CurrentTechnique           = new EffectTechnique(this);
            CurrentTechnique.Passes[0] = new EffectPass(CurrentTechnique);
        }