Question

I have a dynamic heightmap for my terrain, its going to be modified almost every frame, should i use gltexsubimage2d and texture as heightmap or update vertices buffer every frame instead of creating vbo? What approach should be faster? I understand that i am loosing hardware bilinear filter sending data via vbo, but according to google gltexxubimage2d causes problems on mobile devices and it does not look like i could use it frame by frame because its slow.

Actually question should be : Is sending data to gpu memory in texture faster than using vertex attribute?, is it implementation dependant? Do any body achieved texture updating in opengl in android to for example use quad as a video playback canvas? I understand that this question is probably a nonsense on newer devices like mali-400 or tegra3 where both approaches should be susficient in performance for me, but i would like to have compatibility with adreno200 or sgx535.

Was it helpful?

Solution

I would advice to go for the texture modification versus vertex manipulation.

This because the VBO manipulation requires much more data move and memory bandwidth than modifying a texture memory to memory.

Consider that each vertex has at least 5 items (x+y+z+tx+ty) but oftern 8 items considering the normals which are very typical in any lighting algorithm.

On the other side, instead, a texture is just one value per vertex (typically).

One very common mistake of this solution which causes a lot of slowness, is that many rookies (and I am sure this not your case) enable the mipmap generation for the texture they use for their heightmap.

Make sure to disable it:

glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE );

Another advice is to take the format of the pixels of the texture to the very minimum requirement, having an 8888 is much heavier than having a 444 pixel resolution. This translates in a much much faster memory transfer each frame.

I hope this helps in some way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top