diff options
Diffstat (limited to 'src/jake2/render/jogl/Surf.java')
-rw-r--r-- | src/jake2/render/jogl/Surf.java | 126 |
1 files changed, 54 insertions, 72 deletions
diff --git a/src/jake2/render/jogl/Surf.java b/src/jake2/render/jogl/Surf.java index 7f05332..54e0e77 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.2 2004-07-08 20:24:30 hzi Exp $ + * $Id: Surf.java,v 1.3 2004-07-09 06:50:48 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -25,35 +25,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package jake2.render.jogl; -import java.awt.geom.AffineTransform; -import java.awt.image.AffineTransformOp; -import java.awt.image.BufferedImage; -import java.nio.ByteBuffer; +import jake2.Defines; +import jake2.client.*; +import jake2.game.cplane_t; +import jake2.render.*; +import jake2.util.Lib; +import jake2.util.Math3D; + import java.nio.ByteOrder; import java.nio.IntBuffer; import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; import net.java.games.jogl.GL; -import net.java.games.jogl.util.BufferUtils; - -import jake2.Defines; -import jake2.client.dlight_t; -import jake2.client.entity_t; -import jake2.client.lightstyle_t; -import jake2.game.cplane_t; -import jake2.imageio.ImageFrame; -import jake2.render.glpoly_t; -import jake2.render.image_t; -import jake2.render.medge_t; -import jake2.render.mleaf_t; -import jake2.render.mnode_t; -import jake2.render.model_t; -import jake2.render.msurface_t; -import jake2.render.mtexinfo_t; -import jake2.util.Lib; -import jake2.util.Math3D; /** * Surf @@ -92,7 +75,7 @@ public abstract class Surf extends Draw { // the lightmap texture data needs to be kept in // main memory so texsubimage can update properly - byte[] lightmap_buffer = new byte[4 * BLOCK_WIDTH * BLOCK_HEIGHT]; + IntBuffer lightmap_buffer = Lib.newIntBuffer(BLOCK_WIDTH * BLOCK_HEIGHT, ByteOrder.LITTLE_ENDIAN); public gllightmapstate_t() { @@ -129,7 +112,7 @@ public abstract class Surf extends Draw { // Light.java abstract void R_MarkLights (dlight_t light, int bit, mnode_t node); abstract void R_SetCacheState( msurface_t surf ); - abstract void R_BuildLightMap(msurface_t surf, ByteBuffer dest, int stride); + abstract void R_BuildLightMap(msurface_t surf, IntBuffer dest, int stride); /* ============================================================= @@ -178,7 +161,7 @@ public abstract class Surf extends Draw { { v = p.verts[i]; gl.glTexCoord2f(v[3], v[4]); - gl.glVertex3fv(v); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd(); } @@ -208,7 +191,7 @@ public abstract class Surf extends Draw { { v = p.verts[i]; gl.glTexCoord2f ((v[3] + scroll), v[4]); - gl.glVertex3fv( v ); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd (); } @@ -273,7 +256,7 @@ public abstract class Surf extends Draw { { v = p.verts[j]; gl.glTexCoord2f (v[5], v[6] ); - gl.glVertex3fv( v ); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd(); } @@ -290,7 +273,7 @@ public abstract class Surf extends Draw { { v = p.verts[j]; gl.glTexCoord2f (v[5] - soffset, v[6] - toffset ); - gl.glVertex3fv( v ); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd(); } @@ -399,7 +382,7 @@ public abstract class Surf extends Draw { for ( surf = gl_lms.lightmap_surfaces[0]; surf != null; surf = surf.lightmapchain ) { int smax, tmax; - ByteBuffer base; + IntBuffer base; smax = (surf.extents[0]>>4)+1; tmax = (surf.extents[1]>>4)+1; @@ -412,10 +395,10 @@ public abstract class Surf extends Draw { surf.dlight_s = lightPos.x; surf.dlight_t = lightPos.y; - base = ByteBuffer.wrap(gl_lms.lightmap_buffer); - base.position( ( surf.dlight_t * BLOCK_WIDTH + surf.dlight_s ) * LIGHTMAP_BYTES); + base = gl_lms.lightmap_buffer; + base.position(surf.dlight_t * BLOCK_WIDTH + surf.dlight_s ); - R_BuildLightMap (surf, base, BLOCK_WIDTH*LIGHTMAP_BYTES); + R_BuildLightMap (surf, base.slice(), BLOCK_WIDTH); } else { @@ -448,10 +431,10 @@ public abstract class Surf extends Draw { surf.dlight_s = lightPos.x; surf.dlight_t = lightPos.y; - base = ByteBuffer.wrap(gl_lms.lightmap_buffer); - base.position( ( surf.dlight_t * BLOCK_WIDTH + surf.dlight_s ) * LIGHTMAP_BYTES); + base = gl_lms.lightmap_buffer; + base.position(surf.dlight_t * BLOCK_WIDTH + surf.dlight_s ); - R_BuildLightMap (surf, base, BLOCK_WIDTH*LIGHTMAP_BYTES); + R_BuildLightMap (surf, base.slice(), BLOCK_WIDTH); } } @@ -476,7 +459,7 @@ public abstract class Surf extends Draw { gl.glDepthMask( true ); } - private ByteBuffer temp2 = BufferUtils.newByteBuffer(34 * 34 * 4); + private IntBuffer temp2 = Lib.newIntBuffer(34 * 34, ByteOrder.LITTLE_ENDIAN); /* ================ @@ -562,7 +545,7 @@ public abstract class Surf extends Draw { smax = (fa.extents[0]>>4)+1; tmax = (fa.extents[1]>>4)+1; - R_BuildLightMap( fa, temp2, smax*4 ); + R_BuildLightMap( fa, temp2, smax); R_SetCacheState( fa ); GL_Bind( gl_state.lightmap_textures + fa.lightmaptexturenum ); @@ -717,7 +700,7 @@ public abstract class Surf extends Draw { } // direct buffer - ByteBuffer temp = BufferUtils.newByteBuffer(128 * 128 * 4); + private IntBuffer temp = Lib.newIntBuffer(128 * 128, ByteOrder.LITTLE_ENDIAN); void GL_RenderLightmappedPoly( msurface_t surf ) { @@ -766,7 +749,7 @@ public abstract class Surf extends Draw { smax = (surf.extents[0]>>4)+1; tmax = (surf.extents[1]>>4)+1; - R_BuildLightMap( surf, temp, smax*4 ); + R_BuildLightMap( surf, temp, smax); R_SetCacheState( surf ); GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + surf.lightmaptexturenum ); @@ -785,7 +768,7 @@ public abstract class Surf extends Draw { smax = (surf.extents[0]>>4)+1; tmax = (surf.extents[1]>>4)+1; - R_BuildLightMap( surf, temp, smax*4 ); + R_BuildLightMap( surf, temp, smax); GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + 0 ); @@ -825,7 +808,7 @@ public abstract class Surf extends Draw { gl.glMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]); //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3], v[4]); //gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]); - gl.glVertex3fv(v); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd (); } @@ -843,7 +826,7 @@ public abstract class Surf extends Draw { gl.glMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]); //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3], v[4]); //gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]); - gl.glVertex3fv(v); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd (); } @@ -879,7 +862,7 @@ public abstract class Surf extends Draw { gl.glMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]); // qglMTexCoord2fSGIS( GL_TEXTURE0, (v[3]+scroll), v[4]); // qglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]); - gl.glVertex3fv(v); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd(); } @@ -899,7 +882,7 @@ public abstract class Surf extends Draw { gl.glMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]); //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3], v[4]); //gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]); - gl.glVertex3fv(v); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd (); } @@ -1558,7 +1541,7 @@ public abstract class Surf extends Draw { void GL_CreateSurfaceLightmap(msurface_t surf) { int smax, tmax; - ByteBuffer base; + IntBuffer base; if ( (surf.flags & (Defines.SURF_DRAWSKY | Defines.SURF_DRAWTURB)) != 0) return; @@ -1585,13 +1568,12 @@ public abstract class Surf extends Draw { surf.lightmaptexturenum = gl_lms.current_lightmap_texture; - // base = gl_lms.lightmap_buffer; - base = ByteBuffer.wrap(gl_lms.lightmap_buffer); - int basep = (surf.light_t * BLOCK_WIDTH + surf.light_s) * LIGHTMAP_BYTES; + int basep = (surf.light_t * BLOCK_WIDTH + surf.light_s);// * LIGHTMAP_BYTES; + base = gl_lms.lightmap_buffer; base.position(basep); R_SetCacheState( surf ); - R_BuildLightMap(surf, base.slice(), BLOCK_WIDTH * LIGHTMAP_BYTES); + R_BuildLightMap(surf, base.slice(), BLOCK_WIDTH); } lightstyle_t[] lightstyles; @@ -1713,26 +1695,26 @@ public abstract class Surf extends Draw { } - ImageFrame frame; + //ImageFrame frame; - void debugLightmap(byte[] buf, int w, int h, float scale) { - IntBuffer pix = ByteBuffer.wrap(buf).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer(); - - int[] pixel = new int[w * h]; - - pix.get(pixel); - - BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR); - image.setRGB(0, 0, w, h, pixel, 0, w); - AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(scale, scale), AffineTransformOp.TYPE_NEAREST_NEIGHBOR); - BufferedImage tmp = op.filter(image, null); - - if (frame == null) { - frame = new ImageFrame(null); - frame.show(); - } - frame.showImage(tmp); - - } +// void debugLightmap(byte[] buf, int w, int h, float scale) { +// IntBuffer pix = ByteBuffer.wrap(buf).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer(); +// +// int[] pixel = new int[w * h]; +// +// pix.get(pixel); +// +// BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR); +// image.setRGB(0, 0, w, h, pixel, 0, w); +// AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(scale, scale), AffineTransformOp.TYPE_NEAREST_NEIGHBOR); +// BufferedImage tmp = op.filter(image, null); +// +// if (frame == null) { +// frame = new ImageFrame(null); +// frame.show(); +// } +// frame.showImage(tmp); +// +// } } |