Package de.coreengine.rendering.programs
Class Shader
- java.lang.Object
-
- de.coreengine.rendering.programs.Shader
-
- Direct Known Subclasses:
AnimatedEntityShader
,DeferredShader
,EntityShader
,FontShader
,GrasslandShader
,GUIShader
,LensFlareShader
,ParticleShader
,PPShader
,ShadowMapShader
,SkyboxShader
,SunMoonShader
,TerrainShader
,WaterShader
public abstract class Shader extends Object
Class that represents an opengl shader program- Author:
- Darius Dinger
-
-
Field Summary
Fields Modifier and Type Field Description static String
SHADERS_LOCATION
Default location of the glsl shader files
-
Constructor Summary
Constructors Constructor Description Shader()
Creates new Shader and creating shader program in opengl
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addShader(String[] shaderCode, int shaderType, String name)
Adding new shader from sourcecode to the programprotected abstract void
addShaders()
Adding shaders to programprotected abstract void
bindAttribs()
Binding all vbo attributes to shader attribute ("in" variable)protected void
bindAttribute(int attrib, String name)
Binding an attribute from a vbo to an 'in' variable in the shader programmprotected void
bindTexture(int texture, int unit, int type)
Binding texture to an opengl textureunitprotected void
bindTextureUnit(String uniform, int unit)
Binding uniform variable to opengl texture unitprotected int
getUniformLocation(String uniform)
Getting location of anshader uniform variableprotected abstract void
loadUniforms()
Loading uniform locationsprotected void
setUniform(int location, boolean value)
Loading a boolean into a uniform variableprotected void
setUniform(int location, float value)
Loading a float into a uniform variableprotected void
setUniform(int location, float[] matrix)
Loading a 4x4 matrix into a uniform variableprotected void
setUniform(int location, float x, float y)
Loading a 2d vector into a uniform variableprotected void
setUniform(int location, float x, float y, float z)
Loading a 3d vector into a uniform variableprotected void
setUniform(int location, float x, float y, float z, float w)
Loading a 4d vector into a uniform variableprotected void
setUniform(int location, int value)
Loading an int into a uniform variableprotected void
setUniform(int location, Color col)
Loading a color into a uniform vec3f variableprotected void
setUniformArray1f(int location, float[] floats)
Loading a float array into a uniform variableprotected void
setUniformArray1i(int location, int[] ints)
Loading a int array into a uniform variableprotected void
setUniformArray2f(int location, float[] floats)
Loading a vec2 array into a uniform variableprotected void
setUniformArray3f(int location, float[] floats)
Loading a vec3 array into a uniform variablevoid
start()
Starting/enable shaderprogramvoid
stop()
Stopping/disable shaderprogram (use 0)
-
-
-
Field Detail
-
SHADERS_LOCATION
public static final String SHADERS_LOCATION
Default location of the glsl shader files- See Also:
- Constant Field Values
-
-
Method Detail
-
addShader
protected final void addShader(String[] shaderCode, int shaderType, String name)
Adding new shader from sourcecode to the program- Parameters:
shaderCode
- String that contains the shader source codeshaderType
- Type of the shader (vs, fs, geo, tes, tcs, cs)name
- Pseudonym name of the shader for faster error detection
-
getUniformLocation
protected final int getUniformLocation(String uniform)
Getting location of anshader uniform variable- Parameters:
uniform
- Uniform variable name in shader code- Returns:
- Uniforms location
-
bindAttribute
protected final void bindAttribute(int attrib, String name)
Binding an attribute from a vbo to an 'in' variable in the shader programm- Parameters:
attrib
- Vbos attrib to bind (row)name
- 'in' Variable name in shader code
-
bindTextureUnit
protected final void bindTextureUnit(String uniform, int unit)
Binding uniform variable to opengl texture unit- Parameters:
uniform
- Uniform variable name in shader codeunit
- Opengl texture unit id
-
addShaders
protected abstract void addShaders()
Adding shaders to program
-
bindAttribs
protected abstract void bindAttribs()
Binding all vbo attributes to shader attribute ("in" variable)
-
loadUniforms
protected abstract void loadUniforms()
Loading uniform locations
-
start
public void start()
Starting/enable shaderprogram
-
stop
public void stop()
Stopping/disable shaderprogram (use 0)
-
setUniform
protected final void setUniform(int location, boolean value)
Loading a boolean into a uniform variable- Parameters:
location
- Location of the uniform variablevalue
- Boolean to load
-
setUniform
protected final void setUniform(int location, float value)
Loading a float into a uniform variable- Parameters:
location
- Location of the uniform variablevalue
- Float to load
-
setUniform
protected final void setUniform(int location, int value)
Loading an int into a uniform variable- Parameters:
location
- Location of the uniform variablevalue
- Int to load
-
setUniform
protected final void setUniform(int location, float x, float y)
Loading a 2d vector into a uniform variable- Parameters:
location
- Location of the uniform variablex
- First value of the vectory
- Second value of the vector
-
setUniform
protected final void setUniform(int location, float x, float y, float z)
Loading a 3d vector into a uniform variable- Parameters:
location
- Location of the uniform variablex
- First value of the vectory
- Second value of the vectorz
- Third value ofthe vector
-
setUniform
protected final void setUniform(int location, float x, float y, float z, float w)
Loading a 4d vector into a uniform variable- Parameters:
location
- Location of the uniform variablex
- First value of the vectory
- Second value of the vectorz
- Third value ofthe vectorw
- Fourth value of the vector
-
setUniform
protected final void setUniform(int location, float[] matrix)
Loading a 4x4 matrix into a uniform variable- Parameters:
location
- Location of the uniform variablematrix
- 4x4 matrix to load as float array
-
setUniformArray3f
protected final void setUniformArray3f(int location, float[] floats)
Loading a vec3 array into a uniform variable- Parameters:
location
- Location of the uniform variablefloats
- float array to use (x0,y0,z0,x1,y1,z1,x2,...)
-
setUniformArray2f
protected final void setUniformArray2f(int location, float[] floats)
Loading a vec2 array into a uniform variable- Parameters:
location
- Location of the uniform variablefloats
- float array to use (x0,y0,x1,y1,x2,...)
-
setUniformArray1f
protected final void setUniformArray1f(int location, float[] floats)
Loading a float array into a uniform variable- Parameters:
location
- Location of the uniform variablefloats
- float array to use (x0,x1,x2,...)
-
setUniformArray1i
protected final void setUniformArray1i(int location, int[] ints)
Loading a int array into a uniform variable- Parameters:
location
- Location of the uniform variableints
- int array to use (x0,x1,x2,...)
-
setUniform
protected final void setUniform(int location, Color col)
Loading a color into a uniform vec3f variable- Parameters:
location
- Location of the uniform variablecol
- color to load as vec3f
-
bindTexture
protected final void bindTexture(int texture, int unit, int type)
Binding texture to an opengl textureunit- Parameters:
texture
- TextureData to bindunit
- Textureunit to bind texture totype
- TextureData type (GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, ...)
-
-