首页 > 其他分享 >OpenGlobe之ShaderProgramGL3x

OpenGlobe之ShaderProgramGL3x

时间:2023-10-30 14:12:41浏览次数:31  
标签:ShaderObjectGL3x programHandle private readonly program new ShaderProgramGL3x Op

该类有几个成员变量:

        private readonly ShaderObjectGL3x _vertexShader;
        private readonly ShaderObjectGL3x _geometryShader;
        private readonly ShaderObjectGL3x _fragmentShader;
        private readonly ShaderProgramNameGL3x _program;
        private readonly FragmentOutputsGL3x _fragmentOutputs;
        private readonly ShaderVertexAttributeCollection _vertexAttributes;
        private readonly IList<ICleanable> _dirtyUniforms;
        private readonly UniformCollection _uniforms;
        private readonly UniformBlockCollection _uniformBlocks;

构造函数:

public ShaderProgramGL3x(string vertexShaderSource,string geometryShaderSource,string fragmentShaderSource)
{
            _vertexShader = new ShaderObjectGL3x(ShaderType.VertexShader, vertexShaderSource);
            if (geometryShaderSource.Length > 0)
            {
                _geometryShader = new ShaderObjectGL3x(ShaderType.GeometryShaderExt, geometryShaderSource);
            }
            _fragmentShader = new ShaderObjectGL3x(ShaderType.FragmentShader, fragmentShaderSource);

            _program = new ShaderProgramNameGL3x();
            int programHandle = _program.Value;

            GL.AttachShader(programHandle, _vertexShader.Handle);
            if (geometryShaderSource.Length > 0)
            {
                GL.AttachShader(programHandle, _geometryShader.Handle);
            }
            GL.AttachShader(programHandle, _fragmentShader.Handle);

            GL.LinkProgram(programHandle);

            int linkStatus;
            GL.GetProgram(programHandle, ProgramParameter.LinkStatus, out linkStatus);

            if (linkStatus == 0)
            {
                throw new CouldNotCreateVideoCardResourceException("Could not link shader program.  Link Log:  \n\n" + ProgramInfoLog);
            }

            _fragmentOutputs = new FragmentOutputsGL3x(_program);
            _vertexAttributes = FindVertexAttributes(_program);
            _dirtyUniforms = new List<ICleanable>();
            _uniforms = FindUniforms(_program);
            _uniformBlocks = FindUniformBlocks(_program);

            InitializeAutomaticUniforms(_uniforms);
}

传入两个参数:vertexShaderSource和fragmentShaderSource,利用ShaderObjectGL3x对它们初始化(编译)。然后将两个shader的句柄handle链接到programHandle。最后获取_fragmentOutputs、 _vertexAttributes、_dirtyUniforms、_uniforms、_uniformBlocks几个变量的值。

标签:ShaderObjectGL3x,programHandle,private,readonly,program,new,ShaderProgramGL3x,Op
From: https://www.cnblogs.com/2008nmj/p/17797687.html

相关文章

  • OpenGlobe之ShaderObjectGL3x
    该类只有一个私有成员变量_shaderObjectprivateint_shaderObject;这是用来存放地址?初始化:_shaderObject=GL.CreateShader(shaderType);接着,为_shaderObject添加shader源文件:GL.ShaderSource(_shaderObject,sources.Length,sources,lengthPointer);接着,为_sha......
  • OpenGlobe
    Note:OpenGlobeisgreatforlearningalongwithourbook,3DEngineDesignforVirtualGlobes.Butforaproductionquality,opensource,virtualglobebythe......