// // fbo.mm // J // // Created by Joshua Moerman on 8/28/11. // Copyright 2011 Vadovas. All rights reserved. // #import "fbo.h" #import namespace J { fbo::fbo(EAGLContext* context, CAEAGLLayer* layer) : width(0), height(0), fbo_number(0), renderbuffers(), texture_id(0){ glGenFramebuffers(1, &fbo_number); bind(); // much like create_attach_renderbuffer(), but it's not created, it's given by the context. { GLuint buffer; glGenRenderbuffers(1, &buffer); glBindRenderbuffer(GL_RENDERBUFFER, buffer); [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer]; glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width); glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, buffer); renderbuffers[GL_COLOR_ATTACHMENT0] = buffer; } //this will cause a INVALID_OPERATION in bind(). //create_attach_renderbuffer(GL_DEPTH_COMPONENT16, GL_DEPTH_ATTACHMENT); check_error(); check_status(); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); unbind(); } }