OpenGL, what does glTexImage2D do?

What does it do gl.glTexImage2D

? The docs say it "loads texture data". But does this mean that the entire image is in GPU memory? I would like to use one large image file for texture mapping. Next: can I just use VBO for uv coordinates and coordinates to paint the texture?

That's right, I'm using words incorrectly here. I meant I had a 2D UV array and a 2D model array to subexpress the larger PNG image (in texture memory) onto separate tile models. My confusion here is that you don't know how fast these samples can be. Let's say I have a 5000x5000 pixel image. I load it as a texture. Then I create my own algorithm to extract parts of it for drawing. Where can I save the bandwidth for drawing these fragments? If I implement a LOD algorithm to determine which tiles are close, which are far, and which are off-camera, how do I manage each of those tiles in memory? Loaded question that I know but I am struggling to find the best implementation to get started.I am developing for mobile with OpenGL ES 2.0.

+3


source to share


2 answers


What exactly happens when you call glTexImage2D()

is system dependent, and you can't know unless you have developer tools that track GPU and memory usage.

The only thing that is guaranteed is that the data you pass to the call has been destroyed by the time the call returns (since the API definition allows you to modify / release the data after the call) and that the data is available to the GPU when it was being used for rendering. Meanwhile, something fair. Keep in mind that OpenGL is a very asynchronous API. When you make API calls, the work in question is mostly queued for later execution by the GPU and usually does not complete by the time the calls return. This can include calls to load data.

Also, not all GPUs have "GPU memory". In fact, if you look at them in number, very few of them do. Mobile GPUs have caches, but mostly not VRAM in the sense of traditional discrete GPUs. VRAM and cache management is highly system dependent.



With all the caveats above and the image of a GPU with VRAM: while it's possible they can load data into VRAM in a call glTexImage2D()

, I'd be surprised if this was accepted. It just wouldn't make a lot of sense to me. When the texture is loaded, you don't know how soon it will be used for rendering. Since you don't know if all textures will fit into VRAM (and they often won't), you may need to evict it from VRAM before using it. Which would obviously be very wasteful. As a general strategy, I think it will be much more efficient to load texture data into VRAM only when you have a paint call that uses it.

Things will be slightly different if the driver can be very confident that all the texture data will fit into VRAM. But with OpenGL, there really isn't a sane way to know this beforehand. And things get even more complicated because, at least on desktops, you can run multiple applications at the same time and VRAM is a shared resource.

+5


source


You're right.

glteximage2d is the function that actually moves the texture data to the gpu.

you will need to create a texture object first with glGenTextures () and then bind it using glBindTexture ().

there is a good example of this process in opbookl redbook example



you can use this texture with VBO. There are many ways to do this, but alternating vertex coordinates, texture coordinates, and vertex normals and then telling the GPU how to unpack them with multiple glVertexAttribPointer calls is the best option for performance.

you are on the right track with VBOs, the old fixed-pipeline GL file is stripped away, so you just need to learn VBO from the beginning.

this book is not 100% up to date, but it is complete and free and should be a great place to start learning VBO Open GL Book

+1


source







All Articles