mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-30 00:10:53 +00:00
Use vertex arrays in R_RenderLightmappedPoly.
This is done for normal surfaces only. To change SURF_FLOWING surfes I need to find such a surface somewhere in the game...
This commit is contained in:
parent
bcde80834f
commit
5840bd570b
3 changed files with 85 additions and 114 deletions
|
@ -45,9 +45,6 @@
|
||||||
|
|
||||||
#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB
|
#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB
|
||||||
|
|
||||||
#define GL_TEXTURE0_SGIS 0x835E
|
|
||||||
#define GL_TEXTURE1_SGIS 0x835F
|
|
||||||
|
|
||||||
#define GL_POINT_SIZE_MIN_EXT 0x8126
|
#define GL_POINT_SIZE_MIN_EXT 0x8126
|
||||||
#define GL_POINT_SIZE_MAX_EXT 0x8127
|
#define GL_POINT_SIZE_MAX_EXT 0x8127
|
||||||
#define GL_DISTANCE_ATTENUATION_EXT 0x8129
|
#define GL_DISTANCE_ATTENUATION_EXT 0x8129
|
||||||
|
@ -96,7 +93,14 @@
|
||||||
#define GL_OPERAND7_ALPHA_EXT 0x859F
|
#define GL_OPERAND7_ALPHA_EXT 0x859F
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* QGL main functions */
|
#ifdef _WIN32
|
||||||
|
GLAPI void APIENTRY glActiveTextureARB( GLenum texture );
|
||||||
|
GLAPI void APIENTRY glClientActiveTextureARB( GLenum texture );
|
||||||
|
GLAPI void APIENTRY glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t);
|
||||||
|
GLAPI void APIENTRY glMultiTexCoord2fvARB(GLenum target, const GLfloat *v);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// =======================================================================
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is responsible for setting up our QGL extension pointers
|
* This is responsible for setting up our QGL extension pointers
|
||||||
|
|
|
@ -81,8 +81,6 @@
|
||||||
#define REF_VERSION "Yamagi Quake II OpenGL Refresher"
|
#define REF_VERSION "Yamagi Quake II OpenGL Refresher"
|
||||||
#define MAX_LBM_HEIGHT 480
|
#define MAX_LBM_HEIGHT 480
|
||||||
#define BACKFACE_EPSILON 0.01
|
#define BACKFACE_EPSILON 0.01
|
||||||
#define DYNAMIC_LIGHT_WIDTH 128
|
|
||||||
#define DYNAMIC_LIGHT_HEIGHT 128
|
|
||||||
#define LIGHTMAP_BYTES 4
|
#define LIGHTMAP_BYTES 4
|
||||||
#define MAX_LIGHTMAPS 128
|
#define MAX_LIGHTMAPS 128
|
||||||
#define GL_LIGHTMAP_FORMAT GL_RGBA
|
#define GL_LIGHTMAP_FORMAT GL_RGBA
|
||||||
|
@ -96,7 +94,6 @@
|
||||||
/* fall over */
|
/* fall over */
|
||||||
#define ROLL 2
|
#define ROLL 2
|
||||||
|
|
||||||
char *strlwr(char *s);
|
|
||||||
extern viddef_t vid;
|
extern viddef_t vid;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -660,31 +660,42 @@ R_DrawTextureChains(void)
|
||||||
void
|
void
|
||||||
R_RenderLightmappedPoly(msurface_t *surf)
|
R_RenderLightmappedPoly(msurface_t *surf)
|
||||||
{
|
{
|
||||||
int i, nv = surf->polys->numverts;
|
int i;
|
||||||
int map;
|
int map;
|
||||||
|
int nv;
|
||||||
|
int smax;
|
||||||
|
int tmax;
|
||||||
|
float scroll;
|
||||||
float *v;
|
float *v;
|
||||||
image_t *image = R_TextureAnimation(surf->texinfo);
|
|
||||||
qboolean is_dynamic = false;
|
|
||||||
unsigned lmtex = surf->lightmaptexturenum;
|
|
||||||
glpoly_t *p;
|
glpoly_t *p;
|
||||||
|
image_t *image;
|
||||||
|
qboolean is_dynamic;
|
||||||
|
unsigned lmtex;
|
||||||
|
unsigned temp[128 * 128];
|
||||||
|
|
||||||
|
image = R_TextureAnimation(surf->texinfo);
|
||||||
|
is_dynamic = false;
|
||||||
|
lmtex = surf->lightmaptexturenum;
|
||||||
|
nv = surf->polys->numverts;
|
||||||
|
|
||||||
|
// Any dynamic lights on this surface?
|
||||||
for (map = 0; map < MAXLIGHTMAPS && surf->styles[map] != 255; map++)
|
for (map = 0; map < MAXLIGHTMAPS && surf->styles[map] != 255; map++)
|
||||||
{
|
{
|
||||||
if (r_newrefdef.lightstyles[surf->styles[map]].white !=
|
if (r_newrefdef.lightstyles[surf->styles[map]].white != surf->cached_light[map])
|
||||||
surf->cached_light[map])
|
|
||||||
{
|
{
|
||||||
goto dynamic;
|
if (!(surf->texinfo->flags & (SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)))
|
||||||
|
{
|
||||||
|
is_dynamic = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normal dynamic lights
|
||||||
if (surf->dlightframe == r_framecount)
|
if (surf->dlightframe == r_framecount)
|
||||||
{
|
{
|
||||||
dynamic:
|
|
||||||
|
|
||||||
if (gl_dynamic->value)
|
if (gl_dynamic->value)
|
||||||
{
|
{
|
||||||
if (!(surf->texinfo->flags &
|
if (!(surf->texinfo->flags & (SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)))
|
||||||
(SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP)))
|
|
||||||
{
|
{
|
||||||
is_dynamic = true;
|
is_dynamic = true;
|
||||||
}
|
}
|
||||||
|
@ -693,138 +704,97 @@ R_RenderLightmappedPoly(msurface_t *surf)
|
||||||
|
|
||||||
if (is_dynamic)
|
if (is_dynamic)
|
||||||
{
|
{
|
||||||
unsigned temp[128 * 128];
|
// Dynamic lights on a surface
|
||||||
int smax, tmax;
|
if (((surf->styles[map] >= 32) || (surf->styles[map] == 0)) && (surf->dlightframe != r_framecount))
|
||||||
|
|
||||||
if (((surf->styles[map] >= 32) ||
|
|
||||||
(surf->styles[map] == 0)) &&
|
|
||||||
(surf->dlightframe != r_framecount))
|
|
||||||
{
|
{
|
||||||
smax = (surf->extents[0] >> 4) + 1;
|
smax = (surf->extents[0] >> 4) + 1;
|
||||||
tmax = (surf->extents[1] >> 4) + 1;
|
tmax = (surf->extents[1] >> 4) + 1;
|
||||||
|
|
||||||
R_BuildLightMap(surf, (void *)temp, smax * 4);
|
R_BuildLightMap(surf, (void *) temp, smax * 4);
|
||||||
R_SetCacheState(surf);
|
R_SetCacheState(surf);
|
||||||
|
|
||||||
R_MBind(GL_TEXTURE1_ARB, gl_state.lightmap_textures + surf->lightmaptexturenum);
|
R_MBind(GL_TEXTURE1_ARB, gl_state.lightmap_textures + surf->lightmaptexturenum);
|
||||||
|
|
||||||
lmtex = surf->lightmaptexturenum;
|
lmtex = surf->lightmaptexturenum;
|
||||||
|
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, surf->light_s, surf->light_t,
|
glTexSubImage2D(GL_TEXTURE_2D, 0, surf->light_s, surf->light_t, smax,
|
||||||
smax, tmax, GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE, temp);
|
tmax, GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE, temp);
|
||||||
}
|
}
|
||||||
else
|
else // Normal dynamic lights
|
||||||
{
|
{
|
||||||
smax = (surf->extents[0] >> 4) + 1;
|
smax = (surf->extents[0] >> 4) + 1;
|
||||||
tmax = (surf->extents[1] >> 4) + 1;
|
tmax = (surf->extents[1] >> 4) + 1;
|
||||||
|
|
||||||
R_BuildLightMap(surf, (void *)temp, smax * 4);
|
R_BuildLightMap(surf, (void *) temp, smax * 4);
|
||||||
|
|
||||||
R_MBind(GL_TEXTURE1_ARB, gl_state.lightmap_textures + 0);
|
R_MBind(GL_TEXTURE1_ARB, gl_state.lightmap_textures + 0);
|
||||||
|
|
||||||
lmtex = 0;
|
lmtex = 0;
|
||||||
|
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, surf->light_s, surf->light_t,
|
glTexSubImage2D(GL_TEXTURE_2D, 0, surf->light_s, surf->light_t, smax,
|
||||||
smax, tmax, GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE, temp);
|
tmax, GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
c_brush_polys++;
|
c_brush_polys++;
|
||||||
|
|
||||||
R_MBind(GL_TEXTURE0_ARB, image->texnum);
|
R_MBind(GL_TEXTURE0_ARB, image->texnum);
|
||||||
R_MBind(GL_TEXTURE1_ARB, gl_state.lightmap_textures + lmtex);
|
R_MBind(GL_TEXTURE1_ARB, gl_state.lightmap_textures + lmtex);
|
||||||
|
|
||||||
if (surf->texinfo->flags & SURF_FLOWING)
|
|
||||||
{
|
|
||||||
float scroll;
|
|
||||||
|
|
||||||
scroll = -64 * ((r_newrefdef.time / 40.0) - (int)(r_newrefdef.time / 40.0));
|
|
||||||
|
|
||||||
if (scroll == 0.0)
|
|
||||||
{
|
|
||||||
scroll = -64.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (p = surf->polys; p; p = p->chain)
|
|
||||||
{
|
|
||||||
v = p->verts[0];
|
|
||||||
glBegin(GL_POLYGON);
|
|
||||||
|
|
||||||
for (i = 0; i < nv; i++, v += VERTEXSIZE)
|
|
||||||
{
|
|
||||||
qglMultiTexCoord2fARB(GL_TEXTURE0, (v[3]+scroll), v[4]);
|
|
||||||
qglMultiTexCoord2fvARB(GL_TEXTURE1, &v[5]);
|
|
||||||
glVertex3fv(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
for (p = surf->polys; p; p = p->chain)
|
|
||||||
{
|
|
||||||
v = p->verts[0];
|
|
||||||
glBegin(GL_POLYGON);
|
|
||||||
|
|
||||||
for (i=0 ; i< nv; i++, v+= VERTEXSIZE)
|
|
||||||
{
|
|
||||||
qglMultiTexCoord2fvARB(GL_TEXTURE0, &v[3]);
|
|
||||||
qglMultiTexCoord2fvARB(GL_TEXTURE1, &v[5]);
|
|
||||||
glVertex3fv(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else // No dynamic lights
|
||||||
{
|
{
|
||||||
c_brush_polys++;
|
c_brush_polys++;
|
||||||
|
|
||||||
R_MBind(GL_TEXTURE0_ARB, image->texnum);
|
R_MBind(GL_TEXTURE0_ARB, image->texnum);
|
||||||
R_MBind(GL_TEXTURE1_ARB, gl_state.lightmap_textures + lmtex);
|
R_MBind(GL_TEXTURE1_ARB, gl_state.lightmap_textures + lmtex);
|
||||||
|
}
|
||||||
|
|
||||||
if (surf->texinfo->flags & SURF_FLOWING)
|
if (surf->texinfo->flags & SURF_FLOWING)
|
||||||
|
{
|
||||||
|
scroll = -64 * ((r_newrefdef.time / 40.0) - (int) (r_newrefdef.time / 40.0));
|
||||||
|
|
||||||
|
if (scroll == 0.0)
|
||||||
{
|
{
|
||||||
float scroll;
|
scroll = -64.0;
|
||||||
|
|
||||||
scroll = -64 * ((r_newrefdef.time / 40.0) - (int)(r_newrefdef.time / 40.0));
|
|
||||||
|
|
||||||
if (scroll == 0.0)
|
|
||||||
{
|
|
||||||
scroll = -64.0;
|
|
||||||
}
|
|
||||||
for (p = surf->polys; p; p = p->chain)
|
|
||||||
{
|
|
||||||
v = p->verts[0];
|
|
||||||
glBegin(GL_POLYGON);
|
|
||||||
|
|
||||||
for (i=0 ; i< nv; i++, v+= VERTEXSIZE)
|
|
||||||
{
|
|
||||||
qglMultiTexCoord2fARB(GL_TEXTURE0, (v[3]+scroll), v[4]);
|
|
||||||
qglMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]);
|
|
||||||
}
|
|
||||||
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
for (p = surf->polys; p; p = p->chain)
|
||||||
{
|
{
|
||||||
for (p = surf->polys; p; p = p->chain)
|
v = p->verts[0];
|
||||||
|
glBegin(GL_POLYGON);
|
||||||
|
|
||||||
|
for (i = 0; i < nv; i++, v += VERTEXSIZE)
|
||||||
{
|
{
|
||||||
v = p->verts[0];
|
qglMultiTexCoord2fARB(GL_TEXTURE0, (v[3] + scroll), v[4]);
|
||||||
glBegin (GL_POLYGON);
|
qglMultiTexCoord2fvARB(GL_TEXTURE1, &v[5]);
|
||||||
|
glVertex3fv(v);
|
||||||
for (i=0 ; i< nv; i++, v+= VERTEXSIZE)
|
|
||||||
{
|
|
||||||
qglMultiTexCoord2fvARB(GL_TEXTURE0, &v[3]);
|
|
||||||
qglMultiTexCoord2fvARB(GL_TEXTURE1, &v[5]);
|
|
||||||
glVertex3fv(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
glEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (p = surf->polys; p; p = p->chain)
|
||||||
|
{
|
||||||
|
v = p->verts[0];
|
||||||
|
|
||||||
|
// Polygon
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glVertexPointer(3, GL_FLOAT, VERTEXSIZE * sizeof(GLfloat), v);
|
||||||
|
|
||||||
|
// Texture
|
||||||
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
qglClientActiveTextureARB(GL_TEXTURE0_ARB);
|
||||||
|
glTexCoordPointer(2, GL_FLOAT, VERTEXSIZE * sizeof(GLfloat), v + 3);
|
||||||
|
|
||||||
|
// Lightmap
|
||||||
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
qglClientActiveTextureARB(GL_TEXTURE1_ARB);
|
||||||
|
glTexCoordPointer(2, GL_FLOAT, VERTEXSIZE * sizeof(GLfloat), v + 5);
|
||||||
|
|
||||||
|
// Draw the crap
|
||||||
|
glDrawArrays(GL_TRIANGLE_FAN, 0, p->numverts);
|
||||||
|
|
||||||
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue