Package org.boxutil.units.standard
Class ShaderProgram
java.lang.Object
org.boxutil.base.BaseShaderData
org.boxutil.units.standard.ShaderProgram
For example how use it:
// program init
final String vertSrc, fragSrc;
final var program = new ShaderProgram("YourShaderProgramTag-TheCommonDraw", vertSrc, fragSrc);
if (program.isValid()) {
// location setup
// If have uniform
program.initUniformSize(2)
.beginUniform()
.loadUniformIndex("u_u00")
.loadUniformIndex("u_u01")
// if have UBO
.initUniformBlockSize(1)
.beginUniformBlock()
.loadAndSetUniformBlockIndex("BUtilGlobalData", ShaderCore.getMatrixUBOBinding())
// if have subroutine
.initSubroutineSize(5, 2)
.beginSubroutine(0, GL20.GL_VERTEX_SHADER)
.loadSubroutineIndex("p_funA_v00") // of "f_funA_vu"
.loadSubroutineIndex("p_funA_v01") // of "f_funA_vu"
.loadSubroutineIndex("p_funA_v02") // of "f_funA_vu"
.loadSubroutineIndex("p_funB_v00") // of "f_funB_vu"
.loadSubroutineIndex("p_funB_v01") // of "f_funB_vu"
.beginSubroutine(1, GL20.GL_FRAGMENT_SHADER)
.loadSubroutineIndex("p_fun_f00")
.loadSubroutineIndex("p_fun_f01")
.initSubroutineUniformSize(2, 1)
.beginSubroutineUniform(0, GL20.GL_VERTEX_SHADER)
.loadSubroutineUniformIndex("f_funA_vu") // index 0
.loadSubroutineUniformIndex("f_funB_vu") // index 1
.beginSubroutineUniform(1, GL20.GL_FRAGMENT_SHADER)
.loadSubroutineUniformIndex("f_fun_fu")
.computeSubroutineUniformRoute();
}
// When running
// set uniform
GL20.glUniform1i(program.uniform("u_u00"), 2); // put 2 to "u_u00" that use GL13.GL_TEXTURE2, if "u_u00" is a 'sampler2D' type uniform
//GL20.glUniform1i(program.location[0], 2); // or use index
final int texID;
program.bindTexture2D(2, texID); // bind to "u_u00"
GL20.glUniform2f(program.uniform("u_u01"), 1.0f, 0.0f); // put vec2(1.0f, 0.0f) to "u_u01", if "u_u01" is a 'vec2' type uniform
//GL20.glUniform2f(program.location[1], 1.0f, 0.0f); // or use index
// put "p_funA_v00" to "f_funA_vu" and put "p_funB_v00" to "f_funB_vu"
final int[] vertexSub = new int[2];
vertexSub[0] = program.subroutine(0, "p_funA_v00"); // "f_funA_vu" at index-0
//vertexSub[0] = program.subroutineLocation[0][0]; // or use index
vertexSub[1] = program.subroutine(0, "p_funB_v00"); // "f_funB_vu" at index-1
//vertexSub[1] = program.subroutineLocation[0][3]; // or use index
program.putUniformSubroutines(GL20.GL_VERTEX_SHADER, 0, vertexSub);
// put "p_fun_f00" to "f_fun_fu"
program.putUniformSubroutine(GL20.GL_VERTEX_SHADER, 1, 0);
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final int[]protected org.boxutil.backends.util.BUtil_BoundedStr2IntMap[]protected org.boxutil.backends.util.BUtil_BoundedStr2IntMap[]protected org.boxutil.backends.util.BUtil_BoundedStr2IntMapprotected org.boxutil.backends.util.BUtil_BoundedStr2IntMapFields inherited from class org.boxutil.base.BaseShaderData
location, maxSubroutineUniformLocation, structLocation, subroutineLocation, subroutineUniformLocation, uboLocation -
Constructor Summary
ConstructorsConstructorDescriptionShaderProgram(boolean fromPath, String loggerTag, String... source) ShaderProgram(boolean fromPath, String loggerTag, String vert, String frag) ShaderProgram(boolean fromPath, String loggerTag, String vert, String geom, String frag) ShaderProgram(boolean fromPath, String loggerTag, String vert, String tessC, String tessE, String frag) ShaderProgram(boolean fromPath, String loggerTag, String vert, String tessC, String tessE, String geom, String frag) ShaderProgram(int id) ShaderProgram(String loggerTag, String... source) ShaderProgram(String loggerTag, String vert, String frag) ShaderProgram(String loggerTag, String vert, String geom, String frag) -
Method Summary
Modifier and TypeMethodDescriptionbeginSubroutine(int storeCategory, int shaderType) beginSubroutineUniform(int storeCategory, int shaderType) initSubroutineSize(int... categorySize) initSubroutineUniformSize(int... categorySize) initUniformBlockSize(int size) initUniformSize(int size) loadAndSetUniformBlockIndex(int storeIndex, String name, int bindingIndex) loadAndSetUniformBlockIndex(String name, int bindingIndex) loadSubroutineIndex(int storeCategory, int storeIndex, int shaderType, String name) loadSubroutineIndex(String name) loadSubroutineUniformIndex(int storeCategory, int storeIndex, int shaderType, String name) loadUniformBlockIndex(int storeIndex, String name) loadUniformBlockIndex(String name) loadUniformIndex(int storeIndex, String name) loadUniformIndex(String name) intsubroutine(int category, String name) Quickly queries the cached subroutine function location value after it has been set up vialoadSubroutineIndex.intsubroutine_uniform(int category, String name) Quickly queries the cached subroutine uniform location value after it has been set up vialoadSubroutineUniformIndex.intQuickly queries the cached uniform location value after it has been set up vialoadUniformIndex.intuniform_block(String name) Quickly queries the cached uniform block location value after it has been set up vialoadUniformBlockIndexorloadAndSetUniformBlockIndex.Methods inherited from class org.boxutil.base.BaseShaderData
active, bindTexture1D, bindTexture1D, bindTexture2D, bindTexture2D, bindTexture3D, bindTexture3D, bindTextureBuffer, bindTextureBuffer, close, delete, getId, getStructUniformIndex, getSubroutineBuffer, getSubroutineIndex, getSubroutineUniformLocation, getUBOIndex, getUniformIndex, initMaxSubroutineUniformLocation, isValid, putBindingImageTexture, putBindingImageTextureReadOnly, putBindingImageTextureWriteOnly, putBindless, putBindless, putDefaultTextureUnit, putUniformSubroutine, putUniformSubroutines, putUniformSubroutines, putUniformTexture1D, putUniformTexture1D, putUniformTexture2D, putUniformTexture2D, putUniformTexture3D, putUniformTexture3D, putUniformTextureBuffer, putUniformTextureBuffer
-
Field Details
-
uniformMap
protected org.boxutil.backends.util.BUtil_BoundedStr2IntMap uniformMap -
uniformBlockMap
protected org.boxutil.backends.util.BUtil_BoundedStr2IntMap uniformBlockMap -
subroutineMap
protected org.boxutil.backends.util.BUtil_BoundedStr2IntMap[] subroutineMap -
subroutineUniformMap
protected org.boxutil.backends.util.BUtil_BoundedStr2IntMap[] subroutineUniformMap -
_tmpIndex
protected final int[] _tmpIndex
-
-
Constructor Details
-
ShaderProgram
public ShaderProgram(int id) -
ShaderProgram
-
ShaderProgram
-
ShaderProgram
-
ShaderProgram
-
ShaderProgram
-
ShaderProgram
-
ShaderProgram
-
ShaderProgram
-
ShaderProgram
-
ShaderProgram
-
-
Method Details
-
initUniformSize
-
beginUniform
-
loadUniformIndex
-
loadUniformIndex
-
uniform
Quickly queries the cached uniform location value after it has been set up vialoadUniformIndex.- Returns:
-1when does not contain thisname.
-
initUniformBlockSize
-
beginUniformBlock
-
loadUniformBlockIndex
-
loadUniformBlockIndex
-
loadAndSetUniformBlockIndex
-
loadAndSetUniformBlockIndex
public ShaderProgram loadAndSetUniformBlockIndex(int storeIndex, @NotNull String name, int bindingIndex) -
uniform_block
Quickly queries the cached uniform block location value after it has been set up vialoadUniformBlockIndexorloadAndSetUniformBlockIndex.- Returns:
-1when does not contain thisname.
-
initSubroutineSize
-
beginSubroutine
-
loadSubroutineIndex
-
loadSubroutineIndex
public ShaderProgram loadSubroutineIndex(int storeCategory, int storeIndex, int shaderType, @NotNull String name) -
subroutine
Quickly queries the cached subroutine function location value after it has been set up vialoadSubroutineIndex.- Returns:
-1when does not contain thisname.
-
initSubroutineUniformSize
-
beginSubroutineUniform
-
loadSubroutineUniformIndex
-
loadSubroutineUniformIndex
public ShaderProgram loadSubroutineUniformIndex(int storeCategory, int storeIndex, int shaderType, @NotNull String name) -
subroutine_uniform
Quickly queries the cached subroutine uniform location value after it has been set up vialoadSubroutineUniformIndex.- Returns:
-1when does not contain thisname.
-
computeSubroutineUniformRoute
-