在我的代码中,我渲染了Mandelbrot分形,我注意到当我将分辨率从7680x4320提高到15360x8640时,输出图像变为空白,没有报告OpenGL错误。
尺寸在允许的16384x16384限制范围内,并且GPU内存没有溢出,因为我没有出现内存不足错误。
代码:
constexpr GLsizei Width = 15360;
constexpr GLsizei Height = 8640;
// Note: I'm only using GLFW for the OpenGL context
glfwInit();
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
GLFWwindow* window = glfwCreateWindow(800, 600, "Mandelbrot Generator", nullptr, nullptr); // the resolution of the window is not important
glfwMakeContextCurrent(window);
// Note: I'm wrapping OpenGL calls to allow for glGetError() to be called for each func
// Code to generate framebuffer
gl::GenFramebuffers(1, &fbo);
gl::GenRenderbuffers(1, &rbo);
gl::BindRenderBuffer(rbo);
gl::SetRenderbufferStorage(gl::e_RGBA, Width, Height);
gl::BindFramebuffer(gl::e_DrawFramebuffer, fbo);
gl::SetFramebufferRenderBuffer(gl::e_DrawFramebuffer, gl::e_ColorAttachment0, rbo);
// Rendering
gl::BindFramebuffer(gl::e_DrawFramebuffer, fbo);
{
gl::Clear(gl::e_ColorBufferBit);
gl::SetViewport(0, 0, Width, Height);
gl::BindBuffer(gl::e_ArrayBuffer, rect); // rect is a fullscreen quad
gl::DrawArrays(gl::e_Triangles, 0, 6);
gl::BindBuffer(gl::e_ArrayBuffer, 0);
}
gl::BindFramebuffer(gl::e_DrawFramebuffer, 0);
// Saving image
std::vector<GLubyte> pixels(Width * Height * 4);
{
gl::BindFramebuffer(gl::e_ReadFramebuffer, fbo);
gl::ReadPixels(0, 0, Width, Height, gl::e_RGBA, gl::e_UnsignedByte, pixels.data());
}
lodepng::encode("mandelbrot.png", pixels, Width, Height);