Page 1 of 1

GLQuake Memory Saving

Posted: Tue Jun 15, 2010 10:03 pm
by mh
GLQuake is very wasteful on memory. Here we're going to start saving some. This not only reduces overhead on Quake's Hunk memory (meaning that you can fit more stuff, bigger maps, etc in there), but will also speed up map loading times!

The first set of changes are in the texture loader. Break open gl_model.c and change the following.

In Mod_LoadTextures, replace:

Code: Select all

tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );
with

Code: Select all

tx = Hunk_AllocName (sizeof(texture_t), loadname );
remove

Code: Select all

// the pixels immediately follow the structures
memcpy ( tx+1, mt+1, pixels);
change

Code: Select all

tx->gl_texturenum = GL_LoadTexture (mt->name, tx->width, tx->height, (byte *)(tx+1), true, false);
to

Code: Select all

tx->gl_texturenum = GL_LoadTexture (mt->name, tx->width, tx->height, (byte *)(mt+1), true, false);
change

Code: Select all

R_InitSky (tx);
to

Code: Select all

R_InitSky (mt);
Now on to the render.h changes.

change

Code: Select all

void R_InitSky (struct texture_s *mt);	// called at level load
to

Code: Select all

void R_InitSky (struct miptex_s *mt);	// called at level load
And lastly the gl_warp.c changes

replace

Code: Select all

void R_InitSky (texture_t *mt)
with

Code: Select all

void R_InitSky (miptex_t *mt)
All we're doing here is avoiding allocating the texels from the BSP on the hunk. They're only ever used in the texture loader, so why waste perfectly good memory that could be put to better use holding something else? Also good for the PSP people trying to squeeze Quake into 32 MB. :D

The saving for this one? I loaded e1m3, before was 421104 bytes for textures, after was 4992 bytes. That's almost half a MB wasted in stock GLQuake.

Re: GLQuake Memory Saving

Posted: Tue Jun 15, 2010 10:06 pm
by Downsider
mh wrote: In Mod_LoadTextures, replace:

Code: Select all

tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );
with

Code: Select all

tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );
It's the same? :O

Cool tutorial, though.

Posted: Tue Jun 15, 2010 10:13 pm
by mh
You're right. Changed. :lol:

Posted: Tue Jun 15, 2010 11:09 pm
by leileilol
Another waste is the MDL files. They're all UVmapped too efficiently, there is no way to fix that by engine so for them to be happy with GLQuake one would have to make new UVs and power of 16 texture sizes for more memory efficiency and cpu efficiency too so there's less resampling to do on load.

I'd do it if I ever got a binary patcher to work. I'd only submit it as a binary patch form that depends on registered pak1.pak that then patches a whole new pak2.pak (unaffecting pak1 of course)

Posted: Wed Jun 08, 2011 11:34 pm
by ArchAngel
Just tried this in a stock QuakeWorld client and it crashes it... the function looks pretty damn similar to the NQ one... any thoughts?

Posted: Wed Jun 08, 2011 11:48 pm
by mh
Probably R_InitSky or the GL_LoadTexture call. If memory serves there might be a little extra work needed in R_InitSky too, and I haven't tried this in glqwcl so there might be other places where (byte *) (tx + 1) is referred.

I'll try it tomorrow and post an update if I remember. ;)