mirror of
https://github.com/UberGames/ioef.git
synced 2024-11-27 14:32:55 +00:00
OpenGL2: Support half floats for texcoords and vertex colors.
This commit is contained in:
parent
1ba9e7a45e
commit
943259f6b4
10 changed files with 193 additions and 154 deletions
|
@ -412,7 +412,7 @@ void RB_MDRSurfaceAnim( mdrSurface_t *surface )
|
|||
tess.xyz[baseVertex + j][1] = tempVert[1];
|
||||
tess.xyz[baseVertex + j][2] = tempVert[2];
|
||||
|
||||
tess.normal[baseVertex + j] = R_VaoPackNormal(tempNormal);
|
||||
R_VaoPackNormal((byte *)&tess.normal[baseVertex + j], tempNormal);
|
||||
|
||||
tess.texCoords[baseVertex + j][0][0] = v->texCoords[0];
|
||||
tess.texCoords[baseVertex + j][0][1] = v->texCoords[1];
|
||||
|
|
|
@ -709,4 +709,27 @@ void GLimp_InitExtraExtensions()
|
|||
ri.Printf(PRINT_ALL, result[2], extension);
|
||||
}
|
||||
|
||||
// GL_ARB_half_float_vertex
|
||||
extension = "GL_ARB_half_float_vertex";
|
||||
glRefConfig.packedTexcoordDataType = GL_FLOAT;
|
||||
glRefConfig.packedTexcoordDataSize = sizeof(float) * 2;
|
||||
glRefConfig.packedColorDataType = GL_FLOAT;
|
||||
glRefConfig.packedColorDataSize = sizeof(float) * 4;
|
||||
if( GLimp_HaveExtension( extension ) )
|
||||
{
|
||||
if (r_arb_half_float_vertex->integer)
|
||||
{
|
||||
glRefConfig.packedTexcoordDataType = GL_HALF_FLOAT;
|
||||
glRefConfig.packedTexcoordDataSize = sizeof(uint16_t) * 2;
|
||||
glRefConfig.packedColorDataType = GL_HALF_FLOAT;
|
||||
glRefConfig.packedColorDataSize = sizeof(uint16_t) * 4;
|
||||
}
|
||||
|
||||
ri.Printf(PRINT_ALL, result[r_arb_half_float_vertex->integer ? 1 : 0], extension);
|
||||
}
|
||||
else
|
||||
{
|
||||
ri.Printf(PRINT_ALL, result[2], extension);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -199,42 +199,35 @@ int NextPowerOfTwo(int in)
|
|||
return out;
|
||||
}
|
||||
|
||||
unsigned short FloatToHalf(float in)
|
||||
union f32_u {
|
||||
float f;
|
||||
uint32_t i;
|
||||
struct {
|
||||
unsigned int fraction:23;
|
||||
unsigned int exponent:8;
|
||||
unsigned int sign:1;
|
||||
} pack;
|
||||
};
|
||||
|
||||
union f16_u {
|
||||
uint16_t i;
|
||||
struct {
|
||||
unsigned int fraction:10;
|
||||
unsigned int exponent:5;
|
||||
unsigned int sign:1;
|
||||
} pack;
|
||||
};
|
||||
|
||||
uint16_t FloatToHalf(float in)
|
||||
{
|
||||
unsigned short out;
|
||||
|
||||
union
|
||||
{
|
||||
float f;
|
||||
unsigned int i;
|
||||
} f32;
|
||||
|
||||
int sign, inExponent, inFraction;
|
||||
int outExponent, outFraction;
|
||||
union f32_u f32;
|
||||
union f16_u f16;
|
||||
|
||||
f32.f = in;
|
||||
|
||||
sign = (f32.i & 0x80000000) >> 31;
|
||||
inExponent = (f32.i & 0x7F800000) >> 23;
|
||||
inFraction = f32.i & 0x007FFFFF;
|
||||
f16.pack.exponent = CLAMP(f32.pack.exponent - 112, 0, 31);
|
||||
f16.pack.fraction = f32.pack.fraction >> 13;
|
||||
f16.pack.sign = f32.pack.sign;
|
||||
|
||||
outExponent = CLAMP(inExponent - 127, -15, 16) + 15;
|
||||
|
||||
outFraction = 0;
|
||||
if (outExponent == 0x1F)
|
||||
{
|
||||
if (inExponent == 0xFF && inFraction != 0)
|
||||
outFraction = 0x3FF;
|
||||
}
|
||||
else if (outExponent == 0x00)
|
||||
{
|
||||
if (inExponent == 0x00 && inFraction != 0)
|
||||
outFraction = 0x3FF;
|
||||
}
|
||||
else
|
||||
outFraction = inFraction >> 13;
|
||||
|
||||
out = (sign << 15) | (outExponent << 10) | outFraction;
|
||||
|
||||
return out;
|
||||
return f16.i;
|
||||
}
|
||||
|
|
|
@ -101,6 +101,7 @@ cvar_t *r_ext_multi_draw_arrays;
|
|||
cvar_t *r_ext_framebuffer_object;
|
||||
cvar_t *r_ext_texture_float;
|
||||
cvar_t *r_arb_half_float_pixel;
|
||||
cvar_t *r_arb_half_float_vertex;
|
||||
cvar_t *r_ext_framebuffer_multisample;
|
||||
cvar_t *r_arb_seamless_cube_map;
|
||||
cvar_t *r_arb_vertex_type_2_10_10_10_rev;
|
||||
|
@ -1141,6 +1142,7 @@ void R_Register( void )
|
|||
r_ext_framebuffer_object = ri.Cvar_Get( "r_ext_framebuffer_object", "1", CVAR_ARCHIVE | CVAR_LATCH);
|
||||
r_ext_texture_float = ri.Cvar_Get( "r_ext_texture_float", "1", CVAR_ARCHIVE | CVAR_LATCH);
|
||||
r_arb_half_float_pixel = ri.Cvar_Get( "r_arb_half_float_pixel", "1", CVAR_ARCHIVE | CVAR_LATCH);
|
||||
r_arb_half_float_vertex = ri.Cvar_Get( "r_arb_half_float_vertex", "1", CVAR_ARCHIVE | CVAR_LATCH);
|
||||
r_ext_framebuffer_multisample = ri.Cvar_Get( "r_ext_framebuffer_multisample", "0", CVAR_ARCHIVE | CVAR_LATCH);
|
||||
r_arb_seamless_cube_map = ri.Cvar_Get( "r_arb_seamless_cube_map", "0", CVAR_ARCHIVE | CVAR_LATCH);
|
||||
r_arb_vertex_type_2_10_10_10_rev = ri.Cvar_Get( "r_arb_vertex_type_2_10_10_10_rev", "1", CVAR_ARCHIVE | CVAR_LATCH);
|
||||
|
|
|
@ -1416,6 +1416,10 @@ typedef struct {
|
|||
qboolean seamlessCubeMap;
|
||||
|
||||
GLenum packedNormalDataType;
|
||||
GLenum packedTexcoordDataType;
|
||||
GLenum packedColorDataType;
|
||||
int packedTexcoordDataSize;
|
||||
int packedColorDataSize;
|
||||
|
||||
qboolean floatLightmap;
|
||||
qboolean vertexArrayObject;
|
||||
|
@ -1713,6 +1717,7 @@ extern cvar_t *r_ext_multi_draw_arrays;
|
|||
extern cvar_t *r_ext_framebuffer_object;
|
||||
extern cvar_t *r_ext_texture_float;
|
||||
extern cvar_t *r_arb_half_float_pixel;
|
||||
extern cvar_t *r_arb_half_float_vertex;
|
||||
extern cvar_t *r_ext_framebuffer_multisample;
|
||||
extern cvar_t *r_arb_seamless_cube_map;
|
||||
extern cvar_t *r_arb_vertex_type_2_10_10_10_rev;
|
||||
|
@ -2180,8 +2185,10 @@ VERTEX BUFFER OBJECTS
|
|||
============================================================
|
||||
*/
|
||||
|
||||
uint32_t R_VaoPackTangent(vec4_t v);
|
||||
uint32_t R_VaoPackNormal(vec3_t v);
|
||||
int R_VaoPackTangent(byte *out, vec4_t v);
|
||||
int R_VaoPackNormal(byte *out, vec3_t v);
|
||||
int R_VaoPackTexCoord(byte *out, vec2_t st);
|
||||
int R_VaoPackColors(byte *out, vec4_t color);
|
||||
void R_VaoUnpackTangent(vec4_t v, uint32_t b);
|
||||
void R_VaoUnpackNormal(vec3_t v, uint32_t b);
|
||||
|
||||
|
|
|
@ -674,10 +674,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);
|
||||
|
@ -691,7 +691,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);
|
||||
|
@ -711,8 +711,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;
|
||||
|
@ -722,16 +721,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);
|
||||
|
@ -739,9 +734,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
|
||||
}
|
||||
}
|
||||
|
@ -755,20 +748,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);
|
||||
|
@ -776,9 +764,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
|
||||
}
|
||||
}
|
||||
|
@ -807,7 +793,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;
|
||||
|
||||
|
|
|
@ -1130,7 +1130,7 @@ void RB_IQMSurfaceAnim( surfaceType_t *surface ) {
|
|||
normal[1] = DotProduct(&nrmMat[3], &data->normals[3*vtx]);
|
||||
normal[2] = DotProduct(&nrmMat[6], &data->normals[3*vtx]);
|
||||
|
||||
*outNormal = R_VaoPackNormal(normal);
|
||||
R_VaoPackNormal((byte *)outNormal++, normal);
|
||||
|
||||
#ifdef USE_VERT_TANGENT_SPACE
|
||||
tangent[0] = DotProduct(&nrmMat[0], &data->tangents[4*vtx]);
|
||||
|
@ -1138,7 +1138,7 @@ void RB_IQMSurfaceAnim( surfaceType_t *surface ) {
|
|||
tangent[2] = DotProduct(&nrmMat[6], &data->tangents[4*vtx]);
|
||||
tangent[3] = data->tangents[4*vtx+3];
|
||||
|
||||
*outTangent++ = R_VaoPackTangent(tangent);
|
||||
R_VaoPackTangent((byte *)outTangent++, tangent);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ void RB_CalcDeformNormals( deformStage_t *ds ) {
|
|||
|
||||
VectorNormalizeFast( fNormal );
|
||||
|
||||
*normal = R_VaoPackNormal(fNormal);
|
||||
R_VaoPackNormal((byte *)normal, fNormal);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,7 @@ RB_AddQuadStampExt
|
|||
*/
|
||||
void RB_AddQuadStampExt( vec3_t origin, vec3_t left, vec3_t up, float color[4], float s1, float t1, float s2, float t2 ) {
|
||||
vec3_t normal;
|
||||
uint32_t pNormal;
|
||||
int ndx;
|
||||
|
||||
RB_CHECKOVERFLOW( 4, 6 );
|
||||
|
@ -123,10 +124,11 @@ void RB_AddQuadStampExt( vec3_t origin, vec3_t left, vec3_t up, float color[4],
|
|||
// constant normal all the way around
|
||||
VectorSubtract( vec3_origin, backEnd.viewParms.or.axis[0], normal );
|
||||
|
||||
R_VaoPackNormal((byte *)&pNormal, normal);
|
||||
tess.normal[ndx] =
|
||||
tess.normal[ndx+1] =
|
||||
tess.normal[ndx+2] =
|
||||
tess.normal[ndx+3] = R_VaoPackNormal(normal);
|
||||
tess.normal[ndx+3] = pNormal;
|
||||
|
||||
// standard square texture coordinates
|
||||
VectorSet2(tess.texCoords[ndx ][0], s1, t1);
|
||||
|
@ -346,7 +348,7 @@ static void RB_SurfaceVertsAndIndexes( int numVerts, srfVert_t *verts, int numIn
|
|||
dv = verts;
|
||||
normal = &tess.normal[ tess.numVertexes ];
|
||||
for ( i = 0 ; i < numVerts ; i++, dv++, normal++ )
|
||||
*normal = R_VaoPackNormal(dv->normal);
|
||||
R_VaoPackNormal((byte *)normal, dv->normal);
|
||||
}
|
||||
|
||||
#ifdef USE_VERT_TANGENT_SPACE
|
||||
|
@ -355,7 +357,7 @@ static void RB_SurfaceVertsAndIndexes( int numVerts, srfVert_t *verts, int numIn
|
|||
dv = verts;
|
||||
tangent = &tess.tangent[ tess.numVertexes ];
|
||||
for ( i = 0 ; i < numVerts ; i++, dv++, tangent++ )
|
||||
*tangent = R_VaoPackTangent(dv->tangent);
|
||||
R_VaoPackTangent((byte *)tangent, dv->tangent);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -388,7 +390,7 @@ static void RB_SurfaceVertsAndIndexes( int numVerts, srfVert_t *verts, int numIn
|
|||
dv = verts;
|
||||
lightdir = &tess.lightdir[ tess.numVertexes ];
|
||||
for ( i = 0 ; i < numVerts ; i++, dv++, lightdir++ )
|
||||
*lightdir = R_VaoPackNormal(dv->lightdir);
|
||||
R_VaoPackNormal((byte *)lightdir, dv->lightdir);
|
||||
}
|
||||
|
||||
#if 0 // nothing even uses vertex dlightbits
|
||||
|
@ -1147,7 +1149,7 @@ static void LerpMeshVertexes_scalar(mdvSurface_t *surf, float backlerp)
|
|||
VectorCopy(newVerts->xyz, outXyz);
|
||||
VectorCopy(newVerts->normal, normal);
|
||||
|
||||
*outNormal = R_VaoPackNormal(normal);
|
||||
R_VaoPackNormal((byte *)outNormal, normal);
|
||||
|
||||
newVerts++;
|
||||
outXyz += 4;
|
||||
|
@ -1172,7 +1174,7 @@ static void LerpMeshVertexes_scalar(mdvSurface_t *surf, float backlerp)
|
|||
VectorLerp(newVerts->normal, oldVerts->normal, backlerp, normal);
|
||||
VectorNormalize(normal);
|
||||
|
||||
*outNormal = R_VaoPackNormal(normal);
|
||||
R_VaoPackNormal((byte *)outNormal, normal);
|
||||
|
||||
newVerts++;
|
||||
oldVerts++;
|
||||
|
@ -1410,13 +1412,13 @@ static void RB_SurfaceGrid( srfBspSurface_t *srf ) {
|
|||
|
||||
if ( tess.shader->vertexAttribs & ATTR_NORMAL )
|
||||
{
|
||||
*normal++ = R_VaoPackNormal(dv->normal);
|
||||
R_VaoPackNormal((byte *)normal++, dv->normal);
|
||||
}
|
||||
|
||||
#ifdef USE_VERT_TANGENT_SPACE
|
||||
if ( tess.shader->vertexAttribs & ATTR_TANGENT )
|
||||
{
|
||||
*tangent++ = R_VaoPackTangent(dv->tangent);
|
||||
R_VaoPackTangent((byte *)tangent++, dv->tangent);
|
||||
}
|
||||
#endif
|
||||
if ( tess.shader->vertexAttribs & ATTR_TEXCOORD )
|
||||
|
@ -1439,7 +1441,7 @@ static void RB_SurfaceGrid( srfBspSurface_t *srf ) {
|
|||
|
||||
if ( tess.shader->vertexAttribs & ATTR_LIGHTDIRECTION )
|
||||
{
|
||||
*lightdir++ = R_VaoPackNormal(dv->lightdir);
|
||||
R_VaoPackNormal((byte *)lightdir++, dv->lightdir);
|
||||
}
|
||||
|
||||
//*vDlightBits++ = dlightBits;
|
||||
|
|
|
@ -44,81 +44,122 @@ union pack8_u {
|
|||
};
|
||||
|
||||
|
||||
uint32_t R_VaoPackTangent(vec4_t v)
|
||||
int R_VaoPackTangent(byte *out, vec4_t v)
|
||||
{
|
||||
if (glRefConfig.packedNormalDataType == GL_INT_2_10_10_10_REV)
|
||||
{
|
||||
union pack10_u num;
|
||||
union pack10_u *num = (union pack10_u *)out;
|
||||
|
||||
num.pack.x = v[0] * 511.0f;
|
||||
num.pack.y = v[1] * 511.0f;
|
||||
num.pack.z = v[2] * 511.0f;
|
||||
num.pack.w = v[3];
|
||||
|
||||
return num.i;
|
||||
num->pack.x = v[0] * 511.0f;
|
||||
num->pack.y = v[1] * 511.0f;
|
||||
num->pack.z = v[2] * 511.0f;
|
||||
num->pack.w = v[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
union pack8_u num;
|
||||
union pack8_u *num = (union pack8_u *)out;
|
||||
|
||||
num.pack.x = v[0] * 127.0f;
|
||||
num.pack.y = v[1] * 127.0f;
|
||||
num.pack.z = v[2] * 127.0f;
|
||||
num.pack.w = v[3] * 127.0f;
|
||||
|
||||
return num.i;
|
||||
num->pack.x = v[0] * 127.0f;
|
||||
num->pack.y = v[1] * 127.0f;
|
||||
num->pack.z = v[2] * 127.0f;
|
||||
num->pack.w = v[3] * 127.0f;
|
||||
}
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
||||
uint32_t R_VaoPackNormal(vec3_t v)
|
||||
int R_VaoPackNormal(byte *out, vec3_t v)
|
||||
{
|
||||
if (glRefConfig.packedNormalDataType == GL_INT_2_10_10_10_REV)
|
||||
{
|
||||
union pack10_u num;
|
||||
union pack10_u *num = (union pack10_u *)out;
|
||||
|
||||
num.pack.x = v[0] * 511.0f;
|
||||
num.pack.y = v[1] * 511.0f;
|
||||
num.pack.z = v[2] * 511.0f;
|
||||
num.pack.w = 0;
|
||||
|
||||
return num.i;
|
||||
num->pack.x = v[0] * 511.0f;
|
||||
num->pack.y = v[1] * 511.0f;
|
||||
num->pack.z = v[2] * 511.0f;
|
||||
num->pack.w = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
union pack8_u num;
|
||||
union pack8_u *num = (union pack8_u *)out;
|
||||
|
||||
num.pack.x = v[0] * 127.0f;
|
||||
num.pack.y = v[1] * 127.0f;
|
||||
num.pack.z = v[2] * 127.0f;
|
||||
num.pack.w = 0;
|
||||
num->pack.x = v[0] * 127.0f;
|
||||
num->pack.y = v[1] * 127.0f;
|
||||
num->pack.z = v[2] * 127.0f;
|
||||
num->pack.w = 0;
|
||||
}
|
||||
|
||||
return num.i;
|
||||
return 4;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
float *num = (float *)out;
|
||||
|
||||
*num++ = st[0];
|
||||
*num++ = st[1];
|
||||
|
||||
return sizeof(*num) * 2;
|
||||
}
|
||||
}
|
||||
|
||||
int R_VaoPackColors(byte *out, vec4_t color)
|
||||
{
|
||||
if (glRefConfig.packedTexcoordDataType == GL_HALF_FLOAT)
|
||||
{
|
||||
uint16_t *num = (uint16_t *)out;
|
||||
|
||||
*num++ = FloatToHalf(color[0]);
|
||||
*num++ = FloatToHalf(color[1]);
|
||||
*num++ = FloatToHalf(color[2]);
|
||||
*num++ = FloatToHalf(color[3]);
|
||||
|
||||
return sizeof(*num) * 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
float *num = (float *)out;
|
||||
|
||||
*num++ = color[0];
|
||||
*num++ = color[1];
|
||||
*num++ = color[2];
|
||||
*num++ = color[3];
|
||||
|
||||
return sizeof(*num) * 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void R_VaoUnpackTangent(vec4_t v, uint32_t b)
|
||||
{
|
||||
if (glRefConfig.packedNormalDataType == GL_INT_2_10_10_10_REV)
|
||||
{
|
||||
union pack10_u num;
|
||||
union pack10_u *num = (union pack10_u *)&b;
|
||||
|
||||
num.i = b;
|
||||
|
||||
v[0] = num.pack.x / 511.0f;
|
||||
v[1] = num.pack.y / 511.0f;
|
||||
v[2] = num.pack.z / 511.0f;
|
||||
v[3] = num.pack.w;
|
||||
v[0] = num->pack.x / 511.0f;
|
||||
v[1] = num->pack.y / 511.0f;
|
||||
v[2] = num->pack.z / 511.0f;
|
||||
v[3] = num->pack.w;
|
||||
}
|
||||
else
|
||||
{
|
||||
union pack8_u num;
|
||||
union pack8_u *num = (union pack8_u *)&b;
|
||||
|
||||
num.i = b;
|
||||
|
||||
v[0] = num.pack.x / 127.0f;
|
||||
v[1] = num.pack.y / 127.0f;
|
||||
v[2] = num.pack.z / 127.0f;
|
||||
v[3] = num.pack.w / 127.0f;
|
||||
v[0] = num->pack.x / 127.0f;
|
||||
v[1] = num->pack.y / 127.0f;
|
||||
v[2] = num->pack.z / 127.0f;
|
||||
v[3] = num->pack.w / 127.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,23 +167,19 @@ void R_VaoUnpackNormal(vec3_t v, uint32_t b)
|
|||
{
|
||||
if (glRefConfig.packedNormalDataType == GL_INT_2_10_10_10_REV)
|
||||
{
|
||||
union pack10_u num;
|
||||
union pack10_u *num = (union pack10_u *)&b;
|
||||
|
||||
num.i = b;
|
||||
|
||||
v[0] = num.pack.x / 511.0f;
|
||||
v[1] = num.pack.y / 511.0f;
|
||||
v[2] = num.pack.z / 511.0f;
|
||||
v[0] = num->pack.x / 511.0f;
|
||||
v[1] = num->pack.y / 511.0f;
|
||||
v[2] = num->pack.z / 511.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
union pack8_u num;
|
||||
union pack8_u *num = (union pack8_u *)&b;
|
||||
|
||||
num.i = b;
|
||||
|
||||
v[0] = num.pack.x / 127.0f;
|
||||
v[1] = num.pack.y / 127.0f;
|
||||
v[2] = num.pack.z / 127.0f;
|
||||
v[0] = num->pack.x / 127.0f;
|
||||
v[1] = num->pack.y / 127.0f;
|
||||
v[2] = num->pack.z / 127.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -312,9 +349,9 @@ vao_t *R_CreateVao2(const char *name, int numVertexes, srfVert_t *verts, int num
|
|||
vao->attribs[ATTR_INDEX_POSITION ].type = GL_FLOAT;
|
||||
vao->attribs[ATTR_INDEX_NORMAL ].type = glRefConfig.packedNormalDataType;
|
||||
vao->attribs[ATTR_INDEX_TANGENT ].type = glRefConfig.packedNormalDataType;
|
||||
vao->attribs[ATTR_INDEX_TEXCOORD ].type = GL_FLOAT;
|
||||
vao->attribs[ATTR_INDEX_LIGHTCOORD ].type = GL_FLOAT;
|
||||
vao->attribs[ATTR_INDEX_COLOR ].type = GL_FLOAT;
|
||||
vao->attribs[ATTR_INDEX_TEXCOORD ].type = glRefConfig.packedTexcoordDataType;
|
||||
vao->attribs[ATTR_INDEX_LIGHTCOORD ].type = glRefConfig.packedTexcoordDataType;
|
||||
vao->attribs[ATTR_INDEX_COLOR ].type = glRefConfig.packedColorDataType;
|
||||
vao->attribs[ATTR_INDEX_LIGHTDIRECTION].type = glRefConfig.packedNormalDataType;
|
||||
|
||||
vao->attribs[ATTR_INDEX_POSITION ].normalized = GL_FALSE;
|
||||
|
@ -330,9 +367,9 @@ vao_t *R_CreateVao2(const char *name, int numVertexes, srfVert_t *verts, int num
|
|||
#ifdef USE_VERT_TANGENT_SPACE
|
||||
vao->attribs[ATTR_INDEX_TANGENT ].offset = dataSize; dataSize += sizeof(uint32_t);
|
||||
#endif
|
||||
vao->attribs[ATTR_INDEX_TEXCOORD ].offset = dataSize; dataSize += sizeof(verts[0].st);
|
||||
vao->attribs[ATTR_INDEX_LIGHTCOORD ].offset = dataSize; dataSize += sizeof(verts[0].lightmap);
|
||||
vao->attribs[ATTR_INDEX_COLOR ].offset = dataSize; dataSize += sizeof(verts[0].vertexColors);
|
||||
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;
|
||||
vao->attribs[ATTR_INDEX_LIGHTDIRECTION].offset = dataSize; dataSize += sizeof(uint32_t);
|
||||
|
||||
vao->attribs[ATTR_INDEX_POSITION ].stride = dataSize;
|
||||
|
@ -358,40 +395,29 @@ vao_t *R_CreateVao2(const char *name, int numVertexes, srfVert_t *verts, int num
|
|||
|
||||
for (i = 0; i < numVertexes; i++)
|
||||
{
|
||||
uint32_t *p;
|
||||
|
||||
// xyz
|
||||
memcpy(data + dataOfs, &verts[i].xyz, sizeof(verts[i].xyz));
|
||||
dataOfs += sizeof(verts[i].xyz);
|
||||
|
||||
// normal
|
||||
p = (uint32_t *)(data + dataOfs);
|
||||
*p = R_VaoPackNormal(verts[i].normal);
|
||||
dataOfs += sizeof(uint32_t);
|
||||
dataOfs += R_VaoPackNormal(data + dataOfs, verts[i].normal);
|
||||
|
||||
#ifdef USE_VERT_TANGENT_SPACE
|
||||
// tangent
|
||||
p = (uint32_t *)(data + dataOfs);
|
||||
*p = R_VaoPackTangent(verts[i].tangent);
|
||||
dataOfs += sizeof(uint32_t);
|
||||
dataOfs += R_VaoPackTangent(data + dataOfs, verts[i].tangent);
|
||||
#endif
|
||||
|
||||
// vertex texcoords
|
||||
memcpy(data + dataOfs, &verts[i].st, sizeof(verts[i].st));
|
||||
dataOfs += sizeof(verts[i].st);
|
||||
// texcoords
|
||||
dataOfs += R_VaoPackTexCoord(data + dataOfs, verts[i].st);
|
||||
|
||||
// feed vertex lightmap texcoords
|
||||
memcpy(data + dataOfs, &verts[i].lightmap, sizeof(verts[i].lightmap));
|
||||
dataOfs += sizeof(verts[i].lightmap);
|
||||
// lightmap texcoords
|
||||
dataOfs += R_VaoPackTexCoord(data + dataOfs, verts[i].lightmap);
|
||||
|
||||
// feed vertex colors
|
||||
memcpy(data + dataOfs, &verts[i].vertexColors, sizeof(verts[i].vertexColors));
|
||||
dataOfs += sizeof(verts[i].vertexColors);
|
||||
// colors
|
||||
dataOfs += R_VaoPackColors(data + dataOfs, verts[i].vertexColors);
|
||||
|
||||
// feed vertex light directions
|
||||
p = (uint32_t *)(data + dataOfs);
|
||||
*p = R_VaoPackNormal(verts[i].lightdir);
|
||||
dataOfs += sizeof(uint32_t);
|
||||
// light directions
|
||||
dataOfs += R_VaoPackNormal(data + dataOfs, verts[i].lightdir);
|
||||
}
|
||||
|
||||
vao->vertexesSize = dataSize;
|
||||
|
|
Loading…
Reference in a new issue