aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2
diff options
context:
space:
mode:
authorCarsten Weisse <[email protected]>2005-01-17 17:37:02 +0000
committerCarsten Weisse <[email protected]>2005-01-17 17:37:02 +0000
commit8c7a815119230871c1a0447a3dc1c86285759136 (patch)
tree47abcf16542a6c6dff1bd975decec7501efc5f12 /src/jake2
parentf8ed5c5bc8d34e8ffb6da64034b3afe5bb8e606e (diff)
local float[] optimize; code clean up
Diffstat (limited to 'src/jake2')
-rw-r--r--src/jake2/render/lwjgl/Light.java739
1 files changed, 367 insertions, 372 deletions
diff --git a/src/jake2/render/lwjgl/Light.java b/src/jake2/render/lwjgl/Light.java
index 4250d9c..5c46e68 100644
--- a/src/jake2/render/lwjgl/Light.java
+++ b/src/jake2/render/lwjgl/Light.java
@@ -2,7 +2,7 @@
* Light.java
* Copyright (C) 2003
*
- * $Id: Light.java,v 1.2 2004-12-14 12:56:59 cawe Exp $
+ * $Id: Light.java,v 1.3 2005-01-17 17:37:02 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -36,6 +36,7 @@ import jake2.render.mnode_t;
import jake2.render.msurface_t;
import jake2.render.mtexinfo_t;
import jake2.util.Math3D;
+import jake2.util.Vec3Cache;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
@@ -63,23 +64,28 @@ public abstract class Light extends Warp {
=============================================================================
*/
- void R_RenderDlight (dlight_t light)
+ // stack variable
+ private final float[] v = {0, 0, 0};
+ /**
+ * R_RenderDlight
+ */
+ void R_RenderDlight(dlight_t light)
{
- int i, j;
- float a;
- float[] v = {0, 0, 0};
- float rad;
-
- rad = light.intensity * 0.35f;
+ float rad = light.intensity * 0.35f;
Math3D.VectorSubtract (light.origin, r_origin, v);
gl.glBegin (GL11.GL_TRIANGLE_FAN);
gl.glColor3f (light.color[0]*0.2f, light.color[1]*0.2f, light.color[2]*0.2f);
+ int i;
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);
+
+ int j;
+ float a;
for (i=16 ; i>=0 ; i--)
{
a = (float)(i/16.0f * Math.PI*2);
@@ -91,11 +97,9 @@ public abstract class Light extends Warp {
gl.glEnd ();
}
- /*
- =============
- R_RenderDlights
- =============
- */
+ /**
+ * R_RenderDlights
+ */
void R_RenderDlights()
{
if (gl_flashblend.value == 0)
@@ -130,24 +134,16 @@ public abstract class Light extends Warp {
=============================================================================
*/
- /*
- =============
- R_MarkLights
- =============
- */
+ /**
+ * R_MarkLights
+ */
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;
+ cplane_t splitplane = node.plane;
+ float dist = Math3D.DotProduct (light.origin, splitplane.normal) - splitplane.dist;
if (dist > light.intensity - DLIGHT_CUTOFF)
{
@@ -159,9 +155,11 @@ public abstract class Light extends Warp {
R_MarkLights (light, bit, node.children[1]);
return;
}
-
+
// mark the polygons
- for (i=0 ; i<node.numsurfaces ; i++)
+ msurface_t surf;
+ int sidebit;
+ for (int i=0 ; i<node.numsurfaces ; i++)
{
surf = r_worldmodel.surfaces[node.firstsurface + i];
@@ -191,29 +189,23 @@ public abstract class Light extends Warp {
R_MarkLights (light, bit, node.children[1]);
}
-
- /*
- =============
- R_PushDlights
- =============
- */
+ /**
+ * R_PushDlights
+ */
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++) {
+ 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] );
}
}
-
/*
=============================================================================
@@ -225,20 +217,19 @@ public abstract class Light extends Warp {
float[] pointcolor = {0, 0, 0}; // vec3_t
cplane_t lightplane; // used as shadow plane
float[] lightspot = {0, 0, 0}; // vec3_t
-
+
+ /**
+ * RecursiveLightPoint
+ * @param node
+ * @param start
+ * @param end
+ * @return
+ */
int RecursiveLightPoint (mnode_t node, float[] start, float[] end)
{
if (node.contents != -1)
return -1; // didn't hit anything
- msurface_t surf;
- int s, t, ds, dt;
- int i;
- mtexinfo_t tex;
- ByteBuffer lightmap;
- int maps;
- float[] mid = {0, 0, 0};
-
// calculate mid point
// FIXME: optimize for axial
@@ -252,25 +243,34 @@ public abstract class Light extends Warp {
return RecursiveLightPoint (node.children[sideIndex], start, end);
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;
mid[2] = start[2] + (end[2] - start[2])*frac;
// go down front side
int r = RecursiveLightPoint (node.children[sideIndex], start, mid);
- if (r >= 0)
+ if (r >= 0) {
+ Vec3Cache.release(); // mid
return r; // hit something
+ }
- if ( (back < 0) == side )
+ if ( (back < 0) == side ) {
+ Vec3Cache.release(); // mid
return -1; // didn't hit anuthing
+ }
// check for impact on this node
Math3D.VectorCopy (mid, lightspot);
lightplane = plane;
-
int surfIndex = node.firstsurface;
- float[] scale = {0, 0, 0};
- for (i=0 ; i<node.numsurfaces ; i++, surfIndex++)
+
+ msurface_t surf;
+ int s, t, ds, dt;
+ mtexinfo_t tex;
+ ByteBuffer lightmap;
+ int maps;
+ for (int i=0 ; i<node.numsurfaces ; i++, surfIndex++)
{
surf = r_worldmodel.surfaces[surfIndex];
@@ -303,44 +303,43 @@ public abstract class Light extends Warp {
Math3D.VectorCopy (Globals.vec3_origin, pointcolor);
if (lightmap != null)
{
- //float[] scale = {0, 0, 0};
float[] rgb;
lightmapIndex += 3 * (dt * ((surf.extents[0] >> 4) + 1) + ds);
+ float scale0, scale1, scale2;
for (maps = 0 ; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte)255; maps++)
{
rgb = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb;
- scale[0] = gl_modulate.value * rgb[0];
- scale[1] = gl_modulate.value * rgb[1];
- scale[2] = gl_modulate.value * rgb[2];
+ scale0 = gl_modulate.value * rgb[0];
+ scale1 = gl_modulate.value * rgb[1];
+ scale2 = gl_modulate.value * rgb[2];
- pointcolor[0] += (lightmap.get(lightmapIndex + 0) & 0xFF) * scale[0] * (1.0f/255);
- pointcolor[1] += (lightmap.get(lightmapIndex + 1) & 0xFF) * scale[1] * (1.0f/255);
- pointcolor[2] += (lightmap.get(lightmapIndex + 2) & 0xFF) * scale[2] * (1.0f/255);
+ pointcolor[0] += (lightmap.get(lightmapIndex + 0) & 0xFF) * scale0 * (1.0f/255);
+ pointcolor[1] += (lightmap.get(lightmapIndex + 1) & 0xFF) * scale1 * (1.0f/255);
+ pointcolor[2] += (lightmap.get(lightmapIndex + 2) & 0xFF) * scale2 * (1.0f/255);
lightmapIndex += 3 * ((surf.extents[0] >> 4) + 1) * ((surf.extents[1] >> 4) + 1);
}
}
+ Vec3Cache.release(); // mid
return 1;
}
// go down back side
- return RecursiveLightPoint (node.children[1 - sideIndex], mid, end);
+ r = RecursiveLightPoint (node.children[1 - sideIndex], mid, end);
+ Vec3Cache.release(); // mid
+ return r;
}
- /*
- ===============
- R_LightPoint
- ===============
- */
+ // stack variable
+ private final float[] end = {0, 0, 0};
+ /**
+ * R_LightPoint
+ */
void R_LightPoint (float[] p, float[] color)
{
assert (p.length == 3) : "vec3_t bug";
assert (color.length == 3) : "rgb bug";
- float[] end = {0, 0, 0};
- dlight_t dl;
- float add;
-
if (r_worldmodel.lightdata == null)
{
color[0] = color[1] = color[2] = 1.0f;
@@ -365,6 +364,8 @@ public abstract class Light extends Warp {
//
// add dynamic lights
//
+ dlight_t dl;
+ float add;
for (int lnum=0 ; lnum<r_newrefdef.num_dlights ; lnum++)
{
dl = r_newrefdef.dlights[lnum];
@@ -377,7 +378,6 @@ public abstract class Light extends Warp {
Math3D.VectorMA (color, add, dl.color, color);
}
}
-
Math3D.VectorScale (color, gl_modulate.value, color);
}
@@ -385,18 +385,15 @@ public abstract class Light extends Warp {
float[] s_blocklights = new float[34 * 34 * 3];
- /*
- ===============
- R_AddDynamicLights
- ===============
- */
- // TODO sync with jogl renderer. hoz
+// TODO sync with jogl renderer. hoz
+ private final float[] impact = {0, 0, 0};
+ /**
+ * R_AddDynamicLights
+ */
void R_AddDynamicLights(msurface_t surf)
{
int sd, td;
float fdist, frad, fminlight;
- float[] impact = {0, 0, 0};
- float[] local = {0, 0, 0};
int s, t;
dlight_t dl;
float[] pfBL;
@@ -406,6 +403,7 @@ public abstract class Light extends Warp {
int tmax = (surf.extents[1]>>4)+1;
mtexinfo_t tex = surf.texinfo;
+ float local0, local1;
for (int lnum=0 ; lnum<r_newrefdef.num_dlights ; lnum++)
{
if ( (surf.dlightbits & (1<<lnum)) == 0 )
@@ -429,20 +427,20 @@ public abstract class Light extends Warp {
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];
+ local0 = Math3D.DotProduct (impact, tex.vecs[0]) + tex.vecs[0][3] - surf.texturemins[0];
+ local1 = 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);
+ td = (int)(local1 - ftacc);
if ( td < 0 )
td = -td;
for (s=0, fsacc = 0 ; s<smax ; s++, fsacc += 16, pfBLindex += 3)
{
- sd = (int)( local[0] - fsacc );
+ sd = (int)( local0 - fsacc );
if ( sd < 0 )
sd = -sd;
@@ -463,10 +461,9 @@ public abstract class Light extends Warp {
}
}
-
- /*
- ** R_SetCacheState
- */
+ /**
+ * R_SetCacheState
+ */
void R_SetCacheState( msurface_t surf )
{
for (int maps = 0 ; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte)255 ; maps++)
@@ -475,291 +472,289 @@ public abstract class Light extends Warp {
}
}
- /*
- ===============
- R_BuildLightMap
-
- Combine and scale multiple lightmaps into the floating format in blocklights
- ===============
- */
// TODO sync with jogl renderer. hoz
+ /**
+ * R_BuildLightMap
+ *
+ * Combine and scale multiple lightmaps into the floating format in blocklights
+ */
void R_BuildLightMap(msurface_t surf, IntBuffer dest, int stride)
{
- int r, g, b, a, max;
- int i, j;
- ByteBuffer lightmap;
- float[] scale = {0, 0, 0};
- int nummaps;
- float[] bl;
- //lightstyle_t style;
-
- if ( (surf.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33 | Defines.SURF_TRANS66 | Defines.SURF_WARP)) != 0 )
- Com.Error(Defines.ERR_DROP, "R_BuildLightMap called for non-lit surface");
-
- int smax = (surf.extents[0] >> 4) + 1;
- int tmax = (surf.extents[1] >> 4) + 1;
- int size = smax * tmax;
- if (size > ((s_blocklights.length * Defines.SIZE_OF_FLOAT) >> 4) )
- Com.Error(Defines.ERR_DROP, "Bad s_blocklights size");
-
- try {
- // set to full bright if no light data
- if (surf.samples == null)
- {
- int maps;
-
- for (i=0 ; i<size*3 ; i++)
- s_blocklights[i] = 255;
-
-// TODO useless? hoz
-// for (maps = 0 ; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte)255; maps++)
-// {
-// style = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF];
-// }
-
- // goto store;
- throw new longjmpException();
- }
-
- // count the # of maps
- for ( nummaps = 0 ; nummaps < Defines.MAXLIGHTMAPS && surf.styles[nummaps] != (byte)255 ;
- nummaps++)
- ;
-
- lightmap = surf.samples;
- int lightmapIndex = 0;
-
- // add all the lightmaps
- if ( nummaps == 1 )
- {
- int maps;
-
- for (maps = 0 ; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte)255 ;
- maps++)
- {
- bl = s_blocklights;
- int blp = 0;
-
- for (i=0 ; i<3 ; i++)
- scale[i] = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i];
-
- if ( scale[0] == 1.0F &&
- scale[1] == 1.0F &&
- scale[2] == 1.0F )
- {
- for (i=0 ; i<size ; i++)
- {
- bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF;
- bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF;
- bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF;
- }
- }
- else
- {
- for (i=0 ; i<size ; i++)
- {
- bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) * scale[0];
- bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) * scale[1];
- bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) * scale[2];
- }
- }
- //lightmap += size*3; // skip to next lightmap
- }
- }
- else
- {
- int maps;
-
- // memset( s_blocklights, 0, sizeof( s_blocklights[0] ) * size * 3 );
-
- Arrays.fill(s_blocklights, 0, size * 3, 0.0f);
-
- for (maps = 0 ; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte)255 ;
- maps++)
- {
- bl = s_blocklights;
- int blp = 0;
-
- for (i=0 ; i<3 ; i++)
- scale[i] = gl_modulate.value*r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i];
-
- if ( scale[0] == 1.0F &&
- scale[1] == 1.0F &&
- scale[2] == 1.0F )
- {
- for (i=0 ; i<size ; i++)
- {
- bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF;
- bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF;
- bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF;
- }
- }
- else
- {
- for (i=0 ; i<size ; i++)
- {
- bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) * scale[0];
- bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) * scale[1];
- bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) * scale[2];
- }
- }
- //lightmap += size*3; // skip to next lightmap
- }
- }
-
- // add all the dynamic lights
- if (surf.dlightframe == r_framecount)
- R_AddDynamicLights(surf);
-
- // label store:
- } catch (longjmpException store) {}
-
- // put into texture format
- stride -= smax;
- bl = s_blocklights;
- int blp = 0;
-
- int monolightmap = gl_monolightmap.string.charAt(0);
-
- int destp = 0;
-
- if ( monolightmap == '0' )
- {
- for (i=0 ; i<tmax ; i++, destp += stride)
- {
- //dest.position(destp);
-
- for (j=0 ; j<smax ; j++)
- {
-
- r = (int)bl[blp++];
- g = (int)bl[blp++];
- b = (int)bl[blp++];
-
- // catch negative lights
- if (r < 0)
- r = 0;
- if (g < 0)
- g = 0;
- if (b < 0)
- b = 0;
-
- /*
- ** determine the brightest of the three color components
- */
- if (r > g)
- max = r;
- else
- max = g;
- if (b > max)
- max = b;
-
- /*
- ** alpha is ONLY used for the mono lightmap case. For this reason
- ** we set it to the brightest of the color components so that
- ** things don't get too dim.
- */
- a = max;
-
- /*
- ** rescale all the color components if the intensity of the greatest
- ** channel exceeds 1.0
- */
- if (max > 255)
- {
- float t = 255.0F / max;
-
- r = (int)(r*t);
- g = (int)(g*t);
- b = (int)(b*t);
- a = (int)(a*t);
- }
- //r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF;
- dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | (r << 0));
- }
- }
- }
- else
- {
- for (i=0 ; i<tmax ; i++, destp += stride)
- {
- //dest.position(destp);
-
- for (j=0 ; j<smax ; j++)
- {
-
- r = (int) bl[blp++];
- g = (int) bl[blp++];
- b = (int) bl[blp++];
-
- // catch negative lights
- if (r < 0)
- r = 0;
- if (g < 0)
- g = 0;
- if (b < 0)
- b = 0;
-
- /*
- ** determine the brightest of the three color components
- */
- if (r > g)
- max = r;
- else
- max = g;
- if (b > max)
- max = b;
-
- /*
- ** alpha is ONLY used for the mono lightmap case. For this reason
- ** we set it to the brightest of the color components so that
- ** things don't get too dim.
- */
- a = max;
-
- /*
- ** rescale all the color components if the intensity of the greatest
- ** channel exceeds 1.0
- */
- if (max > 255)
- {
- float t = 255.0F / max;
-
- r = (int)(r*t);
- g = (int)(g*t);
- b = (int)(b*t);
- a = (int)(a*t);
- }
-
- /*
- ** So if we are doing alpha lightmaps we need to set the R, G, and B
- ** components to 0 and we need to set alpha to 1-alpha.
- */
- switch ( monolightmap )
- {
- case 'L':
- case 'I':
- r = a;
- g = b = 0;
- break;
- case 'C':
- // try faking colored lighting
- a = 255 - ((r+g+b)/3);
- r *= a/255.0f;
- g *= a/255.0f;
- b *= a/255.0f;
- break;
- case 'A':
- default:
- r = g = b = 0;
- a = 255 - a;
- break;
- }
- //r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF;
- dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | (r << 0));
- }
- }
- }
- }
-
-}
+ int r, g, b, a, max;
+ int i, j;
+ int nummaps;
+ float[] bl;
+ //lightstyle_t style;
+
+ if ((surf.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33
+ | Defines.SURF_TRANS66 | Defines.SURF_WARP)) != 0)
+ Com.Error(Defines.ERR_DROP,
+ "R_BuildLightMap called for non-lit surface");
+
+ int smax = (surf.extents[0] >> 4) + 1;
+ int tmax = (surf.extents[1] >> 4) + 1;
+ int size = smax * tmax;
+ if (size > ((s_blocklights.length * Defines.SIZE_OF_FLOAT) >> 4))
+ Com.Error(Defines.ERR_DROP, "Bad s_blocklights size");
+
+ try {
+ // set to full bright if no light data
+ if (surf.samples == null) {
+ int maps;
+
+ for (i = 0; i < size * 3; i++)
+ s_blocklights[i] = 255;
+
+ // TODO useless? hoz
+ // for (maps = 0 ; maps < Defines.MAXLIGHTMAPS &&
+ // surf.styles[maps] != (byte)255; maps++)
+ // {
+ // style = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF];
+ // }
+
+ // goto store;
+ throw new longjmpException();
+ }
+
+ // count the # of maps
+ for (nummaps = 0; nummaps < Defines.MAXLIGHTMAPS
+ && surf.styles[nummaps] != (byte) 255; nummaps++)
+ ;
+
+ ByteBuffer lightmap = surf.samples;
+ int lightmapIndex = 0;
+
+ // add all the lightmaps
+ float scale0;
+ float scale1;
+ float scale2;
+ if (nummaps == 1) {
+ int maps;
+
+ for (maps = 0; maps < Defines.MAXLIGHTMAPS
+ && surf.styles[maps] != (byte) 255; maps++) {
+ bl = s_blocklights;
+ int blp = 0;
+
+// for (i = 0; i < 3; i++)
+// scale[i] = gl_modulate.value
+// * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i];
+ scale0 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[0];
+ scale1 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[1];
+ scale2 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[2];
+
+ if (scale0 == 1.0F && scale1 == 1.0F
+ && scale2 == 1.0F) {
+ for (i = 0; i < size; i++) {
+ bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF;
+ bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF;
+ bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF;
+ }
+ } else {
+ for (i = 0; i < size; i++) {
+ bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF)
+ * scale0;
+ bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF)
+ * scale1;
+ bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF)
+ * scale2;
+ }
+ }
+ //lightmap += size*3; // skip to next lightmap
+ }
+ } else {
+ int maps;
+
+ // memset( s_blocklights, 0, sizeof( s_blocklights[0] ) * size *
+ // 3 );
+
+ Arrays.fill(s_blocklights, 0, size * 3, 0.0f);
+
+ for (maps = 0; maps < Defines.MAXLIGHTMAPS
+ && surf.styles[maps] != (byte) 255; maps++) {
+ bl = s_blocklights;
+ int blp = 0;
+
+// for (i = 0; i < 3; i++)
+// scale[i] = gl_modulate.value
+// * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i];
+ scale0 = gl_modulate.value
+ * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[0];
+ scale1 = gl_modulate.value
+ * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[1];
+ scale2 = gl_modulate.value
+ * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[2];
+
+
+
+
+ if (scale0 == 1.0F && scale1 == 1.0F
+ && scale2 == 1.0F) {
+ for (i = 0; i < size; i++) {
+ bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF;
+ bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF;
+ bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF;
+ }
+ } else {
+ for (i = 0; i < size; i++) {
+ bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF)
+ * scale0;
+ bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF)
+ * scale1;
+ bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF)
+ * scale2;
+ }
+ }
+ //lightmap += size*3; // skip to next lightmap
+ }
+ }
+
+ // add all the dynamic lights
+ if (surf.dlightframe == r_framecount)
+ R_AddDynamicLights(surf);
+
+ // label store:
+ } catch (longjmpException store) {
+ }
+
+ // put into texture format
+ stride -= smax;
+ bl = s_blocklights;
+ int blp = 0;
+
+ int monolightmap = gl_monolightmap.string.charAt(0);
+
+ int destp = 0;
+
+ if (monolightmap == '0') {
+ for (i = 0; i < tmax; i++, destp += stride) {
+ //dest.position(destp);
+
+ for (j = 0; j < smax; j++) {
+
+ r = (int) bl[blp++];
+ g = (int) bl[blp++];
+ b = (int) bl[blp++];
+
+ // catch negative lights
+ if (r < 0)
+ r = 0;
+ if (g < 0)
+ g = 0;
+ if (b < 0)
+ b = 0;
+
+ /*
+ * * determine the brightest of the three color components
+ */
+ if (r > g)
+ max = r;
+ else
+ max = g;
+ if (b > max)
+ max = b;
+
+ /*
+ * * alpha is ONLY used for the mono lightmap case. For this
+ * reason * we set it to the brightest of the color
+ * components so that * things don't get too dim.
+ */
+ a = max;
+
+ /*
+ * * rescale all the color components if the intensity of
+ * the greatest * channel exceeds 1.0
+ */
+ if (max > 255) {
+ float t = 255.0F / max;
+
+ r = (int) (r * t);
+ g = (int) (g * t);
+ b = (int) (b * t);
+ a = (int) (a * t);
+ }
+ //r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF;
+ dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | r);
+ }
+ }
+ } else {
+ for (i = 0; i < tmax; i++, destp += stride) {
+ //dest.position(destp);
+
+ for (j = 0; j < smax; j++) {
+
+ r = (int) bl[blp++];
+ g = (int) bl[blp++];
+ b = (int) bl[blp++];
+
+ // catch negative lights
+ if (r < 0)
+ r = 0;
+ if (g < 0)
+ g = 0;
+ if (b < 0)
+ b = 0;
+
+ /*
+ * * determine the brightest of the three color components
+ */
+ if (r > g)
+ max = r;
+ else
+ max = g;
+ if (b > max)
+ max = b;
+
+ /*
+ * * alpha is ONLY used for the mono lightmap case. For this
+ * reason * we set it to the brightest of the color
+ * components so that * things don't get too dim.
+ */
+ a = max;
+
+ /*
+ * * rescale all the color components if the intensity of
+ * the greatest * channel exceeds 1.0
+ */
+ if (max > 255) {
+ float t = 255.0F / max;
+
+ r = (int) (r * t);
+ g = (int) (g * t);
+ b = (int) (b * t);
+ a = (int) (a * t);
+ }
+
+ /*
+ * * So if we are doing alpha lightmaps we need to set the
+ * R, G, and B * components to 0 and we need to set alpha to
+ * 1-alpha.
+ */
+ switch (monolightmap) {
+ case 'L':
+ case 'I':
+ r = a;
+ g = b = 0;
+ break;
+ case 'C':
+ // try faking colored lighting
+ a = 255 - ((r + g + b) / 3);
+ float af = a / 255.0f;
+ r *= af;
+ g *= af;
+ b *= af;
+ break;
+ case 'A':
+ default:
+ r = g = b = 0;
+ a = 255 - a;
+ break;
+ }
+ //r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF;
+ dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | r);
+ }
+ }
+ }
+ }
+
+} \ No newline at end of file