现在的位置: 首页 > 综合 > 正文

compile shader

2018年02月06日 ⁄ 综合 ⁄ 共 1753字 ⁄ 字号 评论关闭

First of all, you can determine whether an implementation supports online
shader compilation by checking for the value of GL_SHADER_COMPILER
using glGetBooleanv. If this value is GL_TRUE, then the implementation
supports online shader source compilation. If this value is GL_FALSE, then
only binary shaders are supported (more on that next). Given that an
online compiler is supported, this means you can specify your shaders using
glShaderSource as we have done so far in our examples. There is one thing
you can do to try to mitigate the resource impact of shader compilation.
Once you are finished compiling any shaders for your application, you can
call glReleaseShaderCompiler. This function provides a hint to the
implementation that you are done with the shader compiler and it can free
its resources. Note that this function is only a hint, if you decide to compile
more shaders using glCompileShader, the implementation will need to
reallocate its resources for the compiler.

Example 4-4 Querying for Whether a Shader Compiler is Available

GLboolean shaderCompiler;
GLint numBinaryFormats;
GLint *formats;
// Determine if a shader compiler available
glGetBooleanv(GL_SHADER_COMPILER, &shaderCompiler);
// Determine binary formats available
glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &numBinaryFormats);
formats = malloc(sizeof(GLint) * numBinaryFormats);
glGetIntegerv(GL_SHADER_BINARY_FORMATS, formats);

// "formats" now holds the list of supported binary formats

void glShaderBinary(GLint n, const GLuint* shaders,
GLenum binaryFormat,
const void* binary, GLint length)
n the number of shader objects in the shaders array

shaders an array of shader object handles. Depending on the specific binary format requirements,this will be either a vertex shader object, a fragment shader object, or both.This is defined by the vendor’s shader binary format extension

binaryFormat the vendor-specific binary format token 

binary pointer to the binary data generated by the offline compiler

length the number of bytes in the binary data

抱歉!评论已关闭.