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:
parent
ed3c7ba116
commit
9fcace0e73
@ -161,6 +161,11 @@ int main( int argc, char **argv )
|
|||||||
osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
||||||
|
|
||||||
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height );
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -169,6 +169,9 @@ class OSG_EXPORT GraphicsContext : public Referenced
|
|||||||
/** Get the traits of the GraphicsContext.*/
|
/** Get the traits of the GraphicsContext.*/
|
||||||
inline const Traits* getTraits() const { return _traits.get(); }
|
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.*/
|
/** Set the State object which tracks the current OpenGL state for this graphics context.*/
|
||||||
inline void setState(State* state) { _state = state; }
|
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.*/
|
/** Get the const State object which tracks the current OpenGL state for this graphics context.*/
|
||||||
inline const State* getState() const { return _state.get(); }
|
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.*/
|
/** Realise the GraphicsContext.*/
|
||||||
bool realize();
|
bool realize();
|
||||||
@ -288,6 +306,10 @@ class OSG_EXPORT GraphicsContext : public Referenced
|
|||||||
|
|
||||||
ref_ptr<Traits> _traits;
|
ref_ptr<Traits> _traits;
|
||||||
ref_ptr<State> _state;
|
ref_ptr<State> _state;
|
||||||
|
|
||||||
|
Vec4 _clearColor;
|
||||||
|
GLbitfield _clearMask;
|
||||||
|
|
||||||
OpenThreads::Mutex _mutex;
|
OpenThreads::Mutex _mutex;
|
||||||
OpenThreads::Thread* _threadOfLastMakeCurrent;
|
OpenThreads::Thread* _threadOfLastMakeCurrent;
|
||||||
|
|
||||||
|
@ -126,6 +126,8 @@ void GraphicsContext::decrementContextIDUsageCount(unsigned int contextID)
|
|||||||
|
|
||||||
|
|
||||||
GraphicsContext::GraphicsContext():
|
GraphicsContext::GraphicsContext():
|
||||||
|
_clearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)),
|
||||||
|
_clearMask(0),
|
||||||
_threadOfLastMakeCurrent(0)
|
_threadOfLastMakeCurrent(0)
|
||||||
{
|
{
|
||||||
setThreadSafeRefUnref(true);
|
setThreadSafeRefUnref(true);
|
||||||
@ -137,7 +139,18 @@ GraphicsContext::~GraphicsContext()
|
|||||||
close(false);
|
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()
|
bool GraphicsContext::realize()
|
||||||
{
|
{
|
||||||
if (realizeImplementation())
|
if (realizeImplementation())
|
||||||
@ -212,6 +225,7 @@ void GraphicsContext::swapBuffers()
|
|||||||
if (isCurrent())
|
if (isCurrent())
|
||||||
{
|
{
|
||||||
swapBuffersImplementation();
|
swapBuffersImplementation();
|
||||||
|
clear();
|
||||||
}
|
}
|
||||||
else if (_graphicsThread.valid() &&
|
else if (_graphicsThread.valid() &&
|
||||||
_threadOfLastMakeCurrent == _graphicsThread.get())
|
_threadOfLastMakeCurrent == _graphicsThread.get())
|
||||||
@ -222,6 +236,7 @@ void GraphicsContext::swapBuffers()
|
|||||||
{
|
{
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
swapBuffersImplementation();
|
swapBuffersImplementation();
|
||||||
|
clear();
|
||||||
releaseContext();
|
releaseContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,6 +379,7 @@ void SwapBuffersOperation::operator () (GraphicsContext* context)
|
|||||||
if (context)
|
if (context)
|
||||||
{
|
{
|
||||||
context->swapBuffersImplementation();
|
context->swapBuffersImplementation();
|
||||||
|
context->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user