Class ShaderPrograms
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidbindAdditionalTextures(int program, net.minecraft.resources.ResourceLocation... textures) Binds any number of additional textures to be used by the current shader.static intgetUniformLocation(int program, String uniformName) getUniformLocationreturns an integer that represents the location of a specific uniform variable within a program object.static voidsetAttribValue(int program, String attribName, IntConsumer operation) Sets the value of an attribute from the current shader program using the given operation.static voidsetUniform(int program, String uniformName, float value) Sets the value of a float uniform field from the current shader programstatic voidsetUniform(int program, String uniformName, int value) Sets the value of an int uniform from the current shader programstatic voidsetUniform(int program, String uniformName, FloatBuffer mat4) Sets the value of a mat4 uniform in the current shaderstatic voidsetUniformValue(int program, String uniformName, IntConsumer operation) Sets the value of a uniform from the current shader program using the given operation.static voiduseShader(int program) Sets the currently used program.
-
Method Details
-
useShader
@API(status=MAINTAINED) public static void useShader(int program) Sets the currently used program.If shaders are disallowed in the current game instance, this method returns immediately with no side effect.
- Parameters:
program- the reference to the desired shader (0 to remove any current shader)
-
setAttribValue
@API(status=EXPERIMENTAL) public static void setAttribValue(int program, String attribName, IntConsumer operation) Sets the value of an attribute from the current shader program using the given operation.operationwill only be called if shaders are enabled and an attribute with the given name exists in the current program. It should call one ofGL20attrib functions (eg.GL20.glBindAttribLocation(int, int, ByteBuffer)).- Parameters:
program- OpenGL shader program objectattribName- the name of the attribute field in the shader source fileoperation- a gl operation to apply to this uniform
-
setUniformValue
@API(status=EXPERIMENTAL) public static void setUniformValue(int program, String uniformName, IntConsumer operation) Sets the value of a uniform from the current shader program using the given operation.operationwill only be called if shaders are enabled and a uniform with the given name exists in the current program. It should call one ofGL20uniform functions (eg.GL20.glUniform1iv(int, IntBuffer)).- Parameters:
program- OpenGL shader program objectuniformName- the name of the uniform field in the shader source fileoperation- a gl operation to apply to this uniform
-
setUniform
Sets the value of an int uniform from the current shader program- Parameters:
program- OpenGL shader program objectuniformName- the name of the uniform field in the shader source filevalue- an int value for this uniform
-
setUniform
@API(status=EXPERIMENTAL) public static void setUniform(int program, String uniformName, float value) Sets the value of a float uniform field from the current shader program- Parameters:
program- OpenGL shader program objectuniformName- the name of the uniform field in the shader source filevalue- float value of the uniform
-
setUniform
@API(status=EXPERIMENTAL) public static void setUniform(int program, String uniformName, FloatBuffer mat4) Sets the value of a mat4 uniform in the current shader- Parameters:
program- OpenGL shader program objectuniformName- the name of the uniform field in the shader source filemat4- a raw array of float values
-
getUniformLocation
getUniformLocationreturns an integer that represents the location of a specific uniform variable within a program object.namemust be a string that contains no white space.namemust be an active uniform variable name in program that is not a structure, an array of structures, or a subcomponent of a vector or a matrix.This function returns -1 if name does not correspond to an active uniform variable in
programor ifnamestarts with the reserved prefix "gl_".Uniform locations obtained through this method are cached, limiting performance loss from consecutive calls.
- Parameters:
program- program object to be querieduniformName- string containing the name of the uniform variable whose location is to be queried- Returns:
- an integer that represents the location of a specific uniform variable within a program object
-
bindAdditionalTextures
@API(status=EXPERIMENTAL) public static void bindAdditionalTextures(int program, net.minecraft.resources.ResourceLocation... textures) Binds any number of additional textures to be used by the current shader.The default texture (0) is unaffected. Shaders can access these textures by using uniforms named "textureN" with N being the index of the additional texture, starting at 1.
Example: The callbindAdditionalTextures(rl1, rl2, rl3)will let the shader access those textures via the uniformsuniform sampler2D texture; // the texture that's currently being drawn uniform sampler2D texture1; // the texture designated by rl1 uniform sampler2D texture2; // the texture designated by rl2 uniform sampler2D texture3; // the texture designated by rl3
-