3

我正在尝试将 PBO 复制到启用了 automipmapping 的纹理中,但似乎只生成了顶级纹理(换句话说,没有发生 mipmapping)。

我正在使用

//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:

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)

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);

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

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

据我了解,它应该向我显示纹理金字塔中的第一级而不是第零级纹理,我只得到一个空白的白色纹理。

如何以触发自动 mipmapping 的方式从 PBO 复制纹理?

谢谢。

4

1 回答 1

3

我是个白痴。上面的代码完美运行,问题是

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

不会从纹理中选择 mipmap 级别,而是从未 mipmap 的 pbo 中选择它。相反,您可以显示特定的 mipmapped 级别:

glTexEnvi(GL_TEXTURE_FILTER_CONTROL,GL_TEXTURE_LOD_BIAS, 4);
于 2010-10-07T18:05:14.367 回答