| 52 | } |
| 53 | |
| 54 | bool FrameBufferObject::Initialize(Dimensions dims) |
| 55 | { |
| 56 | bool haveFBO = OPENCSG_HAS_EXT(ARB_framebuffer_object) != 0; |
| 57 | if (!haveFBO) |
| 58 | return false; |
| 59 | |
| 60 | dimensions = dims; |
| 61 | |
| 62 | glGenFramebuffers(1, &framebufferID); |
| 63 | glGenRenderbuffers(1, &depthID); |
| 64 | glGenTextures(1, &textureID); |
| 65 | |
| 66 | glBindFramebuffer(GL_FRAMEBUFFER, framebufferID); |
| 67 | |
| 68 | GLenum target = GL_TEXTURE_2D; |
| 69 | if ( !OPENCSG_HAS_EXT(ARB_texture_non_power_of_two) |
| 70 | && ( OPENCSG_HAS_EXT(ARB_texture_rectangle) |
| 71 | || OPENCSG_HAS_EXT(EXT_texture_rectangle) |
| 72 | || OPENCSG_HAS_EXT(NV_texture_rectangle))) |
| 73 | target = GL_TEXTURE_RECTANGLE_ARB; |
| 74 | |
| 75 | glBindTexture(target, textureID); |
| 76 | glTexImage2D(target, 0, GL_RGBA8, GetWidth(), GetHeight(), 0, GL_RGBA, GL_INT, 0); |
| 77 | glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 78 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 79 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, textureID, 0); |
| 80 | |
| 81 | glBindRenderbuffer(GL_RENDERBUFFER, depthID); |
| 82 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, GetWidth(), GetHeight()); |
| 83 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthID); |
| 84 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthID); |
| 85 | |
| 86 | GLenum status; |
| 87 | status = glCheckFramebufferStatus(GL_FRAMEBUFFER); |
| 88 | if (status == GL_FRAMEBUFFER_UNSUPPORTED) { |
| 89 | Reset(); |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | glBindFramebuffer(GL_FRAMEBUFFER, oldFramebufferID); |
| 94 | glBindTexture(target, 0); |
| 95 | |
| 96 | textureTarget = target; |
| 97 | |
| 98 | initialized = true; |
| 99 | |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | // Releases frame buffer objects |
| 104 | bool FrameBufferObject::Reset() |