From: havoc Date: Thu, 3 Mar 2011 17:48:26 +0000 (+0000) Subject: eliminated color4ub vertex formats, now everything is float, this fixes color wrappin... X-Git-Tag: xonotic-v0.5.0~425^2~16 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a118c522ef01a01fb7ddc188a7b0d6bb05404c38;p=xonotic%2Fdarkplaces.git eliminated color4ub vertex formats, now everything is float, this fixes color wrapping/clamping issues in D3D9 renderer git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10887 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/client.h b/client.h index b26d5198..1147c8ac 100644 --- a/client.h +++ b/client.h @@ -34,7 +34,7 @@ typedef struct tridecal_s // color and initial alpha value float texcoord2f[3][2]; float vertex3f[3][3]; - unsigned char color4ub[3][4]; + float color4f[3][4]; // how long this decal has lived so far (the actual fade begins at cl_decals_time) float lived; // if >= 0 this indicates the decal should follow an animated triangle diff --git a/gl_backend.c b/gl_backend.c index a9b01118..3bbad6c8 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -3720,7 +3720,7 @@ D3DVERTEXELEMENT9 r_vertex3f_d3d9elements[] = D3DVERTEXELEMENT9 r_vertexgeneric_d3d9elements[] = { {0, (int)((size_t)&((r_vertexgeneric_t *)0)->vertex3f ), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, - {0, (int)((size_t)&((r_vertexgeneric_t *)0)->color4ub ), D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0}, + {0, (int)((size_t)&((r_vertexgeneric_t *)0)->color4f ), D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0}, {0, (int)((size_t)&((r_vertexgeneric_t *)0)->texcoord2f), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END() }; @@ -3728,7 +3728,7 @@ D3DVERTEXELEMENT9 r_vertexgeneric_d3d9elements[] = D3DVERTEXELEMENT9 r_vertexmesh_d3d9elements[] = { {0, (int)((size_t)&((r_vertexmesh_t *)0)->vertex3f ), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, - {0, (int)((size_t)&((r_vertexmesh_t *)0)->color4ub ), D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0}, + {0, (int)((size_t)&((r_vertexmesh_t *)0)->color4f ), D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0}, {0, (int)((size_t)&((r_vertexmesh_t *)0)->texcoordtexture2f ), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, {0, (int)((size_t)&((r_vertexmesh_t *)0)->svector3f ), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1}, {0, (int)((size_t)&((r_vertexmesh_t *)0)->tvector3f ), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2}, @@ -3965,19 +3965,12 @@ void R_Mesh_PrepareVertices_Generic_Arrays(int numvertices, const float *vertex3 if (color4f) { for (i = 0;i < numvertices;i++) - Vector4Scale(color4f + 4*i, 255.0f, vertex[i].color4ub); + Vector4Copy(color4f + 4*i, vertex[i].color4f); } else { - float tempcolor4f[4]; - unsigned char tempcolor4ub[4]; - Vector4Scale(gl_state.color4f, 255.0f, tempcolor4f); - tempcolor4ub[0] = (unsigned char)bound(0.0f, tempcolor4f[0], 255.0f); - tempcolor4ub[1] = (unsigned char)bound(0.0f, tempcolor4f[1], 255.0f); - tempcolor4ub[2] = (unsigned char)bound(0.0f, tempcolor4f[2], 255.0f); - tempcolor4ub[3] = (unsigned char)bound(0.0f, tempcolor4f[3], 255.0f); for (i = 0;i < numvertices;i++) - Vector4Copy(tempcolor4ub, vertex[i].color4ub); + Vector4Copy(gl_state.color4f, vertex[i].color4f); } if (texcoord2f) for (i = 0;i < numvertices;i++) @@ -4006,7 +3999,7 @@ void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *ve if (vertexbuffer) { R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); - R_Mesh_ColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->color4ub , vertexbuffer, (int)((unsigned char *)vertex->color4ub - (unsigned char *)vertex)); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , vertexbuffer, (int)((unsigned char *)vertex->texcoord2f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); R_Mesh_TexCoordPointer(2, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); @@ -4016,7 +4009,7 @@ void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *ve else { R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , NULL, 0); - R_Mesh_ColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->color4ub , NULL, 0); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , NULL, 0); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , NULL, 0); R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); R_Mesh_TexCoordPointer(2, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); @@ -4028,14 +4021,14 @@ void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *ve if (vertexbuffer) { R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); - R_Mesh_ColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->color4ub , vertexbuffer, (int)((unsigned char *)vertex->color4ub - (unsigned char *)vertex)); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , vertexbuffer, (int)((unsigned char *)vertex->texcoord2f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); } else { R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , NULL, 0); - R_Mesh_ColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->color4ub , NULL, 0); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , NULL, 0); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , NULL, 0); R_Mesh_TexCoordPointer(1, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0); } @@ -4044,13 +4037,13 @@ void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *ve if (vertexbuffer) { R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); - R_Mesh_ColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->color4ub , vertexbuffer, (int)((unsigned char *)vertex->color4ub - (unsigned char *)vertex)); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , vertexbuffer, (int)((unsigned char *)vertex->texcoord2f - (unsigned char *)vertex)); } else { R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , NULL, 0); - R_Mesh_ColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->color4ub , NULL, 0); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , NULL, 0); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoord2f , NULL, 0); } break; @@ -4074,7 +4067,7 @@ void R_Mesh_PrepareVertices_Generic(int numvertices, const r_vertexgeneric_t *ve break; case RENDERPATH_SOFT: DPSOFTRAST_SetVertexPointer(vertex->vertex3f, sizeof(*vertex)); - DPSOFTRAST_SetColorPointer4ub(vertex->color4ub, sizeof(*vertex)); + DPSOFTRAST_SetColorPointer(vertex->color4f, sizeof(*vertex)); DPSOFTRAST_SetTexCoordPointer(0, 2, sizeof(*vertex), vertex->texcoord2f); DPSOFTRAST_SetTexCoordPointer(1, 2, sizeof(*vertex), NULL); DPSOFTRAST_SetTexCoordPointer(2, 2, sizeof(*vertex), NULL); @@ -4172,19 +4165,12 @@ void R_Mesh_PrepareVertices_Mesh_Arrays(int numvertices, const float *vertex3f, if (color4f) { for (i = 0;i < numvertices;i++) - Vector4Scale(color4f + 4*i, 255.0f, vertex[i].color4ub); + Vector4Copy(color4f + 4*i, vertex[i].color4f); } else { - float tempcolor4f[4]; - unsigned char tempcolor4ub[4]; - Vector4Scale(gl_state.color4f, 255.0f, tempcolor4f); - tempcolor4ub[0] = (unsigned char)bound(0.0f, tempcolor4f[0], 255.0f); - tempcolor4ub[1] = (unsigned char)bound(0.0f, tempcolor4f[1], 255.0f); - tempcolor4ub[2] = (unsigned char)bound(0.0f, tempcolor4f[2], 255.0f); - tempcolor4ub[3] = (unsigned char)bound(0.0f, tempcolor4f[3], 255.0f); for (i = 0;i < numvertices;i++) - Vector4Copy(tempcolor4ub, vertex[i].color4ub); + Vector4Copy(gl_state.color4f, vertex[i].color4f); } if (texcoordtexture2f) for (i = 0;i < numvertices;i++) @@ -4216,7 +4202,7 @@ void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, if (vertexbuffer) { R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); - R_Mesh_ColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->color4ub , vertexbuffer, (int)((unsigned char *)vertex->color4ub - (unsigned char *)vertex)); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , vertexbuffer, (int)((unsigned char *)vertex->texcoordtexture2f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(1, 3, GL_FLOAT , sizeof(*vertex), vertex->svector3f , vertexbuffer, (int)((unsigned char *)vertex->svector3f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(2, 3, GL_FLOAT , sizeof(*vertex), vertex->tvector3f , vertexbuffer, (int)((unsigned char *)vertex->tvector3f - (unsigned char *)vertex)); @@ -4226,7 +4212,7 @@ void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, else { R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , NULL, 0); - R_Mesh_ColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->color4ub , NULL, 0); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , NULL, 0); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , NULL, 0); R_Mesh_TexCoordPointer(1, 3, GL_FLOAT , sizeof(*vertex), vertex->svector3f , NULL, 0); R_Mesh_TexCoordPointer(2, 3, GL_FLOAT , sizeof(*vertex), vertex->tvector3f , NULL, 0); @@ -4238,14 +4224,14 @@ void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, if (vertexbuffer) { R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); - R_Mesh_ColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->color4ub , vertexbuffer, (int)((unsigned char *)vertex->color4ub - (unsigned char *)vertex)); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , vertexbuffer, (int)((unsigned char *)vertex->texcoordtexture2f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(1, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordlightmap2f, vertexbuffer, (int)((unsigned char *)vertex->texcoordlightmap2f - (unsigned char *)vertex)); } else { R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , NULL, 0); - R_Mesh_ColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->color4ub , NULL, 0); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , NULL, 0); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , NULL, 0); R_Mesh_TexCoordPointer(1, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordlightmap2f, NULL, 0); } @@ -4254,13 +4240,13 @@ void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, if (vertexbuffer) { R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , vertexbuffer, (int)((unsigned char *)vertex->vertex3f - (unsigned char *)vertex)); - R_Mesh_ColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->color4ub , vertexbuffer, (int)((unsigned char *)vertex->color4ub - (unsigned char *)vertex)); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , vertexbuffer, (int)((unsigned char *)vertex->color4f - (unsigned char *)vertex)); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , vertexbuffer, (int)((unsigned char *)vertex->texcoordtexture2f - (unsigned char *)vertex)); } else { R_Mesh_VertexPointer( 3, GL_FLOAT , sizeof(*vertex), vertex->vertex3f , NULL, 0); - R_Mesh_ColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(*vertex), vertex->color4ub , NULL, 0); + R_Mesh_ColorPointer( 4, GL_FLOAT , sizeof(*vertex), vertex->color4f , NULL, 0); R_Mesh_TexCoordPointer(0, 2, GL_FLOAT , sizeof(*vertex), vertex->texcoordtexture2f , NULL, 0); } break; @@ -4284,7 +4270,7 @@ void R_Mesh_PrepareVertices_Mesh(int numvertices, const r_vertexmesh_t *vertex, break; case RENDERPATH_SOFT: DPSOFTRAST_SetVertexPointer(vertex->vertex3f, sizeof(*vertex)); - DPSOFTRAST_SetColorPointer4ub(vertex->color4ub, sizeof(*vertex)); + DPSOFTRAST_SetColorPointer(vertex->color4f, sizeof(*vertex)); DPSOFTRAST_SetTexCoordPointer(0, 2, sizeof(*vertex), vertex->texcoordtexture2f); DPSOFTRAST_SetTexCoordPointer(1, 3, sizeof(*vertex), vertex->svector3f); DPSOFTRAST_SetTexCoordPointer(2, 3, sizeof(*vertex), vertex->tvector3f); diff --git a/gl_rmain.c b/gl_rmain.c index 8c5fc54b..b5c972e8 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -11610,7 +11610,7 @@ void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const } if ((batchneed & BATCHNEED_VERTEXMESH_VERTEXCOLOR) && rsurface.batchlightmapcolor4f) for (j = 0, vertexmesh = rsurface.batchvertexmesh;j < batchnumvertices;j++, vertexmesh++) - Vector4Scale(rsurface.batchlightmapcolor4f + 4*j, 255.0f, vertexmesh->color4ub); + Vector4Copy(rsurface.batchlightmapcolor4f + 4*j, vertexmesh->color4f); if (batchneed & BATCHNEED_VERTEXMESH_TEXCOORD) for (j = 0, vertexmesh = rsurface.batchvertexmesh;j < batchnumvertices;j++, vertexmesh++) Vector2Copy(rsurface.batchtexcoordtexture2f + 2*j, vertexmesh->texcoordtexture2f); @@ -12433,7 +12433,7 @@ static void R_DrawTextureSurfaceList_ShowSurfaces(int texturenumsurfaces, const for (j = 0, vi = rsurface.batchfirstvertex;j < rsurface.batchnumvertices;j++, vi++) { VectorCopy(rsurface.batchvertex3f + 3*vi, batchvertex[vi].vertex3f); - Vector4Set(batchvertex[vi].color4ub, 0, 0, 0, 255); + Vector4Set(batchvertex[vi].color4f, 0, 0, 0, 1); } R_Mesh_PrepareVertices_Generic_Unlock(); RSurf_DrawBatch(); @@ -12444,9 +12444,9 @@ static void R_DrawTextureSurfaceList_ShowSurfaces(int texturenumsurfaces, const batchvertex = R_Mesh_PrepareVertices_Generic_Lock(rsurface.batchnumvertices); for (j = 0, vi = rsurface.batchfirstvertex;j < rsurface.batchnumvertices;j++, vi++) { - unsigned char c = vi << 3; + unsigned char c = (vi << 3) * (1.0f / 256.0f); VectorCopy(rsurface.batchvertex3f + 3*vi, batchvertex[vi].vertex3f); - Vector4Set(batchvertex[vi].color4ub, c, c, c, 255); + Vector4Set(batchvertex[vi].color4f, c, c, c, 1); } R_Mesh_PrepareVertices_Generic_Unlock(); RSurf_DrawBatch(); @@ -12458,13 +12458,13 @@ static void R_DrawTextureSurfaceList_ShowSurfaces(int texturenumsurfaces, const batchvertex = R_Mesh_PrepareVertices_Generic_Lock(3*rsurface.batchnumtriangles); for (j = 0, e = rsurface.batchelement3i + 3 * rsurface.batchfirsttriangle;j < rsurface.batchnumtriangles;j++, e += 3) { - unsigned char c = (j + rsurface.batchfirsttriangle) << 3; + unsigned char c = ((j + rsurface.batchfirsttriangle) << 3) * (1.0f / 256.0f); VectorCopy(rsurface.batchvertex3f + 3*e[0], batchvertex[j*3+0].vertex3f); VectorCopy(rsurface.batchvertex3f + 3*e[1], batchvertex[j*3+1].vertex3f); VectorCopy(rsurface.batchvertex3f + 3*e[2], batchvertex[j*3+2].vertex3f); - Vector4Set(batchvertex[j*3+0].color4ub, c, c, c, 255); - Vector4Set(batchvertex[j*3+1].color4ub, c, c, c, 255); - Vector4Set(batchvertex[j*3+2].color4ub, c, c, c, 255); + Vector4Set(batchvertex[j*3+0].color4f, c, c, c, 1); + Vector4Set(batchvertex[j*3+1].color4f, c, c, c, 1); + Vector4Set(batchvertex[j*3+2].color4f, c, c, c, 1); } R_Mesh_PrepareVertices_Generic_Unlock(); R_Mesh_Draw(0, rsurface.batchnumtriangles*3, 0, rsurface.batchnumtriangles, NULL, NULL, 0, NULL, NULL, 0); @@ -12474,7 +12474,7 @@ static void R_DrawTextureSurfaceList_ShowSurfaces(int texturenumsurfaces, const int texturesurfaceindex; int k; const msurface_t *surface; - unsigned char surfacecolor4ub[4]; + float surfacecolor4f[4]; RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_NOGAPS, texturenumsurfaces, texturesurfacelist); batchvertex = R_Mesh_PrepareVertices_Generic_Lock(rsurface.batchfirstvertex + rsurface.batchnumvertices); vi = 0; @@ -12482,11 +12482,11 @@ static void R_DrawTextureSurfaceList_ShowSurfaces(int texturenumsurfaces, const { surface = texturesurfacelist[texturesurfaceindex]; k = (int)(((size_t)surface) / sizeof(msurface_t)); - Vector4Set(surfacecolor4ub, (k & 0xF) << 4, (k & 0xF0), (k & 0xF00) >> 4, 255); + Vector4Set(surfacecolor4f, (k & 0xF) * (1.0f / 16.0f), (k & 0xF0) * (1.0f / 256.0f), (k & 0xF00) * (1.0f / 4096.0f), 1); for (j = 0;j < surface->num_vertices;j++) { VectorCopy(rsurface.batchvertex3f + 3*vi, batchvertex[vi].vertex3f); - Vector4Copy(surfacecolor4ub, batchvertex[vi].color4ub); + Vector4Copy(surfacecolor4f, batchvertex[vi].color4f); vi++; } } @@ -12993,7 +12993,7 @@ static void R_DecalSystem_SpawnTriangle(decalsystem_t *decalsystem, const float // grab a decal and search for another free slot for the next one decals = decalsystem->decals; decal = decalsystem->decals + (i = decalsystem->freedecal++); - for (i = decalsystem->freedecal;i < decalsystem->numdecals && decals[i].color4ub[0][3];i++) + for (i = decalsystem->freedecal;i < decalsystem->numdecals && decals[i].color4f[0][3];i++) ; decalsystem->freedecal = i; if (decalsystem->numdecals <= i) @@ -13004,18 +13004,18 @@ static void R_DecalSystem_SpawnTriangle(decalsystem_t *decalsystem, const float decal->triangleindex = triangleindex; decal->surfaceindex = surfaceindex; decal->decalsequence = decalsequence; - decal->color4ub[0][0] = (unsigned char)(c0[0]*255.0f); - decal->color4ub[0][1] = (unsigned char)(c0[1]*255.0f); - decal->color4ub[0][2] = (unsigned char)(c0[2]*255.0f); - decal->color4ub[0][3] = 255; - decal->color4ub[1][0] = (unsigned char)(c1[0]*255.0f); - decal->color4ub[1][1] = (unsigned char)(c1[1]*255.0f); - decal->color4ub[1][2] = (unsigned char)(c1[2]*255.0f); - decal->color4ub[1][3] = 255; - decal->color4ub[2][0] = (unsigned char)(c2[0]*255.0f); - decal->color4ub[2][1] = (unsigned char)(c2[1]*255.0f); - decal->color4ub[2][2] = (unsigned char)(c2[2]*255.0f); - decal->color4ub[2][3] = 255; + decal->color4f[0][0] = c0[0]; + decal->color4f[0][1] = c0[1]; + decal->color4f[0][2] = c0[2]; + decal->color4f[0][3] = 1; + decal->color4f[1][0] = c1[0]; + decal->color4f[1][1] = c1[1]; + decal->color4f[1][2] = c1[2]; + decal->color4f[1][3] = 1; + decal->color4f[2][0] = c2[0]; + decal->color4f[2][1] = c2[1]; + decal->color4f[2][2] = c2[2]; + decal->color4f[2][3] = 1; decal->vertex3f[0][0] = v0[0]; decal->vertex3f[0][1] = v0[1]; decal->vertex3f[0][2] = v0[2]; @@ -13382,7 +13382,7 @@ static void R_DrawModelDecals_FadeEntity(entity_render_t *ent) for (i = 0, decal = decalsystem->decals;i < numdecals;i++, decal++) { - if (decal->color4ub[0][3]) + if (decal->color4f[0][3]) { decal->lived += frametime; if (killsequence - decal->decalsequence > 0 || decal->lived >= lifetime) @@ -13394,13 +13394,13 @@ static void R_DrawModelDecals_FadeEntity(entity_render_t *ent) } } decal = decalsystem->decals; - while (numdecals > 0 && !decal[numdecals-1].color4ub[0][3]) + while (numdecals > 0 && !decal[numdecals-1].color4f[0][3]) numdecals--; // collapse the array by shuffling the tail decals into the gaps for (;;) { - while (decalsystem->freedecal < numdecals && decal[decalsystem->freedecal].color4ub[0][3]) + while (decalsystem->freedecal < numdecals && decal[decalsystem->freedecal].color4f[0][3]) decalsystem->freedecal++; if (decalsystem->freedecal == numdecals) break; @@ -13464,7 +13464,7 @@ static void R_DrawModelDecals_Entity(entity_render_t *ent) t2f = decalsystem->texcoord2f; for (i = 0, decal = decalsystem->decals;i < numdecals;i++, decal++) { - if (!decal->color4ub[0][3]) + if (!decal->color4f[0][3]) continue; if (surfacevisible && !surfacevisible[decal->surfaceindex]) @@ -13472,24 +13472,21 @@ static void R_DrawModelDecals_Entity(entity_render_t *ent) // update color values for fading decals if (decal->lived >= cl_decals_time.value) - { alpha = 1 - faderate * (decal->lived - cl_decals_time.value); - alpha *= (1.0f/255.0f); - } else - alpha = 1.0f/255.0f; + alpha = 1.0f; - c4f[ 0] = decal->color4ub[0][0] * alpha; - c4f[ 1] = decal->color4ub[0][1] * alpha; - c4f[ 2] = decal->color4ub[0][2] * alpha; + c4f[ 0] = decal->color4f[0][0] * alpha; + c4f[ 1] = decal->color4f[0][1] * alpha; + c4f[ 2] = decal->color4f[0][2] * alpha; c4f[ 3] = 1; - c4f[ 4] = decal->color4ub[1][0] * alpha; - c4f[ 5] = decal->color4ub[1][1] * alpha; - c4f[ 6] = decal->color4ub[1][2] * alpha; + c4f[ 4] = decal->color4f[1][0] * alpha; + c4f[ 5] = decal->color4f[1][1] * alpha; + c4f[ 6] = decal->color4f[1][2] * alpha; c4f[ 7] = 1; - c4f[ 8] = decal->color4ub[2][0] * alpha; - c4f[ 9] = decal->color4ub[2][1] * alpha; - c4f[10] = decal->color4ub[2][2] * alpha; + c4f[ 8] = decal->color4f[2][0] * alpha; + c4f[ 9] = decal->color4f[2][1] * alpha; + c4f[10] = decal->color4f[2][2] * alpha; c4f[11] = 1; t2f[0] = decal->texcoord2f[0][0]; diff --git a/glquake.h b/glquake.h index fc801376..90ef1a7b 100644 --- a/glquake.h +++ b/glquake.h @@ -24,6 +24,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // disable data conversion warnings #ifdef _MSC_VER +#pragma warning(disable : 4310) // LordHavoc: MSVC++ 2008 x86: cast truncates constant value +#pragma warning(disable : 4245) // LordHavoc: MSVC++ 2008 x86: 'initializing' : conversion from 'int' to 'unsigned char', signed/unsigned mismatch +#pragma warning(disable : 4204) // LordHavoc: MSVC++ 2008 x86: nonstandard extension used : non-constant aggregate initializer +#pragma warning(disable : 4267) // LordHavoc: MSVC++ 2008 x64, conversion from 'size_t' to 'int', possible loss of data //#pragma warning(disable : 4244) // LordHavoc: MSVC++ 4 x86, double/float //#pragma warning(disable : 4305) // LordHavoc: MSVC++ 6 x86, double/float //#pragma warning(disable : 4706) // LordHavoc: MSVC++ 2008 x86, assignment within conditional expression diff --git a/model_shared.c b/model_shared.c index 52bf0ed8..0761758c 100644 --- a/model_shared.c +++ b/model_shared.c @@ -2797,7 +2797,7 @@ void Mod_BuildVBOs(void) VectorScale(loadmodel->surfmesh.data_tvector3f + 3*vertexindex, 1.0f, vertexmesh->tvector3f); VectorScale(loadmodel->surfmesh.data_normal3f + 3*vertexindex, 1.0f, vertexmesh->normal3f); if (loadmodel->surfmesh.data_lightmapcolor4f) - Vector4Scale(loadmodel->surfmesh.data_lightmapcolor4f + 4*vertexindex, 255.0f, vertexmesh->color4ub); + Vector4Copy(loadmodel->surfmesh.data_lightmapcolor4f + 4*vertexindex, vertexmesh->color4f); Vector2Copy(loadmodel->surfmesh.data_texcoordtexture2f + 2*vertexindex, vertexmesh->texcoordtexture2f); if (loadmodel->surfmesh.data_texcoordlightmap2f) Vector2Scale(loadmodel->surfmesh.data_texcoordlightmap2f + 2*vertexindex, 1.0f, vertexmesh->texcoordlightmap2f); diff --git a/model_shared.h b/model_shared.h index 02c237fd..b79c1330 100644 --- a/model_shared.h +++ b/model_shared.h @@ -103,18 +103,18 @@ blendweights_t; typedef struct r_vertexgeneric_s { - // 24 bytes + // 36 bytes float vertex3f[3]; - unsigned char color4ub[4]; + float color4f[4]; float texcoord2f[2]; } r_vertexgeneric_t; typedef struct r_vertexmesh_s { - // 68 bytes + // 80 bytes float vertex3f[3]; - unsigned char color4ub[4]; + float color4f[4]; float texcoordtexture2f[2]; float texcoordlightmap2f[2]; float svector3f[3];