Esempio n. 1
0
        internal Effect(Shader shader)
        {
            Shader = shader;
            ParameterData = new byte[Shader.ParametersSize];

            EffectParameter[] parameters = new EffectParameter[Shader.Parameters.Count];
            for (int i = 0; i < Shader.Parameters.Count; i++)
                parameters[i] = new EffectParameter(this, Shader.Parameters[i]);

            EffectPass[] passes = new EffectPass[Shader.Passes.Count];
            for (int i = 0; i < Shader.Passes.Count; i++)
                passes[i] = new EffectPass(this, Shader.Passes[i]);

            Parameters = new EffectParameterCollection(parameters);
            Passes = new EffectPassCollection(passes);

            foreach (EffectParameter parameter in Parameters)
            {
                if (parameter.Class == EffectParameterClass.Sampler)
                {
                    int count = parameter.Parameter.Count == 0 ? 1 : parameter.Parameter.Count;
                    int[] units = new int[count];

                    for (int i = 0; i < count; i++)
                        units[i] = parameter.Parameter.TextureUnit + i;

                    parameter.SetValue(count);
                }
            }
        }
Esempio n. 2
0
        internal void Bind(GraphicsDevice graphicsDevice, IntPtr source)
        {
            if (_lastUsed == this && _lastUsedPointer == source && _lastUsedShader == graphicsDevice.ActiveShader)
                return;

            for (int i = 0; i < graphicsDevice.ActiveShader.Input.Length; i++)
            {
                VertexElement element = null;
                ShaderInput input = graphicsDevice.ActiveShader.Input[i];

                for (int j = 0; j < _vertexElements.Length; j++)
                {
                    if (_vertexElements[j].VertexElementUsage == input.Usage && _vertexElements[j].UsageIndex == input.UsageIndex)
                    {
                        element = _vertexElements[j];
                        break;
                    }
                }

                if (element != null)
                {
                    GL.EnableVertexAttribArray(input.Index);
                    GL.VertexAttribPointer(input.Index, element.ElementCount, element.VertexAttribPointerType, !element.IsNormalized, VertexStride, source + element.Offset);
                }
                else
                {
                    GL.DisableVertexAttribArray(input.Index);
                }
            }

            _lastUsed = this;
            _lastUsedPointer = source;
            _lastUsedShader = graphicsDevice.ActiveShader;
        }
Esempio n. 3
0
 public static void ResetLastUsedCache()
 {
     _lastUsed = null;
     _lastUsedPointer = IntPtr.Zero;
     _lastUsedShader = null;
 }