2012-10-26 01:23:06 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
Copyright (C) 2007-2009 Robert Beckebans <trebor_7@users.sourceforge.net>
|
|
|
|
|
|
|
|
This file is part of XreaL source code.
|
|
|
|
|
|
|
|
XreaL source code 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.
|
|
|
|
|
|
|
|
XreaL source code 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 XreaL source code; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
// tr_vbo.c
|
|
|
|
#include "tr_local.h"
|
|
|
|
|
2013-12-10 01:33:54 +00:00
|
|
|
|
2016-09-06 07:57:15 +00:00
|
|
|
void R_VaoPackTangent(int16_t *out, vec4_t v)
|
2013-12-10 01:33:54 +00:00
|
|
|
{
|
2016-09-06 07:57:15 +00:00
|
|
|
out[0] = v[0] * 32767.0f + (v[0] > 0.0f ? 0.5f : -0.5f);
|
|
|
|
out[1] = v[1] * 32767.0f + (v[1] > 0.0f ? 0.5f : -0.5f);
|
|
|
|
out[2] = v[2] * 32767.0f + (v[2] > 0.0f ? 0.5f : -0.5f);
|
|
|
|
out[3] = v[3] * 32767.0f + (v[3] > 0.0f ? 0.5f : -0.5f);
|
2014-11-04 03:10:35 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 07:57:15 +00:00
|
|
|
void R_VaoPackNormal(int16_t *out, vec3_t v)
|
2014-11-04 03:10:35 +00:00
|
|
|
{
|
2016-09-06 07:57:15 +00:00
|
|
|
out[0] = v[0] * 32767.0f + (v[0] > 0.0f ? 0.5f : -0.5f);
|
|
|
|
out[1] = v[1] * 32767.0f + (v[1] > 0.0f ? 0.5f : -0.5f);
|
|
|
|
out[2] = v[2] * 32767.0f + (v[2] > 0.0f ? 0.5f : -0.5f);
|
|
|
|
out[3] = 0;
|
2014-11-04 03:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int R_VaoPackTexCoord(byte *out, vec2_t st)
|
|
|
|
{
|
|
|
|
if (glRefConfig.packedTexcoordDataType == GL_HALF_FLOAT)
|
|
|
|
{
|
|
|
|
uint16_t *num = (uint16_t *)out;
|
|
|
|
|
|
|
|
*num++ = FloatToHalf(st[0]);
|
|
|
|
*num++ = FloatToHalf(st[1]);
|
|
|
|
|
|
|
|
return sizeof(*num) * 2;
|
2013-12-10 01:33:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-04 03:10:35 +00:00
|
|
|
float *num = (float *)out;
|
2014-10-29 01:15:13 +00:00
|
|
|
|
2014-11-04 03:10:35 +00:00
|
|
|
*num++ = st[0];
|
|
|
|
*num++ = st[1];
|
2014-10-29 01:15:13 +00:00
|
|
|
|
2014-11-04 03:10:35 +00:00
|
|
|
return sizeof(*num) * 2;
|
2013-12-10 01:33:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-04 03:10:35 +00:00
|
|
|
int R_VaoPackColors(byte *out, vec4_t color)
|
2013-12-10 01:33:54 +00:00
|
|
|
{
|
2014-11-04 03:10:35 +00:00
|
|
|
if (glRefConfig.packedTexcoordDataType == GL_HALF_FLOAT)
|
2013-12-10 01:33:54 +00:00
|
|
|
{
|
2014-11-04 03:10:35 +00:00
|
|
|
uint16_t *num = (uint16_t *)out;
|
2014-10-29 01:15:13 +00:00
|
|
|
|
2014-11-04 03:10:35 +00:00
|
|
|
*num++ = FloatToHalf(color[0]);
|
|
|
|
*num++ = FloatToHalf(color[1]);
|
|
|
|
*num++ = FloatToHalf(color[2]);
|
|
|
|
*num++ = FloatToHalf(color[3]);
|
2014-10-29 01:15:13 +00:00
|
|
|
|
2014-11-04 03:10:35 +00:00
|
|
|
return sizeof(*num) * 4;
|
2013-12-10 01:33:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-04 03:10:35 +00:00
|
|
|
float *num = (float *)out;
|
2014-10-29 01:15:13 +00:00
|
|
|
|
2014-11-04 03:10:35 +00:00
|
|
|
*num++ = color[0];
|
|
|
|
*num++ = color[1];
|
|
|
|
*num++ = color[2];
|
|
|
|
*num++ = color[3];
|
2014-10-29 01:15:13 +00:00
|
|
|
|
2014-11-04 03:10:35 +00:00
|
|
|
return sizeof(*num) * 4;
|
2013-12-10 01:33:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-06 07:57:15 +00:00
|
|
|
void R_VaoUnpackTangent(vec4_t v, int16_t *pack)
|
2013-12-10 01:33:54 +00:00
|
|
|
{
|
2016-09-06 07:57:15 +00:00
|
|
|
v[0] = pack[0] / 32767.0f;
|
|
|
|
v[1] = pack[1] / 32767.0f;
|
|
|
|
v[2] = pack[2] / 32767.0f;
|
|
|
|
v[3] = pack[3] / 32767.0f;
|
2013-12-10 01:33:54 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 07:57:15 +00:00
|
|
|
void R_VaoUnpackNormal(vec3_t v, int16_t *pack)
|
2013-12-10 01:33:54 +00:00
|
|
|
{
|
2016-09-06 07:57:15 +00:00
|
|
|
v[0] = pack[0] / 32767.0f;
|
|
|
|
v[1] = pack[1] / 32767.0f;
|
|
|
|
v[2] = pack[2] / 32767.0f;
|
2013-12-10 01:33:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
void Vao_SetVertexPointers(vao_t *vao)
|
|
|
|
{
|
2014-10-23 23:51:10 +00:00
|
|
|
int attribIndex;
|
2014-10-14 08:50:44 +00:00
|
|
|
|
|
|
|
// set vertex pointers
|
2014-10-23 23:51:10 +00:00
|
|
|
for (attribIndex = 0; attribIndex < ATTR_INDEX_COUNT; attribIndex++)
|
2014-10-14 08:50:44 +00:00
|
|
|
{
|
2014-10-23 23:51:10 +00:00
|
|
|
uint32_t attribBit = 1 << attribIndex;
|
|
|
|
vaoAttrib_t *vAtb = &vao->attribs[attribIndex];
|
|
|
|
|
|
|
|
if (vAtb->enabled)
|
2014-10-14 08:50:44 +00:00
|
|
|
{
|
2016-07-25 04:29:13 +00:00
|
|
|
qglVertexAttribPointer(attribIndex, vAtb->count, vAtb->type, vAtb->normalized, vAtb->stride, BUFFER_OFFSET(vAtb->offset));
|
2014-10-23 23:51:10 +00:00
|
|
|
if (glRefConfig.vertexArrayObject || !(glState.vertexAttribsEnabled & attribBit))
|
2016-07-25 04:29:13 +00:00
|
|
|
qglEnableVertexAttribArray(attribIndex);
|
2014-10-23 23:51:10 +00:00
|
|
|
|
|
|
|
if (!glRefConfig.vertexArrayObject || vao == tess.vao)
|
|
|
|
glState.vertexAttribsEnabled |= attribBit;
|
2014-10-14 08:50:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-23 23:51:10 +00:00
|
|
|
// don't disable vertex attribs when using vertex array objects
|
|
|
|
// Vao_SetVertexPointers is only called during init when using VAOs, and vertex attribs start disabled anyway
|
|
|
|
if (!glRefConfig.vertexArrayObject && (glState.vertexAttribsEnabled & attribBit))
|
2016-07-25 04:29:13 +00:00
|
|
|
qglDisableVertexAttribArray(attribIndex);
|
2014-10-23 23:51:10 +00:00
|
|
|
|
|
|
|
if (!glRefConfig.vertexArrayObject || vao == tess.vao)
|
|
|
|
glState.vertexAttribsEnabled &= ~attribBit;
|
2014-10-14 08:50:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-26 01:23:06 +00:00
|
|
|
/*
|
|
|
|
============
|
2014-10-14 08:50:44 +00:00
|
|
|
R_CreateVao
|
2012-10-26 01:23:06 +00:00
|
|
|
============
|
|
|
|
*/
|
2014-10-14 08:50:44 +00:00
|
|
|
vao_t *R_CreateVao(const char *name, byte *vertexes, int vertexesSize, byte *indexes, int indexesSize, vaoUsage_t usage)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
vao_t *vao;
|
2012-10-26 01:23:06 +00:00
|
|
|
int glUsage;
|
|
|
|
|
|
|
|
switch (usage)
|
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
case VAO_USAGE_STATIC:
|
2016-07-25 04:29:13 +00:00
|
|
|
glUsage = GL_STATIC_DRAW;
|
2012-10-26 01:23:06 +00:00
|
|
|
break;
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
case VAO_USAGE_DYNAMIC:
|
2016-07-25 04:29:13 +00:00
|
|
|
glUsage = GL_DYNAMIC_DRAW;
|
2012-10-26 01:23:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-10-14 08:50:44 +00:00
|
|
|
Com_Error(ERR_FATAL, "bad vaoUsage_t given: %i", usage);
|
2012-10-26 01:23:06 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strlen(name) >= MAX_QPATH)
|
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
ri.Error(ERR_DROP, "R_CreateVao: \"%s\" is too long", name);
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
if ( tr.numVaos == MAX_VAOS ) {
|
|
|
|
ri.Error( ERR_DROP, "R_CreateVao: MAX_VAOS hit");
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
2013-01-24 22:53:08 +00:00
|
|
|
R_IssuePendingRenderCommands();
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
vao = tr.vaos[tr.numVaos] = ri.Hunk_Alloc(sizeof(*vao), h_low);
|
|
|
|
tr.numVaos++;
|
|
|
|
|
|
|
|
memset(vao, 0, sizeof(*vao));
|
|
|
|
|
|
|
|
Q_strncpyz(vao->name, name, sizeof(vao->name));
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
if (glRefConfig.vertexArrayObject)
|
|
|
|
{
|
2016-07-26 07:41:31 +00:00
|
|
|
qglGenVertexArrays(1, &vao->vao);
|
|
|
|
qglBindVertexArray(vao->vao);
|
2014-10-14 08:50:44 +00:00
|
|
|
}
|
|
|
|
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
vao->vertexesSize = vertexesSize;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2016-07-25 04:29:13 +00:00
|
|
|
qglGenBuffers(1, &vao->vertexesVBO);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2016-07-25 04:29:13 +00:00
|
|
|
qglBindBuffer(GL_ARRAY_BUFFER, vao->vertexesVBO);
|
|
|
|
qglBufferData(GL_ARRAY_BUFFER, vertexesSize, vertexes, glUsage);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
vao->indexesSize = indexesSize;
|
|
|
|
|
2016-07-25 04:29:13 +00:00
|
|
|
qglGenBuffers(1, &vao->indexesIBO);
|
2014-10-14 08:50:44 +00:00
|
|
|
|
2016-07-25 04:29:13 +00:00
|
|
|
qglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vao->indexesIBO);
|
|
|
|
qglBufferData(GL_ELEMENT_ARRAY_BUFFER, indexesSize, indexes, glUsage);
|
2014-10-14 08:50:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
glState.currentVao = vao;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
GL_CheckErrors();
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
return vao;
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
2014-10-14 08:50:44 +00:00
|
|
|
R_CreateVao2
|
2012-10-26 01:23:06 +00:00
|
|
|
============
|
|
|
|
*/
|
2014-10-14 08:50:44 +00:00
|
|
|
vao_t *R_CreateVao2(const char *name, int numVertexes, srfVert_t *verts, int numIndexes, glIndex_t *indexes)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
vao_t *vao;
|
2012-10-26 01:23:06 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
byte *data;
|
|
|
|
int dataSize;
|
|
|
|
int dataOfs;
|
|
|
|
|
2016-07-25 04:29:13 +00:00
|
|
|
int glUsage = GL_STATIC_DRAW;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
if(!numVertexes || !numIndexes)
|
2012-10-26 01:23:06 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(strlen(name) >= MAX_QPATH)
|
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
ri.Error(ERR_DROP, "R_CreateVao2: \"%s\" is too long", name);
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
if ( tr.numVaos == MAX_VAOS ) {
|
|
|
|
ri.Error( ERR_DROP, "R_CreateVao2: MAX_VAOS hit");
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
2013-01-24 22:53:08 +00:00
|
|
|
R_IssuePendingRenderCommands();
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
vao = tr.vaos[tr.numVaos] = ri.Hunk_Alloc(sizeof(*vao), h_low);
|
|
|
|
tr.numVaos++;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
memset(vao, 0, sizeof(*vao));
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
Q_strncpyz(vao->name, name, sizeof(vao->name));
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 04:57:06 +00:00
|
|
|
// since these vertex attributes are never altered, interleave them
|
2014-10-14 08:50:44 +00:00
|
|
|
vao->attribs[ATTR_INDEX_POSITION ].enabled = 1;
|
|
|
|
vao->attribs[ATTR_INDEX_NORMAL ].enabled = 1;
|
|
|
|
vao->attribs[ATTR_INDEX_TANGENT ].enabled = 1;
|
|
|
|
vao->attribs[ATTR_INDEX_TEXCOORD ].enabled = 1;
|
|
|
|
vao->attribs[ATTR_INDEX_LIGHTCOORD ].enabled = 1;
|
|
|
|
vao->attribs[ATTR_INDEX_COLOR ].enabled = 1;
|
|
|
|
vao->attribs[ATTR_INDEX_LIGHTDIRECTION].enabled = 1;
|
|
|
|
|
|
|
|
vao->attribs[ATTR_INDEX_POSITION ].count = 3;
|
|
|
|
vao->attribs[ATTR_INDEX_NORMAL ].count = 4;
|
|
|
|
vao->attribs[ATTR_INDEX_TANGENT ].count = 4;
|
|
|
|
vao->attribs[ATTR_INDEX_TEXCOORD ].count = 2;
|
|
|
|
vao->attribs[ATTR_INDEX_LIGHTCOORD ].count = 2;
|
|
|
|
vao->attribs[ATTR_INDEX_COLOR ].count = 4;
|
|
|
|
vao->attribs[ATTR_INDEX_LIGHTDIRECTION].count = 4;
|
|
|
|
|
|
|
|
vao->attribs[ATTR_INDEX_POSITION ].type = GL_FLOAT;
|
2016-09-06 07:57:15 +00:00
|
|
|
vao->attribs[ATTR_INDEX_NORMAL ].type = GL_SHORT;
|
|
|
|
vao->attribs[ATTR_INDEX_TANGENT ].type = GL_SHORT;
|
2014-11-04 03:10:35 +00:00
|
|
|
vao->attribs[ATTR_INDEX_TEXCOORD ].type = glRefConfig.packedTexcoordDataType;
|
|
|
|
vao->attribs[ATTR_INDEX_LIGHTCOORD ].type = glRefConfig.packedTexcoordDataType;
|
|
|
|
vao->attribs[ATTR_INDEX_COLOR ].type = glRefConfig.packedColorDataType;
|
2016-09-06 07:57:15 +00:00
|
|
|
vao->attribs[ATTR_INDEX_LIGHTDIRECTION].type = GL_SHORT;
|
2014-10-14 08:50:44 +00:00
|
|
|
|
|
|
|
vao->attribs[ATTR_INDEX_POSITION ].normalized = GL_FALSE;
|
|
|
|
vao->attribs[ATTR_INDEX_NORMAL ].normalized = GL_TRUE;
|
|
|
|
vao->attribs[ATTR_INDEX_TANGENT ].normalized = GL_TRUE;
|
|
|
|
vao->attribs[ATTR_INDEX_TEXCOORD ].normalized = GL_FALSE;
|
|
|
|
vao->attribs[ATTR_INDEX_LIGHTCOORD ].normalized = GL_FALSE;
|
|
|
|
vao->attribs[ATTR_INDEX_COLOR ].normalized = GL_FALSE;
|
|
|
|
vao->attribs[ATTR_INDEX_LIGHTDIRECTION].normalized = GL_TRUE;
|
|
|
|
|
|
|
|
vao->attribs[ATTR_INDEX_POSITION ].offset = 0; dataSize = sizeof(verts[0].xyz);
|
2016-09-06 07:57:15 +00:00
|
|
|
vao->attribs[ATTR_INDEX_NORMAL ].offset = dataSize; dataSize += sizeof(verts[0].normal);
|
|
|
|
vao->attribs[ATTR_INDEX_TANGENT ].offset = dataSize; dataSize += sizeof(verts[0].tangent);
|
2014-11-04 03:10:35 +00:00
|
|
|
vao->attribs[ATTR_INDEX_TEXCOORD ].offset = dataSize; dataSize += glRefConfig.packedTexcoordDataSize;
|
|
|
|
vao->attribs[ATTR_INDEX_LIGHTCOORD ].offset = dataSize; dataSize += glRefConfig.packedTexcoordDataSize;
|
|
|
|
vao->attribs[ATTR_INDEX_COLOR ].offset = dataSize; dataSize += glRefConfig.packedColorDataSize;
|
2016-09-06 07:57:15 +00:00
|
|
|
vao->attribs[ATTR_INDEX_LIGHTDIRECTION].offset = dataSize; dataSize += sizeof(verts[0].lightdir);
|
2014-10-14 08:50:44 +00:00
|
|
|
|
|
|
|
vao->attribs[ATTR_INDEX_POSITION ].stride = dataSize;
|
|
|
|
vao->attribs[ATTR_INDEX_NORMAL ].stride = dataSize;
|
|
|
|
vao->attribs[ATTR_INDEX_TANGENT ].stride = dataSize;
|
|
|
|
vao->attribs[ATTR_INDEX_TEXCOORD ].stride = dataSize;
|
|
|
|
vao->attribs[ATTR_INDEX_LIGHTCOORD ].stride = dataSize;
|
|
|
|
vao->attribs[ATTR_INDEX_COLOR ].stride = dataSize;
|
|
|
|
vao->attribs[ATTR_INDEX_LIGHTDIRECTION].stride = dataSize;
|
|
|
|
|
|
|
|
|
|
|
|
if (glRefConfig.vertexArrayObject)
|
|
|
|
{
|
2016-07-26 07:41:31 +00:00
|
|
|
qglGenVertexArrays(1, &vao->vao);
|
|
|
|
qglBindVertexArray(vao->vao);
|
2014-10-14 08:50:44 +00:00
|
|
|
}
|
|
|
|
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 04:57:06 +00:00
|
|
|
// create VBO
|
|
|
|
dataSize *= numVertexes;
|
|
|
|
data = ri.Hunk_AllocateTempMemory(dataSize);
|
|
|
|
dataOfs = 0;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 04:57:06 +00:00
|
|
|
for (i = 0; i < numVertexes; i++)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
|
|
|
// xyz
|
2014-10-14 04:57:06 +00:00
|
|
|
memcpy(data + dataOfs, &verts[i].xyz, sizeof(verts[i].xyz));
|
|
|
|
dataOfs += sizeof(verts[i].xyz);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
// normal
|
2016-09-06 07:57:15 +00:00
|
|
|
memcpy(data + dataOfs, &verts[i].normal, sizeof(verts[i].normal));
|
|
|
|
dataOfs += sizeof(verts[i].normal);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
// tangent
|
2016-09-06 07:57:15 +00:00
|
|
|
memcpy(data + dataOfs, &verts[i].tangent, sizeof(verts[i].tangent));
|
|
|
|
dataOfs += sizeof(verts[i].tangent);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-11-04 03:10:35 +00:00
|
|
|
// texcoords
|
|
|
|
dataOfs += R_VaoPackTexCoord(data + dataOfs, verts[i].st);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-11-04 03:10:35 +00:00
|
|
|
// lightmap texcoords
|
|
|
|
dataOfs += R_VaoPackTexCoord(data + dataOfs, verts[i].lightmap);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-11-04 03:10:35 +00:00
|
|
|
// colors
|
|
|
|
dataOfs += R_VaoPackColors(data + dataOfs, verts[i].vertexColors);
|
2013-12-10 01:33:54 +00:00
|
|
|
|
2014-11-04 03:10:35 +00:00
|
|
|
// light directions
|
2016-09-06 07:57:15 +00:00
|
|
|
memcpy(data + dataOfs, &verts[i].lightdir, sizeof(verts[i].lightdir));
|
|
|
|
dataOfs += sizeof(verts[i].lightdir);
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
vao->vertexesSize = dataSize;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2016-07-25 04:29:13 +00:00
|
|
|
qglGenBuffers(1, &vao->vertexesVBO);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2016-07-25 04:29:13 +00:00
|
|
|
qglBindBuffer(GL_ARRAY_BUFFER, vao->vertexesVBO);
|
|
|
|
qglBufferData(GL_ARRAY_BUFFER, vao->vertexesSize, data, glUsage);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
// create IBO
|
|
|
|
vao->indexesSize = numIndexes * sizeof(glIndex_t);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2016-07-25 04:29:13 +00:00
|
|
|
qglGenBuffers(1, &vao->indexesIBO);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2016-07-25 04:29:13 +00:00
|
|
|
qglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vao->indexesIBO);
|
|
|
|
qglBufferData(GL_ELEMENT_ARRAY_BUFFER, vao->indexesSize, indexes, glUsage);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
Vao_SetVertexPointers(vao);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
glState.currentVao = vao;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
GL_CheckErrors();
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
ri.Hunk_FreeTempMemory(data);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
return vao;
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
|
2012-10-26 01:23:06 +00:00
|
|
|
/*
|
|
|
|
============
|
2014-10-14 08:50:44 +00:00
|
|
|
R_BindVao
|
2012-10-26 01:23:06 +00:00
|
|
|
============
|
|
|
|
*/
|
2014-10-14 08:50:44 +00:00
|
|
|
void R_BindVao(vao_t * vao)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
if(!vao)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
//R_BindNullVao();
|
|
|
|
ri.Error(ERR_DROP, "R_BindVao: NULL vao");
|
2012-10-26 01:23:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(r_logFile->integer)
|
|
|
|
{
|
|
|
|
// don't just call LogComment, or we will get a call to va() every frame!
|
2014-10-14 08:50:44 +00:00
|
|
|
GLimp_LogComment(va("--- R_BindVao( %s ) ---\n", vao->name));
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
if(glState.currentVao != vao)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
glState.currentVao = vao;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
glState.vertexAttribsInterpolation = 0;
|
2013-10-14 08:55:54 +00:00
|
|
|
glState.vertexAnimation = qfalse;
|
2014-10-14 08:50:44 +00:00
|
|
|
backEnd.pc.c_vaoBinds++;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
if (glRefConfig.vertexArrayObject)
|
|
|
|
{
|
2016-07-26 07:41:31 +00:00
|
|
|
qglBindVertexArray(vao->vao);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
// why you no save GL_ELEMENT_ARRAY_BUFFER binding, Intel?
|
|
|
|
if (1)
|
2016-07-25 04:29:13 +00:00
|
|
|
qglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vao->indexesIBO);
|
2014-10-23 23:51:10 +00:00
|
|
|
|
|
|
|
// tess VAO always has buffers bound
|
|
|
|
if (vao == tess.vao)
|
2016-07-25 04:29:13 +00:00
|
|
|
qglBindBuffer(GL_ARRAY_BUFFER, vao->vertexesVBO);
|
2014-10-14 08:50:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-25 04:29:13 +00:00
|
|
|
qglBindBuffer(GL_ARRAY_BUFFER, vao->vertexesVBO);
|
|
|
|
qglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vao->indexesIBO);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-23 23:51:10 +00:00
|
|
|
// tess VAO doesn't have vertex pointers set until data is uploaded
|
|
|
|
if (vao != tess.vao)
|
|
|
|
Vao_SetVertexPointers(vao);
|
2014-10-14 08:50:44 +00:00
|
|
|
}
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
2014-10-14 08:50:44 +00:00
|
|
|
R_BindNullVao
|
2012-10-26 01:23:06 +00:00
|
|
|
============
|
|
|
|
*/
|
2014-10-14 08:50:44 +00:00
|
|
|
void R_BindNullVao(void)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
GLimp_LogComment("--- R_BindNullVao ---\n");
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
if(glState.currentVao)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
if (glRefConfig.vertexArrayObject)
|
|
|
|
{
|
2016-07-26 07:41:31 +00:00
|
|
|
qglBindVertexArray(0);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
// why you no save GL_ELEMENT_ARRAY_BUFFER binding, Intel?
|
2016-07-25 04:29:13 +00:00
|
|
|
if (1) qglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
2014-10-14 08:50:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-25 04:29:13 +00:00
|
|
|
qglBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
qglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
2014-10-14 08:50:44 +00:00
|
|
|
}
|
|
|
|
glState.currentVao = NULL;
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
GL_CheckErrors();
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
|
2012-10-26 01:23:06 +00:00
|
|
|
/*
|
|
|
|
============
|
2014-10-14 08:50:44 +00:00
|
|
|
R_InitVaos
|
2012-10-26 01:23:06 +00:00
|
|
|
============
|
|
|
|
*/
|
2014-10-14 08:50:44 +00:00
|
|
|
void R_InitVaos(void)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
int vertexesSize, indexesSize;
|
2012-10-26 01:23:06 +00:00
|
|
|
int offset;
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
ri.Printf(PRINT_ALL, "------- R_InitVaos -------\n");
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
tr.numVaos = 0;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
vertexesSize = sizeof(tess.xyz[0]);
|
|
|
|
vertexesSize += sizeof(tess.normal[0]);
|
|
|
|
vertexesSize += sizeof(tess.tangent[0]);
|
|
|
|
vertexesSize += sizeof(tess.vertexColors[0]);
|
|
|
|
vertexesSize += sizeof(tess.texCoords[0][0]) * 2;
|
|
|
|
vertexesSize += sizeof(tess.lightdir[0]);
|
|
|
|
vertexesSize *= SHADER_MAX_VERTEXES;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
indexesSize = sizeof(tess.indexes[0]) * SHADER_MAX_INDEXES;
|
|
|
|
|
|
|
|
tess.vao = R_CreateVao("tessVertexArray_VAO", NULL, vertexesSize, NULL, indexesSize, VAO_USAGE_DYNAMIC);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
tess.vao->attribs[ATTR_INDEX_POSITION ].enabled = 1;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_NORMAL ].enabled = 1;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_TANGENT ].enabled = 1;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_TEXCOORD ].enabled = 1;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_LIGHTCOORD ].enabled = 1;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_COLOR ].enabled = 1;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_LIGHTDIRECTION].enabled = 1;
|
|
|
|
|
|
|
|
tess.vao->attribs[ATTR_INDEX_POSITION ].count = 3;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_NORMAL ].count = 4;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_TANGENT ].count = 4;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_TEXCOORD ].count = 2;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_LIGHTCOORD ].count = 2;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_COLOR ].count = 4;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_LIGHTDIRECTION].count = 4;
|
|
|
|
|
|
|
|
tess.vao->attribs[ATTR_INDEX_POSITION ].type = GL_FLOAT;
|
2016-09-06 07:57:15 +00:00
|
|
|
tess.vao->attribs[ATTR_INDEX_NORMAL ].type = GL_SHORT;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_TANGENT ].type = GL_SHORT;
|
2014-10-14 08:50:44 +00:00
|
|
|
tess.vao->attribs[ATTR_INDEX_TEXCOORD ].type = GL_FLOAT;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_LIGHTCOORD ].type = GL_FLOAT;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_COLOR ].type = GL_FLOAT;
|
2016-09-06 07:57:15 +00:00
|
|
|
tess.vao->attribs[ATTR_INDEX_LIGHTDIRECTION].type = GL_SHORT;
|
2014-10-14 08:50:44 +00:00
|
|
|
|
|
|
|
tess.vao->attribs[ATTR_INDEX_POSITION ].normalized = GL_FALSE;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_NORMAL ].normalized = GL_TRUE;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_TANGENT ].normalized = GL_TRUE;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_TEXCOORD ].normalized = GL_FALSE;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_LIGHTCOORD ].normalized = GL_FALSE;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_COLOR ].normalized = GL_FALSE;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_LIGHTDIRECTION].normalized = GL_TRUE;
|
|
|
|
|
|
|
|
tess.vao->attribs[ATTR_INDEX_POSITION ].offset = offset; offset += sizeof(tess.xyz[0]) * SHADER_MAX_VERTEXES;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_NORMAL ].offset = offset; offset += sizeof(tess.normal[0]) * SHADER_MAX_VERTEXES;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_TANGENT ].offset = offset; offset += sizeof(tess.tangent[0]) * SHADER_MAX_VERTEXES;
|
2012-10-26 01:23:06 +00:00
|
|
|
// these next two are actually interleaved
|
2014-10-14 08:50:44 +00:00
|
|
|
tess.vao->attribs[ATTR_INDEX_TEXCOORD ].offset = offset;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_LIGHTCOORD ].offset = offset + sizeof(tess.texCoords[0][0]);
|
2014-10-14 04:57:06 +00:00
|
|
|
offset += sizeof(tess.texCoords[0][0]) * 2 * SHADER_MAX_VERTEXES;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
tess.vao->attribs[ATTR_INDEX_COLOR ].offset = offset; offset += sizeof(tess.vertexColors[0]) * SHADER_MAX_VERTEXES;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_LIGHTDIRECTION].offset = offset;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
tess.vao->attribs[ATTR_INDEX_POSITION ].stride = sizeof(tess.xyz[0]);
|
|
|
|
tess.vao->attribs[ATTR_INDEX_NORMAL ].stride = sizeof(tess.normal[0]);
|
|
|
|
tess.vao->attribs[ATTR_INDEX_TANGENT ].stride = sizeof(tess.tangent[0]);
|
|
|
|
tess.vao->attribs[ATTR_INDEX_COLOR ].stride = sizeof(tess.vertexColors[0]);
|
|
|
|
tess.vao->attribs[ATTR_INDEX_TEXCOORD ].stride = sizeof(tess.texCoords[0][0]) * 2;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_LIGHTCOORD ].stride = sizeof(tess.texCoords[0][0]) * 2;
|
|
|
|
tess.vao->attribs[ATTR_INDEX_LIGHTDIRECTION].stride = sizeof(tess.lightdir[0]);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 04:57:06 +00:00
|
|
|
tess.attribPointers[ATTR_INDEX_POSITION] = tess.xyz;
|
|
|
|
tess.attribPointers[ATTR_INDEX_TEXCOORD] = tess.texCoords;
|
|
|
|
tess.attribPointers[ATTR_INDEX_NORMAL] = tess.normal;
|
|
|
|
tess.attribPointers[ATTR_INDEX_TANGENT] = tess.tangent;
|
|
|
|
tess.attribPointers[ATTR_INDEX_COLOR] = tess.vertexColors;
|
|
|
|
tess.attribPointers[ATTR_INDEX_LIGHTDIRECTION] = tess.lightdir;
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
Vao_SetVertexPointers(tess.vao);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
R_BindNullVao();
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
GL_CheckErrors();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
2014-10-14 08:50:44 +00:00
|
|
|
R_ShutdownVaos
|
2012-10-26 01:23:06 +00:00
|
|
|
============
|
|
|
|
*/
|
2014-10-14 08:50:44 +00:00
|
|
|
void R_ShutdownVaos(void)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
|
|
|
int i;
|
2014-10-14 08:50:44 +00:00
|
|
|
vao_t *vao;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
ri.Printf(PRINT_ALL, "------- R_ShutdownVaos -------\n");
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
R_BindNullVao();
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
for(i = 0; i < tr.numVaos; i++)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
vao = tr.vaos[i];
|
|
|
|
|
|
|
|
if(vao->vao)
|
2016-07-26 07:41:31 +00:00
|
|
|
qglDeleteVertexArrays(1, &vao->vao);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
if(vao->vertexesVBO)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2016-07-25 04:29:13 +00:00
|
|
|
qglDeleteBuffers(1, &vao->vertexesVBO);
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
if(vao->indexesIBO)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2016-07-25 04:29:13 +00:00
|
|
|
qglDeleteBuffers(1, &vao->indexesIBO);
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
tr.numVaos = 0;
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
2014-10-14 08:50:44 +00:00
|
|
|
R_VaoList_f
|
2012-10-26 01:23:06 +00:00
|
|
|
============
|
|
|
|
*/
|
2014-10-14 08:50:44 +00:00
|
|
|
void R_VaoList_f(void)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
|
|
|
int i;
|
2014-10-14 08:50:44 +00:00
|
|
|
vao_t *vao;
|
2012-10-26 01:23:06 +00:00
|
|
|
int vertexesSize = 0;
|
|
|
|
int indexesSize = 0;
|
|
|
|
|
|
|
|
ri.Printf(PRINT_ALL, " size name\n");
|
|
|
|
ri.Printf(PRINT_ALL, "----------------------------------------------------------\n");
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
for(i = 0; i < tr.numVaos; i++)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
vao = tr.vaos[i];
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
ri.Printf(PRINT_ALL, "%d.%02d MB %s\n", vao->vertexesSize / (1024 * 1024),
|
|
|
|
(vao->vertexesSize % (1024 * 1024)) * 100 / (1024 * 1024), vao->name);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
vertexesSize += vao->vertexesSize;
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
for(i = 0; i < tr.numVaos; i++)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
vao = tr.vaos[i];
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
ri.Printf(PRINT_ALL, "%d.%02d MB %s\n", vao->indexesSize / (1024 * 1024),
|
|
|
|
(vao->indexesSize % (1024 * 1024)) * 100 / (1024 * 1024), vao->name);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
indexesSize += vao->indexesSize;
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
ri.Printf(PRINT_ALL, " %i total VAOs\n", tr.numVaos);
|
2012-10-26 01:23:06 +00:00
|
|
|
ri.Printf(PRINT_ALL, " %d.%02d MB total vertices memory\n", vertexesSize / (1024 * 1024),
|
|
|
|
(vertexesSize % (1024 * 1024)) * 100 / (1024 * 1024));
|
|
|
|
ri.Printf(PRINT_ALL, " %d.%02d MB total triangle indices memory\n", indexesSize / (1024 * 1024),
|
|
|
|
(indexesSize % (1024 * 1024)) * 100 / (1024 * 1024));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
2014-10-14 08:50:44 +00:00
|
|
|
RB_UpdateTessVao
|
2012-10-26 01:23:06 +00:00
|
|
|
|
|
|
|
Adapted from Tess_UpdateVBOs from xreal
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
Update the default VAO to replace the client side vertex arrays
|
2012-10-26 01:23:06 +00:00
|
|
|
==============
|
|
|
|
*/
|
2014-10-14 08:50:44 +00:00
|
|
|
void RB_UpdateTessVao(unsigned int attribBits)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
GLimp_LogComment("--- RB_UpdateTessVao ---\n");
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
backEnd.pc.c_dynamicVaoDraws++;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
// update the default VAO
|
|
|
|
if(tess.numVertexes > 0 && tess.numVertexes <= SHADER_MAX_VERTEXES && tess.numIndexes > 0 && tess.numIndexes <= SHADER_MAX_INDEXES)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 04:57:06 +00:00
|
|
|
int attribIndex;
|
2014-10-29 01:15:13 +00:00
|
|
|
int attribUpload;
|
2014-10-14 04:57:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
R_BindVao(tess.vao);
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
// orphan old vertex buffer so we don't stall on it
|
2016-07-25 04:29:13 +00:00
|
|
|
qglBufferData(GL_ARRAY_BUFFER, tess.vao->vertexesSize, NULL, GL_DYNAMIC_DRAW);
|
2013-10-14 08:55:54 +00:00
|
|
|
|
2014-10-14 04:57:06 +00:00
|
|
|
// if nothing to set, set everything
|
|
|
|
if(!(attribBits & ATTR_BITS))
|
|
|
|
attribBits = ATTR_BITS;
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-29 01:15:13 +00:00
|
|
|
attribUpload = attribBits;
|
|
|
|
|
|
|
|
if((attribUpload & ATTR_TEXCOORD) || (attribUpload & ATTR_LIGHTCOORD))
|
2014-10-14 04:57:06 +00:00
|
|
|
{
|
|
|
|
// these are interleaved, so we update both if either need it
|
|
|
|
// this translates to updating ATTR_TEXCOORD twice as large as it needs
|
2014-10-29 01:15:13 +00:00
|
|
|
attribUpload &= ~ATTR_LIGHTCOORD;
|
|
|
|
attribUpload |= ATTR_TEXCOORD;
|
2014-10-14 04:57:06 +00:00
|
|
|
}
|
2012-10-26 01:23:06 +00:00
|
|
|
|
2014-10-14 04:57:06 +00:00
|
|
|
for (attribIndex = 0; attribIndex < ATTR_INDEX_COUNT; attribIndex++)
|
|
|
|
{
|
2014-10-23 23:51:10 +00:00
|
|
|
uint32_t attribBit = 1 << attribIndex;
|
2014-10-29 01:15:13 +00:00
|
|
|
vaoAttrib_t *vAtb = &tess.vao->attribs[attribIndex];
|
2014-10-23 23:51:10 +00:00
|
|
|
|
2014-10-29 01:15:13 +00:00
|
|
|
if (attribUpload & attribBit)
|
2012-10-26 01:23:06 +00:00
|
|
|
{
|
2014-10-14 08:50:44 +00:00
|
|
|
// note: tess has a VBO where stride == size
|
2016-07-25 04:29:13 +00:00
|
|
|
qglBufferSubData(GL_ARRAY_BUFFER, vAtb->offset, tess.numVertexes * vAtb->stride, tess.attribPointers[attribIndex]);
|
2014-10-29 01:15:13 +00:00
|
|
|
}
|
2014-10-23 23:51:10 +00:00
|
|
|
|
2014-10-29 01:15:13 +00:00
|
|
|
if (attribBits & attribBit)
|
|
|
|
{
|
2014-10-23 23:51:10 +00:00
|
|
|
if (!glRefConfig.vertexArrayObject)
|
2016-07-25 04:29:13 +00:00
|
|
|
qglVertexAttribPointer(attribIndex, vAtb->count, vAtb->type, vAtb->normalized, vAtb->stride, BUFFER_OFFSET(vAtb->offset));
|
2014-10-23 23:51:10 +00:00
|
|
|
|
|
|
|
if (!(glState.vertexAttribsEnabled & attribBit))
|
|
|
|
{
|
2016-07-25 04:29:13 +00:00
|
|
|
qglEnableVertexAttribArray(attribIndex);
|
2014-10-23 23:51:10 +00:00
|
|
|
glState.vertexAttribsEnabled |= attribBit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((glState.vertexAttribsEnabled & attribBit))
|
|
|
|
{
|
2016-07-25 04:29:13 +00:00
|
|
|
qglDisableVertexAttribArray(attribIndex);
|
2014-10-23 23:51:10 +00:00
|
|
|
glState.vertexAttribsEnabled &= ~attribBit;
|
|
|
|
}
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 08:50:44 +00:00
|
|
|
// orphan old index buffer so we don't stall on it
|
2016-07-25 04:29:13 +00:00
|
|
|
qglBufferData(GL_ELEMENT_ARRAY_BUFFER, tess.vao->indexesSize, NULL, GL_DYNAMIC_DRAW);
|
2013-10-14 08:55:54 +00:00
|
|
|
|
2016-07-25 04:29:13 +00:00
|
|
|
qglBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, tess.numIndexes * sizeof(tess.indexes[0]), tess.indexes);
|
2012-10-26 01:23:06 +00:00
|
|
|
}
|
|
|
|
}
|