예제 #1
0
void
RenderTexture::create2DRenderTexture(int jcolor_format, int jdepth_format, bool resolve_depth) {
    initialize(width_, height_);
    GLenum depth_format;
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glBindTexture(target_, gl_texture_->id());
    switch (jcolor_format) {
        case ColorFormat::COLOR_565:
            glTexImage2D(target_, 0, GL_RGB, width_, height_, 0, GL_RGB,
                         GL_UNSIGNED_SHORT_5_6_5, 0);
            break;
        case ColorFormat::COLOR_5551:
            glTexImage2D(target_, 0, GL_RGB5_A1, width_, height_, 0, GL_RGBA,
                         GL_UNSIGNED_SHORT_5_5_5_1, 0);
            break;
        case ColorFormat::COLOR_4444:
            glTexImage2D(target_, 0, GL_RGBA, width_, height_, 0, GL_RGBA,
                         GL_UNSIGNED_SHORT_4_4_4_4, 0);
            break;
        case ColorFormat::COLOR_8888:
            glTexImage2D(target_, 0, GL_RGBA8, width_, height_, 0, GL_RGBA,
                         GL_UNSIGNED_BYTE, 0);
            break;
        case ColorFormat::COLOR_8888_sRGB:
            glTexImage2D(target_, 0, GL_SRGB8_ALPHA8, width_, height_, 0, GL_RGBA,
                         GL_UNSIGNED_BYTE, 0);
            break;
        default:
            break;
    }
    switch (jdepth_format) {
        case DepthFormat::DEPTH_24:
            depth_format = GL_DEPTH_COMPONENT24_OES;
            break;
        case DepthFormat::DEPTH_24_STENCIL_8:
            depth_format = GL_DEPTH24_STENCIL8_OES;
            break;
        default:
            depth_format = GL_DEPTH_COMPONENT16;
            break;
    }
    if (sample_count_ <= 1) {
        generateRenderTextureNoMultiSampling(jdepth_format, depth_format, width_,
                                             height_);
    } else if (resolve_depth) {
        generateRenderTexture(sample_count_, jdepth_format, depth_format, width_,
                              height_, jcolor_format);
    } else {
        generateRenderTextureEXT(sample_count_, jdepth_format, depth_format,
                                 width_, height_);
    }
    if (jdepth_format != DepthFormat::DEPTH_0) {
        GLenum attachment =
                DepthFormat::DEPTH_24_STENCIL_8 == jdepth_format ? GL_DEPTH_STENCIL_ATTACHMENT
                                                                 : GL_DEPTH_ATTACHMENT;
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER,
                                  renderTexture_gl_render_buffer_->id());

    }
    glScissor(0, 0, width_, height_);
    glViewport(0, 0, width_, height_);
    glClearColor(0, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);

    if (resolve_depth && sample_count_ > 1) {
        delete renderTexture_gl_resolve_buffer_;
        renderTexture_gl_resolve_buffer_ = new GLFrameBuffer();
        glBindFramebuffer(GL_FRAMEBUFFER, renderTexture_gl_resolve_buffer_->id());
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                               GL_TEXTURE_2D, gl_texture_->id(), 0);
        GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
        if (status != GL_FRAMEBUFFER_COMPLETE) {
            LOGE(
                    "resolve FBO %i is not complete: 0x%x", renderTexture_gl_resolve_buffer_->id(),
                    status);
        }
    }
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

}
예제 #2
0
GLNonMultiviewRenderTexture::GLNonMultiviewRenderTexture(int width, int height, int sample_count,
                                     int jcolor_format, int jdepth_format, bool resolve_depth,
                                     const TextureParameters* texture_parameters, int viewport[]):GLRenderTexture(width, height, sample_count, jcolor_format, jdepth_format,
                                                                                                  resolve_depth, texture_parameters, viewport) {
    GLRenderImage* colorbuffer = new GLRenderImage(width, height, jcolor_format, texture_parameters);
    GLenum depth_format;

    setImage(colorbuffer);
    initialize();
    getImage()->isReady();
    switch (jdepth_format)
    {
        case DepthFormat::DEPTH_24:
            depth_format = GL_DEPTH_COMPONENT24_OES;
            break;

        case DepthFormat::DEPTH_24_STENCIL_8:
            depth_format = GL_DEPTH24_STENCIL8_OES;
            break;

        default:
            depth_format = GL_DEPTH_COMPONENT16;
            break;
    }
    if (sample_count <= 1)
    {
        generateRenderTextureNoMultiSampling(jdepth_format, depth_format,
                                             width, height);
    }
    else if (resolve_depth)
    {
        generateRenderTexture(sample_count, jdepth_format, depth_format,
                              width, height, jcolor_format);
    }
    else
    {
        generateRenderTextureEXT(sample_count, jdepth_format,
                                 depth_format, width, height);
    }
    if (jdepth_format != DepthFormat::DEPTH_0)
    {
        GLenum attachment = DepthFormat::DEPTH_24_STENCIL_8 == jdepth_format ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT;
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, renderTexture_gl_render_buffer_->id());
    }

    glScissor(0, 0, width, height);
    glViewport(0, 0, width, height);
    glClearColor(0, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT);

    if (resolve_depth && sample_count > 1)
    {
        delete renderTexture_gl_resolve_buffer_;
        renderTexture_gl_resolve_buffer_ = new GLFrameBuffer();
        glBindFramebuffer(GL_FRAMEBUFFER, renderTexture_gl_resolve_buffer_->id());
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                               colorbuffer->getTarget(), colorbuffer->getId(), 0);
        GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
        if (status != GL_FRAMEBUFFER_COMPLETE)
        {
            LOGE("resolve FBO %i is not complete: 0x%x",
                 renderTexture_gl_resolve_buffer_->id(), status);
        }
    }
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    checkGLError(" GLNonMultiviewRenderTexture:");
}