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>
|
|
|
|
|
2011-01-04 02:56:16 +00:00
|
|
|
void GLBE_ClearVBO(vbo_t *vbo)
|
2009-07-05 18:45:53 +00:00
|
|
|
{
|
2012-07-05 19:42:36 +00:00
|
|
|
int vboh[6 + MAXLIGHTMAPS];
|
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;
|
|
|
|
for (i = 0; i < MAXLIGHTMAPS; i++)
|
|
|
|
vboh[6+i] = vbo->lmcoord[i].gl.vbo;
|
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);
|
2010-07-12 22:46:37 +00:00
|
|
|
BZ_Free(vbo->meshlist);
|
2012-07-05 19:42:36 +00:00
|
|
|
BZ_Free(vbo);
|
2009-07-05 18:45:53 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 07:59:11 +00:00
|
|
|
void GLBE_SetupVAO(vbo_t *vbo, unsigned int vaodynamic);
|
|
|
|
|
|
|
|
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;
|
2009-07-05 18:45:53 +00:00
|
|
|
|
2009-07-11 20:56:09 +00:00
|
|
|
if (!qglGenBuffersARB)
|
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);
|
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);
|
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);
|
2009-07-05 18:45:53 +00:00
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
for (s = 0; s < MAXLIGHTMAPS; s++)
|
2009-07-05 18:45:53 +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);
|
|
|
|
}
|
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);
|
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);
|
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);
|
2009-07-05 18:45:53 +00:00
|
|
|
}
|
2011-12-23 03:12:29 +00:00
|
|
|
if (vbo->colours.gl.addr)
|
2009-11-04 21:16:50 +00:00
|
|
|
{
|
2011-12-23 03:12:29 +00:00
|
|
|
vbo->colours.gl.vbo = vbos[0];
|
|
|
|
vbo->colours.gl.addr = (vec4_t*)((char*)vbo->colours.gl.addr - (char*)vdata);
|
2009-11-04 21:16:50 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 07:59:11 +00:00
|
|
|
GLBE_SetupVAO(vbo, vaodynamic);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-07-05 18:45:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
void GLBE_GenBatchVBOs(vbo_t **vbochain, batch_t *firstbatch, batch_t *stopbatch)
|
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;
|
2012-07-05 19:42:36 +00:00
|
|
|
vec2_t *lmcoord[MAXLIGHTMAPS];
|
2011-12-23 03:12:29 +00:00
|
|
|
vec3_t *normals;
|
|
|
|
vec3_t *svector;
|
|
|
|
vec3_t *tvector;
|
|
|
|
vec4_t *colours;
|
|
|
|
index_t *indicies;
|
2012-05-09 15:30:53 +00:00
|
|
|
batch_t *batch;
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2012-07-05 19:42:36 +00:00
|
|
|
sizeof(vec2_t)*MAXLIGHTMAPS+ //lm
|
2012-05-09 15:30:53 +00:00
|
|
|
sizeof(vec3_t)+ //normal
|
|
|
|
sizeof(vec3_t)+ //sdir
|
|
|
|
sizeof(vec3_t)+ //tdir
|
|
|
|
sizeof(vec4_t); //colours
|
|
|
|
|
|
|
|
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));
|
2012-07-05 19:42:36 +00:00
|
|
|
for (s = 0; s < MAXLIGHTMAPS; s++)
|
|
|
|
vbo->lmcoord[s].gl.addr = allocbuf(&p, maxvboverts, sizeof(vec2_t));
|
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));
|
|
|
|
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;
|
2012-07-05 19:42:36 +00:00
|
|
|
for (s = 0; s < 4; s++)
|
|
|
|
lmcoord[s] = vbo->lmcoord[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;
|
|
|
|
colours = vbo->colours.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];
|
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
for (s = 0; s < MAXLIGHTMAPS; 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];
|
|
|
|
}
|
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];
|
|
|
|
}
|
|
|
|
if (m->colors4f_array)
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vcount += v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GL_BuildVBO(vbo, vbo->vertdata, vcount*pervertsize, indicies, ecount*sizeof(index_t), 0))
|
|
|
|
{
|
|
|
|
BZ_Free(vbo->vertdata);
|
|
|
|
vbo->vertdata = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
GLBE_GenBatchVBOs(&mod->vbos, fbatch, batch);
|
|
|
|
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
|
|
|
|
2012-05-09 15:30:53 +00:00
|
|
|
GLBE_GenBatchVBOs(&mod->vbos, fbatch, batch);
|
|
|
|
}
|
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
|
|
|
}
|
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;
|
|
|
|
lm->rectchange.w = 0;
|
|
|
|
lm->rectchange.h = 0;
|
|
|
|
if (!lm->modified)
|
2008-11-09 22:29:28 +00:00
|
|
|
continue;
|
2012-07-05 19:42:36 +00:00
|
|
|
lm->modified = false;
|
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, lm->lightmap_texture);
|
2009-11-04 21:16:50 +00:00
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
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
|
|
|
switch (lightmap_bytes)
|
|
|
|
{
|
|
|
|
case 4:
|
2011-09-05 01:48:23 +00:00
|
|
|
qglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
2012-07-05 19:42:36 +00:00
|
|
|
lm->width, lm->height, 0, (lightmap_bgra?GL_BGRA_EXT:GL_RGBA), GL_UNSIGNED_INT_8_8_8_8_REV,
|
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
|
|
|
lightmap[i]->lightmaps);
|
|
|
|
break;
|
|
|
|
case 3:
|
2011-06-01 13:21:54 +00:00
|
|
|
qglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
|
2012-07-05 19:42:36 +00:00
|
|
|
lm->width, lm->height, 0, (lightmap_bgra?GL_BGR_EXT:GL_RGB), GL_UNSIGNED_BYTE,
|
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
|
|
|
lightmap[i]->lightmaps);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
qglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE,
|
2012-07-05 19:42:36 +00:00
|
|
|
lm->width, lm->height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,
|
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
|
|
|
lightmap[i]->lightmaps);
|
|
|
|
break;
|
|
|
|
}
|
2011-10-27 16:16:29 +00:00
|
|
|
if (r_deluxemapping.ival)
|
2005-09-14 04:25:10 +00:00
|
|
|
{
|
|
|
|
lightmap[i]->deluxmodified = false;
|
2012-07-05 19:42:36 +00:00
|
|
|
lightmap[i]->deluxrectchange.l = lm->width;
|
|
|
|
lightmap[i]->deluxrectchange.t = lm->height;
|
2005-09-14 04:25:10 +00:00
|
|
|
lightmap[i]->deluxrectchange.w = 0;
|
|
|
|
lightmap[i]->deluxrectchange.h = 0;
|
2012-07-05 19:42:36 +00:00
|
|
|
GL_MTBind(0, GL_TEXTURE_2D, lm->deluxmap_texture);
|
2009-11-04 21:16:50 +00:00
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2005-09-14 04:25:10 +00:00
|
|
|
qglTexImage2D (GL_TEXTURE_2D, 0, 3
|
2012-07-05 19:42:36 +00:00
|
|
|
, lm->width, lm->height, 0,
|
2010-07-11 02:22:39 +00:00
|
|
|
GL_RGB, GL_UNSIGNED_BYTE, lightmap[i]->deluxmaps);
|
2005-09-14 04:25:10 +00:00
|
|
|
}
|
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
|