void WindowCaptureCallback::operator () (osg::RenderInfo& renderInfo) const { #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) glReadBuffer(_readBuffer); #endif osg::GraphicsContext* gc = renderInfo.getState()->getGraphicsContext(); osg::ref_ptr<ContextData> cd = getContextData(gc); cd->read(); // If _numFrames is > 0 it means capture that number of frames. if (_numFrames > 0) { --_numFrames; if (_numFrames == 0) { // the callback must remove itself when it's done. if (_position == START_FRAME) renderInfo.getCurrentCamera()->setInitialDrawCallback(0); if (_position == END_FRAME) renderInfo.getCurrentCamera()->setFinalDrawCallback(0); } } int prec = osg::notify(osg::INFO).precision(5); OSG_INFO << "ScreenCaptureHandler: " << "copy=" << (cd->_timeForFullCopy*1000.0f) << "ms, " << "operation=" << (cd->_timeForCaptureOperation*1000.0f) << "ms, " << "total=" << (cd->_timeForFullCopyAndOperation*1000.0f) << std::endl; osg::notify(osg::INFO).precision(prec); cd->_timeForFullCopy = 0; }
void CloudsDrawable::drawImplementation(osg::RenderInfo& renderInfo) const { renderInfo.getState()->disableAllVertexArrays(); _SL->getAtmosphere()->DrawObjects( true, true, true ); renderInfo.getState()->dirtyAllVertexArrays(); }
void SilverLiningNode::SkyDrawable::drawImplementation( osg::RenderInfo& renderInfo ) const { renderInfo.getState()->disableAllVertexArrays(); _silverLining->initializeSilverLining( renderInfo ); _silverLining->atmosphere()->DrawSky( true, false, 0.0, true, false ); renderInfo.getState()->dirtyAllVertexArrays(); }
virtual void operator () (osg::RenderInfo& renderInfo) const { if (!_frameCapture) { OSG_NOTICE<<"No FrameCamera assigned"<<std::endl; return; } unsigned int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber(); CameraNumMap::const_iterator itr = _cameraNumMap.find(renderInfo.getCurrentCamera()); std::string outputFileName = (itr!=_cameraNumMap.end()) ? _frameCapture->getOutputFileName(itr->second, frameNumber) : _frameCapture->getOutputFileName(frameNumber); OSG_NOTICE<<"outputFileName="<<outputFileName<<std::endl; osg::Camera* camera = renderInfo.getCurrentCamera(); osg::Viewport* viewport = camera ? camera->getViewport() : 0; if (viewport) { OSG_NOTICE<<"Doing read of ="<<viewport->x()<<", "<<viewport->y()<<", "<<viewport->width()<<", "<<viewport->height()<<" with pixelFormat=0x"<<std::hex<<_pixelFormat<<std::dec<<std::endl; glReadBuffer(camera->getDrawBuffer()); osg::ref_ptr<osg::Image> image = new osg::Image; image->readPixels(viewport->x(),viewport->y(),viewport->width(),viewport->height(), _pixelFormat, GL_UNSIGNED_BYTE, 1); if (_flip) image->flipVertical(); osgDB::writeImageFile(*image, outputFileName); } }
void SomePointsGenerator::drawImplementation( osg::RenderInfo& renderInfo ) const { //get output buffer unsigned int contextID = renderInfo.getState()->getContextID(); GLuint ubuff= genbuffer->getOrCreateGLBufferObject(contextID)->getGLObjectID(); osg::GLExtensions* ext = renderInfo.getState()->get<osg::GLExtensions>(); ext->glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0,ubuff); glEnable(GL_RASTERIZER_DISCARD); ext->glBeginTransformFeedback(GL_POINTS); osg::Geometry::drawImplementation( renderInfo ); ext->glEndTransformFeedback(); glDisable(GL_RASTERIZER_DISCARD); ext->glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0); }
void dustDrawable::drawImplementation(osg::RenderInfo &renderInfo) const { if (renderer != NULL) { osg::ref_ptr<osg::StateSet> currentState = new osg::StateSet; renderInfo.getState()->captureCurrentState(*currentState); renderInfo.getState()->pushStateSet(currentState.get()); // Save the current state glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); glPushAttrib(GL_ALL_ATTRIB_BITS); /* enum DisplayMode { PARTICLE_POINTS, PARTICLE_SPRITES, PARTICLE_SPRITES_COLOR, PARTICLE_NUM_MODES */ if (starDust::instance()->tuiRender->getState()) { renderer->setSpriteSize(starDust::instance()->particleSize); renderer->display(ParticleRenderer::PARTICLE_SPRITES, cudaParticles->getNumActiveParticles()); //renderer->display(ParticleRenderer::PARTICLE_POINTS); } // Restore the current state glPopAttrib(); glPopClientAttrib(); renderInfo.getState()->popStateSet(); } }
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 ); } }
void LayerDrawable::drawImplementation(osg::RenderInfo& ri) const { DrawState& ds = *_drawState; // Make sure the draw state is up to date: ds.refresh(ri); if (ds._layerOrderUL >= 0) { ds._ext->glUniform1i(ds._layerOrderUL, (GLint)_order); } if (_layer) { if (ds._layerUidUL >= 0) ds._ext->glUniform1i(ds._layerUidUL, (GLint)_layer->getUID()); if (ds._layerOpacityUL >= 0 && _imageLayer) ds._ext->glUniform1f(ds._layerOpacityUL, (GLfloat)_imageLayer->getOpacity()); if (ds._layerMinRangeUL >= 0 && _imageLayer) ds._ext->glUniform1f(ds._layerMinRangeUL, (GLfloat)_imageLayer->getMinVisibleRange()); if (ds._layerMaxRangeUL >= 0 && _imageLayer) ds._ext->glUniform1f(ds._layerMaxRangeUL, (GLfloat)_imageLayer->getMaxVisibleRange()); } else { if (ds._layerUidUL >= 0) ds._ext->glUniform1i(ds._layerUidUL, (GLint)-1); if (ds._layerOpacityUL >= 0) ds._ext->glUniform1f(ds._layerOpacityUL, (GLfloat)1.0f); if (ds._layerMinRangeUL >= 0) ds._ext->glUniform1f(ds._layerMinRangeUL, (GLfloat)0.0f); if (ds._layerMaxRangeUL >= 0) ds._ext->glUniform1f(ds._layerMaxRangeUL, (GLfloat)FLT_MAX); } for (DrawTileCommands::const_iterator tile = _tiles.begin(); tile != _tiles.end(); ++tile) { tile->draw(ri, ds, 0L); } // If set, dirty all OSG state to prevent any leakage - this is sometimes // necessary when doing custom OpenGL within a Drawable. if (_clearOsgState) { ri.getState()->dirtyAllAttributes(); ri.getState()->dirtyAllModes(); 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(); } }
virtual void operator () (osg::RenderInfo& renderInfo) const { mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, mWidth, mHeight); // Callback removes itself when done if (renderInfo.getCurrentCamera()) renderInfo.getCurrentCamera()->setInitialDrawCallback(NULL); }
void ChunkLodDrawable::drawImplementation(osg::RenderInfo& info) const { static int frame = 0; _triangles_rendered = 0; _triangles_per_second = 0; if (_tree != NULL) { if (_lastBoundIndex != _tree->getBoundIndex()) { computeBound(); _lastBoundIndex = _tree->getBoundIndex(); } ChunkLodTree *tree = const_cast<ChunkLodTree*>(_tree); osg::Matrix mv = info.getState()->getModelViewMatrix(); mv.invert(mv); osg::Vec3 viewpoint = mv.getTrans(); info.getState()->disableTexCoordPointersAboveAndIncluding(0); // NEW info.getState()->disableAllVertexArrays(); _details->enable(*info.getState()); osg::Timer t; osg::Timer_t update_t = t.tick(); tree->update(viewpoint, *info.getState()); //osg::Timer_t render_t = t.tick(); _triangles_rendered = tree->render(*info.getState(), *_details); _triangle_count += _triangles_rendered; float dt = t.delta_s(update_t, t.tick()); if (dt > 0.0030) { //float utime = t.delta_s(update_t, render_t) * 1000.0; dt *= 1000.0; //std::cout << "PAUSE c-lod render " << dt << " ms (" << utime << ", " << (dt - utime) << ")\n"; } // stats float d = t.delta_s(_last_tick, t.tick()); if (d > 1.0f) { //std::cout << "update tree for view from " << viewpoint << "\n"; //std::cout << _triangles_rendered << " triangles rendered\n"; _triangles_per_second = static_cast<unsigned long>(_triangle_count / d); _last_tick = t.tick(); _triangle_count = 0; } _details->disable(*info.getState()); info.getState()->disableAllVertexArrays(); info.getState()->dirtyTexCoordPointersAboveAndIncluding(0); info.getState()->setActiveTextureUnit(0); frame++; } }
void Skybox::drawImplementation(osg::RenderInfo& renderInfo) const{ int positionCote=mSize/2; Vec3Array* boxVertices = new osg::Vec3Array; boxVertices->push_back(Vec3f(-positionCote,-positionCote,-positionCote)); //back bottom left 0 boxVertices->push_back(Vec3f(positionCote,-positionCote,-positionCote)); //back bottom right 1 boxVertices->push_back(Vec3f(positionCote,positionCote,-positionCote)); //back up right 2 boxVertices->push_back(Vec3f(-positionCote,positionCote,-positionCote)); //back up left 3 boxVertices->push_back(Vec3f(-positionCote,-positionCote,positionCote)); //front bottom left 4 boxVertices->push_back(Vec3f(positionCote,-positionCote,positionCote)); //front bottom right 5 boxVertices->push_back(Vec3f(positionCote,positionCote,positionCote)); //front up right 6 boxVertices->push_back(Vec3f(-positionCote,positionCote,positionCote)); //front up left 7 osg::ref_ptr<osg::Texture2D> texture (new osg::Texture2D(image.get())); osg::ref_ptr<osg::StateSet> texSS (new osg::StateSet); texture->setInternalFormat(GL_RGBA); texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); texSS->setTextureAttributeAndModes (0, texture.get(), osg::StateAttribute::ON); texSS->setMode(GL_LIGHTING,osg::StateAttribute::OFF); renderInfo.getState()->apply(texSS.get()); boxVertices->at(0)._v; glBegin(GL_QUADS); glTexCoord2f(1.0/4.0, 1.01/3.0);glVertex3fv(boxVertices->at(0)._v); glTexCoord2f(2.0/4.0, 1.01/3.0);glVertex3fv(boxVertices->at(1)._v); glTexCoord2f(2.0/4.0, 1.99/3.0);glVertex3fv(boxVertices->at(2)._v); glTexCoord2f(1.0/4.0, 1.99/3.0);glVertex3fv(boxVertices->at(3)._v); glTexCoord2f(1.0/4.0, 1.01/3.0);glVertex3fv(boxVertices->at(0)._v); glTexCoord2f(0, 1.01/3.0);glVertex3fv(boxVertices->at(4)._v); glTexCoord2f(0, 1.99/3.0);glVertex3fv(boxVertices->at(7)._v); glTexCoord2f(1.0/4.0, 1.99/3.0);glVertex3fv(boxVertices->at(3)._v); glTexCoord2f(1, 1.01/3.0);glVertex3fv(boxVertices->at(4)._v); glTexCoord2f(3.0/4.0, 1.01/3.0);glVertex3fv(boxVertices->at(5)._v); glTexCoord2f(3.0/4.0, 1.99/3.0);glVertex3fv(boxVertices->at(6)._v); glTexCoord2f(1, 1.99/3.0);glVertex3fv(boxVertices->at(7)._v); glTexCoord2f(2.0/4.0, 1.01/3.0);glVertex3fv(boxVertices->at(1)._v); glTexCoord2f(3.0/4.0, 1.01/3.0);glVertex3fv(boxVertices->at(5)._v); glTexCoord2f(3.0/4.0, 1.99/3.0);glVertex3fv(boxVertices->at(6)._v); glTexCoord2f(2.0/4.0, 1.99/3.0);glVertex3fv(boxVertices->at(2)._v); glTexCoord2f(1.01/4.0, 0);glVertex3fv(boxVertices->at(0)._v); glTexCoord2f(1.99/4.0, 0);glVertex3fv(boxVertices->at(1)._v); glTexCoord2f(1.99/4.0, 1.0/3.0);glVertex3fv(boxVertices->at(5)._v); glTexCoord2f(1.01/4.0, 1.0/3.0);glVertex3fv(boxVertices->at(4)._v); glTexCoord2f(1.99/4.0, 2.0/3.0);glVertex3fv(boxVertices->at(2)._v); glTexCoord2f(1.01/4.0, 2.0/3.0);glVertex3fv(boxVertices->at(3)._v); glTexCoord2f(1.01/4.0, 1);glVertex3fv(boxVertices->at(7)._v); glTexCoord2f(1.99/4.0, 1);glVertex3fv(boxVertices->at(6)._v); glEnd(); renderInfo.getState()->apply(); }
virtual void operator () (osg::RenderInfo& renderInfo) const { int w = renderInfo.getCurrentCamera()->getViewport()->width(); int h = renderInfo.getCurrentCamera()->getViewport()->height(); mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, w, h); // Callback removes itself when done if (renderInfo.getCurrentCamera()) renderInfo.getCurrentCamera()->setInitialDrawCallback(NULL); }
void Camera::DrawCallback::operator () (osg::RenderInfo& renderInfo) const { if (renderInfo.getCurrentCamera()) { operator()(*(renderInfo.getCurrentCamera())); } else { OSG_WARN<<"Error: Camera::DrawCallback called without valid camera."<<std::endl; } }
void ossimPlanetViewer::DrawCallback::operator () (osg::RenderInfo& renderInfo) const { if(!theViewer) return; if(theViewer->terrainLayer()&&renderInfo.getState()) { //double delta = osg::Timer::instance()->delta_s(theViewer->theFrameStartTimeStamp, // osg::Timer::instance()->tick()); theViewer->terrainLayer()->compileGLObjects(*renderInfo.getState(), theViewer->terrainLayer()->minimumTimeToCompilePerFrame()); } }
void SilverLiningNode::CloudDrawable::drawImplementation( osg::RenderInfo& renderInfo ) const { renderInfo.getState()->disableAllVertexArrays(); _silverLining->atmosphere()->DrawObjects( true, true, true, 1.0f ); renderInfo.getState()->dirtyAllVertexArrays(); /*void* shadowTexID = 0; SilverLining::Matrix4 lightMatrix, shadowMatrix; if ( _silverLining->atmosphere()->GetShadowMap(shadowTexID, &lightMatrix, &shadowMatrix) ) { }*/ }
void RenderBin::draw(osg::RenderInfo& renderInfo,RenderLeaf*& previous) { renderInfo.pushRenderBin(this); if (_drawCallback.valid()) { _drawCallback->drawImplementation(this,renderInfo,previous); } else drawImplementation(renderInfo,previous); renderInfo.popRenderBin(); }
void drawImplementation(osg::RenderInfo& renderInfo, const osg::Drawable* drawable) const { unsigned contextID = renderInfo.getState()->getContextID(); osg::GLBufferObject* bo = _vbo->getOrCreateGLBufferObject(contextID); if ( bo->isDirty() ) bo->compileBuffer(); GLuint objID = bo->getGLObjectID(); osg::GLExtensions* ext = renderInfo.getState()->get<osg::GLExtensions>(); GLuint numPrims = 0; GLuint& query = _queries[contextID]; if ( query == INT_MAX ) { ext->glGenQueries(1, &query); } else { ext->glGetQueryObjectuiv(query, GL_QUERY_RESULT, &numPrims); s_numInstancesToDraw = numPrims; } ext->glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, objID, _offset, _size); //if ( renderInfo.getState()->checkGLErrors("PRE:glBindBufferBase") ) exit(0); glEnable(GL_RASTERIZER_DISCARD); //if ( renderInfo.getState()->checkGLErrors("PRE:glEnable(GL_RASTERIZER_DISCARD)") ) exit(0); ext->glBeginQuery(TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, query); ext->glBeginTransformFeedback(GL_POINTS); // get from input geom? //if ( renderInfo.getState()->checkGLErrors("PRE:glBeginTransformFeedback(GL_POINTS)") ) exit(0); drawable->drawImplementation(renderInfo); ext->glEndTransformFeedback(); //if ( renderInfo.getState()->checkGLErrors("POST:glEndTransformFeedback") ) exit(0); ext->glEndQuery(TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); glDisable(GL_RASTERIZER_DISCARD); //if ( renderInfo.getState()->checkGLErrors("POST:glDisable(GL_RASTERIZER_DISCARD)") ) exit(0); ext->glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0); //if ( renderInfo.getState()->checkGLErrors("POST:glBindBufferBase") ) exit(0); }
void ScreenCapture::operator()( osg::RenderInfo& ri ) const { if( captureOn_ ) { bool newThread( false ); if( wit_ == NULL ) { wit_ = new WriteImageThread(); newThread = true; } osg::Image* image = new osg::Image; image->setFileName( getFileName( useFrameNum_ ? ri.getState()->getFrameStamp() : NULL ) ); osg::notify( osg::INFO ) << "ScreenCapture: Reading image for file " << image->getFileName() << " ... " << std::endl; const osg::Viewport* vp( ( vp_ == NULL ) ? ri.getState()->getCurrentViewport() : vp_.get() ); image->readPixels( vp->x(), vp->y(), vp->width(), vp->height(), GL_RGBA, GL_UNSIGNED_BYTE ); { OpenThreads::ScopedLock< OpenThreads::Mutex > lock( wit_->lock_ ); wit_->imageList_.push_back( image ); } if( numFrames_ > 0 ) { if( --numFrames_ == 0 ) captureOn_ = false; } if( newThread ) wit_->start(); } else { if( ( wit_ != NULL ) ) { osg::notify( osg::INFO ) << "ScreenCapture: Thread cleanup" << std::endl; if( wit_->isRunning() ) { wit_->cancel(); wit_->join(); } if( wit_->isRunning() ) osg::notify( osg::ALWAYS ) << "Thread is running after join() call." << std::endl; delete wit_; wit_ = NULL; } } }
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(); } }
/** * Draws a bin. Most of this code is copied from osgUtil::RenderBin::drawImplementation. * The modifications are (a) skipping code to render child bins, (b) setting a bin-global * projection matrix in orthographic space, and (c) calling our custom "renderLeaf()" method * instead of RenderLeaf::render() */ void drawImplementation( osgUtil::RenderBin* bin, osg::RenderInfo& renderInfo, osgUtil::RenderLeaf*& previous ) { osg::State& state = *renderInfo.getState(); unsigned int numToPop = (previous ? osgUtil::StateGraph::numToPop(previous->_parent) : 0); if (numToPop>1) --numToPop; unsigned int insertStateSetPosition = state.getStateSetStackSize() - numToPop; if (bin->getStateSet()) { state.insertStateSet(insertStateSetPosition, bin->getStateSet()); } // apply a window-space projection matrix. const osg::Viewport* vp = renderInfo.getCurrentCamera()->getViewport(); if ( vp ) { //TODO see which is faster osg::ref_ptr<osg::RefMatrix>& m = _ortho2D.get(); if ( !m.valid() ) m = new osg::RefMatrix(); m->makeOrtho2D( vp->x(), vp->x()+vp->width()-1, vp->y(), vp->y()+vp->height()-1 ); state.applyProjectionMatrix( m.get() ); //osg::ref_ptr<osg::RefMatrix> rm = new osg::RefMatrix( osg::Matrix::ortho2D( // vp->x(), vp->x()+vp->width()-1, // vp->y(), vp->y()+vp->height()-1 ) ); //state.applyProjectionMatrix( rm.get() ); } // render the list osgUtil::RenderBin::RenderLeafList& leaves = bin->getRenderLeafList(); for(osgUtil::RenderBin::RenderLeafList::reverse_iterator rlitr = leaves.rbegin(); rlitr!= leaves.rend(); ++rlitr) { osgUtil::RenderLeaf* rl = *rlitr; renderLeaf( rl, renderInfo, previous ); previous = rl; } if ( bin->getStateSet() ) { state.removeStateSet(insertStateSetPosition); } }
void PointDrawable::drawImplementation(osg::RenderInfo& ri) const { // The mode validity for PointSprite might never get set since // the OSG GLObjectVisitor cannot traverse the shared stateset; // so this block of code will set it upon first draw. static bool s_sharedStateActivated = false; static Threading::Mutex s_mutex; if (!s_sharedStateActivated) { s_mutex.lock(); if (!s_sharedStateActivated) { osg::PointSprite* sprite = dynamic_cast<osg::PointSprite*>( _sharedStateSet->getTextureAttribute(0, osg::StateAttribute::POINTSPRITE)); if (sprite) sprite->checkValidityOfAssociatedModes(*ri.getState()); s_sharedStateActivated = true; } s_mutex.unlock(); } osg::Geometry::drawImplementation(ri); }
void WindowCaptureCallback::operator () (osg::RenderInfo& renderInfo) const { osg::GraphicsContext* gc = renderInfo.getState()->getGraphicsContext(); if (_gc==NULL) { _gc=gc; } freemovr_assert(_gc==gc); // only a single GraphicsContext supported OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); if (_fileName.empty()) return; // no point in capturing image if it's not used glReadBuffer(GL_BACK); const osg::GraphicsContext::Traits* traits = gc->getTraits(); if (traits!=NULL) { GLenum pixelFormat; pixelFormat = GL_RGBA; // force saving alpha int width = traits->width; int height = traits->height; //std::cout<<"Capture: size="<<width<<"x"<<height<<", format="<<(pixelFormat == GL_RGBA ? "GL_RGBA":"GL_RGB")<<std::endl; _image->readPixels(0, 0, width, height, pixelFormat, GL_UNSIGNED_BYTE); //std::cout << "Writing to: " << _fileName << std::endl; osgDB::writeImageFile(*_image, _fileName); _fileName = ""; } }
virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const { osg::State& state = *renderInfo.getState(); if (!_firstTime) { _previousModelViewMatrix = _currentModelViewMatrix; _currentModelViewMatrix = state.getModelViewMatrix(); _inverseModelViewMatrix.invert(_currentModelViewMatrix); osg::Matrix T(_previousModelViewMatrix*_inverseModelViewMatrix); osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(const_cast<osg::Drawable*>(drawable)); osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray()); for(unsigned int i=0;i+1<vertices->size();i+=2) { (*vertices)[i+1] = (*vertices)[i]*T; } } else { _currentModelViewMatrix = state.getModelViewMatrix(); } _firstTime = false; drawable->drawImplementation(renderInfo); }
virtual void drawImplementation(osg::RenderInfo& renderInfo,const osg::Drawable* drawable) const { if (!_stats) return; osgText::Text* text = (osgText::Text*)(drawable); std::ostringstream viewStr; viewStr.setf(std::ios::left, std::ios::adjustfield); viewStr.width(14); // Used fixed formatting, as scientific will switch to "...e+.." notation for // large numbers of vertices/drawables/etc. viewStr.setf(std::ios::fixed); viewStr.precision(0); unsigned int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber()-1; for (std::vector<std::string>::const_iterator it = _statNames.begin(); it != _statNames.end(); ++it) { if (it->empty()) viewStr << std::endl; else { double value = 0.0; if (_stats->getAttribute(frameNumber, *it, value)) viewStr << std::setw(8) << value << std::endl; else viewStr << std::setw(8) << "." << std::endl; } } text->setText(viewStr.str()); text->drawImplementation(renderInfo); }
virtual void operator()( osg::RenderInfo& renderInfo ) const { osg::Viewport* viewport = renderInfo.getCurrentCamera()->getViewport(); if ( viewport ) TwWindowSize( viewport->width(), viewport->height() ); updateEvents(); TwDraw(); }
void FlexDrawable::drawImplementation( osg::RenderInfo& renderInfo ) const { osg::State* state = renderInfo.getState(); state->disableAllVertexArrays(); // Make sure the client unit and active unit are unified state->setClientActiveTextureUnit( 0 ); state->setActiveTextureUnit( 0 ); if ( !_solver ) return; int numParticles = flexGetActiveCount(_solver); if ( 1 ) // CPU readback { flexGetParticles( _solver, (float*)&_positions[0], numParticles, eFlexMemoryHostAsync ); flexGetVelocities( _solver, (float*)&_velocities[0], numParticles, eFlexMemoryHostAsync ); // Wait for GPU to finish working (can perform async. CPU work here) flexSetFence(); flexWaitFence(); state->lazyDisablingOfVertexAttributes(); state->setVertexPointer( 4, GL_FLOAT, 0, (float*)&_positions[0] ); state->applyDisablingOfVertexAttributes(); glDrawArrays( GL_POINTS, 0, numParticles ); } else // CUDA to OpenGL drawing { // TODO } }
void InitCallback::operator()( osg::RenderInfo& renderInfo ) const { if( _initialized ) return; unsigned int contextID = renderInfo.getState()->getContextID(); /* osgwQuery::QueryBenchmarks* qb = */ osgwQuery::getQueryBenchmarks( contextID, &renderInfo ); _initialized = true; }
virtual void operator () (osg::RenderInfo& renderInfo) const { glReadBuffer(_readBuffer); osg::GraphicsContext* gc = renderInfo.getState()->getGraphicsContext(); osg::ref_ptr<ContextData> cd = getContextData(gc); cd->read(); }
int DepthPeelBin::drawOpaque( osg::RenderInfo& renderInfo, osgUtil::RenderLeaf*& previous, bool& remaining ) { TRACEDUMP("DepthPeelBin::drawOpaque"); int drawCount( 0 ); osg::State& state = *renderInfo.getState(); unsigned int rbc( 0 ), rla( 0 ), rlb( 0 ); // draw first set of draw bins. RenderBinList::iterator rbitr; for(rbitr = _bins.begin(); rbitr!=_bins.end() && rbitr->first<0; ++rbitr) { rbitr->second->draw(renderInfo,previous); rbc++; drawCount++; } // draw fine grained ordering. for(RenderLeafList::iterator rlitr= _renderLeafList.begin(); rlitr!= _renderLeafList.end(); ++rlitr) { osgUtil::RenderLeaf* rl = *rlitr; rl->render(renderInfo,previous); previous = rl; rla++; drawCount++; } // draw coarse grained ordering. for(StateGraphList::iterator oitr=_stateGraphList.begin(); oitr!=_stateGraphList.end(); ++oitr) { for(osgUtil::StateGraph::LeafList::iterator dw_itr = (*oitr)->_leaves.begin(); dw_itr != (*oitr)->_leaves.end(); ++dw_itr) { osgUtil::RenderLeaf* rl = dw_itr->get(); rl->render(renderInfo,previous); previous = rl; rlb++; drawCount++; } } remaining = ( rbitr != _bins.end() ); osg::notify( osg::DEBUG_FP ) << "rbc " << rbc << " rla " << rla << " rlb " << rlb << std::endl; return( drawCount ); }
void OpenVRTextureBuffer::onPreRender(osg::RenderInfo& renderInfo) { osg::State& state = *renderInfo.getState(); const OSG_GLExtensions* fbo_ext = getGLExtensions(state); fbo_ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_MSAA_FBO); fbo_ext->glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D_MULTISAMPLE, m_MSAA_ColorTex, 0); fbo_ext->glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D_MULTISAMPLE, m_MSAA_DepthTex, 0); }