ShaderProgramShaderIt's getting more complicated as you can see (in order to smoothly allow reusing shaders), but the same "Slick-esque" functionality has remained unchanged:
Code:
//option A: from file
ShaderProgram prog = ShaderProgram.load("blah.vert", "blah.frag");
//option B: from source code string
ShaderProgram prog = new ShaderProgram(VERTEX_SOURCE, FRAG_SOURCE);
Advanced users who want to reuse shaders/programs:
Code:
//each shader is compiled when created
Shader sharedVert = new Shader(Shader.VERTEX_SHADER, VERTEX_SOURCE);
Shader sharedFrag = new Shader(Shader.FRAGMENT_SHADER, FRAG_SOURCE);
//this links immediately
ShaderProgram prog = new ShaderProgram(sharedVert, sharedFrag);
//alternatively, we could link it all later
ShaderProgram prog = new ShaderProgram();
prog.setVertexShader(sharedVert);
prog.setFragmentShader(sharedFrag);
prog.link();
//once everything is linked we can release shaders if we no longer need them
//the ShaderProgram still works even if its shader objects have been detached and deleted
sharedVert.release();
sharedFrag.release();
- Creating an empty ShaderProgram will throw an exception if shaders aren't supported.
- Creating a new Shader will throw an exception if the shader doesn't compile.
- Linking a shader program will throw an exception if the current shaders are null, invalid, or if there was an error in linking
- Even if a shader compiles or a program is successfully linked, there might be some error logs.. it's worth checking getLog (or, individually, Shader.getCompileLog / ShaderProgram.getLinkLog
- Advanced shader objects shouldn't be too hard to implement (geometry, tesselation, a vertex shader built from "chunks" of shader objects, etc)
Let me know if you have any issues with the design / structure.