⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 surf.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * Surf.java * Copyright (C) 2003 * * $Id: Surf.java,v 1.9 2005/06/08 21:27:10 cawe Exp $ *//*Copyright (C) 1997-2001 Id Software, Inc.This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of 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 ofMERCHANTABILITY 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 Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*/package jake2.render.lwjgl;import jake2.Defines;import jake2.client.*;import jake2.game.cplane_t;import jake2.qcommon.Com;import jake2.render.*;import jake2.util.Lib;import jake2.util.Math3D;import java.nio.*;import java.util.Arrays;import org.lwjgl.BufferUtils;import org.lwjgl.opengl.GL11;/** * 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 = GL11.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)	{		if (tex.next == null)			return tex.image;		int c = currententity.frame % tex.numframes;		while (c != 0)		{			tex = tex.next;			c--;		}		return tex.image;	}	/**	 * DrawGLPoly	 */	void DrawGLPoly(glpoly_t p)	{		gl.glDrawArrays(GL11.GL_POLYGON, p.pos, p.numverts);	}	/**	 * DrawGLFlowingPoly	 * version 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(GL11.GL_POLYGON, p.pos, p.numverts);		p.endScrolling();	}	/**	 * R_DrawTriangleOutlines	*/	void R_DrawTriangleOutlines()	{        if (gl_showtris.value == 0)            return;        gl.glDisable(GL11.GL_TEXTURE_2D);        gl.glDisable(GL11.GL_DEPTH_TEST);        gl.glColor4f(1, 1, 1, 1);        msurface_t surf;        glpoly_t p;        int j;	        for (int i = 0; i < MAX_LIGHTMAPS; i++) {             for (surf = gl_lms.lightmap_surfaces[i]; surf != null; surf = surf.lightmapchain) {                for (p = surf.polys; p != null; p = p.chain) {                    for (j = 2; j < p.numverts; j++) {                        gl.glBegin(GL11.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(GL11.GL_DEPTH_TEST);        gl.glEnable(GL11.GL_TEXTURE_2D);	}	private final IntBuffer temp2 = Lib.newIntBuffer(34 * 34, ByteOrder.LITTLE_ENDIAN);	/**	 * R_RenderBrushPoly	 */	void R_RenderBrushPoly(msurface_t fa)	{		c_brush_polys++;		image_t image = R_TextureAnimation(fa.texinfo);		if ((fa.flags & Defines.SURF_DRAWTURB) != 0)		{				GL_Bind( image.texnum );			// warp texture, no lightmaps			GL_TexEnv( GL11.GL_MODULATE );			gl.glColor4f( gl_state.inverse_intensity, 						gl_state.inverse_intensity,						gl_state.inverse_intensity,						1.0F );			EmitWaterPolys (fa);			GL_TexEnv( GL11.GL_REPLACE );			return;		}		else		{			GL_Bind( image.texnum );			GL_TexEnv( GL11.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		*/		int maps;		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		boolean is_dynamic = false;		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( GL11.GL_TEXTURE_2D, 0,								  fa.light_s, fa.light_t, 								  smax, tmax, 								  GL_LIGHTMAP_FORMAT, 								  GL11.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()	{		r_world_matrix.clear();		//		// go back to the world matrix		//		gl.glLoadMatrix(r_world_matrix);		gl.glEnable (GL11.GL_BLEND);		GL_TexEnv(GL11.GL_MODULATE );				// the textures are prescaled up for a better lighting range,		// so scale it back down		float intens = gl_state.inverse_intensity;		gl.glInterleavedArrays(GL11.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf);		for (msurface_t 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( GL11.GL_REPLACE );		gl.glColor4f (1,1,1,1);		gl.glDisable (GL11.GL_BLEND);		r_alpha_surfaces = null;	}	/**	 * DrawTextureChains	 */	void DrawTextureChains()	{		c_visible_textures = 0;		msurface_t	s;		image_t image;		int i;		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( GL11.GL_REPLACE );	}	// direct buffer	private final IntBuffer temp = Lib.newIntBuffer(128 * 128, ByteOrder.LITTLE_ENDIAN);		/**	 * GL_RenderLightmappedPoly	 * @param surf	 */	void GL_RenderLightmappedPoly( msurface_t surf )	{		// ersetzt goto		boolean gotoDynamic = false;		int map;		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		boolean is_dynamic = false;		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;				}			}		}		glpoly_t p;		FloatBuffer texCoord = globalPolygonInterleavedBuf;		image_t image = R_TextureAnimation( surf.texinfo );		int lmtex = surf.lightmaptexturenum;		if ( is_dynamic )		{			// ist raus gezogen worden int[] temp = new int[128*128];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -