コード例 #1
0
        public void SetUniform(string name, float v1, float?v2 = null, float?v3 = null, float?v4 = null)
        {
            if (ActiveShaderProgram == null)
            {
                throw new InvalidOperationException("No shader program is loaded. Cannot set uniforms.");
            }

            int uniformLocation = Gl.GetUniformLocation(ActiveShaderProgram.ProgramId, name);

            if (uniformLocation < 0)
            {
                throw new KeyNotFoundException(string.Format("The specified uniform '{0}' cannot be found for program '{1}'.", name, ActiveShaderProgram.ProgramId));
            }

            if (v4 != null && v4.HasValue)
            {
                Gl.Uniform4(uniformLocation, v1, v2.Value, v3.Value, v4.Value);
                return;
            }

            if (v3 != null && v3.HasValue)
            {
                Gl.Uniform3(uniformLocation, v1, v2.Value, v3.Value);
                return;
            }

            if (v2 != null && v2.HasValue)
            {
                Gl.Uniform2(uniformLocation, v1, v2.Value);
                return;
            }

            Gl.Uniform1(uniformLocation, v1);
            return;
        }
コード例 #2
0
        protected override void Renderer_DrawPrepare(RenderThread sender, FrameStageControllerEventArgs args)
        {
            CheckGlErrors("pre-program");
            sender.SelectShader(glyphShader);
            CheckGlErrors("post-program");

            sender.SelectShader(glyphShader);
            sender.SetUniform("resolution", 0, 0, sender.InternalResolution.Width, sender.InternalResolution.Height);
            sender.SetUniform("atlasSize", fontAtlas.AtlasTextureSize.Width, fontAtlas.AtlasTextureSize.Height);
            Gl.Uniform1(Gl.GetUniformLocation(glyphShader.ProgramId, "atlasTexture"), 0);
            CheckGlErrors("post-uniforms");
        }