diff options
Diffstat (limited to 'src/jake2/render/opengl')
-rw-r--r-- | src/jake2/render/opengl/JoglES1Driver.java | 140 | ||||
-rw-r--r-- | src/jake2/render/opengl/JoglES2Driver.java | 20 | ||||
-rw-r--r-- | src/jake2/render/opengl/JoglGL2Driver.java | 10 | ||||
-rw-r--r-- | src/jake2/render/opengl/JoglGL2ES1.java (renamed from src/jake2/render/opengl/JoglES2.java) | 265 | ||||
-rw-r--r-- | src/jake2/render/opengl/NEWTWin.java | 7 |
5 files changed, 345 insertions, 97 deletions
diff --git a/src/jake2/render/opengl/JoglES1Driver.java b/src/jake2/render/opengl/JoglES1Driver.java new file mode 100644 index 0000000..e6edcc5 --- /dev/null +++ b/src/jake2/render/opengl/JoglES1Driver.java @@ -0,0 +1,140 @@ +/* + * JoglDriver.java + * Copyright (C) 2004 + * + */ +/* +Copyright (C) 1997-2001 Id Software, Inc. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + */ + +package jake2.render.opengl; + +import jake2.qcommon.xcommand_t; +import jake2.render.Base; + +import javax.media.nativewindow.util.Dimension; +import javax.media.opengl.*; + +import com.jogamp.newt.ScreenMode; + +/** + * JoglCommon + */ +public abstract class JoglES1Driver extends JoglGL2ES1 implements GLDriver { + + // protected static GLProfile glp = GLProfile.get(GLProfile.GLES1); // exception if n/a is desired + protected static GLProfile glp = GLProfile.get(GLProfile.GL2ES1); // exception if n/a is desired + + protected JoglES1Driver() { + // singleton + } + + private NEWTWin newtWin = null; + + public abstract String getName(); + + public ScreenMode[] getModeList() { + if(null == newtWin) { + throw new RuntimeException("NEWTWin not yet initialized."); + } + return newtWin.getModeList(); + } + + public int setMode(Dimension dim, int mode, boolean fullscreen) { + if(null == newtWin) { + newtWin = new NEWTWin(); + } + int res = newtWin.setMode(glp, dim, mode, fullscreen, getName()); + if( Base.rserr_ok == res ) { + activate(); + setGL(newtWin.window.getGL().getGL2ES1()); + init(0, 0); + + return Base.rserr_ok; + } + return res; + } + + public void shutdown() { + if(null != newtWin) { + newtWin.shutdown(); + } + } + + /** + * @return true + */ + public boolean init(int xpos, int ypos) { + // clear the screen + // first buffer + beginFrame(0.0f); + glViewport(0, 0, newtWin.window.getWidth(), newtWin.window.getHeight()); + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + endFrame(); + // second buffer + beginFrame(0.0f); + glViewport(0, 0, newtWin.window.getWidth(), newtWin.window.getHeight()); + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + endFrame(); + return true; + } + + public void beginFrame(float camera_separation) { + activate(); + } + + public void endFrame() { + newtWin.window.swapBuffers(); + final GLContext ctx = newtWin.window.getContext(); + if ( null != ctx && GLContext.getCurrent() == ctx) { + ctx.release(); + } + newtWin.fpsCounter.tickFPS(); + } + + public void appActivate(boolean activate) { + // do nothing + } + + public void enableLogging(boolean enable) { + // do nothing + } + + public void logNewFrame() { + // do nothing + } + + /* + * @see jake2.client.refexport_t#updateScreen() + */ + public void updateScreen(xcommand_t callback) { + callback.execute(); + } + + protected void activate() { + final GLContext ctx = newtWin.window.getContext(); + if ( null != ctx && GLContext.getCurrent() != ctx ) { + ctx.makeCurrent(); + } + } + + // -------------------------------------------------------------------------- +} diff --git a/src/jake2/render/opengl/JoglES2Driver.java b/src/jake2/render/opengl/JoglES2Driver.java index 7319324..e6dc90a 100644 --- a/src/jake2/render/opengl/JoglES2Driver.java +++ b/src/jake2/render/opengl/JoglES2Driver.java @@ -32,18 +32,28 @@ import javax.media.nativewindow.util.Dimension; import javax.media.opengl.*; import com.jogamp.newt.ScreenMode; +import com.jogamp.opengl.util.glsl.fixedfunc.FixedFuncUtil; +import com.jogamp.opengl.util.glsl.fixedfunc.ShaderSelectionMode; /** * JoglCommon */ -public abstract class JoglES2Driver extends JoglES2 implements GLDriver { +public abstract class JoglES2Driver extends JoglGL2ES1 implements GLDriver { + // protected static GLProfile glp = GLProfile.get(GLProfile.GLES2); // exception if n/a is desired + protected static GLProfile glp = GLProfile.getGL2ES2(); // exception if n/a is desired + + // protected static final ShaderSelectionMode shaderSelectionMode = ShaderSelectionMode.AUTO; + protected static final ShaderSelectionMode shaderSelectionMode = ShaderSelectionMode.COLOR_TEXTURE; + protected JoglES2Driver() { // singleton } private NEWTWin newtWin = null; + public abstract String getName(); + public ScreenMode[] getModeList() { if(null == newtWin) { throw new RuntimeException("NEWTWin not yet initialized."); @@ -55,10 +65,10 @@ public abstract class JoglES2Driver extends JoglES2 implements GLDriver { if(null == newtWin) { newtWin = new NEWTWin(); } - int res = newtWin.setMode(dim, mode, fullscreen); + int res = newtWin.setMode(glp, dim, mode, fullscreen, getName()); if( Base.rserr_ok == res ) { - - setGL(newtWin.window.getGL().getGL2()); + activate(); + setGL( FixedFuncUtil.wrapFixedFuncEmul(newtWin.window.getGL(), shaderSelectionMode, null, true, false) ); init(0, 0); return Base.rserr_ok; @@ -97,11 +107,11 @@ public abstract class JoglES2Driver extends JoglES2 implements GLDriver { } public void endFrame() { + newtWin.window.swapBuffers(); final GLContext ctx = newtWin.window.getContext(); if ( null != ctx && GLContext.getCurrent() == ctx) { ctx.release(); } - newtWin.window.swapBuffers(); newtWin.fpsCounter.tickFPS(); } diff --git a/src/jake2/render/opengl/JoglGL2Driver.java b/src/jake2/render/opengl/JoglGL2Driver.java index 46b7f97..0386e30 100644 --- a/src/jake2/render/opengl/JoglGL2Driver.java +++ b/src/jake2/render/opengl/JoglGL2Driver.java @@ -36,14 +36,18 @@ import com.jogamp.newt.ScreenMode; /** * JoglCommon */ -public abstract class JoglGL2Driver extends JoglGL2 implements GLDriver { +public abstract class JoglGL2Driver extends JoglGL2ES1 implements GLDriver { + protected static GLProfile glp = GLProfile.get(GLProfile.GL2); // exception if n/a is desired + protected JoglGL2Driver() { // singleton } private NEWTWin newtWin = null; + public abstract String getName(); + public ScreenMode[] getModeList() { if(null == newtWin) { throw new RuntimeException("NEWTWin not yet initialized."); @@ -55,7 +59,7 @@ public abstract class JoglGL2Driver extends JoglGL2 implements GLDriver { if(null == newtWin) { newtWin = new NEWTWin(); } - int res = newtWin.setMode(dim, mode, fullscreen); + int res = newtWin.setMode(glp, dim, mode, fullscreen, getName()); if( Base.rserr_ok == res ) { setGL(newtWin.window.getGL().getGL2()); @@ -97,11 +101,11 @@ public abstract class JoglGL2Driver extends JoglGL2 implements GLDriver { } public void endFrame() { + newtWin.window.swapBuffers(); final GLContext ctx = newtWin.window.getContext(); if ( null != ctx && GLContext.getCurrent() == ctx) { ctx.release(); } - newtWin.window.swapBuffers(); newtWin.fpsCounter.tickFPS(); } diff --git a/src/jake2/render/opengl/JoglES2.java b/src/jake2/render/opengl/JoglGL2ES1.java index 1967619..e03a863 100644 --- a/src/jake2/render/opengl/JoglES2.java +++ b/src/jake2/render/opengl/JoglGL2ES1.java @@ -3,65 +3,118 @@ package jake2.render.opengl; import java.nio.*; -import javax.media.opengl.GL2; +import javax.media.opengl.*; -public class JoglES2 implements QGL { - - private GL2 gl; - - JoglES2() { +import com.jogamp.opengl.util.ImmModeSink; + +public class JoglGL2ES1 implements QGL { + + private GL2ES1 gl; + protected final ImmModeSink ims; + private boolean inBlock = false; // within begin/end + + JoglGL2ES1() { // singleton + ims = ImmModeSink.createFixed(4*8, + 3, GL.GL_FLOAT, // vertex + 4, GL.GL_FLOAT, // color + 0, 0, // normal + 2, GL.GL_FLOAT, // texture + GL.GL_STATIC_DRAW); } - - void setGL(GL2 gl) { + + void setGL(GL2ES1 gl) { this.gl = gl; } - - public void glAlphaFunc(int func, float ref) { - gl.glAlphaFunc(func, ref); - } public void glBegin(int mode) { - gl.glBegin(mode); + if(inBlock) { + throw new GLException("glBegin already called"); + } + ims.glBegin(mode); + inBlock = true; } - public void glBindTexture(int target, int texture) { - gl.glBindTexture(target, texture); + public void glEnd() { + if(!inBlock) { + throw new GLException("glBegin not called"); + } + ims.glEnd(gl, true); + inBlock = false; } - public void glBlendFunc(int sfactor, int dfactor) { - gl.glBlendFunc(sfactor, dfactor); + public void glColor3f(float red, float green, float blue) { + glColor4f(red, green, blue, 1f); } - public void glClear(int mask) { - gl.glClear(mask); + public void glColor3ub(byte red, byte green, byte blue) { + glColor4ub(red, green, blue, (byte) 255); } - public void glClearColor(float red, float green, float blue, float alpha) { - gl.glClearColor(red, green, blue, alpha); + public void glColor4f(float red, float green, float blue, float alpha) { + if(inBlock) { + ims.glColor4f(red, green, blue, alpha); + } else { + gl.glColor4f(red, green, blue, alpha); + } } - public void glColor3f(float red, float green, float blue) { - gl.glColor3f(red, green, blue); + public void glColor4ub(byte red, byte green, byte blue, byte alpha) { + final float r = (red & 255) / 255.0f; + final float g = (green & 255) / 255.0f; + final float b = (blue & 255) / 255.0f; + final float a = (alpha & 255) / 255.0f; + glColor4f(r, g, b, a); } - public void glColor3ub(byte red, byte green, byte blue) { - gl.glColor3ub(red, green, blue); + public void glTexCoord2f(float s, float t) { + if(inBlock) { + ims.glTexCoord2f(s, t); + } else { + throw new GLException("glBegin missing"); + } } - public void glColor4f(float red, float green, float blue, float alpha) { - gl.glColor4f(red, green, blue, alpha); + public void glVertex2f(float x, float y) { + if(inBlock) { + ims.glVertex2f(x, y); + } else { + throw new GLException("glBegin missing"); + } } - public void glColor4ub(byte red, byte green, byte blue, byte alpha) { - gl.glColor4ub(red, green, blue, alpha); + public void glVertex3f(float x, float y, float z) { + if(inBlock) { + ims.glVertex3f(x, y, z); + } else { + throw new GLException("glBegin missing"); + } + } + + public void glAlphaFunc(int func, float ref) { + gl.glAlphaFunc(func, ref); + } + + public void glBindTexture(int target, int texture) { + gl.glBindTexture(target, texture); } - public void glColorPointer(int size, boolean unsigned, int stride, - ByteBuffer pointer) { + public void glBlendFunc(int sfactor, int dfactor) { + gl.glBlendFunc(sfactor, dfactor); + } + + public void glClear(int mask) { + gl.glClear(mask); + } + + public void glClearColor(float red, float green, float blue, float alpha) { + gl.glClearColor(red, green, blue, alpha); + } + + public void glColorPointer(int size, boolean unsigned, int stride, ByteBuffer pointer) { gl.glColorPointer(size, GL_UNSIGNED_BYTE, stride, pointer); } - + public void glColorPointer(int size, int stride, FloatBuffer pointer) { gl.glColorPointer(size, GL_FLOAT, stride, pointer); } @@ -83,7 +136,7 @@ public class JoglES2 implements QGL { } public void glDepthRange(double zNear, double zFar) { - gl.glDepthRange(zNear, zFar); + gl.glDepthRangef((float)zNear, (float)zFar); } public void glDisable(int cap) { @@ -95,14 +148,39 @@ public class JoglES2 implements QGL { } public void glDrawArrays(int mode, int first, int count) { - gl.glDrawArrays(mode, first, count); + switch(mode) { + case GL_QUAD_STRIP: + mode=GL.GL_TRIANGLE_STRIP; + break; + case GL_POLYGON: + mode=GL.GL_TRIANGLE_FAN; + break; + } + if ( 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); + } } public void glDrawBuffer(int mode) { - gl.glDrawBuffer(mode); + // FIXME: ignored + if(GL.GL_BACK != mode) { + System.err.println("IGNORED: glDrawBuffer(0x"+Integer.toHexString(mode)+")"); + } } public void glDrawElements(int mode, IntBuffer indices) { + switch(mode) { + case GL_QUAD_STRIP: + mode=GL.GL_TRIANGLE_STRIP; + break; + case GL_POLYGON: + mode=GL.GL_TRIANGLE_FAN; + break; + } gl.glDrawElements(mode, indices.limit(), GL_UNSIGNED_INT, indices); } @@ -114,10 +192,6 @@ public class JoglES2 implements QGL { gl.glEnableClientState(cap); } - public void glEnd() { - gl.glEnd(); - } - public void glFinish() { gl.glFinish(); } @@ -140,16 +214,40 @@ public class JoglES2 implements QGL { } public String glGetString(int name) { + if( GL.GL_EXTENSIONS == name ) { + StringBuilder sb = new StringBuilder(); + sb.append(gl.glGetString(name)); + // sb.append(" GL_EXT_point_parameters"); + sb.append(" GL_ARB_multitexture"); + return sb.toString(); + } return gl.glGetString(name); } - + public void glHint(int target, int mode) { - gl.glHint(target, mode); + gl.glHint(target, mode); } - public void glInterleavedArrays(int format, int stride, - FloatBuffer pointer) { - gl.glInterleavedArrays(format, stride, pointer); + public void glInterleavedArrays(int format, int stride, FloatBuffer pointer) { + // gl.glInterleavedArrays(GL_T2F_V3F, glpoly_t.BYTE_STRIDE, globalPolygonInterleavedBuf); + // gl.glInterleavedArrays(format, stride, pointer); + if(GL_T2F_V3F == format) { + glInterleavedArraysT2F_V3F(stride, pointer); + return; + } + throw new GLException("Type not supported: 0x"+Integer.toHexString(format)); + } + + private void glInterleavedArraysT2F_V3F(int byteStride, FloatBuffer buf) { + int pos = buf.position(); + gl.glTexCoordPointer(2, GL.GL_FLOAT, byteStride, buf); + gl.glEnableClientState(GL2ES1.GL_TEXTURE_COORD_ARRAY); + + buf.position(pos + 2); + gl.glVertexPointer(3, GL.GL_FLOAT, byteStride, buf); + gl.glEnableClientState(GL2ES1.GL_VERTEX_ARRAY); + + buf.position(pos); } public void glLoadIdentity() { @@ -164,8 +262,7 @@ public class JoglES2 implements QGL { gl.glMatrixMode(mode); } - public void glOrtho(double left, double right, double bottom, - double top, double zNear, double zFar) { + public void glOrtho(double left, double right, double bottom, double top, double zNear, double zFar) { gl.glOrtho(left, right, bottom, top, zNear, zFar); } @@ -178,7 +275,9 @@ public class JoglES2 implements QGL { } public void glPolygonMode(int face, int mode) { - gl.glPolygonMode(face, mode); + if( GL_FRONT_AND_BACK != face || GL_FILL != mode ) { // if !default + System.err.println("IGNORED: glPolygonMode(0x"+Integer.toHexString(face)+", 0x"+Integer.toHexString(mode)+")"); + } } public void glPopMatrix() { @@ -189,8 +288,7 @@ public class JoglES2 implements QGL { gl.glPushMatrix(); } - public void glReadPixels(int x, int y, int width, int height, - int format, int type, ByteBuffer pixels) { + public void glReadPixels(int x, int y, int width, int height, int format, int type, ByteBuffer pixels) { gl.glReadPixels(x, y, width, height, format, type, pixels); } @@ -210,10 +308,6 @@ public class JoglES2 implements QGL { gl.glShadeModel(mode); } - public void glTexCoord2f(float s, float t) { - gl.glTexCoord2f(s, t); - } - public void glTexCoordPointer(int size, int stride, FloatBuffer pointer) { gl.glTexCoordPointer(size, GL_FLOAT, stride, pointer); } @@ -222,18 +316,22 @@ public class JoglES2 implements QGL { gl.glTexEnvi(target, pname, param); } - public void glTexImage2D(int target, int level, int internalformat, - int width, int height, int border, int format, int type, - ByteBuffer 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, ByteBuffer pixels) { + 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; + } + 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, - IntBuffer 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, IntBuffer pixels) { + 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; + } + gl.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); } public void glTexParameterf(int target, int pname, float param) { @@ -244,25 +342,15 @@ public class JoglES2 implements QGL { gl.glTexParameteri(target, pname, param); } - public void glTexSubImage2D(int target, int level, int xoffset, - int yoffset, int width, int height, int format, int type, - IntBuffer pixels) { - gl.glTexSubImage2D(target, level, xoffset, yoffset, width, height, - format, type, pixels); + public void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, + int format, int type, IntBuffer pixels) { + gl.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); } public void glTranslatef(float x, float y, float z) { gl.glTranslatef(x, y, z); } - public void glVertex2f(float x, float y) { - gl.glVertex2f(x, y); - } - - public void glVertex3f(float x, float y, float z) { - gl.glVertex3f(x, y, z); - } - public void glVertexPointer(int size, int stride, FloatBuffer pointer) { gl.glVertexPointer(size, GL_FLOAT, stride, pointer); } @@ -271,9 +359,9 @@ public class JoglES2 implements QGL { gl.glViewport(x, y, width, height); } - public void glColorTable(int target, int internalFormat, int width, - int format, int type, ByteBuffer data) { - gl.glColorTable(target, internalFormat, width, format, type, data); + public void glColorTable(int target, int internalFormat, int width, int format, int type, ByteBuffer data) { + // nop / FIXME gl.glColorTable(target, internalFormat, width, format, type, data); + System.err.println("IGNORED: glColorTable(0x"+Integer.toHexString(target)+", 0x"+Integer.toHexString(internalFormat)+", ..)"); } public void glActiveTextureARB(int texture) { @@ -291,27 +379,32 @@ public class JoglES2 implements QGL { public void glPointParameterfEXT(int pname, float param) { gl.glPointParameterf(pname, param); } + public void glLockArraysEXT(int first, int count) { - gl.glLockArraysEXT(first, count); + // nop / FIXME gl.glLockArraysEXT(first, count); + System.err.println("IGNORED: glLockArraysEXT(0x"+Integer.toHexString(first)+", 0x"+Integer.toHexString(count)+", ..)"); } public void glArrayElement(int index) { - gl.glArrayElement(index); + // nop / FIXME gl.glArrayElement(index); + System.err.println("IGNORED: glArrayElement(0x"+Integer.toHexString(index)+")"); } public void glUnlockArraysEXT() { - gl.glUnlockArraysEXT(); + // nop / FIXME gl.glUnlockArraysEXT(); + System.err.println("IGNORED: glUnlockArraysEXT()"); } - + public void glMultiTexCoord2f(int target, float s, float t) { - gl.glMultiTexCoord2f(target, s, t); + // nop / FIXME gl.glMultiTexCoord2f(target, s, t); + System.err.println("IGNORED: glMultiTexCoord2f(0x"+Integer.toHexString(target)+", "+s+", "+t+")"); } - + /* * util extensions */ public void setSwapInterval(int interval) { - gl.setSwapInterval(interval); + gl.setSwapInterval(interval); } } diff --git a/src/jake2/render/opengl/NEWTWin.java b/src/jake2/render/opengl/NEWTWin.java index 662dbc7..833376c 100644 --- a/src/jake2/render/opengl/NEWTWin.java +++ b/src/jake2/render/opengl/NEWTWin.java @@ -73,9 +73,10 @@ public class NEWTWin { * @param dim * @param mode * @param fullscreen + * @param driverName TODO * @return enum Base.rserr_t */ - public int setMode(Dimension dim, int mode, boolean fullscreen) { + public int setMode(GLProfile glp, Dimension dim, int mode, boolean fullscreen, String driverName) { final Dimension newDim = new Dimension(); @@ -110,8 +111,8 @@ public class NEWTWin { } if(null == window) { - window = GLWindow.create(screen, new GLCapabilities(GLProfile.get(GLProfile.GL2))); - window.setTitle("Jake2 (jogl-gl2-newt)"); + window = GLWindow.create(screen, new GLCapabilities(glp)); + window.setTitle("Jake2 ("+driverName+"-newt-"+glp.getName().toLowerCase()+")"); } if (oldDisplayMode == null) { |