mirror of
https://github.com/UberGames/ioef.git
synced 2024-11-27 22:42:09 +00:00
OpenGL2: Prefer VBO/IBO sizes of around 4MB.
This commit is contained in:
parent
8c3ae8d7d2
commit
7672533e8f
1 changed files with 74 additions and 17 deletions
|
@ -1851,6 +1851,9 @@ static void R_CreateWorldVBOs(void)
|
||||||
VBO_t *vbo;
|
VBO_t *vbo;
|
||||||
IBO_t *ibo;
|
IBO_t *ibo;
|
||||||
|
|
||||||
|
int maxVboSize = 4 * 1024 * 1024;
|
||||||
|
int maxIboSize = 4 * 1024 * 1024;
|
||||||
|
|
||||||
int startTime, endTime;
|
int startTime, endTime;
|
||||||
|
|
||||||
startTime = ri.Milliseconds();
|
startTime = ri.Milliseconds();
|
||||||
|
@ -1859,11 +1862,22 @@ static void R_CreateWorldVBOs(void)
|
||||||
numSortedSurfaces = 0;
|
numSortedSurfaces = 0;
|
||||||
for(surface = &s_worldData.surfaces[0]; surface < &s_worldData.surfaces[s_worldData.numsurfaces]; surface++)
|
for(surface = &s_worldData.surfaces[0]; surface < &s_worldData.surfaces[s_worldData.numsurfaces]; surface++)
|
||||||
{
|
{
|
||||||
if(*surface->data == SF_FACE || *surface->data == SF_GRID || *surface->data == SF_TRIANGLES)
|
shader_t *shader = surface->shader;
|
||||||
{
|
|
||||||
|
if (shader->isPortal)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (shader->isSky)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ShaderRequiresCPUDeforms(shader))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(*surface->data == SF_FACE || *surface->data == SF_GRID || *surface->data == SF_TRIANGLES))
|
||||||
|
continue;
|
||||||
|
|
||||||
numSortedSurfaces++;
|
numSortedSurfaces++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// presort surfaces
|
// presort surfaces
|
||||||
surfacesSorted = ri.Malloc(numSortedSurfaces * sizeof(*surfacesSorted));
|
surfacesSorted = ri.Malloc(numSortedSurfaces * sizeof(*surfacesSorted));
|
||||||
|
@ -1871,19 +1885,66 @@ static void R_CreateWorldVBOs(void)
|
||||||
j = 0;
|
j = 0;
|
||||||
for(surface = &s_worldData.surfaces[0]; surface < &s_worldData.surfaces[s_worldData.numsurfaces]; surface++)
|
for(surface = &s_worldData.surfaces[0]; surface < &s_worldData.surfaces[s_worldData.numsurfaces]; surface++)
|
||||||
{
|
{
|
||||||
if(*surface->data == SF_FACE || *surface->data == SF_GRID || *surface->data == SF_TRIANGLES)
|
shader_t *shader = surface->shader;
|
||||||
{
|
|
||||||
|
if (shader->isPortal)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (shader->isSky)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ShaderRequiresCPUDeforms(shader))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(*surface->data == SF_FACE || *surface->data == SF_GRID || *surface->data == SF_TRIANGLES))
|
||||||
|
continue;
|
||||||
|
|
||||||
surfacesSorted[j++] = surface;
|
surfacesSorted[j++] = surface;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
qsort(surfacesSorted, numSortedSurfaces, sizeof(*surfacesSorted), BSPSurfaceCompare);
|
qsort(surfacesSorted, numSortedSurfaces, sizeof(*surfacesSorted), BSPSurfaceCompare);
|
||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
for(firstSurf = lastSurf = surfacesSorted; firstSurf < &surfacesSorted[numSortedSurfaces]; firstSurf = lastSurf)
|
for(firstSurf = lastSurf = currSurf = surfacesSorted; firstSurf < &surfacesSorted[numSortedSurfaces]; firstSurf = currSurf = lastSurf)
|
||||||
{
|
{
|
||||||
while(lastSurf < &surfacesSorted[numSortedSurfaces] && (*lastSurf)->shader->sortedIndex == (*firstSurf)->shader->sortedIndex)
|
int currVboSize, currIboSize;
|
||||||
lastSurf++;
|
|
||||||
|
currVboSize = currIboSize = 0;
|
||||||
|
while (currVboSize < maxVboSize && currIboSize < maxIboSize && lastSurf < &surfacesSorted[numSortedSurfaces])
|
||||||
|
{
|
||||||
|
int addVboSize, addIboSize, currShaderIndex;
|
||||||
|
|
||||||
|
addVboSize = addIboSize = 0;
|
||||||
|
currShaderIndex = (*currSurf)->shader->sortedIndex;
|
||||||
|
while(currSurf < &surfacesSorted[numSortedSurfaces] && (*currSurf)->shader->sortedIndex == currShaderIndex)
|
||||||
|
{
|
||||||
|
srfBspSurface_t *bspSurf = (srfBspSurface_t *) (*currSurf)->data;
|
||||||
|
|
||||||
|
switch (bspSurf->surfaceType)
|
||||||
|
{
|
||||||
|
case SF_FACE:
|
||||||
|
case SF_GRID:
|
||||||
|
case SF_TRIANGLES:
|
||||||
|
addVboSize += bspSurf->numVerts * sizeof(srfVert_t);
|
||||||
|
addIboSize += bspSurf->numTriangles * 3 *sizeof(glIndex_t);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
currSurf++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((currVboSize != 0 && addVboSize + currVboSize > maxVboSize)
|
||||||
|
|| (currIboSize != 0 && addIboSize + currIboSize > maxIboSize))
|
||||||
|
break;
|
||||||
|
|
||||||
|
lastSurf = currSurf;
|
||||||
|
|
||||||
|
currVboSize += addVboSize;
|
||||||
|
currIboSize += addIboSize;
|
||||||
|
}
|
||||||
|
|
||||||
numVerts = 0;
|
numVerts = 0;
|
||||||
numTriangles = 0;
|
numTriangles = 0;
|
||||||
|
@ -1897,12 +1958,8 @@ static void R_CreateWorldVBOs(void)
|
||||||
case SF_FACE:
|
case SF_FACE:
|
||||||
case SF_GRID:
|
case SF_GRID:
|
||||||
case SF_TRIANGLES:
|
case SF_TRIANGLES:
|
||||||
if(bspSurf->numVerts)
|
|
||||||
numVerts += bspSurf->numVerts;
|
numVerts += bspSurf->numVerts;
|
||||||
|
|
||||||
if(bspSurf->numTriangles)
|
|
||||||
numTriangles += bspSurf->numTriangles;
|
numTriangles += bspSurf->numTriangles;
|
||||||
|
|
||||||
numSurfaces++;
|
numSurfaces++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue