diff --git a/GL/flush.c b/GL/flush.c index e64036c..6352b9d 100644 --- a/GL/flush.c +++ b/GL/flush.c @@ -68,6 +68,7 @@ void APIENTRY glKosInit() { initContext(); initLights(); initImmediateMode(); + initFramebuffers(); _glKosInitTextures(); diff --git a/GL/framebuffer.c b/GL/framebuffer.c index d699fab..ae5f3f8 100644 --- a/GL/framebuffer.c +++ b/GL/framebuffer.c @@ -1,19 +1,58 @@ +#include #include "private.h" -static GLuint ACTIVE_FRAMEBUFFER = 0; + +typedef struct { + GLuint index; + GLuint texture_id; + GLboolean is_complete; +} FrameBuffer; + +static FrameBuffer* ACTIVE_FRAMEBUFFER = NULL; static NamedArray FRAMEBUFFERS; -void APIENTRY glGenFramebuffersEXT(GLsizei n, GLuint* framebuffers) { +void initFramebuffers() { + named_array_init(&FRAMEBUFFERS, sizeof(FrameBuffer), 32); +} +void APIENTRY glGenFramebuffersEXT(GLsizei n, GLuint* framebuffers) { + TRACE(); + + while(n--) { + GLuint id = 0; + FrameBuffer* fb = (FrameBuffer*) named_array_alloc(&FRAMEBUFFERS, &id); + fb->index = id; + fb->is_complete = GL_FALSE; + fb->texture_id = 0; + + *framebuffers = id; + framebuffers++; + } } void APIENTRY glDeleteFramebuffersEXT(GLsizei n, const GLuint* framebuffers) { + TRACE(); + while(n--) { + FrameBuffer* fb = (FrameBuffer*) named_array_get(&FRAMEBUFFERS, *framebuffers); + + if(fb == ACTIVE_FRAMEBUFFER) { + ACTIVE_FRAMEBUFFER = NULL; + } + + named_array_release(&FRAMEBUFFERS, *framebuffers++); + } } void APIENTRY glBindFramebufferEXT(GLenum target, GLuint framebuffer) { + TRACE(); + if(framebuffer) { + ACTIVE_FRAMEBUFFER = (FrameBuffer*) named_array_get(&FRAMEBUFFERS, framebuffer); + } else { + ACTIVE_FRAMEBUFFER = NULL; + } } void APIENTRY glFramebufferTexture2DEXT(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) { diff --git a/GL/private.h b/GL/private.h index 811c40f..0be873f 100644 --- a/GL/private.h +++ b/GL/private.h @@ -69,6 +69,7 @@ void initContext(); void initLights(); void initImmediateMode(); void initMatrices(); +void initFramebuffers(); void _matrixLoadNormal(); void _matrixLoadModelView();