📄 gl_rsurf.pas
字号:
{*
** render dynamic lightmaps
*}
if (gl_dynamic.value <> 0) then
begin
LM_InitBlock();
GL_Bind (gl_state.lightmap_textures+0);
if (currentmodel = r_worldmodel) then
Inc(c_visible_lightmaps);
newdrawsurf := gl_lms.lightmap_surfaces[0];
//Y{Y} for ( surf = gl_lms.lightmap_surfaces[0]; surf != 0; surf = surf->lightmapchain )
begin
smax := (surf.extents[0] shr 4)+1;
tmax := (surf.extents[1] shr 4)+1;
if (LM_AllocBlock (smax, tmax, surf.dlight_s, surf.dlight_t))
then begin
base := @gl_lms.lightmap_buffer;
Inc(base, (surf.dlight_t * BLOCK_WIDTH + surf.dlight_s) * LIGHTMAP_BYTES);
//Y R_BuildLightMap (surf, base, BLOCK_WIDTH*LIGHTMAP_BYTES);
end
else begin
// upload what we have so far
LM_UploadBlock (true);
// draw all surfaces that use this lightmap
//Y{Y} for ( drawsurf = newdrawsurf; drawsurf != surf; drawsurf = drawsurf->lightmapchain )
begin
if (drawsurf.polys <> Nil) then
DrawGLPolyChain (drawsurf.polys,
(drawsurf.light_s - drawsurf.dlight_s) * (1.0/128.0),
(drawsurf.light_t - drawsurf.dlight_t) * (1.0/128.0));
end;//for???
newdrawsurf := drawsurf;
// clear the block
LM_InitBlock();
// try uploading the block now
if (NOT LM_AllocBlock( smax, tmax, surf.dlight_s, surf.dlight_t)) then
ri.Sys_Error (ERR_FATAL, 'Consecutive calls to LM_AllocBlock(%d,%d) failed (dynamic)\n', [smax, tmax]);
base := @gl_lms.lightmap_buffer;
Inc(base, (surf.dlight_t * BLOCK_WIDTH + surf.dlight_s) * LIGHTMAP_BYTES);
//Y R_BuildLightMap (surf, base, BLOCK_WIDTH*LIGHTMAP_BYTES);
end;//else
end;//for???
{*
** draw remainder of dynamic lightmaps that haven't been uploaded yet
*}
if (newdrawsurf <> Nil) then
LM_UploadBlock (true);
//Y{Y} for ( surf = newdrawsurf; surf != 0; surf = surf->lightmapchain )
begin
if (surf.polys <> Nil) then
DrawGLPolyChain (surf.polys,
(surf.light_s - surf.dlight_s ) * (1.0/128.0),
(surf.light_t - surf.dlight_t ) * (1.0/128.0));
end;//for???
end;//if
{*
** restore state
*}
qglDisable (GL_BLEND);
qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
qglDepthMask (1);
end;//procedure
{*
================
R_RenderBrushPoly
================
*}
procedure R_RenderBrushPoly (fa : msurface_p);
var
maps,
smax, tmax : integer;
image : image_p;
is_dynamic : qboolean;
// unsigned temp[34*34];}
temp : array [0..34*34-1] of integer; //array [0..34*34*4-1] of byte
label
_dynamic;
begin
is_dynamic := false;
Inc(c_brush_polys);
image := R_TextureAnimation (fa.texinfo);
if ((fa.flags AND SURF_DRAWTURB) <> 0)
then begin
GL_Bind (image.texnum);
// warp texture, no lightmaps
GL_TexEnv (GL_MODULATE);
qglColor4f (gl_state.inverse_intensity,
gl_state.inverse_intensity,
gl_state.inverse_intensity,
1.0);
//Y EmitWaterPolys (fa);
GL_TexEnv (GL_REPLACE);
Exit;
end
else begin
GL_Bind (image.texnum);
GL_TexEnv (GL_REPLACE);
end;
//======
//PGM
if (fa.texinfo.flags AND SURF_FLOWING) <> 0
then DrawGLFlowingPoly (fa)
else DrawGLPoly (fa.polys);
//PGM
//======
{*
** check for lightmap modification
*}
//Y{Y} for ( maps = 0; maps < MAXLIGHTMAPS && fa->styles[maps] != 255; maps++ )
begin
if (r_newrefdef.lightstyles[fa.styles[maps]].white <> fa.cached_light[maps]) then
goto _dynamic;
end;//for???
// dynamic this frame or dynamic previously
if (fa.dlightframe = r_framecount) then
begin
_dynamic:
if ( gl_dynamic.value <> 0 ) then
begin
// if (!( fa.texinfo.flags & (SURF_SKY|SURF_TRANS33|SURF_TRANS66|SURF_WARP ) ) ) then
if ( (fa.texinfo.flags AND (SURF_SKY OR SURF_TRANS33 OR SURF_TRANS66 OR SURF_WARP)) = 0 ) then
is_dynamic := true;
end;
end;//if
if (is_dynamic)
then begin
if ( ((fa.styles[maps] >= 32) OR (fa.styles[maps] = 0)) AND
(fa.dlightframe <> r_framecount) )
then begin
smax := (fa.extents[0] SHR 4)+1;
tmax := (fa.extents[1] SHR 4)+1;
(*Y R_BuildLightMap (fa, (void * )temp, smax*4);
R_SetCacheState (fa);*)
GL_Bind (gl_state.lightmap_textures + fa.lightmaptexturenum);
qglTexSubImage2D (GL_TEXTURE_2D, 0,
fa.light_s, fa.light_t,
smax, tmax,
GL_LIGHTMAP_FORMAT,
GL_UNSIGNED_BYTE, @temp);
fa.lightmapchain := gl_lms.lightmap_surfaces[fa.lightmaptexturenum];
gl_lms.lightmap_surfaces[fa.lightmaptexturenum] := fa;
end
else begin
fa.lightmapchain := gl_lms.lightmap_surfaces[0];
gl_lms.lightmap_surfaces[0] := fa;
end;
end
else begin
fa.lightmapchain := gl_lms.lightmap_surfaces[fa.lightmaptexturenum];
gl_lms.lightmap_surfaces[fa.lightmaptexturenum] := fa;
end;
end;//procedure
{*
================
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.
================
*}
procedure R_DrawAlphaSurfaces; //for gl_rmain
var
s : msurface_p;
intens : float;
begin
//
// go back to the world matrix
//
qglLoadMatrixf (@r_world_matrix);
qglEnable (GL_BLEND);
GL_TexEnv (GL_MODULATE);
// the textures are prescaled up for a better lighting range,
// so scale it back down
intens := gl_state.inverse_intensity;
//{Y} for (s=r_alpha_surfaces ; s ; s=s->texturechain)
s := r_alpha_surfaces;
while (s <> Nil) do
begin
//Y GL_Bind (s.texinfo.image.texnum);
Inc(c_brush_polys);
if (s.texinfo.flags AND SURF_TRANS33) <> 0
then qglColor4f (intens,intens,intens,0.33)
else
if (s.texinfo.flags AND SURF_TRANS66) <> 0
then qglColor4f (intens,intens,intens,0.66)
else qglColor4f (intens,intens,intens,1);
if (s.flags AND SURF_DRAWTURB) <> 0
then (*Y EmitWaterPolys (s)
else*) DrawGLPoly (s.polys);
s := s.texturechain;
end;//for???
GL_TexEnv (GL_REPLACE);
qglColor4f (1,1,1,1);
qglDisable (GL_BLEND);
r_alpha_surfaces := Nil;
end;//procedure
{*
================
DrawTextureChains
================
*}
procedure DrawTextureChains;
var
i : integer;
{ msurface_t *s;
image_t *image;}
begin
c_visible_textures := 0;
//idsoft GL_TexEnv( GL_REPLACE );
(*Y if (NOT Assigned(qglSelectTextureSGIS))
then begin
{Y} for ( i = 0, image=gltextures ; i<numgltextures ; i++,image++)
begin
if (!image.registration_sequence) then
Continue;
s := image.texturechain;
if (!s) then
Continue;
c_visible_textures++;
{Y} for ( ; s ; s=s->texturechain)
R_RenderBrushPoly (s);
image.texturechain := NULL;
end;//for???
end
else begin
{Y} for ( i = 0, image=gltextures ; i<numgltextures ; i++,image++)
begin
if (!image.registration_sequence) then
Continue;
if (!image.texturechain) then
Continue;
c_visible_textures++;
{Y} for ( s = image->texturechain; s ; s=s->texturechain)
begin
// if ( !( s->flags & SURF_DRAWTURB ) )
if ((s.flags AND SURF_DRAWTURB) = 0) then
R_RenderBrushPoly (s);
end;//for???
end;//for???*)
GL_EnableMultitexture (false);
(*Y{Y} for ( i = 0, image=gltextures ; i<numgltextures ; i++,image++)
begin
if (!image.registration_sequence) then
Continue;
s := image.texturechain;
if (!s) then
Continue;
{Y} for ( ; s ; s=s->texturechain)
begin
// if ( s->flags & SURF_DRAWTURB )
if (s.flags AND SURF_DRAWTURB) <> 0) then
R_RenderBrushPoly (s);
end;//for???
image.texturechain := NULL;
end;//for???
//idsoft GL_EnableMultitexture( true );
end;//else*)
GL_TexEnv (GL_REPLACE);
end;//procedure
procedure {static} GL_RenderLightmappedPoly (surf : msurface_p);
var
i, map : integer;
// float *v;
p : glpoly_p;
// unsigned temp[128*128];}
temp : array [0..128*128-1] of integer; //array [0..128*128*4-1] of byte
is_dynamic : qboolean;
smax, tmax : integer;
scroll : float;
//int nv = surf->polys->numverts;
nv : integer;
//image_t *image = R_TextureAnimation( surf->texinfo );
image : image_p;
// unsigned lmtex = surf->lightmaptexturenum;*)
lmtex : integer;
label
dynamic_;
begin
is_dynamic := false;
nv := surf.polys.numverts;
image := R_TextureAnimation(surf.texinfo);
lmtex := surf.lightmaptexturenum;
//Y{Y} for ( map = 0; map < MAXLIGHTMAPS && surf->styles[map] != 255; map++ )
begin
if (r_newrefdef.lightstyles[surf.styles[map]].white <> surf.cached_light[map]) then
goto dynamic_;
end;//for???
// dynamic this frame or dynamic previously
if (surf.dlightframe = r_framecount) then
begin
dynamic_:
if (gl_dynamic.value <> 0) then
begin
// if ( !(surf.texinfo.flags & (SURF_SKY|SURF_TRANS33|SURF_TRANS66|SURF_WARP ) ) )
if (surf.texinfo.flags AND (SURF_SKY OR SURF_TRANS33 OR SURF_TRANS66 OR SURF_WARP) = 0) then
is_dynamic := true;
end;
end;//if
if ( is_dynamic )
then begin
if ( ((surf.styles[map] >= 32) OR (surf.styles[map] = 0)) AND
(surf.dlightframe <> r_framecount) )
then begin
smax := (surf.extents[0] SHR 4)+1;
tmax := (surf.extents[1] SHR 4)+1;
(*Y R_BuildLightMap (surf, (void * )temp, smax*4);
R_SetCacheState (surf);
GL_MBind (GL_TEXTURE1_SGIS, gl_state.lightmap_textures + surf.lightmaptexturenum);*)
lmtex := surf.lightmaptexturenum;
qglTexSubImage2D (GL_TEXTURE_2D, 0,
surf.light_s, surf.light_t,
smax, tmax,
GL_LIGHTMAP_FORMAT,
GL_UNSIGNED_BYTE, @temp);
end
else begin
smax := (surf.extents[0] SHR 4)+1;
tmax := (surf.extents[1] SHR 4)+1;
(*Y R_BuildLightMap (surf, (void * )temp, smax*4);
GL_MBind (GL_TEXTURE1_SGIS, gl_state.lightmap_textures + 0);*)
lmtex := 0;
qglTexSubImage2D (GL_TEXTURE_2D, 0,
surf.light_s, surf.light_t,
smax, tmax,
GL_LIGHTMAP_FORMAT,
GL_UNSIGNED_BYTE, @temp);
end;
Inc(c_brush_polys);
(*Y GL_MBind (GL_TEXTURE0_SGIS, image.texnum);
GL_MBind (GL_TEXTURE1_SGIS, gl_state.lightmap_textures + lmtex);*)
//==========
//PGM
// if (surf->texinfo->flags & SURF_FLOWING)
if (surf.texinfo.flags AND SURF_FLOWING) <> 0
then begin
// scroll := -64 * ( (r_newrefdef.time / 40.0) - (int)(r_newrefdef.time / 40.0) );
scroll := -64 * Frac(r_newrefdef.time / 40.0);
if (scroll = 0.0) then
scroll := -64.0;
//{Y} for ( p = surf->polys; p; p = p->chain )
p := surf.polys;
while p <> Nil do
begin
(*Y v := p.verts[0];
qglBegin (GL_POLYGON);
{Y} for (i=0 ; i< nv; i++, v+= VERTEXSIZE)
begin
qglMTexCoord2fSGIS (GL_TEXTURE0_SGIS, (v[3]+scroll), v[4]);
qglMTexCoord2fSGIS (GL_TEXTURE1_SGIS, v[5], v[6]);
qglVertex3fv (v);
end;//for???*)
qglEnd ();
p := p.chain;
end;//for???
end
else begin
//{Y} for ( p = surf->polys; p; p = p->chain )
p := surf.polys;
while p <> Nil do
begin
(*Y v := p.verts[0];
qglBegin (GL_POLYGON);
{Y} for (i=0 ; i< nv; i++, v+= VERTEXSIZE)
begin
qglMTexCoord2fSGIS (GL_TEXTURE0_SGIS, v[3], v[4]);
qglMTexCoord2fSGIS (GL_TEXTURE1_SGIS, v[5], v[6]);
qglVertex3fv (v);
end;//for???*)
qglEnd ();
p := p.chain;
end;//for???
end;
//PGM
//==========
end//then
else begin
Inc(c_brush_polys);
(*Y GL_MBind (GL_TEXTURE0_SGIS, image.texnum);
GL_MBind (GL_TEXTURE1_SGIS, gl_state.lightmap_textures + lmtex);*)
//==========
//PGM
// if (surf->texinfo->flags & SURF_FLOWING)
if (surf.texinfo.flags AND SURF_FLOWING) <> 0
then begin
// scroll := -64 * ( (r_newrefdef.time / 40.0) - (int)(r_newrefdef.time / 40.0) );
scroll := -64 * Frac(r_newrefdef.time / 40.0);
if (scroll = 0.0) then
scroll := -64.0;
//{Y} for ( p = surf->polys; p; p = p->chain )
p := surf.polys;
while p <> Nil do
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -