From bf27c7e7dbd19cde845368fe3e61f38235788f4d Mon Sep 17 00:00:00 2001 From: Rene Stoeckel Date: Tue, 31 Oct 2006 14:00:23 +0000 Subject: imports cleaned up, independence from individual GL implementations --- src/jake2/render/common/Base.java | 63 ++++++++++++++++++++++++++++++++++++-- src/jake2/render/common/Mesh.java | 31 ++++++++++--------- src/jake2/render/common/Misc.java | 10 ++---- src/jake2/render/common/Model.java | 8 ++--- src/jake2/render/common/Surf.java | 40 ++++++++++-------------- src/jake2/render/common/Warp.java | 6 ++-- 6 files changed, 101 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/jake2/render/common/Base.java b/src/jake2/render/common/Base.java index 9cd2b0f..a9e09c4 100644 --- a/src/jake2/render/common/Base.java +++ b/src/jake2/render/common/Base.java @@ -19,21 +19,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 19.08.2006 by RST. -// $Id: Base.java,v 1.1 2006-10-31 13:06:32 salomo Exp $ +// $Id: Base.java,v 1.2 2006-10-31 14:00:23 salomo Exp $ package jake2.render.common; +import java.nio.*; + public class Base { public static GenericGL ggl; - // to be initialized! + // to be initialized protected int GL_TEXTURE0 = -1; protected int GL_TEXTURE1 = -1; protected int GL_COLOR_INDEX8_EXT = ggl.GL_COLOR_INDEX; public static final String REF_VERSION = "GL 0.01"; - // up / down public static final int PITCH = 0; // left / right @@ -94,4 +95,60 @@ public class Base { public static final int GL_RENDERER_MCD = 0x01000000; public static final int GL_RENDERER_OTHER = 0x80000000; + // to unify BufferUtils. + + public static final int SIZEOF_BYTE = 1; + public static final int SIZEOF_SHORT = 2; + public static final int SIZEOF_INT = 4; + public static final int SIZEOF_FLOAT = 4; + public static final int SIZEOF_LONG = 8; + public static final int SIZEOF_DOUBLE = 8; + + // ---------------------------------------------------------------------- + // Allocation routines + // + + /** + * Allocates a new direct ByteBuffer with the specified number of elements. + * The returned buffer will have its byte order set to the host platform's + * native byte order. + */ + public static ByteBuffer newByteBuffer(int numElements) { + ByteBuffer bb = ByteBuffer.allocateDirect(numElements); + bb.order(ByteOrder.nativeOrder()); + return bb; + } + + /** Allocates a new direct DoubleBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static DoubleBuffer newDoubleBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_DOUBLE); + return bb.asDoubleBuffer(); + } + + /** Allocates a new direct FloatBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static FloatBuffer newFloatBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT); + return bb.asFloatBuffer(); + } + + /** Allocates a new direct IntBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static IntBuffer newIntBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT); + return bb.asIntBuffer(); + } + + /** Allocates a new direct LongBuffer with the specified number of + elements. The returned buffer will have its byte order set to + the host platform's native byte order. */ + public static LongBuffer newLongBuffer(int numElements) { + ByteBuffer bb = newByteBuffer(numElements * SIZEOF_LONG); + return bb.asLongBuffer(); + } + } diff --git a/src/jake2/render/common/Mesh.java b/src/jake2/render/common/Mesh.java index 182dfc8..f00f982 100644 --- a/src/jake2/render/common/Mesh.java +++ b/src/jake2/render/common/Mesh.java @@ -19,7 +19,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 25.08.2006 by RST. -// $Id: Mesh.java,v 1.1 2006-10-31 13:06:32 salomo Exp $ + +// $Id: Mesh.java,v 1.2 2006-10-31 14:00:23 salomo Exp $ package jake2.render.common; @@ -35,9 +36,6 @@ import jake2.util.Vec3Cache; import java.nio.FloatBuffer; import java.nio.IntBuffer; -import net.java.games.joal.util.BufferUtils; - - public abstract class Mesh extends Light { @@ -57,13 +55,17 @@ public abstract class Mesh extends Light { protected float[] shadedots = r_avertexnormal_dots[0]; // bounding box - protected float[][] bbox = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, - { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }; + protected float[][] bbox = { + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, + { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } + }; /* - * ================== R_InitParticleTexture ================== - */ + ================== + R_InitParticleTexture + ================== + */ protected byte[][] dottexture = { { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 1, 1, 0, 0, 0, 0 }, { 0, 1, 1, 1, 1, 0, 0, 0 }, { 0, 1, 1, 1, 1, 0, 0, 0 }, { 0, 0, 1, 1, 0, 0, 0, 0 }, @@ -140,9 +142,9 @@ public abstract class Mesh extends Light { } } - protected FloatBuffer colorArrayBuf = BufferUtils.newFloatBuffer(qfiles.MAX_VERTS * 4); - protected FloatBuffer vertexArrayBuf = BufferUtils.newFloatBuffer(qfiles.MAX_VERTS * 3); - protected FloatBuffer textureArrayBuf = BufferUtils.newFloatBuffer(qfiles.MAX_VERTS * 2); + protected FloatBuffer colorArrayBuf = newFloatBuffer(qfiles.MAX_VERTS * 4); + protected FloatBuffer vertexArrayBuf = newFloatBuffer(qfiles.MAX_VERTS * 3); + protected FloatBuffer textureArrayBuf = newFloatBuffer(qfiles.MAX_VERTS * 2); protected boolean isFilled = false; @@ -460,9 +462,10 @@ public abstract class Mesh extends Light { } /* - * ================= R_DrawAliasModel - * - * ================= + ================= + R_DrawAliasModel + + ================= */ // TODO sync with jogl renderer. hoz protected void R_DrawAliasModel(entity_t e) { diff --git a/src/jake2/render/common/Misc.java b/src/jake2/render/common/Misc.java index 6464c6b..01865ca 100644 --- a/src/jake2/render/common/Misc.java +++ b/src/jake2/render/common/Misc.java @@ -19,17 +19,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 25.08.2006 by RST. -// $Id: Misc.java,v 1.1 2006-10-31 13:06:32 salomo Exp $ +// $Id: Misc.java,v 1.2 2006-10-31 14:00:23 salomo Exp $ package jake2.render.common; -import jake2.*; -import jake2.client.*; -import jake2.game.*; -import jake2.qcommon.*; -import jake2.render.*; -import jake2.server.*; +import jake2.Defines; +import jake2.client.VID; public abstract class Misc extends Mesh { diff --git a/src/jake2/render/common/Model.java b/src/jake2/render/common/Model.java index 8c585b0..a1cdc3a 100644 --- a/src/jake2/render/common/Model.java +++ b/src/jake2/render/common/Model.java @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Created on 19.08.2006 by RST. -// $Id: Model.java,v 1.1 2006-10-31 13:06:32 salomo Exp $ +// $Id: Model.java,v 1.2 2006-10-31 14:00:23 salomo Exp $ package jake2.render.common; @@ -38,8 +38,6 @@ import java.nio.*; import java.util.Arrays; import java.util.Vector; -import net.java.games.jogl.util.BufferUtils; - /** * model loading and caching. */ @@ -1181,10 +1179,10 @@ public abstract class Model extends Image { protected static final int MODEL_BUFFER_SIZE = 50000; protected static FloatBuffer globalModelTextureCoordBuf = - BufferUtils.newFloatBuffer(MODEL_BUFFER_SIZE * 2); + newFloatBuffer(MODEL_BUFFER_SIZE * 2); protected static IntBuffer globalModelVertexIndexBuf = - BufferUtils.newIntBuffer(MODEL_BUFFER_SIZE); + newIntBuffer(MODEL_BUFFER_SIZE); protected void precompileGLCmds(qfiles.dmdl_t model) { model.textureCoordBuf = globalModelTextureCoordBuf.slice(); diff --git a/src/jake2/render/common/Surf.java b/src/jake2/render/common/Surf.java index b91ad2c..2847b7c 100644 --- a/src/jake2/render/common/Surf.java +++ b/src/jake2/render/common/Surf.java @@ -20,28 +20,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Created on 20.08.2006 by RST. -// $Id: Surf.java,v 1.1 2006-10-31 13:06:32 salomo Exp $ +// $Id: Surf.java,v 1.2 2006-10-31 14:00:23 salomo Exp $ package jake2.render.common; -import java.nio.*; -import java.util.Arrays; - -import org.lwjgl.opengl.GL11; - -import net.java.games.jogl.GL; -import net.java.games.jogl.util.BufferUtils; - -import jake2.*; +import jake2.Defines; import jake2.client.*; -import jake2.game.*; -import jake2.qcommon.*; +import jake2.game.cplane_t; +import jake2.qcommon.Com; import jake2.render.*; -import jake2.render.common.Image.pos_t; -import jake2.server.*; import jake2.util.*; +import java.nio.*; +import java.util.Arrays; public abstract class Surf extends Draw { @@ -462,7 +454,7 @@ public abstract class Surf extends Draw { } } - IntBuffer dummy = BufferUtils.newIntBuffer(128 * 128); + IntBuffer dummy = newIntBuffer(128 * 128); /** * GL_BeginBuildingLightmaps. @@ -597,7 +589,7 @@ public abstract class Surf extends Draw { image.texturechain = null; } - GL_TexEnv(GL.GL_REPLACE); + GL_TexEnv(ggl.GL_REPLACE); } protected void GL_RenderLightmappedPoly(msurface_t surf) { @@ -651,9 +643,9 @@ public abstract class Surf extends Draw { lmtex = surf.lightmaptexturenum; - ggl.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, surf.light_s, + ggl.glTexSubImage2D(ggl.GL_TEXTURE_2D, 0, surf.light_s, surf.light_t, smax, tmax, GL_LIGHTMAP_FORMAT, - GL.GL_UNSIGNED_BYTE, temp); + ggl.GL_UNSIGNED_BYTE, temp); } else { smax = (surf.extents[0] >> 4) + 1; @@ -665,9 +657,9 @@ public abstract class Surf extends Draw { lmtex = 0; - ggl.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, surf.light_s, + ggl.glTexSubImage2D(ggl.GL_TEXTURE_2D, 0, surf.light_s, surf.light_t, smax, tmax, GL_LIGHTMAP_FORMAT, - GL.GL_UNSIGNED_BYTE, temp); + ggl.GL_UNSIGNED_BYTE, temp); } @@ -688,12 +680,12 @@ public abstract class Surf extends Draw { for (p = surf.polys; p != null; p = p.chain) { p.beginScrolling(scroll); - ggl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); + ggl.glDrawArrays(ggl.GL_POLYGON, p.pos, p.numverts); p.endScrolling(); } } else { for (p = surf.polys; p != null; p = p.chain) { - ggl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); + ggl.glDrawArrays(ggl.GL_POLYGON, p.pos, p.numverts); } } // PGM @@ -716,14 +708,14 @@ public abstract class Surf extends Draw { for (p = surf.polys; p != null; p = p.chain) { p.beginScrolling(scroll); - ggl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); + ggl.glDrawArrays(ggl.GL_POLYGON, p.pos, p.numverts); p.endScrolling(); } } else { // PGM // ========== for (p = surf.polys; p != null; p = p.chain) { - ggl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); + ggl.glDrawArrays(ggl.GL_POLYGON, p.pos, p.numverts); } // ========== diff --git a/src/jake2/render/common/Warp.java b/src/jake2/render/common/Warp.java index 66612bb..514c9fa 100644 --- a/src/jake2/render/common/Warp.java +++ b/src/jake2/render/common/Warp.java @@ -19,12 +19,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 20.08.2006 by RST. -// $Id: Warp.java,v 1.1 2006-10-31 13:06:32 salomo Exp $ +// $Id: Warp.java,v 1.2 2006-10-31 14:00:23 salomo Exp $ package jake2.render.common; - -import net.java.games.jogl.GL; import jake2.Defines; import jake2.Globals; import jake2.qcommon.Com; @@ -664,7 +662,7 @@ public abstract class Warp extends Surf { GL_Bind(sky_images[skytexorder[i]].texnum); - ggl.glBegin(GL.GL_QUADS); + ggl.glBegin(ggl.GL_QUADS); MakeSkyVec(skymins[0][i], skymins[1][i], i); MakeSkyVec(skymins[0][i], skymaxs[1][i], i); MakeSkyVec(skymaxs[0][i], skymaxs[1][i], i); -- cgit v1.2.3