I am wirting code in MacOS which only support OpenGL 4.1 now.
and I create an framebuffer color attachment for mouse picking which return an int value.
我在MacOS中编写代码,现在只支持OpenGL 4.1。我创建了一个帧缓冲区颜色附件,用于鼠标拾取,它返回一个int值。
// glsl code here
layout(location = 1) out int color2;
...
void main(){
...
color2 = 50;
}
// create RED_INTEGER color attachment
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32I, width, height, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, nullptr);
And now I need to clear this buffer by value=-1.
现在,我需要通过值=-1来清除该缓冲区。
I know there are glClearTexImage()in OpenGL 4.4 like:
我知道OpenGL 4.4中有glClearTexImage(),比如:
int value = -1;
glClearTexImage(colorAttachmentID, 0, RED_INTEGER, GL_INT, &value);
Is there any way to clear such buffer below OpenGL 4.1?
有没有办法在OpenGL 4.1下清除这样的缓冲区?
更多回答
优秀答案推荐
The glClearBuffer*
family of functions can be used to clear specific framebuffer attached images. There are integer forms of these functions.
glClearBuffer* 系列函数可用于清除特定的帧缓冲区附加图像。这些函数有整数形式。
Your code would look like:
您的代码将如下所示:
GLint values[4] = {-1};
glClearBuffer(GL_COLOR, X, &value);
Where X
is the color attachment index, the number you added to GL_COLOR_ATTACHMENT0
when you attached it to the framebuffer.
其中,X是颜色附加索引,即在将GL_COLOR_ATTACHMENT0附加到帧缓冲区时添加到它的数字。
Be aware that buffer clearing always respects the scissor test if it is enabled. So it will only clear within that region.
请注意,如果启用了剪刀测试,则缓冲区清除始终遵循剪刀测试。因此,它只会在该地区内清除。
Also, don't treat this function as an alternative to glClearTexImage
. It is the correct function to use if the image you're clearing is being used as a framebuffer image.
此外,不要将此函数视为glClearTexImage的替代函数。如果要清除的图像被用作帧缓冲区图像,则使用该函数是正确的。
更多回答
我是一名优秀的程序员,十分优秀!