Пример #1
0
void RenderSystem::deleteRenderBuffer(RenderSystem::RenderBufferID* id) {
    glDeleteRenderbuffers(1, id);
    CROSS_GL_ASSERT();
}
Пример #2
0
 virtual void execute() { glDeleteRenderbuffers( 1, &m_id ); }
Пример #3
0
RenderBuffer::~RenderBuffer()
{
	glDeleteRenderbuffers(1, &buffer);
}
Пример #4
0
FBO::~FBO()
{
  if (this->id_depth != 0 && glIsRenderbuffer(this->id_depth)) glDeleteRenderbuffers(1, &this->id_depth);
  if (glIsFramebuffer(this->id) == GL_TRUE) glDeleteFramebuffers(1, &this->id);
}
Пример #5
0
		virtual void deleteFBO(GLuint framebuffer, GLuint depth_stencil,  GLuint img)
		{
			deleteTexture(img);
			glDeleteRenderbuffers(1, &depth_stencil);
			glDeleteFramebuffers(1, &framebuffer);
		}
RenderBufferObject::~RenderBufferObject()
{
  glDeleteRenderbuffers(1, &_id);
}
Пример #7
0
HRESULT
FrameBufferObject::Initialize( COpenGLDevice* pOGLDevice, unsigned int width, unsigned int height )
{
    RETAILMSG(ZONE_INFO, (TEXT("FrameBufferObject::Initialize( %d x %d )"), width, height ));

    HRESULT hr = S_OK;

    if (!pOGLDevice || !width || !height)
    {
        RETAILMSG(ZONE_ERROR, (TEXT("ERROR: FrameBufferObject::Initialize(): pOGLdevice 0x%x, width %d, height %d\n"),
                               pOGLDevice, width, height));

        CHR(E_INVALIDARG);
    }

    if (m_pOGLDevice != NULL)
    {
        m_pOGLDevice->Lock();

        // We are being re-initialized (probably because the screen changed size)
        VERIFYGL( glDeleteRenderbuffers(1, &m_uiDepthRenderbuffer  ));
        VERIFYGL( glDeleteFramebuffers (1, &m_uiFramebuffer        ));
        VERIFYGL( glDeleteTextures     (1, &m_uiTextureID          ));

        m_pOGLDevice->Unlock();
        m_pOGLDevice->Release();

        RETAILMSG(ZONE_INFO, (TEXT("FrameBufferObject::Initialize(); discard old FBO because because of resize\n")));
    }

    m_pOGLDevice    = pOGLDevice;
    m_pOGLDevice->AddRef();
    m_TexWidth      = width;
    m_TexHeight     = height;

    m_pOGLDevice->Lock();

#ifdef USE_DEPTH_BUFFER
    VERIFYGL(glGetIntegerv( GL_MAX_RENDERBUFFER_SIZE, &m_MaxRenderbufferSize ));
    if ((m_MaxRenderbufferSize <= m_TexWidth) ||
            (m_MaxRenderbufferSize <= m_TexHeight))
    {
        // cannot use framebuffer objects as we need to create
        // a depth buffer as a renderbuffer object
        DEBUGCHK(0);
        return E_OUTOFMEMORY;
    }

    VERIFYGL(glGenRenderbuffers (1, &m_uiDepthRenderbuffer));
#endif


    // Create a texture and attach to the FBO as a render target
    VERIFYGL(glGenTextures     (1, &m_uiTextureID));
    VERIFYGL(glBindTexture     (GL_TEXTURE_2D, m_uiTextureID));
    VERIFYGL(glTexParameteri   (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
    VERIFYGL(glTexParameteri   (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
    VERIFYGL(glTexParameteri   (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
    VERIFYGL(glTexParameteri   (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));

    if ( m_pOGLDevice->Use16BitTextures() )
    {
        VERIFYGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_TexWidth, m_TexHeight, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL));
    }
    else if ( m_pOGLDevice->IsGlBGRAExtSupported() )
    {
        VERIFYGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, m_TexWidth, m_TexHeight, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NULL));
    }
    else
    {
        VERIFYGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_TexWidth, m_TexHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL));
    }

    // Generate an off-screen Framebuffer and make it active
    VERIFYGL(glGenFramebuffers  (1, &m_uiFramebuffer));
    VERIFYGL(glBindFramebuffer(GL_FRAMEBUFFER, m_uiFramebuffer));

    // Attach our texture to FBO
    VERIFYGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_uiTextureID, 0));

#ifdef USE_DEPTH_BUFFER
    // Create a depth buffer and attach to the FBO as a render target
    VERIFYGL(glBindRenderbuffer    (GL_RENDERBUFFER, m_uiDepthRenderbuffer));
    VERIFYGL(glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, m_TexWidth, m_TexHeight));
    VERIFYGL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_uiDepthRenderbuffer));
    //VERIFYGL(glClear(GL_DEPTH_BUFFER_BIT));
#endif

    VERIFYGL(glClearColor(1.0f, 0.0f, 1.0f, 1.0f));
    VERIFYGL(glClear(GL_COLOR_BUFFER_BIT));

    GLint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if (status != GL_FRAMEBUFFER_COMPLETE)
    {
        RETAILMSG(ZONE_ERROR, (TEXT("ERROR: FrameBufferObject::Initialize() failed.  Off-screen rendering disabled.\n")));
        DEBUGCHK(0);
        hr = E_FAIL;
    }

