28package com.jogamp.opengl.test.junit.jogl.demos.gl3;
30import java.io.IOException;
31import java.io.InputStream;
32import java.net.URLConnection;
33import java.nio.FloatBuffer;
35import com.jogamp.opengl.GL;
36import com.jogamp.opengl.GL2ES2;
37import com.jogamp.opengl.GL3;
38import com.jogamp.opengl.GL3ES3;
39import com.jogamp.opengl.GLAutoDrawable;
40import com.jogamp.opengl.GLEventListener;
41import com.jogamp.opengl.GLException;
42import com.jogamp.opengl.GLUniformData;
43import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
45import com.jogamp.common.util.IOUtil;
46import com.jogamp.opengl.util.GLArrayDataServer;
47import com.jogamp.opengl.util.PMVMatrix;
48import com.jogamp.opengl.util.glsl.ShaderCode;
49import com.jogamp.opengl.util.glsl.ShaderProgram;
50import com.jogamp.opengl.util.glsl.ShaderState;
51import com.jogamp.opengl.util.glsl.ShaderUtil;
52import com.jogamp.opengl.util.texture.Texture;
53import com.jogamp.opengl.util.texture.TextureCoords;
54import com.jogamp.opengl.util.texture.TextureData;
55import com.jogamp.opengl.util.texture.TextureIO;
72 private final int geomShader;
79 static final String shaderBasename =
"texture01_xxx";
80 static final String[] geomShaderBaseNames =
new String[] {
"passthrough01_xxx",
"flipXYZ01_xxx" };
83 this.geomShader = geomShader;
90 System.err.println(
"Init - START - useGeomShader "+geomShader+
" -> "+geomShaderBaseNames[geomShader]);
99 throw new RuntimeException(
"GL object not a GL3 core compatible profile: "+gl);
102 throw new RuntimeException(
"GL object not >= 3.2, i.e. no geometry shader support.: "+gl);
111 "shader",
"shader/bin", shaderBasename,
true);
113 "shader",
"shader/bin", geomShaderBaseNames[geomShader],
true);
115 "shader",
"shader/bin", shaderBasename,
true);
121 sp.
add(gl, vs, System.err);
122 sp.
add(gl, gs, System.err);
123 sp.
add(gl, fs, System.err);
124 if(!sp.
link(gl, System.err)) {
125 throw new GLException(
"Couldn't link program: "+sp);
140 st.
uniform(gl, pmvMatrixUniform);
143 if(!st.
uniform(gl, pmvMatrixUniform)) {
144 throw new GLException(
"Error setting PMVMatrix in shader: "+st);
147 throw new GLException(
"Error setting mgl_ActiveTexture in shader: "+st);
151 texture = createTestTexture(gl);
152 }
catch (
final IOException e) {
153 throw new RuntimeException(e);
155 if(
null == texture) {
156 throw new RuntimeException(
"Could not load test texture");
165 s_triTexCoords[i++] = tc.left(); s_triTexCoords[i++] = tc.top();
166 s_triTexCoords[i++] = tc.left(); s_triTexCoords[i++] = tc.bottom();
167 s_triTexCoords[i++] = tc.right(); s_triTexCoords[i++] = tc.bottom();
168 s_triTexCoords[i++] = tc.left(); s_triTexCoords[i++] = tc.top();
169 s_triTexCoords[i++] = tc.right(); s_triTexCoords[i++] = tc.top();
170 s_triTexCoords[i++] = tc.right(); s_triTexCoords[i++] = tc.bottom();
179 final FloatBuffer ib = (FloatBuffer)interleavedVBO.
getBuffer();
181 for(
int i=0; i<6; i++) {
182 ib.put(s_triVertices, i*2, 2);
183 ib.put(s_triColors, i*4, 4);
184 ib.put(s_triTexCoords, i*2, 2);
187 interleavedVBO.
seal(gl,
true);
196 private Texture createTestTexture(
final GL3 gl)
throws IOException {
197 final URLConnection urlConn = IOUtil.getResource(
"../../util/texture/test-ntscN_3-01-160x90.png", this.getClass().getClassLoader(), this.getClass());
198 if(
null == urlConn) {
return null; }
199 final InputStream istream = urlConn.getInputStream();
200 if(
null == istream) {
return null; }
201 final TextureData texData = TextureIO.newTextureData(gl.getGLProfile(), istream,
false , TextureIO.PNG);
202 final Texture res = TextureIO.newTexture(gl, texData);
216 pmvMatrixUniform =
null;
235 pmvMatrix.
glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 10.0f);
241 st.
uniform(gl, pmvMatrixUniform);
268 private static final float[] s_triVertices = {
276 private static final float[] s_triColors = {
284 private static final float[] s_triTexCoords = {
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
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 Geometry ShaderCode test case using OpenGL 3.2 core profile features only.
GeomShader01TextureGL3(final int geomShader)
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
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 dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
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 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 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 boolean isGeometryShaderSupported(final GL _gl)
Returns true if GeometryShader is supported, i.e.
Specifies texture coordinates for a rectangular area of a texture.
Represents an OpenGL texture object.
TextureCoords getImageTexCoords()
Returns the set of texture coordinates corresponding to the entire image.
void bind(final GL gl)
Binds this texture to the given GL context.
void disable(final GL gl)
Disables this texture's target (e.g., GL_TEXTURE_2D) in the given GL state.
void enable(final GL gl)
Enables this texture's target (e.g., GL_TEXTURE_2D) in the given GL context's state.
void destroy(final GL gl)
Destroys and nulls the underlying native texture used by this Texture instance if owned,...
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_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...
static final int GL_GEOMETRY_SHADER
GL_ES_VERSION_3_2, GL_VERSION_3_2, GL_OES_geometry_shader, GL_EXT_geometry_shader4,...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
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.
boolean isGL3()
Indicates whether this GL object conforms to the OpenGL ≥ 3.1 core profile.
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 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_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...
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
String glGetString(int name)
Entry point to C language function: const GLubyte * {@native glGetString}(GLenum name) Part of GL_...
void glActiveTexture(int texture)
Entry point to C language function: void {@native glActiveTexture}(GLenum texture) Part of GL_ES_V...
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_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.