As ThomasD suggested in the comments GL_DEPTH24_STENCIL8
worked.
OpenGL invalid operation: copy depth render buffer to default depth buffer
-
31-05-2022 - |
Question
I tried to follow Copying depth render buffer to the depth buffer but it does not work for me. Here is my complete example:
#include <GL/glew.h>
#include <GL/glfw.h>
#include <GL/glu.h>
#include <iostream>
typedef unsigned int uint;
int main()
{
if (glfwInit() != 1)
{
return 1;
}
const uint width = 256;
const uint height = 256;
if (glfwOpenWindow(width, height, 8, 8, 8, 0, 24, 0, GLFW_WINDOW) != 1)
{
return 1;
}
GLenum err = glewInit();
if (GLEW_OK != err)
{
std::cerr << glewGetErrorString(err) << std::endl;
return 1;
}
GLuint r;
glGenRenderbuffers(1, &r);
glBindRenderbuffer(GL_RENDERBUFFER, r);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
GLuint r2;
glGenRenderbuffers(1, &r2);
glBindRenderbuffer(GL_RENDERBUFFER, r2);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
GLuint f;
glGenFramebuffers(1, &f);
glBindFramebuffer(GL_FRAMEBUFFER, f);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, r);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, r2);
std::cout << (glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) << std::endl;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
std::cout << gluErrorString(glGetError()) << std::endl;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, f);
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
std::cout << gluErrorString(glGetError()) << std::endl;
return 0;
}
Output I get:
1
no error
invalid operation
The 24
in glfwOpenWindow
is the number of depth bits. What am I doing wrong?
Solution 2
OTHER TIPS
The parameters to glfwOpenWindow
are specifying the desired values. However, it's entirely possible that your driver doesn't support the exact format you're asking for (24 bit color, 24 bit depth, no alpha, no stencil). GLFW will attempt to find the best match while meeting your minimums.
In this case it's probably giving you the most standard format of RGBA color (32 bit) and a 24/8 bit depth/stencil buffer, or it could be creating a 32 bit depth buffer. You'd actually need to call glfwGetWindowParam
to query the depth and stencil bits for the default framebuffer, and then build your renderbuffers to match that.