Commit 58b93bcc authored by Alvaro Sanchez's avatar Alvaro Sanchez

Made vtkFBO2 derive from vtkFBOBase.

Viewport size can now be queried from vtkFBO2. It is up to the user to decide
whether a cached size is sufficient.
parent 0983eaba
Pipeline #26787 passed with stage
......@@ -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;
......
......@@ -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;
}
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment