Ejemplo n.º 1
0
        /// <summary>
        /// Applies the specified parameter values to all currently active shaders.
        /// </summary>
        /// <param name="sharedParams"></param>
        /// <seealso cref="RetrieveActiveShaders"/>
        private void SetupSharedParameters(ShaderParameterCollection sharedParams)
        {
            this.sharedSamplerBindings = 0;
            this.sharedShaderParameters.Clear();
            if (sharedParams == null)
            {
                return;
            }

            foreach (NativeShaderProgram shader in this.activeShaders)
            {
                NativeShaderProgram.Bind(shader);

                ShaderFieldInfo[] varInfo = shader.Fields;
                NativeShaderProgram.FieldLocation[] locations = shader.FieldLocations;

                // Setup shared sampler bindings and uniform data
                for (int i = 0; i < varInfo.Length; i++)
                {
                    ref ShaderFieldInfo field = ref varInfo[i];

                    if (field.Scope == ShaderFieldScope.Attribute)
                    {
                        continue;
                    }
                    if (field.Type == ShaderFieldType.Sampler2D)
                    {
                        ContentRef <Texture> texRef;
                        if (!sharedParams.TryGetInternal(field.Name, out texRef))
                        {
                            continue;
                        }

                        NativeTexture.Bind(texRef, this.sharedSamplerBindings);
                        GL.Uniform1i(locations[i].Uniform, this.sharedSamplerBindings);

                        this.sharedSamplerBindings++;
                    }
                    else
                    {
                        float[] data;
                        if (!sharedParams.TryGetInternal(field.Name, out data))
                        {
                            continue;
                        }

                        NativeShaderProgram.SetUniform(ref field, locations[i].Uniform, data);
                    }

                    this.sharedShaderParameters.Add(field.Name);
                }
            }
Ejemplo n.º 2
0
        public static void Bind(NativeShaderProgram prog)
        {
            if (curBound == prog)
            {
                return;
            }

            if (prog == null)
            {
                GraphicsBackend.GL.UseProgram(null);
                curBound = null;
            }
            else
            {
                GraphicsBackend.GL.UseProgram(prog.Handle);
                curBound = prog;
            }
        }