Error:
    // Restore the default OS-provided framebuffer
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    m_pOGLDevice->Unlock();

    RETAILMSG(S_OK == hr && ZONE_INFO, (TEXT("FrameBufferObject::Initialize() OK\n")));

    return hr;
}
Пример #8
0
bool
do_blit_test(bool use_es2, bool from_missing_to_complete)
{
    GLuint rb[3];
    GLuint fb[2];
    GLenum status;
    GLenum err;
    const unsigned src = from_missing_to_complete ? 0 : 1;
    const unsigned dst = 1 - src;
    const char *const names[] = {
        "buffer with missing attachment",
        "complete buffer"
    };
    bool pass = true;

    printf("Testing blit from %s to %s...\n", names[src], names[dst]);

    /* Create a depth-only FBO and a depth/color FBO.
     */
    glGenRenderbuffers(ARRAY_SIZE(rb), rb);

    glBindRenderbuffer(GL_RENDERBUFFER, rb[0]);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24,
                          piglit_width, piglit_height);
    glBindRenderbuffer(GL_RENDERBUFFER, rb[1]);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24,
                          piglit_width, piglit_height);
    glBindRenderbuffer(GL_RENDERBUFFER, rb[2]);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA,
                          piglit_width, piglit_height);

    glGenFramebuffers(ARRAY_SIZE(fb), fb);
    glBindFramebuffer(GL_FRAMEBUFFER, fb[0]);
    glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                              GL_RENDERBUFFER, rb[0]);
    if (!use_es2) {
        glDrawBuffer(GL_NONE);
        glReadBuffer(GL_NONE);
    }

    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb[1]);
    glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                              GL_RENDERBUFFER, rb[1]);
    glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                              GL_RENDERBUFFER, rb[2]);

    err = glGetError();
    if (err != 0) {
        fprintf(stderr, "Unexpected GL error state 0x%04x\n", err);
        return false;
    }

    /* Check completeness of the source surface.
     */
    glBindFramebuffer(GL_READ_FRAMEBUFFER, fb[src]);
    status = glCheckFramebufferStatus(GL_READ_FRAMEBUFFER);
    if (status != GL_FRAMEBUFFER_COMPLETE) {
        fprintf(stderr, "Read FBO erroneously incomplete: 0x%04x\n",
                status);
        return false;
    }

    /* In the source surface, clear the depth buffer and draw a single
     * rectangle with a constant depth value.  The depth test setting here
     * is correct.
     */
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb[src]);
    glClearDepth(0.0);
    glClear(GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_ALWAYS);

    piglit_draw_rect_z(0.5, -0.5, -0.5, 1.0, 1.0);

    /* Check completeness of the destination surface.
     */
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb[dst]);
    status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);

    if (status != GL_FRAMEBUFFER_COMPLETE) {
        fprintf(stderr, "Draw FBO erroneously incomplete: 0x%04x\n",
                status);
        return false;
    }

    glBlitFramebuffer(0, 0, piglit_width, piglit_height,
                      0, 0, piglit_width, piglit_height,
                      GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
                      GL_NEAREST);
    err = glGetError();
    if (err != 0) {
        fprintf(stderr, "Unexpected GL error state 0x%04x\n", err);
        return false;
    }

    /* Probe depth values from the destination buffer to make sure the
     * depth part of the blit actually happened.
     */
    glBindFramebuffer(GL_READ_FRAMEBUFFER, fb[dst]);
    pass = piglit_probe_rect_depth(0.25 * piglit_width,
                                   0.25 * piglit_height,
                                   0.4 * piglit_width,
                                   0.4 * piglit_height,
                                   0.75);
    pass = piglit_probe_rect_depth(0,
                                   0,
                                   piglit_width,
                                   0.2 * piglit_height,
                                   0.0)
           && pass;

    glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
    glDeleteFramebuffers(ARRAY_SIZE(fb), fb);
    glDeleteRenderbuffers(ARRAY_SIZE(rb), rb);

    return pass;
}
void FGLRenderBuffers::DeleteRenderBuffer(GLuint &handle)
{
	if (handle != 0)
		glDeleteRenderbuffers(1, &handle);
	handle = 0;
}
Пример #10
0
			GLFramebuffer2D::~GLFramebuffer2D()
			{
				TE_OGL(glDeleteFramebuffers(1, &m_handle_fb));
				TE_OGL(glDeleteRenderbuffers(1, &m_handle_db));
			}
