2004-08-22 22:29:09 +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
|
2011-06-01 13:21:54 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2004-08-22 22:29:09 +00:00
|
|
|
|
|
|
|
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"
|
2009-11-07 13:29:15 +00:00
|
|
|
#if defined(GLQUAKE)
|
2004-08-22 22:29:09 +00:00
|
|
|
#include "glquake.h"
|
|
|
|
#include "shader.h"
|
|
|
|
#include "renderque.h"
|
|
|
|
#include <math.h>
|
|
|
|
|
2018-03-04 14:41:16 +00:00
|
|
|
extern cvar_t r_lightmap_nearest;
|
2014-04-02 00:58:02 +00:00
|
|
|
|
2017-11-30 17:59:11 +00:00
|
|
|
void GLBE_ClearVBO(vbo_t *vbo, qboolean dataonly)
|
2009-07-05 18:45:53 +00:00
|
|
|
{
|
2013-10-08 14:28:11 +00:00
|
|
|
int vboh[6 + MAXRLIGHTMAPS];
|
2009-07-05 18:45:53 +00:00
|
|
|
int i, j;
|
2011-12-23 03:12:29 +00:00
|
|
|
vboh[0] = vbo->indicies.gl.vbo;
|
|
|
|
vboh[1] = vbo->coord.gl.vbo;
|
|
|
|
vboh[2] = vbo->texcoord.gl.vbo;
|
2012-07-05 19:42:36 +00:00
|
|
|
vboh[3] = vbo->normals.gl.vbo;
|
|
|
|
vboh[4] = vbo->svector.gl.vbo;
|
|
|
|
vboh[5] = vbo->tvector.gl.vbo;
|
2013-10-08 14:28:11 +00:00
|
|
|
for (i = 0; i < MAXRLIGHTMAPS; i++)
|
2012-07-05 19:42:36 +00:00
|
|
|
vboh[6+i] = vbo->lmcoord[i].gl.vbo;
|
2009-07-05 18:45:53 +00:00
|
|
|
|
2017-11-30 17:59:11 +00:00
|
|
|
memset (&vbo->indicies, 0, sizeof(vbo->indicies));
|
|
|
|
memset (&vbo->coord, 0, sizeof(vbo->coord));
|
|
|
|
memset (&vbo->texcoord, 0, sizeof(vbo->texcoord));
|
|
|
|
memset (&vbo->normals, 0, sizeof(vbo->normals));
|
|
|
|
memset (&vbo->svector, 0, sizeof(vbo->svector));
|
|
|
|
memset (&vbo->tvector, 0, sizeof(vbo->tvector));
|
|
|
|
memset (&vbo->lmcoord, 0, sizeof(vbo->lmcoord));
|
|
|
|
|
2009-07-05 18:45:53 +00:00
|
|
|
for (i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
if (!vboh[i])
|
|
|
|
continue;
|
|
|
|
for (j = 0; j < 7; j++)
|
|
|
|
{
|
|
|
|
if (vboh[j] == vboh[i])
|
|
|
|
break; //already freed by one of the other ones
|
|
|
|
}
|
|
|
|
if (j == 7)
|
|
|
|
qglDeleteBuffersARB(1, &vboh[i]);
|
|
|
|
}
|
2011-02-25 04:22:14 +00:00
|
|
|
if (vbo->vertdata)
|
|
|
|
BZ_Free(vbo->vertdata);
|
2017-11-30 17:59:11 +00:00
|
|
|
vbo->vertdata = NULL;
|
2010-07-12 22:46:37 +00:00
|
|
|
BZ_Free(vbo->meshlist);
|
2017-11-30 17:59:11 +00:00
|
|
|
vbo->meshlist = NULL;
|
|
|
|
if (!dataonly)
|
|
|
|
BZ_Free(vbo);
|
2009-07-05 18:45:53 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 04:28:08 +00:00
|
|
|
void GLBE_SetupVAO(vbo_t *vbo, unsigned int vaodynamic, unsigned int vaostatic);
|
2012-04-24 07:59:11 +00:00
|
|
|
|
|
|
|
static qboolean GL_BuildVBO(vbo_t *vbo, void *vdata, int vsize, void *edata, int elementsize, unsigned int vaodynamic)
|
2009-07-05 18:45:53 +00:00
|
|
|
{
|
|
|
|
unsigned int vbos[2];
|
2012-07-05 19:42:36 +00:00
|
|
|
int s;
|
2013-05-03 04:28:08 +00:00
|
|
|
unsigned int vaostatic = 0;
|
2009-07-05 18:45:53 +00:00
|
|
|
|
2019-10-26 09:37:52 +00:00
|
|
|
if (!qglGenBuffersARB || !vsize || !elementsize)
|
2009-07-05 18:45:53 +00:00
|
|
|
return false;
|
|
|
|
|
2011-04-30 17:21:10 +00:00
|
|
|
qglGenBuffersARB(1+(elementsize>0), vbos);
|
2009-07-05 18:45:53 +00:00
|
|
|
|
|
|
|
//opengl ate our data, fixup the vbo arrays to point to the vbo instead of the raw data
|
|
|
|
|
2011-12-23 03:12:29 +00:00
|
|
|
if (vbo->indicies.gl.addr && elementsize)
|
2009-07-05 18:45:53 +00:00
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
vbo->indicies.gl.vbo = vbos[1];
|
|
|
|
vbo->indicies.gl.addr = (index_t*)((char*)vbo->indicies.gl.addr - (char*)edata);
|
2014-11-05 05:39:24 +00:00
|
|
|
vaostatic |= 1u<<VATTR_LEG_ELEMENTS;
|
2009-07-05 18:45:53 +00:00
|
|
|
}
|
2011-12-23 03:12:29 +00:00
|
|
|
if (vbo->coord.gl.addr)
|
2009-07-05 18:45:53 +00:00
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
vbo->coord.gl.vbo = vbos[0];
|
|
|
|
vbo->coord.gl.addr = (vecV_t*)((char*)vbo->coord.gl.addr - (char*)vdata);
|
2014-11-05 05:39:24 +00:00
|
|
|
vaostatic |= 1u<<VATTR_VERTEX1;
|
2009-07-05 18:45:53 +00:00
|
|
|
}
|
2011-12-23 03:12:29 +00:00
|
|
|
if (vbo->texcoord.gl.addr)
|
2009-07-05 18:45:53 +00:00
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
vbo->texcoord.gl.vbo = vbos[0];
|
|
|
|
vbo->texcoord.gl.addr = (vec2_t*)((char*)vbo->texcoord.gl.addr - (char*)vdata);
|
2014-11-05 05:39:24 +00:00
|
|
|
vaostatic |= 1u<<VATTR_TEXCOORD;
|
2009-07-05 18:45:53 +00:00
|
|
|
}
|
2013-10-08 14:28:11 +00:00
|
|
|
for (s = 0; s < MAXRLIGHTMAPS; s++)
|
2009-07-05 18:45:53 +00:00
|
|
|
{
|
2013-08-27 13:18:09 +00:00
|
|
|
if (vbo->colours[s].gl.addr)
|
|
|
|
{
|
|
|
|
vbo->colours[s].gl.vbo = vbos[0];
|
|
|
|
vbo->colours[s].gl.addr = (vec4_t*)((char*)vbo->colours[s].gl.addr - (char*)vdata);
|
|
|
|
switch(s)
|
|
|
|
{
|
2014-11-05 05:39:24 +00:00
|
|
|
default: vaostatic |= 1u<<VATTR_COLOUR; break;
|
2013-10-08 14:28:11 +00:00
|
|
|
#if MAXRLIGHTMAPS > 1
|
2014-11-05 05:39:24 +00:00
|
|
|
case 1: vaostatic |= 1u<<VATTR_COLOUR2; break;
|
|
|
|
case 2: vaostatic |= 1u<<VATTR_COLOUR3; break;
|
|
|
|
case 3: vaostatic |= 1u<<VATTR_COLOUR4; break;
|
2013-10-08 14:28:11 +00:00
|
|
|
#endif
|
2013-08-27 13:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
if (vbo->lmcoord[s].gl.addr)
|
|
|
|
{
|
|
|
|
vbo->lmcoord[s].gl.vbo = vbos[0];
|
|
|
|
vbo->lmcoord[s].gl.addr = (vec2_t*)((char*)vbo->lmcoord[s].gl.addr - (char*)vdata);
|
2013-05-03 04:28:08 +00:00
|
|
|
switch(s)
|
|
|
|
{
|
2014-11-05 05:39:24 +00:00
|
|
|
default: vaostatic |= 1u<<VATTR_LMCOORD; break;
|
2013-10-08 14:28:11 +00:00
|
|
|
#if MAXRLIGHTMAPS > 1
|
2014-11-05 05:39:24 +00:00
|
|
|
case 1: vaostatic |= 1u<<VATTR_LMCOORD2; break;
|
|
|
|
case 2: vaostatic |= 1u<<VATTR_LMCOORD3; break;
|
|
|
|
case 3: vaostatic |= 1u<<VATTR_LMCOORD4; break;
|
2013-10-08 14:28:11 +00:00
|
|
|
#endif
|
2013-05-03 04:28:08 +00:00
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
}
|
2009-07-05 18:45:53 +00:00
|
|
|
}
|
2011-12-23 03:12:29 +00:00
|
|
|
if (vbo->normals.gl.addr)
|
2009-07-05 18:45:53 +00:00
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
vbo->normals.gl.vbo = vbos[0];
|
|
|
|
vbo->normals.gl.addr = (vec3_t*)((char*)vbo->normals.gl.addr - (char*)vdata);
|
2014-11-05 05:39:24 +00:00
|
|
|
vaostatic |= 1u<<VATTR_NORMALS;
|
2009-07-05 18:45:53 +00:00
|
|
|
}
|
2011-12-23 03:12:29 +00:00
|
|
|
if (vbo->svector.gl.addr)
|
2009-07-05 18:45:53 +00:00
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
vbo->svector.gl.vbo = vbos[0];
|
|
|
|
vbo->svector.gl.addr = (vec3_t*)((char*)vbo->svector.gl.addr - (char*)vdata);
|
2014-11-05 05:39:24 +00:00
|
|
|
vaostatic |= 1u<<VATTR_SNORMALS;
|
2009-07-05 18:45:53 +00:00
|
|
|
}
|
2011-12-23 03:12:29 +00:00
|
|
|
if (vbo->tvector.gl.addr)
|
2009-07-05 18:45:53 +00:00
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
vbo->tvector.gl.vbo = vbos[0];
|
|
|
|
vbo->tvector.gl.addr = (vec3_t*)((char*)vbo->tvector.gl.addr - (char*)vdata);
|
2014-11-05 05:39:24 +00:00
|
|
|
vaostatic |= 1u<<VATTR_TNORMALS;
|
2009-07-05 18:45:53 +00:00
|
|
|
}
|
2013-08-27 13:18:09 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
|
2013-05-03 04:28:08 +00:00
|
|
|
GLBE_SetupVAO(vbo, vaodynamic, vaostatic);
|
2012-04-24 07:59:11 +00:00
|
|
|
|
2018-04-08 14:24:50 +00:00
|
|
|
if (qglBufferStorage)
|
|
|
|
{ //gl4.4 allows us to explicitly create device-only vbos
|
|
|
|
qglBufferStorage(GL_ARRAY_BUFFER_ARB, vsize, vdata, 0);
|
|
|
|
if (elementsize>0)
|
|
|
|
qglBufferStorage(GL_ELEMENT_ARRAY_BUFFER_ARB, elementsize, edata, 0);
|
|
|
|
}
|
|
|
|
else
|
2012-04-24 07:59:11 +00:00
|
|
|
{
|
2018-04-08 14:24:50 +00:00
|
|
|
qglBufferDataARB(GL_ARRAY_BUFFER_ARB, vsize, vdata, GL_STATIC_DRAW_ARB);
|
|
|
|
if (elementsize>0)
|
|
|
|
{
|
|
|
|
qglBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, elementsize, edata, GL_STATIC_DRAW_ARB);
|
|
|
|
}
|
2012-04-24 07:59:11 +00:00
|
|
|
}
|
|
|
|
|
2009-07-05 18:45:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-03 04:28:08 +00:00
|
|
|
//allocates an aligned buffer. caller needs to make sure there's enough space.
|
2011-02-25 04:22:14 +00:00
|
|
|
void *allocbuf(char **p, int elements, int elementsize)
|
|
|
|
{
|
|
|
|
void *ret;
|
|
|
|
*p += elementsize - 1;
|
2011-06-01 13:21:54 +00:00
|
|
|
*p -= (size_t)*p & (elementsize-1);
|
2011-02-25 04:22:14 +00:00
|
|
|
ret = *p;
|
|
|
|
*p += elements*elementsize;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-03 04:28:08 +00:00
|
|
|
void GLBE_GenBatchVBOs(vbo_t **vbochain, batch_t *firstbatch, batch_t *stopbatch, int lightmaps)
|
2009-05-24 10:11:17 +00:00
|
|
|
{
|
|
|
|
unsigned int maxvboverts;
|
|
|
|
unsigned int maxvboelements;
|
|
|
|
|
2012-07-05 19:42:36 +00:00
|
|
|
unsigned int i, s;
|
2009-05-24 10:11:17 +00:00
|
|
|
unsigned int v;
|
|
|
|
unsigned int vcount, ecount;
|
2009-07-05 18:45:53 +00:00
|
|
|
unsigned int pervertsize; //erm, that name wasn't intentional
|
2009-11-04 21:16:50 +00:00
|
|
|
unsigned int meshes;
|
2009-07-05 18:45:53 +00:00
|
|
|
|
|
|
|
vbo_t *vbo;
|
2009-05-24 10:11:17 +00:00
|
|
|
mesh_t *m;
|
2011-02-25 04:22:14 +00:00
|
|
|
char *p;
|
2009-05-24 10:28:26 +00:00
|
|
|
|
2011-12-23 03:12:29 +00:00
|
|
|
vecV_t *coord;
|
|
|
|
vec2_t *texcoord;
|
2013-10-08 14:28:11 +00:00
|
|
|
vec2_t *lmcoord[MAXRLIGHTMAPS];
|
2011-12-23 03:12:29 +00:00
|
|
|
vec3_t *normals;
|
|
|
|
vec3_t *svector;
|
|
|
|
vec3_t *tvector;
|
2013-10-08 14:28:11 +00:00
|
|
|
vec4_t *colours[MAXRLIGHTMAPS];
|
2011-12-23 03:12:29 +00:00
|
|
|
index_t *indicies;
|
2012-05-09 15:30:53 +00:00
|
|
|
batch_t *batch;
|
2013-05-03 04:28:08 +00:00
|
|
|
int vbosize;
|
2012-05-09 15:30:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
vbo = Z_Malloc(sizeof(*vbo));
|
|
|
|
|
|
|
|
maxvboverts = 0;
|
|
|
|
maxvboelements = 0;
|
|
|
|
meshes = 0;
|
|
|
|
for(batch = firstbatch; batch != stopbatch; batch = batch->next)
|
|
|
|
{
|
2012-07-05 19:42:36 +00:00
|
|
|
for (i=0 ; i<batch->maxmeshes ; i++)
|
2012-05-09 15:30:53 +00:00
|
|
|
{
|
|
|
|
m = batch->mesh[i];
|
|
|
|
meshes++;
|
|
|
|
maxvboelements += m->numindexes;
|
|
|
|
maxvboverts += m->numvertexes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (maxvboverts > MAX_INDICIES)
|
|
|
|
Sys_Error("Building a vbo with too many verticies\n");
|
|
|
|
|
|
|
|
|
|
|
|
vcount = 0;
|
|
|
|
ecount = 0;
|
|
|
|
|
|
|
|
pervertsize = sizeof(vecV_t)+ //coord
|
|
|
|
sizeof(vec2_t)+ //tex
|
2013-05-03 04:28:08 +00:00
|
|
|
sizeof(vec2_t)*lightmaps+ //lm
|
2012-05-09 15:30:53 +00:00
|
|
|
sizeof(vec3_t)+ //normal
|
|
|
|
sizeof(vec3_t)+ //sdir
|
|
|
|
sizeof(vec3_t)+ //tdir
|
2013-08-27 13:18:09 +00:00
|
|
|
sizeof(vec4_t)*lightmaps; //colours
|
2012-05-09 15:30:53 +00:00
|
|
|
|
|
|
|
vbo->vertdata = BZ_Malloc((maxvboverts+1)*pervertsize + (maxvboelements+1)*sizeof(index_t));
|
|
|
|
|
|
|
|
p = vbo->vertdata;
|
|
|
|
|
|
|
|
vbo->coord.gl.addr = allocbuf(&p, maxvboverts, sizeof(vecV_t));
|
|
|
|
vbo->texcoord.gl.addr = allocbuf(&p, maxvboverts, sizeof(vec2_t));
|
2013-05-03 04:28:08 +00:00
|
|
|
for (s = 0; s < lightmaps; s++)
|
2012-07-05 19:42:36 +00:00
|
|
|
vbo->lmcoord[s].gl.addr = allocbuf(&p, maxvboverts, sizeof(vec2_t));
|
2013-10-08 14:28:11 +00:00
|
|
|
for (; s < MAXRLIGHTMAPS; s++)
|
2013-05-03 04:28:08 +00:00
|
|
|
vbo->lmcoord[s].gl.addr = NULL;
|
2012-05-09 15:30:53 +00:00
|
|
|
vbo->normals.gl.addr = allocbuf(&p, maxvboverts, sizeof(vec3_t));
|
|
|
|
vbo->svector.gl.addr = allocbuf(&p, maxvboverts, sizeof(vec3_t));
|
|
|
|
vbo->tvector.gl.addr = allocbuf(&p, maxvboverts, sizeof(vec3_t));
|
2013-08-27 13:18:09 +00:00
|
|
|
for (s = 0; s < lightmaps; s++)
|
|
|
|
vbo->colours[s].gl.addr = allocbuf(&p, maxvboverts, sizeof(vec4_t));
|
2013-10-08 14:28:11 +00:00
|
|
|
for (; s < MAXRLIGHTMAPS; s++)
|
2013-08-27 13:18:09 +00:00
|
|
|
vbo->lmcoord[s].gl.addr = NULL;
|
2013-05-03 04:28:08 +00:00
|
|
|
vbosize = (char*)p - (char*)vbo->coord.gl.addr;
|
|
|
|
if ((char*)p - (char*)vbo->vertdata > (maxvboverts+1)*pervertsize)
|
|
|
|
Sys_Error("GLBE_GenBatchVBOs: aligned overflow");
|
2012-05-09 15:30:53 +00:00
|
|
|
vbo->indicies.gl.addr = allocbuf(&p, maxvboelements, sizeof(index_t));
|
|
|
|
|
|
|
|
coord = vbo->coord.gl.addr;
|
|
|
|
texcoord = vbo->texcoord.gl.addr;
|
2013-10-08 14:28:11 +00:00
|
|
|
for (s = 0; s < MAXRLIGHTMAPS; s++)
|
2013-08-27 13:18:09 +00:00
|
|
|
{
|
2012-07-05 19:42:36 +00:00
|
|
|
lmcoord[s] = vbo->lmcoord[s].gl.addr;
|
2013-08-27 13:18:09 +00:00
|
|
|
colours[s] = vbo->colours[s].gl.addr;
|
|
|
|
}
|
2012-05-09 15:30:53 +00:00
|
|
|
normals = vbo->normals.gl.addr;
|
|
|
|
svector = vbo->svector.gl.addr;
|
|
|
|
tvector = vbo->tvector.gl.addr;
|
|
|
|
indicies = vbo->indicies.gl.addr;
|
|
|
|
|
|
|
|
//vbo->meshcount = meshes;
|
|
|
|
//vbo->meshlist = BZ_Malloc(meshes*sizeof(*vbo->meshlist));
|
|
|
|
|
|
|
|
meshes = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for(batch = firstbatch; batch != stopbatch; batch = batch->next)
|
|
|
|
{
|
|
|
|
batch->vbo = vbo;
|
2012-07-05 19:42:36 +00:00
|
|
|
for (i=0 ; i<batch->maxmeshes ; i++)
|
2012-05-09 15:30:53 +00:00
|
|
|
{
|
|
|
|
m = batch->mesh[i];
|
|
|
|
|
|
|
|
// surf->mark = &vbo->meshlist[meshes++];
|
|
|
|
// *surf->mark = NULL;
|
|
|
|
|
|
|
|
m->vbofirstvert = vcount;
|
|
|
|
m->vbofirstelement = ecount;
|
|
|
|
for (v = 0; v < m->numindexes; v++)
|
|
|
|
indicies[ecount++] = vcount + m->indexes[v];
|
|
|
|
for (v = 0; v < m->numvertexes; v++)
|
|
|
|
{
|
|
|
|
coord[vcount+v][0] = m->xyz_array[v][0];
|
|
|
|
coord[vcount+v][1] = m->xyz_array[v][1];
|
|
|
|
coord[vcount+v][2] = m->xyz_array[v][2];
|
|
|
|
if (m->st_array)
|
|
|
|
{
|
|
|
|
texcoord[vcount+v][0] = m->st_array[v][0];
|
|
|
|
texcoord[vcount+v][1] = m->st_array[v][1];
|
|
|
|
}
|
2013-05-03 04:28:08 +00:00
|
|
|
for (s = 0; s < lightmaps; s++)
|
2012-05-09 15:30:53 +00:00
|
|
|
{
|
2012-07-05 19:42:36 +00:00
|
|
|
if (m->lmst_array[s])
|
|
|
|
{
|
|
|
|
lmcoord[s][vcount+v][0] = m->lmst_array[s][v][0];
|
|
|
|
lmcoord[s][vcount+v][1] = m->lmst_array[s][v][1];
|
|
|
|
}
|
2013-08-27 13:18:09 +00:00
|
|
|
if (m->colors4f_array[s])
|
|
|
|
{
|
|
|
|
colours[s][vcount+v][0] = m->colors4f_array[s][v][0];
|
|
|
|
colours[s][vcount+v][1] = m->colors4f_array[s][v][1];
|
|
|
|
colours[s][vcount+v][2] = m->colors4f_array[s][v][2];
|
|
|
|
colours[s][vcount+v][3] = m->colors4f_array[s][v][3];
|
|
|
|
}
|
2012-05-09 15:30:53 +00:00
|
|
|
}
|
|
|
|
if (m->normals_array)
|
|
|
|
{
|
|
|
|
normals[vcount+v][0] = m->normals_array[v][0];
|
|
|
|
normals[vcount+v][1] = m->normals_array[v][1];
|
|
|
|
normals[vcount+v][2] = m->normals_array[v][2];
|
|
|
|
}
|
|
|
|
if (m->snormals_array)
|
|
|
|
{
|
|
|
|
svector[vcount+v][0] = m->snormals_array[v][0];
|
|
|
|
svector[vcount+v][1] = m->snormals_array[v][1];
|
|
|
|
svector[vcount+v][2] = m->snormals_array[v][2];
|
|
|
|
}
|
|
|
|
if (m->tnormals_array)
|
|
|
|
{
|
|
|
|
tvector[vcount+v][0] = m->tnormals_array[v][0];
|
|
|
|
tvector[vcount+v][1] = m->tnormals_array[v][1];
|
|
|
|
tvector[vcount+v][2] = m->tnormals_array[v][2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vcount += v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-03 04:28:08 +00:00
|
|
|
if (GL_BuildVBO(vbo, vbo->coord.gl.addr, vbosize/*vcount*pervertsize*/, indicies, ecount*sizeof(index_t), 0))
|
2012-05-09 15:30:53 +00:00
|
|
|
{
|
|
|
|
BZ_Free(vbo->vertdata);
|
|
|
|
vbo->vertdata = NULL;
|
|
|
|
}
|
2015-10-11 11:34:58 +00:00
|
|
|
vbo->vertcount = vcount;
|
2012-05-09 15:30:53 +00:00
|
|
|
|
|
|
|
vbo->next = *vbochain;
|
|
|
|
*vbochain = vbo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLBE_GenBrushModelVBO(model_t *mod)
|
|
|
|
{
|
|
|
|
unsigned int vcount;
|
2012-07-07 02:52:39 +00:00
|
|
|
unsigned int cvcount;
|
2011-12-23 03:12:29 +00:00
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
|
|
|
|
batch_t *batch, *fbatch;
|
|
|
|
int sortid;
|
2012-07-05 19:42:36 +00:00
|
|
|
int i;
|
2012-05-09 15:30:53 +00:00
|
|
|
|
|
|
|
fbatch = NULL;
|
|
|
|
vcount = 0;
|
|
|
|
for (sortid = 0; sortid < SHADER_SORT_COUNT; sortid++)
|
|
|
|
{
|
|
|
|
if (!mod->batches[sortid])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (fbatch = batch = mod->batches[sortid]; batch != NULL; batch = batch->next)
|
|
|
|
{
|
2012-07-07 02:52:39 +00:00
|
|
|
for (i = 0, cvcount = 0; i < batch->maxmeshes; i++)
|
|
|
|
cvcount += batch->mesh[i]->numvertexes;
|
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
//firstmesh got reused as the number of verticies in each batch
|
2012-07-07 02:52:39 +00:00
|
|
|
if (vcount + cvcount > MAX_INDICIES)
|
2012-05-09 15:30:53 +00:00
|
|
|
{
|
2013-05-03 04:28:08 +00:00
|
|
|
GLBE_GenBatchVBOs(&mod->vbos, fbatch, batch, mod->lightmaps.surfstyles);
|
2012-05-09 15:30:53 +00:00
|
|
|
fbatch = batch;
|
|
|
|
vcount = 0;
|
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
|
2012-07-07 02:52:39 +00:00
|
|
|
vcount += cvcount;
|
2012-05-09 15:30:53 +00:00
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
|
2013-05-03 04:28:08 +00:00
|
|
|
GLBE_GenBatchVBOs(&mod->vbos, fbatch, batch, mod->lightmaps.surfstyles);
|
2012-05-09 15:30:53 +00:00
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
#if 0
|
2009-07-05 18:45:53 +00:00
|
|
|
if (!mod->numsurfaces)
|
2009-05-24 10:11:17 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (t = 0; t < mod->numtextures; t++)
|
|
|
|
{
|
|
|
|
if (!mod->textures[t])
|
|
|
|
continue;
|
2009-07-05 18:45:53 +00:00
|
|
|
vbo = &mod->textures[t]->vbo;
|
2009-11-04 21:16:50 +00:00
|
|
|
BE_ClearVBO(vbo);
|
2009-05-24 10:11:17 +00:00
|
|
|
|
|
|
|
maxvboverts = 0;
|
|
|
|
maxvboelements = 0;
|
2009-11-04 21:16:50 +00:00
|
|
|
meshes = 0;
|
2009-05-24 10:11:17 +00:00
|
|
|
for (i=0 ; i<mod->numsurfaces ; i++)
|
|
|
|
{
|
|
|
|
if (mod->surfaces[i].texinfo->texture != mod->textures[t])
|
|
|
|
continue;
|
|
|
|
m = mod->surfaces[i].mesh;
|
2009-07-25 11:05:06 +00:00
|
|
|
if (!m)
|
|
|
|
continue;
|
2009-05-24 10:11:17 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
meshes++;
|
2009-05-24 10:11:17 +00:00
|
|
|
maxvboelements += m->numindexes;
|
|
|
|
maxvboverts += m->numvertexes;
|
|
|
|
}
|
2009-11-07 13:29:15 +00:00
|
|
|
#if sizeof_index_t == 2
|
2009-05-24 10:11:17 +00:00
|
|
|
if (maxvboverts > (1<<(sizeof(index_t)*8))-1)
|
|
|
|
continue;
|
2009-11-07 13:29:15 +00:00
|
|
|
#endif
|
2009-05-24 10:11:17 +00:00
|
|
|
if (!maxvboverts)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//fixme: stop this from leaking!
|
|
|
|
vcount = 0;
|
|
|
|
ecount = 0;
|
2009-07-05 18:45:53 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
pervertsize = sizeof(vecV_t)+ //coord
|
2009-07-05 18:45:53 +00:00
|
|
|
sizeof(vec2_t)+ //tex
|
|
|
|
sizeof(vec2_t)+ //lm
|
|
|
|
sizeof(vec3_t)+ //normal
|
|
|
|
sizeof(vec3_t)+ //sdir
|
2009-11-04 21:16:50 +00:00
|
|
|
sizeof(vec3_t)+ //tdir
|
|
|
|
sizeof(vec4_t); //colours
|
2009-07-05 18:45:53 +00:00
|
|
|
|
2011-02-25 04:22:14 +00:00
|
|
|
vbo->vertdata = BZ_Malloc((maxvboverts+1)*pervertsize + (maxvboelements+1)*sizeof(index_t));
|
|
|
|
|
|
|
|
p = vbo->vertdata;
|
2009-07-05 18:45:53 +00:00
|
|
|
|
2011-12-23 03:12:29 +00:00
|
|
|
vbo->coord.gl.addr = allocbuf(&p, maxvboverts, sizeof(vecV_t));
|
|
|
|
vbo->texcoord.gl.addr = allocbuf(&p, maxvboverts, sizeof(vec2_t));
|
|
|
|
vbo->lmcoord.gl.addr = allocbuf(&p, maxvboverts, sizeof(vec2_t));
|
|
|
|
vbo->normals.gl.addr = allocbuf(&p, maxvboverts, sizeof(vec3_t));
|
|
|
|
vbo->svector.gl.addr = allocbuf(&p, maxvboverts, sizeof(vec3_t));
|
|
|
|
vbo->tvector.gl.addr = allocbuf(&p, maxvboverts, sizeof(vec3_t));
|
|
|
|
vbo->colours.gl.addr = allocbuf(&p, maxvboverts, sizeof(vec4_t));
|
|
|
|
vbo->indicies.gl.addr = allocbuf(&p, maxvboelements, sizeof(index_t));
|
|
|
|
|
|
|
|
coord = vbo->coord.gl.addr;
|
|
|
|
texcoord = vbo->texcoord.gl.addr;
|
|
|
|
lmcoord = vbo->lmcoord.gl.addr;
|
|
|
|
normals = vbo->normals.gl.addr;
|
|
|
|
svector = vbo->svector.gl.addr;
|
|
|
|
tvector = vbo->tvector.gl.addr;
|
|
|
|
colours = vbo->colours.gl.addr;
|
|
|
|
indicies = vbo->indicies.gl.addr;
|
2009-07-05 18:45:53 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
vbo->meshcount = meshes;
|
|
|
|
vbo->meshlist = BZ_Malloc(meshes*sizeof(*vbo->meshlist));
|
|
|
|
|
|
|
|
meshes = 0;
|
|
|
|
|
2009-05-24 10:11:17 +00:00
|
|
|
for (i=0 ; i<mod->numsurfaces ; i++)
|
|
|
|
{
|
|
|
|
if (mod->surfaces[i].texinfo->texture != mod->textures[t])
|
|
|
|
continue;
|
|
|
|
m = mod->surfaces[i].mesh;
|
2009-07-25 11:05:06 +00:00
|
|
|
if (!m)
|
|
|
|
continue;
|
2009-05-24 10:11:17 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
mod->surfaces[i].mark = &vbo->meshlist[meshes++];
|
|
|
|
*mod->surfaces[i].mark = NULL;
|
|
|
|
|
2009-05-24 10:11:17 +00:00
|
|
|
m->vbofirstvert = vcount;
|
|
|
|
m->vbofirstelement = ecount;
|
|
|
|
for (v = 0; v < m->numindexes; v++)
|
2011-12-23 03:12:29 +00:00
|
|
|
indicies[ecount++] = vcount + m->indexes[v];
|
2009-05-24 10:11:17 +00:00
|
|
|
for (v = 0; v < m->numvertexes; v++)
|
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
coord[vcount+v][0] = m->xyz_array[v][0];
|
|
|
|
coord[vcount+v][1] = m->xyz_array[v][1];
|
|
|
|
coord[vcount+v][2] = m->xyz_array[v][2];
|
2009-05-24 10:11:17 +00:00
|
|
|
if (m->st_array)
|
2009-06-21 17:45:33 +00:00
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
texcoord[vcount+v][0] = m->st_array[v][0];
|
|
|
|
texcoord[vcount+v][1] = m->st_array[v][1];
|
2009-06-21 17:45:33 +00:00
|
|
|
}
|
2009-05-24 10:11:17 +00:00
|
|
|
if (m->lmst_array)
|
2009-06-21 17:45:33 +00:00
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
lmcoord[vcount+v][0] = m->lmst_array[v][0];
|
|
|
|
lmcoord[vcount+v][1] = m->lmst_array[v][1];
|
2009-06-21 17:45:33 +00:00
|
|
|
}
|
2009-07-18 20:46:42 +00:00
|
|
|
if (m->normals_array)
|
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
normals[vcount+v][0] = m->normals_array[v][0];
|
|
|
|
normals[vcount+v][1] = m->normals_array[v][1];
|
|
|
|
normals[vcount+v][2] = m->normals_array[v][2];
|
2009-07-18 20:46:42 +00:00
|
|
|
}
|
|
|
|
if (m->snormals_array)
|
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
svector[vcount+v][0] = m->snormals_array[v][0];
|
|
|
|
svector[vcount+v][1] = m->snormals_array[v][1];
|
|
|
|
svector[vcount+v][2] = m->snormals_array[v][2];
|
2009-07-18 20:46:42 +00:00
|
|
|
}
|
|
|
|
if (m->tnormals_array)
|
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
tvector[vcount+v][0] = m->tnormals_array[v][0];
|
|
|
|
tvector[vcount+v][1] = m->tnormals_array[v][1];
|
|
|
|
tvector[vcount+v][2] = m->tnormals_array[v][2];
|
2009-07-18 20:46:42 +00:00
|
|
|
}
|
2009-11-04 21:16:50 +00:00
|
|
|
if (m->colors4f_array)
|
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
colours[vcount+v][0] = m->colors4f_array[v][0];
|
|
|
|
colours[vcount+v][1] = m->colors4f_array[v][1];
|
|
|
|
colours[vcount+v][2] = m->colors4f_array[v][2];
|
|
|
|
colours[vcount+v][3] = m->colors4f_array[v][3];
|
2009-11-04 21:16:50 +00:00
|
|
|
}
|
2009-05-24 10:11:17 +00:00
|
|
|
}
|
|
|
|
vcount += v;
|
|
|
|
}
|
2009-07-05 18:45:53 +00:00
|
|
|
|
2012-04-24 07:59:11 +00:00
|
|
|
if (GL_BuildVBO(vbo, vbo->vertdata, vcount*pervertsize, indicies, ecount*sizeof(index_t), 0))
|
2009-07-05 18:45:53 +00:00
|
|
|
{
|
2011-02-25 04:22:14 +00:00
|
|
|
BZ_Free(vbo->vertdata);
|
|
|
|
vbo->vertdata = NULL;
|
2009-07-05 18:45:53 +00:00
|
|
|
}
|
2015-10-11 11:34:58 +00:00
|
|
|
vbo->vertcount = vcount;
|
2009-05-24 10:11:17 +00:00
|
|
|
}
|
2012-05-09 15:30:53 +00:00
|
|
|
#endif
|
2009-05-24 10:11:17 +00:00
|
|
|
}
|
2004-08-22 22:29:09 +00:00
|
|
|
|
2011-01-04 02:56:16 +00:00
|
|
|
void GLBE_UploadAllLightmaps(void)
|
2004-08-22 22:29:09 +00:00
|
|
|
{
|
2012-07-05 19:42:36 +00:00
|
|
|
lightmapinfo_t *lm;
|
2009-11-07 13:29:15 +00:00
|
|
|
int i;
|
2004-08-22 22:29:09 +00:00
|
|
|
//
|
|
|
|
// upload all lightmaps that were filled
|
|
|
|
//
|
|
|
|
for (i=0 ; i<numlightmaps ; i++)
|
|
|
|
{
|
|
|
|
if (!lightmap[i])
|
|
|
|
break; // no more used
|
2012-07-05 19:42:36 +00:00
|
|
|
lm = lightmap[i];
|
|
|
|
lm->rectchange.l = lm->width;
|
|
|
|
lm->rectchange.t = lm->height;
|
2015-10-11 11:34:58 +00:00
|
|
|
lm->rectchange.r = 0;
|
|
|
|
lm->rectchange.b = 0;
|
2012-07-05 19:42:36 +00:00
|
|
|
if (!lm->modified)
|
2008-11-09 22:29:28 +00:00
|
|
|
continue;
|
2012-07-05 19:42:36 +00:00
|
|
|
lm->modified = false;
|
2012-09-30 05:52:03 +00:00
|
|
|
if (!TEXVALID(lm->lightmap_texture))
|
2018-03-04 14:41:16 +00:00
|
|
|
TEXASSIGN(lm->lightmap_texture, Image_CreateTexture(va("***lightmap %i***", i), NULL, (r_lightmap_nearest.ival?IF_NEAREST:IF_LINEAR)|IF_NOMIPMAP));
|
2014-10-05 20:04:11 +00:00
|
|
|
if (!lm->lightmap_texture->num)
|
|
|
|
qglGenTextures(1, &lm->lightmap_texture->num);
|
2012-07-05 19:42:36 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, lm->lightmap_texture);
|
2018-03-04 14:41:16 +00:00
|
|
|
if (r_lightmap_nearest.ival)
|
2014-04-02 00:58:02 +00:00
|
|
|
{
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
}
|
2018-03-04 14:41:16 +00:00
|
|
|
|
2018-10-27 04:32:18 +00:00
|
|
|
qglTexImage2D(GL_TEXTURE_2D, 0, gl_config.formatinfo[lm->fmt].internalformat, lm->width, lm->height, 0, gl_config.formatinfo[lm->fmt].format, gl_config.formatinfo[lm->fmt].type, lightmap[i]->lightmaps);
|
2018-03-04 14:41:16 +00:00
|
|
|
|
|
|
|
if (gl_config.glversion >= (gl_config.gles?3.0:3.3))
|
Fixes, workarounds, and breakages. Hexen2 should work much better (-hexen2 says no mission pack, -portals says h2mp). Started working on splitting bigcoords per client, far too much work still to go on that. Removed gl_ztrick entirely. Enabled csprogs download by default. Added client support for fitzquake's 666 protocol, needs testing, some cleanup for dp protocols too, no server support, couldn't selectively enable it anyway. Now attempting to cache shadow meshes for explosions and stuff. Played with lightmaps a little, should potentially run a little faster on certain (intel?) cards. Tweeked npfte a little to try to avoid deadlocks and crashes. Fixed sky worldspawn parsing. Added h2mp's model format. Fixed baseline issue in q2 client, made servers generate q2 baselines. MOVETYPE_PUSH will not rotate extra if rotation is forced. Made status command show allowed client types. Changed lighting on weapons - should now be shaded.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3572 fc73d0e0-1445-4013-8a0c-d673dee63da5
2010-08-11 03:36:31 +00:00
|
|
|
{
|
2018-10-27 04:32:18 +00:00
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, gl_config.formatinfo[lm->fmt].swizzle_r);
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, gl_config.formatinfo[lm->fmt].swizzle_g);
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, gl_config.formatinfo[lm->fmt].swizzle_b);
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, gl_config.formatinfo[lm->fmt].swizzle_a);
|
Fixes, workarounds, and breakages. Hexen2 should work much better (-hexen2 says no mission pack, -portals says h2mp). Started working on splitting bigcoords per client, far too much work still to go on that. Removed gl_ztrick entirely. Enabled csprogs download by default. Added client support for fitzquake's 666 protocol, needs testing, some cleanup for dp protocols too, no server support, couldn't selectively enable it anyway. Now attempting to cache shadow meshes for explosions and stuff. Played with lightmaps a little, should potentially run a little faster on certain (intel?) cards. Tweeked npfte a little to try to avoid deadlocks and crashes. Fixed sky worldspawn parsing. Added h2mp's model format. Fixed baseline issue in q2 client, made servers generate q2 baselines. MOVETYPE_PUSH will not rotate extra if rotation is forced. Made status command show allowed client types. Changed lighting on weapons - should now be shaded.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3572 fc73d0e0-1445-4013-8a0c-d673dee63da5
2010-08-11 03:36:31 +00:00
|
|
|
}
|
2018-03-04 14:41:16 +00:00
|
|
|
|
2014-12-09 14:39:54 +00:00
|
|
|
//for completeness.
|
|
|
|
lm->lightmap_texture->width = lm->width;
|
|
|
|
lm->lightmap_texture->height = lm->height;
|
|
|
|
lm->lightmap_texture->status = TEX_LOADED;
|
2004-08-22 22:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
|
2004-12-15 19:53:30 +00:00
|
|
|
#endif
|