VirtualBox

Changeset 82240 in vbox


Ignore:
Timestamp:
Nov 27, 2019 12:07:12 PM (5 years ago)
Author:
vboxsync
Message:

Devices/Graphics: OpenGL backend: simplified the color format conversion

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-glHlp.cpp

    r82096 r82240  
    3939    GLboolean normalized;
    4040    GLsizei   stride;
     41    GLsizei   offset;
    4142} VertexAttribDesc;
    4243
     
    6667    GLuint framebuffer;                     /* Framebuffer object name. */
    6768
    68     GLuint aVertexBuffers[2];               /* Vertex attribute buffers. Position + texcoord. */
     69    GLuint vertexBuffer;                    /* Vertex attribute buffer. Position + texcoord. */
    6970} VMSVGA3DFORMATCONVERTER;
    7071
     
    7273static const VertexAttribDesc aVertexAttribs[] =
    7374{
    74     {2, GL_FLOAT, GL_FALSE, 8 }, /* Position. */
    75     {2, GL_FLOAT, GL_FALSE, 8 }  /* Texcoord. */
    76 };
    77 
    78 /* Triangle fan positions. */
    79 static float const aAttrib0[] =
    80 {
    81     -1.0f,  -1.0f,
    82      1.0f,  -1.0f,
    83      1.0f,   1.0f,
    84     -1.0f,   1.0f
    85 };
    86 
    87 /* Triangle fan texcoords. */
    88 static float const aAttrib1[] =
    89 {
    90     0.0f,   0.0f,
    91     1.0f,   0.0f,
    92     1.0f,   1.0f,
    93     0.0f,   1.0f
     75    {2, GL_FLOAT, GL_FALSE, 16, 0 }, /* Position. */
     76    {2, GL_FLOAT, GL_FALSE, 16, 8 }  /* Texcoord. */
     77};
     78
     79/* Triangle fan */
     80static float const aAttribData[] =
     81{
     82    /* positions      texcoords */
     83    -1.0f,  -1.0f,    0.0f,   0.0f,
     84     1.0f,  -1.0f,    1.0f,   0.0f,
     85     1.0f,   1.0f,    1.0f,   1.0f,
     86    -1.0f,   1.0f,    0.0f,   1.0f
    9487};
    9588
     
    432425    GL_CHECK_ERROR();
    433426
     427    pState->ext.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, pConv->framebuffer);
     428    GL_CHECK_ERROR();
     429
     430    static GLenum aDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
     431    pState->ext.glDrawBuffers(RT_ELEMENTS(aDrawBuffers), aDrawBuffers);
     432    GL_CHECK_ERROR();
     433
     434    pState->ext.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
     435    GL_CHECK_ERROR();
     436
    434437    /*
    435      * Vertex attribute arrays.
     438     * Vertex attribute array.
    436439     */
    437     pState->ext.glGenBuffers(RT_ELEMENTS(pConv->aVertexBuffers), pConv->aVertexBuffers);
    438     GL_CHECK_ERROR();
    439 
    440     struct AttribData
    441     {
    442         GLsizeiptr size;
    443         const GLvoid * data;
    444     };
    445 
    446     static struct AttribData attribData[RT_ELEMENTS(pConv->aVertexBuffers)] =
    447     {
    448         { sizeof(aAttrib0), aAttrib0 },
    449         { sizeof(aAttrib1), aAttrib1 },
    450     };
    451 
    452     GLuint index;
    453     for (index = 0; index < RT_ELEMENTS(pConv->aVertexBuffers); ++index)
    454     {
    455         pState->ext.glBindBuffer(GL_ARRAY_BUFFER, pConv->aVertexBuffers[index]);
    456         GL_CHECK_ERROR();
    457 
    458         pState->ext.glBufferData(GL_ARRAY_BUFFER, attribData[index].size, attribData[index].data, GL_STATIC_DRAW);
    459         GL_CHECK_ERROR();
    460 
    461         pState->ext.glVertexAttribPointer(index, aVertexAttribs[index].size, aVertexAttribs[index].type,
    462                                           aVertexAttribs[index].normalized, aVertexAttribs[index].stride,
    463                                           (const GLvoid *)(uintptr_t)0);
    464         GL_CHECK_ERROR();
    465     }
     440    pState->ext.glGenBuffers(1, &pConv->vertexBuffer);
     441    GL_CHECK_ERROR();
     442
     443    pState->ext.glBindBuffer(GL_ARRAY_BUFFER, pConv->vertexBuffer);
     444    GL_CHECK_ERROR();
     445
     446    pState->ext.glBufferData(GL_ARRAY_BUFFER, sizeof(aAttribData), aAttribData, GL_STATIC_DRAW);
     447    GL_CHECK_ERROR();
    466448
    467449    pState->ext.glBindBuffer(GL_ARRAY_BUFFER, 0);
     
    506488    deleteShaderProgram(pState, &pConv->programYUY2ToRGB);
    507489
    508     if (pConv->aVertexBuffers[0])
    509     {
    510         pState->ext.glDeleteBuffers(RT_ELEMENTS(pConv->aVertexBuffers), pConv->aVertexBuffers);
    511         GL_CHECK_ERROR();
    512     }
    513     RT_ZERO(pConv->aVertexBuffers);
     490    if (pConv->vertexBuffer)
     491    {
     492        pState->ext.glDeleteBuffers(1, &pConv->vertexBuffer);
     493        GL_CHECK_ERROR();
     494
     495        pConv->vertexBuffer = 0;
     496    }
    514497
    515498    pConv->pState = 0;
     
    570553    GL_CHECK_ERROR();
    571554
    572     static GLenum aDrawBuffers[] = { GL_COLOR_ATTACHMENT0 };
    573     pState->ext.glDrawBuffers(RT_ELEMENTS(aDrawBuffers), aDrawBuffers);
    574     GL_CHECK_ERROR();
    575 
    576555    Assert(pState->ext.glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
    577556}
     
    586565    PVMSVGA3DCONTEXT pContext = &pState->SharedCtx;
    587566
    588     glBindTexture(GL_TEXTURE_2D, texture);
    589     GL_CHECK_ERROR();
     567    RT_NOREF(texture);
    590568
    591569    pState->ext.glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
    592     GL_CHECK_ERROR();
    593 
    594     glBindTexture(GL_TEXTURE_2D, 0);
    595570    GL_CHECK_ERROR();
    596571
     
    615590                     bool fToRGB)
    616591{
     592    if (!fToRGB)
     593    {
     594        /** @todo Disable readback transfers for now. They cause crash in glDrawArrays with Mesa 19.2 after
     595         * a previously converted texture is deleted and another texture is being converted.
     596         * Such transfer are useless anyway for the emulated YUV formats and the guest should not need them usually.
     597         */
     598        return;
     599    }
     600
     601    LogFunc(("formatConversion: idActiveContext %u, pConv %p, sid=%u, oglid=%u, oglidEmul=%u, mm=%u, %s\n",
     602             pState->idActiveContext, pState->pConv, pSurface->id, pSurface->oglId.texture, pSurface->idEmulated, iMipmap, fToRGB ? "ToRGB" : "FromRGB"));
     603
    617604    PVMSVGA3DFORMATCONVERTER pConv = pState->pConv;
    618605    AssertReturnVoid(pConv);
     
    661648    VMSVGA3D_SET_CURRENT_CONTEXT(pState, pContext);
    662649
    663     GLuint index;
    664     for (index = 0; index < RT_ELEMENTS(pConv->aVertexBuffers); ++index)
    665     {
    666         pState->ext.glEnableVertexAttribArray(index);
    667         GL_CHECK_ERROR();
    668     }
    669 
    670650    setShaderProgram(pState, pProgram, cWidth, cHeight);
    671651
     
    691671    GL_CHECK_ERROR();
    692672
     673    pState->ext.glBindBuffer(GL_ARRAY_BUFFER, pConv->vertexBuffer);
     674    GL_CHECK_ERROR();
     675
     676    GLuint index;
     677    for (index = 0; index < RT_ELEMENTS(aVertexAttribs); ++index)
     678    {
     679        pState->ext.glEnableVertexAttribArray(index);
     680        GL_CHECK_ERROR();
     681
     682        pState->ext.glVertexAttribPointer(index, aVertexAttribs[index].size, aVertexAttribs[index].type,
     683                                          aVertexAttribs[index].normalized, aVertexAttribs[index].stride,
     684                                          (const GLvoid *)(uintptr_t)aVertexAttribs[index].offset);
     685        GL_CHECK_ERROR();
     686    }
     687
    693688    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    694689    GL_CHECK_ERROR();
    695690
     691    pState->ext.glBindBuffer(GL_ARRAY_BUFFER, 0);
     692    GL_CHECK_ERROR();
     693
    696694    glBindTexture(GL_TEXTURE_2D, 0);
    697695    GL_CHECK_ERROR();
     
    702700    GL_CHECK_ERROR();
    703701
    704     for (index = 0; index < RT_ELEMENTS(pConv->aVertexBuffers); ++index)
     702    for (index = 0; index < RT_ELEMENTS(aVertexAttribs); ++index)
    705703    {
    706704        pState->ext.glDisableVertexAttribArray(index);
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