28package com.jogamp.opengl.test.junit.jogl.demos.es2;
30import java.nio.FloatBuffer;
32import com.jogamp.opengl.GL;
33import com.jogamp.opengl.GL2ES2;
34import com.jogamp.opengl.GLAutoDrawable;
35import com.jogamp.opengl.GLEventListener;
36import com.jogamp.opengl.GLUniformData;
37import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
39import com.jogamp.opengl.FBObject;
40import com.jogamp.opengl.FBObject.TextureAttachment;
41import com.jogamp.opengl.FBObject.Attachment.Type;
42import com.jogamp.opengl.util.GLArrayDataServer;
43import com.jogamp.opengl.util.PMVMatrix;
44import com.jogamp.opengl.util.glsl.ShaderCode;
45import com.jogamp.opengl.util.glsl.ShaderProgram;
46import com.jogamp.opengl.util.glsl.ShaderState;
51 private final int swapInterval;
52 private volatile int numSamples;
53 private boolean demo0Only;
75 this.swapInterval = swapInterval;
93 public void setMSAA(
final int numSamples) {
94 this.numSamples=numSamples;
96 public int getMSAA() {
return numSamples; }
104 demo0.
init(drawable);
105 demo1.
init(drawable);
108 "shader/bin",
"texture01_xxx",
true);
110 "shader/bin",
"texture02_xxx",
true);
115 sp0.
add(gl, vp0, System.err);
116 sp0.
add(gl, fp0, System.err);
121 st.
uniform(gl, pmvMatrixUniform);
130 final FloatBuffer ib = (FloatBuffer)interleavedVBO.
getBuffer();
132 for(
int i=0; i<4; i++) {
133 ib.put(s_quadVertices, i*3, 3);
134 ib.put(s_quadColors, i*4, 4);
136 ib.put(s_quadTexCoords, i*2, 2);
139 interleavedVBO.
seal(gl,
true);
152 System.err.println(
"**** Init");
153 initFBOs(gl, drawable);
162 throw new InternalError(
"sample size mismatch: \n\t0: "+fbo0+
"\n\t1: "+fbo1);
188 throw new InternalError(
"sample size mismatch: \n\t0: "+fbo0+
"\n\t1: "+fbo1);
212 pmvMatrixUniform =
null;
213 interleavedVBO =
null;
221 System.err.println(
"**** NumSamples: "+fbo0.
getNumSamples()+
" -> "+numSamples);
222 resetFBOs(gl, drawable);
244 fbo0.
use(gl, fbo0Tex);
247 fbo1.
use(gl, fbo1Tex);
272 System.err.println(
"**** Reshape: "+width+
"x"+height);
273 resetFBOs(gl, drawable);
276 demo0.
reshape(drawable, x, y, width, height);
279 demo1.
reshape(drawable, x, y, width, height);
284 pmvMatrix.
glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 10.0f);
290 st.
uniform(gl, pmvMatrixUniform);
295 private static final float[] s_quadVertices = {
301 private static final float[] s_quadColors = {
306 private static final float[] s_quadTexCoords = {
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
Core utility class simplifying usage of framebuffer objects (FBO) with all GLProfiles.
final void attachRenderbuffer(final GL gl, final Attachment.Type atype, final int reqBits)
Attaches one depth, stencil or packed-depth-stencil buffer to this FBO's instance,...
final void bind(final GL gl)
Bind this FBO, i.e.
final TextureAttachment attachTexture2D(final GL gl, final int attachmentPoint, final boolean alpha)
Attaches a Colorbuffer, i.e.
final int getNumSamples()
Returns the number of samples for multisampling (MSAA).
final void destroy(final GL gl)
final void unuse(final GL gl)
Unbind texture, ie bind 'non' texture 0.
final void use(final GL gl, final TextureAttachment ta)
Synchronize the sampling sink and bind the given TextureAttachment, if not null.
final Colorbuffer getSamplingSink()
Return the multisampling Colorbuffer sink, if using multisampling.
final boolean resetSamplingSink(final GL gl)
Manually validates the MSAA sampling sink, if used.
final ColorAttachment attachColorbuffer(final GL gl, final int attachmentPoint, final boolean alpha)
Attaches a newly created and initialized Colorbuffer, i.e.
final void unbind(final GL gl)
Unbind this FBO, i.e.
final boolean reset(final GL gl, int newWidth, int newHeight, int newSamples)
Resets this FBO's instance.
static final int CHOSEN_BITS
Request current context drawable's chosen depth- or stencil-bits; value {@value}.
void init(final GL gl, final int newWidth, final int newHeight, final int newSamples)
Initializes this FBO's instance.
final Colorbuffer getColorbuffer(final int attachmentPoint)
Return the Colorbuffer attachment at attachmentPoint if it is attached to this FBO,...
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void setDemo0Only(final boolean v)
void setDoRotation(final boolean rotate)
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void reshape(final GLAutoDrawable drawable, 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 display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void setMSAA(final int numSamples)
FBOMix2DemosES2(final int swapInterval)
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
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 drawable)
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 setIgnoreFocus(final boolean v)
void setDoRotation(final boolean rotate)
void display(final GLAutoDrawable glad)
Called by the drawable to initiate OpenGL rendering by the client.
void dispose(final GLAutoDrawable glad)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
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 init(final GLAutoDrawable glad)
Called by the drawable immediately after the OpenGL context is initialized.
void seal(final GL gl, final boolean seal)
Convenience method calling seal(boolean) and enableBuffer(GL, boolean).
void enableBuffer(final GL gl, final boolean enable)
Enables the buffer if enable is true, and transfers the data if required.
static GLArrayDataServer createGLSLInterleaved(final int compsPerElement, final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
Create a VBO for GLSL interleaved array data starting with a new created Buffer object with initialEl...
GLArrayDataWrapper addGLSLSubArray(final String name, final int comps, final int vboTarget)
Configure a segment of this GLSL interleaved array (see createGLSLInterleaved(int,...
Buffer getBuffer()
The Buffer holding the data, may be null if a GPU buffer without client bound data.
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,...
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 ownAttribute(final GLArrayData attribute, final boolean own)
Binds or unbinds the GLArrayData lifecycle to this ShaderState.
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.
TextureAttachment getTextureAttachment()
Casts this object to a TextureAttachment reference, see isTextureAttachment().
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...
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.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
boolean isGLcore()
Indicates whether this GL object uses a GL core profile.
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_MULTISAMPLE
Common in ES1, GL2 and GL3.
void glDrawArrays(int mode, int first, int count)
Entry point to C language function: void {@native glDrawArrays}(GLenum mode, GLint first,...
static final int GL_STATIC_DRAW
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_STATI...
static final int GL_TEXTURE_2D
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_2D" with expr...
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...
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
void glEnable(int cap)
Entry point to C language function: void {@native glEnable}(GLenum cap) Part of GL_ES_VERSION_2_0,...
static final int GL_DEPTH_TEST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_TEST" with expr...
void glActiveTexture(int texture)
Entry point to C language function: void {@native glActiveTexture}(GLenum texture) Part of GL_ES_V...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
static final int GL_TRIANGLE_STRIP
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLE_STRIP" with ...
static final int GL_TEXTURE0
GL_ES_VERSION_2_0, GL_VERSION_1_3, GL_VERSION_ES_1_0, GL_ARB_multitexture Alias for: GL_TEXTURE0_ARB ...
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" wit...
static final int GL_ARRAY_BUFFER
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_ARRAY...
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.