Jump to content
  • Advertisement
Sign in to follow this  
Chris_F

OpenGL Dynamic Textures

This topic is 2567 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I'm new to OpenGL and experimenting with textures at the moment. Currently I have a buffer in main memory that I'm drawing 2d images to (CPU) and then every frame I upload it to a OpenGL texture using glTexImage2d. Is this the best approach or is there a better way? It seems to choke once the texture size exceeds 1024x1024. Next I'm thinking about using the ogg theora library to decode video to a texture, and ideally I'd like to be able to handle 1080p video without issue.

Share this post


Link to post
Share on other sites
Advertisement
If you provide the texture data in the right format (so that the driver doesn't have to convert it) then the only thing you can improve on is hiding the latency. Basically what glTexImage2D does is that it memcpys the data into a "pinned"/"page locked" memory region and sets up (and waits for) an DMA-transfer from that memory region into the gfx card. All the while, the glTexImage2D call blocks.

What you can do (depending on your application) is to decode some texture frames on the cpu in advance and do the uploading in parallel with your other cpu/gpu stuff. The mechanism that OpenGL provides for this is called the pixel buffer object. The basic idea is that you create your own "pinned"/"page locked" piece of memory (the so called pixel buffer) and then memcpy your stuff into that. Afterwards you can kick of an asynchronous (non blocking) dma transfer into the gfx card which means that you can utilize your cpu while the texture is being uploaded.

The following link provides a very good introduction to the topic and also focuses on your specific problem of streaming (video) frames:
http://www.songho.ca/opengl/gl_pbo.html

Share this post


Link to post
Share on other sites

So I'm new to OpenGL and experimenting with textures at the moment. Currently I have a buffer in main memory that I'm drawing 2d images to (CPU) and then every frame I upload it to a OpenGL texture using glTexImage2d. Is this the best approach or is there a better way? It seems to choke once the texture size exceeds 1024x1024. Next I'm thinking about using the ogg theora library to decode video to a texture, and ideally I'd like to be able to handle 1080p video without issue.


Don't use glTexImage2d. Use glTexSubImage2dto update.

and also
http://www.opengl.or...and_pixel_reads

and also
http://www.opengl.or...ed_formats_.233

and yes, use PBO.

Share this post


Link to post
Share on other sites
Currently I have a buffer in main memory that I'm drawing 2d images to (CPU)[/quote]
Well what are you trying to do? You mention Video but also 2d image(s), which made me think you are taking multiple 2d images and putting them into 1 image.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!