From: Carsten W. <ca...@us...> - 2005-01-09 22:36:50
|
Update of /cvsroot/jake2/jake2/src/jake2/render/fastjogl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32096/src/jake2/render/fastjogl Modified Files: Warp.java Model.java Surf.java Added Files: Polygon.java Log Message: the Polygon implementation (FloatBuffer as backbuffer) and the changes to use the interface Index: Warp.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/render/fastjogl/Warp.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Warp.java 22 Sep 2004 19:22:11 -0000 1.4 --- Warp.java 9 Jan 2005 22:36:30 -0000 1.5 *************** *** 201,214 **** // init polys ! glpoly_t poly = new glpoly_t(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]); s = Math3D.DotProduct(verts[i], warpface.texinfo.vecs[0]); t = Math3D.DotProduct(verts[i], warpface.texinfo.vecs[1]); --- 201,215 ---- // init polys ! glpoly_t poly = Polygon.create(numverts + 2); poly.next = warpface.polys; warpface.polys = poly; Math3D.VectorClear(total); total_s = 0; total_t = 0; for (i = 0; i < numverts; i++) { ! 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]); *************** *** 218,234 **** Math3D.VectorAdd(total, verts[i], total); ! poly.verts[i + 1][3] = s; ! poly.verts[i + 1][4] = t; } ! ! Math3D.VectorScale(total, (1.0f / numverts), poly.verts[0]); ! poly.verts[0][3] = total_s / numverts; ! poly.verts[0][4] = total_t / numverts; // 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); // :-) ! ! precompilePolygon(poly); } --- 219,241 ---- Math3D.VectorAdd(total, verts[i], total); ! poly.s1(i + 1, s); ! poly.t1(i + 1, t); } ! ! 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])); ! 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)); } *************** *** 283,287 **** void EmitWaterPolys(msurface_t fa) { glpoly_t p, bp; - float[] v; int i; float s = 0; --- 290,293 ---- *************** *** 297,310 **** scroll = 0; - int index; - FloatBuffer texCoord = globalPolygonInterleavedBuf; for (bp = fa.polys; bp != null; bp = bp.next) { p = bp; ! index = p.pos * POLYGON_STRIDE; for (i = 0; i < p.numverts; i++) { ! v = p.verts[i]; ! os = v[3]; ! ot = v[4]; s = os --- 303,313 ---- scroll = 0; for (bp = fa.polys; bp != null; bp = bp.next) { p = bp; ! gl.glBegin(GL.GL_TRIANGLE_FAN); for (i = 0; i < p.numverts; i++) { ! os = p.s1(i); ! ot = p.t1(i); s = os *************** *** 317,325 **** t *= (1.0f / 64); ! texCoord.put(index, s); ! texCoord.put(index + 1, t); ! index += POLYGON_STRIDE; } ! gl.glDrawArrays(GL.GL_TRIANGLE_FAN, p.pos, p.numverts); } } --- 320,327 ---- t *= (1.0f / 64); ! gl.glTexCoord2f(s, t); ! gl.glVertex3f(p.x(i), p.y(i), p.z(i)); } ! gl.glEnd(); } } *************** *** 522,532 **** */ void R_AddSkySurface(msurface_t fa) { - int i; - glpoly_t p; - // 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]); } ClipSkyPolygon(p.numverts, verts, 0); --- 524,533 ---- */ void R_AddSkySurface(msurface_t fa) { // calculate vertex values for sky box ! for (glpoly_t p = fa.polys; p != null; p = p.next) { ! for (int i = 0; i < p.numverts; 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); Index: Surf.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/render/fastjogl/Surf.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Surf.java 22 Sep 2004 19:22:11 -0000 1.5 --- Surf.java 9 Jan 2005 22:36:31 -0000 1.6 *************** *** 173,192 **** */ void DrawGLFlowingPoly(glpoly_t p) { ! int i; ! float scroll; ! ! scroll = -64 * ((r_newrefdef.time / 40.0f) - (int) (r_newrefdef.time / 40.0f)); if (scroll == 0.0f) scroll = -64.0f; ! FloatBuffer texCoord = globalPolygonInterleavedBuf; ! float[][] v = p.verts; ! int index = p.pos * POLYGON_STRIDE; ! for (i = 0; i < p.numverts; i++) { ! texCoord.put(index, v[i][3] + scroll); ! index += POLYGON_STRIDE; ! } gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); } --- 173,184 ---- */ void DrawGLFlowingPoly(glpoly_t p) { ! float scroll = -64 * ((r_newrefdef.time / 40.0f) - (int) (r_newrefdef.time / 40.0f)); if (scroll == 0.0f) scroll = -64.0f; ! p.beginScrolling(scroll); gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); + p.endScrolling(); } *************** *** 198,205 **** */ void R_DrawTriangleOutlines() { ! int i, j; ! glpoly_t p; ! ! if (gl_showtris.value == 0) return; --- 190,194 ---- */ void R_DrawTriangleOutlines() { ! if (gl_showtris.value == 0) return; *************** *** 208,223 **** gl.glColor4f(1, 1, 1, 1); ! for (i = 0; i < MAX_LIGHTMAPS; i++) { ! msurface_t surf; ! ! for (surf = gl_lms.lightmap_surfaces[i]; surf != null; surf = surf.lightmapchain) { ! p = surf.polys; ! for (; p != null; p = p.chain) { ! for (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.glEnd(); } --- 197,209 ---- gl.glColor4f(1, 1, 1, 1); ! for (int i = 0; i < MAX_LIGHTMAPS; i++) { ! for (msurface_t surf = gl_lms.lightmap_surfaces[i]; surf != null; surf = surf.lightmapchain) { ! for (glpoly_t p = surf.polys; p != null; p = p.chain) { ! for (int j = 2; j < p.numverts; j++) { gl.glBegin(GL.GL_LINE_STRIP); ! 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(); } *************** *** 352,356 **** intens = gl_state.inverse_intensity; ! gl.glInterleavedArrays(GL.GL_T2F_V3F, POLYGON_BYTE_STRIDE, globalPolygonInterleavedBuf); --- 338,342 ---- intens = gl_state.inverse_intensity; ! gl.glInterleavedArrays(GL.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf); *************** *** 520,530 **** for (p = surf.polys; p != null; p = p.chain) { ! v = p.verts; ! index = p.pos * POLYGON_STRIDE; ! for (i = 0; i < p.numverts; i++) { ! texCoord.put(index, v[i][3] + scroll); ! index += POLYGON_STRIDE; ! } gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); } } else { --- 506,512 ---- for (p = surf.polys; p != null; p = p.chain) { ! p.beginScrolling(scroll); gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); + p.endScrolling(); } } else { *************** *** 552,562 **** for (p = surf.polys; p != null; p = p.chain) { ! v = p.verts; ! index = p.pos * POLYGON_STRIDE; ! for (i = 0; i < p.numverts; i++) { ! texCoord.put(index, v[i][3] + scroll); ! index += POLYGON_STRIDE; ! } gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); } } else { --- 534,540 ---- for (p = surf.polys; p != null; p = p.chain) { ! p.beginScrolling(scroll); gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); + p.endScrolling(); } } else { *************** *** 703,711 **** GL_SelectTexture(GL_TEXTURE0); GL_TexEnv(GL.GL_REPLACE); ! gl.glInterleavedArrays(GL.GL_T2F_V3F, POLYGON_BYTE_STRIDE, globalPolygonInterleavedBuf); GL_SelectTexture(GL_TEXTURE1); GL_TexEnv(GL.GL_MODULATE); ! gl.glTexCoordPointer(2, GL.GL_FLOAT, POLYGON_BYTE_STRIDE, globalPolygonTexCoord1Buf); gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); --- 681,689 ---- GL_SelectTexture(GL_TEXTURE0); GL_TexEnv(GL.GL_REPLACE); ! gl.glInterleavedArrays(GL.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf); GL_SelectTexture(GL_TEXTURE1); GL_TexEnv(GL.GL_MODULATE); ! gl.glTexCoordPointer(2, GL.GL_FLOAT, Polygon.BYTE_STRIDE, globalPolygonTexCoord1Buf); gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); *************** *** 876,883 **** GL_SelectTexture(GL_TEXTURE0); GL_TexEnv(GL.GL_REPLACE); ! gl.glInterleavedArrays(GL.GL_T2F_V3F, POLYGON_BYTE_STRIDE, globalPolygonInterleavedBuf); GL_SelectTexture(GL_TEXTURE1); ! gl.glTexCoordPointer(2, GL.GL_FLOAT, POLYGON_BYTE_STRIDE, globalPolygonTexCoord1Buf); gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); --- 854,861 ---- GL_SelectTexture(GL_TEXTURE0); GL_TexEnv(GL.GL_REPLACE); ! gl.glInterleavedArrays(GL.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf); GL_SelectTexture(GL_TEXTURE1); ! gl.glTexCoordPointer(2, GL.GL_FLOAT, Polygon.BYTE_STRIDE, globalPolygonTexCoord1Buf); gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); *************** *** 1075,1079 **** float[] vec; float s, t; - glpoly_t poly; float[] total = { 0, 0, 0 }; --- 1053,1056 ---- *************** *** 1087,1098 **** // draw texture // ! // poly = Hunk_Alloc (sizeof(glpoly_t) + (lnumverts-4) * ! // VERTEXSIZE*sizeof(float)); ! poly = new glpoly_t(lnumverts); poly.next = fa.polys; poly.flags = fa.flags; fa.polys = poly; - poly.numverts = lnumverts; for (i = 0; i < lnumverts; i++) { --- 1064,1072 ---- // draw texture // ! glpoly_t poly = Polygon.create(lnumverts); poly.next = fa.polys; poly.flags = fa.flags; fa.polys = poly; for (i = 0; i < lnumverts; i++) { *************** *** 1115,1121 **** Math3D.VectorAdd(total, vec, total); ! Math3D.VectorCopy(vec, poly.verts[i]); ! poly.verts[i][3] = s; ! poly.verts[i][4] = t; // --- 1089,1097 ---- Math3D.VectorAdd(total, vec, total); ! poly.x(i, vec[0]); ! poly.y(i, vec[1]); ! poly.z(i, vec[2]); ! poly.s1(i, s); ! poly.t1(i, t); // *************** *** 1136,1147 **** t /= BLOCK_HEIGHT * 16; //fa.texinfo.texture.height; ! poly.verts[i][5] = s; ! poly.verts[i][6] = t; } - - poly.numverts = lnumverts; - - precompilePolygon(poly); - } --- 1112,1118 ---- t /= BLOCK_HEIGHT * 16; //fa.texinfo.texture.height; ! poly.s2(i, s); ! poly.t2(i, t); } } *************** *** 1285,1337 **** /* ! * new functions for vertex array handling */ ! static final int POLYGON_BUFFER_SIZE = 120000; ! ! static final int POLYGON_STRIDE = 7; ! ! static final int POLYGON_BYTE_STRIDE = POLYGON_STRIDE ! * BufferUtils.SIZEOF_FLOAT; ! ! static FloatBuffer globalPolygonInterleavedBuf = BufferUtils ! .newFloatBuffer(POLYGON_BUFFER_SIZE * 7); static FloatBuffer globalPolygonTexCoord1Buf = null; static { ! globalPolygonInterleavedBuf.position(POLYGON_STRIDE - 2); globalPolygonTexCoord1Buf = globalPolygonInterleavedBuf.slice(); globalPolygonInterleavedBuf.position(0); }; ! void precompilePolygon(glpoly_t p) { ! ! p.pos = globalPolygonInterleavedBuf.position() / POLYGON_STRIDE; ! ! float[] v; ! FloatBuffer buffer = globalPolygonInterleavedBuf; ! ! for (int i = 0; i < p.verts.length; i++) { ! v = p.verts[i]; ! // textureCoord0 ! buffer.put(v[3]); ! buffer.put(v[4]); ! ! // vertex ! buffer.put(v[0]); ! buffer.put(v[1]); ! buffer.put(v[2]); ! ! // textureCoord1 ! buffer.put(v[5]); ! buffer.put(v[6]); ! } ! } ! ! public static void resetPolygonArrays() { ! globalPolygonInterleavedBuf.rewind(); ! } ! ! //ImageFrame frame; // void debugLightmap(byte[] buf, int w, int h, float scale) { --- 1256,1272 ---- /* ! * new buffers for vertex array handling */ ! static FloatBuffer globalPolygonInterleavedBuf = Polygon.getInterleavedBuffer(); static FloatBuffer globalPolygonTexCoord1Buf = null; static { ! globalPolygonInterleavedBuf.position(Polygon.STRIDE - 2); globalPolygonTexCoord1Buf = globalPolygonInterleavedBuf.slice(); globalPolygonInterleavedBuf.position(0); }; ! //ImageFrame frame; // void debugLightmap(byte[] buf, int w, int h, float scale) { --- NEW FILE: Polygon.java --- /* * Polygon.java * Copyright (C) 2003 * * $Id: Polygon.java,v 1.1 2005/01/09 22:36:31 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.fastjogl; import java.nio.FloatBuffer; import jake2.Defines; import jake2.render.glpoly_t; import jake2.util.Lib; /** * Polygon * * @author cwei */ public final class Polygon extends glpoly_t { private final static int MAX_POLYS = 20000; private final static int MAX_BUFFER_VERTICES = 120000; // backup for s1 scrolling private static float[] s1_old = new float[MAX_VERTICES]; private static FloatBuffer buffer = Lib.newFloatBuffer(MAX_BUFFER_VERTICES * STRIDE); private static int bufferIndex = 0; private static int polyCount = 0; private static Polygon[] polyCache = new Polygon[MAX_POLYS]; static { for (int i = 0; i < polyCache.length; i++) { polyCache[i] = new Polygon(); } } static glpoly_t create(int numverts) { Polygon poly = polyCache[polyCount++]; poly.clear(); poly.numverts = numverts; poly.pos = bufferIndex; bufferIndex += numverts; return poly; } static void reset() { polyCount = 0; bufferIndex = 0; } static FloatBuffer getInterleavedBuffer() { return (FloatBuffer)buffer.rewind(); } private Polygon() { } private final void clear() { next = null; chain = null; numverts = 0; flags = 0; } // the interleaved buffer has the format: // textureCoord0 (index 0, 1) // vertex (index 2, 3, 4) // textureCoord1 (index 5, 6) public final float x(int index) { return buffer.get((index + pos) * 7 + 2); } public final void x(int index, float value) { buffer.put((index + pos) * 7 + 2, value); } public final float y(int index) { return buffer.get((index + pos) * 7 + 3); } public final void y(int index, float value) { buffer.put((index + pos) * 7 + 3, value); } public final float z(int index) { return buffer.get((index + pos) * 7 + 4); } public final void z(int index, float value) { buffer.put((index + pos) * 7 + 4, value); } public final float s1(int index) { return buffer.get((index + pos) * 7 + 0); } public final void s1(int index, float value) { buffer.put((index + pos) * 7 + 0, value); } public final float t1(int index) { return buffer.get((index + pos) * 7 + 1); } public final void t1(int index, float value) { buffer.put((index + pos) * 7 + 1, value); } public final float s2(int index) { return buffer.get((index + pos) * 7 + 5); } public final void s2(int index, float value) { buffer.put((index + pos) * 7 + 5, value); } public final float t2(int index) { return buffer.get((index + pos) * 7 + 6); } public final void t2(int index, float value) { buffer.put((index + pos) * 7 + 6, value); } public final void beginScrolling(float scroll) { int index = pos * 7; for (int i = 0; i < numverts; i++, index+=7) { scroll += s1_old[i] = buffer.get(index); buffer.put(index, scroll); } } public final void endScrolling() { int index = pos * 7; for (int i = 0; i < numverts; i++, index+=7) { buffer.put(index, s1_old[i]); } } } Index: Model.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/render/fastjogl/Model.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Model.java 22 Sep 2004 19:22:10 -0000 1.5 --- Model.java 9 Jan 2005 22:36:31 -0000 1.6 *************** *** 1090,1094 **** protected void R_BeginRegistration(String model) { resetModelArrays(); ! resetPolygonArrays(); cvar_t flushmap; --- 1090,1095 ---- protected void R_BeginRegistration(String model) { resetModelArrays(); ! // resetPolygonArrays(); ! Polygon.reset(); cvar_t flushmap; |