From: Carsten W. <ca...@us...> - 2005-01-16 15:25:01
|
Update of /cvsroot/jake2/jake2/src/jake2/render/fastjogl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26647/src/jake2/render/fastjogl Modified Files: Mesh.java Warp.java Surf.java Light.java Log Message: changes to use the Vec3Cache instead of new float[3] (faster) Index: Light.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/render/fastjogl/Light.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Light.java 12 Jan 2005 12:14:27 -0000 1.10 --- Light.java 16 Jan 2005 15:24:50 -0000 1.11 *************** *** 32,39 **** 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.util.Math3D; import java.nio.ByteBuffer; --- 32,38 ---- import jake2.qcommon.Com; import jake2.qcommon.longjmpException; ! import jake2.render.*; import jake2.util.Math3D; + import jake2.util.Vec3Cache; import java.nio.ByteBuffer; *************** *** 64,74 **** void R_RenderDlight(dlight_t light) { ! int i, j; ! float a; ! float[] v = { 0, 0, 0 }; ! float rad; ! ! rad = light.intensity * 0.35f; ! Math3D.VectorSubtract(light.origin, r_origin, v); --- 63,68 ---- void R_RenderDlight(dlight_t light) { ! float rad = light.intensity * 0.35f; ! float[] v = Vec3Cache.get(); Math3D.VectorSubtract(light.origin, r_origin, v); *************** *** 76,86 **** gl.glColor3f(light.color[0] * 0.2f, light.color[1] * 0.2f, light.color[2] * 0.2f); ! for (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--) { a = (float) (i / 16.0f * Math.PI * 2); ! for (j = 0; j < 3; j++) v[j] = (float) (light.origin[j] + vright[j] * Math.cos(a) * rad + vup[j] * Math.sin(a) * rad); --- 70,82 ---- gl.glColor3f(light.color[0] * 0.2f, light.color[1] * 0.2f, light.color[2] * 0.2f); ! 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); ! float a; ! for (int i = 16; i >= 0; i--) { a = (float) (i / 16.0f * Math.PI * 2); ! 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); *************** *** 88,91 **** --- 84,88 ---- } gl.glEnd(); + Vec3Cache.release(); } *************** *** 128,142 **** */ 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) - splitplane.dist; --- 125,133 ---- */ void R_MarkLights(dlight_t light, int bit, mnode_t node) { if (node.contents != -1) return; ! cplane_t splitplane = node.plane; ! float dist = Math3D.DotProduct(light.origin, splitplane.normal) - splitplane.dist; *************** *** 150,155 **** } // mark the polygons ! for (i = 0; i < node.numsurfaces; i++) { surf = r_worldmodel.surfaces[node.firstsurface + i]; --- 141,148 ---- } + msurface_t surf; + int sidebit; // mark the polygons ! for (int i = 0; i < node.numsurfaces; i++) { surf = r_worldmodel.surfaces[node.firstsurface + i]; *************** *** 182,194 **** */ 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++) { l = r_newrefdef.dlights[i]; R_MarkLights(l, 1 << i, r_worldmodel.nodes[0]); --- 175,186 ---- */ void R_PushDlights() { if (gl_flashblend.value != 0) return; r_dlightframecount = r_framecount + 1; // because the count hasn't + // advanced yet for this frame ! 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]); *************** *** 216,225 **** return -1; // didn't hit anything ! msurface_t surf; ! int s, t, ds, dt; ! int i; ! mtexinfo_t tex; ! ByteBuffer lightmap; ! int maps; // calculate mid point --- 208,213 ---- return -1; // didn't hit anything ! // ByteBuffer lightmap; ! // int maps; // calculate mid point *************** *** 236,240 **** float frac = front / (front - back); ! float[] mid = { 0, 0, 0 }; mid[0] = start[0] + (end[0] - start[0]) * frac; mid[1] = start[1] + (end[1] - start[1]) * frac; --- 224,228 ---- float frac = front / (front - back); ! float[] mid = Vec3Cache.get(); mid[0] = start[0] + (end[0] - start[0]) * frac; mid[1] = start[1] + (end[1] - start[1]) * frac; *************** *** 243,251 **** // go down front side int r = RecursiveLightPoint(node.children[sideIndex], start, mid); ! if (r >= 0) return r; // hit something ! if ((back < 0) == side) return -1; // didn't hit anuthing // check for impact on this node --- 231,243 ---- // go down front side int r = RecursiveLightPoint(node.children[sideIndex], start, mid); ! if (r >= 0) { ! Vec3Cache.release(); return r; // hit something + } ! if ((back < 0) == side) { ! Vec3Cache.release(); return -1; // didn't hit anuthing + } // check for impact on this node *************** *** 254,261 **** int surfIndex = node.firstsurface; float scale0; float scale1; float scale2; ! for (i = 0; i < node.numsurfaces; i++, surfIndex++) { surf = r_worldmodel.surfaces[surfIndex]; --- 246,260 ---- int surfIndex = node.firstsurface; + + msurface_t surf; + mtexinfo_t tex; float scale0; float scale1; float scale2; ! int s, t, ds, dt; ! ByteBuffer lightmap; ! int maps; ! ! for (int i = 0; i < node.numsurfaces; i++, surfIndex++) { surf = r_worldmodel.surfaces[surfIndex]; *************** *** 308,316 **** } } return 1; } // go down back side ! return RecursiveLightPoint(node.children[1 - sideIndex], mid, end); } --- 307,318 ---- } } + Vec3Cache.release(); return 1; } // go down back side ! r = RecursiveLightPoint(node.children[1 - sideIndex], mid, end); ! Vec3Cache.release(); ! return r; } *************** *** 327,331 **** } ! float[] end = { 0, 0, 0 }; end[0] = p[0]; end[1] = p[1]; --- 329,333 ---- } ! float[] end = Vec3Cache.get(); end[0] = p[0]; end[1] = p[1]; *************** *** 357,360 **** --- 359,363 ---- Math3D.VectorScale(color, gl_modulate.value, color); + Vec3Cache.release(); } *************** *** 370,374 **** int sd, td; float fdist, frad, fminlight; ! float[] impact = { 0, 0, 0 }; int s, t; dlight_t dl; --- 373,377 ---- int sd, td; float fdist, frad, fminlight; ! float[] impact = Vec3Cache.get(); int s, t; dlight_t dl; *************** *** 433,436 **** --- 436,440 ---- } } + Vec3Cache.release(); } Index: Warp.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/render/fastjogl/Warp.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Warp.java 10 Jan 2005 00:05:23 -0000 1.6 --- Warp.java 16 Jan 2005 15:24:50 -0000 1.7 *************** *** 31,34 **** --- 31,35 ---- import jake2.render.*; import jake2.util.Math3D; + import jake2.util.Vec3Cache; import net.java.games.jogl.GL; *************** *** 348,353 **** 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; --- 349,352 ---- *************** *** 356,363 **** --- 355,364 ---- 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]); *************** *** 379,382 **** --- 380,385 ---- axis = 4; } + + Vec3Cache.release(2); // v, av // project new texture coords *************** *** 527,533 **** */ void R_ClearSkyBox() { ! int i; ! ! for (i = 0; i < 6; i++) { skymins[0][i] = skymins[1][i] = 9999; skymaxs[0][i] = skymaxs[1][i] = -9999; --- 530,534 ---- */ void R_ClearSkyBox() { ! for (int i = 0; i < 6; i++) { skymins[0][i] = skymins[1][i] = 9999; skymaxs[0][i] = skymaxs[1][i] = -9999; *************** *** 536,548 **** void MakeSkyVec(float s, float t, int axis) { ! float[] v = { 0, 0, 0 }; ! float[] b = { 0, 0, 0 }; ! int j, k; ! b[0] = s * 2300; b[1] = t * 2300; b[2] = 2300; ! for (j = 0; j < 3; j++) { k = st_to_vec[axis][j]; if (k < 0) --- 537,549 ---- void MakeSkyVec(float s, float t, int axis) { ! float[] b = Vec3Cache.get(); b[0] = s * 2300; b[1] = t * 2300; b[2] = 2300; ! float[] v = Vec3Cache.get(); ! int k; ! ! for (int j = 0; j < 3; j++) { k = st_to_vec[axis][j]; if (k < 0) *************** *** 568,571 **** --- 569,574 ---- gl.glTexCoord2f(s, t); gl.glVertex3f(v[0], v[1], v[2]); + + Vec3Cache.release(2); // b, v } *************** *** 577,581 **** void R_DrawSkyBox() { int i; ! if (skyrotate != 0) { // check for no sky at all for (i = 0; i < 6; i++) --- 580,584 ---- void R_DrawSkyBox() { int i; ! if (skyrotate != 0) { // check for no sky at all for (i = 0; i < 6; i++) Index: Mesh.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/render/fastjogl/Mesh.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Mesh.java 22 Sep 2004 19:22:11 -0000 1.6 --- Mesh.java 16 Jan 2005 15:24:50 -0000 1.7 *************** *** 32,35 **** --- 32,36 ---- import jake2.render.image_t; import jake2.util.Math3D; + import jake2.util.Vec3Cache; import java.nio.FloatBuffer; *************** *** 138,144 **** 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]; --- 139,142 ---- *************** *** 163,166 **** --- 161,165 ---- 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, *************** *** 169,172 **** --- 168,172 ---- vectors[2]); + float[] move = Vec3Cache.get(); // vec3_t move[0] = Math3D.DotProduct(frontv, vectors[0]); // forward move[1] = -Math3D.DotProduct(frontv, vectors[1]); // left *************** *** 175,178 **** --- 175,179 ---- 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]; *************** *** 184,187 **** --- 185,190 ---- GL_LerpVerts(paliashdr.num_xyz, ov, verts, move, frontv, backv); + + Vec3Cache.release(3); // frontv, move, backv //gl.glEnableClientState( GL.GL_VERTEX_ARRAY ); *************** *** 273,277 **** qfiles.dtrivertx_t[] verts; int[] order; - float[] point = { 0, 0, 0 }; float height, lheight; int count; --- 276,279 ---- *************** *** 295,298 **** --- 297,301 ---- // TODO shadow drawing with vertex arrays + float[] point = Vec3Cache.get(); while (true) { // get the vertex count and primitive type *************** *** 323,326 **** --- 326,330 ---- gl.glEnd(); } + Vec3Cache.release(); // point } *************** *** 330,336 **** // 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; --- 334,337 ---- *************** *** 353,356 **** --- 354,360 ---- * * compute axially aligned mins and maxs */ + float[] mins = Vec3Cache.get(); + float[] maxs = Vec3Cache.get(); + if (pframe == poldframe) { for (int i = 0; i < 3; i++) { *************** *** 416,419 **** --- 420,425 ---- Math3D.VectorAdd(e.origin, bbox[i], bbox[i]); } + + Vec3Cache.release(2); // mins, maxs int f, mask; Index: Surf.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/render/fastjogl/Surf.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Surf.java 10 Jan 2005 00:14:33 -0000 1.7 --- Surf.java 16 Jan 2005 15:24:50 -0000 1.8 *************** *** 31,34 **** --- 31,35 ---- import jake2.qcommon.Com; import jake2.render.*; + import jake2.util.*; import jake2.util.Lib; import jake2.util.Math3D; *************** *** 611,619 **** */ 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; --- 612,615 ---- *************** *** 622,628 **** gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1; if (e.angles[0] != 0 || e.angles[1] != 0 || e.angles[2] != 0) { rotated = true; ! for (i = 0; i < 3; i++) { mins[i] = e.origin[i] - currentmodel.radius; maxs[i] = e.origin[i] + currentmodel.radius; --- 618,627 ---- 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 (int i = 0; i < 3; i++) { mins[i] = e.origin[i] - currentmodel.radius; maxs[i] = e.origin[i] + currentmodel.radius; *************** *** 634,639 **** } ! if (R_CullBox(mins, maxs)) return; gl.glColor3f(1, 1, 1); --- 633,642 ---- } ! if (R_CullBox(mins, maxs)) { ! Vec3Cache.release(2); // mins, maxs return; + } + + Vec3Cache.release(2); // mins, maxs gl.glColor3f(1, 1, 1); *************** *** 647,654 **** 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 }; Math3D.VectorCopy(modelorg, temp); --- 650,657 ---- Math3D.VectorSubtract(r_newrefdef.vieworg, e.origin, modelorg); if (rotated) { ! float[] temp = Vec3Cache.get(); ! float[] forward = Vec3Cache.get(); ! float[] right = Vec3Cache.get(); ! float[] up = Vec3Cache.get(); Math3D.VectorCopy(modelorg, temp); *************** *** 657,660 **** --- 660,665 ---- modelorg[1] = -Math3D.DotProduct(temp, right); modelorg[2] = Math3D.DotProduct(temp, up); + + Vec3Cache.release(4); // temp, forward, right, up } *************** *** 813,821 **** * ============= R_DrawWorld ============= */ 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) --- 818,824 ---- * ============= R_DrawWorld ============= */ + entity_t worldEnt = new entity_t(); + void R_DrawWorld() { if (r_drawworld.value == 0) *************** *** 828,831 **** --- 831,840 ---- 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; *************** *** 1042,1053 **** float[] vec; float s, t; ! float[] total = { 0, 0, 0 }; ! ! // reconstruct the polygon pedges = currentmodel.edges; lnumverts = fa.numedges; vertpage = 0; - Math3D.VectorClear(total); // // draw texture --- 1051,1059 ---- float[] vec; float s, t; ! // reconstruct the polygon pedges = currentmodel.edges; lnumverts = fa.numedges; vertpage = 0; // // draw texture *************** *** 1077,1082 **** t /= fa.texinfo.image.height; ! Math3D.VectorAdd(total, vec, total); ! poly.x(i, vec[0]); poly.y(i, vec[1]); poly.z(i, vec[2]); --- 1083,1087 ---- t /= fa.texinfo.image.height; ! poly.x(i, vec[0]); poly.y(i, vec[1]); poly.z(i, vec[2]); *************** *** 1157,1166 **** void GL_BeginBuildingLightmaps(model_t m) { // static lightstyle_t lightstyles[MAX_LIGHTSTYLES]; ! int i; ! ! // init lightstyles if (lightstyles == null) { lightstyles = new lightstyle_t[Defines.MAX_LIGHTSTYLES]; ! for (i = 0; i < lightstyles.length; i++) { lightstyles[i] = new lightstyle_t(); } --- 1162,1169 ---- void GL_BeginBuildingLightmaps(model_t m) { // static lightstyle_t lightstyles[MAX_LIGHTSTYLES]; ! // init lightstyles if (lightstyles == null) { lightstyles = new lightstyle_t[Defines.MAX_LIGHTSTYLES]; ! for (int i = 0; i < lightstyles.length; i++) { lightstyles[i] = new lightstyle_t(); } *************** *** 1179,1183 **** * regenerated * the first time they're seen */ ! for (i = 0; i < Defines.MAX_LIGHTSTYLES; i++) { lightstyles[i].rgb[0] = 1; lightstyles[i].rgb[1] = 1; --- 1182,1186 ---- * regenerated * the first time they're seen */ ! for (int i = 0; i < Defines.MAX_LIGHTSTYLES; i++) { lightstyles[i].rgb[0] = 1; lightstyles[i].rgb[1] = 1; |