aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/render
diff options
context:
space:
mode:
authorHolger Zickner <[email protected]>2004-07-08 20:24:48 +0000
committerHolger Zickner <[email protected]>2004-07-08 20:24:48 +0000
commit252832999fa43bce63ca4b643fab5d9dd51fccc4 (patch)
tree98570c65819059d14f0809ae964aa1c6c93684a0 /src/jake2/render
parent4f13ea26c4f47e54e66926f0700cf631e7bb3352 (diff)
import of Jake2 version cebit
Diffstat (limited to 'src/jake2/render')
-rw-r--r--src/jake2/render/jogl/Image.java357
-rw-r--r--src/jake2/render/jogl/Impl.java21
-rw-r--r--src/jake2/render/jogl/Light.java242
-rw-r--r--src/jake2/render/jogl/Mesh.java6
-rw-r--r--src/jake2/render/jogl/Surf.java351
-rw-r--r--src/jake2/render/jogl/Warp.java5
-rw-r--r--src/jake2/render/msurface_t.java43
7 files changed, 539 insertions, 486 deletions
diff --git a/src/jake2/render/jogl/Image.java b/src/jake2/render/jogl/Image.java
index 0f29750..4e65481 100644
--- a/src/jake2/render/jogl/Image.java
+++ b/src/jake2/render/jogl/Image.java
@@ -2,7 +2,7 @@
* Image.java
* Copyright (C) 2003
*
- * $Id: Image.java,v 1.1 2004-07-07 19:59:38 hzi Exp $
+ * $Id: Image.java,v 1.2 2004-07-08 20:24:30 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -549,204 +549,179 @@ public abstract class Image extends Main {
//
// =========================================================
// */
- //
- // typedef struct _TargaHeader {
- // unsigned char id_length, colormap_type, image_type;
- // unsigned short colormap_index, colormap_length;
- // unsigned char colormap_size;
- // unsigned short x_origin, y_origin, width, height;
- // unsigned char pixel_size, attributes;
- // } TargaHeader;
- //
- //
/*
=============
LoadTGA
=============
*/
byte[] LoadTGA(String name, Dimension dim) {
- // TODO LoadTGA()
- // int columns, rows, numPixels;
- // byte *pixbuf;
- // int row, column;
- // byte *buf_p;
- // byte *buffer;
- // int length;
- // TargaHeader targa_header;
- // byte *targa_rgba;
- // byte tmp[2];
- //
- // *pic = NULL;
- //
- // //
- // // load the file
- // //
- // length = ri.FS_LoadFile (name, (void **)&buffer);
- // if (!buffer)
- // {
- // ri.Con_Printf (PRINT_DEVELOPER, "Bad tga file %s\n", name);
- // return;
- // }
- //
- // buf_p = buffer;
- //
- // targa_header.id_length = *buf_p++;
- // targa_header.colormap_type = *buf_p++;
- // targa_header.image_type = *buf_p++;
- //
- // tmp[0] = buf_p[0];
- // tmp[1] = buf_p[1];
- // targa_header.colormap_index = LittleShort ( *((short *)tmp) );
- // buf_p+=2;
- // tmp[0] = buf_p[0];
- // tmp[1] = buf_p[1];
- // targa_header.colormap_length = LittleShort ( *((short *)tmp) );
- // buf_p+=2;
- // targa_header.colormap_size = *buf_p++;
- // targa_header.x_origin = LittleShort ( *((short *)buf_p) );
- // buf_p+=2;
- // targa_header.y_origin = LittleShort ( *((short *)buf_p) );
- // buf_p+=2;
- // targa_header.width = LittleShort ( *((short *)buf_p) );
- // buf_p+=2;
- // targa_header.height = LittleShort ( *((short *)buf_p) );
- // buf_p+=2;
- // targa_header.pixel_size = *buf_p++;
- // targa_header.attributes = *buf_p++;
- //
- // if (targa_header.image_type!=2
- // && targa_header.image_type!=10)
- // ri.Sys_Error (ERR_DROP, "LoadTGA: Only type 2 and 10 targa RGB images supported\n");
- //
- // if (targa_header.colormap_type !=0
- // || (targa_header.pixel_size!=32 && targa_header.pixel_size!=24))
- // ri.Sys_Error (ERR_DROP, "LoadTGA: Only 32 or 24 bit images supported (no colormaps)\n");
- //
- // columns = targa_header.width;
- // rows = targa_header.height;
- // numPixels = columns * rows;
- //
- // if (width)
- // *width = columns;
- // if (height)
- // *height = rows;
- //
- // targa_rgba = malloc (numPixels*4);
- // *pic = targa_rgba;
+ int columns, rows, numPixels;
+ int pixbuf; // index into pic
+ int row, column;
+ byte[] raw;
+ ByteBuffer buf_p;
+ int length;
+ qfiles.tga_t targa_header;
+ byte[] pic = null;
+
//
- // if (targa_header.id_length != 0)
- // buf_p += targa_header.id_length; // skip TARGA image comment
- //
- // if (targa_header.image_type==2) { // Uncompressed, RGB images
- // for(row=rows-1; row>=0; row--) {
- // pixbuf = targa_rgba + row*columns*4;
- // for(column=0; column<columns; column++) {
- // unsigned char red,green,blue,alphabyte;
- // switch (targa_header.pixel_size) {
- // case 24:
- //
- // blue = *buf_p++;
- // green = *buf_p++;
- // red = *buf_p++;
- // *pixbuf++ = red;
- // *pixbuf++ = green;
- // *pixbuf++ = blue;
- // *pixbuf++ = 255;
- // break;
- // case 32:
- // blue = *buf_p++;
- // green = *buf_p++;
- // red = *buf_p++;
- // alphabyte = *buf_p++;
- // *pixbuf++ = red;
- // *pixbuf++ = green;
- // *pixbuf++ = blue;
- // *pixbuf++ = alphabyte;
- // break;
- // }
- // }
- // }
- // }
- // else if (targa_header.image_type==10) { // Runlength encoded RGB images
- // unsigned char red,green,blue,alphabyte,packetHeader,packetSize,j;
- // for(row=rows-1; row>=0; row--) {
- // pixbuf = targa_rgba + row*columns*4;
- // for(column=0; column<columns; ) {
- // packetHeader= *buf_p++;
- // packetSize = 1 + (packetHeader & 0x7f);
- // if (packetHeader & 0x80) { // run-length packet
- // switch (targa_header.pixel_size) {
- // case 24:
- // blue = *buf_p++;
- // green = *buf_p++;
- // red = *buf_p++;
- // alphabyte = 255;
- // break;
- // case 32:
- // blue = *buf_p++;
- // green = *buf_p++;
- // red = *buf_p++;
- // alphabyte = *buf_p++;
- // break;
- // }
- //
- // for(j=0;j<packetSize;j++) {
- // *pixbuf++=red;
- // *pixbuf++=green;
- // *pixbuf++=blue;
- // *pixbuf++=alphabyte;
- // column++;
- // if (column==columns) { // run spans across rows
- // column=0;
- // if (row>0)
- // row--;
- // else
- // goto breakOut;
- // pixbuf = targa_rgba + row*columns*4;
- // }
- // }
- // }
- // else { // non run-length packet
- // for(j=0;j<packetSize;j++) {
- // switch (targa_header.pixel_size) {
- // case 24:
- // blue = *buf_p++;
- // green = *buf_p++;
- // red = *buf_p++;
- // *pixbuf++ = red;
- // *pixbuf++ = green;
- // *pixbuf++ = blue;
- // *pixbuf++ = 255;
- // break;
- // case 32:
- // blue = *buf_p++;
- // green = *buf_p++;
- // red = *buf_p++;
- // alphabyte = *buf_p++;
- // *pixbuf++ = red;
- // *pixbuf++ = green;
- // *pixbuf++ = blue;
- // *pixbuf++ = alphabyte;
- // break;
- // }
- // column++;
- // if (column==columns) { // pixel packet run spans across rows
- // column=0;
- // if (row>0)
- // row--;
- // else
- // goto breakOut;
- // pixbuf = targa_rgba + row*columns*4;
- // }
- // }
- // }
- // }
- // breakOut:;
- // }
- // }
+ // load the file
//
- // ri.FS_FreeFile (buffer);
- return null; // remove this
+ raw = ri.FS_LoadFile (name);
+
+ if (raw == null)
+ {
+ ri.Con_Printf(Defines.PRINT_DEVELOPER, "Bad tga file "+ name +'\n');
+ return null;
+ }
+
+ targa_header = new qfiles.tga_t(raw);
+
+ if (targa_header.image_type != 2 && targa_header.image_type != 10)
+ ri.Sys_Error(Defines.ERR_DROP, "LoadTGA: Only type 2 and 10 targa RGB images supported\n");
+
+ if (targa_header.colormap_type != 0 || (targa_header.pixel_size != 32 && targa_header.pixel_size != 24))
+ ri.Sys_Error (Defines.ERR_DROP, "LoadTGA: Only 32 or 24 bit images supported (no colormaps)\n");
+
+ columns = targa_header.width;
+ rows = targa_header.height;
+ numPixels = columns * rows;
+
+ if (dim != null) {
+ dim.width = columns;
+ dim.height = rows;
+ }
+
+ pic = new byte[numPixels * 4]; // targa_rgba;
+
+ if (targa_header.id_length != 0)
+ targa_header.data.position(targa_header.id_length); // skip TARGA image comment
+
+ buf_p = targa_header.data;
+
+ byte red,green,blue,alphabyte;
+ red = green = blue = alphabyte = 0;
+ int packetHeader, packetSize, j;
+
+ if (targa_header.image_type==2) { // Uncompressed, RGB images
+ for(row=rows-1; row>=0; row--) {
+
+ pixbuf = row * columns * 4;
+
+ for(column=0; column<columns; column++) {
+ switch (targa_header.pixel_size) {
+ case 24:
+
+ blue = buf_p.get();
+ green = buf_p.get();
+ red = buf_p.get();
+ pic[pixbuf++] = red;
+ pic[pixbuf++] = green;
+ pic[pixbuf++] = blue;
+ pic[pixbuf++] = (byte)255;
+ break;
+ case 32:
+ blue = buf_p.get();
+ green = buf_p.get();
+ red = buf_p.get();
+ alphabyte = buf_p.get();
+ pic[pixbuf++] = red;
+ pic[pixbuf++] = green;
+ pic[pixbuf++] = blue;
+ pic[pixbuf++] = alphabyte;
+ break;
+ }
+ }
+ }
+ }
+ else if (targa_header.image_type==10) { // Runlength encoded RGB images
+ for(row=rows-1; row>=0; row--) {
+
+ pixbuf = row * columns * 4;
+ try {
+
+ for(column=0; column<columns; ) {
+
+ packetHeader= buf_p.get() & 0xFF;
+ packetSize = 1 + (packetHeader & 0x7f);
+
+ if ((packetHeader & 0x80) != 0) { // run-length packet
+ switch (targa_header.pixel_size) {
+ case 24:
+ blue = buf_p.get();
+ green = buf_p.get();
+ red = buf_p.get();
+ alphabyte = (byte)255;
+ break;
+ case 32:
+ blue = buf_p.get();
+ green = buf_p.get();
+ red = buf_p.get();
+ alphabyte = buf_p.get();
+ break;
+ }
+
+ for(j=0;j<packetSize;j++) {
+ pic[pixbuf++]=red;
+ pic[pixbuf++]=green;
+ pic[pixbuf++]=blue;
+ pic[pixbuf++]=alphabyte;
+ column++;
+ if (column==columns) { // run spans across rows
+ column=0;
+ if (row>0)
+ row--;
+ else
+ // goto label breakOut;
+ throw new longjmpException();
+
+ pixbuf = row * columns * 4;
+ }
+ }
+ }
+ else { // non run-length packet
+ for(j=0;j<packetSize;j++) {
+ switch (targa_header.pixel_size) {
+ case 24:
+ blue = buf_p.get();
+ green = buf_p.get();
+ red = buf_p.get();
+ pic[pixbuf++] = red;
+ pic[pixbuf++] = green;
+ pic[pixbuf++] = blue;
+ pic[pixbuf++] = (byte)255;
+ break;
+ case 32:
+ blue = buf_p.get();
+ green = buf_p.get();
+ red = buf_p.get();
+ alphabyte = buf_p.get();
+ pic[pixbuf++] = red;
+ pic[pixbuf++] = green;
+ pic[pixbuf++] = blue;
+ pic[pixbuf++] = alphabyte;
+ break;
+ }
+ column++;
+ if (column==columns) { // pixel packet run spans across rows
+ column=0;
+ if (row>0)
+ row--;
+ else
+ // goto label breakOut;
+ throw new longjmpException();
+
+ pixbuf = row * columns * 4;
+ }
+ }
+ }
+ }
+ } catch (longjmpException e){
+ // label breakOut:
+ }
+ }
+ }
+ return pic;
}
/*
diff --git a/src/jake2/render/jogl/Impl.java b/src/jake2/render/jogl/Impl.java
index 48241db..ba8b929 100644
--- a/src/jake2/render/jogl/Impl.java
+++ b/src/jake2/render/jogl/Impl.java
@@ -2,7 +2,7 @@
* Impl.java
* Copyright (C) 2003
*
- * $Id: Impl.java,v 1.2 2004-07-08 15:58:45 hzi Exp $
+ * $Id: Impl.java,v 1.3 2004-07-08 20:24:30 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -137,11 +137,12 @@ public class Impl extends Misc implements GLEventListener {
canvas.addMouseListener(KBD.listener);
canvas.addMouseMotionListener(KBD.listener);
window.addComponentListener(KBD.listener);
-
+ canvas.requestFocus();
+
window.pack();
window.show();
canvas.requestFocus();
-
+
this.canvas = canvas;
vid.width = newDim.width;
@@ -222,12 +223,10 @@ public class Impl extends Misc implements GLEventListener {
this.contextInUse = true;
if (switchToCallback) {
- if (callback == null)
- ri.updateScreenCallback();
- else
- callback.execute();
+ callback.execute();
}
- else {
+ else
+ {
// after the first run (initialization) switch to callback
switchToCallback = true;
@@ -271,9 +270,9 @@ public class Impl extends Misc implements GLEventListener {
* @see jake2.client.refexport_t#updateScreen()
*/
public void updateScreen(xcommand_t callback) {
- if (canvas == null) {
- throw new IllegalStateException("Refresh modul \"" + DRIVER_NAME + "\" have to be initialized.");
- }
+// if (canvas == null) {
+// throw new IllegalStateException("Refresh modul \"" + DRIVER_NAME + "\" have to be initialized.");
+// }
this.callback = callback;
canvas.display();
}
diff --git a/src/jake2/render/jogl/Light.java b/src/jake2/render/jogl/Light.java
index fc23e4a..214641d 100644
--- a/src/jake2/render/jogl/Light.java
+++ b/src/jake2/render/jogl/Light.java
@@ -2,7 +2,7 @@
* Light.java
* Copyright (C) 2003
*
- * $Id: Light.java,v 1.1 2004-07-07 19:59:38 hzi Exp $
+ * $Id: Light.java,v 1.2 2004-07-08 20:24:30 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -29,6 +29,8 @@ import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.Arrays;
+import net.java.games.jogl.GL;
+
import jake2.Defines;
import jake2.Globals;
import jake2.client.dlight_t;
@@ -64,30 +66,30 @@ public abstract class Light extends Warp {
void R_RenderDlight (dlight_t light)
{
-// int i, j;
-// float a;
-// vec3_t v;
-// float rad;
-//
-// rad = light.intensity * 0.35;
-//
-// VectorSubtract (light.origin, r_origin, v);
-//
-// qglBegin (GL_TRIANGLE_FAN);
-// qglColor3f (light.color[0]*0.2, light.color[1]*0.2, light.color[2]*0.2);
-// for (i=0 ; i<3 ; i++)
-// v[i] = light.origin[i] - vpn[i]*rad;
-// qglVertex3fv (v);
-// qglColor3f (0,0,0);
-// for (i=16 ; i>=0 ; i--)
-// {
-// a = i/16.0 * M_PI*2;
-// for (j=0 ; j<3 ; j++)
-// v[j] = light.origin[j] + vright[j]*cos(a)*rad
-// + vup[j]*sin(a)*rad;
-// qglVertex3fv (v);
-// }
-// qglEnd ();
+ int i, j;
+ float a;
+ float[] v = {0, 0, 0};
+ float rad;
+
+ rad = light.intensity * 0.35f;
+
+ 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++)
+ v[i] = light.origin[i] - vpn[i]*rad;
+ gl.glVertex3fv (v);
+ 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);
+ gl.glVertex3fv (v);
+ }
+ gl.glEnd ();
}
/*
@@ -97,29 +99,31 @@ public abstract class Light extends Warp {
*/
void R_RenderDlights()
{
-// int i;
-// dlight_t *l;
-//
-// if (!gl_flashblend.value)
-// return;
-//
-// r_dlightframecount = r_framecount + 1; // because the count hasn't
-// // advanced yet for this frame
-// qglDepthMask (0);
-// qglDisable (GL_TEXTURE_2D);
-// qglShadeModel (GL_SMOOTH);
-// qglEnable (GL_BLEND);
-// qglBlendFunc (GL_ONE, GL_ONE);
-//
-// l = r_newrefdef.dlights;
-// for (i=0 ; i<r_newrefdef.num_dlights ; i++, l++)
-// R_RenderDlight (l);
-//
-// qglColor3f (1,1,1);
-// qglDisable (GL_BLEND);
-// qglEnable (GL_TEXTURE_2D);
-// qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-// qglDepthMask (1);
+ 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
+ gl.glDepthMask(false);
+ gl.glDisable(GL.GL_TEXTURE_2D);
+ gl.glShadeModel (GL.GL_SMOOTH);
+ gl.glEnable (GL.GL_BLEND);
+ gl.glBlendFunc (GL.GL_ONE, GL.GL_ONE);
+
+ for (i=0 ; i<r_newrefdef.num_dlights ; i++)
+ {
+ l = r_newrefdef.dlights[i];
+ R_RenderDlight (l);
+ }
+
+ gl.glColor3f (1,1,1);
+ gl.glDisable(GL.GL_BLEND);
+ gl.glEnable(GL.GL_TEXTURE_2D);
+ gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
+ gl.glDepthMask(true);
}
@@ -390,76 +394,78 @@ public abstract class Light extends Warp {
*/
void R_AddDynamicLights(msurface_t surf)
{
-// int lnum;
-// int sd, td;
-// float fdist, frad, fminlight;
-// vec3_t impact, local;
-// int s, t;
-// int i;
-// int smax, tmax;
-// mtexinfo_t *tex;
-// dlight_t *dl;
-// float *pfBL;
-// float fsacc, ftacc;
-//
-// smax = (surf.extents[0]>>4)+1;
-// tmax = (surf.extents[1]>>4)+1;
-// tex = surf.texinfo;
-//
-// for (lnum=0 ; lnum<r_newrefdef.num_dlights ; lnum++)
-// {
-// if ( !(surf.dlightbits & (1<<lnum) ) )
-// continue; // not lit by this light
-//
-// dl = &r_newrefdef.dlights[lnum];
-// frad = dl.intensity;
-// fdist = DotProduct (dl.origin, surf.plane.normal) -
-// surf.plane.dist;
-// frad -= fabs(fdist);
-// // rad is now the highest intensity on the plane
-//
-// fminlight = DLIGHT_CUTOFF; // FIXME: make configurable?
-// if (frad < fminlight)
-// continue;
-// fminlight = frad - fminlight;
-//
-// for (i=0 ; i<3 ; i++)
-// {
-// impact[i] = dl.origin[i] -
-// surf.plane.normal[i]*fdist;
-// }
-//
-// local[0] = DotProduct (impact, tex.vecs[0]) + tex.vecs[0][3] - surf.texturemins[0];
-// local[1] = DotProduct (impact, tex.vecs[1]) + tex.vecs[1][3] - surf.texturemins[1];
-//
-// pfBL = s_blocklights;
-// for (t = 0, ftacc = 0 ; t<tmax ; t++, ftacc += 16)
-// {
-// td = local[1] - ftacc;
-// if ( td < 0 )
-// td = -td;
-//
-// for ( s=0, fsacc = 0 ; s<smax ; s++, fsacc += 16, pfBL += 3)
-// {
-// sd = Q_ftol( local[0] - fsacc );
-//
-// if ( sd < 0 )
-// sd = -sd;
-//
-// if (sd > td)
-// fdist = sd + (td>>1);
-// else
-// fdist = td + (sd>>1);
-//
-// if ( fdist < fminlight )
-// {
-// pfBL[0] += ( frad - fdist ) * dl.color[0];
-// pfBL[1] += ( frad - fdist ) * dl.color[1];
-// pfBL[2] += ( frad - fdist ) * dl.color[2];
-// }
-// }
-// }
-// }
+ int lnum;
+ int sd, td;
+ float fdist, frad, fminlight;
+ float[] impact = {0, 0, 0};
+ float[] local = {0, 0, 0};
+ int s, t;
+ int i;
+ int smax, tmax;
+ mtexinfo_t tex;
+ dlight_t dl;
+ float[] pfBL;
+ float fsacc, ftacc;
+
+ smax = (surf.extents[0]>>4)+1;
+ tmax = (surf.extents[1]>>4)+1;
+ tex = surf.texinfo;
+
+ for (lnum=0 ; lnum<r_newrefdef.num_dlights ; lnum++)
+ {
+ if ( (surf.dlightbits & (1<<lnum)) == 0 )
+ continue; // not lit by this light
+
+ dl = r_newrefdef.dlights[lnum];
+ frad = dl.intensity;
+ fdist = Math3D.DotProduct (dl.origin, surf.plane.normal) -
+ surf.plane.dist;
+ frad -= Math.abs(fdist);
+ // rad is now the highest intensity on the plane
+
+ fminlight = DLIGHT_CUTOFF; // FIXME: make configurable?
+ if (frad < fminlight)
+ continue;
+ fminlight = frad - fminlight;
+
+ for (i=0 ; i<3 ; i++)
+ {
+ impact[i] = dl.origin[i] -
+ surf.plane.normal[i]*fdist;
+ }
+
+ local[0] = Math3D.DotProduct (impact, tex.vecs[0]) + tex.vecs[0][3] - surf.texturemins[0];
+ local[1] = Math3D.DotProduct (impact, tex.vecs[1]) + tex.vecs[1][3] - surf.texturemins[1];
+
+ pfBL = s_blocklights;
+ int pfBLindex = 0;
+ for (t = 0, ftacc = 0 ; t<tmax ; t++, ftacc += 16)
+ {
+ td = (int)(local[1] - ftacc);
+ if ( td < 0 )
+ td = -td;
+
+ for ( s=0, fsacc = 0 ; s<smax ; s++, fsacc += 16, pfBLindex += 3)
+ {
+ sd = (int)( local[0] - fsacc );
+
+ if ( sd < 0 )
+ sd = -sd;
+
+ if (sd > td)
+ fdist = sd + (td>>1);
+ else
+ fdist = td + (sd>>1);
+
+ if ( fdist < fminlight )
+ {
+ pfBL[pfBLindex + 0] += ( frad - fdist ) * dl.color[0];
+ pfBL[pfBLindex + 1] += ( frad - fdist ) * dl.color[1];
+ pfBL[pfBLindex + 2] += ( frad - fdist ) * dl.color[2];
+ }
+ }
+ }
+ }
}
diff --git a/src/jake2/render/jogl/Mesh.java b/src/jake2/render/jogl/Mesh.java
index 45d28bb..37e4445 100644
--- a/src/jake2/render/jogl/Mesh.java
+++ b/src/jake2/render/jogl/Mesh.java
@@ -2,7 +2,7 @@
* Mesh.java
* Copyright (C) 2003
*
- * $Id: Mesh.java,v 1.2 2004-07-08 15:58:45 hzi Exp $
+ * $Id: Mesh.java,v 1.3 2004-07-08 20:24:30 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -228,7 +228,7 @@ public abstract class Mesh extends Light {
else
{
gl.glEnableClientState( GL.GL_COLOR_ARRAY );
- gl.glColorPointer( 3, GL.GL_FLOAT, 0, colorArrayBuf );
+ gl.glColorPointer( 4, GL.GL_FLOAT, 0, colorArrayBuf );
//
// pre light everything
@@ -237,7 +237,7 @@ public abstract class Mesh extends Light {
for ( i = 0; i < paliashdr.num_xyz; i++ )
{
l = shadedots[verts[i].lightnormalindex];
- colorArrayBuf.put(l * shadelight[0]).put(l * shadelight[1]).put(l * shadelight[2]);
+ colorArrayBuf.put(l * shadelight[0]).put(l * shadelight[1]).put(l * shadelight[2]).put(alpha);
}
}
diff --git a/src/jake2/render/jogl/Surf.java b/src/jake2/render/jogl/Surf.java
index 7baf69f..7f05332 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.1 2004-07-07 19:59:43 hzi Exp $
+ * $Id: Surf.java,v 1.2 2004-07-08 20:24:30 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -36,6 +36,8 @@ 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;
@@ -86,15 +88,21 @@ public abstract class Surf extends Draw {
int current_lightmap_texture;
msurface_t[] lightmap_surfaces = new msurface_t[MAX_LIGHTMAPS];
-
int[] allocated = new int[BLOCK_WIDTH];
// 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];
+
+ public gllightmapstate_t() {
+ for (int i = 0; i < MAX_LIGHTMAPS; i++)
+ lightmap_surfaces[i] = new msurface_t();
+ }
+
public void clearLightmapSurfaces() {
for (int i = 0; i < MAX_LIGHTMAPS; i++)
+ // TODO lightmap_surfaces[i].clear();
lightmap_surfaces[i] = new msurface_t();
}
@@ -390,64 +398,74 @@ public abstract class Surf extends Draw {
for ( surf = gl_lms.lightmap_surfaces[0]; surf != null; surf = surf.lightmapchain )
{
-// int smax, tmax;
-// byte *base;
-//
-// smax = (surf->extents[0]>>4)+1;
-// tmax = (surf->extents[1]>>4)+1;
-//
-// if ( LM_AllocBlock( smax, tmax, &surf->dlight_s, &surf->dlight_t ) )
-// {
-// base = gl_lms.lightmap_buffer;
-// base += ( surf->dlight_t * BLOCK_WIDTH + surf->dlight_s ) * LIGHTMAP_BYTES;
-//
-// R_BuildLightMap (surf, base, BLOCK_WIDTH*LIGHTMAP_BYTES);
-// }
-// else
-// {
-// msurface_t *drawsurf;
-//
-// // upload what we have so far
-// LM_UploadBlock( true );
-//
-// // draw all surfaces that use this lightmap
-// for ( drawsurf = newdrawsurf; drawsurf != surf; drawsurf = drawsurf->lightmapchain )
-// {
-// if ( drawsurf->polys )
-// DrawGLPolyChain( drawsurf->polys,
-// ( drawsurf->light_s - drawsurf->dlight_s ) * ( 1.0 / 128.0 ),
-// ( drawsurf->light_t - drawsurf->dlight_t ) * ( 1.0 / 128.0 ) );
-// }
-//
-// newdrawsurf = drawsurf;
-//
-// // clear the block
-// LM_InitBlock();
-//
-// // try uploading the block now
-// if ( !LM_AllocBlock( smax, tmax, &surf->dlight_s, &surf->dlight_t ) )
-// {
-// ri.Sys_Error( ERR_FATAL, "Consecutive calls to LM_AllocBlock(%d,%d) failed (dynamic)\n", smax, tmax );
-// }
-//
-// base = gl_lms.lightmap_buffer;
-// base += ( surf->dlight_t * BLOCK_WIDTH + surf->dlight_s ) * LIGHTMAP_BYTES;
-//
-// R_BuildLightMap (surf, base, BLOCK_WIDTH*LIGHTMAP_BYTES);
-// }
+ int smax, tmax;
+ ByteBuffer base;
+
+ smax = (surf.extents[0]>>4)+1;
+ tmax = (surf.extents[1]>>4)+1;
+
+ pos_t lightPos = new pos_t(surf.dlight_s, surf.dlight_t);
+
+ if ( LM_AllocBlock( smax, tmax, lightPos) )
+ {
+ // kopiere die koordinaten zurueck
+ 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);
+
+ R_BuildLightMap (surf, base, BLOCK_WIDTH*LIGHTMAP_BYTES);
+ }
+ else
+ {
+ msurface_t drawsurf;
+
+ // upload what we have so far
+ LM_UploadBlock( true );
+
+ // draw all surfaces that use this lightmap
+ for ( drawsurf = newdrawsurf; drawsurf != surf; drawsurf = drawsurf.lightmapchain )
+ {
+ if ( drawsurf.polys != null )
+ DrawGLPolyChain( drawsurf.polys,
+ ( drawsurf.light_s - drawsurf.dlight_s ) * ( 1.0f / 128.0f ),
+ ( drawsurf.light_t - drawsurf.dlight_t ) * ( 1.0f / 128.0f ) );
+ }
+
+ newdrawsurf = drawsurf;
+
+ // clear the block
+ LM_InitBlock();
+
+ // try uploading the block now
+ if ( !LM_AllocBlock( smax, tmax, lightPos) )
+ {
+ ri.Sys_Error( Defines.ERR_FATAL, "Consecutive calls to LM_AllocBlock(" + smax + "," + tmax + ") failed (dynamic)\n");
+ }
+
+ // kopiere die koordinaten zurueck
+ 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);
+
+ R_BuildLightMap (surf, base, BLOCK_WIDTH*LIGHTMAP_BYTES);
+ }
}
/*
** draw remainder of dynamic lightmaps that haven't been uploaded yet
*/
-// if ( newdrawsurf != null )
-// LM_UploadBlock( true );
-//
-// for ( surf = newdrawsurf; surf != null; surf = surf.lightmapchain )
-// {
-// if ( surf.polys != null )
-// DrawGLPolyChain( surf.polys, ( surf.light_s - surf.dlight_s ) * ( 1.0f / 128.0f ), ( surf.light_t - surf.dlight_t ) * ( 1.0f / 128.0f ) );
-// }
+ if ( newdrawsurf != null )
+ LM_UploadBlock( true );
+
+ for ( surf = newdrawsurf; surf != null; surf = surf.lightmapchain )
+ {
+ if ( surf.polys != null )
+ DrawGLPolyChain( surf.polys, ( surf.light_s - surf.dlight_s ) * ( 1.0f / 128.0f ), ( surf.light_t - surf.dlight_t ) * ( 1.0f / 128.0f ) );
+ }
}
/*
@@ -457,6 +475,8 @@ public abstract class Surf extends Draw {
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glDepthMask( true );
}
+
+ private ByteBuffer temp2 = BufferUtils.newByteBuffer(34 * 34 * 4);
/*
================
@@ -503,57 +523,64 @@ public abstract class Surf extends Draw {
// PGM
// ======
-// /*
-// ** check for lightmap modification
-// */
-// for ( maps = 0; maps < MAXLIGHTMAPS && fa->styles[maps] != 255; maps++ )
-// {
-// if ( r_newrefdef.lightstyles[fa->styles[maps]].white != fa->cached_light[maps] )
-// goto dynamic;
-// }
-//
-// // dynamic this frame or dynamic previously
-// if ( ( fa->dlightframe == r_framecount ) )
-// {
-// dynamic:
-// if ( gl_dynamic->value )
-// {
-// if (!( fa->texinfo->flags & (SURF_SKY|SURF_TRANS33|SURF_TRANS66|SURF_WARP ) ) )
-// {
-// is_dynamic = true;
-// }
-// }
-// }
-//
+ // ersetzt goto
+ boolean gotoDynamic = false;
+ /*
+ ** check for lightmap modification
+ */
+ for ( maps = 0; maps < Defines.MAXLIGHTMAPS && fa.styles[maps] != (byte)255; maps++ )
+ {
+ if ( r_newrefdef.lightstyles[fa.styles[maps] & 0xFF].white != fa.cached_light[maps] ) {
+ gotoDynamic = true;
+ break;
+ }
+ }
+
+ // this is a hack from cwei
+ if (maps == 4) maps--;
+
+ // dynamic this frame or dynamic previously
+ if ( gotoDynamic || ( fa.dlightframe == r_framecount ) )
+ {
+ // label dynamic:
+ if ( gl_dynamic.value != 0 )
+ {
+ if (( fa.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33 | Defines.SURF_TRANS66 | Defines.SURF_WARP ) ) == 0)
+ {
+ is_dynamic = true;
+ }
+ }
+ }
+
if ( is_dynamic )
{
-// if ( ( fa->styles[maps] >= 32 || fa->styles[maps] == 0 ) && ( fa->dlightframe != r_framecount ) )
-// {
-// unsigned temp[34*34];
-// int smax, tmax;
-//
-// smax = (fa->extents[0]>>4)+1;
-// tmax = (fa->extents[1]>>4)+1;
-//
-// R_BuildLightMap( fa, (void *)temp, smax*4 );
-// R_SetCacheState( fa );
-//
-// GL_Bind( gl_state.lightmap_textures + fa->lightmaptexturenum );
-//
-// qglTexSubImage2D( GL_TEXTURE_2D, 0,
-// fa->light_s, fa->light_t,
-// smax, tmax,
-// GL_LIGHTMAP_FORMAT,
-// GL_UNSIGNED_BYTE, temp );
-//
-// fa->lightmapchain = gl_lms.lightmap_surfaces[fa->lightmaptexturenum];
-// gl_lms.lightmap_surfaces[fa->lightmaptexturenum] = fa;
-// }
-// else
-// {
-// fa->lightmapchain = gl_lms.lightmap_surfaces[0];
-// gl_lms.lightmap_surfaces[0] = fa;
-// }
+ if ( ( (fa.styles[maps] & 0xFF) >= 32 || fa.styles[maps] == 0 ) && ( fa.dlightframe != r_framecount ) )
+ {
+ // ist ersetzt durch temp2: unsigned temp[34*34];
+ int smax, tmax;
+
+ smax = (fa.extents[0]>>4)+1;
+ tmax = (fa.extents[1]>>4)+1;
+
+ R_BuildLightMap( fa, temp2, smax*4 );
+ R_SetCacheState( fa );
+
+ GL_Bind( gl_state.lightmap_textures + fa.lightmaptexturenum );
+
+ gl.glTexSubImage2D( GL.GL_TEXTURE_2D, 0,
+ fa.light_s, fa.light_t,
+ smax, tmax,
+ GL_LIGHTMAP_FORMAT,
+ GL.GL_UNSIGNED_BYTE, temp2 );
+
+ fa.lightmapchain = gl_lms.lightmap_surfaces[fa.lightmaptexturenum];
+ gl_lms.lightmap_surfaces[fa.lightmaptexturenum] = fa;
+ }
+ else
+ {
+ fa.lightmapchain = gl_lms.lightmap_surfaces[0];
+ gl_lms.lightmap_surfaces[0] = fa;
+ }
}
else
{
@@ -689,6 +716,8 @@ public abstract class Surf extends Draw {
GL_TexEnv( GL.GL_REPLACE );
}
+ // direct buffer
+ ByteBuffer temp = BufferUtils.newByteBuffer(128 * 128 * 4);
void GL_RenderLightmappedPoly( msurface_t surf )
{
@@ -700,66 +729,74 @@ public abstract class Surf extends Draw {
int lmtex = surf.lightmaptexturenum;
glpoly_t p;
-// for ( map = 0; map < Defines.MAXLIGHTMAPS && surf.styles[map] != (byte)255; map++ )
-// {
-// if ( r_newrefdef.lightstyles[surf.styles[map] & 0xFF].white != surf.cached_light[map] )
-// goto dynamic;
-// }
-//
-// // dynamic this frame or dynamic previously
-// if ( ( surf.dlightframe == r_framecount ) )
-// {
-// dynamic:
-// if ( gl_dynamic.value )
-// {
-// if ( !(surf.texinfo.flags & (SURF_SKY|SURF_TRANS33|SURF_TRANS66|SURF_WARP ) ) )
-// {
-// is_dynamic = true;
-// }
-// }
-// }
-//
+ // ersetzt goto
+ boolean gotoDynamic = false;
+
+ for ( map = 0; map < Defines.MAXLIGHTMAPS && (surf.styles[map] != (byte)255); map++ )
+ {
+ if ( r_newrefdef.lightstyles[surf.styles[map] & 0xFF].white != surf.cached_light[map] ) {
+ gotoDynamic = true;
+ break;
+ }
+ }
+
+ // this is a hack from cwei
+ if (map == 4) map--;
+
+ // dynamic this frame or dynamic previously
+ if ( gotoDynamic || ( surf.dlightframe == r_framecount ) )
+ {
+ // label dynamic:
+ if ( gl_dynamic.value != 0 )
+ {
+ if ( (surf.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33 | Defines.SURF_TRANS66 | Defines.SURF_WARP )) == 0 )
+ {
+ is_dynamic = true;
+ }
+ }
+ }
+
if ( is_dynamic )
{
-// unsigned temp[128*128];
-// int smax, tmax;
-//
+ // ist raus gezogen worden int[] temp = new int[128*128];
+ int smax, tmax;
+
if ( ( (surf.styles[map] & 0xFF) >= 32 || surf.styles[map] == 0 ) && ( surf.dlightframe != r_framecount ) )
{
-// smax = (surf.extents[0]>>4)+1;
-// tmax = (surf.extents[1]>>4)+1;
-//
-// R_BuildLightMap( surf, (void *)temp, smax*4 );
-// R_SetCacheState( surf );
-//
-// GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + surf.lightmaptexturenum );
-//
-// lmtex = surf.lightmaptexturenum;
-//
-// gl.glTexSubImage2D( GL_TEXTURE_2D, 0,
-// surf.light_s, surf.light_t,
-// smax, tmax,
-// GL_LIGHTMAP_FORMAT,
-// GL_UNSIGNED_BYTE, temp );
-//
+ smax = (surf.extents[0]>>4)+1;
+ tmax = (surf.extents[1]>>4)+1;
+
+ R_BuildLightMap( surf, temp, smax*4 );
+ R_SetCacheState( surf );
+
+ GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + surf.lightmaptexturenum );
+
+ lmtex = surf.lightmaptexturenum;
+
+ gl.glTexSubImage2D( GL.GL_TEXTURE_2D, 0,
+ surf.light_s, surf.light_t,
+ smax, tmax,
+ GL_LIGHTMAP_FORMAT,
+ GL.GL_UNSIGNED_BYTE, temp );
+
}
else
{
-// smax = (surf.extents[0]>>4)+1;
-// tmax = (surf.extents[1]>>4)+1;
-//
-// R_BuildLightMap( surf, (void *)temp, smax*4 );
-//
-// GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + 0 );
-//
-// lmtex = 0;
-//
-// gl.glTexSubImage2D( GL_TEXTURE_2D, 0,
-// surf.light_s, surf.light_t,
-// smax, tmax,
-// GL_LIGHTMAP_FORMAT,
-// GL_UNSIGNED_BYTE, temp );
-//
+ smax = (surf.extents[0]>>4)+1;
+ tmax = (surf.extents[1]>>4)+1;
+
+ R_BuildLightMap( surf, temp, smax*4 );
+
+ GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + 0 );
+
+ lmtex = 0;
+
+ gl.glTexSubImage2D( GL.GL_TEXTURE_2D, 0,
+ surf.light_s, surf.light_t,
+ smax, tmax,
+ GL_LIGHTMAP_FORMAT,
+ GL.GL_UNSIGNED_BYTE, temp );
+
}
c_brush_polys++;
diff --git a/src/jake2/render/jogl/Warp.java b/src/jake2/render/jogl/Warp.java
index f02acbb..8ccb93a 100644
--- a/src/jake2/render/jogl/Warp.java
+++ b/src/jake2/render/jogl/Warp.java
@@ -2,7 +2,7 @@
* Warp.java
* Copyright (C) 2003
*
- * $Id: Warp.java,v 1.2 2004-07-08 15:58:45 hzi Exp $
+ * $Id: Warp.java,v 1.3 2004-07-08 20:24:30 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -698,8 +698,7 @@ public abstract class Warp extends Model {
pathname = "env/" + skyname + suf[i] + ".pcx";
} else {
// Com_sprintf (pathname, sizeof(pathname), "env/%s%s.tga", skyname, suf[i]);
- // TODO impl: LoadTGA
- pathname = "env/" + skyname + suf[i] + ".pcx";
+ pathname = "env/" + skyname + suf[i] + ".tga";
}
sky_images[i] = GL_FindImage(pathname, it_sky);
diff --git a/src/jake2/render/msurface_t.java b/src/jake2/render/msurface_t.java
index a43ddbd..c6247d9 100644
--- a/src/jake2/render/msurface_t.java
+++ b/src/jake2/render/msurface_t.java
@@ -19,13 +19,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Created on 20.11.2003 by RST.
-// $Id: msurface_t.java,v 1.1 2004-07-07 19:59:35 hzi Exp $
+// $Id: msurface_t.java,v 1.2 2004-07-08 20:24:29 hzi Exp $
package jake2.render;
import java.nio.ByteBuffer;
import jake2.game.*;
+import jake2.qcommon.texinfo_t;
import jake2.*;
public class msurface_t
@@ -50,7 +51,8 @@ public class msurface_t
public msurface_t texturechain;
public msurface_t lightmapchain;
- public mtexinfo_t texinfo;
+ // TODO check this
+ public mtexinfo_t texinfo = new mtexinfo_t();
// lighting info
public int dlightframe;
@@ -62,5 +64,40 @@ public class msurface_t
// values currently used in lightmap
//public byte samples[]; // [numstyles*surfsize]
public ByteBuffer samples; // [numstyles*surfsize]
-
+
+ public void clear() {
+ visframe = 0;
+ //plane = null;
+ flags = 0;
+
+ firstedge = 0;
+ numedges = 0;
+
+ texturemins[0] = texturemins[1] = 0;
+ extents[0] = extents[1] = 0;
+
+ light_s = light_t = 0;
+ dlight_s = dlight_t = 0;
+
+ //polys = null;
+ texturechain = null;
+ lightmapchain = null;
+
+ //texinfo = null;
+
+ dlightframe = 0;
+ dlightbits = 0;
+
+ lightmaptexturenum = 0;
+
+ for (int i = 0; i < styles.length; i++)
+ {
+ styles[i] = 0;
+ }
+ for (int i = 0; i < cached_light.length; i++)
+ {
+ cached_light[i] = 0;
+ }
+ //samples = null;
+ }
}