This library simplifies the process of loading, binding, and using shaders in an LWJGL OpenGL application. It handles all of the OpenGL interactions and supports many GLSL data types by default using JOML. It has a great deal of customization allowing for new data types to be used instead of the defaults provided by this library.
Gradle dependency:
compile group: 'org.viduus', name: 'lwjgl-shader-manager', version: '0.0.1'
- shader loading
- load specified default value for uniform variables
- attribute binding
- custom type handlers (to and from GPU)
- custom shader loader
- vulkan shader pipeline
This shader manager is only intended for opengl applications using buffered rendering.
public class Example {
public static void main(String[] args) {
// tell opengl what shader we want to use
ShaderProgram program = shader_manager.shader("simple");
program.bind();
// update model matrix
ShaderVariable model_matrix = program.uniform("model_matrix");
// since this is the first call, it returns the default value assigned in the shader
Matrix4f mat = (Matrix4f) model_matrix.value();
mat.rotate(0.1f, 0, 1, 0);
// the value is automatically pushed to the GPU
model_matrix.value(mat);
// bind shader attributes
ShaderVariable in_position = program.attribute("in_position");
ShaderVariable in_color = program.attribute("in_color");
// automatically binds the attributes and their offsets to the vbo buffer
// it assumes that the data is tightly packed
program.bindAttributes(in_position, in_color);
// unbind attributes
program.unbindAttributes(in_position, in_color);
}
}
You can find a full working example here
glsl type | java type | read | write |
---|---|---|---|
boolean | Boolean | ✔️ | |
float | Float | ✔️ | ✔️ |
vec2 | Vector2f | ✔️ | ✔️ |
vec3 | Vector3f | ✔️ | ✔️ |
vec4 | Vector4f | ✔️ | ✔️ |
mat3 | Matrix3f | ✔️ | ✔️ |
mat4 | Matrix4f | ✔️ | ✔️ |
int | Int | ✔️ | ✔️ |
ivec2 | Vector2i | ✔️ | ✔️ |
ivec3 | Vector3i | ✔️ | ✔️ |
ivec4 | Vector4i | ✔️ | ✔️ |