Texture management strategies?

I

Ilmari Heikkinen

Hello, I'm writing this OpenGL engine thing, and am currently wondering
about a good way to manage loading, replacing and disposing of
textures.

It's doable to preload 20 images as rgba data into system memory, but
trying to preload them into GL textures gets very slow. So there's a
need to load textures into GL on the fly and delete unused textures.

This is roughly what I'm currently doing every three seconds in a
slideshow program:

tex_id = renderer.textures[image.texture.object_id]
if tex_id
image_filename = images[counter]
GL.PushAttrib(GL::TEXTURE_BIT)
GL.BindTexture(TEXTURE_2D, tex_id)
bitmap = load_image(image_filename)
GL.TexImage2D(TEXTURE_2D,
0, 4,
bitmap.width, bitmap.height,
0, color_mode, pixel_format,
bitmap.pixels)
GL.PopAttrib()
end

It's not very pretty... Instead of the whole
bindtexture-texsubimage2d-exposing-graphics-API-blah, I'd like to do
this:

image.texture = images[counter]

And have the texture manager take care of disposing unused textures.


image.replace_texture( images[counter] )

Would be an alternative for cases where the texture size stays the same
but the contents change (like with video.)


But I haven't really done this sort of stuff before. Any pointers on
where to start or what would be a good way to do this? Books on the
subject ?:)


Grateful for any help
- Ilmari
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top