diff options
author | Sven Gothel <[email protected]> | 2012-10-19 17:13:14 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-10-19 17:13:14 +0200 |
commit | 0d353c8bec9cc0c9f3dc6326177f3022c920f677 (patch) | |
tree | 984e3e4bf884142edfd0c3a2b27cf9b66029bcf2 | |
parent | 7b18dfedf6c04f77a6032539f8b70d434375d139 (diff) |
Fix/Enhance NEWT ScreenMode (FS) integration, simplify NEWTWin creation
- Only list unique resolutions
- Use List<ScreenMode>
- Properly deactivateGLContext()/activateGLContext() for setMode(..)
Further:
- JoglES2Driver: Claim to have pointExt (FFP emul will follow up)
-rw-r--r-- | Jake2.sh | 2 | ||||
-rw-r--r-- | src/jake2/client/VID.java | 27 | ||||
-rw-r--r-- | src/jake2/client/refexport_t.java | 4 | ||||
-rw-r--r-- | src/jake2/render/DummyRenderer.java | 7 | ||||
-rw-r--r-- | src/jake2/render/JoglDummyRenderer.java | 18 | ||||
-rw-r--r-- | src/jake2/render/JoglES1Renderer.java | 18 | ||||
-rw-r--r-- | src/jake2/render/JoglES2Renderer.java | 18 | ||||
-rw-r--r-- | src/jake2/render/JoglGL2Renderer.java | 18 | ||||
-rw-r--r-- | src/jake2/render/opengl/GLDriver.java | 4 | ||||
-rw-r--r-- | src/jake2/render/opengl/JoglDummyDriver.java | 22 | ||||
-rw-r--r-- | src/jake2/render/opengl/JoglES1Driver.java | 24 | ||||
-rw-r--r-- | src/jake2/render/opengl/JoglES2Driver.java | 28 | ||||
-rw-r--r-- | src/jake2/render/opengl/JoglGL2Driver.java | 21 | ||||
-rw-r--r-- | src/jake2/render/opengl/JoglGL2ES1.java | 8 | ||||
-rw-r--r-- | src/jake2/render/opengl/NEWTWin.java | 162 |
15 files changed, 186 insertions, 195 deletions
@@ -13,6 +13,7 @@ D0_ARGS="-Djava.awt.headless=true" #D_ARGS="-Dnewt.debug.Window.MouseEvent" #D_ARGS="-Dnewt.debug.Window.KeyEvent" +#D_ARGS="-Dnewt.debug.Screen -Dnewt.debug.Window" #D_ARGS="-Djogl.debug=all" #D_ARGS="-Djogl.debug.DebugGL -Djogl.debug.TraceGL" #D_ARGS="-Djogl.debug.DebugGL" @@ -34,6 +35,7 @@ D0_ARGS="-Djava.awt.headless=true" #G_ARGS="+set s_impl dummy +set timeout 12000 +set cl_timeout 12000 +set gl_mode 0 +set vid_ref jogles2" G_ARGS="+set s_impl dummy +set timeout 12000 +set cl_timeout 12000 +set gl_mode 0 +set vid_ref jogles1" +# G_ARGS2="+set vid_fullscreen 1" # G_ARGS2="+set jogl_gl2 0 +set jogl_gl2es1 1 +set jogl_gl2es2 1 +set jogl_rgb565 1" # G_ARGS2="+set gl_texturemode GL_LINEAR_MIPMAP_NEAREST" # G_ARGS2="+set r_shadows 0 +set gl_shadows 0 +set gl_dynamic 0" diff --git a/src/jake2/client/VID.java b/src/jake2/client/VID.java index f27d4f3..19aff61 100644 --- a/src/jake2/client/VID.java +++ b/src/jake2/client/VID.java @@ -25,6 +25,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package jake2.client; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + import jake2.Defines; import jake2.Globals; import jake2.game.Cmd; @@ -486,22 +490,24 @@ public class VID extends Globals { }; static void initModeList() { - ScreenMode[] modes = re.getModeList(); - fs_resolutions = new String[modes.length]; - fs_modes = new vidmode_t[modes.length]; - for (int i = 0; i < modes.length; i++) { - final ScreenMode sm = modes[i]; + final List<ScreenMode> modes = re.getModeList(); + final ArrayList<String> fs_resolutions_list = new ArrayList<String>(); + final ArrayList<vidmode_t> fs_modes_list = new ArrayList<vidmode_t>(); + final HashSet<DimensionImmutable> resSet = new HashSet<DimensionImmutable>(); + for (int i = 0; i < modes.size(); i++) { + final ScreenMode sm = modes.get(modes.size() - 1 - i); // reverse order: low -> high res. final MonitorMode mm = sm.getMonitorMode(); final SurfaceSize ss = mm.getSurfaceSize(); final DimensionImmutable m = ss.getResolution(); - final StringBuffer sb = new StringBuffer(); + if( resSet.add(m) ) { + final StringBuffer sb = new StringBuffer(); sb.append('['); sb.append(m.getWidth()); sb.append(' '); sb.append(m.getHeight()); while (sb.length() < 10) sb.append(' '); sb.append(']'); - fs_resolutions[i] = sb.toString(); + fs_resolutions_list.add(sb.toString()); sb.setLength(0); sb.append("Mode "); sb.append(i); @@ -509,8 +515,13 @@ public class VID extends Globals { sb.append(m.getWidth()); sb.append('x'); sb.append(m.getHeight()); - fs_modes[i] = new vidmode_t(sb.toString(), m.getWidth(), m.getHeight(), i); + fs_modes_list.add(new vidmode_t(sb.toString(), m.getWidth(), m.getHeight(), i)); + } } + fs_resolutions = new String[fs_resolutions_list.size()]; + fs_modes = new vidmode_t[fs_modes_list.size()]; + fs_resolutions_list.toArray(fs_resolutions); + fs_modes_list.toArray(fs_modes); } private static void initRefs() { diff --git a/src/jake2/client/refexport_t.java b/src/jake2/client/refexport_t.java index 3cde83e..7a2a8f0 100644 --- a/src/jake2/client/refexport_t.java +++ b/src/jake2/client/refexport_t.java @@ -26,6 +26,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package jake2.client; +import java.util.List; + import jake2.qcommon.xcommand_t; import jake2.render.image_t; import jake2.render.model_t; @@ -108,7 +110,7 @@ public interface refexport_t { int apiVersion(); - ScreenMode[] getModeList(); + List<ScreenMode> getModeList(); KBD getKeyboardHandler(); } diff --git a/src/jake2/render/DummyRenderer.java b/src/jake2/render/DummyRenderer.java index 73d05a6..2bc2c2e 100644 --- a/src/jake2/render/DummyRenderer.java +++ b/src/jake2/render/DummyRenderer.java @@ -7,6 +7,9 @@ package jake2.render; +import java.util.ArrayList; +import java.util.List; + import javax.media.nativewindow.util.Dimension; import com.jogamp.newt.ScreenMode; @@ -170,8 +173,8 @@ public class DummyRenderer implements refexport_t { /* (non-Javadoc) * @see jake2.client.refexport_t#getModeList() */ - public ScreenMode[] getModeList() { - return null; + public List<ScreenMode> getModeList() { + return new ArrayList<ScreenMode>(); } /* (non-Javadoc) diff --git a/src/jake2/render/JoglDummyRenderer.java b/src/jake2/render/JoglDummyRenderer.java index 56e986e..e39bd23 100644 --- a/src/jake2/render/JoglDummyRenderer.java +++ b/src/jake2/render/JoglDummyRenderer.java @@ -73,7 +73,7 @@ final class JoglDummyRenderer extends JoglDummyDriver implements refexport_t, Re // pre init, reads Cvar's if (!impl.R_Init(vid_xpos, vid_ypos)) return false; // activates the OpenGL context - activate(); + activateGLContext(); // post init return impl.R_Init2(); @@ -90,7 +90,7 @@ final class JoglDummyRenderer extends JoglDummyDriver implements refexport_t, Re * @see jake2.client.refexport_t#BeginRegistration(java.lang.String) */ public final void BeginRegistration(String map) { - activate(); + activateGLContext(); impl.R_BeginRegistration(map); } @@ -98,7 +98,7 @@ final class JoglDummyRenderer extends JoglDummyDriver implements refexport_t, Re * @see jake2.client.refexport_t#RegisterModel(java.lang.String) */ public final model_t RegisterModel(String name) { - activate(); + activateGLContext(); return impl.R_RegisterModel(name); } @@ -106,7 +106,7 @@ final class JoglDummyRenderer extends JoglDummyDriver implements refexport_t, Re * @see jake2.client.refexport_t#RegisterSkin(java.lang.String) */ public final image_t RegisterSkin(String name) { - activate(); + activateGLContext(); return impl.R_RegisterSkin(name); } @@ -114,14 +114,14 @@ final class JoglDummyRenderer extends JoglDummyDriver implements refexport_t, Re * @see jake2.client.refexport_t#RegisterPic(java.lang.String) */ public final image_t RegisterPic(String name) { - activate(); + activateGLContext(); return impl.Draw_FindPic(name); } /** * @see jake2.client.refexport_t#SetSky(java.lang.String, float, float[]) */ public final void SetSky(String name, float rotate, float[] axis) { - activate(); + activateGLContext(); impl.R_SetSky(name, rotate, axis); } @@ -129,7 +129,7 @@ final class JoglDummyRenderer extends JoglDummyDriver implements refexport_t, Re * @see jake2.client.refexport_t#EndRegistration() */ public final void EndRegistration() { - activate(); + activateGLContext(); impl.R_EndRegistration(); } @@ -165,7 +165,7 @@ final class JoglDummyRenderer extends JoglDummyDriver implements refexport_t, Re * @see jake2.client.refexport_t#DrawChar(int, int, int) */ public final void DrawChar(int x, int y, int num) { - activate(); + activateGLContext(); impl.Draw_Char(x, y, num); } @@ -226,7 +226,7 @@ final class JoglDummyRenderer extends JoglDummyDriver implements refexport_t, Re } public void screenshot() { - activate(); + activateGLContext(); impl.GL_ScreenShot_f(); } diff --git a/src/jake2/render/JoglES1Renderer.java b/src/jake2/render/JoglES1Renderer.java index 7798019..f798857 100644 --- a/src/jake2/render/JoglES1Renderer.java +++ b/src/jake2/render/JoglES1Renderer.java @@ -73,7 +73,7 @@ final class JoglES1Renderer extends JoglES1Driver implements refexport_t, Ref { return false; } // activates the OpenGL context - activate(); + activateGLContext(); // post init return impl.R_Init2(); @@ -90,7 +90,7 @@ final class JoglES1Renderer extends JoglES1Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#BeginRegistration(java.lang.String) */ public final void BeginRegistration(String map) { - activate(); + activateGLContext(); impl.R_BeginRegistration(map); } @@ -98,7 +98,7 @@ final class JoglES1Renderer extends JoglES1Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#RegisterModel(java.lang.String) */ public final model_t RegisterModel(String name) { - activate(); + activateGLContext(); return impl.R_RegisterModel(name); } @@ -106,7 +106,7 @@ final class JoglES1Renderer extends JoglES1Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#RegisterSkin(java.lang.String) */ public final image_t RegisterSkin(String name) { - activate(); + activateGLContext(); return impl.R_RegisterSkin(name); } @@ -114,14 +114,14 @@ final class JoglES1Renderer extends JoglES1Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#RegisterPic(java.lang.String) */ public final image_t RegisterPic(String name) { - activate(); + activateGLContext(); return impl.Draw_FindPic(name); } /** * @see jake2.client.refexport_t#SetSky(java.lang.String, float, float[]) */ public final void SetSky(String name, float rotate, float[] axis) { - activate(); + activateGLContext(); impl.R_SetSky(name, rotate, axis); } @@ -129,7 +129,7 @@ final class JoglES1Renderer extends JoglES1Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#EndRegistration() */ public final void EndRegistration() { - activate(); + activateGLContext(); impl.R_EndRegistration(); } @@ -165,7 +165,7 @@ final class JoglES1Renderer extends JoglES1Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#DrawChar(int, int, int) */ public final void DrawChar(int x, int y, int num) { - activate(); + activateGLContext(); impl.Draw_Char(x, y, num); } @@ -226,7 +226,7 @@ final class JoglES1Renderer extends JoglES1Driver implements refexport_t, Ref { } public void screenshot() { - activate(); + activateGLContext(); impl.GL_ScreenShot_f(); } diff --git a/src/jake2/render/JoglES2Renderer.java b/src/jake2/render/JoglES2Renderer.java index dec8a4a..a832ac1 100644 --- a/src/jake2/render/JoglES2Renderer.java +++ b/src/jake2/render/JoglES2Renderer.java @@ -71,7 +71,7 @@ final class JoglES2Renderer extends JoglES2Driver implements refexport_t, Ref { // pre init, reads Cvar's if (!impl.R_Init(vid_xpos, vid_ypos)) return false; // activates the OpenGL context - activate(); + activateGLContext(); // post init return impl.R_Init2(); @@ -88,7 +88,7 @@ final class JoglES2Renderer extends JoglES2Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#BeginRegistration(java.lang.String) */ public final void BeginRegistration(String map) { - activate(); + activateGLContext(); impl.R_BeginRegistration(map); } @@ -96,7 +96,7 @@ final class JoglES2Renderer extends JoglES2Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#RegisterModel(java.lang.String) */ public final model_t RegisterModel(String name) { - activate(); + activateGLContext(); return impl.R_RegisterModel(name); } @@ -104,7 +104,7 @@ final class JoglES2Renderer extends JoglES2Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#RegisterSkin(java.lang.String) */ public final image_t RegisterSkin(String name) { - activate(); + activateGLContext(); return impl.R_RegisterSkin(name); } @@ -112,14 +112,14 @@ final class JoglES2Renderer extends JoglES2Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#RegisterPic(java.lang.String) */ public final image_t RegisterPic(String name) { - activate(); + activateGLContext(); return impl.Draw_FindPic(name); } /** * @see jake2.client.refexport_t#SetSky(java.lang.String, float, float[]) */ public final void SetSky(String name, float rotate, float[] axis) { - activate(); + activateGLContext(); impl.R_SetSky(name, rotate, axis); } @@ -127,7 +127,7 @@ final class JoglES2Renderer extends JoglES2Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#EndRegistration() */ public final void EndRegistration() { - activate(); + activateGLContext(); impl.R_EndRegistration(); } @@ -163,7 +163,7 @@ final class JoglES2Renderer extends JoglES2Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#DrawChar(int, int, int) */ public final void DrawChar(int x, int y, int num) { - activate(); + activateGLContext(); impl.Draw_Char(x, y, num); } @@ -224,7 +224,7 @@ final class JoglES2Renderer extends JoglES2Driver implements refexport_t, Ref { } public void screenshot() { - activate(); + activateGLContext(); impl.GL_ScreenShot_f(); } diff --git a/src/jake2/render/JoglGL2Renderer.java b/src/jake2/render/JoglGL2Renderer.java index 48432d7..ef5117b 100644 --- a/src/jake2/render/JoglGL2Renderer.java +++ b/src/jake2/render/JoglGL2Renderer.java @@ -71,7 +71,7 @@ final class JoglGL2Renderer extends JoglGL2Driver implements refexport_t, Ref { // pre init, reads Cvar's if (!impl.R_Init(vid_xpos, vid_ypos)) return false; // activates the OpenGL context - activate(); + activateGLContext(); // post init return impl.R_Init2(); @@ -88,7 +88,7 @@ final class JoglGL2Renderer extends JoglGL2Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#BeginRegistration(java.lang.String) */ public final void BeginRegistration(String map) { - activate(); + activateGLContext(); impl.R_BeginRegistration(map); } @@ -96,7 +96,7 @@ final class JoglGL2Renderer extends JoglGL2Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#RegisterModel(java.lang.String) */ public final model_t RegisterModel(String name) { - activate(); + activateGLContext(); return impl.R_RegisterModel(name); } @@ -104,7 +104,7 @@ final class JoglGL2Renderer extends JoglGL2Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#RegisterSkin(java.lang.String) */ public final image_t RegisterSkin(String name) { - activate(); + activateGLContext(); return impl.R_RegisterSkin(name); } @@ -112,14 +112,14 @@ final class JoglGL2Renderer extends JoglGL2Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#RegisterPic(java.lang.String) */ public final image_t RegisterPic(String name) { - activate(); + activateGLContext(); return impl.Draw_FindPic(name); } /** * @see jake2.client.refexport_t#SetSky(java.lang.String, float, float[]) */ public final void SetSky(String name, float rotate, float[] axis) { - activate(); + activateGLContext(); impl.R_SetSky(name, rotate, axis); } @@ -127,7 +127,7 @@ final class JoglGL2Renderer extends JoglGL2Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#EndRegistration() */ public final void EndRegistration() { - activate(); + activateGLContext(); impl.R_EndRegistration(); } @@ -163,7 +163,7 @@ final class JoglGL2Renderer extends JoglGL2Driver implements refexport_t, Ref { * @see jake2.client.refexport_t#DrawChar(int, int, int) */ public final void DrawChar(int x, int y, int num) { - activate(); + activateGLContext(); impl.Draw_Char(x, y, num); } @@ -224,7 +224,7 @@ final class JoglGL2Renderer extends JoglGL2Driver implements refexport_t, Ref { } public void screenshot() { - activate(); + activateGLContext(); impl.GL_ScreenShot_f(); } diff --git a/src/jake2/render/opengl/GLDriver.java b/src/jake2/render/opengl/GLDriver.java index 6fda8cf..0967576 100644 --- a/src/jake2/render/opengl/GLDriver.java +++ b/src/jake2/render/opengl/GLDriver.java @@ -1,5 +1,7 @@ package jake2.render.opengl; +import java.util.List; + import javax.media.nativewindow.util.Dimension; import jake2.qcommon.xcommand_t; @@ -24,7 +26,7 @@ public interface GLDriver { void logNewFrame(); - ScreenMode[] getModeList(); + List<ScreenMode> getModeList(); void updateScreen(xcommand_t callback); diff --git a/src/jake2/render/opengl/JoglDummyDriver.java b/src/jake2/render/opengl/JoglDummyDriver.java index fb41bf7..3316f2a 100644 --- a/src/jake2/render/opengl/JoglDummyDriver.java +++ b/src/jake2/render/opengl/JoglDummyDriver.java @@ -25,6 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package jake2.render.opengl; +import java.util.List; + import jake2.qcommon.xcommand_t; import jake2.render.Base; @@ -49,7 +51,7 @@ public abstract class JoglDummyDriver extends DummyGL implements GLDriver { public abstract String getName(); - public ScreenMode[] getModeList() { + public List<ScreenMode> getModeList() { if(null == newtWin) { throw new RuntimeException("NEWTWin not yet initialized."); } @@ -62,7 +64,6 @@ public abstract class JoglDummyDriver extends DummyGL implements GLDriver { } int res = newtWin.setMode(glp, dim, mode, fullscreen, getName()); if( Base.rserr_ok == res ) { - activate(); init(0, 0); return Base.rserr_ok; @@ -71,7 +72,6 @@ public abstract class JoglDummyDriver extends DummyGL implements GLDriver { } public void shutdown() { - deactivate(); if(null != newtWin) { newtWin.shutdown(); } @@ -98,7 +98,7 @@ public abstract class JoglDummyDriver extends DummyGL implements GLDriver { } public void beginFrame(float camera_separation) { - activate(); + activateGLContext(); } public void endFrame() { @@ -126,18 +126,12 @@ public abstract class JoglDummyDriver extends DummyGL implements GLDriver { callback.execute(); } - protected void activate() { - final GLContext ctx = newtWin.window.getContext(); - if ( null != ctx && GLContext.getCurrent() != ctx ) { - ctx.makeCurrent(); - } + protected final void activateGLContext() { + newtWin.activateGLContext(); } - protected void deactivate() { - final GLContext ctx = newtWin.window.getContext(); - if ( null != ctx && GLContext.getCurrent() == ctx) { - ctx.release(); - } + protected final void deactivateGLContext() { + newtWin.activateGLContext(); } // -------------------------------------------------------------------------- diff --git a/src/jake2/render/opengl/JoglES1Driver.java b/src/jake2/render/opengl/JoglES1Driver.java index 64d3790..790b2d8 100644 --- a/src/jake2/render/opengl/JoglES1Driver.java +++ b/src/jake2/render/opengl/JoglES1Driver.java @@ -25,6 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package jake2.render.opengl; +import java.util.List; + import jake2.game.cvar_t; import jake2.qcommon.Cvar; import jake2.qcommon.xcommand_t; @@ -59,7 +61,7 @@ public abstract class JoglES1Driver extends JoglGL2ES1 implements GLDriver { public abstract String getName(); - public ScreenMode[] getModeList() { + public List<ScreenMode> getModeList() { if(null == newtWin) { throw new RuntimeException("NEWTWin not yet initialized."); } @@ -72,7 +74,6 @@ public abstract class JoglES1Driver extends JoglGL2ES1 implements GLDriver { } int res = newtWin.setMode(glp, dim, mode, fullscreen, getName()); if( Base.rserr_ok == res ) { - activate(); setGL(newtWin.window.getGL().getGL2ES1()); init(0, 0); @@ -82,7 +83,6 @@ public abstract class JoglES1Driver extends JoglGL2ES1 implements GLDriver { } public void shutdown() { - deactivate(); if(null != newtWin) { newtWin.shutdown(); } @@ -109,7 +109,7 @@ public abstract class JoglES1Driver extends JoglGL2ES1 implements GLDriver { } public void beginFrame(float camera_separation) { - activate(); + newtWin.activateGLContext(); } public void endFrame() { @@ -137,18 +137,12 @@ public abstract class JoglES1Driver extends JoglGL2ES1 implements GLDriver { callback.execute(); } - protected void activate() { - final GLContext ctx = newtWin.window.getContext(); - if ( null != ctx && GLContext.getCurrent() != ctx ) { - ctx.makeCurrent(); - } + protected final void activateGLContext() { + newtWin.activateGLContext(); } - - protected void deactivate() { - final GLContext ctx = newtWin.window.getContext(); - if ( null != ctx && GLContext.getCurrent() == ctx) { - ctx.release(); - } + + protected final void deactivateGLContext() { + newtWin.activateGLContext(); } // -------------------------------------------------------------------------- diff --git a/src/jake2/render/opengl/JoglES2Driver.java b/src/jake2/render/opengl/JoglES2Driver.java index b6a0a62..f4b0519 100644 --- a/src/jake2/render/opengl/JoglES2Driver.java +++ b/src/jake2/render/opengl/JoglES2Driver.java @@ -25,6 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package jake2.render.opengl; +import java.util.List; + import jake2.game.cvar_t; import jake2.qcommon.Cvar; import jake2.qcommon.xcommand_t; @@ -57,14 +59,14 @@ public abstract class JoglES2Driver extends JoglGL2ES1 implements GLDriver { protected static final ShaderSelectionMode shaderSelectionMode = ShaderSelectionMode.COLOR_TEXTURE2; protected JoglES2Driver() { - super(false); + super(true); } private NEWTWin newtWin = null; public abstract String getName(); - public ScreenMode[] getModeList() { + public List<ScreenMode> getModeList() { if(null == newtWin) { throw new RuntimeException("NEWTWin not yet initialized."); } @@ -77,7 +79,6 @@ public abstract class JoglES2Driver extends JoglGL2ES1 implements GLDriver { } int res = newtWin.setMode(glp, dim, mode, fullscreen, getName()); if( Base.rserr_ok == res ) { - activate(); setGL( FixedFuncUtil.wrapFixedFuncEmul(newtWin.window.getGL(), shaderSelectionMode, null, true, false) ); init(0, 0); @@ -87,7 +88,6 @@ public abstract class JoglES2Driver extends JoglGL2ES1 implements GLDriver { } public void shutdown() { - deactivate(); if(null != newtWin) { newtWin.shutdown(); } @@ -114,7 +114,7 @@ public abstract class JoglES2Driver extends JoglGL2ES1 implements GLDriver { } public void beginFrame(float camera_separation) { - activate(); + activateGLContext(); } public void endFrame() { @@ -141,20 +141,14 @@ public abstract class JoglES2Driver extends JoglGL2ES1 implements GLDriver { 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(); - } - } - protected void deactivate() { - final GLContext ctx = newtWin.window.getContext(); - if ( null != ctx && GLContext.getCurrent() == ctx) { - ctx.release(); - } + protected final void activateGLContext() { + newtWin.activateGLContext(); } + protected final void deactivateGLContext() { + newtWin.activateGLContext(); + } + // -------------------------------------------------------------------------- } diff --git a/src/jake2/render/opengl/JoglGL2Driver.java b/src/jake2/render/opengl/JoglGL2Driver.java index c2ca450..6fa7af7 100644 --- a/src/jake2/render/opengl/JoglGL2Driver.java +++ b/src/jake2/render/opengl/JoglGL2Driver.java @@ -25,6 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package jake2.render.opengl; +import java.util.List; + import jake2.game.cvar_t; import jake2.qcommon.Cvar; import jake2.qcommon.xcommand_t; @@ -59,7 +61,7 @@ public abstract class JoglGL2Driver extends JoglGL2ES1 implements GLDriver { public abstract String getName(); - public ScreenMode[] getModeList() { + public List<ScreenMode> getModeList() { if(null == newtWin) { throw new RuntimeException("NEWTWin not yet initialized."); } @@ -82,7 +84,6 @@ public abstract class JoglGL2Driver extends JoglGL2ES1 implements GLDriver { } public void shutdown() { - deactivate(); if(null != newtWin) { newtWin.shutdown(); } @@ -109,7 +110,7 @@ public abstract class JoglGL2Driver extends JoglGL2ES1 implements GLDriver { } public void beginFrame(float camera_separation) { - activate(); + activateGLContext(); } public void endFrame() { @@ -137,18 +138,12 @@ public abstract class JoglGL2Driver extends JoglGL2ES1 implements GLDriver { callback.execute(); } - protected void activate() { - final GLContext ctx = newtWin.window.getContext(); - if ( null != ctx && GLContext.getCurrent() != ctx ) { - ctx.makeCurrent(); - } + protected final void activateGLContext() { + newtWin.activateGLContext(); } - protected void deactivate() { - final GLContext ctx = newtWin.window.getContext(); - if ( null != ctx && GLContext.getCurrent() == ctx) { - ctx.release(); - } + protected final void deactivateGLContext() { + newtWin.activateGLContext(); } // -------------------------------------------------------------------------- diff --git a/src/jake2/render/opengl/JoglGL2ES1.java b/src/jake2/render/opengl/JoglGL2ES1.java index e560bac..524fdaf 100644 --- a/src/jake2/render/opengl/JoglGL2ES1.java +++ b/src/jake2/render/opengl/JoglGL2ES1.java @@ -306,10 +306,6 @@ public class JoglGL2ES1 implements QGL { gl.glPixelStorei(pname, param); } - public void glPointSize(float size) { - gl.glPointSize(size); - } - public void glPolygonMode(int face, int 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)+")"); @@ -408,6 +404,10 @@ public class JoglGL2ES1 implements QGL { gl.glClientActiveTexture(texture); } + public void glPointSize(float size) { + gl.glPointSize(size); + } + public void glPointParameterEXT(int pname, FloatBuffer pfParams) { gl.glPointParameterfv(pname, pfParams); } diff --git a/src/jake2/render/opengl/NEWTWin.java b/src/jake2/render/opengl/NEWTWin.java index d9164dd..fe62060 100644 --- a/src/jake2/render/opengl/NEWTWin.java +++ b/src/jake2/render/opengl/NEWTWin.java @@ -22,6 +22,7 @@ import javax.media.nativewindow.util.Dimension; import javax.media.nativewindow.util.DimensionImmutable; import javax.media.nativewindow.util.SurfaceSize; import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; import javax.media.opengl.GLProfile; import jogamp.opengl.FPSCounterImpl; @@ -43,16 +44,13 @@ public class NEWTWin { volatile GLWindow window = null; final FPSCounterImpl fpsCounter = new FPSCounterImpl(); - public ScreenMode[] getModeList() { - final List<ScreenMode> sml = screen.getScreenModes(); - ScreenMode[] sma = new ScreenMode[sml.size()]; - sml.toArray(sma); - return sma; + public List<ScreenMode> getModeList() { + return screen.getScreenModes(); } public ScreenMode findDisplayMode(DimensionImmutable dim) { final List<ScreenMode> sml = ScreenModeUtil.filterByResolution(screen.getScreenModes(), dim); - if(null == sml || sml.size() == 0) { + if(sml.size() == 0) { return oldDisplayMode; } return sml.get(0); @@ -86,25 +84,13 @@ public class NEWTWin { final Dimension newDim = new Dimension(); - VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\n"); + VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display for profile "+glp+"\n"); - VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":"); - - /** - if (Globals.appletMode && container == null) { - container = (Container) Globals.applet; - } */ - - final boolean screenRemRef; if(null == screen) { screen = NewtFactory.createScreen(NewtFactory.createDisplay(null), 0); screen.addReference(); // trigger native creation - screenRemRef = true; } else if( !screen.isNativeValid() ) { screen.addReference(); // trigger native creation - screenRemRef = true; - } else { - screenRemRef = false; } if (!VID.GetModeInfo(newDim, mode)) { @@ -112,34 +98,27 @@ public class NEWTWin { return Base.rserr_invalid_mode; } - VID.Printf(Defines.PRINT_ALL, " " + newDim.getWidth() + " " + newDim.getHeight() + '\n'); + VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ", " + newDim.getWidth() + " x " + newDim.getHeight() + ", fs " + fullscreen + ", driver " + driverName + "\n"); - if (!Globals.appletMode) { - // destroy the existing window - if (window != null) shutdown(); - } + // destroy the existing window, not screen + shutdownImpl(false); - if(null == window) { - final GLCapabilities caps = new GLCapabilities(glp); - CapabilitiesChooser chooser = null; // default - { - final cvar_t v = Cvar.Get("jogl_rgb565", "0", 0); - if( v.value != 0f ) { - caps.setRedBits(5); - caps.setGreenBits(6); - caps.setBlueBits(5); - chooser = new GenericGLCapabilitiesChooser(); // don't trust native GL-TK chooser - } - } - window = GLWindow.create(screen, caps); - window.setCapabilitiesChooser(chooser); - window.setTitle("Jake2 ("+driverName+"-newt-"+glp.getName().toLowerCase()+")"); + if(null != window) { + throw new InternalError("XXX"); } - - if (oldDisplayMode == null) { - oldDisplayMode = window.getScreen().getCurrentScreenMode(); + final GLCapabilities caps = new GLCapabilities(glp); + CapabilitiesChooser chooser = null; // default + { + final cvar_t v = Cvar.Get("jogl_rgb565", "0", 0); + if( v.value != 0f ) { + caps.setRedBits(5); + caps.setGreenBits(6); + caps.setBlueBits(5); + chooser = new GenericGLCapabilitiesChooser(); // don't trust native GL-TK chooser + } } - + window = GLWindow.create(screen, caps); + window.setCapabilitiesChooser(chooser); window.addWindowListener(new WindowAdapter() { public void windowDestroyNotify(WindowEvent e) { if (!Globals.appletMode) { @@ -148,55 +127,32 @@ public class NEWTWin { } public void windowResized(WindowEvent e) { - int width = window.getWidth(); - int height = window.getHeight(); - final int mask = ~0x03; - if ((width & 0x03) != 0) { - width &= mask; - width += 4; - } - - Base.setVid(width, height); - // let the sound and input subsystems know about the new window - VID.NewWindow(width, height); + propagateNewSize(); } }); + window.setTitle("Jake2 ("+driverName+"-newt-"+glp.getName().toLowerCase()+")"); - if (Globals.appletMode) { - // Destroy the previous display if there is one - shutdown(); - - // We don't support full-screen mode - fullscreen = false; + if (oldDisplayMode == null) { + oldDisplayMode = window.getScreen().getCurrentScreenMode(); } // We need to feed the NEWT Window to the NEWTKBD NEWTKBD.Init(window); - window.setSize(newDim.getWidth(), newDim.getHeight()); - - // D I F F E R E N T J A K E 2 E V E N T P R O C E S S I N G window.addWindowListener(NEWTKBD.listener); window.addKeyListener(NEWTKBD.listener); window.addMouseListener(NEWTKBD.listener); if (fullscreen) { - window.setFullscreen(true); - ScreenMode sm = findDisplayMode(newDim); final DimensionImmutable smDim = sm.getMonitorMode().getSurfaceSize().getResolution(); newDim.setWidth( smDim.getWidth() ); newDim.setHeight( smDim.getHeight() ); window.getScreen().setCurrentScreenMode(sm); window.setFullscreen(true); - window.setVisible(true); - - VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + sm.toString() + '\n'); - } else { - if (!Globals.appletMode) { - window.setVisible(true); - } else { + window.setSize(newDim.getWidth(), newDim.getHeight()); + if (Globals.appletMode) { // Notify the size listener about the change final SizeChangeListener listener = Globals.sizeChangeListener; if (listener != null) { @@ -204,6 +160,7 @@ public class NEWTWin { } } } + window.setVisible(true); if (!Globals.appletMode) { while ( !window.isNativeValid()|| !window.isRealized() ) { @@ -214,30 +171,67 @@ public class NEWTWin { } window.requestFocus(); window.display(); // force GL resource validation - + VID.Printf(Defines.PRINT_ALL, "...reques GLCaps "+window.getRequestedCapabilities()+'\n'); VID.Printf(Defines.PRINT_ALL, "...chosen GLCaps "+window.getChosenGLCapabilities()+'\n'); - - if(screenRemRef) { - screen.removeReference(); - } - + VID.Printf(Defines.PRINT_ALL, "...size "+window.getWidth()+" x "+window.getHeight()+'\n'); fpsCounter.setUpdateFPSFrames(isARM ? 60 : 4*60, System.err); + // propagateNewSize("init"); + activateGLContext(); + return Base.rserr_ok; } + + private void propagateNewSize() { + final int width = window.getWidth(); + final int height = window.getHeight(); + final int _width; + final int mask = ~0x03; + if ((width & 0x03) != 0) { + _width = ( width & mask ) + 4; + } else { + _width = width; + } + VID.Printf(Defines.PRINT_ALL, "Resize: " + width + " x " + height + ", masked " + _width + "x" + height + "\n"); + Base.setVid(_width, height); + // let the sound and input subsystems know about the new window + VID.NewWindow(_width, height); + } + + protected final void activateGLContext() { + final GLContext ctx = window.getContext(); + if ( null != ctx && GLContext.getCurrent() != ctx ) { + ctx.makeCurrent(); + } + } + + protected final void deactivateGLContext() { + final GLContext ctx = window.getContext(); + if ( null != ctx && GLContext.getCurrent() == ctx) { + ctx.release(); + } + } + void shutdown() { - if (!Globals.appletMode) { - if ( null != window ) { + shutdownImpl(true); + } + + private void shutdownImpl(boolean withScreen) { + if ( null != window ) { + deactivateGLContext(); + if (!Globals.appletMode) { window.destroy(); - } - } else { - if ( null != window ) { + } else { window.destroy(); // same thing } + window = null; + } + if( withScreen && null != screen ) { + screen.destroy(); + screen = null; } - window = null; } } |