Пример #11
0
bool GBuffer::setupFbo(unsigned int windowWidth, unsigned int windowHeight) {

    m_buffer_w = windowWidth;
    m_buffer_h = windowHeight;

    // delete existing fbo, textures, and render buffer in case we are regenerating at new size
    glDeleteTextures(GBUFFER_NUM_TEXTURES, m_textures);
    glDeleteRenderbuffers(1, &m_renderBuffer);
    glDeleteFramebuffers(1, &m_fbo);

    // create an fbo
    glGenFramebuffers(1, &m_fbo);
    glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);

    // create all gbuffer textures
    glGenTextures(GBUFFER_NUM_TEXTURES, m_textures);

    // albedo/diffuse (16-bit channel rgba)
    glBindTexture(GL_TEXTURE_2D, m_textures[GBUFFER_TEXTURE_TYPE_ALBEDO]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, m_buffer_w, m_buffer_h, 0, GL_RGBA, GL_FLOAT, NULL);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + GBUFFER_TEXTURE_TYPE_ALBEDO, GL_TEXTURE_2D, m_textures[GBUFFER_TEXTURE_TYPE_ALBEDO], 0);

    // normals + depth (32-bit RGBA float for accuracy)
    glBindTexture(GL_TEXTURE_2D, m_textures[GBUFFER_TEXTURE_TYPE_NORMALS_DEPTH]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, m_buffer_w, m_buffer_h, 0, GL_RGBA, GL_FLOAT, NULL);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + GBUFFER_TEXTURE_TYPE_NORMALS_DEPTH, GL_TEXTURE_2D, m_textures[GBUFFER_TEXTURE_TYPE_NORMALS_DEPTH], 0);

    // lighting pass (16-bit RGBA)
    glBindTexture(GL_TEXTURE_2D, m_textures[GBUFFER_TEXTURE_TYPE_LIGHT_PASS]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_buffer_w, m_buffer_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + GBUFFER_TEXTURE_TYPE_LIGHT_PASS, GL_TEXTURE_2D, m_textures[GBUFFER_TEXTURE_TYPE_LIGHT_PASS], 0);

    // create depth texture (we don't use this explicitly, but since we use depth testing when rendering + for our stencil pass, our FBO needs a depth buffer)
    // we make it a renderbuffer and not a texture as we'll never access it directly in a shader
    glGenRenderbuffers(1, &m_renderBuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, m_renderBuffer);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH32F_STENCIL8, m_buffer_w, m_buffer_h);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_renderBuffer);

    // check status
    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
    glBindTexture(GL_TEXTURE_2D, 0);

    if (status != GL_FRAMEBUFFER_COMPLETE) {
        ofLogError("GBuffer::setupFbo()", "Could not create framebuffer");
        return false;
    }

    return true;
}
Пример #12
0
void renderer_cool::draw(int vertex_count)
{
    static bool initial_resize = false;
    if (!initial_resize)
    {
        if (enabler->fullscreen)
            resize(size_x, size_y);
        else
            resize((size_x/init->font.small_font_dispx)*init->font.small_font_dispx, (size_y/init->font.small_font_dispy)*init->font.small_font_dispy);
            //resize(gps->dimx*init->font.small_font_dispx, gps->dimy*init->font.small_font_dispy);

        reshape_gl();
        initial_resize = true;
    }

    static df::viewscreen *prevws = NULL;
    df::viewscreen *ws = Gui::getCurViewscreen();
    is_main_scr = df::viewscreen_dwarfmodest::_identity.is_direct_instance(ws) || df::viewscreen_dungeonmodest::_identity.is_direct_instance(ws);
    if (ws != prevws)
    {
        gps->force_full_display_count = 1;
        prevws = ws;
        /*if (is_main_scr)
        {
            for (int x = 1; x < gps->dimx-gmenu_w-1; x++)
            {
                for (int y = 1; y < gps->dimy-1; y++)
                {
                    const int tile1 = x * gps->dimy + y;
                    for (int i = 0; i < 6; i++)
                        *(fg + tile * 4 * i + 3) = 0;
                }
            }
        }*/
    }    

    display_new(is_main_scr);

#ifdef WIN32
    // We can't do this in plugin_init() because OpenGL context isn't initialized by that time
    static bool glew_init = false;
    if (!glew_init)
    {
        GLenum err = glewInit();
        if (err != GLEW_OK)
            *out2 << glewGetErrorString(err);
        glew_init = true;
    }
#endif

    static int old_dimx, old_dimy, old_winx, old_winy;
    if (domapshot)
    {
        if (domapshot == 10)
        {
            old_dimx = gps->dimx;
            old_dimy = gps->dimy;
            old_winx = *df::global::window_x;
            old_winy = *df::global::window_y;

            grid_resize(world->map.x_count + 36, world->map.y_count + 2);
            *df::global::window_x = 0;
            *df::global::window_y = 0;
            gps->force_full_display_count = 1;
        }
        domapshot--;
    }

    GLuint framebuffer, renderbuffer;
    GLenum status;
    if (domapshot == 5)
    {
        // Set the width and height appropriately for your image
        GLuint imageWidth = gps->dimx * dispx,
               imageHeight = gps->dimy * dispy;
        //Set up a FBO with one renderbuffer attachment
        glGenFramebuffers(1, &framebuffer);
        glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
        glGenRenderbuffers(1, &renderbuffer);
        glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
        glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, imageWidth, imageHeight);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                  GL_RENDERBUFFER, renderbuffer);
        glViewport(0, 0, gps->dimx * dispx, gps->dimy * dispy);

        /*glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        glOrtho(0,gps->dimx,gps->dimy,0,-1,1);*/
    }

    if (is_main_scr)
    {
        bool skip = false;
        if (df::viewscreen_dungeonmodest::_identity.is_direct_instance(ws))
        {
            int m = df::global::ui_advmode->menu;
            bool tmode = advmode_needs_map(m);
            skip = !tmode;
        }

        if (!skip)
        {
            /////
            glViewport(goff_x, goff_y_gl, gdimx * gdispx, gdimy * gdispy);

            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrtho(0, gdimx, gdimy, 0, -1, 1);
            //glTranslatef(1,-1,0);

            //glScissor(off_x+(float)size_x/gps->dimx, off_y+(float)size_y/gps->dimy, gsize_x, gsize_y);
            //glEnable(GL_SCISSOR_TEST);
            //glClearColor(1,0,0,1);
            //glClear(GL_COLOR_BUFFER_BIT);

            if (multi_rendered && fogdensity > 0)
            {
                glEnable(GL_FOG);
                glFogfv(GL_FOG_COLOR, fogcolor);
                glFogf(GL_FOG_DENSITY, fogdensity);
                glFogi(GL_FOG_COORD_SRC, GL_FOG_COORD);
                glEnableClientState(GL_FOG_COORD_ARRAY);
                glFogCoordPointer(GL_FLOAT, 0, fogcoord);
            }

            glVertexPointer(2, GL_FLOAT, 0, gvertexes);

            // Render background colors
            glDisable(GL_TEXTURE_2D);
            glDisableClientState(GL_TEXTURE_COORD_ARRAY);
            glDisable(GL_BLEND);
            glColorPointer(4, GL_FLOAT, 0, gbg);
            glDrawArrays(GL_TRIANGLES, 0, gdimx * gdimy * 6);

            // Render foreground
            glEnable(GL_TEXTURE_2D);
            glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            glTexCoordPointer(2, GL_FLOAT, 0, gtex);
            glColorPointer(4, GL_FLOAT, 0, gfg);
            glDrawArrays(GL_TRIANGLES, 0, gdimx * gdimy * 6);

            if (multi_rendered)
            {
                glDisableClientState(GL_FOG_COORD_ARRAY);
                glDisable(GL_FOG);
            }

            // Prepare and render shadows
            if (multi_rendered)
            {
                int elemcnt = 0;
                //TODO: don't do this if view not moved and tiles with shadows not changed
                {
                    gl_texpos *txt = (gl_texpos *) enabler->textures.gl_texpos;
                    int x1 = std::min(gdimx, world->map.x_count-gwindow_x);                
                    int y1 = std::min(gdimy, world->map.y_count-gwindow_y);

                    for (int tile = 0; tile < gdimx * gdimy; tile++)
                    {
                        int xx = tile / gdimy;
                        int yy = tile % gdimy;

                        int d = depth[tile];
                        if (d && d != 0x7f) //TODO: no need for the second check in fort mode
                        {
                            GLfloat *tex = shadowtex + elemcnt * 2;

                            bool top = false, left = false, btm = false, right = false;
                            if (xx > 0 && (depth[((xx - 1)*gdimy + yy)]) < d)
                            {
                                memcpy(shadowvert + elemcnt * 2, gvertexes + tile * 6 * 2, 6 * 2 * sizeof(float));
                                SETTEX(shadow_texpos[0]);
                                elemcnt += 6;
                                left = true;
                            }
                            if (yy < y1 - 1 && (depth[((xx)*gdimy + yy + 1)]) < d)
                            {
                                memcpy(shadowvert + elemcnt * 2, gvertexes + tile * 6 * 2, 6 * 2 * sizeof(float));
                                SETTEX(shadow_texpos[1]);
                                elemcnt += 6;
                                btm = true;
                            }
                            if (yy > 0 && (depth[((xx)*gdimy + yy - 1)]) < d)
                            {
                                memcpy(shadowvert + elemcnt * 2, gvertexes + tile * 6 * 2, 6 * 2 * sizeof(float));
                                SETTEX(shadow_texpos[2]);
                                elemcnt += 6;
                                top = true;
                            }
                            if (xx < x1-1 && (depth[((xx + 1)*gdimy + yy)]) < d)
                            {
                                memcpy(shadowvert + elemcnt * 2, gvertexes + tile * 6 * 2, 6 * 2 * sizeof(float));
                                SETTEX(shadow_texpos[3]);
                                elemcnt += 6;
                                right = true;
                            }

                            if (!right && !btm && xx < x1 - 1 && yy < y1 - 1 && (depth[((xx + 1)*gdimy + yy + 1)]) < d)
                            {
                                memcpy(shadowvert + elemcnt * 2, gvertexes + tile * 6 * 2, 6 * 2 * sizeof(float));
                                SETTEX(shadow_texpos[4]);
                                elemcnt += 6;
                            }
                            if (!left && !btm && xx > 0 && yy < y1 - 1 && (depth[((xx - 1)*gdimy + yy + 1)]) < d)
                            {
                                memcpy(shadowvert + elemcnt * 2, gvertexes + tile * 6 * 2, 6 * 2 * sizeof(float));
                                SETTEX(shadow_texpos[5]);
                                elemcnt += 6;
                            }
                            if (!left && !top && xx > 0 && yy > 0 && (depth[((xx - 1)*gdimy + yy - 1)]) < d)
                            {
                                memcpy(shadowvert + elemcnt * 2, gvertexes + tile * 6 * 2, 6 * 2 * sizeof(float));
                                SETTEX(shadow_texpos[6]);
                                elemcnt += 6;
                            }
                            if (!top && !right && xx < x1 - 1 && yy > 0 && (depth[((xx + 1)*gdimy + yy - 1)]) < d)
                            {
                                memcpy(shadowvert + elemcnt * 2, gvertexes + tile * 6 * 2, 6 * 2 * sizeof(float));
                                SETTEX(shadow_texpos[7]);
                                elemcnt += 6;
                            }
                        }
                    }
                }

                if (elemcnt)
                {
                    glDisableClientState(GL_COLOR_ARRAY);
                    glColor4fv(shadowcolor);
                    glEnable(GL_BLEND);
                    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                    //glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
                    glTexCoordPointer(2, GL_FLOAT, 0, shadowtex);
                    glVertexPointer(2, GL_FLOAT, 0, shadowvert);
                    glDrawArrays(GL_TRIANGLES, 0, elemcnt);
                    glEnableClientState(GL_COLOR_ARRAY);
                }
            }

            glDisable(GL_SCISSOR_TEST);

            glViewport(off_x, off_y, size_x, size_y);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrtho(0, tdimx, tdimy, 0, -1, 1);            
        }
    }
    {
        glVertexPointer(2, GL_FLOAT, 0, vertexes);

        // Render background colors
        glDisable(GL_TEXTURE_2D);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        glEnable(GL_BLEND);
        glColorPointer(4, GL_FLOAT, 0, bg);
        glDrawArrays(GL_TRIANGLES, 0, tdimx*tdimy*6);

        // Render foreground
        glEnable(GL_TEXTURE_2D);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glTexCoordPointer(2, GL_FLOAT, 0, tex);
        glColorPointer(4, GL_FLOAT, 0, fg);
        glDrawArrays(GL_TRIANGLES, 0, tdimx*tdimy*6);
    }


    if (domapshot == 1)
    {
        int w = world->map.x_count * dispx;
        int h = world->map.y_count * dispy;

        unsigned char *data = (unsigned char *) malloc(w * h * 3);

        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        glPixelStorei(GL_PACK_ROW_LENGTH, 0);
        glReadPixels(dispx, dispy, w, h, GL_BGR, GL_UNSIGNED_BYTE, data);


#pragma pack(push,1)
        typedef struct _TgaHeader
        {
            unsigned char IDLength;        /* 00h  Size of Image ID field */
            unsigned char ColorMapType;    /* 01h  Color map type */
            unsigned char ImageType;       /* 02h  Image type code */
            unsigned short CMapStart;       /* 03h  Color map origin */
            unsigned short CMapLength;      /* 05h  Color map length */
            unsigned char CMapDepth;       /* 07h  Depth of color map entries */
            unsigned short XOffset;         /* 08h  X origin of image */
            unsigned short YOffset;         /* 0Ah  Y origin of image */
            unsigned short Width;           /* 0Ch  Width of image */
            unsigned short Height;          /* 0Eh  Height of image */
            unsigned char PixelDepth;      /* 10h  Image pixel size */
            unsigned char ImageDescriptor; /* 11h  Image descriptor byte */
        } TGAHEAD;
#pragma pop

        TGAHEAD hdr;
        memset(&hdr, 0, sizeof(hdr));
        hdr.ImageType = 2;
        hdr.Width = w;
        hdr.Height = h;
        hdr.PixelDepth = 24;


        *out2 << w << " " << h << std::endl;
        std::ofstream img("mapshot.tga", std::ofstream::binary);
        img.write((const char *)&hdr, sizeof(hdr));
        /*        for (int j = 0; j<w*h*3; j++)
                {
                    unsigned char c = data[j+0];
                    data[0] = data[j+2];
                    data[j+2] = c;
                }*/
        img.write((const char *)data, w * h * 3);

        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        // Delete the renderbuffer attachment
        glDeleteRenderbuffers(1, &renderbuffer);

        grid_resize(old_dimx, old_dimy);
        *df::global::window_x = old_winx;
        *df::global::window_y = old_winy;
        gps->force_full_display_count = 1;
        domapshot = 0;
    }
}
Пример #13
0
RenderBuffer::~RenderBuffer()
{
	glDeleteRenderbuffers(1, &_id);
    CHECK_OPENGL_ERROR();
}
Пример #14
0
void GL::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers) {
    GL_CHECK(glDeleteRenderbuffers(n, renderbuffers));
}
 void operator() (GLsizei count, GLuint* ptr) const {
     glDeleteRenderbuffers(count, ptr);
 }
