Uninitialized Texture in OpenGL

自作多情 提交于 2019-12-12 14:59:27

问题


Is there an easy and fast way to create an uninitialized texture in OpenGL?

My current approach looks like this:

std::vector<byte> nothing = std::vector<byte>([size of texture in bytes]);
glTexImage(
   target,
   level,
   internalFormat,
   size,
   border,
   format,
   type,
   nothing
   );

but this involves the upload of nothing.

Another approach would be to create an uninitialized buffer (by calling glBufferData without data) and to create the texture from this buffer. But afaik this has twice the memory footprint (and i am on a low memory budget).

Is there a good way to create a texture that will be written to later without using bandwidth or extra memory?


回答1:


Just pass a null pointer for data. This is how it's specified in OpenGL since version 1. From the OpenGL 1.2 specification, section 3.8.1, page 118, last paragraph:

If the data argument of TexImage1D, TexImage2D, or TexImage3D is a null pointer (a zero-valued pointer in the C implementation), a one-, two-, or three-dimensional texture array is created with the specified target, level, internalformat, width, height, and depth, but with unspecified image contents. In this case no pixel values are accessed in client memory, and no pixel processing is performed. Errors are generated, however, exactly as though the data pointer were valid.



来源:https://stackoverflow.com/questions/5660374/uninitialized-texture-in-opengl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!