Optimizing
I've already learned the hard way about having texture atlas/pages
Moderator: Inside3D Admins
Spike wrote:as you mention opengles, I assume you're making an arm/mobile port.
mh wrote:[*]Changing lightmaps to native GPU formats and scheduling updates to reduce pipeline stalls.
int smax, tmax;
unsigned *base = gl_lms.lightmap_data[surf->lightmaptexturenum];
RECT *rect = &gl_lms.lightrect[surf->lightmaptexturenum];
smax = (surf->extents[0] >> 4) + 1;
tmax = (surf->extents[1] >> 4) + 1;
base += (surf->light_t * LIGHTMAP_SIZE) + surf->light_s;
R_BuildLightMap (surf, base, LIGHTMAP_SIZE);
R_SetCacheState (surf);
gl_lms.modified[surf->lightmaptexturenum] = true;
if (surf->lightrect.left < rect->left) rect->left = surf->lightrect.left;
if (surf->lightrect.right > rect->right) rect->right = surf->lightrect.right;
if (surf->lightrect.top < rect->top) rect->top = surf->lightrect.top;
if (surf->lightrect.bottom > rect->bottom) rect->bottom = surf->lightrect.bottom; GL_BindTexture (GL_TEXTURE2, GL_TEXTURE_2D_ARRAY, r_lightmapsampler, gl_state.lightmap_textures);
// upload any lightmaps that were modified
for (i = 0; i < gl_lms.current_lightmap_texture; i++)
{
if (gl_lms.modified[i])
{
if (!stateset)
{
glPixelStorei (GL_UNPACK_ROW_LENGTH, LIGHTMAP_SIZE);
stateset = true;
}
// texture is already bound so just modify it
glTexSubImage3D (GL_TEXTURE_2D_ARRAY, 0,
gl_lms.lightrect[i].left, gl_lms.lightrect[i].top, i,
(gl_lms.lightrect[i].right - gl_lms.lightrect[i].left), (gl_lms.lightrect[i].bottom - gl_lms.lightrect[i].top), 1,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
gl_lms.lightmap_data[i] + (gl_lms.lightrect[i].top * LIGHTMAP_SIZE) + gl_lms.lightrect[i].left);
gl_lms.lightrect[i].left = LIGHTMAP_SIZE;
gl_lms.lightrect[i].right = 0;
gl_lms.lightrect[i].top = LIGHTMAP_SIZE;
gl_lms.lightrect[i].bottom = 0;
gl_lms.modified[i] = false;
}
}
if (stateset)
glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);typedef struct
{
int left;
int right;
int top;
int bottom;
} rect_t;
typedef struct
{
int internal_format;
int current_lightmap_texture;
msurface_t *lightmap_surfaces[MAX_LIGHTMAPS];
byte lightmap_update[MAX_LIGHTMAPS][4*LM_BLOCK_WIDTH*LM_BLOCK_HEIGHT];
rect_t lightrect[MAX_LIGHTMAPS];
qboolean modified[MAX_LIGHTMAPS];
int allocated[LM_BLOCK_WIDTH];
// the lightmap texture data needs to be kept in
// main memory so texsubimage can update properly
byte lightmap_buffer[4*LM_BLOCK_WIDTH*LM_BLOCK_HEIGHT];
} gllightmapstate_t;
extern gllightmapstate_t gl_lms;
typedef struct gllightmapstate_s
{
int current_lightmap_texture;
int allocated[LIGHTMAP_SIZE];
qboolean modified[MAX_LIGHTMAPS];
RECT lightrect[MAX_LIGHTMAPS];
// the lightmap texture data needs to be kept in
// main memory so texsubimage can update properly
int lmhunkmark;
byte *lmhunkbase;
unsigned *lightmap_data[MAX_LIGHTMAPS];
} gllightmapstate_t; gl_lms.modified[surf->lightmaptexturenum] = true;
if (surf->lightrect.left < rect->left) rect->left = surf->lightrect.left;
if (surf->lightrect.right > rect->right) rect->right = surf->lightrect.right;
if (surf->lightrect.top < rect->top) rect->top = surf->lightrect.top;
if (surf->lightrect.bottom > rect->bottom) rect->bottom = surf->lightrect.bottom;Users browsing this forum: No registered users and 0 guests