/// <summary> /// R_RenderBrushPoly /// </summary> private void RenderBrushPoly(MemorySurface fa) { _BrushPolys++; if ((fa.flags & ( Int32 )Q1SurfaceFlags.Sky) != 0) { // warp texture, no lightmaps WarpableTextures.EmitBothSkyLayers(Host.RealTime, Host.RenderContext.Origin, fa); return; } var t = TextureAnimation(fa.texinfo.texture); t.texture.Bind( ); if ((fa.flags & ( Int32 )Q1SurfaceFlags.Turbulence) != 0) { // warp texture, no lightmaps WarpableTextures.EmitWaterPolys(Host.RealTime, fa); return; } if ((fa.flags & ( Int32 )Q1SurfaceFlags.Underwater) != 0) { Host.Video.Device.Graphics.DrawWaterPoly(fa.polys, Host.RealTime); } else { Host.Video.Device.Graphics.DrawPoly(fa.polys, t.scaleX, t.scaleY); } // add the poly to the proper lightmap chain fa.polys.chain = _LightMapPolys[fa.lightmaptexturenum]; _LightMapPolys[fa.lightmaptexturenum] = fa.polys; // check for lightmap modification var modified = false; for (var maps = 0; maps < BspDef.MAXLIGHTMAPS && fa.styles[maps] != 255; maps++) { if (_LightStyleValue[fa.styles[maps]] != fa.cached_light[maps]) { modified = true; break; } } if (modified || fa.dlightframe == _FrameCount || // dynamic this frame fa.cached_dlight) // dynamic previously { if (Host.Cvars.Dynamic.Get <Boolean>( )) { LightMapTexture.LightMapModified[fa.lightmaptexturenum] = true; UpdateRect(fa, ref LightMapTexture.LightMapRectChange[fa.lightmaptexturenum]); var offset = fa.lightmaptexturenum * _LightMapBytes * RenderDef.BLOCK_WIDTH * RenderDef.BLOCK_HEIGHT; offset += fa.light_t * RenderDef.BLOCK_WIDTH * _LightMapBytes + fa.light_s * _LightMapBytes; BuildLightMap(fa, new ByteArraySegment(_LightMaps, offset), RenderDef.BLOCK_WIDTH * _LightMapBytes); } } }
private void DrawTextureChains( ) { if (!Host.Cvars.glTexSort.Get <Boolean>( )) { Host.Video.Device.DisableMultitexture( ); if (TextureChains.SkyChain != null) { WarpableTextures.DrawSkyChain(Host.RealTime, Host.RenderContext.Origin, TextureChains.SkyChain); TextureChains.SkyChain = null; } return; } var world = Host.Client.cl.worldmodel; for (var i = 0; i < world.NumTextures; i++) { var t = world.Textures[i]; if (t == null) { continue; } var s = t.texturechain; if (s == null) { continue; } if (i == _SkyTextureNum) { WarpableTextures.DrawSkyChain(Host.RealTime, Host.RenderContext.Origin, s); } //else if( i == _MirrorTextureNum && _MirrorAlpha.Value != 1.0f ) //{ // MirrorChain( s ); // continue; //} else { if ((s.flags & ( Int32 )Q1SurfaceFlags.Turbulence) != 0 && Host.Cvars.WaterAlpha.Get <Single>( ) != 1.0f) { continue; // draw translucent water later } for ( ; s != null; s = s.texturechain) { RenderBrushPoly(s); } } t.texturechain = null; } }
public render(Host host) { Host = host; Particles = new ParticleSystem(Host.Video.Device); WarpableTextures = new WarpableTextures(Host.Video.Device); }
/// <summary> /// R_DrawSequentialPoly /// Systems that have fast state and texture changes can /// just do everything as it passes with no need to sort /// </summary> private void DrawSequentialPoly(MemorySurface s) { // // normal lightmaped poly // if ((s.flags & (( Int32 )Q1SurfaceFlags.Sky | ( Int32 )Q1SurfaceFlags.Turbulence | ( Int32 )Q1SurfaceFlags.Underwater)) == 0) { RenderDynamicLightmaps(s); var p = s.polys; var t = TextureAnimation(s.texinfo.texture); if (Host.Video.Device.Desc.SupportsMultiTexture) { Host.Video.Device.Graphics.DrawSequentialPolyMultiTexture(t.texture, LightMapTexture, _LightMaps, p, s.lightmaptexturenum); return; } else { Host.Video.Device.Graphics.DrawSequentialPoly(t.texture, LightMapTexture, p, s.lightmaptexturenum); } return; } // // subdivided water surface warp // if ((s.flags & ( Int32 )Q1SurfaceFlags.Turbulence) != 0) { Host.Video.Device.DisableMultitexture( ); s.texinfo.texture.texture.Bind( ); WarpableTextures.EmitWaterPolys(Host.RealTime, s); return; } // // subdivided sky warp // if ((s.flags & ( Int32 )Q1SurfaceFlags.Sky) != 0) { WarpableTextures.EmitBothSkyLayers(Host.RealTime, Host.RenderContext.Origin, s); return; } // // underwater warped with lightmap // RenderDynamicLightmaps(s); if (Host.Video.Device.Desc.SupportsMultiTexture) { var t = TextureAnimation(s.texinfo.texture); Host.DrawingContext.SelectTexture(MTexTarget.TEXTURE0_SGIS); Host.Video.Device.Graphics.DrawWaterPolyMultiTexture(_LightMaps, t.texture, LightMapTexture, s.lightmaptexturenum, s.polys, Host.RealTime); } else { var p = s.polys; var t = TextureAnimation(s.texinfo.texture); t.texture.Bind( ); Host.Video.Device.Graphics.DrawWaterPoly(p, Host.RealTime); LightMapTexture.BindLightmap((( GLTextureDesc )LightMapTexture.Desc).TextureNumber + s.lightmaptexturenum); Host.Video.Device.Graphics.DrawWaterPolyLightmap(p, Host.RealTime, true); } }
/// <summary> /// R_DrawWaterSurfaces /// </summary> private void DrawWaterSurfaces( ) { if (Host.Cvars.WaterAlpha.Get <Single>( ) == 1.0f && Host.Cvars.glTexSort.Get <Boolean>( )) { return; } // // go back to the world matrix // Host.Video.Device.ResetMatrix( ); // WaterAlpha is broken - will fix when we introduce GLSL... //if ( _WaterAlpha.Value < 1.0 ) //{ // GL.Enable( EnableCap.Blend ); // GL.Color4( 1, 1, 1, _WaterAlpha.Value ); // GL.TexEnv( TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, ( Int32 ) TextureEnvMode.Modulate ); //} if (!Host.Cvars.glTexSort.Get <Boolean>( )) { if (TextureChains.WaterChain == null) { return; } for (var s = TextureChains.WaterChain; s != null; s = s.texturechain) { s.texinfo.texture.texture.Bind( ); WarpableTextures.EmitWaterPolys(Host.RealTime, s); } TextureChains.WaterChain = null; } else { for (var i = 0; i < Host.Client.cl.worldmodel.NumTextures; i++) { var t = Host.Client.cl.worldmodel.Textures[i]; if (t == null) { continue; } var s = t.texturechain; if (s == null) { continue; } if ((s.flags & ( Int32 )Q1SurfaceFlags.Turbulence) == 0) { continue; } // set modulate mode explicitly t.texture.Bind( ); for ( ; s != null; s = s.texturechain) { WarpableTextures.EmitWaterPolys(Host.RealTime, s); } t.texturechain = null; } } // WaterAlpha is broken - will fix when we introduce GLSL... //if( _WaterAlpha.Value < 1.0 ) //{ // GL.TexEnv( TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, ( Int32 ) TextureEnvMode.Replace ); // GL.Color4( 1f, 1, 1, 1 ); // GL.Disable( EnableCap.Blend ); //} }