diff --git a/include/osgViewer/api/Win32/PixelBufferWin32 b/include/osgViewer/api/Win32/PixelBufferWin32 new file mode 100644 index 000000000..d0771b50d --- /dev/null +++ b/include/osgViewer/api/Win32/PixelBufferWin32 @@ -0,0 +1,87 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +/* Note, elements of PixeBufferWin32 have used Prodcer/RenderSurface_Win32.cpp as both + * a guide to use of X11/GLX and copiying directly in the case of setBorder(). + * These elements are license under OSGPL as above, with Copyright (C) 2001-2004 Don Burns. + */ + +#ifndef OSGVIEWER_PIXELBUFFERWIN32 +#define OSGVIEWER_PIXELBUFFERWIN32 1 + +#include + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0500 +#endif +#include + +namespace osgViewer +{ + +class OSGVIEWER_EXPORT PixelBufferWin32 : public osgViewer::GraphicsWindow +{ + public: + + PixelBufferWin32(osg::GraphicsContext::Traits* traits); + + virtual ~PixelBufferWin32(); + + virtual bool isSameKindAs(const Object* object) const { return dynamic_cast(object)!=0; } + virtual const char* libraryName() const { return "osgViewer"; } + virtual const char* className() const { return "PixelBufferWin32"; } + + virtual bool valid() const { return _valid; } + + /** Realize the GraphicsContext.*/ + virtual bool realizeImplementation(); + + /** Return true if the graphics context has been realised and is ready to use.*/ + virtual bool isRealizedImplementation() const { return _realized; } + + /** Close the graphics context.*/ + virtual void closeImplementation(); + + /** Make this graphics context current.*/ + virtual bool makeCurrentImplementation(); + + /** Release the graphics context.*/ + virtual bool releaseContextImplementation(); + + /** Swap the front and back buffers.*/ + virtual void swapBuffersImplementation(); + + /** Get native window.*/ + HWND getHWND() const { return _hwnd; } + + HDC getHDC() const { return _hdc; } + + /** Get native OpenGL graphics context.*/ + HGLRC getWGLContext() const { return _hglrc; } + + protected: + + void init(); + + HWND _hwnd; + HDC _hdc; + HGLRC _hglrc; + + bool _initialized; + bool _valid; + bool _realized; +}; + +} + +#endif diff --git a/src/osgViewer/CMakeLists.txt b/src/osgViewer/CMakeLists.txt index 3410c3f5c..e61e75289 100644 --- a/src/osgViewer/CMakeLists.txt +++ b/src/osgViewer/CMakeLists.txt @@ -33,10 +33,18 @@ SET(LIB_COMMON_FILES IF(WIN32) - SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS} ${HEADER_PATH}/api/Win32/GraphicsWindowWin32) - SET(LIB_COMMON_FILES ${LIB_COMMON_FILES} GraphicsWindowWin32.cpp) + SET(LIB_PUBLIC_HEADERS ${LIB_PUBLIC_HEADERS} + ${HEADER_PATH}/api/Win32/GraphicsWindowWin32 + ${HEADER_PATH}/api/Win32/PixelBufferWin32 + ) + + SET(LIB_COMMON_FILES ${LIB_COMMON_FILES} + GraphicsWindowWin32.cpp + PixelBufferWin32.cpp + ) ELSE(WIN32) + IF(APPLE) # FIXME: OS X needs selection mechanism for Cocoa, Carbon, X11 @@ -56,6 +64,7 @@ ELSE(WIN32) ) ENDIF(APPLE) + ENDIF(WIN32) diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index b5eac814f..fd10a8e67 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -299,59 +300,7 @@ class Win32WindowingSystem : public osg::GraphicsContext::WindowingSystemInterfa Win32WindowingSystem& operator=( const Win32WindowingSystem& ); }; -// -// This is the class we need to create for pbuffers and display devices that are not attached to the desktop -// (and thus cannot have windows created on their surface). -// -// Note its not a GraphicsWindow as it won't need any of the event handling and window mapping facilities. -// - -class GraphicsContextWin32 : public osg::GraphicsContext -{ - public: - - GraphicsContextWin32(osg::GraphicsContext::Traits* traits); - ~GraphicsContextWin32(); - - virtual bool valid() const; - - /** Realise the GraphicsContext implementation, - * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ - virtual bool realizeImplementation(); - - /** Return true if the graphics context has been realised, and is ready to use, implementation. - * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ - virtual bool isRealizedImplementation() const; - - /** Close the graphics context implementation. - * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ - virtual void closeImplementation(); - - /** Make this graphics context current implementation. - * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ - virtual bool makeCurrentImplementation(); - - /** Make this graphics context current with specified read context implementation. - * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ - virtual bool makeContextCurrentImplementation(GraphicsContext* /*readContext*/); - - /** Release the graphics context.*/ - virtual bool releaseContextImplementation(); - - /** Pure virtual, Bind the graphics context to associated texture implementation. - * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ - virtual void bindPBufferToTextureImplementation(GLenum /*buffer*/); - - /** Swap the front and back buffers implementation. - * Pure virtual - must be implemented by Concrate implementations of GraphicsContext. */ - virtual void swapBuffersImplementation(); - - protected: - - bool _valid; -}; - -////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // Error reporting ////////////////////////////////////////////////////////////////////////////// @@ -955,7 +904,7 @@ osg::GraphicsContext* Win32WindowingSystem::createGraphicsContext( osg::Graphics { if (traits->pbuffer) { - osg::ref_ptr pbuffer = new GraphicsContextWin32(traits); + osg::ref_ptr pbuffer = new PixelBufferWin32(traits); if (pbuffer->valid()) return pbuffer.release(); else return 0; } @@ -2177,67 +2126,6 @@ LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT uMsg, W ::CallWindowProc(_windowProcedure, hwnd, uMsg, wParam, lParam); } -////////////////////////////////////////////////////////////////////////////// -// GraphicsContextWin32 implementation -////////////////////////////////////////////////////////////////////////////// - -GraphicsContextWin32::GraphicsContextWin32( osg::GraphicsContext::Traits* traits ) -: _valid(false) -{ - _traits = traits; -} - -GraphicsContextWin32::~GraphicsContextWin32() -{ -} - -bool GraphicsContextWin32::valid() const -{ - return _valid; -} - -bool GraphicsContextWin32::realizeImplementation() -{ - osg::notify(osg::NOTICE) << "GraphicsContextWin32::realizeImplementation() not implemented." << std::endl; return false; -} - -bool GraphicsContextWin32::isRealizedImplementation() const -{ - osg::notify(osg::NOTICE) << "GraphicsContextWin32::isRealizedImplementation() not implemented." << std::endl; return false; -} - -void GraphicsContextWin32::closeImplementation() -{ - osg::notify(osg::NOTICE) << "GraphicsContextWin32::closeImplementation() not implemented." << std::endl; -} - -bool GraphicsContextWin32::makeCurrentImplementation() -{ - osg::notify(osg::NOTICE) << "GraphicsContextWin32::makeCurrentImplementation() not implemented." << std::endl; - return false; -} - -bool GraphicsContextWin32::makeContextCurrentImplementation( GraphicsContext* /*readContext*/ ) -{ - osg::notify(osg::NOTICE) << "GraphicsContextWin32::makeContextCurrentImplementation(..) not implemented." << std::endl; - return false; -} - -bool GraphicsContextWin32::releaseContextImplementation() -{ - osg::notify(osg::NOTICE) << "GraphicsContextWin32::releaseContextImplementation(..) not implemented." << std::endl; - return false; -} - -void GraphicsContextWin32::bindPBufferToTextureImplementation( GLenum /*buffer*/ ) -{ - osg::notify(osg::NOTICE) << "GraphicsContextWin32::void bindPBufferToTextureImplementation(..) not implemented." << std::endl; -} - -void GraphicsContextWin32::swapBuffersImplementation() -{ - osg::notify(osg::NOTICE) << "GraphicsContextWin32:: swapBuffersImplementation() not implemented." << std::endl; -} ////////////////////////////////////////////////////////////////////////////// // Class responsible for registering the Win32 Windowing System interface diff --git a/src/osgViewer/PixelBufferWin32.cpp b/src/osgViewer/PixelBufferWin32.cpp new file mode 100644 index 000000000..bb7899dee --- /dev/null +++ b/src/osgViewer/PixelBufferWin32.cpp @@ -0,0 +1,107 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. + * + * Some elements of GraphicsWindowWin32 have used the Producer implementation as a reference. + * These elements are licensed under OSGPL as above, with Copyright (C) 2001-2004 Don Burns. + */ + +#include + +#include +#include +#include +#include + +using namespace osgViewer; + + +PixelBufferWin32::PixelBufferWin32( osg::GraphicsContext::Traits* traits ): + _hwnd(0), + _hdc(0), + _hglrc(0), + _initialized(false), + _valid(false), + _realized(false) +{ + _traits = traits; + + init(); + + if (valid()) + { + setState( new osg::State ); + getState()->setGraphicsContext(this); + + if (_traits.valid() && _traits->sharedContext) + { + getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); + incrementContextIDUsageCount( getState()->getContextID() ); + } + else + { + getState()->setContextID( osg::GraphicsContext::createNewContextID() ); + } + } +} + +PixelBufferWin32::~PixelBufferWin32() +{ +} + +bool PixelBufferWin32::valid() const +{ + return _valid; +} + +bool PixelBufferWin32::realizeImplementation() +{ + osg::notify(osg::NOTICE) << "PixelBufferWin32::realizeImplementation() not implemented." << std::endl; return false; +} + +bool PixelBufferWin32::isRealizedImplementation() const +{ + osg::notify(osg::NOTICE) << "PixelBufferWin32::isRealizedImplementation() not implemented." << std::endl; return false; +} + +void PixelBufferWin32::closeImplementation() +{ + osg::notify(osg::NOTICE) << "PixelBufferWin32::closeImplementation() not implemented." << std::endl; +} + +bool PixelBufferWin32::makeCurrentImplementation() +{ + osg::notify(osg::NOTICE) << "PixelBufferWin32::makeCurrentImplementation() not implemented." << std::endl; + return false; +} + +bool PixelBufferWin32::makeContextCurrentImplementation( GraphicsContext* /*readContext*/ ) +{ + osg::notify(osg::NOTICE) << "PixelBufferWin32::makeContextCurrentImplementation(..) not implemented." << std::endl; + return false; +} + +bool PixelBufferWin32::releaseContextImplementation() +{ + osg::notify(osg::NOTICE) << "PixelBufferWin32::releaseContextImplementation(..) not implemented." << std::endl; + return false; +} + +void PixelBufferWin32::bindPBufferToTextureImplementation( GLenum /*buffer*/ ) +{ + osg::notify(osg::NOTICE) << "PixelBufferWin32::void bindPBufferToTextureImplementation(..) not implemented." << std::endl; +} + +void PixelBufferWin32::swapBuffersImplementation() +{ + osg::notify(osg::NOTICE) << "PixelBufferWin32:: swapBuffersImplementation() not implemented." << std::endl; +} +