Added GraphicsContext support for clearing the graphis context. The clearing

is off by default (ClearMask is 0), but can be switched on when ClearMask is
non zero.  GraphicsContext::clear() is called after each swap buffers
This commit is contained in:
Robert Osfield 2007-01-05 15:24:06 +00:00
parent ed3c7ba116
commit 9fcace0e73
4 changed files with 47 additions and 4 deletions

View File

@ -161,6 +161,11 @@ int main( int argc, char **argv )
osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height );
// need to ensure that the window is cleared make sure that the complete window is set the correct colour
// rather than just the parts of the window that are under the camera's viewports
gw->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f));
gw->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
else
{

View File

@ -169,6 +169,9 @@ class OSG_EXPORT GraphicsContext : public Referenced
/** Get the traits of the GraphicsContext.*/
inline const Traits* getTraits() const { return _traits.get(); }
/** Return whether a valid and usable GraphicsContext has been created.*/
virtual bool valid() const { return false; }
/** Set the State object which tracks the current OpenGL state for this graphics context.*/
inline void setState(State* state) { _state = state; }
@ -178,10 +181,25 @@ class OSG_EXPORT GraphicsContext : public Referenced
/** Get the const State object which tracks the current OpenGL state for this graphics context.*/
inline const State* getState() const { return _state.get(); }
/** Return whether a valid and usable GraphicsContext has been created.*/
virtual bool valid() const { return false; }
/** Sets the clear color. */
inline void setClearColor(const Vec4& color) { _clearColor = color; }
/** Returns the clear color. */
inline const Vec4& getClearColor() const { return _clearColor; }
/** Set the clear mask used in glClear(..).
* Defaults to GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT. */
inline void setClearMask(GLbitfield mask) { _clearMask = mask; }
/** Get the clear mask.*/
inline GLbitfield getClearMask() const { return _clearMask; }
/** Do an OpenGL clear of the full graphics context/window.
* Note, must only be called from a thread with this context current.*/
virtual void clear();
/** Realise the GraphicsContext.*/
bool realize();
@ -288,6 +306,10 @@ class OSG_EXPORT GraphicsContext : public Referenced
ref_ptr<Traits> _traits;
ref_ptr<State> _state;
Vec4 _clearColor;
GLbitfield _clearMask;
OpenThreads::Mutex _mutex;
OpenThreads::Thread* _threadOfLastMakeCurrent;

View File

@ -126,6 +126,8 @@ void GraphicsContext::decrementContextIDUsageCount(unsigned int contextID)
GraphicsContext::GraphicsContext():
_clearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)),
_clearMask(0),
_threadOfLastMakeCurrent(0)
{
setThreadSafeRefUnref(true);
@ -137,7 +139,18 @@ GraphicsContext::~GraphicsContext()
close(false);
}
/** Realise the GraphicsContext.*/
void GraphicsContext::clear()
{
if (_clearMask==0 || !_traits) return;
glViewport(0, 0, _traits->width, _traits->height);
glScissor(0, 0, _traits->width, _traits->height);
glClearColor( _clearColor[0], _clearColor[1], _clearColor[2], _clearColor[3]);
glClear( _clearMask );
}
bool GraphicsContext::realize()
{
if (realizeImplementation())
@ -212,6 +225,7 @@ void GraphicsContext::swapBuffers()
if (isCurrent())
{
swapBuffersImplementation();
clear();
}
else if (_graphicsThread.valid() &&
_threadOfLastMakeCurrent == _graphicsThread.get())
@ -222,6 +236,7 @@ void GraphicsContext::swapBuffers()
{
makeCurrent();
swapBuffersImplementation();
clear();
releaseContext();
}
}

View File

@ -379,6 +379,7 @@ void SwapBuffersOperation::operator () (GraphicsContext* context)
if (context)
{
context->swapBuffersImplementation();
context->clear();
}
}