当前位置: 首页>>代码示例>>C++>>正文


C++ RenderInfo::getContextID方法代码示例

本文整理汇总了C++中osg::RenderInfo::getContextID方法的典型用法代码示例。如果您正苦于以下问题:C++ RenderInfo::getContextID方法的具体用法?C++ RenderInfo::getContextID怎么用?C++ RenderInfo::getContextID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在osg::RenderInfo的用法示例。


在下文中一共展示了RenderInfo::getContextID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: drawImplementation

 virtual void drawImplementation( osg::RenderInfo& renderInfo ) const
 {
     unsigned int contextID = renderInfo.getContextID();
     if ( !_initialized )
     {
         NanoVGDrawable* constMe = const_cast<NanoVGDrawable*>(this);
         glewInit();
         constMe->_vg = nvgCreateGL2( NVG_ANTIALIAS|NVG_STENCIL_STROKES|NVG_DEBUG );
         if ( !constMe->_vg )
         {
             OSG_NOTICE << "[NanoVGDrawable] Failed to create VG context" << std::endl;
             return;
         }
         
         constMe->initializeGL( renderInfo.getState() );
         constMe->_activeContextID = contextID;
         constMe->_initialized = true;
     }
     else if ( _vg && contextID==_activeContextID )
     {
         osg::State* state = renderInfo.getState();
         state->disableAllVertexArrays();
         state->disableTexCoordPointer( 0 );
         
         nvgBeginFrame( _vg, _width, _height, 1.0f );
         updateGL( state );
         nvgEndFrame( _vg );
     }
 }
开发者ID:AlessandroZanella,项目名称:osgRecipes,代码行数:29,代码来源:osgnanovg.cpp

示例2:

void
LayerDrawable::drawImplementation(osg::RenderInfo& ri) const
{
    //OE_INFO << LC << (_layer ? _layer->getName() : "[empty]") << " tiles=" << _tiles.size() << std::endl;

    // Get this context's state values:
    PerContextDrawState& ds = _drawState->getPCDS(ri.getContextID());

    ds.refresh(ri, _drawState->_bindings);

    if (ds._layerUidUL >= 0)
    {
        GLint uid = _layer ? (GLint)_layer->getUID() : (GLint)-1;
        ds._ext->glUniform1i(ds._layerUidUL, uid);
    }
    else
    {
        // This just means that the fragment shader for this layer doesn't use oe_layer_uid
    }

    for (DrawTileCommands::const_iterator tile = _tiles.begin(); tile != _tiles.end(); ++tile)
    {
        tile->draw(ri, *_drawState, 0L);
    }

    // If set, dirty all OSG state to prevent any leakage - this is sometimes
    // necessary when doing custom OpenGL within a Drawable.
    if (_clearOsgState)
    {
        // Dirty the texture attributes so OSG can properly reset them
        // NOTE: cannot call state.dirtyAllAttributes, because that would invalidate
        // positional state like light sources!
        reinterpret_cast<StateEx*>(ri.getState())->dirtyAllTextureAttributes();

        // NOTE: this is a NOOP in OSG 3.5.x, but not in 3.4.x ... Later we will need to
        // revisit whether to call disableAllVertexArrays() in 3.5.x instead.
        ri.getState()->dirtyAllVertexArrays();
        
        // unbind local buffers when finished.
        ds._ext->glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
        ds._ext->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);

        // gw: no need to do this, in fact it will cause positional attributes
        // (light clip planes and lights) to immediately be reapplied under the
        // current MVM, which will by definition be wrong!)
        //ri.getState()->apply();
    }
}
开发者ID:aroth-fastprotect,项目名称:osgearth,代码行数:48,代码来源:LayerDrawable.cpp

示例3: drawImplementation

void CallbackDrawable::drawImplementation(osg::RenderInfo& ri) const
{
    glPushAttrib(GL_ALL_ATTRIB_BITS);

    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_TEXTURE_1D);

    MyGLClientState state;
    //printGLState();
    pushClientState(state);
    _renderer->draw(ri.getContextID());
    popClientState(state);

    glPopAttrib();
}
开发者ID:CalVR,项目名称:calvr_plugins,代码行数:16,代码来源:CallbackDrawable.cpp

示例4:

