示例#1
0
void *GeoVectorProperty::mapBuffer(GLenum eAccess, DrawEnv *pEnv)
{
    void *returnValue = NULL;

    if((getUseVBO() == true) && (getGLId() != 0))
    {
        Window *pWin = pEnv->getWindow();

        osgSinkUnusedWarning(pWin);

        OSGGETGLFUNCBYID_GL3_ES( glBindBuffer, 
                                 osgGlBindBuffer,
                                _funcBindBuffer, 
                                 pWin);

        OSGGETGLFUNCBYID_GL3   ( glMapBuffer, 
                                 osgGlMapBuffer,
                                _funcMapBuffer, 
                                 pWin);

        pWin->validateGLObject(getGLId(), pEnv);                
        
        osgGlBindBuffer(GL_ARRAY_BUFFER_ARB,
                        pWin->getGLObjectId(getGLId()));

        returnValue = osgGlMapBuffer(GL_ARRAY_BUFFER_ARB, eAccess);

        osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
    }

    return returnValue;
}
示例#2
0
bool GeoVectorProperty::unmapBuffer(DrawEnv *pEnv)
{
    bool returnValue = true;

    if((getUseVBO() == true) && (getGLId() != 0))
    {
        Window *pWin = pEnv->getWindow();

        osgSinkUnusedWarning(pWin);

        OSGGETGLFUNCBYID_GL3_ES( glBindBuffer, 
                                 osgGlBindBuffer,
                                _funcBindBuffer, 
                                 pWin);

        OSGGETGLFUNCBYID_GL3   ( glUnmapBuffer, 
                                 osgGlUnmapBuffer,
                                _funcUnmapBuffer, 
                                 pWin);

        osgGlBindBuffer(GL_ARRAY_BUFFER_ARB,
                        pWin->getGLObjectId(getGLId()));

        returnValue = (osgGlUnmapBuffer(GL_ARRAY_BUFFER_ARB) != 0);

        osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
    }
    
    return returnValue;
}
/*! GL object handler
    destroy it
*/
void GeoMultiPropertyData::handleDestroyGL(DrawEnv                 *pEnv, 
                               UInt32                   id, 
                               Window::GLObjectStatusE  mode)
{
    Window *pWin = pEnv->getWindow();

    osgSinkUnusedWarning(pWin);

    if(mode == Window::destroy)
    {   
        OSGGETGLFUNCBYID_GL3_ES( glDeleteBuffers, 
                                 osgGlDeleteBuffers,
                                _funcDeleteBuffers,    
                                 pWin              );

        GLuint buf = id;
        osgGlDeleteBuffers(1, &buf);

        pWin->setGLObjectId(id, 0);
    }
    else if(mode == Window::finaldestroy)
    {
        //SWARNING << "Last texture user destroyed" << std::endl;
    }
    else
    {
        SWARNING << "GeoMultiPropertyData::handleDestroyGL: Illegal mode: "
                 << mode << " for id " << id << std::endl;
    }

}
bool GeoImmediatePumpGroup::glextInitFunction(void)
{
    _extSecondaryColor      =
        Window::registerExtension("GL_EXT_secondary_color");
    _extMultitexture        =
        Window::registerExtension("GL_ARB_multitexture");
    _arbVertexProgram       =
        Window::registerExtension("GL_ARB_vertex_program");

    for(UInt16 i = 0; i < numFormats; ++i)
    {
        for(UInt16 j = 0; j < 4; ++j)
        {
            pumpFuncIDs[0][i][j] = Window::invalidFunctionID;
            pumpFuncIDs[1][i][j] = Window::invalidFunctionID;
        }
    }

    for(UInt16 i = 0; i < uiNumSecColFunc; ++i)
        secondaryColorInitFuncs[i].init(pumpFuncIDs[SecColorsPumpSlot],
                                        _extSecondaryColor             );

    for(UInt16 i = 0; i < uiNumMTexFuncs; ++i)
        multiTexCoordsInitFuncs[i].init(pumpFuncIDs[TexCoords1PumpSlot],
                                        _extMultitexture                );

    for(UInt16 i = 0; i < uiNumAttribFuncs; ++i)
        attribInitFuncs[i].init(attribPumpFuncIDs, _arbVertexProgram);

    for(UInt16 i = 0; i < uiNumNormAttribFuncs; ++i)
        normAttribInitFuncs[i].init(normAttribPumpFuncIDs, _arbVertexProgram);
 
#if defined(OSG_USE_OGLES_PROTOS) || defined(OSG_USE_OGL3_PROTOS) || \
    defined(OSG_USE_OGL4_PROTOS)
    osgSinkUnusedWarning(attribPumpFuncs);
    osgSinkUnusedWarning(attribNormPumpFuncs);
#endif

    return true;
}
UInt32 GeoMultiPropertyData::handleGL(DrawEnv                 *pEnv, 
                                      UInt32                   id, 
                                      Window::GLObjectStatusE  mode,
                                      UInt32                   uiOptions)
{
    Window *pWin = pEnv->getWindow();

    osgSinkUnusedWarning(pWin);

    if(mode == Window::initialize || mode == Window::reinitialize ||
       mode == Window::needrefresh )
    {
        OSGGETGLFUNCBYID_GL3_ES( glBindBuffer, 
                                 osgGlBindBuffer,
                                _funcBindBuffer,    
                                 pWin              );
        OSGGETGLFUNCBYID_GL3_ES( glBufferData,
                                 osgGlBufferData,
                                _funcBufferData,    
                                 pWin              );

        osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, id);

        osgGlBufferData(  GL_ARRAY_BUFFER_ARB,
                         _mfIData.size(),
                        &_mfIData[0],
                             GL_STATIC_DRAW_ARB);

        osgGlBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
    }
    else
    {
        SWARNING << "GeoMultiPropertyData(" << this 
                 << "::handleGL: Illegal mode: "
                 << mode << " for id " << id << std::endl;
    }

    return 0;
}
void ComputeShaderChunk::updateProceduralVariables(
    DrawEnv *pEnv,
    UInt32   uiUpdateDependents)
{
    UInt32 uiProgram = pEnv->getActiveShader();

    if(uiProgram == 0)
        return;

    const ShaderProgramVariables::MFProceduralVariablesType *pMFVars = NULL;

    if(_sfVariables.getValue() != NULL)
    {
        pMFVars   = _sfVariables.getValue()->getMFProceduralVariables();
    }

    if(pMFVars == NULL || pMFVars->size() == 0)
    {
        return;
    }

    MFInt32 &vVarLocations = *this->editMFProceduralVariableLocations();

    OSG_ASSERT(pMFVars->size() == vVarLocations.size());

    MFInt32::iterator mLocIt = vVarLocations.begin();

    ShaderProgramVariables::MFProceduralVariablesType::const_iterator mVarIt  =
        pMFVars->begin();
    ShaderProgramVariables::MFProceduralVariablesType::const_iterator mVarEnd =
        pMFVars->end  ();

    Window *pWin = pEnv->getWindow();

    osgSinkUnusedWarning(pWin);

    for(; mVarIt != mVarEnd; ++mVarIt, ++mLocIt)
    {
        ShaderVariable *pVar = *mVarIt;

        switch(pVar->getTypeId())
        {
            case ShaderVariable::SHVTypeOSG:
            {
                ShaderVariableOSG *p =
                    dynamic_cast<ShaderVariableOSG *>(pVar);

                if(0x0000 == (p->getDependency() & uiUpdateDependents))
                    continue;

                if(*mLocIt == -1)
                {
                    OSGGETGLFUNCBYID_GL3_ES(
                        glGetUniformLocation,
                        osgGlGetUniformLocation,
                        ShaderProgram::getFuncIdGetUniformLocation(),
                        pWin);

                    *mLocIt = osgGlGetUniformLocation(uiProgram,
                                                      p->getName().c_str());
                }

                p->evaluate(pEnv, *mLocIt);                
            }
            break;

            case ShaderVariable::SHVTypeFunctor:
            {
                ShaderVariableFunctor *p =
                    dynamic_cast<ShaderVariableFunctor *>(pVar);

                if(0x0000 == (p->getDependency() & uiUpdateDependents))
                    continue;

                if(*mLocIt == -1)
                {
                    OSGGETGLFUNCBYID_GL3_ES(
                        glGetUniformLocation,
                        osgGlGetUniformLocation,
                        ShaderProgram::getFuncIdGetUniformLocation(),
                        pWin);

                    *mLocIt = osgGlGetUniformLocation(uiProgram,
                                                      p->getName().c_str());
                }

                p->evaluate(pEnv, *mLocIt);                
            }
            break;

            default:
                break;
        }
    }
}
void PointChunk::deactivate(DrawEnv *pEnv, UInt32)
{
#ifndef OSG_OGL_ES2
    if(getSize() != 1.f)
        glPointSize(1.f);
#endif

    Window *pWin = pEnv->getWindow();

    osgSinkUnusedWarning(pWin);

#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
    if(getSmooth())
        glDisable(GL_POINT_SMOOTH);
#endif

#if GL_ARB_point_parameters
    if(getMinSize() >= 0.f)
    {
        if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104))
        {
            OSGGETGLFUNCBYID_GL3( glPointParameterf,
                                  osgGlPointParameterf,
                                 _funcIdPointParameterf,
                                  pWin);
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
            OSGGETGLFUNCBYID_GL3( glPointParameterfv,
                                  osgGlPointParameterfv,
                                 _funcIdPointParameterfv,
                                  pWin);
 
            osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, 0);
            osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, 1e10);
