29package com.jogamp.opengl.demos.es2;
31import java.nio.FloatBuffer;
33import com.jogamp.common.os.Platform;
34import com.jogamp.math.FloatUtil;
35import com.jogamp.math.Recti;
36import com.jogamp.math.Vec3f;
37import com.jogamp.opengl.GL;
38import com.jogamp.opengl.GL2ES2;
39import com.jogamp.opengl.GLAutoDrawable;
40import com.jogamp.opengl.GLES2;
41import com.jogamp.opengl.GLEventListener;
42import com.jogamp.opengl.GLException;
43import com.jogamp.opengl.GLExtensions;
44import com.jogamp.opengl.GLUniformData;
45import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
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.texture.Texture;
52import com.jogamp.opengl.util.texture.TextureCoords;
53import com.jogamp.opengl.util.texture.TextureSequence;
54import com.jogamp.opengl.util.texture.TextureSequence.TextureFrame;
65 private final boolean texSeqShared;
70 private float zrot = 0f;
71 private final boolean orthoProjection;
72 private float nearPlaneNormalized;
76 private float alpha = 1.0f;
78 private boolean useOriginalScale =
false;
79 private float[] verts =
null;
83 this.texSeq = texSource;
84 this.texSeqShared = texSeqShared;
85 this.orthoProjection = orthoProjection;
89 public void setZoom(
final float zoom) { this.zoom = zoom; }
92 public boolean hasEffect(
final int e) {
return 0 != ( effects & e ) ; }
102 private static final String shaderBasename =
"texsequence_xxx";
103 private static final String myTextureLookupName =
"myTexture2D";
105 private void initShader(
final GL2ES2 gl) {
108 "shader",
"shader/bin", shaderBasename,
true);
110 "shader",
"shader/bin", shaderBasename,
true);
112 boolean preludeGLSLVersion =
true;
117 if( Platform.OSType.ANDROID == Platform.getOSType() && gl.
isGLES3() ) {
121 preludeGLSLVersion =
false;
134 final StringBuilder sFpIns =
new StringBuilder();
140 final ShaderProgram sp =
new ShaderProgram();
143 if(!sp.link(gl, System.err)) {
144 throw new GLException(
"Couldn't link program: "+sp);
148 st =
new ShaderState();
155 throw new InternalError(
"texSeq null");
159 if(
null == frame ) {
171 reshapePMV(viewPort.width(), viewPort.height());
173 if(!st.
uniform(gl, pmvMatrixUniform)) {
174 throw new GLException(
"Error setting PMVMatrix in shader: "+st);
177 throw new GLException(
"Error setting mgl_ActiveTexture in shader: "+st);
184 final float mAspect = mWidth/mHeight;
185 System.err.println(
"XXX0: mov aspect: "+mAspect);
187 if(orthoProjection) {
188 if(useOriginalScale && mWidth < dWidth && mHeight < dHeight) {
189 xs = mWidth/2f; ys = xs / mAspect;
191 xs = dWidth/2f; ys = xs / mAspect;
194 if(useOriginalScale && mWidth < dWidth && mHeight < dHeight) {
195 xs = mAspect * ( mWidth / dWidth ) ; ys = xs / mAspect ;
197 xs = mAspect; ys = 1f;
200 verts =
new float[] { -1f*xs, -1f*ys, 0f,
204 System.err.println(
"XXX0: pixel LB: "+verts[0]+
", "+verts[1]+
", "+verts[2]);
205 System.err.println(
"XXX0: pixel RT: "+verts[3]+
", "+verts[4]+
", "+verts[5]);
208 pmvMatrix.
mapObjToWin(
new Vec3f(verts[0], verts[1], verts[2]), viewPort, winLB);
209 pmvMatrix.
mapObjToWin(
new Vec3f(verts[3], verts[4], verts[5]), viewPort, winRT);
210 System.err.println(
"XXX0: win LB: "+winLB);
211 System.err.println(
"XXX0: win RT: "+winRT);
230 System.out.println(
"iVBO: "+interleavedVBO);
231 System.out.println(st);
235 final float ss = 1f, ts = 1f;
236 final boolean wasEnabled = interleavedVBO.
enabled();
237 interleavedVBO.
seal(gl,
false);
240 final FloatBuffer ib = (FloatBuffer)interleavedVBO.
getBuffer();
242 System.err.println(
"XXX0: "+tc);
247 ib.put(verts[0]); ib.put(verts[1]); ib.put(verts[2]);
249 ib.put( 0); ib.put( 0); ib.put( 0); ib.put(alpha);
251 ib.put( 1); ib.put( 1); ib.put( 1); ib.put(alpha);
253 ib.put( tc.left() *ss); ib.put( tc.bottom() *ts);
256 ib.put(verts[3]); ib.put(verts[1]); ib.put(verts[2]);
258 ib.put( 0); ib.put( 0); ib.put( 0); ib.put(alpha);
260 ib.put( 1); ib.put( 1); ib.put( 1); ib.put(alpha);
262 ib.put( tc.right() *ss); ib.put( tc.bottom() *ts);
265 ib.put(verts[0]); ib.put(verts[4]); ib.put(verts[2]);
266 ib.put( 1); ib.put( 1); ib.put( 1); ib.put(alpha);
267 ib.put( tc.left() *ss); ib.put( tc.top() *ts);
270 ib.put(verts[3]); ib.put(verts[4]); ib.put(verts[2]);
271 ib.put( 1); ib.put( 1); ib.put( 1); ib.put(alpha);
272 ib.put( tc.right() *ss); ib.put( tc.top() *ts);
274 interleavedVBO.
seal(gl,
true);
285 reshapePMV(width, height);
287 st.
uniform(gl, pmvMatrixUniform);
291 System.out.println(
"pR "+texSeq);
294 private final float zNear = 1f;
295 private final float zFar = 10f;
297 private void reshapePMV(
final int width,
final int height) {
300 if(orthoProjection) {
301 final float fw = width / 2f;
302 final float fh = height/ 2f;
303 pmvMatrix.
glOrthof(-fw, fw, -fh, fh, -1.0f, 1.0f);
304 nearPlaneNormalized = 0f;
307 nearPlaneNormalized = 1f/(10f-1f);
309 System.err.println(
"XXX0: Perspective nearPlaneNormalized: "+nearPlaneNormalized);
318 if(
null == texSeq) {
return; }
319 disposeImpl(drawable,
true);
321 private void disposeImpl(
final GLAutoDrawable drawable,
final boolean disposeTexSeq) {
322 if( disposeTexSeq ) {
325 pmvMatrixUniform =
null;
336 if(
null == texSeq) {
return; }
355 st.
uniform(gl, pmvMatrixUniform);
359 final TextureSequence.TextureFrame texFrame;
365 if(
null != texFrame) {
366 tex = texFrame.getTexture();
Basic Float math utility functions.
static final float QUARTER_PI
The value PI/4, i.e.
Rectangle with x, y, width and height integer components.
3D Vector based upon three float components.
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
final boolean mapObjToWin(final Vec3f objPos, final Recti viewport, final Vec3f winPos)
Map object coordinates to window coordinates.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Class holding OpenGL extension strings, commonly used by JOGL's implementation.
static final String OES_EGL_image_external
Simple planar movie player w/ orthogonal 1:1 projection.
static final int EFFECT_GRADIENT_BOTTOM2TOP
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void setTransparency(final float alpha)
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
static final int EFFECT_NORMAL
void setZRotation(final float zrot)
void updateInterleavedVBO(final GL gl, final Texture tex)
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
boolean hasEffect(final int e)
void setUseOriginalScale(final boolean v)
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 setZoom(final float zoom)
void setEffects(final int e)
TextureSequenceES2(final TextureSequence texSource, final boolean texSeqShared, final boolean orthoProjection, final float zoom0)
static final int EFFECT_TRANSPARENT
void seal(final GL gl, final boolean seal)
Convenience method calling seal(boolean) and enableBuffer(GL, boolean).
void rewind()
Rewinds this buffer.
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 glTranslatef(final float x, final float y, final float z)
Translate the current matrix.
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 gluPerspective(final float fovy_rad, final float aspect, final float zNear, final float zFar)
Multiply the current matrix with the perspective/frustum matrix.
final void glRotatef(final float ang_deg, final float x, final float y, final float z)
Rotate the current 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.
final int addGLSLVersion(final GL2ES2 gl)
Add GLSL version at the head 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 replaceInShaderSource(final String oldName, final String newName)
Replaces oldName with newName in all shader sources.
final int addDefaultShaderPrecision(final GL2ES2 gl, int pos)
Adds default precision to source code at given position if required, i.e.
int insertShaderSource(final int shaderIdx, final String tag, final int fromIndex, final CharSequence data)
Adds data after the line containing tag.
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.
Specifies texture coordinates for a rectangular area of a texture.
Texture holder interface, maybe specialized by implementation to associated related data.
final Texture getTexture()
Represents an OpenGL texture object.
int getImageHeight()
Returns the height of the image contained within this texture.
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.
boolean getMustFlipVertically()
Indicates whether this texture's texture coordinates must be flipped vertically in order to properly ...
void disable(final GL gl)
Disables this texture's target (e.g., GL_TEXTURE_2D) in the given GL state.
float getAspectRatio()
Returns the original aspect ratio of the image, defined as (image width) / (image height),...
void enable(final GL gl)
Enables this texture's target (e.g., GL_TEXTURE_2D) in the given GL context's state.
int getImageWidth()
Returns the width of the image contained within this texture.
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.
boolean isExtensionAvailable(String glExtensionName)
Returns true if the specified OpenGL extension can be used successfully through this GL instance give...
boolean isGLES3()
Indicates whether this GL object conforms to the OpenGL ES ≥ 3.0 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.
static final int GL_TEXTURE_EXTERNAL_OES
GL_OES_EGL_image_external Define "GL_TEXTURE_EXTERNAL_OES" with expression '0x8D65',...
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_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.
Protocol for texture sequences, like animations, movies, etc.
TextureFrame getLastTexture()
Returns the last updated texture.
int getTextureTarget()
Returns the texture target used by implementation.
String getTextureLookupFragmentShaderImpl()
Returns the complete texture2D lookup function code of type.
String getTextureSampler2DType()
Returns either sampler2D or samplerExternalOES depending on getLastTexture().
String setTextureLookupFunctionName(String texLookupFuncName)
Set the desired shader code's texture lookup function name.
int getTextureUnit()
Return the texture unit used to render the current frame.
TextureFrame getNextTexture(GL gl)
Returns the next texture to be rendered.
String getRequiredExtensionsShaderStub()
In case a shader extension is required, based on the implementation and the runtime GL profile,...