开发者

Uninitialized Texture in OpenGL

Is there an easy and fast way to create an uninitialized texture in OpenGL开发者_C百科?

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