📄 surf.java
字号:
/* * Surf.java * Copyright (C) 2003 * * $Id: Surf.java,v 1.10 2005/06/08 21:27:09 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 jake2.Defines;import jake2.client.*;import jake2.game.cplane_t;import jake2.qcommon.Com;import jake2.render.*;import jake2.util.*;import jake2.util.Lib;import jake2.util.Math3D;import java.nio.*;import java.util.Arrays;import net.java.games.jogl.GL;import net.java.games.jogl.util.BufferUtils;/** * Surf * * @author cwei */public abstract class Surf extends Draw { // GL_RSURF.C: surface-related refresh code float[] modelorg = { 0, 0, 0 }; // relative to viewpoint msurface_t r_alpha_surfaces; static final int DYNAMIC_LIGHT_WIDTH = 128; static final int DYNAMIC_LIGHT_HEIGHT = 128; static final int LIGHTMAP_BYTES = 4; static final int BLOCK_WIDTH = 128; static final int BLOCK_HEIGHT = 128; static final int MAX_LIGHTMAPS = 128; int c_visible_lightmaps; int c_visible_textures; static final int GL_LIGHTMAP_FORMAT = GL.GL_RGBA; static class gllightmapstate_t { int internal_format; 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]; IntBuffer lightmap_buffer = Lib.newIntBuffer( BLOCK_WIDTH * BLOCK_HEIGHT, ByteOrder.LITTLE_ENDIAN); 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(); } } gllightmapstate_t gl_lms = new gllightmapstate_t(); // Model.java abstract byte[] Mod_ClusterPVS(int cluster, model_t model); // Warp.java abstract void R_DrawSkyBox(); abstract void R_AddSkySurface(msurface_t surface); abstract void R_ClearSkyBox(); abstract void EmitWaterPolys(msurface_t fa); // 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, IntBuffer dest, int stride); /* * ============================================================= * * BRUSH MODELS * * ============================================================= */ /* * =============== R_TextureAnimation * * Returns the proper texture for a given time and base texture * =============== */ image_t R_TextureAnimation(mtexinfo_t tex) { int c; if (tex.next == null) return tex.image; c = currententity.frame % tex.numframes; while (c != 0) { tex = tex.next; c--; } return tex.image; } /* * ================ DrawGLPoly ================ */ void DrawGLPoly(glpoly_t p) { gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); } // ============ // PGM /* * ================ DrawGLFlowingPoly -- version of DrawGLPoly that handles * scrolling texture ================ */ 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(); } // PGM // ============ /* * * R_DrawTriangleOutlines */ void R_DrawTriangleOutlines() { 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 (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(); } } } } gl.glEnable(GL.GL_DEPTH_TEST); gl.glEnable(GL.GL_TEXTURE_2D); } private IntBuffer temp2 = Lib .newIntBuffer(34 * 34, ByteOrder.LITTLE_ENDIAN); /* * ================ R_RenderBrushPoly ================ */ void R_RenderBrushPoly(msurface_t fa) { int maps; image_t image; boolean is_dynamic = false; c_brush_polys++; image = R_TextureAnimation(fa.texinfo); if ((fa.flags & Defines.SURF_DRAWTURB) != 0) { GL_Bind(image.texnum); // warp texture, no lightmaps GL_TexEnv(GL.GL_MODULATE); gl.glColor4f(gl_state.inverse_intensity, gl_state.inverse_intensity, gl_state.inverse_intensity, 1.0F); EmitWaterPolys(fa); GL_TexEnv(GL.GL_REPLACE); return; } else { GL_Bind(image.texnum); GL_TexEnv(GL.GL_REPLACE); } // ====== // PGM if ((fa.texinfo.flags & Defines.SURF_FLOWING) != 0) DrawGLFlowingPoly(fa.polys); else DrawGLPoly(fa.polys); // PGM // ====== // 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] & 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); 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 { fa.lightmapchain = gl_lms.lightmap_surfaces[fa.lightmaptexturenum]; gl_lms.lightmap_surfaces[fa.lightmaptexturenum] = fa; } } /* * ================ R_DrawAlphaSurfaces * * Draw water surfaces and windows. The BSP tree is waled front to back, so * unwinding the chain of alpha_surfaces will draw back to front, giving * proper ordering. ================ */ void R_DrawAlphaSurfaces() { msurface_t s; float intens; // // go back to the world matrix // gl.glLoadMatrixf(r_world_matrix); gl.glEnable(GL.GL_BLEND); GL_TexEnv(GL.GL_MODULATE); // the textures are prescaled up for a better lighting range, // so scale it back down intens = gl_state.inverse_intensity; gl.glInterleavedArrays(GL.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf); for (s = r_alpha_surfaces; s != null; s = s.texturechain) { GL_Bind(s.texinfo.image.texnum); c_brush_polys++; if ((s.texinfo.flags & Defines.SURF_TRANS33) != 0) gl.glColor4f(intens, intens, intens, 0.33f); else if ((s.texinfo.flags & Defines.SURF_TRANS66) != 0) gl.glColor4f(intens, intens, intens, 0.66f); else gl.glColor4f(intens, intens, intens, 1); if ((s.flags & Defines.SURF_DRAWTURB) != 0) EmitWaterPolys(s); else if ((s.texinfo.flags & Defines.SURF_FLOWING) != 0) // PGM // 9/16/98 DrawGLFlowingPoly(s.polys); // PGM else DrawGLPoly(s.polys); } GL_TexEnv(GL.GL_REPLACE); gl.glColor4f(1, 1, 1, 1); gl.glDisable(GL.GL_BLEND); r_alpha_surfaces = null; } /* * ================ DrawTextureChains ================ */ void DrawTextureChains() { int i; msurface_t s; image_t image; c_visible_textures = 0; for (i = 0; i < numgltextures; i++) { image = gltextures[i]; if (image.registration_sequence == 0) continue; if (image.texturechain == null) continue; c_visible_textures++; for (s = image.texturechain; s != null; s = s.texturechain) { if ((s.flags & Defines.SURF_DRAWTURB) == 0) R_RenderBrushPoly(s); } } GL_EnableMultitexture(false); for (i = 0; i < numgltextures; i++) { image = gltextures[i]; if (image.registration_sequence == 0) continue; s = image.texturechain; if (s == null) continue; for (; s != null; s = s.texturechain) { if ((s.flags & Defines.SURF_DRAWTURB) != 0) R_RenderBrushPoly(s); } image.texturechain = null; } GL_TexEnv(GL.GL_REPLACE); } // direct buffer private IntBuffer temp = Lib.newIntBuffer(128 * 128, ByteOrder.LITTLE_ENDIAN); void GL_RenderLightmappedPoly(msurface_t surf) { int i, nv = surf.polys.numverts; int map = 0; int index; float[][] v; FloatBuffer texCoord = globalPolygonInterleavedBuf; image_t image = R_TextureAnimation(surf.texinfo); boolean is_dynamic = false; int lmtex = surf.lightmaptexturenum; glpoly_t p; // 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -