X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fframebuffer.cpp;h=f3b1bd90768f6382909196a3b668742ae174031a;hp=2302b6ca5d817fc9b84e5d583fb1da10036c446f;hb=da646c739f87bf28c5a7af2bc180b93b3444321b;hpb=a851cf197844a2eb15fd5ee2c350ee296e415dca diff --git a/src/framebuffer.cpp b/src/framebuffer.cpp index 2302b6c..f3b1bd9 100644 --- a/src/framebuffer.cpp +++ b/src/framebuffer.cpp @@ -7,6 +7,7 @@ void FrameBuffer::Create(int w, int h) { if (m_render_texture) { + // FrameBuffer was already Created, destroy it before creating again Destroy(); } m_width = w; @@ -15,7 +16,7 @@ void FrameBuffer::Create(int w, int h) glGenFramebuffers(1, &m_render_fbo); glBindTexture(GL_TEXTURE_2D, m_render_texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glBindFramebuffer(GL_FRAMEBUFFER, m_render_fbo); @@ -27,25 +28,26 @@ void FrameBuffer::Create(int w, int h) void FrameBuffer::Destroy() { - if (!m_render_texture) return; + if (!m_render_texture) return; // wasn't Created (or already Destroyed) glDeleteFramebuffers(1, &m_render_fbo); glDeleteTextures(1, &m_render_texture); } void FrameBuffer::Bind() { + // will draw to this FrameBuffer glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_render_fbo); } void FrameBuffer::UnBind() { - glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); // will both draw to and read pixels from screen } void FrameBuffer::Blit() { - glBindFramebuffer(GL_READ_FRAMEBUFFER, m_render_fbo); - glBlitFramebuffer(0, 0, m_width, m_height, 0, 0, m_width, m_height, GL_COLOR_BUFFER_BIT, GL_NEAREST); + glBindFramebuffer(GL_READ_FRAMEBUFFER, m_render_fbo); // read pixels from this FrameBuffer + glBlitFramebuffer(0, 0, m_width, m_height, 0, 0, m_width, m_height, GL_COLOR_BUFFER_BIT, GL_NEAREST); // draw pixels } void FrameBuffer::Clear(float r, float g, float b, float a)