summaryrefslogtreecommitdiffstats
path: root/src/jake2
diff options
context:
space:
mode:
Diffstat (limited to 'src/jake2')
-rw-r--r--src/jake2/render/jogl/Model.java4
-rw-r--r--src/jake2/render/jogl/Polygon.java137
-rw-r--r--src/jake2/render/jogl/Surf.java129
-rw-r--r--src/jake2/render/jogl/Warp.java49
4 files changed, 222 insertions, 97 deletions
diff --git a/src/jake2/render/jogl/Model.java b/src/jake2/render/jogl/Model.java
index 2508d69..8ec3d85 100644
--- a/src/jake2/render/jogl/Model.java
+++ b/src/jake2/render/jogl/Model.java
@@ -2,7 +2,7 @@
* Model.java
* Copyright (C) 2003
*
- * $Id: Model.java,v 1.4 2004-07-16 10:11:35 cawe Exp $
+ * $Id: Model.java,v 1.5 2005-01-09 22:34:21 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -1149,6 +1149,8 @@ public abstract class Model extends Surf {
protected void R_BeginRegistration(String model)
{
cvar_t flushmap;
+
+ Polygon.reset();
registration_sequence++;
r_oldviewcluster = -1; // force markleafs
diff --git a/src/jake2/render/jogl/Polygon.java b/src/jake2/render/jogl/Polygon.java
new file mode 100644
index 0000000..5b2db25
--- /dev/null
+++ b/src/jake2/render/jogl/Polygon.java
@@ -0,0 +1,137 @@
+/*
+ * Polygon.java
+ * Copyright (C) 2003
+ *
+ * $Id: Polygon.java,v 1.1 2005-01-09 22:34:21 cawe Exp $
+ */
+/*
+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.jogl;
+
+import jake2.render.glpoly_t;
+
+/**
+ * Polygon
+ *
+ * @author cwei
+ */
+public final class Polygon extends glpoly_t {
+
+ private final static int MAXPOLYS = 20000;
+ private final static int MAX_BUFFER_VERTICES = 120000;
+
+ private static float[] buffer = new float[MAX_BUFFER_VERTICES * STRIDE];
+ private static int bufferIndex = 0;
+ private static int polyCount = 0;
+ private static Polygon[] polyCache = new Polygon[MAXPOLYS];
+ static {
+ for (int i = 0; i < polyCache.length; i++) {
+ polyCache[i] = new Polygon();
+ }
+ }
+
+ public static glpoly_t create(int numverts) {
+ Polygon poly = polyCache[polyCount++];
+ poly.clear();
+ poly.numverts = numverts;
+ poly.pos = bufferIndex;
+ bufferIndex += numverts;
+ return poly;
+ }
+
+ public static void reset() {
+ polyCount = 0;
+ bufferIndex = 0;
+ }
+
+ private Polygon() {
+ }
+
+ private final void clear() {
+ next = null;
+ chain = null;
+ numverts = 0;
+ flags = 0;
+ }
+
+ public final float x(int index) {
+ return buffer[(index + pos) * 7 + 0];
+ }
+
+ public final void x(int index, float value) {
+ buffer[(index + pos) * 7 + 0] = value;
+ }
+
+ public final float y(int index) {
+ return buffer[(index + pos) * 7 + 1];
+ }
+
+ public final void y(int index, float value) {
+ buffer[(index + pos) * 7 + 1] = value;
+ }
+
+ public final float z(int index) {
+ return buffer[(index + pos) * 7 + 2];
+ }
+
+ public final void z(int index, float value) {
+ buffer[(index + pos) * 7 + 2] = value;
+ }
+
+ public final float s1(int index) {
+ return buffer[(index + pos) * 7 + 3];
+ }
+
+ public final void s1(int index, float value) {
+ buffer[(index + pos) * 7 + 3] = value;
+ }
+
+ public final float t1(int index) {
+ return buffer[(index + pos) * 7 + 4];
+ }
+
+ public final void t1(int index, float value) {
+ buffer[(index + pos) * 7 + 4] = value;
+ }
+
+ public final float s2(int index) {
+ return buffer[(index + pos) * 7 + 5];
+ }
+
+ public final void s2(int index, float value) {
+ buffer[(index + pos) * 7 + 5] = value;
+ }
+
+ public final float t2(int index) {
+ return buffer[(index + pos) * 7 + 6];
+ }
+
+ public final void t2(int index, float value) {
+ buffer[(index + pos) * 7 + 6] = value;
+ }
+
+ public final void beginScrolling(float value) {
+ // not in use
+ }
+
+ public final void endScrolling() {
+ // not in use
+ }
+}
diff --git a/src/jake2/render/jogl/Surf.java b/src/jake2/render/jogl/Surf.java
index f4eb76b..7b5e221 100644
--- a/src/jake2/render/jogl/Surf.java
+++ b/src/jake2/render/jogl/Surf.java
@@ -2,7 +2,7 @@
* Surf.java
* Copyright (C) 2003
*
- * $Id: Surf.java,v 1.5 2004-07-16 10:11:35 cawe Exp $
+ * $Id: Surf.java,v 1.6 2005-01-09 22:34:21 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -154,15 +154,11 @@ public abstract class Surf extends Draw {
*/
void DrawGLPoly(glpoly_t p)
{
- int i;
- float[] v;
-
gl.glBegin(GL.GL_POLYGON);
- for (i=0 ; i<p.numverts ; i++)
+ for (int i=0 ; i<p.numverts ; i++)
{
- v = p.verts[i];
- gl.glTexCoord2f(v[3], v[4]);
- gl.glVertex3f(v[0], v[1], v[2]);
+ gl.glTexCoord2f(p.s1(i), p.t1(i));
+ gl.glVertex3f(p.x(i), p.y(i), p.z(i));
}
gl.glEnd();
}
@@ -176,23 +172,16 @@ public abstract class Surf extends Draw {
*/
void DrawGLFlowingPoly(msurface_t fa)
{
- int i;
- float[] v;
- glpoly_t p;
- float scroll;
-
- p = fa.polys;
-
- scroll = -64 * ( (r_newrefdef.time / 40.0f) - (int)(r_newrefdef.time / 40.0f) );
+ float scroll = -64 * ( (r_newrefdef.time / 40.0f) - (int)(r_newrefdef.time / 40.0f) );
if(scroll == 0.0f)
scroll = -64.0f;
gl.glBegin (GL.GL_POLYGON);
- for (i=0 ; i<p.numverts ; i++)
+ glpoly_t p = fa.polys;
+ for (int i=0 ; i<p.numverts ; i++)
{
- v = p.verts[i];
- gl.glTexCoord2f ((v[3] + scroll), v[4]);
- gl.glVertex3f(v[0], v[1], v[2]);
+ gl.glTexCoord2f(p.s1(i) + scroll, p.t1(i));
+ gl.glVertex3f(p.x(i), p.y(i), p.z(i));
}
gl.glEnd ();
}
@@ -204,9 +193,6 @@ public abstract class Surf extends Draw {
*/
void R_DrawTriangleOutlines()
{
- int i, j;
- glpoly_t p;
-
if (gl_showtris.value == 0)
return;
@@ -214,28 +200,27 @@ public abstract class Surf extends Draw {
gl.glDisable (GL.GL_DEPTH_TEST);
gl.glColor4f (1,1,1,1);
- for (i=0 ; i<MAX_LIGHTMAPS ; i++)
+ for (int i=0 ; i<MAX_LIGHTMAPS ; i++)
{
msurface_t surf;
for ( surf = gl_lms.lightmap_surfaces[i]; surf != null; surf = surf.lightmapchain )
{
- p = surf.polys;
+ glpoly_t p = surf.polys;
for ( ; p != null ; p=p.chain)
{
- for (j=2 ; j<p.numverts ; j++ )
+ for (int j=2 ; j<p.numverts ; j++ )
{
gl.glBegin (GL.GL_LINE_STRIP);
- gl.glVertex3fv (p.verts[0]);
- gl.glVertex3fv (p.verts[j-1]);
- gl.glVertex3fv (p.verts[j]);
- gl.glVertex3fv (p.verts[0]);
+ gl.glVertex3f(p.x(0), p.y(0), p.z(0));
+ gl.glVertex3f(p.x(j-1), p.y(j-1), p.z(j-1));
+ gl.glVertex3f(p.x(j), p.y(j), p.z(j));
+ gl.glVertex3f(p.x(0), p.y(0), p.z(0));
gl.glEnd ();
}
}
}
}
-
gl.glEnable (GL.GL_DEPTH_TEST);
gl.glEnable (GL.GL_TEXTURE_2D);
}
@@ -249,15 +234,11 @@ public abstract class Surf extends Draw {
{
for ( ; p != null; p = p.chain )
{
- float[] v;
- int j;
-
gl.glBegin(GL.GL_POLYGON);
- for (j=0 ; j<p.numverts ; j++)
+ for (int j=0 ; j<p.numverts ; j++)
{
- v = p.verts[j];
- gl.glTexCoord2f (v[5], v[6] );
- gl.glVertex3f(v[0], v[1], v[2]);
+ gl.glTexCoord2f (p.s2(j), p.t2(j));
+ gl.glVertex3f(p.x(j), p.y(j), p.z(j));
}
gl.glEnd();
}
@@ -266,15 +247,11 @@ public abstract class Surf extends Draw {
{
for ( ; p != null; p = p.chain )
{
- float[] v;
- int j;
-
gl.glBegin(GL.GL_POLYGON);
- for (j=0 ; j<p.numverts ; j++)
+ for (int j=0 ; j<p.numverts ; j++)
{
- v = p.verts[j];
- gl.glTexCoord2f (v[5] - soffset, v[6] - toffset );
- gl.glVertex3f(v[0], v[1], v[2]);
+ gl.glTexCoord2f (p.s2(j) - soffset, p.t2(j) - toffset);
+ gl.glVertex3f(p.x(j), p.y(j), p.z(j));
}
gl.glEnd();
}
@@ -803,13 +780,11 @@ public abstract class Surf extends Draw {
gl.glBegin (GL.GL_POLYGON);
for (i=0 ; i< nv; i++)
{
- v = p.verts[i];
-
- gl.glMultiTexCoord2fARB(GL_TEXTURE0, (v[3] + scroll), v[4]);
- gl.glMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]);
- //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3], v[4]);
+ gl.glMultiTexCoord2fARB(GL_TEXTURE0, p.s1(i) + scroll, p.t1(i));
+ gl.glMultiTexCoord2fARB(GL_TEXTURE1, p.s2(i), p.t2(i));
+ //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3] + scroll, v[4]);
//gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]);
- gl.glVertex3f(v[0], v[1], v[2]);
+ gl.glVertex3f(p.x(i), p.y(i), p.z(i));
}
gl.glEnd ();
}
@@ -821,13 +796,11 @@ public abstract class Surf extends Draw {
gl.glBegin (GL.GL_POLYGON);
for (i=0 ; i< nv; i++)
{
- v = p.verts[i];
-
- gl.glMultiTexCoord2fARB(GL_TEXTURE0, v[3], v[4]);
- gl.glMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]);
+ gl.glMultiTexCoord2fARB(GL_TEXTURE0, p.s1(i), p.t1(i));
+ gl.glMultiTexCoord2fARB(GL_TEXTURE1, p.s2(i), p.t2(i));
//gglMTexCoord2fSGIS( GL_TEXTURE0, v[3], v[4]);
//gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]);
- gl.glVertex3f(v[0], v[1], v[2]);
+ gl.glVertex3f(p.x(i), p.y(i), p.z(i));
}
gl.glEnd ();
}
@@ -857,13 +830,11 @@ public abstract class Surf extends Draw {
gl.glBegin(GL.GL_POLYGON);
for (i=0 ; i< nv; i++)
{
- v = p.verts[i];
-
- gl.glMultiTexCoord2fARB(GL_TEXTURE0, (v[3]+scroll), v[4]);
- gl.glMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]);
- // qglMTexCoord2fSGIS( GL_TEXTURE0, (v[3]+scroll), v[4]);
- // qglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]);
- gl.glVertex3f(v[0], v[1], v[2]);
+ gl.glMultiTexCoord2fARB(GL_TEXTURE0, p.s1(i) + scroll, p.t1(i));
+ gl.glMultiTexCoord2fARB(GL_TEXTURE1, p.s2(i), p.t2(i));
+ //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3] + scroll, v[4]);
+ //gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]);
+ gl.glVertex3f(p.x(i), p.y(i), p.z(i));
}
gl.glEnd();
}
@@ -877,13 +848,11 @@ public abstract class Surf extends Draw {
gl.glBegin (GL.GL_POLYGON);
for (i=0 ; i< nv; i++)
{
- v = p.verts[i];
-
- gl.glMultiTexCoord2fARB(GL_TEXTURE0, v[3], v[4]);
- gl.glMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]);
+ gl.glMultiTexCoord2fARB(GL_TEXTURE0, p.s1(i), p.t1(i));
+ gl.glMultiTexCoord2fARB(GL_TEXTURE1, p.s2(i), p.t2(i));
//gglMTexCoord2fSGIS( GL_TEXTURE0, v[3], v[4]);
//gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]);
- gl.glVertex3f(v[0], v[1], v[2]);
+ gl.glVertex3f(p.x(i), p.y(i), p.z(i));
}
gl.glEnd ();
}
@@ -1477,12 +1446,11 @@ public abstract class Surf extends Draw {
// draw texture
//
// poly = Hunk_Alloc (sizeof(glpoly_t) + (lnumverts-4) * VERTEXSIZE*sizeof(float));
- poly = new glpoly_t(lnumverts);
+ poly = Polygon.create(lnumverts);
poly.next = fa.polys;
poly.flags = fa.flags;
fa.polys = poly;
- poly.numverts = lnumverts;
for (i=0 ; i<lnumverts ; i++)
{
@@ -1505,9 +1473,15 @@ public abstract class Surf extends Draw {
t /= fa.texinfo.image.height;
Math3D.VectorAdd (total, vec, total);
- Math3D.VectorCopy (vec, poly.verts[i]);
- poly.verts[i][3] = s;
- poly.verts[i][4] = t;
+ //Math3D.VectorCopy (vec, poly.verts[i]);
+ poly.x(i, vec[0]);
+ poly.y(i, vec[1]);
+ poly.z(i, vec[2]);
+
+ //poly.verts[i][3] = s;
+ //poly.verts[i][4] = t;
+ poly.s1(i, s);
+ poly.t1(i, t);
//
// lightmap texture coordinates
@@ -1524,12 +1498,11 @@ public abstract class Surf extends Draw {
t += 8;
t /= BLOCK_HEIGHT*16; //fa.texinfo.texture.height;
- poly.verts[i][5] = s;
- poly.verts[i][6] = t;
+ //poly.verts[i][5] = s;
+ //poly.verts[i][6] = t;
+ poly.s2(i, s);
+ poly.t2(i, t);
}
-
- poly.numverts = lnumverts;
-
}
/*
diff --git a/src/jake2/render/jogl/Warp.java b/src/jake2/render/jogl/Warp.java
index bde9697..58c5081 100644
--- a/src/jake2/render/jogl/Warp.java
+++ b/src/jake2/render/jogl/Warp.java
@@ -2,7 +2,7 @@
* Warp.java
* Copyright (C) 2003
*
- * $Id: Warp.java,v 1.7 2004-09-22 19:22:16 salomo Exp $
+ * $Id: Warp.java,v 1.8 2005-01-09 22:34:21 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -197,16 +197,18 @@ public abstract class Warp extends Model {
// VERTEXSIZE*sizeof(float));
// init polys
- glpoly_t poly = new glpoly_t(numverts + 2);
+ glpoly_t poly = Polygon.create(numverts + 2);
poly.next = warpface.polys;
warpface.polys = poly;
- poly.numverts = numverts + 2;
Math3D.VectorClear(total);
total_s = 0;
total_t = 0;
for (i = 0; i < numverts; i++) {
- Math3D.VectorCopy(verts[i], poly.verts[i + 1]);
+ //Math3D.VectorCopy(verts[i], poly.verts[i + 1]);
+ poly.x(i + 1, verts[i][0]);
+ poly.y(i + 1, verts[i][1]);
+ poly.z(i + 1, verts[i][2]);
s = Math3D.DotProduct(verts[i], warpface.texinfo.vecs[0]);
t = Math3D.DotProduct(verts[i], warpface.texinfo.vecs[1]);
@@ -214,17 +216,27 @@ public abstract class Warp extends Model {
total_t += t;
Math3D.VectorAdd(total, verts[i], total);
- poly.verts[i + 1][3] = s;
- poly.verts[i + 1][4] = t;
+ poly.s1(i + 1, s);
+ poly.t1(i + 1, t);
}
-
- Math3D.VectorScale(total, (1.0f / numverts), poly.verts[0]);
- poly.verts[0][3] = total_s / numverts;
- poly.verts[0][4] = total_t / numverts;
+
+ float scale = 1.0f / numverts;
+ poly.x(0, total[0] * scale);
+ poly.y(0, total[1] * scale);
+ poly.z(0, total[2] * scale);
+ poly.s1(0, total_s * scale);
+ poly.t1(0, total_t * scale);
// memcpy (poly.verts[i+1], poly.verts[1], sizeof(poly.verts[0]));
- System.arraycopy(poly.verts[1], 0, poly.verts[i + 1], 0,
- poly.verts[1].length); // :-)
+// System.arraycopy(poly.verts[1], 0, poly.verts[i + 1], 0,
+// poly.verts[1].length); // :-)
+ poly.x(i + 1, poly.x(1));
+ poly.y(i + 1, poly.y(1));
+ poly.z(i + 1, poly.z(1));
+ poly.s1(i + 1, poly.s1(1));
+ poly.t1(i + 1, poly.t1(1));
+ poly.s2(i + 1, poly.s2(1));
+ poly.t2(i + 1, poly.t2(1));
}
/*
@@ -277,7 +289,6 @@ public abstract class Warp extends Model {
*/
void EmitWaterPolys(msurface_t fa) {
glpoly_t p, bp;
- float[] v;
int i;
float s = 0;
float t = 0;
@@ -295,9 +306,8 @@ public abstract class Warp extends Model {
gl.glBegin(GL.GL_TRIANGLE_FAN);
for (i = 0; i < p.numverts; i++) {
- v = p.verts[i];
- os = v[3];
- ot = v[4];
+ os = p.s1(i);
+ ot = p.t1(i);
s = os
+ Warp.SIN[(int) ((ot * 0.125f + r_newrefdef.time) * TURBSCALE) & 255];
@@ -309,7 +319,7 @@ public abstract class Warp extends Model {
t *= (1.0f / 64);
gl.glTexCoord2f(s, t);
- gl.glVertex3f(v[0], v[1], v[2]);
+ gl.glVertex3f(p.x(i), p.y(i), p.z(i));
}
gl.glEnd();
}
@@ -518,7 +528,10 @@ public abstract class Warp extends Model {
// calculate vertex values for sky box
for (p = fa.polys; p != null; p = p.next) {
for (i = 0; i < p.numverts; i++) {
- Math3D.VectorSubtract(p.verts[i], r_origin, verts[i]);
+ //Math3D.VectorSubtract(p.verts[i], r_origin, verts[i]);
+ verts[i][0] = p.x(i) - r_origin[0];
+ verts[i][1] = p.y(i) - r_origin[1];
+ verts[i][2] = p.z(i) - r_origin[2];
}
ClipSkyPolygon(p.numverts, verts, 0);
}