diff options
author | Sven Gothel <sgothel@jausoft.com> | 2012-10-12 22:01:24 +0200 |
---|---|---|
committer | Sven Gothel <sgothel@jausoft.com> | 2012-10-12 22:01:24 +0200 |
commit | e03c5a17f1e6ebe7c8581469f35feb67a7100d15 (patch) | |
tree | cf8022663809d0b215d102465fcaf418dda33b7a /src/jogl/classes | |
parent | d1537f0359f917e5a6b1e77852fa1b1ac8a54d5f (diff) |
FixedFuncHook: Add ES2 alignment of certain GL functions, i.e. GL_QUAD_STRIP/GL_POLYGON/GL_QUADS mapping, glTexImage2D internalformat/format match.
Diffstat (limited to 'src/jogl/classes')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java | 4 | ||||
-rw-r--r-- | src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java | 53 |
2 files changed, 52 insertions, 5 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java index 238e402d1..1292a9298 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java +++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java @@ -422,12 +422,12 @@ public class ImmModeSink { if ( GL_QUADS == mode && !gl.isGL2() ) { if( GL.GL_UNSIGNED_BYTE == type ) { final ByteBuffer b = (ByteBuffer) indices; - for (int j = 0; j < b.remaining(); j++) { + for (int j = b.position(); j < b.remaining(); j++) { gl.glDrawArrays(GL.GL_TRIANGLE_FAN, (int)(0x000000ff & b.get(j)), 4); } } else { final ShortBuffer b = (ShortBuffer) indices; - for (int j = 0; j < b.remaining(); j++) { + for (int j = b.position(); j < b.remaining(); j++) { gl.glDrawArrays(GL.GL_TRIANGLE_FAN, (int)(0x0000ffff & b.get(j)), 4); } } diff --git a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java index abf71ba41..77b7a16b7 100644 --- a/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java +++ b/src/jogl/classes/jogamp/opengl/util/glsl/fixedfunc/FixedFuncHook.java @@ -30,9 +30,12 @@ package jogamp.opengl.util.glsl.fixedfunc; import java.nio.Buffer; +import java.nio.ByteBuffer; import java.nio.IntBuffer; +import java.nio.ShortBuffer; import javax.media.opengl.GL; +import javax.media.opengl.GL2; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLArrayData; import javax.media.opengl.GLException; @@ -113,15 +116,49 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun // FixedFuncHookIf - hooks // public void glDrawArrays(int mode, int first, int count) { - fixedFunction.validate(gl); + fixedFunction.validate(gl); + switch(mode) { + case GL2.GL_QUAD_STRIP: + mode=GL.GL_TRIANGLE_STRIP; + break; + case GL2.GL_POLYGON: + mode=GL.GL_TRIANGLE_FAN; + break; + } + if ( GL2.GL_QUADS == mode && !gl.isGL2() ) { + for (int j = first; j < count - 3; j += 4) { + gl.glDrawArrays(GL.GL_TRIANGLE_FAN, j, 4); + } + } else { + gl.glDrawArrays(mode, first, count); + } + gl.glDrawArrays(mode, first, count); } public void glDrawElements(int mode, int count, int type, java.nio.Buffer indices) { fixedFunction.validate(gl); - gl.glDrawElements(mode, count, type, indices); + if ( GL2.GL_QUADS == mode && !gl.isGL2() ) { + if( GL.GL_UNSIGNED_BYTE == type ) { + final ByteBuffer b = (ByteBuffer) indices; + for (int j = b.position(); j < count; j++) { + gl.glDrawArrays(GL.GL_TRIANGLE_FAN, (int)(0x000000ff & b.get(j)), 4); + } + } else { + final ShortBuffer b = (ShortBuffer) indices; + for (int j = b.position(); j < count; j++) { + gl.glDrawArrays(GL.GL_TRIANGLE_FAN, (int)(0x0000ffff & b.get(j)), 4); + } + } + } else { + gl.glDrawElements(mode, count, type, indices); + // GL2: gl.glDrawRangeElements(mode, 0, count-1, indices.remaining(), type, indices); + } } public void glDrawElements(int mode, int count, int type, long indices_buffer_offset) { fixedFunction.validate(gl); + if ( GL2.GL_QUADS == mode && !gl.isGL2() ) { + throw new GLException("Cannot handle indexed QUADS on !GL2 w/ VBO due to lack of CPU index access"); + } gl.glDrawElements(mode, count, type, indices_buffer_offset); } @@ -183,11 +220,21 @@ public class FixedFuncHook implements GLLightingFunc, GLMatrixFunc, GLPointerFun } public void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels) { + // align internalformat w/ format, an ES2 requirement + switch(internalformat) { + case 3: internalformat= ( GL.GL_RGBA == format ) ? GL.GL_RGBA : GL.GL_RGB; break; + case 4: internalformat= ( GL.GL_RGB == format ) ? GL.GL_RGB : GL.GL_RGBA; break; + } fixedFunction.glTexImage2D(target, /* level, */ internalformat, /*width, height, border, */ format /*, type, pixels*/); gl.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); } public void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, - int format, int type, long pixels_buffer_offset) { + int format, int type, long pixels_buffer_offset) { + // align internalformat w/ format, an ES2 requirement + switch(internalformat) { + case 3: internalformat= ( GL.GL_RGBA == format ) ? GL.GL_RGBA : GL.GL_RGB; break; + case 4: internalformat= ( GL.GL_RGB == format ) ? GL.GL_RGB : GL.GL_RGBA; break; + } fixedFunction.glTexImage2D(target, /* level, */ internalformat, /*width, height, border, */ format /*, type, pixels*/); gl.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels_buffer_offset); } |