// Compile with c++ ./depth_stencil_unbind.cc -Wall $(pkg-config --cflags --libs glew sdl2 gl) -o depth_stencil_unbind #include #include #include #include #include #define assert_gl_no_error assert(glGetError() == GL_NO_ERROR) int main() { SDL_Init(SDL_INIT_VIDEO); SDL_Window * const window = SDL_CreateWindow( "Repeated creation of program binaries", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 256, 256, SDL_WINDOW_OPENGL); if (!window) { std::cerr << "Could not create window: " << SDL_GetError() << '\n'; return 1; } SDL_GLContext gl_context = SDL_GL_CreateContext(window); const GLenum glew_error = glewInit(); if (glew_error != GLEW_OK) { std::cerr << "Could not initialise glew : " << glewGetErrorString(glew_error)<< '\n'; return 1; } GLuint renderbuffer; glGenRenderbuffers(1, &renderbuffer); assert(glGetError() == GL_NO_ERROR); glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); assert(glGetError() == GL_NO_ERROR); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 256, 256); assert(glGetError() == GL_NO_ERROR); GLuint framebuffer; glGenFramebuffers(1, &framebuffer); assert(glGetError() == GL_NO_ERROR); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer); assert(glGetError() == GL_NO_ERROR); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderbuffer); assert(glGetError() == GL_NO_ERROR); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0); assert(glGetError() == GL_NO_ERROR); GLint attachment_type; glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachment_type); assert(glGetError() == GL_NO_ERROR); assert(attachment_type == GL_NONE); SDL_GL_DeleteContext(gl_context); SDL_DestroyWindow(window); SDL_Quit(); }