diff --git a/Rendering/Core/vtkFrameBufferObjectBase.h b/Rendering/Core/vtkFrameBufferObjectBase.h index 30e860eff8e5f4713dff00d5e68445bd63355872..d185b021ecb1e5561f0f5919bae809e9ef81253f 100644 --- a/Rendering/Core/vtkFrameBufferObjectBase.h +++ b/Rendering/Core/vtkFrameBufferObjectBase.h @@ -32,6 +32,8 @@ class VTKRENDERINGCORE_EXPORT vtkFrameBufferObjectBase : public vtkObject vtkTypeMacro(vtkFrameBufferObjectBase, vtkObject); void PrintSelf(ostream& os, vtkIndent indent); + // Description: + // Dimensions in pixels of the framebuffer. virtual int *GetLastSize() = 0; virtual void GetLastSize (int &_arg1, int &_arg2) = 0; virtual void GetLastSize (int _arg[2]) = 0; diff --git a/Rendering/OpenGL2/vtkFrameBufferObject2.cxx b/Rendering/OpenGL2/vtkFrameBufferObject2.cxx index 98aeed4db7ed6c3170af43417b9683c5cd83a217..97b12913e87502543c8d6cf0bf94466a93a9bf90 100644 --- a/Rendering/OpenGL2/vtkFrameBufferObject2.cxx +++ b/Rendering/OpenGL2/vtkFrameBufferObject2.cxx @@ -39,6 +39,8 @@ vtkFrameBufferObject2::vtkFrameBufferObject2() this->PreviousReadFBO = 0; this->PreviousDrawBuffer = GL_NONE; this->PreviousReadBuffer = GL_NONE; + this->LastViewportSize[0] = -1; + this->LastViewportSize[1] = -1; } //---------------------------------------------------------------------------- @@ -176,7 +178,7 @@ void vtkFrameBufferObject2::Bind(unsigned int mode) { assert(this->FBOIndex!=0); // need to call glGenFramebuffers first - // need to ensure that binding is esxtablished *every* time because + // need to ensure that binding is established *every* time because // if other code binds over us then all of our subsequent calls // will affect that fbo not ours. glBindFramebuffer((GLenum)mode, this->FBOIndex); @@ -551,6 +553,54 @@ void vtkFrameBufferObject2::Download( pbo->UnBind(); } +//----------------------------------------------------------------------------- +int* vtkFrameBufferObject2::GetLastSize(bool forceUpdate) +{ + if (forceUpdate) + this->QueryViewportSize(); + + return this->LastViewportSize; +} + +//----------------------------------------------------------------------------- +int* vtkFrameBufferObject2::GetLastSize() +{ + this->QueryViewportSize(); + return this->LastViewportSize; +} + +//----------------------------------------------------------------------------- +void vtkFrameBufferObject2::GetLastSize(int &width, int &height) +{ + this->QueryViewportSize(); + width = this->LastViewportSize[0]; + height = this->LastViewportSize[1]; +} + +//----------------------------------------------------------------------------- +void vtkFrameBufferObject2::GetLastSize(int size[2]) +{ + this->GetLastSize(size[0], size[1]); +} + +//----------------------------------------------------------------------------- +void vtkFrameBufferObject2::QueryViewportSize() +{ + if (!this->Context) + { + vtkErrorMacro("Failed to query viewport size because" + "there is no context set!"); + return; + } + + GLint vp[4]; + glGetIntegerv(GL_VIEWPORT, vp); + vtkOpenGLStaticCheckErrorMacro("Error querying viewport size!"); + + this->LastViewportSize[0] = vp[2]; + this->LastViewportSize[1] = vp[3]; +} + //----------------------------------------------------------------------------- int vtkFrameBufferObject2::GetOpenGLType(int vtkType) { @@ -727,5 +777,7 @@ void vtkFrameBufferObject2::PrintSelf(ostream& os, vtkIndent indent) << indent << "PreviousReadFBO=" << this->PreviousReadFBO << endl << indent << "PreviousDrawBuffer=" << this->PreviousDrawBuffer << endl << indent << "PreviousReadBuffer=" << this->PreviousReadBuffer << endl + << indent << "Last Viewport Size =" << "[" << this->LastViewportSize[0] << ", " + << this->LastViewportSize[1] << "]" << endl << endl; } diff --git a/Rendering/OpenGL2/vtkFrameBufferObject2.h b/Rendering/OpenGL2/vtkFrameBufferObject2.h index d9f06baf681cd21ac4db538b0b9afc1c231ccf84..fed0d870264a6b765c2bf64b98d66454f1fc78cb 100644 --- a/Rendering/OpenGL2/vtkFrameBufferObject2.h +++ b/Rendering/OpenGL2/vtkFrameBufferObject2.h @@ -42,7 +42,7 @@ #ifndef vtkFrameBufferObject2_h #define vtkFrameBufferObject2_h -#include "vtkObject.h" +#include "vtkFrameBufferObjectBase.h" #include "vtkRenderingOpenGL2Module.h" // For export macro #include "vtkSmartPointer.h" // needed for vtkSmartPointer. #include "vtkWeakPointer.h" // needed for vtkWeakPointer. @@ -78,11 +78,11 @@ class vtkRenderbuffer; class vtkPixelBufferObject; class vtkOpenGLRenderWindow; -class VTKRENDERINGOPENGL2_EXPORT vtkFrameBufferObject2 : public vtkObject +class VTKRENDERINGOPENGL2_EXPORT vtkFrameBufferObject2 : public vtkFrameBufferObjectBase { public: static vtkFrameBufferObject2* New(); - vtkTypeMacro(vtkFrameBufferObject2, vtkObject); + vtkTypeMacro(vtkFrameBufferObject2, vtkFrameBufferObjectBase); void PrintSelf(ostream& os, vtkIndent indent); // Description: @@ -274,6 +274,23 @@ public: int oglFormat, vtkPixelBufferObject *pbo); + // Description: + // Dimensions in pixels of the framebuffer. Given that InitializeViewport + // is static, these methods query the viewport size directly from GL. The + // cached size (LastViewportSize) will appear uninitialized (-1) until one + // one of these methods has been called. As with InitializeViewport, the + // methods affect the currently bound FBO (user must bind first). + virtual int* GetLastSize(); + virtual void GetLastSize(int &width, int &height); + virtual void GetLastSize(int size[2]); + + // Description: + // Additional overload which lets the user decide whether the returned size + // should be the currently cached value or first be updated from GL. As with + // InitializeViewport, the method affects the currently bound FBO (user must + // bind first). + int* GetLastSize(bool forceUpdate); + protected: // Description: // Load all necessary extensions. @@ -286,7 +303,6 @@ protected: // delete buffer (occurs during destruction or context swicth) void DestroyFBO(); - // Description: // Given a vtk type get a compatible open gl type. int GetOpenGLType(int vtkType); @@ -301,8 +317,13 @@ protected: unsigned int PreviousReadFBO; unsigned int PreviousDrawBuffer; unsigned int PreviousReadBuffer; + int LastViewportSize[2]; private: + // Description: + // Queries viewport dimensions from GL. + inline void QueryViewportSize(); + vtkFrameBufferObject2(const vtkFrameBufferObject2&) VTK_DELETE_FUNCTION; void operator=(const vtkFrameBufferObject2&) VTK_DELETE_FUNCTION;