void
PerContextDrawState::refresh(osg::RenderInfo& ri, const RenderBindings* bindings)
{
    // Establish a GL Extensions handle:
    if (!_ext.valid())
    {
        _ext = osg::GLExtensions::Get(ri.getContextID(), true);
    }

    // Size the sampler states property:
    if (_samplerState._samplers.size() < bindings->size())
    {
        _samplerState._samplers.resize(bindings->size());
    }

    const osg::Program::PerContextProgram* pcp = ri.getState()->getLastAppliedProgramObject();
    if (pcp && (pcp != _pcp))
    {
        // Reset all sampler matrix states since their uniform locations are going to change.
        //_runningLayerDrawOrder = 0;
        _elevTexelCoeff.clear();
        _morphConstants.clear();
        _parentTextureExists.clear();
        _samplerState.clear();

        // for each sampler binding, initialize its state tracking structure 
        // and resolve its matrix uniform location:
        for (unsigned i = 0; i < bindings->size(); ++i)
        {
            const SamplerBinding& binding = (*bindings)[i];
            _samplerState._samplers[i]._matrixUL = pcp->getUniformLocation(osg::Uniform::getNameID(binding.matrixName()));
        }

        // resolve all the other uniform locations:
        _tileKeyUL = pcp->getUniformLocation(osg::Uniform::getNameID("oe_tile_key"));
        _elevTexelCoeffUL = pcp->getUniformLocation(osg::Uniform::getNameID("oe_tile_elevTexelCoeff"));
        _parentTextureExistsUL = pcp->getUniformLocation(osg::Uniform::getNameID("oe_layer_texParentExists"));
        _layerUidUL = pcp->getUniformLocation(osg::Uniform::getNameID("oe_layer_uid"));
        _layerOrderUL = pcp->getUniformLocation(osg::Uniform::getNameID("oe_layer_order"));
        _morphConstantsUL = pcp->getUniformLocation(osg::Uniform::getNameID("oe_tile_morph"));
    }

    _pcp = pcp;
}
开发者ID:pprabhu78,项目名称:osgearth,代码行数:44,代码来源:DrawState.cpp

示例5: drawImplementation

void MYGUIManager::drawImplementation( osg::RenderInfo& renderInfo ) const
{
    unsigned int contextID = renderInfo.getContextID();
    if ( !_initialized )
    {
        MYGUIManager* constMe = const_cast<MYGUIManager*>(this);
        constMe->_platform = new MyGUI::OpenGLPlatform;
        constMe->_platform->initialise( constMe );
        constMe->setupResources();
        
        constMe->_gui = new MyGUI::Gui;
        constMe->_gui->initialise( _resourceCoreFile );
        constMe->initializeControls();

		osg::ref_ptr<osgViewer::GraphicsWindow> gw;
		if (_gw.lock(gw)) {
			gw->useCursor(_useHWCursor);
		}
		MyGUI::PointerManager& manager = MyGUI::PointerManager::getInstance();
		manager.setVisible(!_useHWCursor);
		manager.eventChangeMousePointer += MyGUI::newDelegate(constMe, &MYGUIManager::notifyChangeMousePointer);

        constMe->_activeContextID = contextID;
        constMe->_initialized = true;
    }
    else if ( contextID==_activeContextID )
    {
        osg::State* state = renderInfo.getState();
        state->disableAllVertexArrays();
        state->disableTexCoordPointer( 0 );
        
        glPushMatrix();
        glPushAttrib( GL_ALL_ATTRIB_BITS );
		if ( _platform )
		{
		    updateEvents();
		    _platform->getRenderManagerPtr()->drawOneFrame();
        }
        glPopAttrib();
        glPopMatrix();
    }
}
开发者ID:acmepjz,项目名称:turning-polyhedron-reloaded,代码行数:42,代码来源:MYGUIManager.cpp

示例6: drawImplementation

void MYGUIManager::drawImplementation( osg::RenderInfo& renderInfo ) const
{
	MYGUIManager* constMe = const_cast<MYGUIManager*>(this);

    unsigned int contextID = renderInfo.getContextID();
    if ( !_initialized )
    {
		constMe->_platform = new MyOpenGLPlatform;
        constMe->_platform->initialise( constMe );
        constMe->setupResources();
        
        constMe->_gui = new MyGUI::Gui;
        constMe->_gui->initialise( _resourceCoreFile );
        constMe->initializeControls();
        
        constMe->_activeContextID = contextID;
        constMe->_initialized = true;
    }
    else if ( contextID==_activeContextID )
    {
        osg::State* state = renderInfo.getState();
        state->disableAllVertexArrays();
		state->disableTexCoordPointer( 1 );
        
        glPushMatrix();
        glPushAttrib( GL_ALL_ATTRIB_BITS );
		if ( _platform )
		{
			constMe->setIntersectionPoint(getIntersectionPoint(),true);
			constMe->lock();
		    updateEvents();
			_platform->getMyRenderManagerPtr()->drawOneFrame();
			constMe->unlock();
        }
        glPopAttrib();
        glPopMatrix();

		state->dirtyAllVertexArrays();
		state->dirtyTexCoordPointer(1);
		state->dirtyAllAttributes();
    }
}
开发者ID:qqdiguo,项目名称:MuseOpenIG,代码行数:42,代码来源:MYGUIManager.cpp

