VirtualBox

Ignore:
Timestamp:
Feb 22, 2011 1:45:06 PM (14 years ago)
Author:
vboxsync
Message:

crOpenGL: use PBO to get texture data in offscreen rendering mode

Location:
trunk/src/VBox/HostServices/SharedOpenGL/crserverlib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/get_components.py

    r32078 r36052  
    3131        'GL_TEXTURE_HEIGHT': 1,
    3232        'GL_TEXTURE_DEPTH': 1,
    33         # 'GL_TEXTURE_INTERNAL_FORMAT': 1,  THIS CONFLICTS WITH SOMETHING?!
     33        # 'GL_TEXTURE_INTERNAL_FORMAT': 1,  THIS CONFLICTS WITH GL_TEXTURE_COMPONENTS!
    3434        'GL_TEXTURE_BORDER': 1,
    3535        'GL_TEXTURE_RED_SIZE': 1,
     
    110110        'GL_CURRENT_QUERY_ARB': (1, 'CR_ARB_occlusion_query'),
    111111        'GL_TEXTURE_COMPRESSED_IMAGE_SIZE': (1, 'CR_ARB_texture_compression'),
     112    'GL_TEXTURE_COMPRESSED': (1, 'CR_ARB_texture_compression'),
    112113        'GL_COORD_REPLACE_ARB': (1, 'CR_ARB_point_sprite'),
    113114}
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_config.c

    r35969 r36052  
    5757    cr_server.screenCount = 0;
    5858    cr_server.bForceOffscreenRendering = GL_FALSE;
     59    cr_server.bUsePBOForReadback = GL_FALSE;
    5960}
    6061
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_main.c

    r36050 r36052  
    339339    crStateDiffAPI( &(cr_server.head_spu->dispatch_table) );
    340340
     341    /*Check for PBO support*/
     342    if (crStateGetCurrent()->extensions.ARB_pixel_buffer_object)
     343    {
     344        cr_server.bUsePBOForReadback=GL_TRUE;
     345    }
     346
    341347    return GL_TRUE;
    342348}
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_muralfbo.c

    r35998 r36052  
    189189    GLuint uid;
    190190    GLenum status;
     191    SPUDispatchTable *gl = &cr_server.head_spu->dispatch_table;
    191192
    192193    CRASSERT(mural->idFBO==0);
    193194
    194195    /*Color texture*/
    195     cr_server.head_spu->dispatch_table.GenTextures(1, &mural->idColorTex);
    196     cr_server.head_spu->dispatch_table.BindTexture(GL_TEXTURE_2D, mural->idColorTex);
    197     cr_server.head_spu->dispatch_table.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    198     cr_server.head_spu->dispatch_table.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    199     cr_server.head_spu->dispatch_table.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    200     cr_server.head_spu->dispatch_table.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    201     cr_server.head_spu->dispatch_table.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mural->width, mural->height,
    202                                                   0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
     196    gl->GenTextures(1, &mural->idColorTex);
     197    gl->BindTexture(GL_TEXTURE_2D, mural->idColorTex);
     198    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     199    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     200    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
     201    gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
     202    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     203    {
     204        gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
     205    }
     206    gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mural->width, mural->height,
     207                   0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
    203208
    204209    /*Depth&Stencil*/
    205     cr_server.head_spu->dispatch_table.GenRenderbuffersEXT(1, &mural->idDepthStencilRB);
    206     cr_server.head_spu->dispatch_table.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
    207     cr_server.head_spu->dispatch_table.RenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT,
    208                                                               mural->width, mural->height);
     210    gl->GenRenderbuffersEXT(1, &mural->idDepthStencilRB);
     211    gl->BindRenderbufferEXT(GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
     212    gl->RenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT,
     213                               mural->width, mural->height);
    209214
    210215    /*FBO*/
    211     cr_server.head_spu->dispatch_table.GenFramebuffersEXT(1, &mural->idFBO);
    212     cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mural->idFBO);
    213 
    214     cr_server.head_spu->dispatch_table.FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
    215                                                                GL_TEXTURE_2D, mural->idColorTex, 0);
    216     cr_server.head_spu->dispatch_table.FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
    217                                                                   GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
    218     cr_server.head_spu->dispatch_table.FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
    219                                                                   GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
    220 
    221     status = cr_server.head_spu->dispatch_table.CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
     216    gl->GenFramebuffersEXT(1, &mural->idFBO);
     217    gl->BindFramebufferEXT(GL_FRAMEBUFFER_EXT, mural->idFBO);
     218
     219    gl->FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
     220                                GL_TEXTURE_2D, mural->idColorTex, 0);
     221    gl->FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
     222                                   GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
     223    gl->FramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
     224                                   GL_RENDERBUFFER_EXT, mural->idDepthStencilRB);
     225
     226    status = gl->CheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    222227    if (status!=GL_FRAMEBUFFER_COMPLETE_EXT)
    223228    {
     
    228233    mural->fboHeight = mural->height;
    229234
     235    /*PBO*/
     236    if (cr_server.bUsePBOForReadback)
     237    {
     238        gl->GenBuffersARB(1, &mural->idPBO);
     239        gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, mural->idPBO);
     240        gl->BufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, mural->width*mural->height*4, 0, GL_STREAM_READ_ARB);
     241        gl->BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid);
     242
     243        if (!mural->idPBO)
     244        {
     245            crWarning("PBO create failed");
     246        }
     247    }
     248
    230249    /*Restore gl state*/
    231250    uid = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->hwid;
    232     cr_server.head_spu->dispatch_table.BindTexture(GL_TEXTURE_2D, uid);
     251    gl->BindTexture(GL_TEXTURE_2D, uid);
    233252
    234253    uid = ctx->framebufferobject.renderbuffer ? ctx->framebufferobject.renderbuffer->hwid:0;
    235     cr_server.head_spu->dispatch_table.BindRenderbufferEXT(GL_RENDERBUFFER_EXT, uid);
     254    gl->BindRenderbufferEXT(GL_RENDERBUFFER_EXT, uid);
    236255
    237256    uid = ctx->framebufferobject.drawFB ? ctx->framebufferobject.drawFB->hwid:0;
    238     cr_server.head_spu->dispatch_table.BindFramebufferEXT(GL_FRAMEBUFFER_EXT, uid);
     257    gl->BindFramebufferEXT(GL_FRAMEBUFFER_EXT, uid);
     258
     259    if (crStateIsBufferBound(GL_PIXEL_UNPACK_BUFFER_ARB))
     260    {
     261        gl->BindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, ctx->bufferobject.unpackBuffer->hwid);
     262    }
    239263}
    240264
     
    252276        mural->idColorTex = 0;
    253277        mural->idDepthStencilRB = 0;
     278    }
     279
     280    if (mural->idPBO!=0)
     281    {
     282        CRASSERT(cr_server.bUsePBOForReadback);
     283        cr_server.head_spu->dispatch_table.DeleteBuffersARB(1, &mural->idPBO);
     284        mural->idPBO = 0;
    254285    }
    255286}
     
    308339void crServerPresentFBO(CRMuralInfo *mural)
    309340{
    310     char *pixels, *tmppixels;
     341    char *pixels=NULL, *tmppixels;
    311342    GLuint uid;
    312343    int i, j;
    313344    CRrecti rect, rectwr, sectr;
     345    GLboolean bUsePBO;
    314346    CRContext *ctx = crStateGetCurrent();
    315347
     
    321353    }
    322354
    323     pixels = crAlloc(4*mural->fboWidth*mural->fboHeight);
    324     if (!pixels)
    325     {
    326         crWarning("Out of memory in crServerPresentFBO");
     355    if (!mural->width || !mural->height)
     356    {
    327357        return;
    328358    }
    329359
     360    if (cr_server.bUsePBOForReadback && !mural->idPBO)
     361    {
     362        crWarning("Mural doesn't have PBO even though bUsePBOForReadback is set!");
     363    }
     364
     365    bUsePBO = cr_server.bUsePBOForReadback && mural->idPBO;
     366
    330367    cr_server.head_spu->dispatch_table.BindTexture(GL_TEXTURE_2D, mural->idColorTex);
     368
     369    if (bUsePBO)
     370    {
     371        CRASSERT(mural->idPBO);
     372        cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, mural->idPBO);
     373    }
     374    else
     375    {
     376        if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     377        {
     378            cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
     379        }
     380
     381        pixels = crAlloc(4*mural->fboWidth*mural->fboHeight);
     382        if (!pixels)
     383        {
     384            crWarning("Out of memory in crServerPresentFBO");
     385            return;
     386        }
     387    }
     388
     389    /*read the texture, note pixels are NULL for PBO case as it's offset in the buffer*/   
    331390    cr_server.head_spu->dispatch_table.GetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
     391
     392    /*restore gl state*/
    332393    uid = ctx->texture.unit[ctx->texture.curTextureUnit].currentTexture2D->hwid;
    333394    cr_server.head_spu->dispatch_table.BindTexture(GL_TEXTURE_2D, uid);
     395
     396    if (bUsePBO)
     397    {
     398        pixels = cr_server.head_spu->dispatch_table.MapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY);
     399        if (!pixels)
     400        {
     401            crWarning("Failed to MapBuffer in crServerPresentFBO");
     402            return;
     403        }
     404    }
    334405
    335406    for (i=0; i<cr_server.screenCount; ++i)
     
    383454        }
    384455    }
    385     crFree(pixels);
     456
     457    if (bUsePBO)
     458    {
     459        cr_server.head_spu->dispatch_table.UnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
     460        cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid);
     461    }
     462    else
     463    {
     464        crFree(pixels);
     465        if (crStateIsBufferBound(GL_PIXEL_PACK_BUFFER_ARB))
     466        {
     467            cr_server.head_spu->dispatch_table.BindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, ctx->bufferobject.packBuffer->hwid);
     468        }
     469    }
    386470}
    387471
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette