2003-01-17 21:18:53 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
// r_surf.c: surface-related refresh code
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
|
|
|
|
|
|
|
#ifndef GL_RGBA4
|
|
|
|
#define GL_RGBA4 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
int lightmap_bytes; // 1, 2, or 4
|
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
int lightmap_textures = 0;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
#define MAX_LIGHTMAPS 256
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
glpoly_t *lightmap_polys[MAX_LIGHTMAPS];
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================================================
|
2003-05-04 21:47:08 +00:00
|
|
|
Global vertex table stuff:
|
|
|
|
|
|
|
|
The global vertex table contains world+brush model+static models+curve vertices.
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
We first add vertices to a dynamically allocated buffer (malloc)
|
|
|
|
at the end of level loading we copy that to a "quake" allocated
|
|
|
|
buffer (on the Hunk)
|
|
|
|
====================================================
|
|
|
|
*/
|
|
|
|
mmvertex_t *globalVertexTable = NULL;
|
|
|
|
|
|
|
|
mmvertex_t *tempVertices = NULL;
|
|
|
|
int tempVerticesSize = 0;
|
|
|
|
int numTempVertices = 0;
|
|
|
|
|
|
|
|
int R_GetNextVertexIndex(void) {
|
|
|
|
return numTempVertices;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
Returns the index of the vertex the date was copied to...
|
|
|
|
*/
|
|
|
|
int R_AllocateVertexInTemp(vec3_t pos, float texture [2], float lightmap[2], byte color[4]) {
|
|
|
|
|
|
|
|
int i;
|
|
|
|
mmvertex_t *temp;
|
|
|
|
|
|
|
|
|
|
|
|
if (!tempVertices) {
|
|
|
|
tempVerticesSize = 512;
|
|
|
|
tempVertices = malloc(tempVerticesSize*sizeof(mmvertex_t));
|
|
|
|
numTempVertices = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numTempVertices >= tempVerticesSize) {
|
|
|
|
|
|
|
|
tempVerticesSize+=512;
|
|
|
|
temp = malloc(tempVerticesSize*sizeof(mmvertex_t));
|
|
|
|
if (!temp) Sys_Error("R_AllocateVertexInTemp: malloc failed\n");
|
|
|
|
Q_memcpy(temp,tempVertices,(tempVerticesSize-512)*sizeof(mmvertex_t));
|
|
|
|
free(tempVertices);
|
|
|
|
tempVertices = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
VectorCopy(pos,tempVertices[numTempVertices].position);
|
|
|
|
for (i=0; i<2; i++) {
|
|
|
|
tempVertices[numTempVertices].texture[i] = texture[i];
|
|
|
|
tempVertices[numTempVertices].lightmap[i] = lightmap[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<4; i++) {
|
|
|
|
tempVertices[numTempVertices].color[i] = color[i];
|
|
|
|
}
|
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
globalVertexTable = tempVertices;
|
|
|
|
|
2003-01-17 21:18:53 +00:00
|
|
|
numTempVertices++;
|
|
|
|
return numTempVertices-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_CopyVerticesToHunk(void)
|
|
|
|
{
|
|
|
|
globalVertexTable = Hunk_Alloc(numTempVertices*sizeof(mmvertex_t));
|
|
|
|
Q_memcpy(globalVertexTable,tempVertices,numTempVertices*sizeof(mmvertex_t));
|
|
|
|
free(tempVertices);
|
|
|
|
Con_Printf("Copied %i vertices to hunk\n",numTempVertices);
|
|
|
|
|
|
|
|
tempVertices = NULL;
|
|
|
|
tempVerticesSize = 0;
|
|
|
|
numTempVertices = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_EnableVertexTable(int fields) {
|
|
|
|
|
|
|
|
glVertexPointer(3, GL_FLOAT, VERTEXSIZE*sizeof(float), globalVertexTable);
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
|
|
|
|
if (fields & VERTEX_TEXTURE) {
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, VERTEXSIZE*sizeof(float), (float *)(globalVertexTable)+3);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fields & VERTEX_LIGHTMAP) {
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE1_ARB);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, VERTEXSIZE*sizeof(float), (float *)(globalVertexTable)+5);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
}
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_DisableVertexTable(int fields) {
|
|
|
|
|
|
|
|
glVertexPointer(3, GL_FLOAT, 0, globalVertexTable);
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
|
|
|
|
if (fields & VERTEX_TEXTURE) {
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fields & VERTEX_LIGHTMAP) {
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE1_ARB);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
}
|
|
|
|
qglClientActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
}
|
|
|
|
|
|
|
|
void R_RenderDynamicLightmaps (msurface_t *fa);
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================
|
|
|
|
|
|
|
|
BRUSH MODELS
|
|
|
|
|
|
|
|
=============================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
extern int solidskytexture;
|
|
|
|
extern int alphaskytexture;
|
|
|
|
extern float speedscale; // for top sky and bottom sky
|
|
|
|
|
|
|
|
void DrawGLWaterPoly (glpoly_t *p);
|
|
|
|
void DrawGLWaterPolyLightmap (glpoly_t *p);
|
|
|
|
|
|
|
|
//lpMTexFUNC qgl MTexCoord2fSGIS = NULL;
|
|
|
|
//lpSelTexFUNC qgl SelectTextureSGIS = NULL;
|
|
|
|
|
|
|
|
/* NV_register_combiners command function pointers
|
|
|
|
PENTA: I put them here because mtex functions are above it, and I hadent't any ispiration for some other place.
|
|
|
|
*/
|
|
|
|
PFNGLCOMBINERPARAMETERFVNVPROC qglCombinerParameterfvNV = NULL;
|
|
|
|
PFNGLCOMBINERPARAMETERIVNVPROC qglCombinerParameterivNV = NULL;
|
|
|
|
PFNGLCOMBINERPARAMETERFNVPROC qglCombinerParameterfNV = NULL;
|
|
|
|
PFNGLCOMBINERPARAMETERINVPROC qglCombinerParameteriNV = NULL;
|
|
|
|
PFNGLCOMBINERINPUTNVPROC qglCombinerInputNV = NULL;
|
|
|
|
PFNGLCOMBINEROUTPUTNVPROC qglCombinerOutputNV = NULL;
|
|
|
|
PFNGLFINALCOMBINERINPUTNVPROC qglFinalCombinerInputNV = NULL;
|
|
|
|
PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC qglGetCombinerInputParameterfvNV = NULL;
|
|
|
|
PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC qglGetCombinerInputParameterivNV = NULL;
|
|
|
|
PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC qglGetCombinerOutputParameterfvNV = NULL;
|
|
|
|
PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC qglGetCombinerOutputParameterivNV = NULL;
|
|
|
|
PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC qglGetFinalCombinerInputParameterfvNV = NULL;
|
|
|
|
PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC qglGetFinalCombinerInputParameterivNV = NULL;
|
2003-02-03 14:01:02 +00:00
|
|
|
PFNGLCOMBINERSTAGEPARAMETERFVNVPROC qglCombinerStageParameterfvNV = NULL;
|
|
|
|
PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC qglGetCombinerStageParameterfvNV = NULL;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
PFNGLTEXIMAGE3DEXT qglTexImage3DEXT = NULL;
|
|
|
|
|
|
|
|
PFNGLACTIVETEXTUREARBPROC qglActiveTextureARB = NULL;
|
|
|
|
PFNGLCLIENTACTIVETEXTUREARBPROC qglClientActiveTextureARB = NULL;
|
|
|
|
PFNGLMULTITEXCOORD1FARBPROC qglMultiTexCoord1fARB = NULL;
|
|
|
|
PFNGLMULTITEXCOORD2FARBPROC qglMultiTexCoord2fARB = NULL;
|
|
|
|
PFNGLMULTITEXCOORD2FVARBPROC qglMultiTexCoord2fvARB = NULL;
|
|
|
|
PFNGLMULTITEXCOORD3FARBPROC qglMultiTexCoord3fARB = NULL;
|
|
|
|
PFNGLMULTITEXCOORD3FVARBPROC qglMultiTexCoord3fvARB = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
ARB_vertex_program
|
|
|
|
PFNGLBINDPROGRAMARBPROC qglBindProgramARB = NULL;
|
|
|
|
PFNGLDELETEPROGRAMSARBPROC qglDeleteProgramsARB = NULL;
|
|
|
|
PFNGLGENPROGRAMSARBPROC qglGenProgramsARB = NULL;
|
|
|
|
PFNGLGETPROGRAMIVARBPROC qglGetProgramivARB = NULL;
|
|
|
|
PFNGLGETPROGRAMSTRINGARBPROC qglGetProgramStringARB = NULL;
|
|
|
|
PFNGLGETVERTEXATTRIBDVARBPROC qglGetVertexAttribdvARB = NULL;
|
|
|
|
PFNGLGETVERTEXATTRIBFVARBPROC qglGetVertexAttribfvARB = NULL;
|
|
|
|
PFNGLGETVERTEXATTRIBIVARBPROC qglGetVertexAttribivARB = NULL;
|
|
|
|
PFNGLGETVERTEXATTRIBPOINTERVARBPROC qglGetVertexAttribPointervARB = NULL;
|
|
|
|
PFNGLISPROGRAMARBPROC qglIsProgramARB = NULL;
|
|
|
|
PFNGPROGRAMSTRINGARBPROC qglProgramStringARB = NULL;
|
|
|
|
PFNGLTRACKMATRIXNVPROC glTrackMatrixNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB1DARBPROC qglVertexAttrib1dARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB1DVARBPROC qglVertexAttrib1dvARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB1FARBPROC qglVertexAttrib1fARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB1FVARBPROC qglVertexAttrib1fvARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB1SARBPROC qglVertexAttrib1sARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB1SVARBPROC qglVertexAttrib1svARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB2DARBPROC qglVertexAttrib2dARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB2DVARBPROC qglVertexAttrib2dvARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB2FARBPROC qglVertexAttrib2fARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB2FVARBPROC qglVertexAttrib2fvARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB2SARBPROC qglVertexAttrib2sARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB2SVARBPROC qglVertexAttrib2svARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB3DARBPROC qglVertexAttrib3dARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB3DVARBPROC qglVertexAttrib3dvARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB3FARBPROC qglVertexAttrib3fARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB3FVARBPROC qglVertexAttrib3fvARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB3SARBPROC qglVertexAttrib3sARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB3SVARBPROC qglVertexAttrib3svARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4DARBPROC qglVertexAttrib4dARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4DVARBPROC qglVertexAttrib4dvARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4FARBPROC qglVertexAttrib4fARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4FVARBPROC qglVertexAttrib4fvARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4SARBPROC qglVertexAttrib4sARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4SVARBPROC qglVertexAttrib4svARB = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4UBVARBPROC qglVertexAttrib4ubvARB = NULL;
|
|
|
|
*/
|
|
|
|
|
|
|
|
PFNGLAREPROGRAMSRESIDENTNVPROC qglAreProgramsResidentNV = NULL;
|
|
|
|
PFNGLBINDPROGRAMNVPROC qglBindProgramNV = NULL;
|
|
|
|
PFNGLDELETEPROGRAMSNVPROC qglDeleteProgramsNV = NULL;
|
|
|
|
PFNGLEXECUTEPROGRAMNVPROC qglExecuteProgramNV = NULL;
|
|
|
|
PFNGLGENPROGRAMSNVPROC qglGenProgramsNV = NULL;
|
|
|
|
PFNGLGETPROGRAMPARAMETERDVNVPROC qglGetProgramParameterdvNV = NULL;
|
|
|
|
PFNGLGETPROGRAMPARAMETERFVNVPROC qglGetProgramParameterfvNV = NULL;
|
|
|
|
PFNGLGETPROGRAMIVNVPROC qglGetProgramivNV = NULL;
|
|
|
|
PFNGLGETPROGRAMSTRINGNVPROC qglGetProgramStringNV = NULL;
|
|
|
|
PFNGLGETTRACKMATRIXIVNVPROC qglGetTrackMatrixivNV = NULL;
|
|
|
|
PFNGLGETVERTEXATTRIBDVNVPROC qglGetVertexAttribdvNV = NULL;
|
|
|
|
PFNGLGETVERTEXATTRIBFVNVPROC qglGetVertexAttribfvNV = NULL;
|
|
|
|
PFNGLGETVERTEXATTRIBIVNVPROC qglGetVertexAttribivNV = NULL;
|
|
|
|
PFNGLGETVERTEXATTRIBPOINTERVNVPROC qglGetVertexAttribPointervNV = NULL;
|
|
|
|
PFNGLISPROGRAMNVPROC qglIsProgramNV = NULL;
|
|
|
|
PFNGLLOADPROGRAMNVPROC qglLoadProgramNV = NULL;
|
|
|
|
PFNGLPROGRAMPARAMETER4DNVPROC qglProgramParameter4dNV = NULL;
|
|
|
|
PFNGLPROGRAMPARAMETER4DVNVPROC qglProgramParameter4dvNV = NULL;
|
|
|
|
PFNGLPROGRAMPARAMETER4FNVPROC qglProgramParameter4fNV = NULL;
|
|
|
|
PFNGLPROGRAMPARAMETER4FVNVPROC qglProgramParameter4fvNV = NULL;
|
|
|
|
PFNGLPROGRAMPARAMETERS4DVNVPROC qglProgramParameters4dvNV = NULL;
|
|
|
|
PFNGLPROGRAMPARAMETERS4FVNVPROC qglProgramParameters4fvNV = NULL;
|
|
|
|
PFNGLREQUESTRESIDENTPROGRAMSNVPROC qglRequestResidentProgramsNV = NULL;
|
|
|
|
PFNGLTRACKMATRIXNVPROC qglTrackMatrixNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBPOINTERNVPROC qglVertexAttribPointerNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB1DNVPROC qglVertexAttrib1dNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB1DVNVPROC qglVertexAttrib1dvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB1FNVPROC qglVertexAttrib1fNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB1FVNVPROC qglVertexAttrib1fvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB1SNVPROC qglVertexAttrib1sNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB1SVNVPROC qglVertexAttrib1svNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB2DNVPROC qglVertexAttrib2dNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB2DVNVPROC qglVertexAttrib2dvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB2FNVPROC qglVertexAttrib2fNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB2FVNVPROC qglVertexAttrib2fvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB2SNVPROC qglVertexAttrib2sNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB2SVNVPROC qglVertexAttrib2svNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB3DNVPROC qglVertexAttrib3dNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB3DVNVPROC qglVertexAttrib3dvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB3FNVPROC qglVertexAttrib3fNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB3FVNVPROC qglVertexAttrib3fvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB3SNVPROC qglVertexAttrib3sNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB3SVNVPROC qglVertexAttrib3svNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4DNVPROC qglVertexAttrib4dNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4DVNVPROC qglVertexAttrib4dvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4FNVPROC qglVertexAttrib4fNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4FVNVPROC qglVertexAttrib4fvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4SNVPROC qglVertexAttrib4sNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4SVNVPROC qglVertexAttrib4svNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIB4UBVNVPROC qglVertexAttrib4ubvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBS1DVNVPROC qglVertexAttribs1dvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBS1FVNVPROC qglVertexAttribs1fvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBS1SVNVPROC qglVertexAttribs1svNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBS2DVNVPROC qglVertexAttribs2dvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBS2FVNVPROC qglVertexAttribs2fvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBS2SVNVPROC qglVertexAttribs2svNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBS3DVNVPROC qglVertexAttribs3dvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBS3FVNVPROC qglVertexAttribs3fvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBS3SVNVPROC qglVertexAttribs3svNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBS4DVNVPROC qglVertexAttribs4dvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBS4FVNVPROC qglVertexAttribs4fvNV = NULL;
|
|
|
|
PFNGLVERTEXATTRIBS4SVNVPROC qglVertexAttribs4svNV = NULL;
|
2003-05-04 21:47:08 +00:00
|
|
|
PFNGLVERTEXATTRIBS4UBVNVPROC qglVertexAttribs4ubvNV = NULL;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
// <AWE> There are some diffs with the function parameters. wgl stuff not present with MacOS X. -DC- and SDL
|
|
|
|
#if defined (__APPLE__) || defined (MACOSX) || defined (SDL) || defined (__glx__)
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
PFNGLFLUSHVERTEXARRAYRANGEAPPLEPROC qglFlushVertexArrayRangeAPPLE = NULL;
|
|
|
|
PFNGLVERTEXARRAYRANGEAPPLEPROC qglVertexArrayRangeAPPLE = NULL;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
#else
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
PFNGLFLUSHVERTEXARRAYRANGENVPROC qglFlushVertexArrayRangeNV = NULL;
|
|
|
|
PFNGLVERTEXARRAYRANGENVPROC glVertexArrayRangeNV = NULL;
|
|
|
|
PFNWGLALLOCATEMEMORYNVPROC wglAllocateMemoryNV = NULL;
|
|
|
|
PFNWGLFREEMEMORYNVPROC wglFreeMemoryNV = NULL;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
#endif /* __APPLE__ || MACOSX */
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
qboolean mtexenabled = false;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
void GL_SelectTexture (GLenum target);
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
void GL_DisableMultitexture(void)
|
|
|
|
{
|
|
|
|
if (mtexenabled) {
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
mtexenabled = false;
|
2003-01-17 21:18:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
void GL_EnableMultitexture(void)
|
2003-01-17 21:18:53 +00:00
|
|
|
{
|
2003-05-04 21:47:08 +00:00
|
|
|
if (gl_mtexable) {
|
|
|
|
GL_SelectTexture(GL_TEXTURE1_ARB);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
mtexenabled = true;
|
2003-01-17 21:18:53 +00:00
|
|
|
}
|
2003-05-04 21:47:08 +00:00
|
|
|
}
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
void R_RenderBrushPolyCaustics (msurface_t *fa)
|
|
|
|
{ int i;
|
|
|
|
float *v;
|
|
|
|
glpoly_t *p;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
glBegin (GL_TRIANGLE_FAN);
|
|
|
|
p = fa->polys;
|
|
|
|
//v = p->verts[0];
|
|
|
|
v = (float *)(&globalVertexTable[p->firstvertex]);
|
|
|
|
for (i=0 ; i<p->numverts ; i++, v+= VERTEXSIZE)
|
|
|
|
{
|
|
|
|
glTexCoord2f (v[5], v[6]);
|
|
|
|
glVertex3fv (v);
|
2003-01-17 21:18:53 +00:00
|
|
|
}
|
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
glEnd ();
|
2003-01-17 21:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
DrawTextureChains
|
|
|
|
PENTA: Modifications
|
|
|
|
|
|
|
|
We fill the causistics chain here!
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void DrawTextureChains (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
msurface_t *s;
|
2003-02-15 17:59:35 +00:00
|
|
|
mapshader_t *sh;
|
|
|
|
shader_t *shani;
|
2003-01-17 21:18:53 +00:00
|
|
|
qboolean found = false;
|
2003-02-15 17:59:35 +00:00
|
|
|
mesh_t *mesh;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
//glBlendFunc(GL_ZERO,GL_SRC_COLOR);
|
|
|
|
//glEnable(GL_BLEND);
|
|
|
|
glDepthMask (1);
|
|
|
|
GL_DisableMultitexture();
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
glColor3f(sh_lightmapbright.value,sh_lightmapbright.value,sh_lightmapbright.value);
|
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
/* GL_EnableMultitexture();
|
2003-01-17 21:18:53 +00:00
|
|
|
if (sh_colormaps.value) {
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
} else {
|
|
|
|
//No colormaps: Color maps are bound on tmu 0 so disable it
|
|
|
|
//and let tu1 modulate itself with the light map brightness
|
|
|
|
glDisable(GL_REGISTER_COMBINERS_NV);
|
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
GL_SelectTexture(GL_TEXTURE1_ARB);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PRIMARY_COLOR_ARB);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
|
|
|
}
|
2003-02-15 17:59:35 +00:00
|
|
|
*/
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (gl_wireframe.value) {
|
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
GL_SelectTexture(GL_TEXTURE1_ARB);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
|
|
|
|
causticschain = NULL; //clear chain here
|
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
//R_EnableVertexTable(VERTEX_TEXTURE | VERTEX_LIGHTMAP);
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
for (i=0 ; i<cl.worldmodel->nummapshaders ; i++)
|
2003-01-17 21:18:53 +00:00
|
|
|
{
|
2003-02-15 17:59:35 +00:00
|
|
|
sh = &cl.worldmodel->mapshaders[i];
|
|
|
|
if (!sh)
|
2003-01-17 21:18:53 +00:00
|
|
|
continue;
|
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
s = sh->texturechain;
|
2003-01-17 21:18:53 +00:00
|
|
|
if (!s)
|
|
|
|
continue;
|
2003-03-15 19:37:33 +00:00
|
|
|
if (!IsShaderBlended(sh->shader) || gl_wireframe.value) {
|
2003-02-15 17:59:35 +00:00
|
|
|
R_DrawWorldAmbientChain(sh->texturechain);
|
|
|
|
sh->texturechain = NULL;
|
|
|
|
}
|
|
|
|
}
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
|
|
|
|
for (i=0 ; i<cl.worldmodel->nummapshaders ; i++)
|
|
|
|
{
|
|
|
|
sh = &cl.worldmodel->mapshaders[i];
|
|
|
|
mesh = sh->meshchain;
|
|
|
|
|
|
|
|
if (!mesh)
|
|
|
|
continue;
|
|
|
|
|
2003-03-15 19:37:33 +00:00
|
|
|
if (!IsShaderBlended(mesh->shader->shader) || gl_wireframe.value) {
|
2003-02-15 17:59:35 +00:00
|
|
|
while (mesh) {
|
|
|
|
R_DrawMeshAmbient(mesh);
|
|
|
|
mesh = mesh->next;
|
|
|
|
}
|
|
|
|
sh->meshchain = NULL;
|
|
|
|
}
|
2003-01-17 21:18:53 +00:00
|
|
|
}
|
2003-02-15 17:59:35 +00:00
|
|
|
|
2003-03-02 20:23:52 +00:00
|
|
|
if (gl_wireframe.value) {
|
|
|
|
for (i=0 ; i<cl.worldmodel->nummapshaders ; i++)
|
|
|
|
{
|
|
|
|
cl.worldmodel->mapshaders[i].meshchain = NULL;
|
|
|
|
cl.worldmodel->mapshaders[i].texturechain = NULL;
|
|
|
|
}
|
2003-03-15 19:37:33 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
2003-03-02 20:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
//R_DisableVertexTable(VERTEX_TEXTURE | VERTEX_LIGHTMAP);
|
2003-01-17 21:18:53 +00:00
|
|
|
GL_SelectTexture(GL_TEXTURE1_ARB);
|
|
|
|
GL_DisableMultitexture();
|
|
|
|
//glDisable(GL_BLEND);
|
|
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glDepthMask (1);
|
2003-02-15 17:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrawBlendedTextureChains (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
msurface_t *s;
|
|
|
|
mapshader_t *sh;
|
|
|
|
shader_t *shani;
|
|
|
|
qboolean found = false;
|
|
|
|
mesh_t *mesh;
|
|
|
|
|
|
|
|
glDepthMask (1);
|
|
|
|
//GL_DisableMultitexture();
|
|
|
|
/*glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
glColor3f(sh_lightmapbright.value,sh_lightmapbright.value,sh_lightmapbright.value);
|
|
|
|
|
|
|
|
if (gl_wireframe.value) {
|
|
|
|
GL_SelectTexture(GL_TEXTURE0_ARB);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
GL_SelectTexture(GL_TEXTURE1_ARB);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
causticschain = NULL; //clear chain here
|
|
|
|
|
|
|
|
//R_EnableVertexTable(VERTEX_TEXTURE | VERTEX_LIGHTMAP);
|
|
|
|
|
|
|
|
for (i=0 ; i<cl.worldmodel->nummapshaders ; i++)
|
|
|
|
{
|
|
|
|
sh = &cl.worldmodel->mapshaders[i];
|
|
|
|
if (!sh)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
s = sh->texturechain;
|
|
|
|
if (!s)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (IsShaderBlended(sh->shader)) {
|
|
|
|
R_DrawWorldAmbientChain(sh->texturechain);
|
|
|
|
sh->texturechain = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0 ; i<cl.worldmodel->nummapshaders ; i++)
|
|
|
|
{
|
|
|
|
sh = &cl.worldmodel->mapshaders[i];
|
|
|
|
mesh = sh->meshchain;
|
|
|
|
|
|
|
|
if (!mesh)
|
|
|
|
continue;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
if (IsShaderBlended(mesh->shader->shader)) {
|
|
|
|
while (mesh) {
|
|
|
|
R_DrawMeshAmbient(mesh);
|
|
|
|
mesh = mesh->next;
|
|
|
|
}
|
|
|
|
sh->meshchain = NULL;
|
|
|
|
}
|
2003-01-17 21:18:53 +00:00
|
|
|
}
|
2003-02-15 17:59:35 +00:00
|
|
|
//R_DisableVertexTable(VERTEX_TEXTURE | VERTEX_LIGHTMAP);
|
|
|
|
//GL_SelectTexture(GL_TEXTURE1_ARB);
|
|
|
|
//GL_DisableMultitexture();
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glDepthMask (1);
|
2003-01-17 21:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void R_DrawBrushModelCaustics (entity_t *e);
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_DrawCaustics
|
|
|
|
|
|
|
|
Tenebrae does "real cauistics", projected textures on all things including ents
|
|
|
|
(Other mods seem to just add an extra, not properly projected layer to the polygons in the world.)
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void R_DrawCaustics(void) {
|
|
|
|
|
|
|
|
msurface_t *s;
|
|
|
|
int i;
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
|
|
|
|
GLfloat sPlane[4] = {0.01, 0.005, 0.0, 0.0 };
|
|
|
|
GLfloat tPlane[4] = {0.0, 0.01, 0.005, 0.0 };
|
|
|
|
|
|
|
|
if (!gl_caustics.value) return;
|
|
|
|
|
|
|
|
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
|
|
|
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
|
|
|
glTexGenfv(GL_S, GL_OBJECT_PLANE, sPlane);
|
|
|
|
glTexGenfv(GL_T, GL_OBJECT_PLANE, tPlane);
|
|
|
|
glEnable(GL_TEXTURE_GEN_S);
|
|
|
|
glEnable(GL_TEXTURE_GEN_T);
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_DST_COLOR, GL_ONE);
|
|
|
|
|
|
|
|
GL_Bind(caustics_textures[(int)(cl.time*16)&7]);
|
|
|
|
busy_caustics = true;
|
|
|
|
s = causticschain;
|
|
|
|
|
|
|
|
R_EnableVertexTable(0);
|
|
|
|
while (s) {
|
|
|
|
//R_RenderBrushPolyCaustics (s);
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN,s->polys->firstvertex,s->polys->numverts);
|
|
|
|
s = s->texturechain;
|
|
|
|
}
|
|
|
|
R_DisableVertexTable(0);
|
|
|
|
|
|
|
|
for (i=0 ; i<cl_numvisedicts ; i++)
|
|
|
|
{
|
|
|
|
currententity = cl_visedicts[i];
|
|
|
|
|
|
|
|
if (currententity->angles[0] || currententity->angles[1] || currententity->angles[2])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0 ; i<3 ; i++)
|
|
|
|
{
|
|
|
|
mins[i] = currententity->origin[i] - currententity->model->radius;
|
|
|
|
maxs[i] = currententity->origin[i] + currententity->model->radius;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VectorAdd (currententity->origin,currententity->model->mins, mins);
|
|
|
|
VectorAdd (currententity->origin,currententity->model->maxs, maxs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (R_CullBox (mins, maxs))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//quick hack! check if ent is below water
|
2003-02-03 14:01:02 +00:00
|
|
|
if ((!(CL_PointContents(mins) & CONTENTS_WATER)) && (!(CL_PointContents(maxs) & CONTENTS_WATER)))
|
2003-01-17 21:18:53 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mirror) {
|
|
|
|
if (mirror_clipside == BoxOnPlaneSide(mins, maxs, mirror_plane)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( BoxOnPlaneSide(mins, maxs, &mirror_far_plane) == 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (currententity->model->type)
|
|
|
|
{
|
|
|
|
case mod_alias:
|
|
|
|
R_DrawAliasModel (1.0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case mod_brush:
|
|
|
|
R_DrawBrushModelCaustics(currententity);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
busy_caustics = false;
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
|
|
glDisable(GL_TEXTURE_GEN_S);
|
|
|
|
glDisable(GL_TEXTURE_GEN_T);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
R_DrawBrushModel
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void R_DrawBrushModelCaustics (entity_t *e)
|
|
|
|
{
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
int i;
|
|
|
|
msurface_t *psurf;
|
|
|
|
float dot;
|
|
|
|
mplane_t *pplane;
|
|
|
|
model_t *clmodel;
|
|
|
|
qboolean rotated;
|
|
|
|
|
|
|
|
//bright = 1;
|
|
|
|
|
|
|
|
currententity = e;
|
|
|
|
currenttexture = -1;
|
|
|
|
|
|
|
|
clmodel = e->model;
|
|
|
|
|
|
|
|
if (e->angles[0] || e->angles[1] || e->angles[2])
|
|
|
|
{
|
|
|
|
rotated = true;
|
|
|
|
for (i=0 ; i<3 ; i++)
|
|
|
|
{
|
|
|
|
mins[i] = e->origin[i] - clmodel->radius;
|
|
|
|
maxs[i] = e->origin[i] + clmodel->radius;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rotated = false;
|
|
|
|
VectorAdd (e->origin, clmodel->mins, mins);
|
|
|
|
VectorAdd (e->origin, clmodel->maxs, maxs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (R_CullBox (mins, maxs))
|
|
|
|
return;
|
|
|
|
|
|
|
|
VectorSubtract (r_refdef.vieworg, e->origin, modelorg);
|
|
|
|
if (rotated)
|
|
|
|
{
|
|
|
|
vec3_t temp;
|
|
|
|
vec3_t forward, right, up;
|
|
|
|
|
|
|
|
VectorCopy (modelorg, temp);
|
|
|
|
AngleVectors (e->angles, forward, right, up);
|
|
|
|
modelorg[0] = DotProduct (temp, forward);
|
|
|
|
modelorg[1] = -DotProduct (temp, right);
|
|
|
|
modelorg[2] = DotProduct (temp, up);
|
|
|
|
}
|
|
|
|
|
|
|
|
psurf = &clmodel->surfaces[clmodel->firstmodelsurface];
|
|
|
|
|
|
|
|
glPushMatrix ();
|
|
|
|
e->angles[0] = -e->angles[0]; // stupid quake bug
|
|
|
|
R_RotateForEntity (e);
|
|
|
|
e->angles[0] = -e->angles[0]; // stupid quake bug
|
|
|
|
|
|
|
|
//Draw model with specified ambient color
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// draw texture
|
|
|
|
//
|
|
|
|
for (i=0 ; i<clmodel->nummodelsurfaces ; i++, psurf++)
|
|
|
|
{
|
|
|
|
// find which side of the node we are on
|
|
|
|
pplane = psurf->plane;
|
|
|
|
|
|
|
|
dot = DotProduct (modelorg, pplane->normal) - pplane->dist;
|
|
|
|
|
|
|
|
// draw the polygon
|
|
|
|
if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
|
|
|
|
(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON)))
|
|
|
|
{
|
|
|
|
R_RenderBrushPolyCaustics (psurf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//R_BlendLightmaps (); nope no lightmaps
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
glPopMatrix ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
R_DrawBrushModel
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void R_DrawBrushModelAmbient (entity_t *e)
|
|
|
|
{
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
int i;
|
|
|
|
msurface_t *psurf;
|
|
|
|
float dot;
|
|
|
|
mplane_t *pplane;
|
|
|
|
model_t *clmodel;
|
|
|
|
qboolean rotated;
|
|
|
|
|
|
|
|
//bright = 1;
|
|
|
|
|
|
|
|
currententity = e;
|
|
|
|
currenttexture = -1;
|
|
|
|
|
|
|
|
clmodel = e->model;
|
|
|
|
|
|
|
|
if (e->angles[0] || e->angles[1] || e->angles[2])
|
|
|
|
{
|
|
|
|
rotated = true;
|
|
|
|
for (i=0 ; i<3 ; i++)
|
|
|
|
{
|
|
|
|
mins[i] = e->origin[i] - clmodel->radius;
|
|
|
|
maxs[i] = e->origin[i] + clmodel->radius;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rotated = false;
|
|
|
|
VectorAdd (e->origin, clmodel->mins, mins);
|
|
|
|
VectorAdd (e->origin, clmodel->maxs, maxs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (R_CullBox (mins, maxs))
|
|
|
|
return;
|
|
|
|
|
|
|
|
VectorSubtract (r_refdef.vieworg, e->origin, modelorg);
|
|
|
|
if (rotated)
|
|
|
|
{
|
|
|
|
vec3_t temp;
|
|
|
|
vec3_t forward, right, up;
|
|
|
|
|
|
|
|
VectorCopy (modelorg, temp);
|
|
|
|
AngleVectors (e->angles, forward, right, up);
|
|
|
|
modelorg[0] = DotProduct (temp, forward);
|
|
|
|
modelorg[1] = -DotProduct (temp, right);
|
|
|
|
modelorg[2] = DotProduct (temp, up);
|
|
|
|
}
|
|
|
|
|
|
|
|
psurf = &clmodel->surfaces[clmodel->firstmodelsurface];
|
|
|
|
|
|
|
|
glPushMatrix ();
|
|
|
|
e->angles[0] = -e->angles[0]; // stupid quake bug
|
|
|
|
R_RotateForEntity (e);
|
|
|
|
e->angles[0] = -e->angles[0]; // stupid quake bug
|
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
R_DrawBrushAmbient(e);
|
|
|
|
|
|
|
|
/* //Draw model with specified ambient color
|
2003-01-17 21:18:53 +00:00
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// draw texture
|
|
|
|
//
|
|
|
|
for (i=0 ; i<clmodel->nummodelsurfaces ; i++, psurf++)
|
|
|
|
{
|
|
|
|
// find which side of the node we are on
|
|
|
|
pplane = psurf->plane;
|
|
|
|
|
|
|
|
dot = DotProduct (modelorg, pplane->normal) - pplane->dist;
|
|
|
|
|
|
|
|
// draw the polygon
|
|
|
|
if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
|
|
|
|
(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON)))
|
|
|
|
{
|
|
|
|
R_RenderBrushPolyLightmap (psurf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//R_BlendLightmaps (); nope no lightmaps
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
2003-02-15 17:59:35 +00:00
|
|
|
*/
|
2003-01-17 21:18:53 +00:00
|
|
|
glPopMatrix ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================
|
|
|
|
|
|
|
|
WORLD MODEL
|
|
|
|
|
|
|
|
=============================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
R_RecursiveWorldNode
|
|
|
|
|
|
|
|
PENTA: Modifications
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
qboolean didnode;
|
2003-05-04 21:47:08 +00:00
|
|
|
aabox_t worldbox;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
void R_RecursiveWorldNode (mnode_t *node)
|
|
|
|
{
|
|
|
|
int c, side, i;
|
|
|
|
mplane_t *plane;
|
|
|
|
msurface_t *surf, **mark;
|
|
|
|
mleaf_t *pleaf;
|
2003-02-15 17:59:35 +00:00
|
|
|
mesh_t *mesh;
|
2003-01-17 21:18:53 +00:00
|
|
|
double dot;
|
2003-05-04 21:47:08 +00:00
|
|
|
aabox_t leafbox;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
if (node->contents == CONTENTS_SOLID)
|
|
|
|
return; // solid
|
|
|
|
|
|
|
|
if (node->visframe != r_visframecount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (R_CullBox (node->minmaxs, node->minmaxs+3))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mirror) {
|
|
|
|
|
|
|
|
int side = BoxOnPlaneSide(node->minmaxs, node->minmaxs+3, mirror_plane);
|
|
|
|
if ((mirror_clipside == side)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( BoxOnPlaneSide(node->minmaxs, node->minmaxs+3, &mirror_far_plane) == 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if a leaf node, draw stuff
|
2003-02-03 14:01:02 +00:00
|
|
|
if (node->contents & CONTENTS_LEAF)
|
2003-01-17 21:18:53 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (mirror) {
|
|
|
|
if (mirror_clipside == BoxOnPlaneSide(node->minmaxs, node->minmaxs+3, mirror_plane)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
pleaf = (mleaf_t *)node;
|
2003-05-04 21:47:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
leafbox = constructBox(pleaf->minmaxs,pleaf->minmaxs+3);
|
|
|
|
worldbox = addBoxes(&worldbox,&leafbox);
|
|
|
|
|
2003-01-17 21:18:53 +00:00
|
|
|
mark = pleaf->firstmarksurface;
|
|
|
|
c = pleaf->nummarksurfaces;
|
|
|
|
|
|
|
|
if (c)
|
|
|
|
{
|
|
|
|
//Con_Printf("Leaf with %i surfaces\n",c);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
if ((*mark)->flags & SURF_MIRROR) {
|
|
|
|
if (!mirror)
|
|
|
|
R_AllocateMirror((*mark));
|
|
|
|
mark++;
|
|
|
|
continue;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
if ((*mark)->flags & SURF_MIRROR) {
|
|
|
|
|
|
|
|
//PENTA the SURF_UNDERWATER check is needed so that we dont draw glass
|
|
|
|
//twice since we design it as a water block we would render two poly's with the
|
|
|
|
//mirror otherwice
|
|
|
|
if( (! (((*mark)->flags & SURF_UNDERWATER) && ((*mark)->flags & SURF_GLASS)) )|| (!((*mark)->flags & SURF_DRAWTURB)))
|
|
|
|
|
|
|
|
if (!mirror) R_AllocateMirror((*mark));
|
|
|
|
//destroy visframe
|
|
|
|
(*mark)->visframe = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if ((*mark)->visframe == r_framecount) {
|
|
|
|
mark++;
|
|
|
|
continue;
|
|
|
|
}
|
2003-02-15 17:59:35 +00:00
|
|
|
/*
|
2003-01-17 21:18:53 +00:00
|
|
|
if (((*mark)->flags & SURF_DRAWTURB) && ((*mark)->flags & SURF_MIRROR)) {
|
|
|
|
mark++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((*mark)->flags & SURF_DRAWTURB) && (mirror)) {
|
|
|
|
mark++;
|
|
|
|
continue;
|
|
|
|
}
|
2003-02-15 17:59:35 +00:00
|
|
|
*/
|
|
|
|
(*mark)->texturechain = (*mark)->shader->texturechain;
|
|
|
|
(*mark)->shader->texturechain = (*mark);
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
if (!((*mark)->flags & (SURF_DRAWSKY | SURF_DRAWTURB))) {
|
|
|
|
(*mark)->polys->chain = lightmap_polys[(*mark)->lightmaptexturenum];
|
|
|
|
lightmap_polys[(*mark)->lightmaptexturenum] = (*mark)->polys;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
(*mark)->visframe = r_framecount;
|
|
|
|
mark++;
|
|
|
|
} while (--c);
|
|
|
|
}
|
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
c = pleaf->firstmesh;
|
2003-01-17 21:18:53 +00:00
|
|
|
//if (pleaf->numcurves) Con_Printf("Numcurves %i\n",pleaf->numcurves);
|
2003-02-15 17:59:35 +00:00
|
|
|
for (i=0; i<pleaf->nummeshes; i++) {
|
|
|
|
mesh = &cl.worldmodel->meshes[cl.worldmodel->leafmeshes[c+i]];
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
if (mesh->visframe == r_framecount) continue;
|
|
|
|
mesh->visframe = r_framecount;
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-06-25 09:41:54 +00:00
|
|
|
if (R_CullBox(mesh->mins, mesh->maxs)) continue;
|
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
mesh->next = mesh->shader->meshchain;
|
|
|
|
mesh->shader->meshchain = mesh;
|
2003-01-17 21:18:53 +00:00
|
|
|
//Con_Printf("AddCurve\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// deal with model fragments in this leaf
|
|
|
|
// steek de statishe moddellen voor dit leafy in de lijst
|
|
|
|
// waarom zo ingewikkeld doen via efrags is nog niet helemaal duidelijk
|
|
|
|
if (pleaf->efrags)
|
|
|
|
R_StoreEfrags (&pleaf->efrags);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// node is just a decision point, so go down the apropriate sides
|
|
|
|
|
|
|
|
// find which side of the node we are on
|
|
|
|
plane = node->plane;
|
|
|
|
|
|
|
|
switch (plane->type)
|
|
|
|
{
|
|
|
|
case PLANE_X:
|
|
|
|
dot = modelorg[0] - plane->dist;
|
|
|
|
break;
|
|
|
|
case PLANE_Y:
|
|
|
|
dot = modelorg[1] - plane->dist;
|
|
|
|
break;
|
|
|
|
case PLANE_Z:
|
|
|
|
dot = modelorg[2] - plane->dist;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dot = DotProduct (modelorg, plane->normal) - plane->dist;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dot >= 0)
|
|
|
|
side = 0;
|
|
|
|
else
|
|
|
|
side = 1;
|
|
|
|
|
|
|
|
// recurse down the children, front side first
|
|
|
|
R_RecursiveWorldNode (node->children[side]);
|
2003-02-15 17:59:35 +00:00
|
|
|
R_RecursiveWorldNode (node->children[!side]);
|
2003-01-17 21:18:53 +00:00
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
/*
|
2003-01-17 21:18:53 +00:00
|
|
|
// draw stuff
|
|
|
|
c = node->numsurfaces;
|
|
|
|
|
|
|
|
if (c)
|
|
|
|
{
|
|
|
|
surf = cl.worldmodel->surfaces + node->firstsurface;
|
|
|
|
|
|
|
|
if (dot < 0 -BACKFACE_EPSILON)
|
|
|
|
side = SURF_PLANEBACK;
|
|
|
|
else if (dot > BACKFACE_EPSILON)
|
|
|
|
side = 0;
|
|
|
|
{
|
|
|
|
if (c) Con_Printf("Node with %i surf\n",c);
|
|
|
|
|
|
|
|
for ( ; c ; c--, surf++)
|
|
|
|
{
|
|
|
|
if (surf->visframe != r_framecount)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// don't backface underwater surfaces, because they warp
|
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
if ( (dot < 0) ^ !!(surf->flags & SURF_PLANEBACK))
|
|
|
|
continue; // wrong side
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
if (surf->flags & SURF_MIRROR) {
|
|
|
|
|
|
|
|
//PENTA the SURF_UNDERWATER check is needed so that we dont draw glass
|
|
|
|
//twice since we design it as a water block we would render two poly's with the
|
|
|
|
//mirror otherwice
|
|
|
|
if( (! ((surf->flags & SURF_UNDERWATER) && (surf->flags & SURF_GLASS)) )|| (!(surf->flags & SURF_DRAWTURB)))
|
|
|
|
|
|
|
|
if (!mirror) R_AllocateMirror(surf);
|
|
|
|
//destroy visframe
|
|
|
|
surf->visframe = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((surf->flags & SURF_DRAWTURB) && (surf->flags & SURF_MIRROR)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((surf->flags & SURF_DRAWTURB) && (mirror)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if sorting by texture, just store it out
|
2003-02-15 17:59:35 +00:00
|
|
|
//if (gl_texsort.value)
|
|
|
|
//{
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
// add the surface to the proper texture chain
|
|
|
|
//if (!mirror
|
|
|
|
//|| surf->texinfo->texture != cl.worldmodel->textures[mirrortexturenum])
|
|
|
|
//{
|
2003-02-15 17:59:35 +00:00
|
|
|
surf->texturechain = surf->shader->texturechain;
|
|
|
|
surf->shader->texturechain = surf;
|
2003-01-17 21:18:53 +00:00
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
// add the poly to the proper lightmap chain
|
|
|
|
//steek hem in de lijst en vermenigvuldig de lightmaps er achteraf over via
|
|
|
|
//r_blendlightmaps
|
|
|
|
//we steken geen lucht/water polys in de lijst omdat deze geen
|
|
|
|
//lightmaps hebben
|
|
|
|
if (!(surf->flags & (SURF_DRAWSKY | SURF_DRAWTURB))) {
|
|
|
|
surf->polys->chain = lightmap_polys[surf->lightmaptexturenum];
|
|
|
|
lightmap_polys[surf->lightmaptexturenum] = surf->polys;
|
|
|
|
}
|
|
|
|
|
2003-02-15 17:59:35 +00:00
|
|
|
|
|
|
|
//} else if (surf->flags & SURF_DRAWSKY) {
|
|
|
|
// surf->texturechain = skychain;
|
|
|
|
// skychain = surf;
|
|
|
|
//} else if (surf->flags & SURF_DRAWTURB) {
|
|
|
|
// surf->texturechain = waterchain;
|
|
|
|
// waterchain = surf;
|
|
|
|
//} else
|
|
|
|
// R_DrawSequentialPoly (surf);
|
|
|
|
//
|
2003-01-17 21:18:53 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2003-02-15 17:59:35 +00:00
|
|
|
*/
|
2003-01-17 21:18:53 +00:00
|
|
|
// recurse down the back side
|
2003-02-15 17:59:35 +00:00
|
|
|
//R_RecursiveWorldNode (node->children[!side]);
|
2003-01-17 21:18:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_InitDrawWorld
|
|
|
|
|
|
|
|
Make sure everyting is set up correctly to draw
|
|
|
|
the world model.
|
|
|
|
|
|
|
|
PENTA: Modifications
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void R_InitDrawWorld (void)
|
|
|
|
{
|
|
|
|
entity_t ent;
|
|
|
|
|
|
|
|
memset (&ent, 0, sizeof(ent));
|
|
|
|
ent.model = cl.worldmodel;
|
|
|
|
|
|
|
|
VectorCopy (r_refdef.vieworg, modelorg);
|
|
|
|
|
|
|
|
currententity = &ent;
|
|
|
|
currenttexture = -1;
|
|
|
|
|
|
|
|
glColor3f (1,1,1);
|
|
|
|
memset (lightmap_polys, 0, sizeof(lightmap_polys));
|
|
|
|
//#ifdef QUAKE2
|
|
|
|
|
|
|
|
R_ClearSkyBox ();
|
|
|
|
//#endif
|
|
|
|
//if (mirror) Con_Printf("RWorldn\n");
|
|
|
|
//mark visible polygons/ents
|
2003-05-04 21:47:08 +00:00
|
|
|
worldbox = emptyBox();
|
2003-01-17 21:18:53 +00:00
|
|
|
R_RecursiveWorldNode (cl.worldmodel->nodes);
|
|
|
|
//#ifdef QUAKE2
|
|
|
|
|
|
|
|
if (gl_wireframe.value) return;
|
|
|
|
R_DrawSkyBox ();
|
|
|
|
//if (gl_fog.value) glEnable(GL_FOG);
|
|
|
|
//#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_WorldMultiplyTextures
|
|
|
|
|
|
|
|
Once we have drawn the lightmap in the depth buffer multiply the textures over it
|
|
|
|
PENTA: New
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void R_WorldMultiplyTextures(void) {
|
|
|
|
DrawTextureChains ();
|
|
|
|
//R_RenderDlights (); //render "fake" dynamic lights als die aan staan
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_MarkLeaves
|
|
|
|
|
|
|
|
|
|
|
|
Markeer visible leafs voor dit frame
|
|
|
|
aangeroepen vanuit render scene voor alle
|
|
|
|
ander render code
|
|
|
|
(hmm handig hiernaa kunnen we dus al van de vis voor de camera
|
|
|
|
gebruik maken en toch nog stuff doen)
|
|
|
|
|
|
|
|
PENTA: Modifications
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
2003-05-04 21:47:08 +00:00
|
|
|
|
2003-01-17 21:18:53 +00:00
|
|
|
void R_MarkLeaves (void)
|
|
|
|
{
|
|
|
|
byte *vis;
|
|
|
|
mnode_t *node;
|
|
|
|
mleaf_t *leaf;
|
|
|
|
int i;
|
|
|
|
byte solid[4096];
|
|
|
|
|
|
|
|
//zelfde leaf als vorige frame vermijd van vis opnieuw te calculaten
|
|
|
|
// if (r_oldviewleaf == r_viewleaf && !r_novis.value)
|
|
|
|
// return;
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
r_visframecount++;//begin nieuwe timestamp
|
|
|
|
r_oldviewleaf = r_viewleaf;
|
|
|
|
|
|
|
|
if (r_novis.value)
|
|
|
|
{
|
|
|
|
vis = solid;
|
|
|
|
memset (solid, 0xff, (cl.worldmodel->numleafs+7)>>3);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
vis = Mod_LeafPVS (r_viewleaf, cl.worldmodel);//vraag visible leafs vanuit dit leaf aan model
|
|
|
|
|
|
|
|
for (i=0 ; i<cl.worldmodel->numleafs ; i++)//overloop alle leafs
|
|
|
|
{
|
|
|
|
|
|
|
|
leaf = cl.worldmodel->leafs+i;
|
|
|
|
if (vis[leaf->cluster>>3] & (1<<(leaf->cluster&7))) // staat leaf i's vis bit op true ?
|
|
|
|
{
|
2003-02-03 14:01:02 +00:00
|
|
|
// check area portals
|
|
|
|
if (! (r_refdef.areabits[leaf->area>>3] & (1<<(leaf->area&7)) ) ) {
|
|
|
|
continue; // not visible
|
|
|
|
}
|
|
|
|
|
2003-01-17 21:18:53 +00:00
|
|
|
node = (mnode_t *)leaf;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (node->visframe == r_visframecount) //node al op true gezet dit frame, exit
|
|
|
|
break;
|
|
|
|
node->visframe = r_visframecount;//zet node zijn timestamp voor dit frame
|
|
|
|
node = node->parent;//mark parents as vis
|
|
|
|
} while (node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================================
|
|
|
|
|
|
|
|
LIGHTMAP ALLOCATION
|
|
|
|
|
|
|
|
=============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LIGHTMAP_WIDTH 128
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
GL_BuildLightmaps
|
|
|
|
|
|
|
|
Lightmaps are much easyer with q3, we just upload all the lightmaps here,
|
|
|
|
and he surface then binds the correct lightmap...
|
|
|
|
Of course we can't have dynamic lights with this but we don't need those anyway...
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
void GL_BuildLightmaps (void)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
model_t *m;
|
|
|
|
|
|
|
|
r_framecount = 1; // no dlightcache
|
|
|
|
|
|
|
|
if (!lightmap_textures)
|
|
|
|
{
|
|
|
|
lightmap_textures = texture_extension_number;
|
|
|
|
texture_extension_number += MAX_LIGHTMAPS;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_lightmap_format = GL_RGB;
|
|
|
|
lightmap_bytes = 4;
|
|
|
|
|
|
|
|
for (i=0 ; i<cl.worldmodel->numlightmaps ; i++)
|
|
|
|
{
|
2003-03-02 20:23:52 +00:00
|
|
|
|
2003-05-04 21:47:08 +00:00
|
|
|
//Con_Printf("Lightmap %i (texnum: %i)\n",i,lightmap_textures + i);
|
2003-01-17 21:18:53 +00:00
|
|
|
GL_Bind(lightmap_textures + i);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexImage2D (GL_TEXTURE_2D, 0, 3
|
|
|
|
, LIGHTMAP_WIDTH, LIGHTMAP_WIDTH, 0,
|
|
|
|
gl_lightmap_format, GL_UNSIGNED_BYTE,
|
|
|
|
cl.worldmodel->lightdata+(i*LIGHTMAP_WIDTH*LIGHTMAP_WIDTH*3));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|