aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jake2/render/JoglDummyRenderer.java256
-rw-r--r--src/jake2/render/JoglES2Renderer.java1
-rw-r--r--src/jake2/render/Renderer.java7
-rw-r--r--src/jake2/render/opengl/DummyGL.java13
-rw-r--r--src/jake2/render/opengl/JoglDummyDriver.java140
-rw-r--r--src/jake2/render/opengl/JoglES1Driver.java3
-rw-r--r--src/jake2/render/opengl/JoglES2Driver.java3
-rw-r--r--src/jake2/render/opengl/JoglGL2Driver.java3
8 files changed, 419 insertions, 7 deletions
diff --git a/src/jake2/render/JoglDummyRenderer.java b/src/jake2/render/JoglDummyRenderer.java
new file mode 100644
index 0000000..56e986e
--- /dev/null
+++ b/src/jake2/render/JoglDummyRenderer.java
@@ -0,0 +1,256 @@
+/*
+ * JoglRenderer.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;
+
+import javax.media.nativewindow.util.Dimension;
+
+import jake2.Defines;
+import jake2.client.refdef_t;
+import jake2.client.refexport_t;
+import jake2.render.opengl.JoglDummyDriver;
+import jake2.sys.NEWTKBD;
+import jake2.sys.KBD;
+
+/**
+ * JoglRenderer
+ *
+ * @author dsanders/cwei
+ */
+final class JoglDummyRenderer extends JoglDummyDriver implements refexport_t, Ref {
+
+ public static final String DRIVER_NAME = "jogldummy";
+
+ private KBD kbd = new NEWTKBD();
+
+ // is set from Renderer factory
+ private RenderAPI impl;
+
+ static {
+ Renderer.register(new JoglDummyRenderer());
+ };
+
+ private JoglDummyRenderer() {
+ // singleton
+ }
+
+ // ============================================================================
+ // public interface for Renderer implementations
+ //
+ // refexport_t (ref.h)
+ // ============================================================================
+
+ /**
+ * @see jake2.client.refexport_t#Init()
+ */
+ public boolean Init(int vid_xpos, int vid_ypos) {
+ // init the OpenGL drivers
+ impl.setGLDriver(this);
+
+ // Cvar.Set("gl_clear", "1"); // FIXME
+
+ // pre init, reads Cvar's
+ if (!impl.R_Init(vid_xpos, vid_ypos)) return false;
+ // activates the OpenGL context
+ activate();
+
+ // post init
+ return impl.R_Init2();
+ }
+
+ /**
+ * @see jake2.client.refexport_t#Shutdown()
+ */
+ public void Shutdown() {
+ impl.R_Shutdown();
+ }
+
+ /**
+ * @see jake2.client.refexport_t#BeginRegistration(java.lang.String)
+ */
+ public final void BeginRegistration(String map) {
+ activate();
+ impl.R_BeginRegistration(map);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#RegisterModel(java.lang.String)
+ */
+ public final model_t RegisterModel(String name) {
+ activate();
+ return impl.R_RegisterModel(name);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#RegisterSkin(java.lang.String)
+ */
+ public final image_t RegisterSkin(String name) {
+ activate();
+ return impl.R_RegisterSkin(name);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#RegisterPic(java.lang.String)
+ */
+ public final image_t RegisterPic(String name) {
+ activate();
+ 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();
+ impl.R_SetSky(name, rotate, axis);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#EndRegistration()
+ */
+ public final void EndRegistration() {
+ activate();
+ impl.R_EndRegistration();
+ }
+
+ /**
+ * @see jake2.client.refexport_t#RenderFrame(jake2.client.refdef_t)
+ */
+ public final void RenderFrame(refdef_t fd) {
+ impl.R_RenderFrame(fd);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#DrawGetPicSize(Dimension, java.lang.String)
+ */
+ public final void DrawGetPicSize(Dimension dim, String name) {
+ impl.Draw_GetPicSize(dim, name);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#DrawPic(int, int, java.lang.String)
+ */
+ public final void DrawPic(int x, int y, String name) {
+ impl.Draw_Pic(x, y, name);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#DrawStretchPic(int, int, int, int, java.lang.String)
+ */
+ public final void DrawStretchPic(int x, int y, int w, int h, String name) {
+ impl.Draw_StretchPic(x, y, w, h, name);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#DrawChar(int, int, int)
+ */
+ public final void DrawChar(int x, int y, int num) {
+ activate();
+ impl.Draw_Char(x, y, num);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#DrawTileClear(int, int, int, int, java.lang.String)
+ */
+ public final void DrawTileClear(int x, int y, int w, int h, String name) {
+ impl.Draw_TileClear(x, y, w, h, name);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#DrawFill(int, int, int, int, int)
+ */
+ public final void DrawFill(int x, int y, int w, int h, int c) {
+ impl.Draw_Fill(x, y, w, h, c);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#DrawFadeScreen()
+ */
+ public final void DrawFadeScreen() {
+ impl.Draw_FadeScreen();
+ }
+
+ /**
+ * @see jake2.client.refexport_t#DrawStretchRaw(int, int, int, int, int, int, byte[])
+ */
+ public final void DrawStretchRaw(int x, int y, int w, int h, int cols, int rows, byte[] data) {
+ impl.Draw_StretchRaw(x, y, w, h, cols, rows, data);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#CinematicSetPalette(byte[])
+ */
+ public final void CinematicSetPalette(byte[] palette) {
+ impl.R_SetPalette(palette);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#BeginFrame(float)
+ */
+ public final void BeginFrame(float camera_separation) {
+ impl.R_BeginFrame(camera_separation);
+ }
+
+ /**
+ * @see jake2.client.refexport_t#EndFrame()
+ */
+ public final void EndFrame() {
+ endFrame();
+ }
+
+ /**
+ * @see jake2.client.refexport_t#AppActivate(boolean)
+ */
+ public final void AppActivate(boolean activate) {
+ appActivate(activate);
+ }
+
+ public void screenshot() {
+ activate();
+ impl.GL_ScreenShot_f();
+ }
+
+ public final int apiVersion() {
+ return Defines.API_VERSION;
+ }
+
+ public KBD getKeyboardHandler() {
+ return kbd;
+ }
+ // ============================================================================
+ // Ref interface
+ // ============================================================================
+
+ public final String getName() {
+ return DRIVER_NAME;
+ }
+
+ public final String toString() {
+ return DRIVER_NAME;
+ }
+
+ public final refexport_t GetRefAPI(RenderAPI renderer) {
+ this.impl = renderer;
+ return this;
+ }
+}
diff --git a/src/jake2/render/JoglES2Renderer.java b/src/jake2/render/JoglES2Renderer.java
index d7137fe..dc836dc 100644
--- a/src/jake2/render/JoglES2Renderer.java
+++ b/src/jake2/render/JoglES2Renderer.java
@@ -29,7 +29,6 @@ import javax.media.nativewindow.util.Dimension;
import jake2.Defines;
import jake2.client.refdef_t;
import jake2.client.refexport_t;
-import jake2.qcommon.Cvar;
import jake2.render.opengl.JoglES2Driver;
import jake2.sys.NEWTKBD;
import jake2.sys.KBD;
diff --git a/src/jake2/render/Renderer.java b/src/jake2/render/Renderer.java
index 28936d0..7b83525 100644
--- a/src/jake2/render/Renderer.java
+++ b/src/jake2/render/Renderer.java
@@ -44,6 +44,13 @@ public class Renderer {
static {
try {
try {
+ Class.forName("jake2.render.JoglDummyRenderer");
+ } catch (Throwable t) {
+ // ignore the new jogl driver if runtime not in classpath
+ System.err.println("Catched exception: "+t.getMessage());
+ // t.printStackTrace();
+ }
+ try {
Class.forName("javax.media.opengl.GL2");
Class.forName("jake2.render.JoglGL2Renderer");
} catch (Throwable t) {
diff --git a/src/jake2/render/opengl/DummyGL.java b/src/jake2/render/opengl/DummyGL.java
index eeae547..45cc9df 100644
--- a/src/jake2/render/opengl/DummyGL.java
+++ b/src/jake2/render/opengl/DummyGL.java
@@ -1,13 +1,14 @@
package jake2.render.opengl;
-
-import java.nio.*;
+import java.nio.ByteBuffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
public class DummyGL implements QGL {
private static QGL self = new DummyGL();
- private DummyGL() {
+ protected DummyGL() {
// singleton
}
@@ -141,6 +142,12 @@ public class DummyGL implements QGL {
switch (name) {
case GL_EXTENSIONS:
return "GL_ARB_multitexture";
+ case GL_VERSION:
+ return "2.0.0 Dummy";
+ case GL_VENDOR:
+ return "Dummy Cooperation";
+ case GL_RENDERER:
+ return "Dummy Renderer";
default:
return "";
}
diff --git a/src/jake2/render/opengl/JoglDummyDriver.java b/src/jake2/render/opengl/JoglDummyDriver.java
new file mode 100644
index 0000000..5b65ecf
--- /dev/null
+++ b/src/jake2/render/opengl/JoglDummyDriver.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 JoglDummyDriver extends DummyGL implements GLDriver {
+
+ protected static GLProfile glp = GLProfile.getGL2ES2(); // exception if n/a is desired
+
+ protected JoglDummyDriver() {
+ super();
+ // 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();
+ 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/JoglES1Driver.java b/src/jake2/render/opengl/JoglES1Driver.java
index e6edcc5..afb1c12 100644
--- a/src/jake2/render/opengl/JoglES1Driver.java
+++ b/src/jake2/render/opengl/JoglES1Driver.java
@@ -103,10 +103,11 @@ public abstract class JoglES1Driver extends JoglGL2ES1 implements GLDriver {
public void endFrame() {
newtWin.window.swapBuffers();
+ /**
final GLContext ctx = newtWin.window.getContext();
if ( null != ctx && GLContext.getCurrent() == ctx) {
ctx.release();
- }
+ } */
newtWin.fpsCounter.tickFPS();
}
diff --git a/src/jake2/render/opengl/JoglES2Driver.java b/src/jake2/render/opengl/JoglES2Driver.java
index 037eba9..7d2926d 100644
--- a/src/jake2/render/opengl/JoglES2Driver.java
+++ b/src/jake2/render/opengl/JoglES2Driver.java
@@ -108,10 +108,11 @@ public abstract class JoglES2Driver extends JoglGL2ES1 implements GLDriver {
public void endFrame() {
newtWin.window.swapBuffers();
+ /*
final GLContext ctx = newtWin.window.getContext();
if ( null != ctx && GLContext.getCurrent() == ctx) {
ctx.release();
- }
+ } */
newtWin.fpsCounter.tickFPS();
}
diff --git a/src/jake2/render/opengl/JoglGL2Driver.java b/src/jake2/render/opengl/JoglGL2Driver.java
index 0386e30..ccabf7f 100644
--- a/src/jake2/render/opengl/JoglGL2Driver.java
+++ b/src/jake2/render/opengl/JoglGL2Driver.java
@@ -102,10 +102,11 @@ public abstract class JoglGL2Driver extends JoglGL2ES1 implements GLDriver {
public void endFrame() {
newtWin.window.swapBuffers();
+ /**
final GLContext ctx = newtWin.window.getContext();
if ( null != ctx && GLContext.getCurrent() == ctx) {
ctx.release();
- }
+ } */
newtWin.fpsCounter.tickFPS();
}