28package com.jogamp.opengl.demos.es2;
30import java.nio.FloatBuffer;
32import com.jogamp.opengl.GL;
33import com.jogamp.opengl.GL2ES2;
34import com.jogamp.opengl.GL2GL3;
35import com.jogamp.opengl.GLAutoDrawable;
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLEventListener;
38import com.jogamp.opengl.GLException;
39import com.jogamp.opengl.GLUniformData;
40import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
41import com.jogamp.common.util.VersionUtil;
42import com.jogamp.math.Recti;
43import com.jogamp.newt.event.WindowAdapter;
44import com.jogamp.newt.event.WindowEvent;
45import com.jogamp.newt.opengl.GLWindow;
46import com.jogamp.opengl.demos.util.CommandlineOptions;
47import com.jogamp.opengl.util.Animator;
48import com.jogamp.opengl.util.GLArrayDataServer;
49import com.jogamp.opengl.util.PMVMatrix;
50import com.jogamp.opengl.util.caps.NonFSAAGLCapsChooser;
51import com.jogamp.opengl.util.glsl.ShaderCode;
52import com.jogamp.opengl.util.glsl.ShaderProgram;
53import com.jogamp.opengl.util.glsl.ShaderState;
68 private final int swapInterval;
81 this.swapInterval = swapInterval;
97 "shader/bin",
"texture01_xxx",
true);
99 "shader/bin",
"texture01_customtex",
true);
104 sp0.
add(gl, vp0, System.err);
105 sp0.
add(gl, fp0, System.err);
110 st.
uniform(gl, pmvMatrixUniform);
119 final FloatBuffer ib = (FloatBuffer)interleavedVBO.
getBuffer();
121 for(
int i=0; i<4; i++) {
122 ib.put(s_quadVertices, i*3, 3);
123 ib.put(s_quadColors, i*4, 4);
125 ib.put(s_quadTexCoords, i*2, 2);
128 interleavedVBO.
seal(gl,
true);
141 initFBO(gl, viewport.width()/2, viewport.height());
147 private int fboID, fboWidth, fboHeight;
148 private int colorTexID, depthTexID;
149 private int depthRenderID;
150 private final boolean useDepthTexture =
true;
151 private final int colorAttachmentPoint = 0;
153 private void initTexParam(
final GL2ES2 gl) {
159 private void initFBO(
final GL2ES2 gl,
final int width,
final int height) {
161 final int tmp[] = { 0 };
171 if (0 == colorTexID) {
175 if( useDepthTexture ) {
178 if (0 == depthTexID) {
179 throw new GLException(
"XXX");
183 depthRenderID = tmp[0];
184 if (0 == depthRenderID) {
185 throw new GLException(
"XXX");
192 throw new GLException(
"XXX");
198 final boolean alpha=
true;
199 final int iFormat, dataFormat, dataType;
201 iFormat = alpha ? GL.GL_RGBA8 : GL.GL_RGB8;
202 dataFormat = alpha ? GL.GL_RGBA : GL.GL_RGB;
203 dataType = GL.GL_UNSIGNED_BYTE;
205 iFormat = alpha ? GL.GL_RGBA : GL.GL_RGB;
206 dataFormat = alpha ? GL.GL_RGBA : GL.GL_RGB;
207 dataType = GL.GL_UNSIGNED_BYTE;
209 iFormat = alpha ? GL.GL_RGBA8 : GL.GL_RGB8;
212 dataFormat = alpha ? GL.GL_BGRA : GL.GL_RGB;
213 dataType = alpha ? GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV : GL.GL_UNSIGNED_BYTE;
216 gl.
glTexImage2D(GL.GL_TEXTURE_2D, 0, iFormat, width, height, 0, dataFormat, dataType,
null);
219 gl.
glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0 + colorAttachmentPoint, GL.GL_TEXTURE_2D, colorTexID, 0);
222 if( useDepthTexture ) {
224 gl.
glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_DEPTH_COMPONENT32, width, height, 0, GL2ES2.GL_DEPTH_COMPONENT, GL.GL_FLOAT,
null);
235 if( GL.GL_FRAMEBUFFER_COMPLETE != fboStatus ) {
236 throw new GLException(
"FBO not complete, but 0x"+Integer.toHexString(fboStatus));
241 private void disposeFBO(
final GL gl) {
242 gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fboID);
243 gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0 + colorAttachmentPoint, GL.GL_TEXTURE_2D, 0, 0);
244 if( useDepthTexture ) {
245 gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_TEXTURE_2D, 0, 0);
247 gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER, 0);
249 gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
251 final int tmp[] = { colorTexID };
252 gl.glDeleteTextures(1, tmp, 0);
254 if( useDepthTexture ) {
255 final int tmp[] = { depthTexID };
256 gl.glDeleteTextures(1, tmp, 0);
258 final int tmp[] = { depthRenderID };
259 gl.glDeleteRenderbuffers(1, tmp, 0);
267 gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0);
269 final int tmp[] = { fboID };
270 gl.glDeleteFramebuffers(1, tmp, 0);
274 private void resetFBOs(
final GL2ES2 gl,
final int width,
final int height) {
275 if( fboWidth != width || fboHeight != height ) {
277 initFBO(gl, width, height);
289 pmvMatrixUniform =
null;
290 interleavedVBO =
null;
302 gl.
glViewport(viewport.x(), viewport.y(), fboWidth, fboHeight);
328 gl.
glViewport(viewport.x(), viewport.y(), viewport.width(), viewport.height());
332 gl.
glViewport(viewport.x()+fboWidth, viewport.y(), fboWidth, fboHeight);
352 gl.
glViewport(viewport.x(), viewport.y(), viewport.width(), viewport.height());
361 viewport.
set(x, y, width, height);
363 System.err.println(
"**** Reshape.Reset: "+width+
"x"+height);
364 resetFBOs(gl, width/2, height);
366 gl.
glViewport(viewport.x(), viewport.y(), fboWidth, fboHeight);
368 demo.
reshape(drawable, x, y, fboWidth, fboHeight);
370 gl.
glViewport(viewport.x(), viewport.y(), viewport.width(), viewport.height());
376 pmvMatrix.
glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 10.0f);
382 st.
uniform(gl, pmvMatrixUniform);
387 private static final float[] s_quadVertices = {
393 private static final float[] s_quadColors = {
398 private static final float[] s_quadTexCoords = {
405 public static void main(
final String[] args) {
408 System.err.println(options);
409 System.err.println(VersionUtil.getPlatformInfo());
413 System.out.println(
"Requested: " + reqCaps);
425 animator.
add(window);
Rectangle with x, y, width and height integer components.
void set(final Recti o)
this = o, returns this.
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void setTitle(final String title)
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
CapabilitiesChooser setCapabilitiesChooser(final CapabilitiesChooser chooser)
Set the CapabilitiesChooser to help determine the native visual type.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
FBO demo using a texture attachment for color- and depth-buffer.
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
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.
static void main(final String[] args)
GearsFBO01(final int swapInterval)
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.
GLCapabilities getGLCaps()
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
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.
Custom GLCapabilitiesChooser, filtering out all full screen anti-aliasing (FSAA, multisample) capabil...
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.
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.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
boolean isGLES()
Indicates whether this GL object conforms to one of the OpenGL ES profiles, see isGLES1(),...
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.
boolean isGLES3()
Indicates whether this GL object conforms to the OpenGL ES ≥ 3.0 profile.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
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.
void dispose(GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void display(GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void init(GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
Called by the drawable during the first repaint after the component has been resized.
void glFramebufferTexture2D(int target, int attachment, int textarget, int texture, int level)
Entry point to C language function: void {@native glFramebufferTexture2D}(GLenum target,...
static final int GL_TEXTURE_MAG_FILTER
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_MAG_FILTER" with expression '...
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_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_2D" with expression '0x0DE1',...
static final int GL_TEXTURE_WRAP_S
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_WRAP_S" with expression '0x28...
void glBindTexture(int target, int texture)
Entry point to C language function: void {@native glBindTexture}(GLenum target, GLuint texture) Pa...
static final int GL_FLOAT
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FLOAT" with expression '0x1406',...
void glGenTextures(int n, IntBuffer textures)
Entry point to C language function: void {@native glGenTextures}(GLsizei n, GLuint * textures) Par...
int glCheckFramebufferStatus(int target)
Entry point to C language function: GLenum {@native glCheckFramebufferStatus}(GLenum target) Part ...
void glRenderbufferStorage(int target, int internalformat, int width, int height)
Entry point to C language function: void {@native glRenderbufferStorage}(GLenum target,...
void glGenFramebuffers(int n, IntBuffer framebuffers)
Entry point to C language function: void {@native glGenFramebuffers}(GLsizei n, GLuint * framebuffer...
static final int GL_TEXTURE_MIN_FILTER
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_MIN_FILTER" with expression '...
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" with expression '0x...
void glBindRenderbuffer(int target, int renderbuffer)
Entry point to C language function: void {@native glBindRenderbuffer}(GLenum target,...
void glFramebufferRenderbuffer(int target, int attachment, int renderbuffertarget, int renderbuffer)
Entry point to C language function: void {@native glFramebufferRenderbuffer}(GLenum target,...
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_TEXTURE_WRAP_T
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_WRAP_T" with expression '0x28...
static final int GL_DEPTH_TEST
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_TEST" with expression '0x0B71',...
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_...
void glTexParameteri(int target, int pname, int param)
Entry point to C language function: void {@native glTexParameteri}(GLenum target,...
static final int GL_TRIANGLE_STRIP
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLE_STRIP" with expression '0x00...
void glBindFramebuffer(int target, int framebuffer)
Entry point to C language function: void {@native glBindFramebuffer}(GLenum target,...
static final int GL_NEAREST
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_NEAREST" with expression '0x2600',...
void glViewport(int x, int y, int width, int height)
Entry point to C language function: void {@native glViewport}(GLint x, GLint y, GLsizei width,...
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 ...
void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels)
Entry point to C language function: void {@native glTexImage2D}(GLenum target, GLint level,...
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" with expression '0x...
static final int GL_CLAMP_TO_EDGE
GL_ES_VERSION_2_0, GL_VERSION_1_2, GL_VERSION_ES_1_0, GL_SGIS_texture_edge_clamp Alias for: GL_CLAMP_...
void glGenRenderbuffers(int n, IntBuffer renderbuffers)
Entry point to C language function: void {@native glGenRenderbuffers}(GLsizei n, GLuint * renderbuff...
static final int GL_FRAMEBUFFER
GL_ES_VERSION_2_0, GL_ARB_framebuffer_object, GL_VERSION_3_0, GL_OES_framebuffer_object,...
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.