View Full Version : Texture Swapping
10-11-2000, 12:29 PM
I want to use several large textures in my game. 1024x1024 is what I'm testing with.
The problem is 20 of those use up to much texture memory. I solved this by only loading four textures at a time since only four is close to the camera at a time and I made the textures further away smaller.
My problem is switching between textures. If I change one 1024x1024 texture each frame with glTexSubImage2d() or glTexImage2d() the framerate drops to about 5 (I have a Rage128) The textures are stored in pointers in RGB 24 bit.
each frame I do this:
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1024, 1024, GL_RGB, GL_UNSIGNED_BYTE, texture);
the texture is initially set up like this:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 1024, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, texture);
[This message has been edited by Erik Rufelt (edited 10-11-2000).]
10-12-2000, 01:18 AM
You want to use 20 1024x1024 textures on a Rage128? You fruitcake :-)
I once wrote an app that used live video from a FireWire camera as a texture. Coincidentally I also got to try it on a Rage128 and even for a 512x512 grayscale video at 15 fps, the card just couldn't keep up.
Back to business, though. It sounds like you're sending textures to the card for every frame, regardless of whether this is necessary or not. You could try to check which textures you'll need in the current frame, and only call glTexSubImage2D() if you need _different_ textures than for the last frame.
Keep in mind that uploading a 1024x1024 you will have to upload 1Mpixels. By looking at your code, I assume you get 16 bit colors since you don't specify a specific texture format, and even though you are still transfering 24 bit colors, and we get 3 Mbytes per texture to upload when you only need to upload 2 Mbyte. Smaller textures further away isn't going to solve the problem. But smaller textures closer to the camera will, some at least. You said you wan't large textures, but do you really NEED them. I think you have to reconsider, and probably go down to at least 512x512, since it will reduce the amount of memory to a fourth. If you do so, you will also be able to keep more textures in memory at a given time, and less texture swaps needen, and even less memory will be transfered.
[This message has been edited by Bob (edited 10-12-2000).]
10-12-2000, 07:27 AM
I won't change the texture every frame in my game, but if the framerate drops 5 even for just one frame it will still be too much.
I'm rendering a terrain which is very large so that's why I cant put on texture over the whole thing... I've tried using smaller tiles and it works but when switching to lower detail further away from the camera it doesn't quite work... that's why I wanted a 10000x10000 texture or something like that. Since this isn't possible I thought I'd use 10x10 1024x1024 textures. Since most of the terrain is just grass or sand or something I could use the same texture many times but I need aobut 20 total to make it look good... since a maximum of four can be close to the camera at ones it would work if I switched textures when another came closer and created a smaller copy of the texture for the one further away...
I read some other posts about reflection and someone wrote that the way to do it was rendering into the backbuffer and using that as a texture.... I thought that if that worked I could switch textures the same way.
If your ladscape mostly consists of grass and sand, I really think you should use tiled textures with multipass rendering using multitexturing. I use this technique in my landscape engine, and it's really easy and works nice and fast.
What you need is two tiled textures and a greyscale mask. The mask is used to determine what texture should be drawn. A grey value means that the two texture blend together. The mask doesn't have to be of the same size and resolution as the landscape. It can be a smaller texture that is stretched to fit the landscape.
10-14-2000, 03:37 AM
You can also use a lesser resolution, and add a detail texture over your landscape. In my experience, it will look very good, and keep a nice framerate.
If you want to keep using your method, you'd better ask yourself if you need to change the 1024x1024 texture every frame. You do not modify the whole texture, do you ? If you only change an area 128x128 of your texture, you only need to send this 128x128 area, not the rest. If you need to change all the pixels of the 1024x1024 texture, you probably have a problem in your design :)
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.