12#ifndef GAMP_GLSLSHADERSTATE_HPP_
13#define GAMP_GLSLSHADERSTATE_HPP_
22 using namespace gamp::render::gl;
23 using namespace gamp::render::gl::data;
30 class GLSLTextureRaster {
32 bool textureVertFlipped;
36 PMVMatrix4f m_pmvMatrix;
41 GLSLTextureRaster(
int textureUnit,
bool textureVertFlipped) {
42 this.textureVertFlipped = textureVertFlipped;
43 this.textureUnit = textureUnit;
65 if(!sp.link(
gl, System.err)) {
66 throw GLException(
"Couldn't link program: "+sp);
68 sp.useProgram(
gl,
true);
71 pmvMatrix =
new PMVMatrix4f();
72 pmvMatrix.loadPIdentity();
73 pmvMatrix.loadMvIdentity();
74 pmvMatrixUniform =
new GLUniformData(
"mgl_PMVMatrix", 4, 4, pmvMatrix.getSyncPMv());
75 if( pmvMatrixUniform.setLocation(
gl, sp.program()) < 0 ) {
76 throw GLException(
"Couldn't locate "+pmvMatrixUniform+
" in shader: "+sp);
78 gl.glUniform(pmvMatrixUniform);
80 activeTexUniform =
new GLUniformData(
"mgl_Texture0", textureUnit);
81 if( activeTexUniform.setLocation(
gl, sp.program()) < 0 ) {
82 throw GLException(
"Couldn't locate "+activeTexUniform+
" in shader: "+sp);
84 gl.glUniform(activeTexUniform);
86 final float[] s_quadTexCoords;
87 if( textureVertFlipped ) {
88 s_quadTexCoords = s_quadTexCoords01;
90 s_quadTexCoords = s_quadTexCoords00;
95 final GLArrayData vArrayData = interleavedVBO.addGLSLSubArray(
"mgl_Vertex", 3,
GL.GL_ARRAY_BUFFER);
97 throw GLException(
"Couldn't locate "+vArrayData+
" in shader: "+sp);
99 final GLArrayData tArrayData = interleavedVBO.addGLSLSubArray(
"mgl_MultiTexCoord", 2,
GL.GL_ARRAY_BUFFER);
101 throw GLException(
"Couldn't locate "+tArrayData+
" in shader: "+sp);
103 final FloatBuffer ib = (FloatBuffer)interleavedVBO.getBuffer();
104 for(
int i=0; i<4; i++) {
105 ib.put(s_quadVertices, i*3, 3);
106 ib.put(s_quadTexCoords, i*2, 2);
109 interleavedVBO.seal(
gl,
true);
110 interleavedVBO.enableBuffer(
gl,
false);
112 sp.useProgram(
gl,
false);
115 public void reshape(
final GL2ES2
gl,
final int x,
final int y,
final int width,
final int height) {
117 pmvMatrix.loadPIdentity();
118 pmvMatrix.orthoP(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 10.0f);
120 pmvMatrix.loadMvIdentity();
122 sp.useProgram(
gl,
true);
123 gl.glUniform(pmvMatrixUniform);
124 sp.useProgram(
gl,
false);
129 if(null != pmvMatrixUniform) {
130 pmvMatrixUniform = null;
133 if(null != interleavedVBO) {
134 interleavedVBO.destroy(
gl);
145 sp.useProgram(
gl,
true);
146 interleavedVBO.enableBuffer(
gl,
true);
148 gl.glDrawArrays(
GL.GL_TRIANGLE_STRIP, 0, 4);
150 interleavedVBO.enableBuffer(
gl,
false);
151 sp.useProgram(
gl,
false);
155 private static final float[] s_quadVertices = {
161 private static final float[] s_quadTexCoords00 = {
167 private static final float[] s_quadTexCoords01 = {
Server data buffer for VBO GLArrayData usage of given template-type Value_type.
static server_ref createGLSLInterleaved(GLsizei compsPerElement, bool normalized, GLsizei initialElementCount, GLenum vboUsage)
Create a VBO for GLSL interleaved array data starting with a new created Buffer object with initialEl...
Interface for a generic data buffer to be used for OpenGL arrays.
void setLocation(GLint loc) noexcept
Sets the given location of the shader attribute.
static final String shaderSrcPath
static final String shaderBasename
void reshape(final GL2ES2 gl, final int x, final int y, final int width, final int height)
void init(final GL2ES2 gl)
void dispose(final GL2ES2 gl)
void display(final GL2ES2 gl)
static final String shaderBinPath
Convenient shader code class to use and instantiate vertex or fragment programs.
size_t defaultShaderCustomization(const GL &gl, bool preludeVersion=true, bool addDefaultPrecision=true, bool addDefaultDefines=true)
Default customization of this shader source code.
static ShaderCodeRef create(GLenum type, size_t count, const source_list_t &sources) noexcept
static std::string f(uint32_t v)