osg.ShaderComponent是OpenSceneGraph中的组件,用于创建和管理着色器程序。该组件可用于OpenGL ES 2.0、OpenGL 2.0和OpenGL 3.0。通过使用osg.ShaderComponent,用户可以轻松地创建和管理着色器程序。
osg.ShaderComponent(mode: int)
import osg
shader = osg.ShaderComponent(osg.GL_VERTEX_SHADER)
shader.bind()
if shader.isBound():
shader.addSourceCode("#version 300 es\n"
"in vec4 position;\n"
"void main()\n"
"{\n"
" gl_Position = position;\n"
"}\n")
shader.addUniform("projectionMatrix", osg.Uniform.FLOAT_MAT4)
shader.addUniform("modelViewMatrix", osg.Uniform.FLOAT_MAT4)
projection = osg.Matrixd()
modelview = osg.Matrixd()
shader.setUniformValue("projectionMatrix", projection)
shader.setUniformValue("modelViewMatrix", modelview)
shader.unbind()
addSourceCode(code: str)
addUniform(name: str, type: int)
setUniformValue(name: str, value: Union[int, float, str, osg.Matrixd, osg.Vec2, osg.Vec3, osg.Vec4])
setUniformArray(name: str, value: List[Tuple[Union[int, float, str, osg.Matrixd, osg.Vec2, osg.Vec3, osg.Vec4]]])
bind() -> bool
unbind()
isBound() -> bool