Commit 426d5d8d authored by Ken Martin's avatar Ken Martin

Some fixes to framebuffer resorce management

Set the context early, break from OpenGL resource
creation.
parent f161cf55
......@@ -335,7 +335,6 @@ void vtkAndroidRenderWindowInteractor::HandleCommand(int32_t cmd)
{
LOGW("Creating Window");
this->RenderWindow->SetWindowId(this->AndroidApplication->window);
this->RenderWindow->Start();
LOGW("Done Creating Window start");
this->RenderWindow->Render();
LOGW("Done first render");
......
......@@ -299,6 +299,7 @@ vtkOpenGLFramebufferObject::~vtkOpenGLFramebufferObject()
delete i->second;
}
this->ColorBuffers.clear();
this->Context = nullptr;
}
//-----------------------------------------------------------------------------
......@@ -346,22 +347,21 @@ unsigned int vtkOpenGLFramebufferObject::GetBothMode()
//----------------------------------------------------------------------------
void vtkOpenGLFramebufferObject::CreateFBO()
{
this->FBOIndex = 0;
GLuint temp;
glGenFramebuffers(1, &temp);
vtkOpenGLCheckErrorMacro("failed at glGenFramebuffers");
this->FBOIndex = temp;
if (!this->FBOIndex)
{
this->ResourceCallback->RegisterGraphicsResources(this->Context);
this->FBOIndex = 0;
GLuint temp;
glGenFramebuffers(1, &temp);
vtkOpenGLCheckErrorMacro("failed at glGenFramebuffers");
this->FBOIndex = temp;
}
}
//----------------------------------------------------------------------------
void vtkOpenGLFramebufferObject::DestroyFBO()
{
// because we don't hold a reference to the render
// context we don't have any control on when it is
// destroyed. In fact it may be destroyed before
// we are(eg smart pointers), in which case we should
// do nothing.
if (this->Context && (this->FBOIndex != 0))
if (this->FBOIndex != 0)
{
GLuint fbo = static_cast<GLuint>(this->FBOIndex);
glDeleteFramebuffers(1, &fbo);
......@@ -382,7 +382,6 @@ void vtkOpenGLFramebufferObject::ReleaseGraphicsResources(vtkWindow* win)
this->DestroyDepthBuffer(win);
this->DestroyColorBuffers(win);
this->DestroyFBO();
this->Context = nullptr;
this->Modified();
}
......@@ -397,8 +396,6 @@ void vtkOpenGLFramebufferObject::SetContext(vtkRenderWindow* rw)
return;
}
this->ResourceCallback->RegisterGraphicsResources(renWin);
// all done if assigned null
if (!renWin)
{
......@@ -412,8 +409,6 @@ void vtkOpenGLFramebufferObject::SetContext(vtkRenderWindow* rw)
}
// initialize
this->Context = renWin;
this->Context->MakeCurrent();
this->CreateFBO();
}
//----------------------------------------------------------------------------
......@@ -737,6 +732,13 @@ void vtkOpenGLFramebufferObject::Bind()
void vtkOpenGLFramebufferObject::Bind(unsigned int mode)
{
if (!this->Context)
{
vtkErrorMacro("Attempt to bind framebuffer without a context");
return;
}
this->Context->MakeCurrent();
this->CreateFBO();
if (this->FBOIndex != 0)
{
// note this also changes the draw/read buffers as they are
......
......@@ -164,7 +164,6 @@
#include "vtkFrameBufferObjectBase.h"
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkWeakPointer.h" // needed for vtkWeakPointer.
#include <map> // for the maps
#include <vector> // for the lists of logical buffers.
......@@ -490,7 +489,7 @@ protected:
vtkOpenGLFramebufferObject();
~vtkOpenGLFramebufferObject() override;
vtkWeakPointer<vtkOpenGLRenderWindow> Context;
vtkOpenGLRenderWindow* Context;
unsigned int FBOIndex;
......
......@@ -178,6 +178,7 @@ vtkOpenGLRenderWindow::vtkOpenGLRenderWindow()
strcpy(this->WindowName, defaultWindowName);
this->OffScreenFramebuffer = vtkOpenGLFramebufferObject::New();
this->OffScreenFramebuffer->SetContext(this);
this->BackLeftBuffer = static_cast<unsigned int>(GL_BACK_LEFT);
this->BackRightBuffer = static_cast<unsigned int>(GL_BACK_RIGHT);
......@@ -1790,7 +1791,6 @@ int vtkOpenGLRenderWindow::CreateOffScreenFramebuffer(int width, int height)
this->MultSamples = 0;
#endif
}
this->OffScreenFramebuffer->SetContext(this);
this->GetState()->PushFramebufferBindings();
this->OffScreenFramebuffer->PopulateFramebuffer(width, height,
true, // textures
......
......@@ -148,8 +148,13 @@ void vtkPanoramicProjectionPass::InitOpenGLResources(vtkOpenGLRenderWindow* renW
if (this->FrameBufferObject == nullptr)
{
this->FrameBufferObject = vtkOpenGLFramebufferObject::New();
}
if (!this->FrameBufferObject->GetFBOIndex())
{
this->FrameBufferObject->SetContext(renWin);
renWin->GetState()->PushFramebufferBindings();
this->FrameBufferObject->Bind();
this->FrameBufferObject->Resize(this->CubeResolution, this->CubeResolution);
this->FrameBufferObject->AddDepthAttachment();
renWin->GetState()->PopFramebufferBindings();
......
......@@ -183,6 +183,7 @@ void vtkWin32RenderWindowInteractor::Initialize()
// get the info we need from the RenderingWindow
ren = (vtkWin32OpenGLRenderWindow*)(this->RenderWindow);
ren->Start();
ren->End();
size = ren->GetSize();
ren->GetPosition();
this->WindowId = ren->GetWindowId();
......
......@@ -392,6 +392,7 @@ void vtkXRenderWindowInteractor::Initialize()
this->WindowId = XtWindow(this->Top);
ren->Start();
ren->End();
this->Enable();
this->Size[0] = size[0];
this->Size[1] = size[1];
......
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