Implemented the beginings of the osgProducer::GraphicsContexImplementation.

Added options into osgprerender for controlling how to do the pre rendering i.e.
--fbo, --pbuffer, --fb --window, and also added the option for controlling the
window size with --width and --height.
This commit is contained in:
Robert Osfield
2005-07-21 19:27:19 +00:00
parent 7776924407
commit 302c58fc93
10 changed files with 277 additions and 131 deletions

View File

@@ -4,6 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
EventAdapter.cpp\
KeyboardMouseCallback.cpp\
GraphicsContextImplementation.cpp\
OsgCameraGroup.cpp\
OsgSceneHandler.cpp\
ViewerEventHandler.cpp\

View File

@@ -511,6 +511,19 @@ bool OsgCameraGroup::realize()
}
}
// now set up GraphicsContext wrappers for each of the render surfaces
// to all core OSG classes to keep track of the graphics context.
for(RenderSurfaceStateMap::iterator ritr = _renderSurfaceStateMap.begin();
ritr != _renderSurfaceStateMap.end();
++ritr)
{
Producer::RenderSurface* rs = ritr->first;
osg::State* state = ritr->second;
GraphicsContextImplementation* gc = new GraphicsContextImplementation(rs);
gc->setState(state);
state->setGraphicsContext(gc);
_gcList.push_back(gc);
}
if( _global_stateset == NULL && _shvec.size() > 0 )
{

View File

@@ -1217,6 +1217,84 @@ void CullVisitor::apply(osg::CameraNode& camera)
}
}
}
else if (camera.getRenderTargetImplmentation()==osg::CameraNode::PIXEL_BUFFER ||
camera.getRenderTargetImplmentation()==osg::CameraNode::SEPERATE_WINDOW )
{
osg::ref_ptr<osg::GraphicsContext> context = rtts->getGraphicsContext();
if (!context)
{
// set up the traits of the graphics context that we want
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->_width = viewport->width();
traits->_height = viewport->height();
traits->_pbuffer = (camera.getRenderTargetImplmentation()==osg::CameraNode::PIXEL_BUFFER);
traits->_windowDecoration = (camera.getRenderTargetImplmentation()==osg::CameraNode::SEPERATE_WINDOW);
bool colorAttached = false;
bool depthAttached = false;
bool stencilAttached = false;
for(osg::CameraNode::BufferAttachmentMap::iterator itr = bufferAttachements.begin();
itr != bufferAttachements.end();
++itr)
{
osg::CameraNode::BufferComponent buffer = itr->first;
osg::CameraNode::Attachment& attachment = itr->second;
switch(buffer)
{
case(osg::CameraNode::DEPTH_BUFFER):
{
traits->_depth = 24;
depthAttached = true;
break;
}
case(osg::CameraNode::STENCIL_BUFFER):
{
traits->_stencil = 8;
stencilAttached = true;
break;
}
default:
{
traits->_red = 8;
traits->_green = 8;
traits->_blue = 8;
traits->_alpha = 0; // ??? need to look at attachment, just do quick and dirty right now.
colorAttached = true;
break;
}
}
}
if (!depthAttached)
{
traits->_depth = 24;
}
if (!colorAttached)
{
traits->_red = 8;
traits->_green = 8;
traits->_blue = 8;
traits->_alpha = 0; // ???
}
// create the graphics context according to these traits.
context = osg::GraphicsContext::createGraphicsContext(traits.get());
if (!context)
{
osg::notify(osg::NOTICE)<<"Failed to aquire Graphics Context"<<std::endl;
}
rtts->setGraphicsContext(context.get());
}
}
}

View File

@@ -40,35 +40,64 @@ void RenderToTextureStage::draw(osg::State& state,RenderLeaf*& previous)
//cout << "begining RTTS draw "<<this<< " "<<_viewport->x()<<","<< _viewport->y()<<","<< _viewport->width()<<","<< _viewport->height()<<std::endl;
osg::State* useState = &state;
osg::GraphicsContext* callingContext = state.getGraphicsContext();
osg::GraphicsContext* useContext = callingContext;
if (_graphicsContext.valid() && _graphicsContext != callingContext)
{
useState = _graphicsContext->getState();
useContext = _graphicsContext.get();
useContext->makeCurrent();
glDrawBuffer(GL_FRONT);
glReadBuffer(GL_FRONT);
}
osg::FBOExtensions* fbo_ext = _fbo.valid() ? osg::FBOExtensions::instance(state.getContextID()) : 0;
bool fbo_supported = fbo_ext && fbo_ext->isSupported();
if (fbo_supported)
{
_fbo->apply(state);
_fbo->apply(*useState);
}
RenderStage::draw(state,previous);
// do the actual rendering of the scene.
RenderStage::draw(*useState,previous);
// now copy the rendered image to attached texture.
if (_texture.valid() && !fbo_supported)
{
//cout << " reading "<<this<< " "<<_viewport->x()<<","<< _viewport->y()<<","<< _viewport->width()<<","<< _viewport->height()<<std::endl;
if (callingContext && useContext!= callingContext)
{
// make the calling context use the pbuffer context for reading.
callingContext->makeContextCurrent(useContext);
glReadBuffer(GL_FRONT);
}
// need to implement texture cube map etc...
_texture->copyTexImage2D(state,_viewport->x(),_viewport->y(),_viewport->width(),_viewport->height());
}
if (_image.valid())
{
_image->readPixels(_viewport->x(),_viewport->y(),_viewport->width(),_viewport->height(),_imageReadPixelFormat,_imageReadPixelDataType);
}
if (fbo_supported)
{
// switch of the frame buffer object
fbo_ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
if (callingContext && useContext != callingContext)
{
// restore the graphics context.
callingContext->makeCurrent();
glReadBuffer(GL_BACK);
}
}