示例7: noticeFinishRendering

    //--------------------------------------------------------------------------
    void UnitInMipmapOut::noticeFinishRendering(osg::RenderInfo &renderInfo, const osg::Drawable* drawable)
    {
        // this method will be called everytime when a drawable of this unit
        // is rendered. Hence we check here if we are using hardware mipmap 
        // generation and apply this if neccessary

        // if we have used a shader to generate mipmaps, then we can safely return
        if (mUseShader) return;

        // get the fbo extensions
        osg::FBOExtensions* fbo_ext = osg::FBOExtensions::instance(renderInfo.getContextID(),true);
        
        // we don't use shader, that means that the mipmaps are generated in hardware, hence do this
        std::map<int, osg::ref_ptr<osg::Texture> >::iterator it = mOutputTex.begin();
        for (; it != mOutputTex.end(); it++)
        {
            renderInfo.getState()->applyTextureAttribute(0, it->second.get());
            fbo_ext->glGenerateMipmap(it->second->getTextureTarget());
        }
    }
开发者ID:dschmid2,项目名称:osgPPU,代码行数:21,代码来源:UnitInMipmapOut.cpp

示例8: glPushMatrix

void SiltEffect::SiltDrawable::drawImplementation(osg::RenderInfo& renderInfo) const
{
    if (!_geometry) return;

    const osg::Geometry::Extensions* extensions = osg::Geometry::getExtensions(renderInfo.getContextID(),true);

    glPushMatrix();

    typedef std::vector<const CellMatrixMap::value_type*> DepthMatrixStartTimeVector;
    DepthMatrixStartTimeVector orderedEntries;
    orderedEntries.reserve(_currentCellMatrixMap.size());

    for(CellMatrixMap::const_iterator citr = _currentCellMatrixMap.begin();
        citr != _currentCellMatrixMap.end();
        ++citr)
    {
        orderedEntries.push_back(&(*citr));
    }

    std::sort(orderedEntries.begin(),orderedEntries.end(),LessFunctor());

    for(DepthMatrixStartTimeVector::reverse_iterator itr = orderedEntries.rbegin();
        itr != orderedEntries.rend();
        ++itr)
    {
        extensions->glMultiTexCoord1f(GL_TEXTURE0+1, (*itr)->second.startTime);

        glMatrixMode( GL_MODELVIEW );
        glLoadMatrix((*itr)->second.modelview.ptr());

        _geometry->draw(renderInfo);

        unsigned int numVertices = osg::minimum(_geometry->getVertexArray()->getNumElements(), _numberOfVertices);
        glDrawArrays(_drawType, 0, numVertices);
    }

    glPopMatrix();
}
开发者ID:energonQuest,项目名称:dtOcean,代码行数:38,代码来源:SiltEffect.cpp

示例9: drawImplementation

void CudaTestDrawable::drawImplementation(osg::RenderInfo& ri) const
{
    if(ri.getContextID())
    {
	return;
    }
    //std::cerr << "Draw context: " << ri.getContextID() << std::endl;
    if(!_init)
    {
	init();
	_init = true;
    }

    glFinish();

    struct timeval start,end;
    getTime(start);

    copyData();

    getTime(end);
    printDiff("Copy Time: ",start,end);
}
开发者ID:CalVR,项目名称:calvr_plugins,代码行数:23,代码来源:CudaTestDrawable.cpp

示例10: drawImplementation

