Commit 131d87ca authored by Aashish Chaudhary's avatar Aashish Chaudhary
Browse files

Do not create objects every render frame

parent 19c75043
...@@ -112,6 +112,7 @@ public: ...@@ -112,6 +112,7 @@ public:
this->TextureSize[0] = this->TextureSize[1] = this->TextureSize[2] = -1; this->TextureSize[0] = this->TextureSize[1] = this->TextureSize[2] = -1;
this->WindowLowerLeft[0] = this->WindowLowerLeft[1] = 0; this->WindowLowerLeft[0] = this->WindowLowerLeft[1] = 0;
this->WindowSize[0] = this->WindowSize[1] = 0; this->WindowSize[0] = this->WindowSize[1] = 0;
this->LastWindowSize[0] = this->LastWindowSize[1] = 0;
this->ScalarsRange[0][0] = this->ScalarsRange[0][1] = 0.0; this->ScalarsRange[0][0] = this->ScalarsRange[0][1] = 0.0;
this->ScalarsRange[1][0] = this->ScalarsRange[1][1] = 0.0; this->ScalarsRange[1][0] = this->ScalarsRange[1][1] = 0.0;
this->ScalarsRange[2][0] = this->ScalarsRange[2][1] = 0.0; this->ScalarsRange[2][0] = this->ScalarsRange[2][1] = 0.0;
...@@ -287,6 +288,11 @@ public: ...@@ -287,6 +288,11 @@ public:
void ConvertTextureToImageData(vtkTextureObject* texture, void ConvertTextureToImageData(vtkTextureObject* texture,
vtkImageData* output); vtkImageData* output);
// Render to framebuffer object
void RenderToFBO(vtkRenderer* ren);
void ReleaseRenderToImageGraphicsResources(vtkWindow* win);
// Private member variables // Private member variables
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
vtkOpenGLGPUVolumeRayCastMapper* Parent; vtkOpenGLGPUVolumeRayCastMapper* Parent;
...@@ -321,6 +327,7 @@ public: ...@@ -321,6 +327,7 @@ public:
int TextureSize[3]; int TextureSize[3];
int WindowLowerLeft[2]; int WindowLowerLeft[2];
int WindowSize[2]; int WindowSize[2];
int LastWindowSize[2];
double ScalarsRange[4][2]; double ScalarsRange[4][2];
double LoadedBounds[6]; double LoadedBounds[6];
...@@ -2053,6 +2060,133 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal:: ...@@ -2053,6 +2060,133 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::
id->Delete(); id->Delete();
} }
//----------------------------------------------------------------------------
void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::RenderToFBO(vtkRenderer* ren)
{
if ( (this->LastWindowSize[0] != this->WindowSize[0]) ||
(this->LastWindowSize[1] != this->WindowSize[1]) )
{
this->LastWindowSize[0] = this->WindowSize[0];
this->LastWindowSize[1] = this->WindowSize[1];
this->ReleaseRenderToImageGraphicsResources(ren->GetRenderWindow());
}
if (!this->FBO)
{
this->FBO = vtkFrameBufferObject2::New();
}
this->FBO->SetContext(vtkOpenGLRenderWindow::SafeDownCast(
ren->GetRenderWindow()));
this->FBO->Bind(GL_FRAMEBUFFER);
this->FBO->InitializeViewport(this->WindowSize[0], this->WindowSize[1]);
if (!this->RTTDepthBufferTextureObject ||
!this->RTTDepthTextureObject ||
!this->RTTColorTextureObject)
{
this->RTTDepthBufferTextureObject = vtkTextureObject::New();
this->RTTDepthBufferTextureObject->SetContext(
vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow()));
this->RTTDepthBufferTextureObject->AllocateDepth(
this->WindowSize[0], this->WindowSize[1], vtkTextureObject::Float32);
this->RTTDepthBufferTextureObject->SetMinificationFilter(
vtkTextureObject::Nearest);
this->RTTDepthBufferTextureObject->SetMagnificationFilter(
vtkTextureObject::Nearest);
this->RTTDepthBufferTextureObject->SetAutoParameters(0);
this->RTTDepthBufferTextureObject->Bind();
this->RTTDepthTextureObject = vtkTextureObject::New();
this->RTTDepthTextureObject->SetContext(
vtkOpenGLRenderWindow::SafeDownCast(
ren->GetRenderWindow()));
this->RTTDepthTextureObject->Create2D(this->WindowSize[0],
this->WindowSize[1], 1,
VTK_UNSIGNED_CHAR, false);
this->RTTDepthTextureObject->SetMinificationFilter(
vtkTextureObject::Nearest);
this->RTTDepthTextureObject->SetMagnificationFilter(
vtkTextureObject::Nearest);
this->RTTDepthTextureObject->SetAutoParameters(0);
this->RTTDepthTextureObject->Bind();
this->RTTColorTextureObject = vtkTextureObject::New();
this->RTTColorTextureObject->SetContext(
vtkOpenGLRenderWindow::SafeDownCast(
ren->GetRenderWindow()));
this->RTTColorTextureObject->SetMinificationFilter(
vtkTextureObject::Nearest);
this->RTTColorTextureObject->SetMagnificationFilter(
vtkTextureObject::Nearest);
this->RTTColorTextureObject->Create2D(this->WindowSize[0],
this->WindowSize[1], 4,
VTK_UNSIGNED_CHAR, false);
this->RTTColorTextureObject->SetAutoParameters(0);
this->RTTColorTextureObject->Bind();
this->FBO->AddTexDepthAttachment(
GL_DRAW_FRAMEBUFFER,
this->RTTDepthBufferTextureObject->GetHandle());
this->FBO->AddTexColorAttachment(
GL_DRAW_FRAMEBUFFER, 0U,
this->RTTColorTextureObject->GetHandle());
this->FBO->AddTexColorAttachment(
GL_DRAW_FRAMEBUFFER, 1U,
this->RTTDepthTextureObject->GetHandle());
this->FBO->ActivateDrawBuffers(2);
this->FBO->UnBind(GL_FRAMEBUFFER);
}
this->FBO->Bind(GL_FRAMEBUFFER);
this->FBO->CheckFrameBufferStatus(GL_FRAMEBUFFER);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
}
//----------------------------------------------------------------------------
void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal
::ReleaseRenderToImageGraphicsResources(vtkWindow* win)
{
vtkOpenGLRenderWindow *rwin =
vtkOpenGLRenderWindow::SafeDownCast(win);
if (rwin)
{
if (this->FBO)
{
this->FBO->Delete();
this->FBO = 0;
}
if (this->RTTDepthBufferTextureObject)
{
this->RTTDepthBufferTextureObject->ReleaseGraphicsResources(win);
this->RTTDepthBufferTextureObject->Delete();
this->RTTDepthBufferTextureObject = 0;
}
if (this->RTTDepthTextureObject)
{
this->RTTDepthTextureObject->ReleaseGraphicsResources(win);
this->RTTDepthTextureObject->Delete();
this->RTTDepthTextureObject = 0;
}
if (this->RTTColorTextureObject)
{
this->RTTColorTextureObject->ReleaseGraphicsResources(win);
this->RTTColorTextureObject->Delete();
this->RTTColorTextureObject = 0;
}
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
vtkOpenGLGPUVolumeRayCastMapper::vtkOpenGLGPUVolumeRayCastMapper() : vtkOpenGLGPUVolumeRayCastMapper::vtkOpenGLGPUVolumeRayCastMapper() :
vtkGPUVolumeRayCastMapper() vtkGPUVolumeRayCastMapper()
...@@ -2102,16 +2236,14 @@ vtkTextureObject* vtkOpenGLGPUVolumeRayCastMapper::GetColorTexture() ...@@ -2102,16 +2236,14 @@ vtkTextureObject* vtkOpenGLGPUVolumeRayCastMapper::GetColorTexture()
void vtkOpenGLGPUVolumeRayCastMapper::GetDepthImage(vtkImageData* output) void vtkOpenGLGPUVolumeRayCastMapper::GetDepthImage(vtkImageData* output)
{ {
return this->Impl->ConvertTextureToImageData( return this->Impl->ConvertTextureToImageData(
this->Impl->RTTDepthTextureObject, this->Impl->RTTDepthTextureObject, output);
output);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void vtkOpenGLGPUVolumeRayCastMapper::GetColorImage(vtkImageData* output) void vtkOpenGLGPUVolumeRayCastMapper::GetColorImage(vtkImageData* output)
{ {
return this->Impl->ConvertTextureToImageData( return this->Impl->ConvertTextureToImageData(
this->Impl->RTTColorTextureObject, this->Impl->RTTColorTextureObject, output);
output);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -2141,25 +2273,7 @@ void vtkOpenGLGPUVolumeRayCastMapper::ReleaseGraphicsResources( ...@@ -2141,25 +2273,7 @@ void vtkOpenGLGPUVolumeRayCastMapper::ReleaseGraphicsResources(
this->Impl->DepthTextureObject = 0; this->Impl->DepthTextureObject = 0;
} }
if (this->Impl->FBO) this->Impl->ReleaseRenderToImageGraphicsResources(window);
{
this->Impl->FBO->Delete();
this->Impl->FBO = 0;
}
if (this->Impl->RTTDepthTextureObject)
{
this->Impl->RTTDepthTextureObject->ReleaseGraphicsResources(window);
this->Impl->RTTDepthTextureObject->Delete();
this->Impl->RTTDepthTextureObject = 0;
}
if (this->Impl->RTTColorTextureObject)
{
this->Impl->RTTColorTextureObject->ReleaseGraphicsResources(window);
this->Impl->RTTColorTextureObject->Delete();
this->Impl->RTTColorTextureObject = 0;
}
if(this->Impl->MaskTextures != 0) if(this->Impl->MaskTextures != 0)
{ {
...@@ -2683,108 +2797,7 @@ void vtkOpenGLGPUVolumeRayCastMapper::GPURender(vtkRenderer* ren, ...@@ -2683,108 +2797,7 @@ void vtkOpenGLGPUVolumeRayCastMapper::GPURender(vtkRenderer* ren,
if (this->RenderToImage) if (this->RenderToImage)
{ {
if (!this->Impl->FBO) this->Impl->RenderToFBO(ren);
{
this->Impl->FBO = vtkFrameBufferObject2::New();
}
this->Impl->FBO->SetContext(vtkOpenGLRenderWindow::SafeDownCast(
ren->GetRenderWindow()));
this->Impl->FBO->Bind(GL_FRAMEBUFFER);
this->Impl->FBO->InitializeViewport(this->Impl->WindowSize[0],
this->Impl->WindowSize[1]);
if (this->Impl->RTTDepthBufferTextureObject)
{
this->Impl->RTTDepthBufferTextureObject->ReleaseGraphicsResources(
ren->GetRenderWindow());
this->Impl->RTTDepthBufferTextureObject->Delete();
this->Impl->RTTDepthBufferTextureObject = 0;
}
if (this->Impl->RTTDepthTextureObject)
{
this->Impl->RTTDepthTextureObject->ReleaseGraphicsResources(
ren->GetRenderWindow());
this->Impl->RTTDepthTextureObject->Delete();
this->Impl->RTTDepthTextureObject = 0;
}
if (this->Impl->RTTColorTextureObject)
{
this->Impl->RTTColorTextureObject->ReleaseGraphicsResources(
ren->GetRenderWindow());
this->Impl->RTTColorTextureObject->Delete();
this->Impl->RTTColorTextureObject = 0;
}
if (!this->Impl->RTTDepthBufferTextureObject ||
!this->Impl->RTTDepthTextureObject ||
!this->Impl->RTTColorTextureObject)
{
this->Impl->RTTDepthBufferTextureObject = vtkTextureObject::New();
this->Impl->RTTDepthBufferTextureObject->SetContext(
vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow()));
this->Impl->RTTDepthBufferTextureObject->AllocateDepth(
this->Impl->WindowSize[0], this->Impl->WindowSize[1], vtkTextureObject::Float32);
this->Impl->RTTDepthBufferTextureObject->SetMinificationFilter(
vtkTextureObject::Nearest);
this->Impl->RTTDepthBufferTextureObject->SetMagnificationFilter(
vtkTextureObject::Nearest);
this->Impl->RTTDepthBufferTextureObject->SetAutoParameters(0);
this->Impl->RTTDepthBufferTextureObject->Bind();
this->Impl->RTTDepthTextureObject = vtkTextureObject::New();
this->Impl->RTTDepthTextureObject->SetContext(
vtkOpenGLRenderWindow::SafeDownCast(
ren->GetRenderWindow()));
this->Impl->RTTDepthTextureObject->Create2D(this->Impl->WindowSize[0],
this->Impl->WindowSize[1], 1,
VTK_UNSIGNED_CHAR, false);
this->Impl->RTTDepthTextureObject->SetMinificationFilter(
vtkTextureObject::Nearest);
this->Impl->RTTDepthTextureObject->SetMagnificationFilter(
vtkTextureObject::Nearest);
this->Impl->RTTDepthTextureObject->SetAutoParameters(0);
this->Impl->RTTDepthTextureObject->Bind();
this->Impl->RTTColorTextureObject = vtkTextureObject::New();
this->Impl->RTTColorTextureObject->SetContext(
vtkOpenGLRenderWindow::SafeDownCast(
ren->GetRenderWindow()));
this->Impl->RTTColorTextureObject->SetMinificationFilter(
vtkTextureObject::Nearest);
this->Impl->RTTColorTextureObject->SetMagnificationFilter(
vtkTextureObject::Nearest);
this->Impl->RTTColorTextureObject->Create2D(this->Impl->WindowSize[0],
this->Impl->WindowSize[1], 4,
VTK_UNSIGNED_CHAR, false);
this->Impl->RTTColorTextureObject->SetAutoParameters(0);
this->Impl->RTTColorTextureObject->Bind();
this->Impl->FBO->AddTexDepthAttachment(
GL_DRAW_FRAMEBUFFER,
this->Impl->RTTDepthBufferTextureObject->GetHandle());
this->Impl->FBO->AddTexColorAttachment(
GL_DRAW_FRAMEBUFFER, 0U,
this->Impl->RTTColorTextureObject->GetHandle());
this->Impl->FBO->AddTexColorAttachment(
GL_DRAW_FRAMEBUFFER, 1U,
this->Impl->RTTDepthTextureObject->GetHandle());
this->Impl->FBO->ActivateDrawBuffers(2);
this->Impl->FBO->UnBind(GL_FRAMEBUFFER);
}
this->Impl->FBO->Bind(GL_FRAMEBUFFER);
this->Impl->FBO->CheckFrameBufferStatus(GL_FRAMEBUFFER);
vtkCheckFrameBufferStatusMacro(GL_FRAMEBUFFER);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
} }
// Allocate important variables // Allocate important variables
......
...@@ -35,12 +35,16 @@ public: ...@@ -35,12 +35,16 @@ public:
// Description: // Description:
// Low level API to enable access to depth texture in // Low level API to enable access to depth texture in
// RenderToTexture mode. // RenderToTexture mode. It will return either NULL if
// RenderToImage was never turned on or texture captured
// the last time RenderToImage was on.
vtkTextureObject* GetDepthTexture(); vtkTextureObject* GetDepthTexture();
// Description: // Description:
// Low level API to enable access to color texture in // Low level API to enable access to color texture in
// RenderToTexture mode. // RenderToTexture mode. It will return either NULL if
// RenderToImage was never turned on or texture captured
// the last time RenderToImage was on.
vtkTextureObject* GetColorTexture(); vtkTextureObject* GetColorTexture();
// Description: // Description:
......
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