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

📄 surf.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		gl.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);		GL_EnableMultitexture( false );		DrawTextureChains();		R_DrawSkyBox();		R_DrawTriangleOutlines();	}	final byte[] fatvis = new byte[Defines.MAX_MAP_LEAFS / 8];	/**	 * R_MarkLeaves	 * Mark the leaves and nodes that are in the PVS for the current	 * cluster	 */	void R_MarkLeaves()	{		if (r_oldviewcluster == r_viewcluster && r_oldviewcluster2 == r_viewcluster2 && r_novis.value == 0 && r_viewcluster != -1)			return;		// development aid to let you run around and see exactly where		// the pvs ends		if (gl_lockpvs.value != 0)			return;		r_visframecount++;		r_oldviewcluster = r_viewcluster;		r_oldviewcluster2 = r_viewcluster2;		int i;		if (r_novis.value != 0 || r_viewcluster == -1 || r_worldmodel.vis == null)		{			// mark everything			for (i=0 ; i<r_worldmodel.numleafs ; i++)				r_worldmodel.leafs[i].visframe = r_visframecount;			for (i=0 ; i<r_worldmodel.numnodes ; i++)				r_worldmodel.nodes[i].visframe = r_visframecount;			return;		}		byte[] vis = Mod_ClusterPVS(r_viewcluster, r_worldmodel);		int c;		// may have to combine two clusters because of solid water boundaries		if (r_viewcluster2 != r_viewcluster)		{			// memcpy (fatvis, vis, (r_worldmodel.numleafs+7)/8);			System.arraycopy(vis, 0, fatvis, 0, (r_worldmodel.numleafs+7) >> 3);			vis = Mod_ClusterPVS(r_viewcluster2, r_worldmodel);			c = (r_worldmodel.numleafs + 31) >> 5;			c <<= 2;			for (int k=0 ; k<c ; k+=4) {				fatvis[k] |= vis[k];				fatvis[k + 1] |= vis[k + 1];				fatvis[k + 2] |= vis[k + 2];				fatvis[k + 3] |= vis[k + 3];			}			vis = fatvis;		}		mnode_t node;		mleaf_t leaf;		int cluster;		for ( i=0; i < r_worldmodel.numleafs; i++)		{			leaf = r_worldmodel.leafs[i];			cluster = leaf.cluster;			if (cluster == -1)				continue;			if (((vis[cluster>>3] & 0xFF) & (1 << (cluster & 7))) != 0)			{				node = (mnode_t)leaf;				do				{					if (node.visframe == r_visframecount)						break;					node.visframe = r_visframecount;					node = node.parent;				} while (node != null);			}		}	}	/*	=============================================================================	  LIGHTMAP ALLOCATION	=============================================================================	*/	/**	 * LM_InitBlock	 */	void LM_InitBlock()	{		Arrays.fill(gl_lms.allocated, 0);	}	/**	 * LM_UploadBlock	 * @param dynamic	 */	void LM_UploadBlock( boolean dynamic )	{		int texture = ( dynamic ) ? 0 : gl_lms.current_lightmap_texture;		GL_Bind( gl_state.lightmap_textures + texture );		gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);		gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);		gl_lms.lightmap_buffer.rewind();		if ( dynamic )		{			int height = 0;			for (int i = 0; i < BLOCK_WIDTH; i++ )			{				if ( gl_lms.allocated[i] > height )					height = gl_lms.allocated[i];			}			gl.glTexSubImage2D( GL11.GL_TEXTURE_2D, 							  0,							  0, 0,							  BLOCK_WIDTH, height,							  GL_LIGHTMAP_FORMAT,							  GL11.GL_UNSIGNED_BYTE,							  gl_lms.lightmap_buffer );		}		else		{			gl.glTexImage2D( GL11.GL_TEXTURE_2D, 						   0, 						   gl_lms.internal_format,						   BLOCK_WIDTH, BLOCK_HEIGHT, 						   0, 						   GL_LIGHTMAP_FORMAT, 						   GL11.GL_UNSIGNED_BYTE, 						   gl_lms.lightmap_buffer );			if ( ++gl_lms.current_lightmap_texture == MAX_LIGHTMAPS )				Com.Error( Defines.ERR_DROP, "LM_UploadBlock() - MAX_LIGHTMAPS exceeded\n" );							//debugLightmap(gl_lms.lightmap_buffer, 128, 128, 4);		}	}	/**	 * LM_AllocBlock	 * @param w	 * @param h	 * @param pos	 * @return a texture number and the position inside it	 */	boolean LM_AllocBlock (int w, int h, pos_t pos)	{		int best = BLOCK_HEIGHT;		int x = pos.x; 		int y = pos.y;		int best2;		int i, j;		for (i=0 ; i<BLOCK_WIDTH-w ; i++)		{			best2 = 0;			for (j=0 ; j<w ; j++)			{				if (gl_lms.allocated[i+j] >= best)					break;				if (gl_lms.allocated[i+j] > best2)					best2 = gl_lms.allocated[i+j];			}			if (j == w)			{	// this is a valid spot				pos.x = x = i;				pos.y = y = best = best2;			}		}		if (best + h > BLOCK_HEIGHT)			return false;		for (i=0 ; i<w ; i++)			gl_lms.allocated[x + i] = best + h;		return true;	}	/**	 * GL_BuildPolygonFromSurface	 */	void GL_BuildPolygonFromSurface(msurface_t fa)	{		// reconstruct the polygon		medge_t[] pedges = currentmodel.edges;		int lnumverts = fa.numedges;		int vertpage = 0;		//		// draw texture		//		// poly = Hunk_Alloc (sizeof(glpoly_t) + (lnumverts-4) * VERTEXSIZE*sizeof(float));		glpoly_t poly = Polygon.create(lnumverts);		poly.next = fa.polys;		poly.flags = fa.flags;		fa.polys = poly;		int lindex;		float[] vec;		medge_t r_pedge;		float s, t;		for (int i=0 ; i<lnumverts ; i++)		{			lindex = currentmodel.surfedges[fa.firstedge + i];			if (lindex > 0)			{				r_pedge = pedges[lindex];				vec = currentmodel.vertexes[r_pedge.v[0]].position;			}			else			{				r_pedge = pedges[-lindex];				vec = currentmodel.vertexes[r_pedge.v[1]].position;			}			s = Math3D.DotProduct (vec, fa.texinfo.vecs[0]) + fa.texinfo.vecs[0][3];			s /= fa.texinfo.image.width;			t = Math3D.DotProduct (vec, fa.texinfo.vecs[1]) + fa.texinfo.vecs[1][3];			t /= fa.texinfo.image.height;			poly.x(i, vec[0]);			poly.y(i, vec[1]);			poly.z(i, vec[2]);						poly.s1(i, s);			poly.t1(i, t);			//			// lightmap texture coordinates			//			s = Math3D.DotProduct (vec, fa.texinfo.vecs[0]) + fa.texinfo.vecs[0][3];			s -= fa.texturemins[0];			s += fa.light_s*16;			s += 8;			s /= BLOCK_WIDTH*16; //fa.texinfo.texture.width;			t = Math3D.DotProduct (vec, fa.texinfo.vecs[1]) + fa.texinfo.vecs[1][3];			t -= fa.texturemins[1];			t += fa.light_t*16;			t += 8;			t /= BLOCK_HEIGHT*16; //fa.texinfo.texture.height;			poly.s2(i, s);			poly.t2(i, t);		}	}	/**	 * GL_CreateSurfaceLightmap	 */	void GL_CreateSurfaceLightmap(msurface_t surf)	{		if ( (surf.flags & (Defines.SURF_DRAWSKY | Defines.SURF_DRAWTURB)) != 0)			return;		int smax = (surf.extents[0]>>4)+1;		int tmax = (surf.extents[1]>>4)+1;				pos_t lightPos = new pos_t(surf.light_s, surf.light_t);		if ( !LM_AllocBlock( smax, tmax, lightPos ) )		{			LM_UploadBlock( false );			LM_InitBlock();			lightPos = new pos_t(surf.light_s, surf.light_t);			if ( !LM_AllocBlock( smax, tmax, lightPos ) )			{				Com.Error( Defines.ERR_FATAL, "Consecutive calls to LM_AllocBlock(" + smax +"," + tmax +") failed\n");			}		}				// kopiere die koordinaten zurueck		surf.light_s = lightPos.x;		surf.light_t = lightPos.y;		surf.lightmaptexturenum = gl_lms.current_lightmap_texture;				IntBuffer base = gl_lms.lightmap_buffer;		base.position(surf.light_t * BLOCK_WIDTH + surf.light_s);		R_SetCacheState( surf );		R_BuildLightMap(surf, base.slice(), BLOCK_WIDTH);	}	lightstyle_t[] lightstyles;	private final IntBuffer dummy = BufferUtils.createIntBuffer(128*128);	/**	 * GL_BeginBuildingLightmaps	 */	void GL_BeginBuildingLightmaps(model_t m)	{		// static lightstyle_t	lightstyles[MAX_LIGHTSTYLES];		int i;		// init lightstyles		if ( lightstyles == null ) {			lightstyles = new lightstyle_t[Defines.MAX_LIGHTSTYLES];			for (i = 0; i < lightstyles.length; i++)			{				lightstyles[i] = new lightstyle_t();							}		}		// memset( gl_lms.allocated, 0, sizeof(gl_lms.allocated) );		Arrays.fill(gl_lms.allocated, 0);		r_framecount = 1;		// no dlightcache		GL_EnableMultitexture( true );		GL_SelectTexture( GL_TEXTURE1);		/*		** setup the base lightstyles so the lightmaps won't have to be regenerated		** the first time they're seen		*/		for (i=0 ; i < Defines.MAX_LIGHTSTYLES ; i++)		{			lightstyles[i].rgb[0] = 1;			lightstyles[i].rgb[1] = 1;			lightstyles[i].rgb[2] = 1;			lightstyles[i].white = 3;		}		r_newrefdef.lightstyles = lightstyles;		if (gl_state.lightmap_textures == 0)		{			gl_state.lightmap_textures = TEXNUM_LIGHTMAPS;		}		gl_lms.current_lightmap_texture = 1;		/*		** if mono lightmaps are enabled and we want to use alpha		** blending (a,1-a) then we're likely running on a 3DLabs		** Permedia2.  In a perfect world we'd use a GL_ALPHA lightmap		** in order to conserve space and maximize bandwidth, however 		** this isn't a perfect world.		**		** So we have to use alpha lightmaps, but stored in GL_RGBA format,		** which means we only get 1/16th the color resolution we should when		** using alpha lightmaps.  If we find another board that supports		** only alpha lightmaps but that can at least support the GL_ALPHA		** format then we should change this code to use real alpha maps.		*/				char format = gl_monolightmap.string.toUpperCase().charAt(0);				if ( format == 'A' )		{			gl_lms.internal_format = gl_tex_alpha_format;		}		/*		** try to do hacked colored lighting with a blended texture		*/		else if ( format == 'C' )		{			gl_lms.internal_format = gl_tex_alpha_format;		}		else if ( format == 'I' )		{			gl_lms.internal_format = GL11.GL_INTENSITY8;		}		else if ( format == 'L' ) 		{			gl_lms.internal_format = GL11.GL_LUMINANCE8;		}		else		{			gl_lms.internal_format = gl_tex_solid_format;		}		/*		** initialize the dynamic lightmap texture		*/		GL_Bind( gl_state.lightmap_textures + 0 );		gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);		gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);		gl.glTexImage2D( GL11.GL_TEXTURE_2D, 					   0, 					   gl_lms.internal_format,					   BLOCK_WIDTH, BLOCK_HEIGHT, 					   0, 					   GL_LIGHTMAP_FORMAT, 					   GL11.GL_UNSIGNED_BYTE, 					   dummy );	}	/**	 * GL_EndBuildingLightmaps	 */	void GL_EndBuildingLightmaps()	{		LM_UploadBlock( false );		GL_EnableMultitexture( false );	}		/*	 * new buffers for vertex array handling	 */	static FloatBuffer globalPolygonInterleavedBuf = Polygon.getInterleavedBuffer();	static FloatBuffer globalPolygonTexCoord1Buf = null;	static {	 	globalPolygonInterleavedBuf.position(Polygon.STRIDE - 2);	 	globalPolygonTexCoord1Buf = globalPolygonInterleavedBuf.slice();		globalPolygonInterleavedBuf.position(0);	 };	//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);//		//	}}

⌨️ 快捷键说明

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