GetUniformLocation() public method

public GetUniformLocation ( string name ) : int
name string
return int
コード例 #1
0
        public void Render(Camera camera)
        {
            GL.UseProgram(shader.Program);
            GL.BindVertexArray(quadVao);
            GL.EnableVertexAttribArray(0);

            var uniformLocation = shader.GetUniformLocation("m_vTintColorSceneObject");

            if (uniformLocation > -1)
            {
                GL.Uniform4(uniformLocation, Vector4.One);
            }

            uniformLocation = shader.GetUniformLocation("m_vTintColorDrawCall");
            if (uniformLocation > -1)
            {
                GL.Uniform3(uniformLocation, Vector3.One);
            }

            material.Render(shader);

            GL.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);

            material.PostRender();

            GL.BindVertexArray(0);
            GL.UseProgram(0);
        }
コード例 #2
0
        public void Render(Shader shader)
        {
            //Start at 1, texture unit 0 is reserved for the animation texture
            var textureUnit = 1;
            int uniformLocation;

            foreach (var texture in Textures)
            {
                uniformLocation = shader.GetUniformLocation(texture.Key);

                if (uniformLocation > -1)
                {
                    GL.ActiveTexture(TextureUnit.Texture0 + textureUnit);
                    GL.BindTexture(TextureTarget.Texture2D, texture.Value);
                    GL.Uniform1(uniformLocation, textureUnit);

                    textureUnit++;
                }
            }

            foreach (var param in Material.FloatParams)
            {
                uniformLocation = shader.GetUniformLocation(param.Key);

                if (uniformLocation > -1)
                {
                    GL.Uniform1(uniformLocation, param.Value);
                }
            }

            foreach (var param in Material.VectorParams)
            {
                uniformLocation = shader.GetUniformLocation(param.Key);

                if (uniformLocation > -1)
                {
                    GL.Uniform4(uniformLocation, new Vector4(param.Value.X, param.Value.Y, param.Value.Z, param.Value.W));
                }
            }

            var alphaReference = shader.GetUniformLocation("g_flAlphaTestReference");

            if (alphaReference > -1)
            {
                GL.Uniform1(alphaReference, flAlphaTestReference);
            }

            if (isTranslucent)
            {
                GL.DepthMask(false);
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactor.SrcAlpha, isAdditiveBlend ? BlendingFactor.One : BlendingFactor.OneMinusSrcAlpha);
            }

            if (isRenderBackfaces)
            {
                GL.Disable(EnableCap.CullFace);
            }
        }
コード例 #3
0
        public void Render(Camera camera, RenderPass renderPass)
        {
            if (renderPass == RenderPass.Translucent || renderPass == RenderPass.Both)
            {
                if (dynamic)
                {
                    Rebuild();
                }

                GL.Enable(EnableCap.Blend);
                GL.Enable(EnableCap.DepthTest);
                GL.DepthMask(false);
                GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
                GL.UseProgram(shader.Program);

                var projectionViewMatrix = camera.ViewProjectionMatrix.ToOpenTK();
                GL.UniformMatrix4(shader.GetUniformLocation("uProjectionViewMatrix"), false, ref projectionViewMatrix);

                GL.BindVertexArray(vaoHandle);
                GL.DrawArrays(PrimitiveType.Lines, 0, vertexCount);
                GL.BindVertexArray(0);
                GL.UseProgram(0);
                GL.DepthMask(true);
                GL.Disable(EnableCap.Blend);
                GL.Disable(EnableCap.DepthTest);
            }
        }
コード例 #4
0
        public void Render(Camera camera, RenderPass renderPass)
        {
            GL.UseProgram(shader.Program);
            GL.BindVertexArray(quadVao);
            GL.EnableVertexAttribArray(0);

            var uniformLocation = shader.GetUniformLocation("m_vTintColorSceneObject");

            if (uniformLocation > -1)
            {
                GL.Uniform4(uniformLocation, Vector4.One);
            }

            uniformLocation = shader.GetUniformLocation("m_vTintColorDrawCall");
            if (uniformLocation > -1)
            {
                GL.Uniform3(uniformLocation, Vector3.One);
            }

            var identity = Matrix4.Identity;

            uniformLocation = shader.GetUniformLocation("uProjectionViewMatrix");
            if (uniformLocation > -1)
            {
                GL.UniformMatrix4(uniformLocation, false, ref identity);
            }

            uniformLocation = shader.GetUniformLocation("transform");
            if (uniformLocation > -1)
            {
                GL.UniformMatrix4(uniformLocation, false, ref identity);
            }

            material.Render(shader);

            GL.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);

            material.PostRender();

            GL.BindVertexArray(0);
            GL.UseProgram(0);
        }
コード例 #5
0
        public void Render(Camera camera)
        {
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            GL.UseProgram(shader.Program);

            var projectionViewMatrix = camera.CameraViewMatrix * camera.ProjectionMatrix;

            GL.UniformMatrix4(shader.GetUniformLocation("uProjectionViewMatrix"), false, ref projectionViewMatrix);

            GL.BindVertexArray(vao);
            GL.DrawArrays(PrimitiveType.Lines, 0, vertexCount);
            GL.BindVertexArray(0);
            GL.UseProgram(0);
            GL.Disable(EnableCap.Blend);
        }
コード例 #6
0
        public override void Render(Scene.RenderContext context)
        {
            if (!Enabled)
            {
                return;
            }

            var viewProjectionMatrix = (Transform * context.Camera.ViewProjectionMatrix).ToOpenTK();

            GL.UseProgram(shader.Program);

            GL.UniformMatrix4(shader.GetUniformLocation("uProjectionViewMatrix"), false, ref viewProjectionMatrix);
            GL.DepthMask(false);

            GL.BindVertexArray(vaoHandle);
            GL.DrawElements(PrimitiveType.Lines, indexCount, DrawElementsType.UnsignedInt, 0);
            GL.BindVertexArray(0);

            GL.DepthMask(true);
        }