#endif
            osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1);
            
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
            GLfloat att[3] = { 1, 0, 0 };
            
            osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
#endif
        }
        
    }
#endif

#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
#if GL_ARB_point_sprite
    if(getSprite())
    {
        if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200))
        {
            glDisable(GL_POINT_SPRITE_ARB);
        }
        
    }
#endif
#endif

#if ! defined(GL_ARB_point_parameters) && ! defined(GL_ARB_point_sprite)
    pEnv;
#endif
}
void PointChunk::changeFrom(DrawEnv    *pEnv, 
                            StateChunk *old_chunk, 
                            UInt32               )
{
    PointChunk *old = dynamic_cast<PointChunk *>(old_chunk);

#ifndef OSG_OGL_ES2
    if(getSize() != old->getSize())
        glPointSize(getSize());
#endif

#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
    if(getSmooth() && !old->getSmooth())
    {
        glEnable(GL_POINT_SMOOTH);
    }
    else if(!getSmooth() && old->getSmooth())
    {
        glDisable(GL_POINT_SMOOTH);
    }
#endif

    Window *pWin = pEnv->getWindow();

    osgSinkUnusedWarning(pWin);

#if GL_ARB_point_parameters
    if(getMinSize() >= 0.f)
    {
        if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104))
        {
            OSGGETGLFUNCBYID_GL3( glPointParameterf,
                                  osgGlPointParameterf,
                                 _funcIdPointParameterf,
                                  pWin);
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
            OSGGETGLFUNCBYID_GL3( glPointParameterfv,
                                  osgGlPointParameterfv,
                                 _funcIdPointParameterfv,
                                  pWin);

            osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, getMinSize());
            osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, getMaxSize());