Пример #16
0
   void BeginRender(const Rect &inRect,bool inForHitTest)
   {
      if (!inForHitTest)
      {
         if (mContextId!=gTextureContextVersion)
         {
            updateContext();
         }

         #ifndef NME_GLES
         #ifndef SDL_OGL
         #ifndef GLFW_OGL
         wglMakeCurrent(mDC,mOGLCtx);
         #endif
         #endif
         #endif

         if (mHasZombie)
         {
            mHasZombie = false;
            if (mZombieTextures.size())
            {
               glDeleteTextures(mZombieTextures.size(),&mZombieTextures[0]);
               mZombieTextures.resize(0);
            }

            if (mZombieVbos.size())
            {
               glDeleteBuffers(mZombieVbos.size(),&mZombieVbos[0]);
               mZombieVbos.resize(0);
            }

            if (mZombiePrograms.size())
            {
               for(int i=0;i<mZombiePrograms.size();i++)
                  glDeleteProgram(mZombiePrograms[i]);
               mZombiePrograms.resize(0);
            }

            if (mZombieShaders.size())
            {
               for(int i=0;i<mZombieShaders.size();i++)
                  glDeleteShader(mZombieShaders[i]);
               mZombieShaders.resize(0);
            }

            if (mZombieFramebuffers.size())
            {
               glDeleteFramebuffers(mZombieFramebuffers.size(),&mZombieFramebuffers[0]);
               mZombieFramebuffers.resize(0);
            }

            if (mZombieRenderbuffers.size())
            {
               glDeleteRenderbuffers(mZombieRenderbuffers.size(),&mZombieRenderbuffers[0]);
               mZombieRenderbuffers.resize(0);
            }
         }


         // Force dirty
         mViewport.w = -1;
         SetViewport(inRect);


         glEnable(GL_BLEND);

        #ifdef WEBOS
         glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
         #endif

         mLineWidth = 99999;

         // printf("DrawArrays: %d, DrawBitmaps:%d  Buffers:%d\n", sgDrawCount, sgDrawBitmap, sgBufferCount );
         sgDrawCount = 0;
         sgDrawBitmap = 0;
      }
   }
