Added screen
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "framebuffer.h"
|
||||
#include "display/display.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
@@ -19,6 +20,41 @@ void frameBufferInitBackbuffer() {
|
||||
FRAMEBUFFER_BOUND = &FRAMEBUFFER_BACKBUFFER;
|
||||
}
|
||||
|
||||
#if DISPLAY_SIZE_DYNAMIC == 1
|
||||
void frameBufferInit(
|
||||
framebuffer_t *framebuffer,
|
||||
const uint32_t width,
|
||||
const uint32_t height
|
||||
) {
|
||||
#if DISPLAY_SDL2 == 1
|
||||
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, GL_RGBA, (texturedata_t){
|
||||
.rgba = { .colors = NULL }
|
||||
});
|
||||
|
||||
glGenFramebuffersEXT(1, &framebuffer->id);
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer->id);
|
||||
|
||||
glFramebufferTexture2DEXT(
|
||||
GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
||||
GL_TEXTURE_2D, framebuffer->texture.id, 0
|
||||
);
|
||||
|
||||
if(
|
||||
glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) !=
|
||||
GL_FRAMEBUFFER_COMPLETE_EXT
|
||||
) {
|
||||
assertUnreachable("Framebuffer is not complete");
|
||||
}
|
||||
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t frameBufferGetWidth(const framebuffer_t *framebuffer) {
|
||||
#if DISPLAY_SDL2
|
||||
if(framebuffer == &FRAMEBUFFER_BACKBUFFER) {
|
||||
@@ -31,8 +67,7 @@ int32_t frameBufferGetWidth(const framebuffer_t *framebuffer) {
|
||||
#endif
|
||||
}
|
||||
|
||||
assertUnreachable("Framebuffer width not implemented");
|
||||
return 0;
|
||||
return framebuffer->texture.width;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -48,8 +83,7 @@ int32_t frameBufferGetHeight(const framebuffer_t *framebuffer) {
|
||||
#endif
|
||||
}
|
||||
|
||||
assertUnreachable("Framebuffer height not implemented");
|
||||
return 0;
|
||||
return framebuffer->texture.height;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -78,6 +112,7 @@ void frameBufferBind(const framebuffer_t *framebuffer) {
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer->id);
|
||||
#endif
|
||||
}
|
||||
|
||||
glViewport(
|
||||
0, 0,
|
||||
frameBufferGetWidth(framebuffer), frameBufferGetHeight(framebuffer)
|
||||
@@ -109,11 +144,6 @@ void frameBufferClear(uint8_t flags, color_t color) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes of the framebuffer using EXT methods.
|
||||
*
|
||||
* @param framebuffer The framebuffer to dispose of.
|
||||
*/
|
||||
void frameBufferDispose(framebuffer_t *framebuffer) {
|
||||
assertNotNull(framebuffer, "Framebuffer cannot be NULL");
|
||||
|
||||
@@ -125,56 +155,8 @@ void frameBufferDispose(framebuffer_t *framebuffer) {
|
||||
#if DISPLAY_SIZE_DYNAMIC == 0
|
||||
assertUnreachable("Dynamic size framebuffers not supported");
|
||||
#else
|
||||
textureDispose(&framebuffer->texture);
|
||||
glDeleteFramebuffersEXT(1, &framebuffer->id);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
// #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, GL_RGBA, 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
|
||||
}
|
Reference in New Issue
Block a user