aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/render/fastjogl
diff options
context:
space:
mode:
authorCarsten Weisse <[email protected]>2005-01-16 15:24:50 +0000
committerCarsten Weisse <[email protected]>2005-01-16 15:24:50 +0000
commit982b32358c7425a6d6ba309926ff2c4e07a4f846 (patch)
tree62502de97f3714c69d4dc0939dc355a16447b7af /src/jake2/render/fastjogl
parent206af6f53316086e446cfc93a761e4eab6d9ce72 (diff)
changes to use the Vec3Cache instead of new float[3]
(faster)
Diffstat (limited to 'src/jake2/render/fastjogl')
-rw-r--r--src/jake2/render/fastjogl/Light.java84
-rw-r--r--src/jake2/render/fastjogl/Mesh.java22
-rw-r--r--src/jake2/render/fastjogl/Surf.java57
-rw-r--r--src/jake2/render/fastjogl/Warp.java27
4 files changed, 103 insertions, 87 deletions
diff --git a/src/jake2/render/fastjogl/Light.java b/src/jake2/render/fastjogl/Light.java
index 208946b..f617e9f 100644
--- a/src/jake2/render/fastjogl/Light.java
+++ b/src/jake2/render/fastjogl/Light.java
@@ -2,7 +2,7 @@
* Light.java
* Copyright (C) 2003
*
- * $Id: Light.java,v 1.10 2005-01-12 12:14:27 hzi Exp $
+ * $Id: Light.java,v 1.11 2005-01-16 15:24:50 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -31,10 +31,9 @@ import jake2.client.dlight_t;
import jake2.game.cplane_t;
import jake2.qcommon.Com;
import jake2.qcommon.longjmpException;
-import jake2.render.mnode_t;
-import jake2.render.msurface_t;
-import jake2.render.mtexinfo_t;
+import jake2.render.*;
import jake2.util.Math3D;
+import jake2.util.Vec3Cache;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
@@ -63,30 +62,28 @@ public abstract class Light extends Warp {
*/
void R_RenderDlight(dlight_t light) {
- int i, j;
- float a;
- float[] v = { 0, 0, 0 };
- float rad;
-
- rad = light.intensity * 0.35f;
-
+ float rad = light.intensity * 0.35f;
+ float[] v = Vec3Cache.get();
Math3D.VectorSubtract(light.origin, r_origin, v);
gl.glBegin(GL.GL_TRIANGLE_FAN);
gl.glColor3f(light.color[0] * 0.2f, light.color[1] * 0.2f,
light.color[2] * 0.2f);
- for (i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++)
v[i] = light.origin[i] - vpn[i] * rad;
+
gl.glVertex3f(v[0], v[1], v[2]);
gl.glColor3f(0, 0, 0);
- for (i = 16; i >= 0; i--) {
+ float a;
+ for (int i = 16; i >= 0; i--) {
a = (float) (i / 16.0f * Math.PI * 2);
- for (j = 0; j < 3; j++)
+ for (int j = 0; j < 3; j++)
v[j] = (float) (light.origin[j] + vright[j] * Math.cos(a) * rad + vup[j]
* Math.sin(a) * rad);
gl.glVertex3f(v[0], v[1], v[2]);
}
gl.glEnd();
+ Vec3Cache.release();
}
/*
@@ -127,17 +124,11 @@ public abstract class Light extends Warp {
* ============= R_MarkLights =============
*/
void R_MarkLights(dlight_t light, int bit, mnode_t node) {
- cplane_t splitplane;
- float dist;
- msurface_t surf;
- int i;
- int sidebit;
-
if (node.contents != -1)
return;
- splitplane = node.plane;
- dist = Math3D.DotProduct(light.origin, splitplane.normal)
+ cplane_t splitplane = node.plane;
+ float dist = Math3D.DotProduct(light.origin, splitplane.normal)
- splitplane.dist;
if (dist > light.intensity - DLIGHT_CUTOFF) {
@@ -149,8 +140,10 @@ public abstract class Light extends Warp {
return;
}
+ msurface_t surf;
+ int sidebit;
// mark the polygons
- for (i = 0; i < node.numsurfaces; i++) {
+ for (int i = 0; i < node.numsurfaces; i++) {
surf = r_worldmodel.surfaces[node.firstsurface + i];
@@ -181,15 +174,14 @@ public abstract class Light extends Warp {
* ============= R_PushDlights =============
*/
void R_PushDlights() {
- int i;
- dlight_t l;
-
if (gl_flashblend.value != 0)
return;
r_dlightframecount = r_framecount + 1; // because the count hasn't
+
// advanced yet for this frame
- for (i = 0; i < r_newrefdef.num_dlights; i++) {
+ dlight_t l;
+ for (int i = 0; i < r_newrefdef.num_dlights; i++) {
l = r_newrefdef.dlights[i];
R_MarkLights(l, 1 << i, r_worldmodel.nodes[0]);
}
@@ -215,12 +207,8 @@ public abstract class Light extends Warp {
if (node.contents != -1)
return -1; // didn't hit anything
- msurface_t surf;
- int s, t, ds, dt;
- int i;
- mtexinfo_t tex;
- ByteBuffer lightmap;
- int maps;
+// ByteBuffer lightmap;
+// int maps;
// calculate mid point
@@ -235,28 +223,39 @@ public abstract class Light extends Warp {
return RecursiveLightPoint(node.children[sideIndex], start, end);
float frac = front / (front - back);
- float[] mid = { 0, 0, 0 };
+ float[] mid = Vec3Cache.get();
mid[0] = start[0] + (end[0] - start[0]) * frac;
mid[1] = start[1] + (end[1] - start[1]) * frac;
mid[2] = start[2] + (end[2] - start[2]) * frac;
// go down front side
int r = RecursiveLightPoint(node.children[sideIndex], start, mid);
- if (r >= 0)
+ if (r >= 0) {
+ Vec3Cache.release();
return r; // hit something
+ }
- if ((back < 0) == side)
+ if ((back < 0) == side) {
+ Vec3Cache.release();
return -1; // didn't hit anuthing
+ }
// check for impact on this node
Math3D.VectorCopy(mid, lightspot);
lightplane = plane;
int surfIndex = node.firstsurface;
+
+ msurface_t surf;
+ mtexinfo_t tex;
float scale0;
float scale1;
float scale2;
- for (i = 0; i < node.numsurfaces; i++, surfIndex++) {
+ int s, t, ds, dt;
+ ByteBuffer lightmap;
+ int maps;
+
+ for (int i = 0; i < node.numsurfaces; i++, surfIndex++) {
surf = r_worldmodel.surfaces[surfIndex];
if ((surf.flags & (Defines.SURF_DRAWTURB | Defines.SURF_DRAWSKY)) != 0)
@@ -307,11 +306,14 @@ public abstract class Light extends Warp {
* ((surf.extents[1] >> 4) + 1);
}
}
+ Vec3Cache.release();
return 1;
}
// go down back side
- return RecursiveLightPoint(node.children[1 - sideIndex], mid, end);
+ r = RecursiveLightPoint(node.children[1 - sideIndex], mid, end);
+ Vec3Cache.release();
+ return r;
}
/*
@@ -326,7 +328,7 @@ public abstract class Light extends Warp {
return;
}
- float[] end = { 0, 0, 0 };
+ float[] end = Vec3Cache.get();
end[0] = p[0];
end[1] = p[1];
end[2] = p[2] - 2048;
@@ -356,6 +358,7 @@ public abstract class Light extends Warp {
}
Math3D.VectorScale(color, gl_modulate.value, color);
+ Vec3Cache.release();
}
// ===================================================================
@@ -369,7 +372,7 @@ public abstract class Light extends Warp {
void R_AddDynamicLights(msurface_t surf) {
int sd, td;
float fdist, frad, fminlight;
- float[] impact = { 0, 0, 0 };
+ float[] impact = Vec3Cache.get();
int s, t;
dlight_t dl;
float[] pfBL;
@@ -432,6 +435,7 @@ public abstract class Light extends Warp {
}
}
}
+ Vec3Cache.release();
}
/*
diff --git a/src/jake2/render/fastjogl/Mesh.java b/src/jake2/render/fastjogl/Mesh.java
index 63c8ad4..a5b86b6 100644
--- a/src/jake2/render/fastjogl/Mesh.java
+++ b/src/jake2/render/fastjogl/Mesh.java
@@ -2,7 +2,7 @@
* Mesh.java
* Copyright (C) 2003
*
- * $Id: Mesh.java,v 1.6 2004-09-22 19:22:11 salomo Exp $
+ * $Id: Mesh.java,v 1.7 2005-01-16 15:24:50 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -31,6 +31,7 @@ import jake2.client.entity_t;
import jake2.qcommon.qfiles;
import jake2.render.image_t;
import jake2.util.Math3D;
+import jake2.util.Vec3Cache;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
@@ -137,9 +138,6 @@ public abstract class Mesh extends Light {
int count;
float alpha;
- float[] move = { 0, 0, 0 }; // vec3_t
- float[] frontv = { 0, 0, 0 }; // vec3_t
- float[] backv = { 0, 0, 0 }; // vec3_t
qfiles.daliasframe_t frame = paliashdr.aliasFrames[currententity.frame];
@@ -162,18 +160,21 @@ public abstract class Mesh extends Light {
float frontlerp = 1.0f - backlerp;
+ float[] frontv = Vec3Cache.get(); // vec3_t
// move should be the delta back to the previous frame * backlerp
Math3D.VectorSubtract(currententity.oldorigin, currententity.origin,
frontv);
Math3D.AngleVectors(currententity.angles, vectors[0], vectors[1],
vectors[2]);
+ float[] move = Vec3Cache.get(); // vec3_t
move[0] = Math3D.DotProduct(frontv, vectors[0]); // forward
move[1] = -Math3D.DotProduct(frontv, vectors[1]); // left
move[2] = Math3D.DotProduct(frontv, vectors[2]); // up
Math3D.VectorAdd(move, oldframe.translate, move);
+ float[] backv = Vec3Cache.get(); // vec3_t
for (int i = 0; i < 3; i++) {
move[i] = backlerp * move[i] + frontlerp * frame.translate[i];
frontv[i] = frontlerp * frame.scale[i];
@@ -183,6 +184,8 @@ public abstract class Mesh extends Light {
// ab hier wird optimiert
GL_LerpVerts(paliashdr.num_xyz, ov, verts, move, frontv, backv);
+
+ Vec3Cache.release(3); // frontv, move, backv
//gl.glEnableClientState( GL.GL_VERTEX_ARRAY );
gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertexArrayBuf);
@@ -272,7 +275,6 @@ public abstract class Mesh extends Light {
void GL_DrawAliasShadow(qfiles.dmdl_t paliashdr, int posenum) {
qfiles.dtrivertx_t[] verts;
int[] order;
- float[] point = { 0, 0, 0 };
float height, lheight;
int count;
qfiles.daliasframe_t frame;
@@ -294,6 +296,7 @@ public abstract class Mesh extends Light {
// TODO shadow drawing with vertex arrays
+ float[] point = Vec3Cache.get();
while (true) {
// get the vertex count and primitive type
count = order[orderIndex++];
@@ -322,6 +325,7 @@ public abstract class Mesh extends Light {
gl.glEnd();
}
+ Vec3Cache.release(); // point
}
/*
@@ -329,9 +333,6 @@ public abstract class Mesh extends Light {
*/
// TODO sync with jogl renderer. hoz
boolean R_CullAliasModel(entity_t e) {
- float[] mins = { 0, 0, 0 };
- float[] maxs = { 0, 0, 0 };
-
qfiles.dmdl_t paliashdr = (qfiles.dmdl_t) currentmodel.extradata;
if ((e.frame >= paliashdr.num_frames) || (e.frame < 0)) {
@@ -352,6 +353,9 @@ public abstract class Mesh extends Light {
/*
* * compute axially aligned mins and maxs
*/
+ float[] mins = Vec3Cache.get();
+ float[] maxs = Vec3Cache.get();
+
if (pframe == poldframe) {
for (int i = 0; i < 3; i++) {
mins[i] = pframe.translate[i];
@@ -415,6 +419,8 @@ public abstract class Mesh extends Light {
Math3D.VectorAdd(e.origin, bbox[i], bbox[i]);
}
+
+ Vec3Cache.release(2); // mins, maxs
int f, mask;
int aggregatemask = ~0; // 0xFFFFFFFF
diff --git a/src/jake2/render/fastjogl/Surf.java b/src/jake2/render/fastjogl/Surf.java
index 5220a97..d9748d8 100644
--- a/src/jake2/render/fastjogl/Surf.java
+++ b/src/jake2/render/fastjogl/Surf.java
@@ -2,7 +2,7 @@
* Surf.java
* Copyright (C) 2003
*
- * $Id: Surf.java,v 1.7 2005-01-10 00:14:33 cawe Exp $
+ * $Id: Surf.java,v 1.8 2005-01-16 15:24:50 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -30,6 +30,7 @@ import jake2.client.*;
import jake2.game.cplane_t;
import jake2.qcommon.Com;
import jake2.render.*;
+import jake2.util.*;
import jake2.util.Lib;
import jake2.util.Math3D;
@@ -610,20 +611,18 @@ public abstract class Surf extends Draw {
* ================= R_DrawBrushModel =================
*/
void R_DrawBrushModel(entity_t e) {
- float[] mins = { 0, 0, 0 };
- float[] maxs = { 0, 0, 0 };
- int i;
- boolean rotated;
-
if (currentmodel.nummodelsurfaces == 0)
return;
currententity = e;
gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1;
+ float[] mins = Vec3Cache.get();
+ float[] maxs = Vec3Cache.get();
+ boolean rotated;
if (e.angles[0] != 0 || e.angles[1] != 0 || e.angles[2] != 0) {
rotated = true;
- for (i = 0; i < 3; i++) {
+ for (int i = 0; i < 3; i++) {
mins[i] = e.origin[i] - currentmodel.radius;
maxs[i] = e.origin[i] + currentmodel.radius;
}
@@ -633,8 +632,12 @@ public abstract class Surf extends Draw {
Math3D.VectorAdd(e.origin, currentmodel.maxs, maxs);
}
- if (R_CullBox(mins, maxs))
+ if (R_CullBox(mins, maxs)) {
+ Vec3Cache.release(2); // mins, maxs
return;
+ }
+
+ Vec3Cache.release(2); // mins, maxs
gl.glColor3f(1, 1, 1);
@@ -646,16 +649,18 @@ public abstract class Surf extends Draw {
Math3D.VectorSubtract(r_newrefdef.vieworg, e.origin, modelorg);
if (rotated) {
- float[] temp = { 0, 0, 0 };
- float[] forward = { 0, 0, 0 };
- float[] right = { 0, 0, 0 };
- float[] up = { 0, 0, 0 };
+ float[] temp = Vec3Cache.get();
+ float[] forward = Vec3Cache.get();
+ float[] right = Vec3Cache.get();
+ float[] up = Vec3Cache.get();
Math3D.VectorCopy(modelorg, temp);
Math3D.AngleVectors(e.angles, forward, right, up);
modelorg[0] = Math3D.DotProduct(temp, forward);
modelorg[1] = -Math3D.DotProduct(temp, right);
modelorg[2] = Math3D.DotProduct(temp, up);
+
+ Vec3Cache.release(4); // temp, forward, right, up
}
gl.glPushMatrix();
@@ -812,11 +817,9 @@ public abstract class Surf extends Draw {
/*
* ============= R_DrawWorld =============
*/
+ entity_t worldEnt = new entity_t();
+
void R_DrawWorld() {
- entity_t ent = new entity_t();
- // auto cycle the world frame for texture animation
- ent.frame = (int) (r_newrefdef.time * 2);
- currententity = ent;
if (r_drawworld.value == 0)
return;
@@ -827,6 +830,12 @@ public abstract class Surf extends Draw {
currentmodel = r_worldmodel;
Math3D.VectorCopy(r_newrefdef.vieworg, modelorg);
+
+ entity_t ent = worldEnt;
+ // auto cycle the world frame for texture animation
+ ent.clear();
+ ent.frame = (int) (r_newrefdef.time * 2);
+ currententity = ent;
gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1;
@@ -1041,14 +1050,11 @@ public abstract class Surf extends Draw {
int vertpage;
float[] vec;
float s, t;
- float[] total = { 0, 0, 0 };
-
- // reconstruct the polygon
+ // reconstruct the polygon
pedges = currentmodel.edges;
lnumverts = fa.numedges;
vertpage = 0;
- Math3D.VectorClear(total);
//
// draw texture
//
@@ -1076,8 +1082,7 @@ public abstract class Surf extends Draw {
+ fa.texinfo.vecs[1][3];
t /= fa.texinfo.image.height;
- Math3D.VectorAdd(total, vec, total);
- poly.x(i, vec[0]);
+ poly.x(i, vec[0]);
poly.y(i, vec[1]);
poly.z(i, vec[2]);
poly.s1(i, s);
@@ -1156,12 +1161,10 @@ public abstract class Surf extends Draw {
*/
void GL_BeginBuildingLightmaps(model_t m) {
// static lightstyle_t lightstyles[MAX_LIGHTSTYLES];
- int i;
-
- // init lightstyles
+ // init lightstyles
if (lightstyles == null) {
lightstyles = new lightstyle_t[Defines.MAX_LIGHTSTYLES];
- for (i = 0; i < lightstyles.length; i++) {
+ for (int i = 0; i < lightstyles.length; i++) {
lightstyles[i] = new lightstyle_t();
}
}
@@ -1178,7 +1181,7 @@ public abstract class Surf extends Draw {
* * setup the base lightstyles so the lightmaps won't have to be
* regenerated * the first time they're seen
*/
- for (i = 0; i < Defines.MAX_LIGHTSTYLES; i++) {
+ for (int i = 0; i < Defines.MAX_LIGHTSTYLES; i++) {
lightstyles[i].rgb[0] = 1;
lightstyles[i].rgb[1] = 1;
lightstyles[i].rgb[2] = 1;
diff --git a/src/jake2/render/fastjogl/Warp.java b/src/jake2/render/fastjogl/Warp.java
index 9d5f1c2..d8687a4 100644
--- a/src/jake2/render/fastjogl/Warp.java
+++ b/src/jake2/render/fastjogl/Warp.java
@@ -2,7 +2,7 @@
* Warp.java
* Copyright (C) 2003
*
- * $Id: Warp.java,v 1.6 2005-01-10 00:05:23 cawe Exp $
+ * $Id: Warp.java,v 1.7 2005-01-16 15:24:50 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -30,6 +30,7 @@ import jake2.Globals;
import jake2.qcommon.Com;
import jake2.render.*;
import jake2.util.Math3D;
+import jake2.util.Vec3Cache;
import net.java.games.jogl.GL;
/**
@@ -347,18 +348,18 @@ public abstract class Warp extends Model {
void DrawSkyPolygon(int nump, float[][] vecs) {
int i, j;
- float[] v = { 0, 0, 0 };
- float[] av = { 0, 0, 0 };
float s, t, dv;
int axis;
float[] vp;
c_sky++;
// decide which face it maps to
+ float[] v = Vec3Cache.get();
Math3D.VectorCopy(Globals.vec3_origin, v);
for (i = 0; i < nump; i++) {
Math3D.VectorAdd(vecs[i], v, v);
}
+ float[] av = Vec3Cache.get();
av[0] = Math.abs(v[0]);
av[1] = Math.abs(v[1]);
av[2] = Math.abs(v[2]);
@@ -378,6 +379,8 @@ public abstract class Warp extends Model {
else
axis = 4;
}
+
+ Vec3Cache.release(2); // v, av
// project new texture coords
for (i = 0; i < nump; i++) {
@@ -526,24 +529,22 @@ public abstract class Warp extends Model {
* ============== R_ClearSkyBox ==============
*/
void R_ClearSkyBox() {
- int i;
-
- for (i = 0; i < 6; i++) {
+ for (int i = 0; i < 6; i++) {
skymins[0][i] = skymins[1][i] = 9999;
skymaxs[0][i] = skymaxs[1][i] = -9999;
}
}
void MakeSkyVec(float s, float t, int axis) {
- float[] v = { 0, 0, 0 };
- float[] b = { 0, 0, 0 };
- int j, k;
-
+ float[] b = Vec3Cache.get();
b[0] = s * 2300;
b[1] = t * 2300;
b[2] = 2300;
- for (j = 0; j < 3; j++) {
+ float[] v = Vec3Cache.get();
+ int k;
+
+ for (int j = 0; j < 3; j++) {
k = st_to_vec[axis][j];
if (k < 0)
v[j] = -b[-k - 1];
@@ -567,6 +568,8 @@ public abstract class Warp extends Model {
t = 1.0f - t;
gl.glTexCoord2f(s, t);
gl.glVertex3f(v[0], v[1], v[2]);
+
+ Vec3Cache.release(2); // b, v
}
/*
@@ -576,7 +579,7 @@ public abstract class Warp extends Model {
void R_DrawSkyBox() {
int i;
-
+
if (skyrotate != 0) { // check for no sky at all
for (i = 0; i < 6; i++)
if (skymins[0][i] < skymaxs[0][i]