Пример #17
0
enum piglit_result
piglit_display(void)
{
	bool warn = false, pass = true;
	GLuint rb, fbo;
	int i, j;
	float times[ARRAY_LENGTH(gl_formats)][ARRAY_LENGTH(gl_types)];

	glGenRenderbuffersEXT(1, &rb);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
				 GL_RGBA, texture_size, texture_size);
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	glGenFramebuffersEXT(1, &fbo);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
				     GL_COLOR_ATTACHMENT0_EXT,
				     GL_RENDERBUFFER_EXT, rb);
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	/* Set up basic GL stuff */
	glEnable(GL_TEXTURE_2D);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	warn = !test_exact();

	for (i = 0; i < ARRAY_LENGTH(gl_formats); ++i) {
		for (j = 0; j < ARRAY_LENGTH(gl_types); ++j) {
			if (!valid_combination(gl_formats[i], gl_types[j]))
				continue;

			pass &= run_test(gl_formats[i], gl_types[j],
					 &times[i][j]);
		}
	}

	glDisable(GL_TEXTURE_2D);
	glDeleteFramebuffers(1, &fbo);
	glDeleteRenderbuffers(1, &rb);

	if (benchmark) {
		fprintf(stdout, "internalFormat, format, type, time (us/call)\n");
		for (i = 0; i < ARRAY_LENGTH(gl_formats); ++i) {
			for (j = 0; j < ARRAY_LENGTH(gl_types); ++j) {
				if (!valid_combination(gl_formats[i], gl_types[j]))
					continue;

				fprintf(stdout, "%s, %s, %s, %.3f\n",
					piglit_get_gl_enum_name(format->internal_format),
					piglit_get_gl_enum_name(gl_formats[i]),
					piglit_get_gl_enum_name(gl_types[j]),
					times[i][j]);
			}
		}
	}

	if (pass) {
		return warn ? PIGLIT_WARN : PIGLIT_PASS;
	} else {
		return PIGLIT_FAIL;
	}
}
Пример #18
0
enum piglit_result
piglit_display(void)
{
	GLubyte *win_image, *fbo_image;
	GLuint fbo, rb;
	bool pass = true;

	win_image = (GLubyte *) malloc(piglit_width * piglit_height * 3);
	fbo_image = (GLubyte *) malloc(piglit_width * piglit_height * 3);

	glPixelStorei(GL_PACK_ALIGNMENT, 1);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	glGenFramebuffers(1, &fbo);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
	glGenRenderbuffers(1, &rb);
	glBindRenderbuffer(GL_RENDERBUFFER, rb);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA,
			      piglit_width, piglit_height);
	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
				  GL_RENDERBUFFER, rb);

	assert(glGetError() == 0);

	assert(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) ==
			 GL_FRAMEBUFFER_COMPLETE_EXT);

	/* draw reference image in the window */
	glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
	draw_test_image();
	glReadPixels(0, 0, piglit_width, piglit_height,
		     GL_RGB, GL_UNSIGNED_BYTE, win_image);

	/* draw test image in fbo */
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
	glReadBuffer(GL_COLOR_ATTACHMENT0);
	draw_test_image();
	glReadPixels(0, 0, piglit_width, piglit_height,
		     GL_RGB, GL_UNSIGNED_BYTE, fbo_image);

	/* compare images */
	if (memcmp(win_image, fbo_image, piglit_width * piglit_height * 3)) {
#if 0 /* helpful debug code */
		int i, k;
		for (i = k = 0; i < piglit_width * piglit_height * 3; i++) {
			if (win_image[i] != fbo_image[i] && k++ < 40)
				printf("%d: %d vs. %d\n",
				       i, win_image[i], fbo_image[i]);
		}
#endif
		printf("Image comparison failed!\n");
		pass = false;
	}
	else if (!piglit_automatic) {
		printf("Image comparison passed.\n");
	}

	glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);

