Created
December 6, 2017 19:34
-
-
Save jarcode-foss/89647e80e133edfa012de5ae0304a49f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* setup screen framebuffer object and its texture */ | |
struct gl_sfbo { | |
GLuint fbo, tex, shader; | |
bool valid; | |
const char* name; | |
struct gl_bind* binds; | |
size_t binds_sz; | |
}; | |
static void setup_sfbo(struct gl_sfbo* s, int w, int h) { | |
GLuint tex = s->valid ? s->tex : ({ glGenTextures(1, &s->tex); s->tex; }); | |
GLuint fbo = s->valid ? s->fbo : ({ glGenFramebuffers(1, &s->fbo); s->fbo; }); | |
s->valid = true; | |
/* bind texture and setup space */ | |
glBindTexture(GL_TEXTURE_2D, tex); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); | |
/* setup and bind framebuffer to texture */ | |
glBindFramebuffer(GL_FRAMEBUFFER, fbo); | |
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0); | |
switch (glCheckFramebufferStatus(GL_FRAMEBUFFER)) { | |
case GL_FRAMEBUFFER_COMPLETE: break; | |
default: | |
fprintf(stderr, "error in frambuffer state\n"); | |
abort(); | |
} | |
glBindFramebuffer(GL_FRAMEBUFFER, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment