optimizing texture size

Blitz3D Forums/Blitz3D Beginners Area/optimizing texture size

Osoko(Posted 2006) [#1]
Hi there,
I have a big X file with many objects and textures in it.
Each object has only one texture applied to it.
I want to deal with the texture size, according to the distance from the camera.
I've 3 textures size for every objects, small medium and big.
The name of the texture define the size, Mytexture0.jpg,Mytexture1.jpg,Mytexture2.jpg
How to correctly access the hierarchy and change the texture
?


Mustang(Posted 2006) [#2]
Don't. Blitz3D & DirectX automatically generates set of different sized textures called mip-maps. There is no need for the user to do anything by themselves if it's just size related. Changing textures by yourself doesn't make your program faster, probably just the opposite.

And if you load only ONE .X file, then you have one object with lot's of textures, not many objects with one texture. If you want them to be individual objects you'll have break the big .X file to many smaller ones.


Osoko(Posted 2006) [#3]
Well, i want to do this for reduce the amount of texture used in my project. It's in use with freetexture.
The only one X file is more practice for me, or I will have to export a lot of objects, which takes times.
In my X file, meshes are separate ( not welded ), and as i say, one texture for one meshe.
In fact, with 3 set of texture, i have a 128, 64 and 32 mo demo. I want to have just one, which can optimize the amount of memory.
For example, the 128 mo demo has asbolutly no optimisation, i thought that free the big texture for distant objects and replace it with a small one could help.


jfk EO-11110(Posted 2006) [#4]
When you load the mesh with LoadAnimMesh instead of LoadMesh then you'll be able to access the sub-meshes as children entities (using a recursive hierarchy parser). You may then track down the brushes and their textures as demonstrated in the SaveB3D Example (Code archives) and replace the textures by downscaled copies (probalby scaled using a temporary imagebuffer and Copyrect).

But I have to agree with Mustang, there isn't much you can optimize, other than replacing the texture files by smaller versions. Note: when 2 Objects use the same texture with the same texture flags, Blitz has already optmized the usage and holds only one copy of it in memory, so it wouldn't make sense to replace the texture of the one that is far away, if the other one is located near the camera, but it would eat even more Vram.


Osoko(Posted 2006) [#5]
There is no sharing of object, i'm making an very old street of my city. Every house is unique. As i'm making a photorealistic work i'm going to explode my memory budget ( i have 256 but want the demo to work with 128 or 64 too). I can't make any optimisation like in a normal game, i'm working on a church built in 1230 and very old houses ( 1483, for one of the most exceptionnal ). My work is not a game, but a virtual visite of these monuments. I'm not an expert programmer, but Blitz permits me too achieve my goal : it works great !
Now, i'm looking for optimisation.


jfk EO-11110(Posted 2006) [#6]
virtual visite? so people can walk to the distant buildings? So you have to swap the textures on the fly? This will freze the app, in the worst case for a few seconds, because DirectX has to send the textures to the Vram, that takes some time.

I would first try to run the 256 version with only 64 Megs, probably DirectX is doing this already using virtual Vram and Mipmapping.

Anyway, if you want to try it, it's possible, altough I'm not sure if it will help a lot. Here's the Source that shows how to track down the textures used by a bursh and the brush used by a surface:
http://www.blitzbasic.com/codearcs/codearcs.php?code=866
(note the order of the surfaces differs each time you run the app. Note: GetBrushTexture creates a texture clone and GetSurfaceBrush creates a brush clone, both should be deleted after the identification of the used texture file)

If you want to access the sub-meshes as children (using LoadAnimMesh instead of LoadMesh) then you may use a Hierarchy parser like this:
http://www.blitzbasic.com/codearcs/codearcs.php?code=615
where this one shows how to determine if a child is a mesh or a pivot or a bone etc:
http://www.blitzbasic.com/codearcs/codearcs.php?code=1170

If every sub mesh is using only one texture then you probably don't need to track down the textures as seen in SaveB3D, you could also indentify a child by its entity name (probably simply store the texture filename in the entity name).