#if 0	/* for debug/compare (alternate diplaying Window vs. FBO image) */
	{
		int i;
		glWindowPos2i(0,0);
		for (i = 0; i < 10; i++) {
			GLubyte *image = (i & 1) ? fbo_image : win_image;
			printf("Showing %s image\n", (i & 1) ? "FBO" : "window");
			glDrawPixels(piglit_width, piglit_height,
				     GL_RGB, GL_UNSIGNED_BYTE, image);
			piglit_present_results();
			sleep(1);
		}
	}
#endif

	piglit_present_results();

	glDeleteRenderbuffers(1, &rb);
	glDeleteFramebuffers(1, &fbo);
	free(win_image);
	free(fbo_image);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Пример #19
0
void viewFreeOffscreenBuffer( View *v )
{
    glDeleteTextures( 1, &v->rgba );
    glDeleteRenderbuffers( 1, &v->depth );
    glDeleteFramebuffers( 1, &v->fbo );
}
Пример #20
0
	OGLESDepthStencilRenderView::~OGLESDepthStencilRenderView()
	{
		glDeleteRenderbuffers(1, &rbo_);
	}
Пример #21
0
void slop::Framebuffer::create( unsigned int width, unsigned int height, unsigned char flags, std::string shader ) {
    if ( m_width == width && m_height == height && m_flags == flags ) {
        return;
    }
    delete m_shader;
    m_shader = new slop::Shader( shader, resource->getRealPath( shader + ".vert" ), resource->getRealPath( shader + ".frag" ) );
    if ( GLEW_VERSION_3_0 ) {
        glDeleteFramebuffers( 1, &m_frame );
        if ( m_flags & color ) {
            glDeleteTextures( 1, &m_texture );
        }
        if ( m_flags & depth && !( m_flags & stencil ) ) {
            glDeleteRenderbuffers( 1, &m_depth );
        }
        if ( m_flags & stencil ) {
            glDeleteRenderbuffers( 1, &m_stencil );
        }
    } else if ( GLEW_EXT_framebuffer_object ) {
        glDeleteFramebuffersEXT( 1, &m_frame );
        if ( m_flags & color ) {
            glDeleteTextures( 1, &m_texture );
        }
        if ( m_flags & depth && !( m_flags & stencil ) ) {
            glDeleteRenderbuffersEXT( 1, &m_depth );
        }
        if ( m_flags & stencil ) {
            glDeleteRenderbuffersEXT( 1, &m_stencil );
        }
    }
    m_flags = flags;
    m_width = width;
    m_height = height;
    if ( GLEW_VERSION_3_0 ) {
        glGenFramebuffers( 1, &m_frame );
        glBindFramebuffer( GL_FRAMEBUFFER, m_frame );

        if ( m_flags & color ) {
            glGenTextures( 1, &m_texture );
            glBindTexture( GL_TEXTURE_2D, m_texture );
            glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, m_width, m_height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0 );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
            glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0 );
        }

        if ( m_flags & depth && !( m_flags & stencil ) ) {
            glGenRenderbuffers( 1, &m_depth );
            glBindRenderbuffer( GL_RENDERBUFFER, m_depth );
            glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_width, m_height );
            glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depth );
        }

        //This is the only way I could get a proper stencil buffer, by making a GL_DEPTH_STENCIL attachment to both points.
        if ( m_flags & stencil ) {
            glGenRenderbuffers( 1, &m_stencil );
            glBindRenderbuffer( GL_RENDERBUFFER, m_stencil );
            glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_STENCIL, m_width, m_height );
            glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_stencil );
            glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_stencil );
        }
        //Make sure we unbind when we're done.
        glBindFramebuffer( GL_FRAMEBUFFER, 0 );
    } else if ( GLEW_EXT_framebuffer_object ) {
        glGenFramebuffersEXT( 1, &m_frame );
        glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, m_frame );

        if ( m_flags & color ) {
            glGenTextures( 1, &m_texture );
            glBindTexture( GL_TEXTURE_2D, m_texture );
            glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, m_width, m_height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0 );
           glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
            glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_texture, 0 );
        }

        if ( m_flags & depth && !( m_flags & stencil ) ) {
            glGenRenderbuffersEXT( 1, &m_depth );
            glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, m_depth );
            glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, m_width, m_height );
            glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depth );
        }

        //This is the only way I could get a proper stencil buffer, by making a GL_DEPTH_STENCIL attachment to both points.
        if ( m_flags & stencil ) {
            glGenRenderbuffersEXT( 1, &m_stencil );
            glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, m_stencil );
            glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, m_width, m_height );
            glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_stencil );
            glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_stencil );
        }
        //Make sure we unbind when we're done.
        glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
    }
}
Пример #22
0
void QGLFramebufferObjectPrivate::init(QGLFramebufferObject *q, const QSize &sz,
                                       QGLFramebufferObject::Attachment attachment,
                                       GLenum texture_target, GLenum internal_format, GLint samples)
{
    QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext());
    fbo_guard.setContext(ctx);

    bool ext_detected = (QGLExtensions::glExtensions() & QGLExtensions::FramebufferObject);
    if (!ext_detected || (ext_detected && !qt_resolve_framebufferobject_extensions(ctx)))
        return;

    size = sz;
    target = texture_target;
    // texture dimensions

    QT_RESET_GLERROR(); // reset error state
    GLuint fbo = 0;
    glGenFramebuffers(1, &fbo);
    glBindFramebuffer(GL_FRAMEBUFFER_EXT, fbo);
    fbo_guard.setId(fbo);

    glDevice.setFBO(q, attachment);

    QT_CHECK_GLERROR();
    // init texture
    if (samples == 0) {
        glGenTextures(1, &texture);
        glBindTexture(target, texture);
        glTexImage2D(target, 0, internal_format, size.width(), size.height(), 0,
                GL_RGBA, GL_UNSIGNED_BYTE, NULL);
#ifndef QT_OPENGL_ES
        glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#else
        glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameterf(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameterf(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#endif
        glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                target, texture, 0);

        QT_CHECK_GLERROR();
        valid = checkFramebufferStatus();
        glBindTexture(target, 0);

        color_buffer = 0;
    } else {
        GLint maxSamples;
        glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSamples);

        samples = qBound(1, int(samples), int(maxSamples));

        glGenRenderbuffers(1, &color_buffer);
        glBindRenderbuffer(GL_RENDERBUFFER_EXT, color_buffer);
        if (glRenderbufferStorageMultisampleEXT) {
            glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples,
                internal_format, size.width(), size.height());
        } else {
            samples = 0;
            glRenderbufferStorage(GL_RENDERBUFFER_EXT, internal_format,
                size.width(), size.height());
        }

        glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
                                     GL_RENDERBUFFER_EXT, color_buffer);

        QT_CHECK_GLERROR();
        valid = checkFramebufferStatus();

        if (valid)
            glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_SAMPLES_EXT, &samples);
    }

    if (attachment == QGLFramebufferObject::CombinedDepthStencil
        && (QGLExtensions::glExtensions() & QGLExtensions::PackedDepthStencil)) {
        // depth and stencil buffer needs another extension
        glGenRenderbuffers(1, &depth_stencil_buffer);
        Q_ASSERT(!glIsRenderbuffer(depth_stencil_buffer));
        glBindRenderbuffer(GL_RENDERBUFFER_EXT, depth_stencil_buffer);
        Q_ASSERT(glIsRenderbuffer(depth_stencil_buffer));
        if (samples != 0 && glRenderbufferStorageMultisampleEXT)
            glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples,
                GL_DEPTH24_STENCIL8_EXT, size.width(), size.height());
        else
            glRenderbufferStorage(GL_RENDERBUFFER_EXT,
                GL_DEPTH24_STENCIL8_EXT, size.width(), size.height());

        GLint i = 0;
        glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_DEPTH_SIZE_EXT, &i);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
                                     GL_RENDERBUFFER_EXT, depth_stencil_buffer);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
                                     GL_RENDERBUFFER_EXT, depth_stencil_buffer);
        fbo_attachment = QGLFramebufferObject::CombinedDepthStencil;

        valid = checkFramebufferStatus();
        if (!valid)
            glDeleteRenderbuffers(1, &depth_stencil_buffer);
    } else if (attachment == QGLFramebufferObject::Depth
               || attachment == QGLFramebufferObject::CombinedDepthStencil)
    {
        glGenRenderbuffers(1, &depth_stencil_buffer);
        Q_ASSERT(!glIsRenderbuffer(depth_stencil_buffer));
        glBindRenderbuffer(GL_RENDERBUFFER_EXT, depth_stencil_buffer);
        Q_ASSERT(glIsRenderbuffer(depth_stencil_buffer));
        if (samples != 0 && glRenderbufferStorageMultisampleEXT) {
#ifdef QT_OPENGL_ES
#define GL_DEPTH_COMPONENT16 0x81A5
            glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples,
                GL_DEPTH_COMPONENT16, size.width(), size.height());
#else
            glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples,
                GL_DEPTH_COMPONENT, size.width(), size.height());
