OpenGL 中未初始化的纹理 [英] Uninitialized Texture in OpenGL

查看:86
本文介绍了OpenGL 中未初始化的纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单快捷的方法可以在 OpenGL 中创建未初始化的纹理?

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.

另一种方法是创建一个未初始化的缓冲区(通过调用没有数据的 glBufferData)并从该缓冲区创建纹理.但是 afaik 这有两倍的内存占用(而且我的内存预算很低).

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 起在 OpenGL 中的指定方式.来自 OpenGL 1.2 规范,第 3.8.1 节,第 118 页,最后一段:

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:

如果 TexImage1D 的 data 参数,TexImage2D 或 TexImage3D 为空指针(零值指针在C 实现)、一个、两个或三维纹理数组是使用指定的目标创建,级别,内部格式,宽度,高度,和深度,但具有未指定的图像内容.在这种情况下没有像素值在客户端内存中访问,并且没有进行像素处理.错误生成,然而,完全一样尽管数据指针有效.

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.

这篇关于OpenGL 中未初始化的纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