将像素传递给glTexImage2D()后会发生什么? [英] What happens to pixels after passing them into glTexImage2D()?

查看:190
本文介绍了将像素传递给glTexImage2D()后会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果例如我创建像素数组,像这样:

  int * getPixels()
{
int * pixels = new int [10];
pixels [0] = 1;
pixels [1] = 0;
pixels [1] = 1;
// etc ...
}

glTexImage2D(...,getPixels()); gltexImage2D是否使用该引用或将像素复制到自己的内存中?


如果答案是前者,那么我应该如何做?

  int * p = getPixels(); 
glTexImage2D(...,p);

/ *只是改为删除[],因为删除
*只会删除第一个元素! * /
delete [] p;

解决方案

://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/teximage2d.html>手册页,听起来像glTexImage2D分配了自己的内存。
这将是有意义的,理想的OpenGL API将发送数据存储在显卡本身(如果驱动程序/实现/等允许)。


在GL版本1.1或更高版本中,像素可能是空指针。
在这种情况下,纹理内存被分配以容纳宽度和高度高度的纹理
。然后你可以下载子纹理到
初始化这个纹理内存。如果用户尝试
将纹理
图像的未初始化部分应用于原始图像,则该图像未定义。


所以,我想象一下,一旦你生成你的纹理释放内存没有危害。


If for example I create an array of pixels, like so:

int *getPixels()
{
    int *pixels = new int[10];
    pixels[0] = 1;
    pixels[1] = 0;
    pixels[1] = 1;
    // etc...
}

glTexImage2D(..., getPixels());

Does glTexImage2D use that reference or copy the pixels into it's own memory?

If the answer is the former, then should I do the following?

int *p = getPixels();
glTexImage2D(..., p);

/* Just changed to delete[], because delete
 * would only delete the first element! */
delete[] p;

解决方案

From this quote in the man page, it sounds like glTexImage2D allocates its own memory. This would make sense, ideally the OpenGL API would send data to be stored on the graphics card itself (if drivers/implementation/etc permitted).

In GL version 1.1 or greater, pixels may be a null pointer. In this case texture memory is allocated to accommodate a texture of width width and height height. You can then download subtextures to initialize this texture memory. The image is undefined if the user tries to apply an uninitialized portion of the texture image to a primitive.

So yea, I'd imagine there is no harm in freeing the memory once you've generated your texture.

这篇关于将像素传递给glTexImage2D()后会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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