Exemplo n.º 1
0
        public OpenGLShaderSet(
            OpenGLVertexInputLayout inputLayout,
            OpenGLShader vertexShader,
            OpenGLShader tessellationControlShader,
            OpenGLShader tessellationEvaluationShader,
            OpenGLShader geometryShader,
            OpenGLShader fragmentShader)
        {
            InputLayout  = inputLayout;
            VertexShader = vertexShader;
            TessellationControlShader    = tessellationControlShader;
            TessellationEvaluationShader = tessellationEvaluationShader;
            GeometryShader = geometryShader;
            FragmentShader = fragmentShader;

            ProgramID = GL.CreateProgram();
            GL.AttachShader(ProgramID, vertexShader.ShaderID);
            if (tessellationControlShader != null)
            {
                GL.AttachShader(ProgramID, tessellationControlShader.ShaderID);
            }
            if (tessellationEvaluationShader != null)
            {
                GL.AttachShader(ProgramID, tessellationEvaluationShader.ShaderID);
            }
            if (geometryShader != null)
            {
                GL.AttachShader(ProgramID, geometryShader.ShaderID);
            }
            GL.AttachShader(ProgramID, fragmentShader.ShaderID);

            int slot = 0;

            foreach (var input in inputLayout.InputDescriptions)
            {
                for (int i = 0; i < input.Elements.Length; i++)
                {
                    GL.BindAttribLocation(ProgramID, slot, input.Elements[i].Name);
                    slot += 1;
                }
            }

            GL.LinkProgram(ProgramID);

            int linkStatus;

            GL.GetProgram(ProgramID, GetProgramParameterName.LinkStatus, out linkStatus);
            if (linkStatus != 1)
            {
                string log = GL.GetProgramInfoLog(ProgramID);
                throw new VeldridException($"Error linking GL program: {log}");
            }
        }
Exemplo n.º 2
0
        public OpenGLShaderSet(
            OpenGLVertexInputLayout inputLayout,
            OpenGLShader vertexShader,
            OpenGLShader tessellationControlShader,
            OpenGLShader tessellationEvaluationShader,
            OpenGLShader geometryShader,
            OpenGLShader fragmentShader)
        {
            InputLayout  = inputLayout;
            VertexShader = vertexShader;
            TessellationControlShader    = tessellationControlShader;
            TessellationEvaluationShader = tessellationEvaluationShader;
            GeometryShader = geometryShader;
            FragmentShader = fragmentShader;

            ProgramID = GL.CreateProgram();
            GL.AttachShader(ProgramID, vertexShader.ShaderID);
            if (tessellationControlShader != null)
            {
                GL.AttachShader(ProgramID, tessellationControlShader.ShaderID);
            }
            if (tessellationEvaluationShader != null)
            {
                GL.AttachShader(ProgramID, tessellationEvaluationShader.ShaderID);
            }
            if (geometryShader != null)
            {
                GL.AttachShader(ProgramID, geometryShader.ShaderID);
            }
            GL.AttachShader(ProgramID, fragmentShader.ShaderID);

            int slot = 0;

            foreach (VertexInputDescription input in inputLayout.InputDescriptions)
            {
                for (int i = 0; i < input.Elements.Length; i++)
                {
                    GL.BindAttribLocation(ProgramID, slot, input.Elements[i].Name);
                    slot += 1;
                }
            }

            GL.LinkProgram(ProgramID);

#if DEBUG && GL_VALIDATE_VERTEX_INPUT_ELEMENTS
            slot = 0;
            foreach (VertexInputDescription input in inputLayout.InputDescriptions)
            {
                for (int i = 0; i < input.Elements.Length; i++)
                {
                    int location = GL.GetAttribLocation(ProgramID, input.Elements[i].Name);
                    if (location == -1)
                    {
                        throw new VeldridException("There was no attribute variable with the name " + input.Elements[i].Name);
                    }
                    slot += 1;
                }
            }
#endif

            int linkStatus;
            GL.GetProgram(ProgramID, GetProgramParameterName.LinkStatus, out linkStatus);
            if (linkStatus != 1)
            {
                string log = GL.GetProgramInfoLog(ProgramID);
                throw new VeldridException($"Error linking GL program: {log}");
            }
        }