#endif
            osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 
                                 getFadeThreshold());
            
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
            GLfloat att[3] = { getConstantAttenuation (),
                               getLinearAttenuation   (),
                               getQuadraticAttenuation() };
            
            osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
#endif
        }
        
    }
    else if(old->getMinSize() >= 0.f)
    {
        if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104))
        {
            OSGGETGLFUNCBYID_GL3( glPointParameterf,
                                  osgGlPointParameterf,
                                 _funcIdPointParameterf,
                                  pWin);
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
            OSGGETGLFUNCBYID_GL3( glPointParameterfv,
                                  osgGlPointParameterfv,
                                 _funcIdPointParameterfv,
                                  pWin);

            osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, 0);
            osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, 1e10);
#endif
            osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1);
            
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
            GLfloat att[3] = { 1, 0, 0 };
            
            osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
#endif
        }
    }
#endif

#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
#if GL_ARB_point_sprite
    if(getSprite() && !old->getSprite())
    {
        if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200))
        {
#if GL_NV_point_sprite
            if(pEnv->getWindow()->hasExtension(_extPointSpriteNV))
            {
                OSGGETGLFUNCBYID_GL3( glPointParameterf,
                                      osgGlPointParameterf,
                                     _funcIdPointParameterf,
                                      pWin);

                osgGlPointParameterf(GL_POINT_SPRITE_R_MODE_NV, 
                                     Real32(getRMode()));
            }
#endif
            
            glEnable(GL_POINT_SPRITE_ARB);
        }
        
    }
    else if(!getSprite() && old->getSprite())
    {
        if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200))
        {
           glDisable(GL_POINT_SPRITE_ARB);
        }
        
    }
#endif
#endif

#if ! defined(GL_ARB_point_parameters) && ! defined(GL_ARB_point_sprite)
    pEnv;
#endif
}
示例#9
0
void GeoVectorProperty::deactivate(DrawEnv *pEnv, UInt32 slot)
{
    Window *pWin   = pEnv->getWindow();

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

    slot &= 15;

    osgSinkUnusedWarning(pWin);

    if(pWin->hasExtOrVersion(_extVertexBufferObject, 
                             0x0105, 
                             0x0200                ) && isGeneric)
    {
        OSGGETGLFUNCBYID_GL3_ES( glDisableVertexAttribArray,
                                 osgGlDisableVertexAttribArray,
                                _funcDisableVertexAttribArrayARB,
                                 pWin);

        osgGlDisableVertexAttribArray(slot);
    }
    else
    {
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
        switch(slot)
        {
            case 0:
                glDisableClientState(GL_VERTEX_ARRAY);
                break;

            case 2: 
                glDisableClientState(GL_NORMAL_ARRAY);
                break;

            case 3: 
                glDisableClientState(GL_COLOR_ARRAY);
                break;

            case 4: 
                glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
                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);

                    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
                }
                else if(slot == 8)
                {
                    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
                }
                else
                {
                    SWARNING << "GeoVectorProperty::deactivate: Window "
                             << "has no Multi Texture extension" << std::endl;
                }
            }
            break;

            default:    
                FWARNING(("GeoVectorProperty::deactivate: Non-Generic"
                          " attribute nr. %d unknown!\n", slot));
                break;
        }
#endif
    }
}
示例#10
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
    }
}