29package com.jogamp.opengl.test.junit.jogl.util;
31import com.jogamp.opengl.GL;
32import com.jogamp.opengl.GL2ES2;
33import com.jogamp.opengl.GLAutoDrawable;
34import com.jogamp.opengl.GLEventListener;
35import com.jogamp.opengl.GLException;
36import com.jogamp.opengl.GLUniformData;
37import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
39import com.jogamp.opengl.util.ImmModeSink;
40import com.jogamp.opengl.util.PMVMatrix;
41import com.jogamp.opengl.util.glsl.ShaderCode;
42import com.jogamp.opengl.util.glsl.ShaderProgram;
43import com.jogamp.opengl.util.glsl.ShaderState;
49 private final int glBufferUsage;
61 glBufferUsage = useVBO ? GL.GL_STATIC_DRAW : 0;
74 "../demos/es2/shader",
"../demos/es2/shader/bin",
"mgl_default_xxx",
true);
76 "../demos/es2/shader",
"../demos/es2/shader/bin",
"mgl_default_xxx",
true);
81 sp.
add(gl, vp0, System.err);
82 sp.
add(gl, fp0, System.err);
86 if(!sp.
link(gl, System.err)) {
87 throw new GLException(
"Could not link program: "+sp);
95 st.
uniform(gl, pmvMatrixUniform);
98 throw new GLException(
"Could not find location for uniform: "+pmvMatrixUniform+
", "+sp);
120 final int numSteps = 20;
121 final double increment = Math.PI / numSteps;
122 final double radius = 1;
124 for (
int i = numSteps - 1; i >= 0; i--) {
125 ims.
glVertex3f((
float) (radius * Math.cos(i * increment)),
126 (
float) (radius * Math.sin(i * increment)),
129 ims.
glVertex3f((
float) (-1.0 * radius * Math.cos(i * increment)),
130 (
float) (-1.0 * radius * Math.sin(i * increment)),
134 ims.
glEnd(gl,
false);
173 System.err.println(
"reshape ..");
179 pmvMatrix.
glOrthof( 0.0f, width, 0.0f, height, -1, 1 );
186 st.
uniform(gl, pmvMatrixUniform);
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
DemoGL2ES2ImmModeSink(final boolean useVBO, final boolean useShaderState)
void reshape(final GLAutoDrawable glad, final int x, final int y, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
void dispose(final GLAutoDrawable glad)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void init(final GLAutoDrawable glad)
Called by the drawable immediately after the OpenGL context is initialized.
void displayChanged(final GLAutoDrawable drawable, final boolean modeChanged, final boolean deviceChanged)
final void glVertex2f(final float x, final float y)
final void glVertex3f(final float x, final float y, final float z)
void destroy(final GL gl)
static ImmModeSink createGLSL(final int initialElementCount, final int vComps, final int vDataType, final int cComps, final int cDataType, final int nComps, final int nDataType, final int tComps, final int tDataType, final int glBufferUsage, final ShaderState st)
Uses a GL2ES2 GLSL shader immediate mode sink, utilizing the given ShaderState.
final void glColor4f(final float x, final float y, final float z, final float a)
final void glColor3f(final float x, final float y, final float z)
final void glEnd(final GL gl)
PMVMatrix implements a subset of the fixed function pipeline GLMatrixFunc using PMVMatrix4f.
final void glMatrixMode(final int matrixName)
Sets the current matrix mode.
final void glOrthof(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)
Multiply the current matrix with the orthogonal matrix.
final void glLoadIdentity()
Load the current matrix with the identity matrix.
Convenient shader code class to use and instantiate vertex or fragment programs.
final int defaultShaderCustomization(final GL2ES2 gl, final boolean preludeVersion, final boolean addDefaultPrecision)
Default customization of this shader source code.
static ShaderCode create(final GL2ES2 gl, final int type, final int count, final Class<?> context, final String[] sourceFiles, final boolean mutableStringBuilder)
Creates a complete ShaderCode object while reading all shader source of sourceFiles,...
int program()
Returns the shader program name, which is non zero if valid.
synchronized void useProgram(final GL2ES2 gl, boolean on)
synchronized boolean link(final GL2ES2 gl, final PrintStream verboseOut)
Links the shader code to the program.
synchronized void add(final ShaderCode shaderCode)
Adds a new shader to this program.
ShaderState allows to sharing data between shader programs, while updating the attribute and uniform ...
void setVerbose(final boolean v)
synchronized void useProgram(final GL2ES2 gl, final boolean on)
Turns the shader program on or off.
synchronized boolean attachShaderProgram(final GL2ES2 gl, final ShaderProgram prog, final boolean enable)
Attach or switch a shader program.
synchronized void destroy(final GL2ES2 gl)
Calls release(gl, true, true, true).
boolean uniform(final GL2ES2 gl, final GLUniformData data)
Set the uniform data, if it's location is valid, i.e.
void ownUniform(final GLUniformData uniform)
Bind the GLUniform lifecycle to this ShaderState.
FloatBuffer getSyncFloats()
Return the FloatBuffer after synchronizing it w/ the underlying getMatrices().
static final int GL_VERTEX_SHADER
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_EXT_vertex_shader, GL_ARB_vertex_shader Alias for: GL_VERTEX_SH...
void glUniform(GLUniformData data)
void glUseProgram(int program)
Entry point to C language function: void {@native glUseProgram}(GLuint program) Part of GL_ES_VERS...
static final int GL_FRAGMENT_SHADER
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_ATI_fragment_shader, GL_ARB_fragment_shader Alias for: GL_FRAGM...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
static final int GL_TRIANGLES
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLES" with expre...
static final int GL_VERSION
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VERSION" with express...
static final int GL_FLOAT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FLOAT" with expressio...
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" wit...
String glGetString(int name)
Entry point to C language function: const GLubyte * {@native glGetString}(GLenum name) Part of GL_...
static final int GL_RENDERER
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RENDERER" with expres...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
static final int GL_VENDOR
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VENDOR" with expressi...
static final int GL_LINES
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_LINES" with expressio...
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
static final int GL_MODELVIEW
Matrix mode modelview.