如何使用Mipmapping将CUDA生成的PBO复制到Texture [英] How to copy CUDA generated PBO to Texture with Mipmapping

查看:376
本文介绍了如何使用Mipmapping将CUDA生成的PBO复制到Texture的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将PBO复制到启用了自动映射映射的纹理中,但是似乎只有顶级纹理被生成(换句话说,没有发生mip映射)。

I'm trying to copy a PBO into a Texture with automipmapping enabled, but it seems only the top level texture is generated (in other words, no mipmapping is occuring).

我正在使用

//Generate a buffer ID called a PBO (Pixel Buffer Object)
glGenBuffers(1, pbo);
//Make this the current UNPACK buffer
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, *pbo);
//Allocate data for the buffer. 4-channel 8-bit image
glBufferData(GL_PIXEL_UNPACK_BUFFER, size_tex_data, NULL, GL_DYNAMIC_COPY);
cudaGLRegisterBufferObject(*pbo);

我使用

// Enable Texturing
glEnable(GL_TEXTURE_2D);

// Generate a texture identifier
glGenTextures(1,textureID);

// Make this the current texture (remember that GL is state-based)
glBindTexture( GL_TEXTURE_2D, *textureID);

// Allocate the texture memory. The last parameter is NULL since we only
// want to allocate memory, not initialize it
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, size_x, size_y, 0,
GL_RGBA, GL_FLOAT, NULL);

// Must set the filter mode, GL_LINEAR enables interpolation when scaling
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

稍后在内核中我使用类似的方法修改PBO:

Later in a kernel I modify the PBO using something like:

float4* aryPtr = NULL;
cudaGLMapBufferObject((void**)&aryPtr, *pbo);

//Pixel* gpuPixelsRawPtr = thrust::raw_pointer_cast(&gpuPixels[0]);
//... do some cuda stuff to aryPtr ...

//If we don't unmap the PBO then OpenGL won't be able to use it:
cudaGLUnmapBufferObject(*pbo);



现在,在使用上面生成的纹理绘制到屏幕之前,我调用:
注意rtMipmapTex = * textureID上面和rtResultPBO = * pbo上面)

Now, before I draw to the screen using the texture generated above I call: (note that rtMipmapTex = *textureID above and rtResultPBO = *pbo above)

glEnable(GL_DEPTH);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, rtMipmapTex);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, rtResultPBO);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, canvasSize.x, canvasSize.y, GL_RGBA, GL_FLOAT, NULL);

这一切都可以正常显示纹理。但是,如果我将最后一行改为

This all works fine and correctly displays the texture. But, if I change that last line to

glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, canvasSize.x, canvasSize.y, GL_RGBA, GL_FLOAT, NULL);

根据我的理解,而不是纹理金字塔中的零级纹理,我只是得到一个空白的白色纹理。

which, as far as I understand, should show me the first level instead of the zeroth level texture in the texture pyramid, I just get a blank white texture.

如何从PBO复制纹理, -mipmapping是否被触发?

How do I copy the texture from the PBO in such a way that the auto-mipmapping is triggered?

谢谢。

推荐答案

蠢货。上面的代码工作完美,问题是

I was being an idiot. The above code works perfectly, the problem was that

glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, canvasSize.x, canvasSize.y, GL_RGBA, GL_FLOAT, NULL);

不从纹理中选择mipmap级别,它从pbo中选择,不是mipmapped。您可以使用以下方式显示特定的映射级别:

doesn't select the mipmap level from the texture, it selects it from the pbo, which is not mipmapped. Instead you can display the particular mipmapped level with:

glTexEnvi(GL_TEXTURE_FILTER_CONTROL,GL_TEXTURE_LOD_BIAS, 4);

这篇关于如何使用Mipmapping将CUDA生成的PBO复制到Texture的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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