#endif
        } else {
#ifdef QT_OPENGL_ES
#define GL_DEPTH_COMPONENT16 0x81A5
            glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT16, size.width(), size.height());
#else
            glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, size.width(), size.height());
#endif
        }
        GLint i = 0;
        glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT, GL_RENDERBUFFER_DEPTH_SIZE_EXT, &i);
        glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
                                     GL_RENDERBUFFER_EXT, depth_stencil_buffer);
        fbo_attachment = QGLFramebufferObject::Depth;
        valid = checkFramebufferStatus();
        if (!valid)
            glDeleteRenderbuffers(1, &depth_stencil_buffer);
    } else {
        fbo_attachment = QGLFramebufferObject::NoAttachment;
    }

    glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo);
    if (!valid) {
        if (color_buffer)
            glDeleteRenderbuffers(1, &color_buffer);
        else
            glDeleteTextures(1, &texture);
        glDeleteFramebuffers(1, &fbo);
        fbo_guard.setId(0);
    }
    QT_CHECK_GLERROR();

    format.setTextureTarget(target);
    format.setSamples(int(samples));
    format.setAttachment(fbo_attachment);
    format.setInternalTextureFormat(internal_format);
}
Пример #23
0
//---------------------------------------------------------------------------
GL2Renderbuffer::~GL2Renderbuffer()
{
	// delete the renderbuffer.
	glDeleteRenderbuffers( 1, &m_hGLHandle );
}
Пример #24
0
 ~RBO()
 {
     glDeleteRenderbuffers(1,&id());
 }