void PanoDrawableLOD::drawImplementation(osg::RenderInfo& ri) const
{
    if(_badInit)
    {
	return;
    }

    glPushAttrib(GL_ALL_ATTRIB_BITS);

    int context = ri.getContextID();

    int eye = 0;
    osg::Node::NodeMask parentMask;

    if(!getNumParents())
    {
	glPopAttrib();
	return;
    }

    parentMask = getParent(0)->getNodeMask();

    if((parentMask & CULL_MASK_LEFT) || (parentMask & CULL_MASK) || (ScreenConfig::instance()->getEyeSeparationMultiplier() == 0.0))
    {
	if(ScreenBase::getEyeSeparation() >= 0)
	{
	    eye = DRAW_LEFT;
	}
	else
	{
	    eye = DRAW_RIGHT;
	}
    }
    else
    {
	if(ScreenBase::getEyeSeparation() >= 0)
	{
	    eye = DRAW_RIGHT;
	}
	else
	{
	    eye = DRAW_LEFT;
	}
    }

    _pdi->initLock.lock();

    if(!_pdi->initMap[context])
    {
	if(!_pdi->cacheMap[context])
	{
	    GLenum err = glewInit();
	    if (GLEW_OK != err)
	    {
		std::cerr << "Error on glew init: " << glewGetErrorString(err) << std::endl;
		_badInit = true;
		_pdi->initLock.unlock();
		glPopAttrib();
		return;
	    }
	    int cachesize = ConfigManager::getInt("value","Plugin.PanoViewLOD.CacheSize",256);
	    _pdi->cacheMap[context] = new sph_cache(cachesize);
	    _pdi->cacheMap[context]->set_debug(false);

	    _pdi->updateLock[context] = new OpenThreads::Mutex();
	}

	int time = 1;
	if(_pdi->modelMap[context])
	{
	    time = _pdi->modelMap[context]->get_time();
	    delete _pdi->modelMap[context];
	    delete _pdi->transitionModelMap[context];
	}
	GLint buffer,ebuffer;
	glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&buffer);
	glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING,&ebuffer);

	_pdi->modelMap[context] = new sph_model(*_pdi->cacheMap[context],_vertData,_fragData,_mesh,_depth,_size);
	_pdi->transitionModelMap[context] = new sph_model(*_pdi->cacheMap[context],_vertData,_fragData,_mesh,_depth,_size);
	// Set start time to last model's time since timestamps are used by the disk cache
	_pdi->modelMap[context]->set_time(time);
	_pdi->transitionModelMap[context]->set_time(time);

	glBindBuffer(GL_ARRAY_BUFFER, buffer);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebuffer);

	_pdi->leftFileIDs[context] = std::vector<int>();
	_pdi->rightFileIDs[context] = std::vector<int>();
    }

    if(!(_pdi->initMap[context] & eye))
    {
	if(eye & DRAW_LEFT)
	{
	    for(int i = 0; i < _pdi->leftEyeFiles.size(); i++)
	    {
		_pdi->leftFileIDs[context].push_back(_pdi->cacheMap[context]->add_file(_pdi->leftEyeFiles[i]));
	    }
	    if(_pdi->leftEyeFiles.size() > 1 && _currentIndex < _pdi->leftFileIDs[context].size())
//.........这里部分代码省略.........
开发者ID:cehughes,项目名称:calvr_plugins,代码行数:101,代码来源:PanoDrawableLOD.cpp

示例11: drawImplementation

void NoesisDrawable::drawImplementation( osg::RenderInfo& renderInfo ) const
{
    unsigned int contextID = renderInfo.getContextID();
    if ( !_initialized )
    {
        if ( !NoesisSystemManager::contextInitialized )
        {
            NsGetKernel()->InitSystems();
            NoesisSystemManager::contextInitialized = true;
        }

        NoesisDrawable* constMe = const_cast<NoesisDrawable*>( this );
        constMe->initializeUI( renderInfo );
        constMe->registerEventHandlers();
        _activeContextID = contextID;
        _initialized = true;
    }
    else if ( contextID==_activeContextID )
    {
        if ( _dirty )
        {
            _uiRenderer->SetSize( _width, _height );
            _dirty = false;
        }
        
        osg::State* state = renderInfo.getState();
        state->disableAllVertexArrays();
        
        // Make sure the client unit and active unit are unified
        state->setClientActiveTextureUnit( 0 );
        state->setActiveTextureUnit( 0 );
        
#if !PARALLEL_UPDATING_AND_RENDERING
        // Update
        NsGetKernel()->Tick();

        osg::FrameStamp* fs = renderInfo.getView()->getFrameStamp();
        if ( fs ) _uiRenderer->Update( fs->getSimulationTime() );
#endif
        // Obtain commands
        RenderCommands renderCommands = _uiRenderer->WaitForUpdate();
        osg::FBOExtensions* fbo = osg::FBOExtensions::instance(contextID, true);

        // Render offscreen
        if ( fbo )
        {;
            _uiRenderer->Render( renderCommands.offscreenCommands.GetPtr() );
            fbo->glBindFramebuffer( GL_FRAMEBUFFER_EXT, 0 );
        }

        // Render
        _uiRenderer->Render( renderCommands.commands.GetPtr() );

        // Restore buffer states
        osg::GLBufferObject::Extensions* buf = osg::GLBufferObject::getExtensions(contextID, true);
        buf->glBindBuffer( GL_ARRAY_BUFFER_ARB, 0 );
        buf->glBindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 );

        osg::GL2Extensions* gl2 = osg::GL2Extensions::Get(contextID, true);
        gl2->glDisableVertexAttribArray( 0 );
        gl2->glDisableVertexAttribArray( 1 );
        gl2->glDisableVertexAttribArray( 2 );
        gl2->glDisableVertexAttribArray( 3 );
        gl2->glDisableVertexAttribArray( 4 );
        gl2->glDisableVertexAttribArray( 5 );
        gl2->glDisableVertexAttribArray( 6 );
    }
    else
        std::cout << "Multiple contexts are not supported at present!" << std::endl;
}
开发者ID:Noesis,项目名称:OSGBindings,代码行数:70,代码来源:NoesisWrapper.cpp

示例12: glClear

void ScreenInterlacedTopBottom::InterlaceCallback::operator()(
        osg::RenderInfo &renderInfo) const
{
    int context = renderInfo.getContextID();
    const osg::GL2Extensions* extensions = osg::GL2Extensions::Get(context,
            true);
    //osg::FBOExtensions* ext = osg::FBOExtensions::instance(context,true);
    //ext->glBindFramebuffer(osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER, 0);
    //glColorMask(true,true,true,true);
    //osgDB::writeImageFile(*screen->image,"/home/aprudhom/testImage.tif");
    //exit(0);
    //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    //glFinish();
    //return;
    /*if(skip)
     {
     //screen->_camera->setClearColor(osg::Vec4(1.0,0,0,0));
     skip = false;
     return;
     }
     else
     {
     //screen->_camera->setClearColor(osg::Vec4(0,1.0,0,0));
     skip = true;
     }*/

    if(first)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }

    //glPushAttrib(GL_ALL_ATTRIB_BITS);

    //std::cerr << "Callback." << std::endl;
    if(!_initMap[context])
    {
        OpenThreads::ScopedLock < OpenThreads::Mutex > lock(_initLock);
        std::string shaderdir = CalVR::instance()->getResourceDir() + "/shaders/";

        osg::Shader * vert, *frag;
        if(odd)
        {
            vert = osg::Shader::readShaderFile(osg::Shader::VERTEX,
                    osgDB::findDataFile(shaderdir + "interlace.vert"));
            frag = osg::Shader::readShaderFile(osg::Shader::FRAGMENT,
                    osgDB::findDataFile(shaderdir + "interlace-odd.frag"));
        }
        else
        {
            vert = osg::Shader::readShaderFile(osg::Shader::VERTEX,
                    osgDB::findDataFile(shaderdir + "interlace.vert"));
            frag = osg::Shader::readShaderFile(osg::Shader::FRAGMENT,
                    osgDB::findDataFile(shaderdir + "interlace-even.frag"));
        }

        _programMap[context] = new osg::Program;
        _programMap[context]->addShader(vert);
        _programMap[context]->addShader(frag);

        _geometryMap[context] = new osg::Geometry();

        osg::DrawArrays * quad = new osg::DrawArrays(
                osg::PrimitiveSet::TRIANGLE_STRIP,0,0);
        osg::Vec2Array * verts = new osg::Vec2Array(0);
        _geometryMap[context]->setVertexArray(verts);
        _geometryMap[context]->addPrimitiveSet(quad);
        verts->push_back(osg::Vec2(-1.0,1.0));
        verts->push_back(osg::Vec2(-1.0,-1.0));
        verts->push_back(osg::Vec2(1.0,1.0));
        verts->push_back(osg::Vec2(1.0,-1.0));

        _geometryMap[context]->setUseDisplayList(false);

        quad->setCount(4);

        /*glGenBuffers(1,&_arrayMap[context]);
         glBindBuffer(GL_ARRAY_BUFFER, arrayMap[context]);
         float points[8] = {-1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0};

         glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(float), points, GL_STATIC_DRAW);
         glBindBuffer(GL_ARRAY_BUFFER, 0);*/

        _initMap[context] = true;
    }

    glViewport((int)screen->_myInfo->myChannel->left,
            (int)screen->_myInfo->myChannel->bottom,
            (int)screen->_myInfo->myChannel->width,
            (int)screen->_myInfo->myChannel->height);

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    //GLint activeTexture,bindtex;
    //glGetIntegerv(GL_ACTIVE_TEXTURE,&activeTexture);

//.........这里部分代码省略.........
开发者ID:TheNumenorean,项目名称:calvr,代码行数:101,代码来源:ScreenInterlacedTopBottom.cpp

示例13: defined

void PrecipitationEffect::PrecipitationDrawable::drawImplementation(osg::RenderInfo& renderInfo) const
{
#if defined(OSG_GL_MATRICES_AVAILABLE)

if (!_geometry) return;


    const osg::Geometry::Extensions* extensions = osg::Geometry::getExtensions(renderInfo.getContextID(),true);

    // save OpenGL matrices
    glPushMatrix();

    if (_requiresPreviousMatrix)
    {
        renderInfo.getState()->setActiveTextureUnit(0);
        glMatrixMode( GL_TEXTURE );
        glPushMatrix();
    }

    typedef std::vector<const CellMatrixMap::value_type*> DepthMatrixStartTimeVector;
    DepthMatrixStartTimeVector orderedEntries;
    orderedEntries.reserve(_currentCellMatrixMap.size());

    for(CellMatrixMap::const_iterator citr = _currentCellMatrixMap.begin();
        citr != _currentCellMatrixMap.end();
        ++citr)
    {
        orderedEntries.push_back(&(*citr));
    }

    std::sort(orderedEntries.begin(),orderedEntries.end(),LessFunctor());

    for(DepthMatrixStartTimeVector::reverse_iterator itr = orderedEntries.rbegin();
        itr != orderedEntries.rend();
        ++itr)
    {
        extensions->glMultiTexCoord1f(GL_TEXTURE0+1, (*itr)->second.startTime);

        // load cells current modelview matrix
        if (_requiresPreviousMatrix)
        {
            glMatrixMode( GL_MODELVIEW );
            glLoadMatrix((*itr)->second.modelview.ptr());

            CellMatrixMap::const_iterator pitr = _previousCellMatrixMap.find((*itr)->first);
            if (pitr != _previousCellMatrixMap.end())
            {
                // load previous frame modelview matrix for motion blurr effect
                glMatrixMode( GL_TEXTURE );
                glLoadMatrix(pitr->second.modelview.ptr());
            }
            else
            {
                // use current modelview matrix as "previous" frame value, cancelling motion blurr effect
                glMatrixMode( GL_TEXTURE );
                glLoadMatrix((*itr)->second.modelview.ptr());
            }
        }
        else
        {
            glLoadMatrix((*itr)->second.modelview.ptr());
        }

        _geometry->draw(renderInfo);

        unsigned int numVertices = osg::minimum(_geometry->getVertexArray()->getNumElements(), _numberOfVertices);
        glDrawArrays(_drawType, 0, numVertices);
    }

    // restore OpenGL matrices
    if (_requiresPreviousMatrix)
    {
        glPopMatrix();
        glMatrixMode( GL_MODELVIEW );
    }

    glPopMatrix();
#else
    OSG_NOTICE<<"Warning: ParticleEffect::drawImplementation(..) not fully implemented."<<std::endl;
#endif
}
开发者ID:Kurdakov,项目名称:emscripten_OSG,代码行数:81,代码来源:PrecipitationEffect.cpp

示例14: updateHeightMap

void
TritonDrawable::drawImplementation(osg::RenderInfo& renderInfo) const
{
    osg::State* state = renderInfo.getState();

    state->disableAllVertexArrays();

    _TRITON->initialize( renderInfo );
    if ( !_TRITON->ready() )
        return;

    if ( _TRITON->passHeightMapToTriton() && !_terrainChangedCallback.valid() )
    {
        const_cast<TritonDrawable*>(this)->setupHeightMap(*state);
    }

    ::Triton::Environment* environment = _TRITON->getEnvironment();

    osgEarth::NativeProgramAdapterCollection& adapters = _adapters[ state->getContextID() ];
    if ( adapters.empty() )
    {
        const char* prefix = "oe_";
        adapters.push_back( new osgEarth::NativeProgramAdapter(state, (GLint)_TRITON->getOcean()->GetShaderObject(::Triton::GOD_RAYS), prefix));
        adapters.push_back( new osgEarth::NativeProgramAdapter(state, (GLint)_TRITON->getOcean()->GetShaderObject(::Triton::SPRAY_PARTICLES), prefix));
        adapters.push_back( new osgEarth::NativeProgramAdapter(state, (GLint)_TRITON->getOcean()->GetShaderObject(::Triton::WAKE_SPRAY_PARTICLES), prefix));
        adapters.push_back( new osgEarth::NativeProgramAdapter(state, (GLint)_TRITON->getOcean()->GetShaderObject(::Triton::WATER_DECALS), prefix));
        adapters.push_back( new osgEarth::NativeProgramAdapter(state, (GLint)_TRITON->getOcean()->GetShaderObject(::Triton::WATER_SURFACE_PATCH), prefix));
        adapters.push_back( new osgEarth::NativeProgramAdapter(state, (GLint)_TRITON->getOcean()->GetShaderObject(::Triton::WATER_SURFACE), prefix));
    }
    adapters.apply( state );

    // Pass the final view and projection matrices into Triton.
    if ( environment )
    {
        environment->SetCameraMatrix( state->getModelViewMatrix().ptr() );
        environment->SetProjectionMatrix( state->getProjectionMatrix().ptr() );
    }

    if ( _TRITON->passHeightMapToTriton() )
    {
        unsigned cid = renderInfo.getContextID();

        bool dirty =
            ( _contextDirty[cid] ) ||
            ( renderInfo.getView()->getCamera()->getViewMatrix()       != _viewMatrix ) ||
            ( renderInfo.getView()->getCamera()->getProjectionMatrix() != _projMatrix );

        if ( dirty )
        {
            updateHeightMap( renderInfo );
            _contextDirty[renderInfo.getContextID()] = 0;
            _viewMatrix = renderInfo.getView()->getCamera()->getViewMatrix();
            _projMatrix = renderInfo.getView()->getCamera()->getProjectionMatrix();
        }
    }

    state->dirtyAllVertexArrays();

    // Now light and draw the ocean:
    if ( environment )
    {
        // User pre-draw callback:
        if (_TRITON->getCallback())
        {
            _TRITON->getCallback()->onDrawOcean(
                _TRITON->getEnvironmentWrapper(),
                _TRITON->getOceanWrapper());
        }

        // The sun position is roughly where it is in our skybox texture:

        // Since this is a simple example we will just assume that Sun is the light from View light source
        // TODO: fix this...
        osg::Light* light = renderInfo.getView() ? renderInfo.getView()->getLight() : NULL;

        // This is the light attached to View so there are no transformations above..
        // But in general case you would need to accumulate all transforms above the light into this matrix
        osg::Matrix lightLocalToWorldMatrix = osg::Matrix::identity();

        // If you don't know where the sun lightsource is attached and don't know its local to world matrix you may use
        // following elaborate scheme to grab the light source while drawing Triton ocean:
        // - Install cull callback to catch CullVisitor and record pointer to its associated RenderStage
        //   I was hoping RenderStage can be found from renderInfo in drawImplementation but I didn't figure how ...
        // - When TritonDrawable::drawImplementation is called all lights will be already applied to OpenGL
        //   then just find proper infinite directional light by scanning renderStage->PositionalStateContainer.
        // - Note that we canot scan for the lights inside cull because they may not be traversed before Triton drawable
        // - When you found interesting ligt source that can work as Sun, read its modelview matrix and lighting params
        //   Multiply light position by ( modelview * inverse camera view ) and pass this to Triton with lighting colors

        if ( light && light->getPosition().w() == 0 )
        {
            osg::Vec4 ambient = light->getAmbient();
            osg::Vec4 diffuse = light->getDiffuse();
            osg::Vec4 position = light->getPosition();

            // Compute light position/direction in the world
            position = position * lightLocalToWorldMatrix;

            // Diffuse direction and color
            environment->SetDirectionalLight(
//.........这里部分代码省略.........
开发者ID:dardok,项目名称:osgearth,代码行数:101,代码来源:TritonDrawable.cpp

示例15: atan

void
TritonDrawable::updateHeightMap(osg::RenderInfo& renderInfo) const
{
    if ( !_TRITON->ready() )
        return;

    osg::ref_ptr<MapNode> mapNode;
    if (!_mapNode.lock(mapNode))
        return;

    const osg::Matrix& viewMatrix = renderInfo.getCurrentCamera()->getViewMatrix();
    const osg::Matrix& projectionMatrix = renderInfo.getCurrentCamera()->getProjectionMatrix();

    osg::Vec3d eye, center, up;
    viewMatrix.getLookAt(eye, center, up);
    double fovyDEG=0.0, aspectRatio=0.0, zNear=0.0, zFar=0.0;
    projectionMatrix.getPerspective(fovyDEG, aspectRatio,zNear,zFar);

    // aspect_ratio = tan( HFOV/2 ) / tan( VFOV/2 )
    // tan( HFOV/2 ) = tan( VFOV/2 ) * aspect_ratio
    // HFOV/2 = atan( tan( VFOV/2 ) * aspect_ratio )
    // HFOV = 2.0 * atan( tan( VFOV/2 ) * aspect_ratio )
    double fovxDEG = osg::RadiansToDegrees( 2.0 * atan( tan(osg::DegreesToRadians(fovyDEG))/2.0 * aspectRatio ));

    double eyeLat=0.0, eyeLon=0.0, eyeHeight=0.0;
    mapNode->getMap()->getSRS()->getEllipsoid()->convertXYZToLatLongHeight(eye.x(), eye.y(), eye.z(), eyeLat, eyeLon, eyeHeight);
    double clampedEyeX=0.0, clampedEyeY=0.0,clampedEyeZ=0.0;
    mapNode->getMap()->getSRS()->getEllipsoid()->convertLatLongHeightToXYZ(eyeLat, eyeLon, 0.0, clampedEyeX, clampedEyeY, clampedEyeZ);
    osg::Vec3 mslEye(clampedEyeX,clampedEyeY,clampedEyeZ);
    double lookAtLat=0.0, lookAtLon=0.0, lookAtHeight=0.0;
    mapNode->getMap()->getSRS()->getEllipsoid()->convertXYZToLatLongHeight(center.x(), center.y(), center.z(), lookAtLat, lookAtLon, lookAtHeight);

    // Calculate the distance to the horizon from the eyepoint
    double eyeLen = eye.length();
    double radE = mslEye.length();
    double hmax = radE + 8848.0;
    double hmin = radE - 12262.0;
    double hasl = osg::maximum(0.1, eyeLen - radE);
    double radius = eyeLen - hasl;
    double horizonDistance = osg::minimum(radE, sqrt( 2.0*radius*hasl + hasl*hasl ));

    osg::Vec3d heightCamEye(eye);

    double near = osg::maximum(1.0, heightCamEye.length() - hmax);
    double far = osg::maximum(10.0, heightCamEye.length() - hmin + radE);
    //osg::notify( osg::ALWAYS ) << "near = " << near << "; far = " << far << std::endl;

    //horizonDistance *= 0.25;

    _heightCamera->setProjectionMatrix(osg::Matrix::ortho(-horizonDistance,horizonDistance,-horizonDistance,horizonDistance,near,far) );
    _heightCamera->setViewMatrixAsLookAt( heightCamEye, osg::Vec3d(0.0,0.0,0.0), osg::Vec3d(0.0,0.0,1.0));

    const osg::Matrixd bias(0.5, 0.0, 0.0, 0.0,
                            0.0, 0.5, 0.0, 0.0,
                            0.0, 0.0, 0.5, 0.0,
                            0.5, 0.5, 0.5, 1.0);

    osg::Matrix hMM = _heightCamera->getViewMatrix() * _heightCamera->getProjectionMatrix() * bias;
    ::Triton::Matrix4 heightMapMatrix(hMM(0,0),hMM(0,1),hMM(0,2),hMM(0,3),
                                      hMM(1,0),hMM(1,1),hMM(1,2),hMM(1,3),
                                      hMM(2,0),hMM(2,1),hMM(2,2),hMM(2,3),
                                      hMM(3,0),hMM(3,1),hMM(3,2),hMM(3,3));

    osg::Texture::TextureObject* texObj = _heightMap->getTextureObject(renderInfo.getContextID());

    if(texObj)
    {
        PassHeightMapToTritonCallback* cb = dynamic_cast<PassHeightMapToTritonCallback*>(_heightCamera->getFinalDrawCallback());
        if( cb )
        {
            cb->_enable = true;
            cb->_id = texObj->id();
            cb->_heightMapMatrix = heightMapMatrix;
        }
    }
    else
    {
        // may happen on the first frame; ignore
        //OE_WARN << LC << "Texture object is NULL (Internal error)" << std::endl;
    }

#ifdef DEBUG_HEIGHTMAP
    mapNode->getParent(0)->removeChild(0, 1);
    mapNode->getParent(0)->insertChild(0, makeFrustumFromCamera(_heightCam));
#endif /* DEBUG_HEIGHTMAP */
}
开发者ID:dardok,项目名称:osgearth,代码行数:86,代码来源:TritonDrawable.cpp


注:本文中的osg::RenderInfo::getContextID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。