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(); } }
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(); } }