Пример #25
0
void GL__DeleteRenderbuffer(::uStatic* __this, ::uUInt renderbuffer_)
{
    glDeleteRenderbuffers(1, &renderbuffer_);
}
Пример #26
0
RenderBuffer::~RenderBuffer()
{
    glDeleteRenderbuffers(1, &bufferId);
    assert(FrameBuffer::getError() == GL_NO_ERROR);
}
Пример #27
0
void GLFramebuffer::free() {
    glDeleteRenderbuffers(1, &mColor);
    glDeleteRenderbuffers(1, &mDepth);
}
Пример #28
0
 template<> void Destroy<GlObject_Type::RenderBuffer>(RawGLHandle object)
 { 
     glDeleteRenderbuffers(1, &object);
 }
Пример #29
0
void GraphicsContext3D::deleteRenderbuffer(Platform3DObject renderbuffer)
{
    makeContextCurrent();
    glDeleteRenderbuffers(1, &renderbuffer);
}
Пример #30
0
bool Context::try_create_fbo( GLsizei width , GLsizei height , int flags )
{
	tplog2( "CREATING FRAMEBUFFER" );

	GLuint 		fbo;
	GLuintSet 	rb;

	bool h_depth = false;
	bool h_stencil = false;

	glGenFramebuffers( 1 , & fbo );

	glBindFramebuffer( GL_FRAMEBUFFER , fbo );

	glFramebufferTexture2D( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , texture_target , texture , 0 );

	if ( flags & FBO_TRY_DEPTH_STENCIL )
	{
		tplog2( "  CREATING DEPTH/STENCIL RENDERBUFFERS" );

		GLuint depth_stencil_rb;

		glGenRenderbuffers( 1 , & depth_stencil_rb );
		glBindRenderbuffer( GL_RENDERBUFFER , depth_stencil_rb );
		glRenderbufferStorage( GL_RENDERBUFFER , GL_DEPTH_STENCIL , width , height );
		glBindRenderbuffer( GL_RENDERBUFFER , 0 );
	    glFramebufferRenderbuffer( GL_FRAMEBUFFER , GL_STENCIL_ATTACHMENT , GL_RENDERBUFFER, depth_stencil_rb );
	    glFramebufferRenderbuffer( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_RENDERBUFFER , depth_stencil_rb );

	    rb.insert( depth_stencil_rb );

	    h_depth = true;
	    h_stencil = true;
	}

	if ( flags & FBO_TRY_DEPTH )
	{
		tplog2( "  CREATING DEPTH RENDERBUFFER" );

		GLuint depth_rb;

		glGenRenderbuffers( 1 , & depth_rb );
	    glBindRenderbuffer( GL_RENDERBUFFER , depth_rb );
	    glRenderbufferStorage( GL_RENDERBUFFER , GL_DEPTH_COMPONENT16 , width , height );
	    glBindRenderbuffer( GL_RENDERBUFFER , 0 );
	    glFramebufferRenderbuffer( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_RENDERBUFFER , depth_rb );

	    rb.insert( depth_rb );

	    h_depth = true;
	}

	if ( flags & FBO_TRY_STENCIL )
	{
		tplog2( "  CREATING STENCIL RENDERBUFFER" );

		GLuint stencil_rb;

	    glGenRenderbuffers( 1 , & stencil_rb );
	    glBindRenderbuffer( GL_RENDERBUFFER , stencil_rb );
	    glRenderbufferStorage( GL_RENDERBUFFER , GL_STENCIL_INDEX8 , width , height );
	    glBindRenderbuffer( GL_RENDERBUFFER , 0 );
	    glFramebufferRenderbuffer( GL_FRAMEBUFFER , GL_STENCIL_ATTACHMENT , GL_RENDERBUFFER , stencil_rb );

	    rb.insert( stencil_rb );

	    h_stencil = true;
	}

	if ( GL_FRAMEBUFFER_COMPLETE != glCheckFramebufferStatus( GL_FRAMEBUFFER ) )
	{
		glBindFramebuffer( GL_FRAMEBUFFER , 0 );

		tplog2( "  DESTROYING FRAMEBUFFER %u" , fbo );
		glDeleteFramebuffers( 1 , & fbo );

		for ( GLuintSet::const_iterator it = rb.begin(); it != rb.end(); ++it )
		{
			tplog2( "  DESTROYING RENDERBUFFER %u" , *it );
			glDeleteRenderbuffers( 1 , & * it );
		}

		tplog2( "* FRAMEBUFFER IS NOT COMPLETE" );

		return false;
	}

	tplog2( "* FRAMEBUFFER IS COMPLETE" );

	framebuffer = fbo;
	renderbuffers.insert( rb.begin() , rb.end() );
	have_depth = h_depth;
	have_stencil = h_stencil;

	return true;
}