📄 gl_rsurf.pas
字号:
// PLEASE, don't modify this file
// 81% complete
{----------------------------------------------------------------------------}
{ }
{ File(s): GL_RSURF.C: surface-related refresh code }
{ }
{ Initial conversion by : YgriK (Igor Karpov) - glYgriK@hotbox.ru }
{ Initial conversion on : 16-Jan-2002 }
{ }
{ This File contains part of convertion of Quake2 source to ObjectPascal. }
{ More information about this project can be found at: }
{ http://www.sulaco.co.za/quake2/ }
{ }
{ 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. }
{ }
{----------------------------------------------------------------------------}
{ Updated on : }
{ Updated by : }
{ }
{----------------------------------------------------------------------------}
{ * Still dependent (to compile correctly) on: }
{ x) }
{ }
{----------------------------------------------------------------------------}
{ * TODO: }
{ 1) Do more tests }
{ }
{----------------------------------------------------------------------------}
// GL_RSURF.C: surface-related refresh code
unit gl_rsurf;
interface
uses q_shared, ref, qfiles,
gl_local, GL, qgl_win, gl_model_h, gl_rmain;
procedure R_DrawAlphaSurfaces; //for gl_rmain
procedure R_DrawBrushModel (e : entity_p); //for gl_rmain
procedure R_DrawWorld; //for gl_rmain
procedure R_MarkLeaves; //for gl_rmain
procedure GL_BuildPolygonFromSurface (fa : msurface_p); //for gl_model
procedure GL_CreateSurfaceLightmap (surf : msurface_p); //for gl_model
procedure GL_BeginBuildingLightmaps (m : model_p); //for gl_model
procedure GL_EndBuildingLightmaps; //for gl_model
implementation
uses gl_model, gl_image;
// Math_procedure Xxx(); overload;{$I OVERLOAD_need_remove.inc}
//#include <assert.h>
var
//static vec3_t modelorg; // relative to viewpoint
modelorg : vec3_t; // relative to viewpoint
//msurface_t *r_alpha_surfaces;
r_alpha_surfaces : msurface_p;
const
DYNAMIC_LIGHT_WIDTH = 128;
DYNAMIC_LIGHT_HEIGHT = 128;
LIGHTMAP_BYTES = 4;
BLOCK_WIDTH = 128;
BLOCK_HEIGHT = 128;
MAX_LIGHTMAPS = 128;
GL_LIGHTMAP_FORMAT = GL_RGBA;
(*typedef struct
{
...
} gllightmapstate_t;
static gllightmapstate_t gl_lms;*)
type
gllightmapstate_t = record
internal_format : integer;
current_lightmap_texture : integer;
// msurface_t *lightmap_surfaces[MAX_LIGHTMAPS];
lightmap_surfaces : array [0..MAX_LIGHTMAPS-1] of msurface_p;
allocated : array [0..BLOCK_WIDTH-1] of integer;
// the lightmap texture data needs to be kept in
// main memory so texsubimage can update properly
lightmap_buffer : array [0..4*BLOCK_WIDTH*BLOCK_HEIGHT-1] of byte;
end;
var
gl_lms : gllightmapstate_t;
(*static void LM_InitBlock( void );
static void LM_UploadBlock( qboolean dynamic );
static qboolean LM_AllocBlock (int w, int h, int *x, int *y);*)
function {static} LM_AllocBlock (w, h : integer; {int *x, int *y}var x, y : integer) : qboolean; forward;
procedure {static} LM_UploadBlock (dynamic_ : qboolean); forward;
procedure {static} LM_InitBlock; forward;
(*extern void R_SetCacheState( msurface_t *surf );
extern void R_BuildLightMap (msurface_t *surf, byte *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)
function R_TextureAnimation (tex : mtexinfo_p) : image_p;
var
c : integer;
begin
if (tex.next=Nil) then
begin
//Y Result := tex.image;
Exit;
end;
(* c := currententity.frame % tex.numframes;
while (c)
{
tex := tex.next;
c--;
}*)
c := currententity.frame MOD tex.numframes;
while (c<>0) do
begin
tex := tex.next;
Dec(c);
end;
//Y Result := tex.image;
end;//function
(*#if 0
/*
=================
WaterWarpPolyVerts
Mangles the x and y coordinates in a copy of the poly
so that any drawing routine can be water warped
=================
*/
glpoly_t *WaterWarpPolyVerts (glpoly_t *p)
{
int i;
float *v, *nv;
static byte buffer[1024];
glpoly_t *out;
out = (glpoly_t * )buffer;
out->numverts = p->numverts;
v = p->verts[0];
nv = out->verts[0];
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE, nv+=VERTEXSIZE)
{
nv[0] = v[0] + 4*sin(v[1]*0.05+r_newrefdef.time)*sin(v[2]*0.05+r_newrefdef.time);
nv[1] = v[1] + 4*sin(v[0]*0.05+r_newrefdef.time)*sin(v[2]*0.05+r_newrefdef.time);
nv[2] = v[2];
nv[3] = v[3];
nv[4] = v[4];
nv[5] = v[5];
nv[6] = v[6];
}
return out;
}
/*
================
DrawGLWaterPoly
Warp the vertex coordinates
================
*/
void DrawGLWaterPoly (glpoly_t *p)
{
int i;
float *v;
p = WaterWarpPolyVerts (p);
qglBegin (GL_TRIANGLE_FAN);
v = p->verts[0];
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
{
qglTexCoord2f (v[3], v[4]);
qglVertex3fv (v);
}
qglEnd ();
}
void DrawGLWaterPolyLightmap (glpoly_t *p)
{
int i;
float *v;
p = WaterWarpPolyVerts (p);
qglBegin (GL_TRIANGLE_FAN);
v = p->verts[0];
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
{
qglTexCoord2f (v[5], v[6]);
qglVertex3fv (v);
}
qglEnd ();
}
#endif*)
{*
================
DrawGLPoly
================
*}
procedure DrawGLPoly (p : glpoly_p);
var
i : integer;
// float *v;
v : pfloat;
begin
qglBegin (GL_POLYGON);
(*original C-code:
v = p->verts[0];
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
{
qglTexCoord2f (v[3], v[4]);
qglVertex3fv (v);
}*)
(*Y//PAS1 - ???
v := p.verts[0];
{Y} for i:=0 to p.numverts-1 do// ; i++, v+= VERTEXSIZE)
begin
qglTexCoord2f (v[3], v[4]);
qglVertex3fv (v);
end;//for???
//PAS2 - ???
for i:=0 to p.numverts-1 do
begin
v := p.verts[i]; //add info: gl_model.h (typedef struct gl_poly_s)
qglTexCoord2f (v[3], v[4]);
qglVertex3fv (v);
end;*)
qglEnd ();
end;//procedure
//============
//PGM
{*
================
DrawGLFlowingPoly -- version of DrawGLPoly that handles scrolling texture
================
*}
procedure DrawGLFlowingPoly (fa : msurface_p);
var
i : integer;
// float *v;
p : glpoly_p;
scroll : float;
begin
p := fa.polys;
// scroll := -64 * ( (r_newrefdef.time / 40.0) - (int)(r_newrefdef.time / 40.0) );
//Y scroll := -64 * Frac(r_newrefdef.time / 40.0); //Y
if (scroll = 0.0) then
scroll := -64.0;
qglBegin (GL_POLYGON);
(*Y v := p.verts[0];
{Y} for i:=0 to p.numverts-1 do// ; i++, v+= VERTEXSIZE)
begin
qglTexCoord2f ((v[3] + scroll), v[4]);
qglVertex3fv (v);
end;//for???*)
qglEnd ();
end;//procedure
//PGM
//============
{*
** R_DrawTriangleOutlines
*}
procedure R_DrawTriangleOutlines;
var
i, j : integer;
p : glpoly_p;
surf : msurface_p;
begin
if (gl_showtris.value <> 0) then
Exit;
qglDisable (GL_TEXTURE_2D);
qglDisable (GL_DEPTH_TEST);
qglColor4f (1,1,1,1);
for i:=0 to MAX_LIGHTMAPS-1 do
begin
(*Y{Y} for ( surf = gl_lms.lightmap_surfaces[i]; surf != 0; surf = surf->lightmapchain )
begin
p := surf.polys;
{Y} for ( ; p ; p=p->chain)
begin*)
for j:=2 to p.numverts-1 do
begin
qglBegin (GL_LINE_STRIP);
qglVertex3fv (@p.verts[0]);
qglVertex3fv (@p.verts[j-1]);
qglVertex3fv (@p.verts[j]);
qglVertex3fv (@p.verts[0]);
qglEnd ();
end;
(*Y end;//for???
end;//for???*)
end;//for i
qglEnable (GL_DEPTH_TEST);
qglEnable (GL_TEXTURE_2D);
end;//procedure
{*
** DrawGLPolyChain
*}
procedure DrawGLPolyChain (p : glpoly_p; soffset, toffset : float);
var
// float *v;
j : integer;
begin
if (soffset = 0) and (toffset = 0)
then begin
(*Y{Y} for ( ; p != 0; p = p->chain )
begin
qglBegin (GL_POLYGON);
v := p.verts[0];
{Y} for j:=0 to p.numverts-1 do// ; j++, v+= VERTEXSIZE)
begin
qglTexCoord2f (v[5], v[6]);
qglVertex3fv (v);
end;
qglEnd ();
end;//for???*)
end
else begin
(*Y{Y} for ( ; p != 0; p = p->chain )
begin
qglBegin (GL_POLYGON);
v := p.verts[0];
{Y} for j:=0 to p.numverts-1 do// ; j++, v+= VERTEXSIZE)
begin
qglTexCoord2f (v[5] - soffset, v[6] - toffset);
qglVertex3fv (v);
end;
qglEnd ();
end;//for???*)
end;
end;//procedure
{*
** R_BlendLightMaps
**
** This routine takes all the given light mapped surfaces in the world and
** blends them into the framebuffer.
*}
procedure R_BlendLightmaps;
var
i, smax, tmax : integer;
// msurface_t *surf, *newdrawsurf = 0;
surf,
newdrawsurf,
drawsurf : msurface_p;
// byte *base;
base : PByte;
begin
newdrawsurf := Nil;
// don't bother if we're set to fullbright
if (r_fullbright.value <> 0) then
Exit;
if (r_worldmodel.lightdata <> Nil) then
Exit;
// don't bother writing Z
qglDepthMask (0);
{*
** set the appropriate blending mode unless we're only looking at the
** lightmaps.
*}
if (gl_lightmap.value <> 0) then
begin
qglEnable (GL_BLEND);
if (gl_saturatelighting.value <> 0)
then qglBlendFunc (GL_ONE, GL_ONE)
else begin
if (gl_monolightmap.string_[0] <> '0')
then begin
(*Y Case (toupper(gl_monolightmap.string[0])) of
'I': qglBlendFunc (GL_ZERO, GL_SRC_COLOR);
'L': qglBlendFunc (GL_ZERO, GL_SRC_COLOR);
//???
'A':
else
qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
end;//case*)
end
else qglBlendFunc (GL_ZERO, GL_SRC_COLOR);
end;//else
end;//if
if (currentmodel = r_worldmodel) then
c_visible_lightmaps := 0;
{*
** render static lightmaps first
*}
for i:=1 to MAX_LIGHTMAPS-1 do
if ( gl_lms.lightmap_surfaces[i] <> Nil ) then
begin
if (currentmodel = r_worldmodel) then
Inc(c_visible_lightmaps);
GL_Bind (gl_state.lightmap_textures + i);
(*Y for ( surf = gl_lms.lightmap_surfaces[i]; surf != 0; surf = surf->lightmapchain )*)
begin
if (surf.polys <> Nil) then
DrawGLPolyChain (surf.polys, 0, 0);
end;//for???
end;//if
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -