summaryrefslogtreecommitdiff
path: root/src/renderergl2/tr_model.c
diff options
context:
space:
mode:
authorSmileTheory <SmileTheory@gmail.com>2014-11-03 19:10:35 -0800
committerTim Angus <tim@ngus.net>2015-03-17 11:38:54 +0000
commitf2cd353409185a408d175367ff1bc81a9c74a8ed (patch)
treed4a94ba395715f53ca7ee8e7989041c2fdc5736c /src/renderergl2/tr_model.c
parentf3fe657d5e529f9f5235823d7b356d5a55aa04b3 (diff)
OpenGL2: Support half floats for texcoords and vertex colors.
Diffstat (limited to 'src/renderergl2/tr_model.c')
-rw-r--r--src/renderergl2/tr_model.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/src/renderergl2/tr_model.c b/src/renderergl2/tr_model.c
index b14ce534..bd6a6d21 100644
--- a/src/renderergl2/tr_model.c
+++ b/src/renderergl2/tr_model.c
@@ -675,10 +675,10 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize,
{
// vertex animation, store texcoords first, then position/normal/tangents
offset_st = 0;
- offset_xyz = surf->numVerts * sizeof(vec2_t);
+ offset_xyz = surf->numVerts * glRefConfig.packedTexcoordDataSize;
offset_normal = offset_xyz + sizeof(vec3_t);
offset_tangent = offset_normal + sizeof(uint32_t);
- stride_st = sizeof(vec2_t);
+ stride_st = glRefConfig.packedTexcoordDataSize;
stride_xyz = sizeof(vec3_t) + sizeof(uint32_t);
#ifdef USE_VERT_TANGENT_SPACE
stride_xyz += sizeof(uint32_t);
@@ -692,7 +692,7 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize,
// no animation, interleave everything
offset_xyz = 0;
offset_st = offset_xyz + sizeof(vec3_t);
- offset_normal = offset_st + sizeof(vec2_t);
+ offset_normal = offset_st + glRefConfig.packedTexcoordDataSize;
offset_tangent = offset_normal + sizeof(uint32_t);
#ifdef USE_VERT_TANGENT_SPACE
stride_xyz = offset_tangent + sizeof(uint32_t);
@@ -712,8 +712,7 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize,
{
st = surf->st;
for ( j = 0 ; j < surf->numVerts ; j++, st++ ) {
- memcpy(data + dataOfs, &st->st, sizeof(vec2_t));
- dataOfs += sizeof(vec2_t);
+ dataOfs += R_VaoPackTexCoord(data + dataOfs, st->st);
}
v = surf->verts;
@@ -723,16 +722,12 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize,
vec3_t nxt;
vec4_t tangent;
#endif
- uint32_t *p;
-
// xyz
memcpy(data + dataOfs, &v->xyz, sizeof(vec3_t));
dataOfs += sizeof(vec3_t);
// normal
- p = (uint32_t *)(data + dataOfs);
- *p = R_VaoPackNormal(v->normal);
- dataOfs += sizeof(uint32_t);
+ dataOfs += R_VaoPackNormal(data + dataOfs, v->normal);
#ifdef USE_VERT_TANGENT_SPACE
CrossProduct(v->normal, v->tangent, nxt);
@@ -740,9 +735,7 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize,
tangent[3] = (DotProduct(nxt, v->bitangent) < 0.0f) ? -1.0f : 1.0f;
// tangent
- p = (uint32_t *)(data + dataOfs);
- *p = R_VaoPackTangent(tangent);
- dataOfs += sizeof(uint32_t);
+ dataOfs += R_VaoPackTangent(data + dataOfs, tangent);
#endif
}
}
@@ -756,20 +749,15 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize,
vec3_t nxt;
vec4_t tangent;
#endif
- uint32_t *p;
-
// xyz
memcpy(data + dataOfs, &v->xyz, sizeof(vec3_t));
dataOfs += sizeof(v->xyz);
// st
- memcpy(data + dataOfs, &st->st, sizeof(vec2_t));
- dataOfs += sizeof(st->st);
+ dataOfs += R_VaoPackTexCoord(data + dataOfs, st->st);
// normal
- p = (uint32_t *)(data + dataOfs);
- *p = R_VaoPackNormal(v->normal);
- dataOfs += sizeof(uint32_t);
+ dataOfs += R_VaoPackNormal(data + dataOfs, v->normal);
#ifdef USE_VERT_TANGENT_SPACE
CrossProduct(v->normal, v->tangent, nxt);
@@ -777,9 +765,7 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize,
tangent[3] = (DotProduct(nxt, v->bitangent) < 0.0f) ? -1.0f : 1.0f;
// tangent
- p = (uint32_t *)(data + dataOfs);
- *p = R_VaoPackTangent(tangent);
- dataOfs += sizeof(uint32_t);
+ dataOfs += R_VaoPackTangent(data + dataOfs, tangent);
#endif
}
}
@@ -808,7 +794,7 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize,
vaoSurf->vao->attribs[ATTR_INDEX_TANGENT ].count = 4;
vaoSurf->vao->attribs[ATTR_INDEX_POSITION].type = GL_FLOAT;
- vaoSurf->vao->attribs[ATTR_INDEX_TEXCOORD].type = GL_FLOAT;
+ vaoSurf->vao->attribs[ATTR_INDEX_TEXCOORD].type = glRefConfig.packedTexcoordDataType;
vaoSurf->vao->attribs[ATTR_INDEX_NORMAL ].type = glRefConfig.packedNormalDataType;
vaoSurf->vao->attribs[ATTR_INDEX_TANGENT ].type = glRefConfig.packedNormalDataType;