VirtualBox

Changeset 45027 in vbox for trunk/src/VBox/GuestHost


Ignore:
Timestamp:
Mar 13, 2013 6:17:40 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
84269
Message:

crOpenGL: shader/program state fixes; glDrawXxx-based blitting fixes, etc.

Location:
trunk/src/VBox/GuestHost/OpenGL
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/include/cr_hash.h

    r44887 r45027  
    3030DECLEXPORT(GLuint) crHashIdPoolAllocBlock( CRHashIdPool *pool, GLuint count );
    3131DECLEXPORT(void) crHashIdPoolFreeBlock( CRHashIdPool *pool, GLuint first, GLuint count );
     32/* @return GL_TRUE if the id is allocated, and GL_FALSE if the id was already allocated */
    3233DECLEXPORT(GLboolean) crHashIdPoolAllocId( CRHashIdPool *pool, GLuint id );
    3334
     
    4041 * which will also ensure there is no entry with the specified key left in the table */
    4142DECLEXPORT(GLuint) crHashtableAllocKeys( CRHashTable *h, GLsizei range );
     43/* @return GL_TRUE if the id is allocated, and GL_FALSE if the id was already allocated */
    4244DECLEXPORT(GLboolean) crHashtableAllocRegisterKey( CRHashTable *h,  GLuint key);
    4345DECLEXPORT(void) crHashtableDelete( CRHashTable *h, unsigned long key, CRHashtableCallback deleteCallback );
  • trunk/src/VBox/GuestHost/OpenGL/include/state/cr_glsl.h

    r44529 r45027  
    100100DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateShader(GLuint id, GLenum type);
    101101DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateProgram(GLuint id);
     102DECLEXPORT(GLuint) STATE_APIENTRY crStateDeleteObjectARB( GLhandleARB obj );
    102103
    103104DECLEXPORT(GLboolean) STATE_APIENTRY crStateIsProgramUniformsCached(GLuint program);
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_glsl.c

    r44930 r45027  
    259259}
    260260
     261DECLEXPORT(GLuint) STATE_APIENTRY crStateDeleteObjectARB( GLhandleARB obj )
     262{
     263    GLuint hwId = crStateGetProgramHWID(obj);
     264    if (hwId)
     265    {
     266        crStateDeleteProgram(obj);
     267    }
     268    else
     269    {
     270        hwId = crStateGetShaderHWID(obj);
     271        crStateDeleteShader(obj);
     272    }
     273    return hwId;
     274}
     275
    261276DECLEXPORT(GLuint) STATE_APIENTRY crStateCreateShader(GLuint hwid, GLenum type)
    262277{
     
    268283    CRASSERT(!crStateGetShaderObj(stateId));
    269284#else
     285    /* the proogram and shader names must not intersect because DeleteObjectARB must distinguish between them
     286     * see crStateDeleteObjectARB
     287     * this is why use programs table for shader keys allocation */
     288    stateId = crHashtableAllocKeys(g->glsl.programs, 1);
     289    if (!stateId)
     290    {
     291        crWarning("failed to allocate program key");
     292        return 0;
     293    }
     294
    270295    /* the id may not necesserily be hwid after save state restoration */
    271296    while ((pShader = crStateGetShaderObj(stateId)) != NULL)
     
    312337    }
    313338#else
    314     /* the id may not necesserily be hwid after save state restoration */
    315     while ((pProgram = crStateGetProgramObj(stateId)) != NULL)
    316     {
    317         GLuint newStateId = stateId + 7;
    318         crDebug("Program object %d already exists, generating a new one, %d", stateId, newStateId);
    319         stateId = newStateId;
     339    stateId = crHashtableAllocKeys(g->glsl.programs, 1);
     340    if (!stateId)
     341    {
     342        crWarning("failed to allocate program key");
     343        return 0;
    320344    }
    321345#endif
     
    324348    if (!pProgram)
    325349    {
    326         crWarning("crStateCreateShader: Out of memory!");
     350        crWarning("crStateCreateProgram: Out of memory!");
    327351        return 0;
    328352    }
     
    364388}
    365389
     390static void crStateDbgCheckNoProgramOfId(void *data)
     391{
     392    crError("Unexpected Program id");
     393}
     394
    366395DECLEXPORT(void) STATE_APIENTRY crStateDeleteShader(GLuint shader)
    367396{
     
    379408        CRContext *g = GetCurrentContext();
    380409        crHashtableDelete(g->glsl.shaders, shader, crStateFreeGLSLShader);
     410        /* since we use programs table for key allocation key allocation, we need to
     411         * free the key in the programs table.
     412         * See comment in crStateCreateShader */
     413        crHashtableDelete(g->glsl.programs, shader, crStateDbgCheckNoProgramOfId);
    381414    }
    382415}
  • trunk/src/VBox/GuestHost/OpenGL/util/blitter.cpp

    r45009 r45027  
    112112
    113113/* GL_TRIANGLE_FAN */
    114 DECLINLINE(GLfloat*) crBltVtRectTFNormalized(const RTRECT *pRect, uint32_t normalX, uint32_t normalY, GLfloat* pBuff)
     114DECLINLINE(GLfloat*) crBltVtRectTFNormalized(const RTRECT *pRect, uint32_t normalX, uint32_t normalY, GLfloat* pBuff, uint32_t height)
    115115{
    116116    /* going ccw:
     
    121121    /* xLeft yTop */
    122122    pBuff[0] = ((float)pRect->xLeft)/((float)normalX);
    123     pBuff[1] = ((float)pRect->yTop)/((float)normalY);
     123    pBuff[1] = ((float)(height ? height - pRect->yTop : pRect->yTop))/((float)normalY);
    124124
    125125    /* xLeft yBottom */
    126126    pBuff[2] = pBuff[0];
    127     pBuff[3] = ((float)pRect->yBottom)/((float)normalY);
     127    pBuff[3] = ((float)(height ? height - pRect->yBottom : pRect->yBottom))/((float)normalY);
    128128
    129129    /* xRight yBottom */
     
    137137}
    138138
    139 DECLINLINE(GLint*) crBltVtRectTF(const RTRECT *pRect, uint32_t normalX, uint32_t normalY, GLint* pBuff)
     139DECLINLINE(GLint*) crBltVtRectTF(const RTRECT *pRect, uint32_t normalX, uint32_t normalY, GLint* pBuff, uint32_t height)
    140140{
    141141    /* xLeft yTop */
    142142    pBuff[0] = pRect->xLeft;
    143     pBuff[1] = pRect->yTop;
     143    pBuff[1] = height ? height - pRect->yTop : pRect->yTop;
    144144
    145145    /* xLeft yBottom */
    146146    pBuff[2] = pBuff[0];
    147     pBuff[3] = pRect->yBottom;
     147    pBuff[3] = height ? height - pRect->yBottom : pRect->yBottom;
    148148
    149149    /* xRight yBottom */
     
    169169    pIndex[4] = iBase + 2;
    170170    pIndex[5] = iBase + 3;
    171     *piBase = iBase + 6;
     171    *piBase = iBase + 4;
    172172    return pIndex + 6;
    173173}
    174174
    175175/* Indexed GL_TRIANGLES */
    176 DECLINLINE(GLfloat*) crBltVtRectITNormalized(const RTRECT *pRect, uint32_t normalX, uint32_t normalY, GLfloat* pBuff)
    177 {
    178     GLfloat* ret = crBltVtRectTFNormalized(pRect, normalX, normalY, pBuff);
     176DECLINLINE(GLfloat*) crBltVtRectITNormalized(const RTRECT *pRect, uint32_t normalX, uint32_t normalY, GLfloat* pBuff, uint32_t height)
     177{
     178    GLfloat* ret = crBltVtRectTFNormalized(pRect, normalX, normalY, pBuff, height);
    179179    return ret;
    180180}
    181181
    182 DECLINLINE(GLint*) crBltVtRectIT(RTRECT *pRect, uint32_t normalX, uint32_t normalY, GLint* pBuff, GLubyte **ppIndex, GLubyte *piBase)
    183 {
    184     GLint* ret = crBltVtRectTF(pRect, normalX, normalY, pBuff);
     182DECLINLINE(GLint*) crBltVtRectIT(RTRECT *pRect, uint32_t normalX, uint32_t normalY, GLint* pBuff, GLubyte **ppIndex, GLubyte *piBase, uint32_t height)
     183{
     184    GLint* ret = crBltVtRectTF(pRect, normalX, normalY, pBuff, height);
    185185
    186186    if (ppIndex)
     
    203203
    204204
    205 static GLfloat* crBltVtRectsITNormalized(const RTRECT *paRects, uint32_t cRects, uint32_t normalX, uint32_t normalY, GLfloat* pBuff, GLubyte **ppIndex, GLubyte *piBase)
     205static GLfloat* crBltVtRectsITNormalized(const RTRECT *paRects, uint32_t cRects, uint32_t normalX, uint32_t normalY, GLfloat* pBuff, GLubyte **ppIndex, GLubyte *piBase, uint32_t height)
    206206{
    207207    uint32_t i;
    208208    for (i = 0; i < cRects; ++i)
    209209    {
    210         pBuff = crBltVtRectITNormalized(&paRects[i], normalX, normalY, pBuff);
     210        pBuff = crBltVtRectITNormalized(&paRects[i], normalX, normalY, pBuff, height);
    211211    }
    212212
     
    235235        }
    236236
     237#ifndef DEBUG_misha
     238        /* debugging: ensure we calculate proper buffer size */
    237239        cbBuffer += 16;
     240#endif
    238241
    239242        pBuffer->pvBuffer = RTMemAlloc(cbBuffer);
     
    291294{
    292295    GLuint normalX, normalY;
     296    uint32_t height = (fFlags & CRBLT_F_OFFSCREEN) ? 0 : pDstSize->cy;
    293297
    294298    switch (pSrc->target)
     
    329333        {
    330334            pVerticies = (GLfloat*)crBltBufGet(&pBlitter->Verticies, cElements * 2 * sizeof (*pVerticies));
    331             crBltVtRectTFNormalized(paDstRect, normalX, normalY, pVerticies);
     335            crBltVtRectTFNormalized(paDstRect, normalX, normalY, pVerticies, height);
    332336            pTexCoords = pVerticies;
    333337        }
     
    335339        {
    336340            pVerticies = (GLfloat*)crBltBufGet(&pBlitter->Verticies, cElements * 2 * 2 * sizeof (*pVerticies));
    337             pTexCoords = crBltVtRectTFNormalized(paDstRect, 1, 1, pVerticies);
    338             crBltVtRectTFNormalized(paSrcRect, normalX, normalY, pTexCoords);
     341            pTexCoords = crBltVtRectTFNormalized(paDstRect, 1, 1, pVerticies, height);
     342            crBltVtRectTFNormalized(paSrcRect, normalX, normalY, pTexCoords, height);
    339343        }
    340344
     
    365369        if (bUseSameVerticies)
    366370        {
    367             pVerticies = (GLfloat*)crBltBufGet(&pBlitter->Verticies, cElements * 2 * sizeof (*pVerticies));
    368             crBltVtRectsITNormalized(paDstRect, cRects, normalX, normalY, pVerticies, &pIndicies, &iIdxBase);
     371            pVerticies = (GLfloat*)crBltBufGet(&pBlitter->Verticies, cElements * 2 * sizeof (*pVerticies) + cIndicies * sizeof (*pIndicies));
     372            crBltVtRectsITNormalized(paDstRect, cRects, normalX, normalY, pVerticies, &pIndicies, &iIdxBase, height);
    369373            pTexCoords = pVerticies;
    370374        }
    371375        else
    372376        {
    373             pVerticies = (GLfloat*)crBltBufGet(&pBlitter->Verticies, cElements * 2 * 2 * sizeof (*pVerticies));
    374             pTexCoords = crBltVtRectsITNormalized(paDstRect, cRects, 1, 1, pVerticies, &pIndicies, &iIdxBase);
    375             crBltVtRectsITNormalized(paSrcRect, cRects, normalX, normalY, pTexCoords, NULL, NULL);
     377            pVerticies = (GLfloat*)crBltBufGet(&pBlitter->Verticies, cElements * 2 * 2 * sizeof (*pVerticies) + cIndicies * sizeof (*pIndicies));
     378            pTexCoords = crBltVtRectsITNormalized(paDstRect, cRects, 1, 1, pVerticies, &pIndicies, &iIdxBase, height);
     379            crBltVtRectsITNormalized(paSrcRect, cRects, normalX, normalY, pTexCoords, NULL, NULL, height);
    376380        }
    377381
Note: See TracChangeset for help on using the changeset viewer.

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