28package com.jogamp.opengl.demos.gl4es31;
30import com.jogamp.common.util.VersionUtil;
31import com.jogamp.newt.event.WindowAdapter;
32import com.jogamp.newt.event.WindowEvent;
33import com.jogamp.newt.opengl.GLWindow;
34import com.jogamp.opengl.GL;
35import com.jogamp.opengl.GL2ES2;
36import com.jogamp.opengl.GL2ES3;
37import com.jogamp.opengl.GL3;
38import com.jogamp.opengl.GL3ES3;
39import com.jogamp.opengl.GLAutoDrawable;
40import com.jogamp.opengl.GLCapabilities;
41import com.jogamp.opengl.GLEventListener;
42import com.jogamp.opengl.GLException;
43import com.jogamp.opengl.GLUniformData;
44import com.jogamp.opengl.demos.util.CommandlineOptions;
45import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
46import com.jogamp.opengl.util.Animator;
47import com.jogamp.opengl.util.GLBuffers;
48import com.jogamp.opengl.util.PMVMatrix;
49import com.jogamp.opengl.util.caps.NonFSAAGLCapsChooser;
50import com.jogamp.opengl.util.glsl.ShaderCode;
51import com.jogamp.opengl.util.glsl.ShaderProgram;
52import com.jogamp.opengl.util.glsl.ShaderState;
53import com.jogamp.opengl.util.glsl.ShaderUtil;
65 private boolean usesPMVMatrix;
67 private int iLocVertex = -1, iLocColor = -1;
70 private static final int CompPerElem = 3;
71 private static final int BytesPerElem = CompPerElem * FloatByteSize;
72 private static final int ByteStride = 2 * CompPerElem * FloatByteSize;
73 private static final String shaderBasename =
"compute01_xxx";
78 private static final int GROUP_SIZE_HEIGHT = 8, GROUP_SIZE_WIDTH = 8;
79 private static final int NUM_VERTS_H = 16, NUM_VERTS_V = 16;
94 throw new RuntimeException(
"GL object not >= 4.3 or ES >= 3.1, i.e. no compute shader support.: "+gl);
100 final int[] tmp =
new int[1];
109 System.err.println(
"iVBO: "+iVBO+
": "+NUM_VERTS_H+
"x"+NUM_VERTS_V);
113 "shader",
"shader/bin", shaderBasename,
true);
117 sp.
add(gl, cs, System.err);
118 if(!sp.
link(gl, System.err)) {
119 throw new GLException(
"Couldn't link program: "+sp);
125 if(!stComp.
uniform(gl, uRadius)) {
126 throw new GLException(
"Error setting radius in shader: "+uRadius);
128 System.err.println(
"uRadius: "+uRadius);
132 usesPMVMatrix =
true;
135 "shader",
"shader/bin", shaderBasename,
true);
137 "shader",
"shader/bin", shaderBasename,
true);
142 sp.
add(gl, vs, System.err);
143 sp.
add(gl, fs, System.err);
144 if(!sp.
link(gl, System.err)) {
145 throw new GLException(
"Couldn't link program: "+sp);
156 if( usesPMVMatrix ) {
159 if(!stGfx.
uniform(gl, pmvMatrixUniform)) {
160 throw new GLException(
"Error setting PMVMatrix in shader: "+stGfx);
164 if( iLocVertex < 0 ) {
165 throw new GLException(
"Couldn't find gca_Vertex: "+sp);
168 if( iLocColor < 0 ) {
169 throw new GLException(
"Couldn't find gca_Color: "+sp);
171 System.err.println(
"iLocVertex: "+iLocVertex);
172 System.err.println(
"iLocColor: "+iLocColor);
193 pmvMatrixUniform =
null;
199 final int[] tmp =
new int[] { iVBO } ;
214 pmvMatrix.
glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 10.0f);
220 if( usesPMVMatrix ) {
221 stGfx.
uniform(gl, pmvMatrixUniform);
227 float radius_dir = -1.0f;
243 }
else if( r < 0.01f ){
246 r += radius_dir * 0.004f;
252 final int gIndexBufferBinding = 0;
260 gl.
glDispatchCompute((NUM_VERTS_H % GROUP_SIZE_WIDTH + NUM_VERTS_H) / GROUP_SIZE_WIDTH,
261 (NUM_VERTS_V % GROUP_SIZE_HEIGHT + NUM_VERTS_V) / GROUP_SIZE_HEIGHT,
290 public static void main(
final String[] args) {
293 System.err.println(options);
294 System.err.println(VersionUtil.getPlatformInfo());
297 System.out.println(
"Requested: " + reqCaps);
310 animator.
add(window);
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.
final GLRendererQuirks getRendererQuirks()
Returns the instance of GLRendererQuirks, allowing one to determine workarounds.
final String getGLVersion()
Returns a valid OpenGL version string, ie
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
final StringBuilder toString(StringBuilder sb)
JOGL Compute ShaderCode demo using OpenGL 4.3 or ES 3.1 core profile features.
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
static void main(final String[] args)
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.
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.
Utility routines for dealing with direct buffers.
static final int sizeOfGLType(final int glType)
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,...
int program()
Returns the shader program name, which is non zero if valid.
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 ...
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 boolean isComputeShaderSupported(final GL _gl)
Returns true if ComputeShader is supported, i.e.
void glVertexAttribPointer(int index, int size, int type, boolean normalized, int stride, long pointer_buffer_offset)
Entry point to C language function: void {@native glVertexAttribPointer}(GLuint index,...
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 glEnableVertexAttribArray(int index)
Entry point to C language function: void {@native glEnableVertexAttribArray}(GLuint index) Part of...
int glGetAttribLocation(int program, String name)
Entry point to C language function: GLint {@native glGetAttribLocation}(GLuint program,...
static final int GL_SHADING_LANGUAGE_VERSION
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_ARB_shading_language_100 Alias for: GL_SHADING_LANGUAGE_VERSION...
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...
void glMemoryBarrier(int barriers)
Entry point to C language function: void {@native glMemoryBarrier}(GLbitfield barriers) Part of GL...
static final int GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT
GL_ARB_shader_image_load_store, GL_VERSION_4_2, GL_ES_VERSION_3_1, GL_EXT_shader_image_load_store Ali...
void glBindBufferBase(int target, int index, int buffer)
Entry point to C language function: void {@native glBindBufferBase}(GLenum target,...
static final int GL_COMPUTE_SHADER
GL_ARB_compute_shader, GL_ES_VERSION_3_1, GL_VERSION_4_3 Define "GL_COMPUTE_SHADER" with expression '...
static final int GL_SHADER_STORAGE_BUFFER
GL_ES_VERSION_3_1, GL_VERSION_4_3, GL_ARB_shader_storage_buffer_object Define "GL_SHADER_STORAGE_BUFF...
void glDispatchCompute(int num_groups_x, int num_groups_y, int num_groups_z)
Entry point to C language function: void {@native glDispatchCompute}(GLuint num_groups_x,...
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 hasGLSL()
Indicates whether this GL object supports GLSL.
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
GL3 getGL3()
Casts this object to the GL3 interface.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
GLContext getContext()
Returns the GLContext associated which this GL object.
boolean isFunctionAvailable(String glFunctionName)
Returns true if the specified OpenGL core- or extension-function can be used successfully through thi...
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void glGenBuffers(int n, IntBuffer buffers)
Entry point to C language function: void {@native glGenBuffers}(GLsizei n, GLuint * buffers) Part ...
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_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...
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
static final int GL_LINE_STRIP
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_LINE_STRIP" with expr...
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_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...
void glDeleteBuffers(int n, IntBuffer buffers)
Entry point to C language function: void {@native glDeleteBuffers}(GLsizei n, const GLuint * buffers...
void glBindBuffer(int target, int buffer)
Entry point to C language function: void {@native glBindBuffer}(GLenum target, GLuint buffer) Part...
void glBufferData(int target, long size, Buffer data, int usage)
Entry point to C language function: void {@native glBufferData}(GLenum target, GLsizeiptr size,...
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.