Exemplo n.º 1
0
		inline BYTE getNormalizeR(DWORD n) { return getNormalize(n, _min.r, _max.r); }
Exemplo n.º 2
0
void GeoVectorProperty::activate(DrawEnv *pEnv, UInt32 slot)
{
    Window *pWin = pEnv->getWindow();

    bool isGeneric = (slot >= 16);  // !!!HACK. needs to be replaced for 2.0
    slot &= 15;

    bool hasVBO = pWin->hasExtOrVersion(_extVertexBufferObject, 0x0105, 0x0200);

    osgSinkUnusedWarning(pWin);

    if(hasVBO && isGeneric == true)
    {
        OSGGETGLFUNCBYID_GL3_ES( glVertexAttribPointer, 
                                 osgGlVertexAttribPointer,
                                _funcVertexAttribPointerARB,
                                 pWin);

        if(getGLId() != 0 && getUseVBO()) // Do we have a VBO?
        {
            pWin->validateGLObject(getGLId(), pEnv);
            
            OSGGETGLFUNCBYID_GL3_ES(  glBindBuffer, 
                                      osgGlBindBuffer,
                                     _funcBindBuffer, 
                                      pWin);
            
            osgGlBindBuffer(GL_ARRAY_BUFFER_ARB,
                            pWin->getGLObjectId(getGLId()));
            
            osgGlVertexAttribPointer(slot, 
                                     getDimension(),
                                     getFormat   (),
                                     getNormalize(),
                                     getStride   (), 
                                     0);
            
            osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
        }
        else
        {
            osgGlVertexAttribPointer(slot, 
                                     getDimension(),
                                     getFormat   (), 
                                     getNormalize(),
                                     getStride   (), 
                                     getData     ());
        }
        
        OSGGETGLFUNCBYID_GL3_ES( glEnableVertexAttribArray,
                                 osgGlEnableVertexAttribArray,
                                _funcEnableVertexAttribArrayARB,
                                 pWin);
        
        osgGlEnableVertexAttribArray(slot);
  
        OSGGETGLFUNCBYID_GL3_ES( glVertexAttribDivisor,
                                 osgGlVertexAttribDivisor,
                                _funcVertexAttribDivisorARB,
                                 pWin);
 
        osgGlVertexAttribDivisor(slot, _sfDivisor.getValue());
    }
    else 
    {        
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
        const void *pData = NULL;

        OSGGETGLFUNCBYID_GL3_ES( glBindBuffer, 
                                 osgGlBindBuffer,
                                _funcBindBuffer, 
                                 pWin);

        hasVBO &= getUseVBO() && (getGLId() != 0);

        if(hasVBO == true) // Do we have a VBO?
        {
            pWin->validateGLObject(getGLId(), pEnv);                

            osgGlBindBuffer(GL_ARRAY_BUFFER_ARB,
                            pWin->getGLObjectId(getGLId()));
        }
        else
        {
            pData = getData();
        }
        
        switch(slot)
        {
            case 0:     
                glVertexPointer(getDimension(), 
                                getFormat   (),
                                getStride   (),
                                pData         );

                glEnableClientState(GL_VERTEX_ARRAY);
                break;

            case 2:     
                glNormalPointer(getFormat(),
                                getStride(),
                                pData      );

                glEnableClientState(GL_NORMAL_ARRAY);
                break;

            case 3:   
                glColorPointer(getDimension(), 
                               getFormat   (),
                               getStride   (), 
                               pData         );

                glEnableClientState(GL_COLOR_ARRAY);
                break;

            case 4:   
                if(pWin->hasExtOrVersion(_extSecondaryColor, 0x0104))
                {
                    OSGGETGLFUNCBYID_GL3( glSecondaryColorPointer,
                                          osgGlSecondaryColorPointer,
                                         _funcSecondaryColorPointer,
                                          pWin);

                    osgGlSecondaryColorPointer(getDimension(),
                                               getFormat   (),
                                               getStride   (), 
                                               pData         );

                    glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
                }
                else
                {
                    FWARNING(("GeoVectorProperty::activate: Window "
                              "has no Secondary Color extension\n"));
                }
                break;

            case 8:  
            case 9:
            case 10: 
            case 11:
            case 12: 
            case 13:
            case 14: 
            case 15:
            {
                if(pWin->hasExtOrVersion(_extMultitexture, 0x0103, 0x0200))
                {
                    OSGGETGLFUNCBYID_GL3_ES( glClientActiveTexture,
                                             osgGlClientActiveTexture,
                                            _funcClientActiveTextureARB,
                                             pWin);

                    osgGlClientActiveTexture(GL_TEXTURE0_ARB + slot - 8);

                    glTexCoordPointer(getDimension(),
                                      getFormat   (),
                                      getStride   (),
                                      pData         );

                    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
                }
                else if(slot == 8)
                {
                    glTexCoordPointer(getDimension(),
                                      getFormat   (),
                                      getStride   (),
                                      pData         );

                    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
                }
                else
                {
                    SWARNING << "GeoVectorProperty::activate: Window "
                             << "has no Multi Texture extension" << std::endl;
                }
            }
            break;

            default:    FWARNING(("GeoVectorProperty::activate: Non-Generic"
                                  " attribute nr. %d unknown!\n", slot));
                break;

        }
        if(hasVBO == true) // Do we have a VBO?
        {
            osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
        }
#endif
    }
}