diff options
author | Carsten Weisse <[email protected]> | 2005-01-09 22:36:31 +0000 |
---|---|---|
committer | Carsten Weisse <[email protected]> | 2005-01-09 22:36:31 +0000 |
commit | 2fb37c78fb3ef89482b20b0521e6f1c63bba36c3 (patch) | |
tree | adbb88f3114984c42910a8608e37c3570cf8f9e1 /src/jake2/render/fastjogl/Surf.java | |
parent | 1e005eacf3cd42609500e1953803029967a1f366 (diff) |
the Polygon implementation (FloatBuffer as backbuffer) and the changes to use the interface
Diffstat (limited to 'src/jake2/render/fastjogl/Surf.java')
-rw-r--r-- | src/jake2/render/fastjogl/Surf.java | 133 |
1 files changed, 34 insertions, 99 deletions
diff --git a/src/jake2/render/fastjogl/Surf.java b/src/jake2/render/fastjogl/Surf.java index e15e1d8..752d83f 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.5 2004-09-22 19:22:11 salomo Exp $ + * $Id: Surf.java,v 1.6 2005-01-09 22:36:31 cawe Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -172,22 +172,14 @@ public abstract class Surf extends Draw { * scrolling texture ================ */ void DrawGLFlowingPoly(glpoly_t p) { - int i; - float scroll; - - scroll = -64 + float 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; - } + p.beginScrolling(scroll); gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); + p.endScrolling(); } // PGM @@ -197,28 +189,22 @@ public abstract class Surf extends Draw { * * R_DrawTriangleOutlines */ void R_DrawTriangleOutlines() { - int i, j; - glpoly_t p; - - if (gl_showtris.value == 0) + if (gl_showtris.value == 0) return; gl.glDisable(GL.GL_TEXTURE_2D); gl.glDisable(GL.GL_DEPTH_TEST); 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++) { + 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.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(); } } @@ -351,7 +337,7 @@ public abstract class Surf extends Draw { // so scale it back down intens = gl_state.inverse_intensity; - gl.glInterleavedArrays(GL.GL_T2F_V3F, POLYGON_BYTE_STRIDE, + gl.glInterleavedArrays(GL.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf); for (s = r_alpha_surfaces; s != null; s = s.texturechain) { @@ -519,13 +505,9 @@ public abstract class Surf extends Draw { scroll = -64.0f; 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; - } + p.beginScrolling(scroll); gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); + p.endScrolling(); } } else { for (p = surf.polys; p != null; p = p.chain) { @@ -551,13 +533,9 @@ public abstract class Surf extends Draw { scroll = -64.0f; 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; - } + p.beginScrolling(scroll); gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); + p.endScrolling(); } } else { // PGM @@ -702,11 +680,11 @@ public abstract class Surf extends Draw { GL_EnableMultitexture(true); GL_SelectTexture(GL_TEXTURE0); GL_TexEnv(GL.GL_REPLACE); - gl.glInterleavedArrays(GL.GL_T2F_V3F, POLYGON_BYTE_STRIDE, + 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, + gl.glTexCoordPointer(2, GL.GL_FLOAT, Polygon.BYTE_STRIDE, globalPolygonTexCoord1Buf); gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); @@ -875,10 +853,10 @@ public abstract class Surf extends Draw { GL_SelectTexture(GL_TEXTURE0); GL_TexEnv(GL.GL_REPLACE); - gl.glInterleavedArrays(GL.GL_T2F_V3F, POLYGON_BYTE_STRIDE, + gl.glInterleavedArrays(GL.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf); GL_SelectTexture(GL_TEXTURE1); - gl.glTexCoordPointer(2, GL.GL_FLOAT, POLYGON_BYTE_STRIDE, + gl.glTexCoordPointer(2, GL.GL_FLOAT, Polygon.BYTE_STRIDE, globalPolygonTexCoord1Buf); gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); @@ -1074,7 +1052,6 @@ public abstract class Surf extends Draw { int vertpage; float[] vec; float s, t; - glpoly_t poly; float[] total = { 0, 0, 0 }; // reconstruct the polygon @@ -1086,14 +1063,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); + glpoly_t poly = Polygon.create(lnumverts); poly.next = fa.polys; poly.flags = fa.flags; fa.polys = poly; - poly.numverts = lnumverts; for (i = 0; i < lnumverts; i++) { lindex = currentmodel.surfedges[fa.firstedge + i]; @@ -1114,9 +1088,11 @@ 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; + poly.x(i, vec[0]); + poly.y(i, vec[1]); + poly.z(i, vec[2]); + poly.s1(i, s); + poly.t1(i, t); // // lightmap texture coordinates @@ -1135,14 +1111,9 @@ 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.s2(i, s); + poly.t2(i, t); } - - poly.numverts = lnumverts; - - precompilePolygon(poly); - } /* @@ -1284,55 +1255,19 @@ public abstract class Surf extends Draw { } /* - * new functions for vertex array handling + * new buffers 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 globalPolygonInterleavedBuf = Polygon.getInterleavedBuffer(); static FloatBuffer globalPolygonTexCoord1Buf = null; static { - globalPolygonInterleavedBuf.position(POLYGON_STRIDE - 2); + 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; + //ImageFrame frame; // void debugLightmap(byte[] buf, int w, int h, float scale) { // IntBuffer pix = |