VirtualBox

Ignore:
Timestamp:
Sep 20, 2009 10:02:28 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
52579
Message:

video hw accel: use one shader instead of multiple to fox old ATI driver problems

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.cpp

    r22953 r23162  
    933933}
    934934
    935 class VBoxVHWAGlShader
     935class VBoxVHWAGlShaderComponent
    936936{
    937937public:
    938     VBoxVHWAGlShader(const char *aRcName, GLenum aType) :
    939         mShader(0),
     938    VBoxVHWAGlShaderComponent(const char *aRcName, GLenum aType) :
    940939        mRcName(aRcName),
    941         mType(aType)
     940        mType(aType),
     941        mInitialized(false)
    942942    {}
    943943
    944 //    virtual ~VBoxVHWAGlShader();
     944//    virtual ~VBoxVHWAGlShaderComponent();
     945
    945946
    946947    int init();
    947948//    virtual int initUniforms(class VBoxVHWAGlProgram * pProgram){}
    948     void uninit();
    949     bool isInitialized() { return mShader; }
    950     GLuint shader() {return mShader;}
     949//    void uninit();
     950
     951    const char * contents() { return mSource.constData(); }
     952    bool isInitialized() { return mInitialized; }
    951953private:
    952     GLuint mShader;
    953954    const char *mRcName;
    954955    GLenum mType;
     956    QByteArray mSource;
     957    bool mInitialized;
    955958};
    956959
    957 int VBoxVHWAGlShader::init()
     960int VBoxVHWAGlShaderComponent::init()
    958961{
    959962//    Assert(!isInitialized());
     
    971974    QString program = is.readAll();
    972975
     976    mSource = program.toAscii();
     977
     978    mInitialized = true;
     979    return VINF_SUCCESS;
     980}
     981
     982class VBoxVHWAGlShader
     983{
     984public:
     985    VBoxVHWAGlShader() :
     986        mType(GL_FRAGMENT_SHADER),
     987        mcComponents(0)
     988    {}
     989
     990    VBoxVHWAGlShader & operator= (const VBoxVHWAGlShader & other)
     991    {
     992        mcComponents = other.mcComponents;
     993        mType = other.mType;
     994        if(mcComponents)
     995        {
     996            maComponents = new VBoxVHWAGlShaderComponent*[mcComponents];
     997            memcpy(maComponents, other.maComponents, mcComponents * sizeof(maComponents[0]));
     998        }
     999        return *this;
     1000    }
     1001
     1002    VBoxVHWAGlShader(const VBoxVHWAGlShader & other)
     1003    {
     1004        mcComponents = other.mcComponents;
     1005        mType = other.mType;
     1006        if(mcComponents)
     1007        {
     1008            maComponents = new VBoxVHWAGlShaderComponent*[mcComponents];
     1009            memcpy(maComponents, other.maComponents, mcComponents * sizeof(maComponents[0]));
     1010        }
     1011    }
     1012
     1013    VBoxVHWAGlShader(GLenum aType, VBoxVHWAGlShaderComponent ** aComponents, int cComponents)
     1014        : mType(aType)
     1015    {
     1016        maComponents = new VBoxVHWAGlShaderComponent*[cComponents];
     1017        mcComponents = cComponents;
     1018        memcpy(maComponents, aComponents, cComponents * sizeof(maComponents[0]));
     1019    }
     1020
     1021    ~VBoxVHWAGlShader() {delete[] maComponents;}
     1022    int init();
     1023    GLenum type() { return mType; }
     1024    GLuint shader() { return mShader; }
     1025private:
     1026    GLenum mType;
     1027    GLuint mShader;
     1028    VBoxVHWAGlShaderComponent ** maComponents;
     1029    int mcComponents;
     1030};
     1031
     1032int VBoxVHWAGlShader::init()
     1033{
     1034    int rc;
     1035    int *length;
     1036    const char **sources;
     1037    length = new int[mcComponents];
     1038    sources = new const char*[mcComponents];
     1039    for(int i = 0; i < mcComponents; i++)
     1040    {
     1041        length[i] = -1;
     1042        rc = maComponents[i]->init();
     1043        Assert(RT_SUCCESS(rc));
     1044        if(RT_FAILURE(rc))
     1045            return rc;
     1046        sources[i] = maComponents[i]->contents();
     1047    }
     1048
     1049#ifdef DEBUG
     1050    VBOXQGLLOG(("\ncompiling shaders:\n------------\n"));
     1051    for(int i = 0; i < mcComponents; i++)
     1052    {
     1053        VBOXQGLLOG(("**********\n%s\n***********\n", sources[i]));
     1054    }
     1055    VBOXQGLLOG(("------------\n"));
     1056#endif
    9731057    mShader = vboxglCreateShader(mType);
    974     Assert(mShader);
    975     if(!mShader)
    976         return VERR_GENERAL_FAILURE;
    977 
    978  //   int length = program.length();
    979     QByteArray asciiStr = program.toAscii();
    980     const char * contents = asciiStr.constData();
    981     GLint length = -1;
    9821058
    9831059    VBOXQGL_CHECKERR(
    984             vboxglShaderSource(mShader, 1, &contents, &length);
     1060            vboxglShaderSource(mShader, mcComponents, sources, length);
    9851061            );
    9861062
     
    9971073    GLchar * pBuf = new GLchar[16300];
    9981074    vboxglGetShaderInfoLog(mShader, 16300, NULL, pBuf);
    999     VBOXQGLLOG(("compile log for shader:\n-----------\n%s\n---------\n", contents));
    1000     VBOXQGLLOG(("%s\n**********\n", pBuf));
     1075    VBOXQGLLOG(("\ncompile log:\n-----------\n%s\n---------\n", pBuf));
    10011076    delete pBuf;
    10021077#endif
     
    10071082        return VINF_SUCCESS;
    10081083    }
    1009 
    10101084
    10111085
     
    10141088            );
    10151089    mShader = 0;
     1090
     1091    delete[] length;
     1092    delete[] sources;
    10161093    return VERR_GENERAL_FAILURE;
    1017 }
    1018 
    1019 void VBoxVHWAGlShader::uninit()
    1020 {
    1021     if(!isInitialized())
    1022         return;
    1023 
    1024     VBOXQGL_CHECKERR(
    1025             vboxglDeleteShader(mShader);
    1026             );
    1027     mShader = 0;
    10281094}
    10291095
     
    10431109private:
    10441110    GLuint mProgram;
    1045     VBoxVHWAGlShader ** mpShaders;
     1111    VBoxVHWAGlShader *mShaders;
    10461112    int mcShaders;
    10471113};
     
    10491115VBoxVHWAGlProgram::VBoxVHWAGlProgram(VBoxVHWAGlShader ** apShaders, int acShaders) :
    10501116       mProgram(0),
    1051        mpShaders(NULL),
    10521117       mcShaders(0)
    10531118{
     
    10551120    if(acShaders)
    10561121    {
    1057         mpShaders = (VBoxVHWAGlShader **)malloc(sizeof(VBoxVHWAGlShader *) * acShaders);
    1058         memcpy(mpShaders, apShaders, sizeof(VBoxVHWAGlShader *) * acShaders);
     1122        mShaders = new VBoxVHWAGlShader[acShaders];
     1123        for(int i = 0; i < acShaders; i++)
     1124        {
     1125            mShaders[i] = *apShaders[i];
     1126        }
    10591127        mcShaders = acShaders;
    10601128    }
     
    10651133    uninit();
    10661134
    1067     if(mpShaders)
    1068     {
    1069         free(mpShaders);
     1135    if(mShaders)
     1136    {
     1137        delete[] mShaders;
    10701138    }
    10711139}
     
    10841152    for(int i = 0; i < mcShaders; i++)
    10851153    {
    1086         int rc = mpShaders[i]->init();
     1154        int rc = mShaders[i].init();
    10871155        Assert(RT_SUCCESS(rc));
    10881156        if(RT_FAILURE(rc))
     
    11031171        {
    11041172            VBOXQGL_CHECKERR(
    1105                     vboxglAttachShader(mProgram, mpShaders[i]->shader());
     1173                    vboxglAttachShader(mProgram, mShaders[i].shader());
    11061174                    );
    11071175        }
     
    14761544    ProgramList mPrograms;
    14771545
    1478     VBoxVHWAGlShader mShaderCConvApplyAYUV;
    1479 
    1480     VBoxVHWAGlShader mShaderCConvAYUV;
    1481 //    VBoxVHWAGlShader mShaderCConvAYUVVoid;
    1482     VBoxVHWAGlShader mShaderCConvBGR;
    1483 //    VBoxVHWAGlShader mShaderCConvBGRVoid;
    1484     VBoxVHWAGlShader mShaderCConvUYVY;
    1485 //    VBoxVHWAGlShader mShaderCConvUYVYVoid;
    1486     VBoxVHWAGlShader mShaderCConvYUY2;
    1487 //    VBoxVHWAGlShader mShaderCConvYUY2Void;
    1488     VBoxVHWAGlShader mShaderCConvYV12;
    1489 //    VBoxVHWAGlShader mShaderCConvYV12Void;
    1490     VBoxVHWAGlShader mShaderSplitBGRA;
     1546    VBoxVHWAGlShaderComponent mShaderCConvApplyAYUV;
     1547
     1548    VBoxVHWAGlShaderComponent mShaderCConvAYUV;
     1549//    VBoxVHWAGlShaderComponent mShaderCConvAYUVVoid;
     1550    VBoxVHWAGlShaderComponent mShaderCConvBGR;
     1551//    VBoxVHWAGlShaderComponent mShaderCConvBGRVoid;
     1552    VBoxVHWAGlShaderComponent mShaderCConvUYVY;
     1553//    VBoxVHWAGlShaderComponent mShaderCConvUYVYVoid;
     1554    VBoxVHWAGlShaderComponent mShaderCConvYUY2;
     1555//    VBoxVHWAGlShaderComponent mShaderCConvYUY2Void;
     1556    VBoxVHWAGlShaderComponent mShaderCConvYV12;
     1557//    VBoxVHWAGlShaderComponent mShaderCConvYV12Void;
     1558    VBoxVHWAGlShaderComponent mShaderSplitBGRA;
    14911559
    14921560    /* expected the dst surface texture to be bound to the 1-st tex unit */
    1493     VBoxVHWAGlShader mShaderCKeyDst;
     1561    VBoxVHWAGlShaderComponent mShaderCKeyDst;
    14941562    /* expected the dst surface texture to be bound to the 2-nd tex unit */
    1495     VBoxVHWAGlShader mShaderCKeyDst2;
    1496 //    VBoxVHWAGlShader mShaderCKeyDstVoid;
    1497 //    VBoxVHWAGlShader mShaderCKeySrc;
    1498 //    VBoxVHWAGlShader mShaderCKeySrcVoid;
    1499 
    1500     VBoxVHWAGlShader mShaderMainOverlay;
    1501     VBoxVHWAGlShader mShaderMainOverlayNoCKey;
     1563    VBoxVHWAGlShaderComponent mShaderCKeyDst2;
     1564//    VBoxVHWAGlShaderComponent mShaderCKeyDstVoid;
     1565//    VBoxVHWAGlShaderComponent mShaderCKeySrc;
     1566//    VBoxVHWAGlShaderComponent mShaderCKeySrcVoid;
     1567
     1568    VBoxVHWAGlShaderComponent mShaderMainOverlay;
     1569    VBoxVHWAGlShaderComponent mShaderMainOverlayNoCKey;
    15021570
    15031571    friend class VBoxVHWAGlProgramVHWA;
     
    15061574VBoxVHWAGlProgramVHWA * VBoxVHWAGlProgramMngr::createProgram(uint32_t type, uint32_t fourcc)
    15071575{
    1508     VBoxVHWAGlShader * apShaders[16];
     1576    VBoxVHWAGlShaderComponent * apShaders[16];
    15091577    uint32_t cShaders = 0;
    15101578
     
    15871655    Assert(cShaders <= RT_ELEMENTS(apShaders));
    15881656
    1589     VBoxVHWAGlProgramVHWA *pProgram =  new VBoxVHWAGlProgramVHWA(/*this, */type, fourcc, apShaders, cShaders);
     1657    VBoxVHWAGlShader shader(GL_FRAGMENT_SHADER, apShaders, cShaders);
     1658    VBoxVHWAGlShader *pShader = &shader;
     1659
     1660    VBoxVHWAGlProgramVHWA *pProgram =  new VBoxVHWAGlProgramVHWA(/*this, */type, fourcc, &pShader, 1);
    15901661    pProgram->init();
    15911662
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