예제 #1
0
void col::render::OpenGLESIOSContext::resizeRenderTarget(uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
    makeCurrent();
    deleteRenderTarget();
    
    // framebuffer object
    GL_COMMAND(glGenFramebuffers(1, &m_defaultFramebuffer));
    GL_COMMAND(glBindFramebuffer(GL_FRAMEBUFFER, m_defaultFramebuffer));
    
    // color target
    GL_COMMAND(glGenRenderbuffers(1, &m_colorRenderBuffer));
    GL_COMMAND(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRenderBuffer));
    GL_COMMAND([m_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)m_view.layer]);
    GL_COMMAND(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorRenderBuffer));
    
    GLint actualWidth, actualHeight;
    GL_COMMAND(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &actualWidth));
    GL_COMMAND(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &actualHeight));
    
    // depth / stencil combo target
    GL_COMMAND(glGenRenderbuffers(1, &m_depthRenderBuffer));
    GL_COMMAND(glBindRenderbuffer(GL_RENDERBUFFER, m_depthRenderBuffer));
    //GL_COMMAND(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, actualWidth, actualHeight));
    GL_COMMAND(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, actualWidth, actualHeight));
    GL_COMMAND(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthRenderBuffer));
    //GL_COMMAND(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthRenderBuffer));
    
    GL_COMMAND(glViewport(0, 0, actualWidth, actualHeight));
    
    GL_COMMAND(GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER));
    switch(status) {
        case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
            COL_LOG_FATAL("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
            break;
            
        case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
            COL_LOG_FATAL("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS");
            break;
            
        case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
            COL_LOG_FATAL("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
            break;
            
        case GL_FRAMEBUFFER_UNSUPPORTED:
            COL_LOG_FATAL("GL_FRAMEBUFFER_UNSUPPORTED");
            break;
            
        case GL_FRAMEBUFFER_COMPLETE:
            break;
            
        default:
            COL_LOG_FATAL("Unknown framebuffer status");
            break;
    }
}
예제 #2
0
RenderingContext::~RenderingContext()
{
    try{
        deleteRenderTarget();
    }
    catch(...){
        std::cerr<<"RenderingContext destructor error--"<<__FILE__<<": "<<__LINE__<<"\n";
    }
    try{
        destroyShaderProgram();
    }
    catch(...){
        std::cerr<<"RenderingContext destructor error--"<<__FILE__<<": "<<__LINE__<<"\n";
    }
}