A glTexImage2D question
If I use a glTexImage2D
call to create a texture with a buffer like this:
glTexImage2D(GL_TEXTURE_2D /* target*/,
0 /* level */,
GL_RGBA /* internal format */,
width /* w */,
height /* h */,
0 /* border */,
GL_RGBA /* format (RGBA 4)*/,
GL_UNSIGNED_BYTE /* type */,
buffer /* pixel buffer */);
开发者_开发百科
Can I modify the buffer and expect the texture to change with it?
Or is the texture finalized after the call?
No, OpenGL will create it's own copy of the texture so you can't modify it without copying it back and forth (but this also means you're able to reuse or free the buffer.
If you want to change a portion of the texture, you'll often use glTexSubImage2D
. Note that this function expects the new data to be contiguous; so if you've only changed a small square in the middle of your texture, it's not the best idea to make the change in your original buffer because then you'd have to send all of the pixels for the rows you've changed instead of just the affected columns.
精彩评论