Inside3D!
     

GLQuake Memory Saving

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials
View previous topic :: View next topic  
Author Message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Tue Jun 15, 2010 10:03 pm    Post subject: GLQuake Memory Saving Reply with quote

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:
tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );

with
Code:
tx = Hunk_AllocName (sizeof(texture_t), loadname );

remove
Code:
// the pixels immediately follow the structures
memcpy ( tx+1, mt+1, pixels);

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

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

change
Code:
R_InitSky (tx);

to
Code:
R_InitSky (mt);

Now on to the render.h changes.

change
Code:
void R_InitSky (struct texture_s *mt);   // called at level load

to
Code:
void R_InitSky (struct miptex_s *mt);   // called at level load

And lastly the gl_warp.c changes

replace
Code:
void R_InitSky (texture_t *mt)

with
Code:
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. Very Happy

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.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines


Last edited by mh on Tue Jun 15, 2010 10:13 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Downsider



Joined: 16 Sep 2008
Posts: 477

PostPosted: Tue Jun 15, 2010 10:06 pm    Post subject: Re: GLQuake Memory Saving Reply with quote

mh wrote:

In Mod_LoadTextures, replace:
Code:
tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );

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


It's the same? :O

Cool tutorial, though.
Back to top
View user's profile Send private message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Tue Jun 15, 2010 10:13 pm    Post subject: Reply with quote

You're right. Changed. Laughing
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
leileilol



Joined: 15 Oct 2004
Posts: 1321

PostPosted: Tue Jun 15, 2010 11:09 pm    Post subject: Reply with quote

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)
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group