VirtualBox

Ignore:
Timestamp:
Sep 29, 2009 9:55:43 AM (15 years ago)
Author:
vboxsync
Message:

crOpenGL: fix uniform location isn't uint and fix array uniforms caching for linux/nvidia combo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_glsl.c

    r23402 r23403  
    738738        }
    739739        pProgram->pUniforms[i].data = NULL;
    740         pProgram->pUniforms[i].location = ((GLuint*)pCurrent)[0];
    741         pCurrent += sizeof(GLuint);
     740        pProgram->pUniforms[i].location = ((GLint*)pCurrent)[0];
     741        pCurrent += sizeof(GLint);
    742742        cbName = ((GLsizei*)pCurrent)[0];
    743743        pCurrent += sizeof(GLsizei);
     
    762762}
    763763#else
     764static GLboolean crStateGLSLProgramCacheOneUniform(GLuint location, GLsizei cbName, GLchar *pName,
     765                                                   char **pCurrent, GLsizei *pcbWritten, GLsizei maxcbData)
     766{
     767    *pcbWritten += sizeof(GLint)+sizeof(GLsizei)+cbName;
     768    if (*pcbWritten>maxcbData)
     769    {
     770        crWarning("crStateGLSLProgramCacheUniforms: buffer too small");
     771        crFree(pName);
     772        return GL_FALSE;
     773    }
     774
     775    crDebug("crStateGLSLProgramCacheUniforms: uniform[%i]=%s.", location, pName);
     776
     777    ((GLint*)*pCurrent)[0] = location;
     778    *pCurrent += sizeof(GLint);
     779    ((GLsizei*)*pCurrent)[0] = cbName;
     780    *pCurrent += sizeof(GLsizei);
     781    crMemcpy(*pCurrent, pName, cbName);
     782    *pCurrent += cbName;
     783
     784    return GL_TRUE;
     785}
     786
    764787DECLEXPORT(void) STATE_APIENTRY
    765788crStateGLSLProgramCacheUniforms(GLuint program, GLsizei maxcbData, GLsizei *cbData, GLvoid *pData)
     
    795818    if (activeUniforms>0)
    796819    {
    797         /*+8 to make sure our array uniforms with higher indices will fit in as well*/
     820        /*+8 to make sure our array uniforms with higher indices and [] will fit in as well*/
    798821        GLchar *name = (GLchar *) crAlloc(maxUniformLen+8);
    799822        GLenum type;
    800823        GLint size;
    801824        GLsizei cbName;
    802         GLuint location;
     825        GLint location;
    803826
    804827        if (!name)
     
    813836            location = diff_api.GetUniformLocation(pProgram->hwid, name);
    814837
    815             cbWritten += sizeof(GLuint)+sizeof(GLsizei)+cbName;
    816             if (cbWritten>maxcbData)
    817             {
    818                 crWarning("crStateGLSLProgramCacheUniforms: buffer too small");
    819                 crFree(name);
     838            if (!crStateGLSLProgramCacheOneUniform(location, cbName, name, &pCurrent, &cbWritten, maxcbData))
    820839                return;
    821             }
    822 
    823             crDebug("crStateGLSLProgramCacheUniforms: uniform[%i]=%d, %s. size=%i", i, location, name, size);
    824 
    825             ((GLuint*)pCurrent)[0] = location;
    826             pCurrent += sizeof(GLuint);
    827             ((GLsizei*)pCurrent)[0] = cbName;
    828             pCurrent += sizeof(GLsizei);
    829             crMemcpy(pCurrent, name, cbName);
    830             pCurrent += cbName;
    831840
    832841            /* Only one active uniform variable will be reported for a uniform array by glGetActiveUniform,
     
    836845            {
    837846                char *pIndexStr = crStrchr(name, '[');
    838                 fakeUniformsCount += size-1;
    839                
    840 
     847                GLint firstIndex=1;
     848                fakeUniformsCount += size;
     849
     850                crDebug("crStateGLSLProgramCacheUniforms: expanding array uniform, size=%i", size);
     851
     852                /*For array uniforms it's valid to query location of 1st element as both uniform and uniform[0].
     853                 *The name returned by glGetActiveUniform is driver dependant,
     854                 *atleast it's with [0] on win/ati and without [0] on linux/nvidia.
     855                 */               
    841856                if (!pIndexStr)
    842857                {
    843                     crWarning("Array uniform name %s doesn't contain [!?", name);
     858                    pIndexStr = name+cbName;
     859                    firstIndex=0;
    844860                }
    845861                else
    846862                {
    847                     for (j=1; j<size; ++j)
    848                     {
    849                         sprintf(pIndexStr, "[%i]", j);
    850                         cbName = crStrlen(name);
    851 
    852                         location = diff_api.GetUniformLocation(pProgram->hwid, name);
    853                         crDebug("crStateGLSLProgramCacheUniforms: uniform[%i].[%i]=%d, %s", i, j, location, name);
    854 
    855                         cbWritten += sizeof(GLuint)+sizeof(GLsizei)+cbName;
    856                         if (cbWritten>maxcbData)
    857                         {
    858                             crWarning("crStateGLSLProgramCacheUniforms: buffer too small");
    859                             crFree(name);
    860                             return;
    861                         }
    862 
    863                         ((GLuint*)pCurrent)[0] = location;
    864                         pCurrent += sizeof(GLuint);
    865                         ((GLsizei*)pCurrent)[0] = cbName;
    866                         pCurrent += sizeof(GLsizei);
    867                         crMemcpy(pCurrent, name, cbName);
    868                         pCurrent += cbName;
    869                     }
     863                    cbName = pIndexStr-name;
     864                    if (!crStateGLSLProgramCacheOneUniform(location, cbName, name, &pCurrent, &cbWritten, maxcbData))
     865                        return;
     866                }
     867
     868                for (j=firstIndex; j<size; ++j)
     869                {
     870                    sprintf(pIndexStr, "[%i]", j);
     871                    cbName = crStrlen(name);
     872
     873                    location = diff_api.GetUniformLocation(pProgram->hwid, name);
     874
     875                    if (!crStateGLSLProgramCacheOneUniform(location, cbName, name, &pCurrent, &cbWritten, maxcbData))
     876                        return;
    870877                }
    871878            }
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