2

I have a texture which I use as a texture map. Its a 2048 by 2048 texture divided in squares of 256 pixels each. So I have 64 "slots". This map can be empty, partly filled or full. On screen I am drawing simple squares with a slot of the sprite map each.

The problem is that I have to update this map from time to time when the asset for the slot becomes available. These assets are being downloaded from the internet but the initial information arrives in advance so I can tell how many slots I will use and see the local storage to check which ones are already available to be drawn at the start.

For example. My info says there will be 10 squares, from these 5 are available locally so when the sprite map is initialized these squares are already filled and ready to be drawn. On the screen I will show 10 squares. 5 of them will have the image stored in the texture map for those slots, the remaining 5 are drawn with a temporal image. As a new asset for a slot is downloaded I want to update my sprite map (which is bound and used for drawing) with the new corresponding texture, after the draw is finished and the sprite map has been updated I set up a flag which tells OpenGL that it should start drawing with that slot instead of the temporal image.

From what I have read, there are 3 ways to update a sprite map.

1) Upload a new one with glTextImage2D: I am currently using this approach. I will create another updater texture and then simply swap it. But i frequently run into memory warnings.

2) Modify the texture with glTextSubImage2D: I cant get this to work, I keep getting memory access errors or black textures. I believe its either because the thread is not the same or I am accessing a texture in use.

3) Use Frame Buffer Objects: I could try this but I am not certain if i can Draw on my texturebuffer while it is already being used.

What is the correct way of solving this?

This is meant to be used on an iPhone so resources are limited.

Edit: I found this post which talks about something related here.

Unfortunately I dont think its focused on modifying a texture that is currently being used.

Community
  • 1
  • 1
Pochi
  • 13,391
  • 3
  • 64
  • 104

1 Answers1

0

the thread is not the same

OpenGL-ES API is absolutely not multi-threaded. Update your texture from main thread. Because your texture must be uploaded on gpu, glTextSubImage2D is the fastest and simplest path. Keep this direction :)

Render on a Frame Buffer (attached on your texture) is very fast for rendering data which are already on gpu. (not your case). And yes you can draw on a frame buffer bound to a texture (= a frame buffer which use the texture as color attachment).

Just one contrain: You can't read and write the same texture in one draw call (The texture attached to the current frame buffer can't be bound to a texture unit)

Vivien
  • 768
  • 6
  • 9
  • having it bind on a different tread was part of the issue, this along with having my texture coordinates inverted. – Pochi Jun 28 '13 at 07:33