/** * Copyright (c) 2025 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "framebuffer.h" #include "assert/assert.h" #include "util/memory.h" #if RENDER_USE_FRAMEBUFFER void frameBufferInit( framebuffer_t *framebuffer, const uint32_t width, const uint32_t height ) { assertNotNull(framebuffer, "Framebuffer cannot be NULL"); assertTrue(width > 0 && height > 0, "Width & height must be greater than 0"); memoryZero(framebuffer, sizeof(framebuffer_t)); textureInit(&framebuffer->texture, width, height, NULL); // Generate the framebuffer object using EXT glGenFramebuffersEXT(1, &framebuffer->id); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer->id); // Attach the texture to the framebuffer glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, framebuffer->texture.id, 0 ); // Check if the framebuffer is complete if(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) { assertUnreachable("Framebuffer is not complete"); } // Unbind the framebuffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); } void frameBufferBind(const framebuffer_t *framebuffer) { if(framebuffer == NULL) { glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); return; } // Bind the framebuffer for rendering glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer->id); } void frameBufferDispose(framebuffer_t *framebuffer) { assertNotNull(framebuffer, "Framebuffer cannot be NULL"); glDeleteFramebuffersEXT(1, &framebuffer->id); textureDispose(&framebuffer->texture); } #endif