Commit 672a797b authored by Ken Martin's avatar Ken Martin

make vtkOpenGLTexture use vtkTextureObject

Change-Id: I1edde97d85741909ebae51652fdfd266f50e036f
parent 4b4c7cb2
......@@ -72,6 +72,7 @@ set(Module_SRCS
vtkOpenGLTextureUnitManager.cxx
vtkRenderPass.cxx
vtkRenderState.cxx
vtkTextureObject.cxx
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.cxx
)
......@@ -79,7 +80,6 @@ if (NOT ANDROID)
set(Module_SRCS ${Module_SRCS}
vtkPixelBufferObject.cxx
vtkFrameBufferObject.cxx
vtkTextureObject.cxx
)
endif()
......
......@@ -80,7 +80,7 @@ void vtkFrameBufferObject::DestroyFBO()
}
//----------------------------------------------------------------------------
bool vtkFrameBufferObject::IsSupported(vtkRenderWindow *)
bool vtkFrameBufferObject::IsSupported(vtkOpenGLRenderWindow *)
{
bool fbo = (glewIsSupported("GL_EXT_framebuffer_object") != 0);
bool fboBlit = (glewIsSupported("GL_EXT_framebuffer_blit") != 0);
......@@ -89,7 +89,7 @@ bool vtkFrameBufferObject::IsSupported(vtkRenderWindow *)
}
//----------------------------------------------------------------------------
bool vtkFrameBufferObject::LoadRequiredExtensions(vtkRenderWindow *vtkNotUsed(win))
bool vtkFrameBufferObject::LoadRequiredExtensions(vtkOpenGLRenderWindow *vtkNotUsed(win))
{
bool fbo = (glewIsSupported("GL_EXT_framebuffer_object") != 0);
bool fboBlit = (glewIsSupported("GL_EXT_framebuffer_blit") != 0);
......@@ -98,7 +98,7 @@ bool vtkFrameBufferObject::LoadRequiredExtensions(vtkRenderWindow *vtkNotUsed(wi
}
//----------------------------------------------------------------------------
void vtkFrameBufferObject::SetContext(vtkRenderWindow *renWin)
void vtkFrameBufferObject::SetContext(vtkOpenGLRenderWindow *renWin)
{
// avoid pointless re-assignment
if (this->Context==renWin)
......@@ -117,10 +117,7 @@ void vtkFrameBufferObject::SetContext(vtkRenderWindow *renWin)
return;
}
// check for support
vtkOpenGLRenderWindow *context
= vtkOpenGLRenderWindow::SafeDownCast(renWin);
if ( !context
|| !this->LoadRequiredExtensions(renWin))
if (!this->LoadRequiredExtensions(renWin))
{
vtkErrorMacro("Context does not support the required extensions");
return;
......@@ -132,7 +129,7 @@ void vtkFrameBufferObject::SetContext(vtkRenderWindow *renWin)
}
//----------------------------------------------------------------------------
vtkRenderWindow *vtkFrameBufferObject::GetContext()
vtkOpenGLRenderWindow *vtkFrameBufferObject::GetContext()
{
return this->Context;
}
......@@ -386,8 +383,8 @@ void vtkFrameBufferObject::CreateColorBuffers(
colorBuffer->SetContext(this->Context);
colorBuffer->SetMinificationFilter(vtkTextureObject::Nearest);
colorBuffer->SetLinearMagnification(false);
colorBuffer->SetWrapS(vtkTextureObject::Clamp);
colorBuffer->SetWrapT(vtkTextureObject::Clamp);
colorBuffer->SetWrapS(vtkTextureObject::ClampToEdge);
colorBuffer->SetWrapT(vtkTextureObject::ClampToEdge);
if (!colorBuffer->Create2D(
width,
height,
......
......@@ -51,8 +51,8 @@ public:
// context to avoid reference loops.
// SetContext() may raise an error is the OpenGL context does not support the
// required OpenGL extensions.
void SetContext(vtkRenderWindow *context);
vtkRenderWindow *GetContext();
void SetContext(vtkOpenGLRenderWindow *context);
vtkOpenGLRenderWindow *GetContext();
// Description:
// User must take care that width/height match the dimensions of
......@@ -158,7 +158,7 @@ public:
// Description:
// Returns if the context supports the required extensions.
// Extension will be loaded when the conetxt is set.
static bool IsSupported(vtkRenderWindow *renWin);
static bool IsSupported(vtkOpenGLRenderWindow *renWin);
// Description:
// Validate the current FBO configuration (attachments, formats, etc)
......@@ -170,7 +170,7 @@ protected:
// Description:
// Load all necessary extensions.
static
bool LoadRequiredExtensions(vtkRenderWindow *renWin);
bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin);
// gen buffer (occurs when context is set)
void CreateFBO();
......@@ -223,7 +223,7 @@ protected:
vtkFrameBufferObject();
~vtkFrameBufferObject();
vtkWeakPointer<vtkRenderWindow> Context;
vtkWeakPointer<vtkOpenGLRenderWindow> Context;
bool DepthBufferNeeded;
bool ColorBuffersDirty;
......
......@@ -249,15 +249,16 @@ void vtkOpenGLPolyDataMapper::BuildShader(std::string &VSSource,
{
FSSource = vtkgl::replace(FSSource,
"//VTK::DepthPeeling::Dec",
"uniform sampler2DRect opaqueZTexture;"
"uniform sampler2DRect translucentZTexture;");
"uniform vec2 screenSize;\n"
"uniform sampler2D opaqueZTexture;\n"
"uniform sampler2D translucentZTexture;\n");
FSSource = vtkgl::replace(FSSource,
"//VTK::DepthPeeling::Impl",
"float odepth = texture2DRect(opaqueZTexture, gl_FragCoord.xy).r; "
"if (gl_FragCoord.z >= odepth) { discard; } "
"float tdepth = texture2DRect(translucentZTexture, gl_FragCoord.xy).r; "
"if (gl_FragCoord.z <= tdepth) { discard; } "
// "gl_FragColor = vec4(odepth*odepth,tdepth*tdepth,gl_FragCoord.z*gl_FragCoord.z,1.0);"
"float odepth = texture2D(opaqueZTexture, gl_FragCoord.xy/screenSize).r;\n"
"if (gl_FragCoord.z >= odepth) { discard; }\n"
"float tdepth = texture2D(translucentZTexture, gl_FragCoord.xy/screenSize).r;\n"
"if (gl_FragCoord.z <= tdepth) { discard; }\n"
// "gl_FragColor = vec4(odepth*odepth,tdepth*tdepth,gl_FragCoord.z*gl_FragCoord.z,1.0);"
);
}
......@@ -465,7 +466,7 @@ void vtkOpenGLPolyDataMapper::SetMapperShaderParameters(vtkgl::CellBO &cellBO,
{
texture = actor->GetProperty()->GetTexture(0);
}
int tunit = renWin->GetTextureUnitForTexture(texture);
int tunit = vtkOpenGLTexture::SafeDownCast(texture)->GetTextureUnit();
cellBO.CachedProgram->Program.SetUniformi("texture1", tunit);
}
......@@ -473,11 +474,17 @@ void vtkOpenGLPolyDataMapper::SetMapperShaderParameters(vtkgl::CellBO &cellBO,
if (ren->GetLastRenderingUsedDepthPeeling())
{
vtkOpenGLRenderer *oglren = vtkOpenGLRenderer::SafeDownCast(ren);
int otunit = renWin->GetTextureUnitForTexture(oglren->GetOpaqueZTexture());
int otunit = oglren->GetOpaqueZTextureUnit();
cellBO.CachedProgram->Program.SetUniformi("opaqueZTexture", otunit);
int ttunit = renWin->GetTextureUnitForTexture(oglren->GetTranslucentZTexture());
int ttunit = oglren->GetTranslucentZTextureUnit();
cellBO.CachedProgram->Program.SetUniformi("translucentZTexture", ttunit);
int *renSize = ren->GetSize();
float screenSize[2];
screenSize[0] = renSize[0];
screenSize[1] = renSize[1];
cellBO.CachedProgram->Program.SetUniform2f("screenSize", screenSize);
}
if (this->LastSelectionState)
......
......@@ -158,29 +158,32 @@ void vtkOpenGLPolyDataMapper2D::BuildShader(
{
FSSource = vtkgl::replace(FSSource,
"//VTK::DepthPeeling::Dec",
"uniform sampler2DRect translucentRGBATexture;"
"uniform sampler2DRect currentRGBATexture;");
"uniform vec2 screenSize;\n"
"uniform sampler2D translucentRGBATexture;\n"
"uniform sampler2D currentRGBATexture;\n");
FSSource = vtkgl::replace(FSSource,
"//VTK::DepthPeeling::Impl", ""
"vec4 t1Color = texture2DRect(translucentRGBATexture, gl_FragCoord.xy); "
"vec4 t2Color = texture2DRect(currentRGBATexture, gl_FragCoord.xy); "
"gl_FragColor.a = t1Color.a + t2Color.a * (1.0-t1Color.a); "
"if (gl_FragColor.a > 0.0) { gl_FragColor.rgb = (t1Color.rgb*t1Color.a + t2Color.rgb*t2Color.a*(1.0-t1Color.a))/gl_FragColor.a; } "
"else { gl_FragColor.rgb = vec3(0.0,0.0,0.0); }"
"//VTK::DepthPeeling::Impl",
"vec4 t1Color = texture2D(translucentRGBATexture, gl_FragCoord.xy/screenSize);\n"
"vec4 t2Color = texture2D(currentRGBATexture, gl_FragCoord.xy/screenSize);\n"
"gl_FragColor.a = t1Color.a + t2Color.a * (1.0-t1Color.a);\n"
"if (gl_FragColor.a > 0.0) { gl_FragColor.rgb = (t1Color.rgb*t1Color.a + t2Color.rgb*t2Color.a*(1.0-t1Color.a))/gl_FragColor.a; }\n"
"else { gl_FragColor.rgb = vec3(0.0,0.0,0.0); }\n"
);
}
if (ren && ren->GetLastRenderingUsedDepthPeeling() == 3)
{
FSSource = vtkgl::replace(FSSource,
"//VTK::DepthPeeling::Dec",
"uniform sampler2DRect translucentRGBATexture;"
"uniform sampler2DRect currentRGBATexture;");
"uniform vec2 screenSize;\n"
"uniform sampler2D translucentRGBATexture;\n"
"uniform sampler2D opaqueRGBATexture;\n");
FSSource = vtkgl::replace(FSSource,
"//VTK::DepthPeeling::Impl", ""
"vec4 t1Color = texture2DRect(translucentRGBATexture, gl_FragCoord.xy); "
"vec4 t2Color = texture2DRect(currentRGBATexture, gl_FragCoord.xy); "
"gl_FragColor.a = 1.0;"
"gl_FragColor.rgb = (t1Color.rgb*t1Color.a + t2Color.rgb*(1.0-t1Color.a));"
"//VTK::DepthPeeling::Impl",
"vec4 t1Color = texture2D(translucentRGBATexture, gl_FragCoord.xy/screenSize);\n"
"vec4 t2Color = texture2D(opaqueRGBATexture, gl_FragCoord.xy/screenSize);\n"
"gl_FragColor.a = 1.0;\n"
"gl_FragColor.rgb = (t1Color.rgb*t1Color.a + t2Color.rgb*(1.0-t1Color.a));\n"
// "gl_FragColor.rgb = (t1Color.rgb*0.5 + t2Color.rgb*0.5);\n"
);
}
......@@ -273,8 +276,8 @@ void vtkOpenGLPolyDataMapper2D::UpdateShader(vtkgl::CellBO &cellBO,
int tunit = 0;
if (ta)
{
vtkTexture *texture = ta->GetTexture();
tunit = renWin->GetTextureUnitForTexture(texture);
vtkOpenGLTexture *texture = vtkOpenGLTexture::SafeDownCast(ta->GetTexture());
tunit = texture->GetTextureUnit();
}
cellBO.CachedProgram->Program.SetUniformi("texture1", tunit);
}
......@@ -282,20 +285,31 @@ void vtkOpenGLPolyDataMapper2D::UpdateShader(vtkgl::CellBO &cellBO,
// if depth peeling for trabslucetn compositing
if (ren->GetLastRenderingUsedDepthPeeling() == 2)
{
int ttunit = renWin->GetTextureUnitForTexture(ren->GetTranslucentRGBATexture());
int ttunit = ren->GetTranslucentRGBATextureUnit();
cellBO.CachedProgram->Program.SetUniformi("translucentRGBATexture", ttunit);
int ctunit = renWin->GetTextureUnitForTexture(ren->GetCurrentRGBATexture());
int ctunit = ren->GetCurrentRGBATextureUnit();
cellBO.CachedProgram->Program.SetUniformi("currentRGBATexture", ctunit);
int *renSize = ren->GetSize();
float screenSize[2];
screenSize[0] = renSize[0];
screenSize[1] = renSize[1];
cellBO.CachedProgram->Program.SetUniform2f("screenSize", screenSize);
}
// if depth peeling final compositing
if (ren->GetLastRenderingUsedDepthPeeling() == 3)
{
int ttunit = renWin->GetTextureUnitForTexture(ren->GetTranslucentRGBATexture());
int ttunit = ren->GetTranslucentRGBATextureUnit();
cellBO.CachedProgram->Program.SetUniformi("translucentRGBATexture", ttunit);
int ctunit = renWin->GetTextureUnitForTexture(ren->GetOpaqueRGBATexture());
cellBO.CachedProgram->Program.SetUniformi("currentRGBATexture", ctunit);
}
int ctunit = ren->GetOpaqueRGBATextureUnit();
cellBO.CachedProgram->Program.SetUniformi("opaqueRGBATexture", ctunit);
int *renSize = ren->GetSize();
float screenSize[2];
screenSize[0] = renSize[0];
screenSize[1] = renSize[1];
cellBO.CachedProgram->Program.SetUniform2f("screenSize", screenSize);
}
this->SetPropertyShaderParameters(cellBO, viewport, actor);
......
......@@ -92,39 +92,7 @@ vtkOpenGLRenderWindow::vtkOpenGLRenderWindow()
this->LastGraphicError=static_cast<unsigned int>(GL_NO_ERROR);
#endif
this->DrawPixelsActor = vtkTexturedActor2D::New();
vtkNew<vtkPolyDataMapper2D> mapper;
vtkNew<vtkPolyData> polydata;
vtkNew<vtkPoints> points;
points->SetNumberOfPoints(4);
polydata->SetPoints(points.Get());
vtkNew<vtkCellArray> tris;
tris->InsertNextCell(3);
tris->InsertCellPoint(0);
tris->InsertCellPoint(1);
tris->InsertCellPoint(2);
tris->InsertNextCell(3);
tris->InsertCellPoint(0);
tris->InsertCellPoint(2);
tris->InsertCellPoint(3);
polydata->SetPolys(tris.Get());
vtkNew<vtkTrivialProducer> prod;
prod->SetOutput(polydata.Get());
// Set some properties.
mapper->SetInputConnection(prod->GetOutputPort());
this->DrawPixelsActor->SetMapper(mapper.Get());
vtkNew<vtkTexture> texture;
texture->RepeatOff();
this->DrawPixelsActor->SetTexture(texture.Get());
vtkNew<vtkFloatArray> tcoords;
tcoords->SetNumberOfComponents(2);
tcoords->SetNumberOfTuples(4);
polydata->GetPointData()->SetTCoords(tcoords.Get());
this->DrawPixelsActor = NULL;
this->OwnContext=1;
}
......@@ -692,6 +660,44 @@ void vtkOpenGLRenderWindow::DrawPixels(int x1, int y1, int x2, int y2, int numCo
x_hi = x1;
}
if (this->DrawPixelsActor == NULL)
{
this->DrawPixelsActor = vtkTexturedActor2D::New();
vtkNew<vtkPolyDataMapper2D> mapper;
vtkNew<vtkPolyData> polydata;
vtkNew<vtkPoints> points;
points->SetNumberOfPoints(4);
polydata->SetPoints(points.Get());
vtkNew<vtkCellArray> tris;
tris->InsertNextCell(3);
tris->InsertCellPoint(0);
tris->InsertCellPoint(1);
tris->InsertCellPoint(2);
tris->InsertNextCell(3);
tris->InsertCellPoint(0);
tris->InsertCellPoint(2);
tris->InsertCellPoint(3);
polydata->SetPolys(tris.Get());
vtkNew<vtkTrivialProducer> prod;
prod->SetOutput(polydata.Get());
// Set some properties.
mapper->SetInputConnection(prod->GetOutputPort());
this->DrawPixelsActor->SetMapper(mapper.Get());
vtkNew<vtkTexture> texture;
texture->RepeatOff();
this->DrawPixelsActor->SetTexture(texture.Get());
vtkNew<vtkFloatArray> tcoords;
tcoords->SetNumberOfComponents(2);
tcoords->SetNumberOfTuples(4);
polydata->GetPointData()->SetTCoords(tcoords.Get());
}
vtkPolyData *pd = vtkPolyDataMapper2D::SafeDownCast(this->DrawPixelsActor->GetMapper())->GetInput();
vtkPoints *points = pd->GetPoints();
points->SetPoint(0, x_low, y_low, 0);
......@@ -1496,10 +1502,10 @@ int vtkOpenGLRenderWindow::SetZbufferData( int x1, int y1, int x2, int y2,
}
void vtkOpenGLRenderWindow::ActivateTexture(vtkTexture *texture)
void vtkOpenGLRenderWindow::ActivateTexture(vtkTextureObject *texture)
{
// Only add if it isn't already there
typedef std::map<const vtkTexture *, int>::const_iterator TRIter;
typedef std::map<const vtkTextureObject *, int>::const_iterator TRIter;
TRIter found = this->TextureResourceIds.find(texture);
if (found == this->TextureResourceIds.end())
{
......@@ -1518,10 +1524,10 @@ void vtkOpenGLRenderWindow::ActivateTexture(vtkTexture *texture)
}
}
void vtkOpenGLRenderWindow::DeactivateTexture(vtkTexture *texture)
void vtkOpenGLRenderWindow::DeactivateTexture(vtkTextureObject *texture)
{
// Only deactivate if it isn't already there
typedef std::map<const vtkTexture *, int>::iterator TRIter;
typedef std::map<const vtkTextureObject *, int>::iterator TRIter;
TRIter found = this->TextureResourceIds.find(texture);
if (found != this->TextureResourceIds.end())
{
......@@ -1530,10 +1536,10 @@ void vtkOpenGLRenderWindow::DeactivateTexture(vtkTexture *texture)
}
}
int vtkOpenGLRenderWindow::GetTextureUnitForTexture(vtkTexture *texture)
int vtkOpenGLRenderWindow::GetTextureUnitForTexture(vtkTextureObject *texture)
{
// Only deactivate if it isn't already there
typedef std::map<const vtkTexture *, int>::const_iterator TRIter;
typedef std::map<const vtkTextureObject *, int>::const_iterator TRIter;
TRIter found = this->TextureResourceIds.find(texture);
if (found != this->TextureResourceIds.end())
{
......
......@@ -33,8 +33,9 @@ class vtkOpenGLHardwareSupport;
class vtkOpenGLTextureUnitManager;
class vtkOpenGLShaderCache;
class vtkStdString;
class vtkTexturedActor2D;
class vtkTexture;
class vtkTexturedActor2D;
class vtkTextureObject;
class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderWindow : public vtkRenderWindow
{
......@@ -92,17 +93,18 @@ public:
virtual int SetZbufferData( int x1, int y1, int x2, int y2,
vtkFloatArray *buffer );
// Description:
// Activate a texture unit for this texture
void ActivateTexture(vtkTexture *);
void ActivateTexture(vtkTextureObject *);
// Description:
// Deactive a previously activated texture
void DeactivateTexture(vtkTexture *);
void DeactivateTexture(vtkTextureObject *);
// Description:
// Get the texture unit for a given texture object
int GetTextureUnitForTexture(vtkTexture *);
int GetTextureUnitForTexture(vtkTextureObject *);
// Description:
// Get the size of the depth buffer.
......@@ -207,7 +209,7 @@ protected:
long OldMonitorSetting;
//BTX
std::map<const vtkTexture *, int> TextureResourceIds;
std::map<const vtkTextureObject *, int> TextureResourceIds;
//ETX
int GetPixelData(int x, int y, int x2, int y2, int front, unsigned char* data);
......
......@@ -196,6 +196,28 @@ vtkOpenGLTexture *vtkOpenGLRendererCreateDepthPeelingTexture(
return result;
}
// get the texture units for depth peeling
int vtkOpenGLRenderer::GetOpaqueRGBATextureUnit()
{
return vtkOpenGLRenderWindow::SafeDownCast(this->RenderWindow)->GetTextureUnitForTexture(this->OpaqueRGBATexture->GetTextureObject());
}
int vtkOpenGLRenderer::GetOpaqueZTextureUnit()
{
return vtkOpenGLRenderWindow::SafeDownCast(this->RenderWindow)->GetTextureUnitForTexture(this->OpaqueZTexture->GetTextureObject());
}
int vtkOpenGLRenderer::GetTranslucentRGBATextureUnit()
{
return vtkOpenGLRenderWindow::SafeDownCast(this->RenderWindow)->GetTextureUnitForTexture(this->TranslucentRGBATexture->GetTextureObject());
}
int vtkOpenGLRenderer::GetTranslucentZTextureUnit()
{
return vtkOpenGLRenderWindow::SafeDownCast(this->RenderWindow)->GetTextureUnitForTexture(this->TranslucentZTexture->GetTextureObject());
}
int vtkOpenGLRenderer::GetCurrentRGBATextureUnit()
{
return vtkOpenGLRenderWindow::SafeDownCast(this->RenderWindow)->GetTextureUnitForTexture(this->CurrentRGBATexture->GetTextureObject());
}
// ----------------------------------------------------------------------------
// Description:
// Render translucent polygonal geometry. Default implementation just call
......@@ -314,8 +336,8 @@ void vtkOpenGLRenderer::DeviceRenderTranslucentPolygonalGeometry()
}
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClearColor(0.0,0.0,0.0,0.0); // always clear to black
//glClearDepth(static_cast<GLclampf>(1.0));
// glClearColor(0.0,0.0,0.0,0.0); // always clear to black
// glClearDepth(static_cast<GLclampf>(1.0));
#ifdef GL_MULTISAMPLE
glDisable(GL_MULTISAMPLE);
#endif
......@@ -323,11 +345,11 @@ void vtkOpenGLRenderer::DeviceRenderTranslucentPolygonalGeometry()
// Get opaqueRGBA
this->OpaqueRGBATexture->Load(this);
this->OpaqueRGBATexture->CopyTexImage(this, this->ViewportX, this->ViewportY, this->ViewportWidth, this->ViewportHeight);
this->OpaqueRGBATexture->CopyTexImage(this->ViewportX, this->ViewportY, this->ViewportWidth, this->ViewportHeight);
// Get opaqueZ
this->OpaqueZTexture->Load(this);
this->OpaqueZTexture->CopyTexImage(this, this->ViewportX, this->ViewportY, this->ViewportWidth, this->ViewportHeight);
this->OpaqueZTexture->CopyTexImage(this->ViewportX, this->ViewportY, this->ViewportWidth, this->ViewportHeight);
// Initialize TranslucentZ to 0.0
vtkImageData *id = this->TranslucentZTexture->GetImageDataInput(0);
......@@ -359,6 +381,8 @@ void vtkOpenGLRenderer::DeviceRenderTranslucentPolygonalGeometry()
{
// clear the zbuffer and color buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
this->OpaqueZTexture->Load(this);
this->TranslucentZTexture->Load(this);
// render the translucent geometry
this->LastRenderingUsedDepthPeeling=1;
......@@ -368,7 +392,7 @@ void vtkOpenGLRenderer::DeviceRenderTranslucentPolygonalGeometry()
this->UpdateTranslucentPolygonalGeometry();
// update translucentZ
this->TranslucentZTexture->CopyTexImage(this, this->ViewportX, this->ViewportY, this->ViewportWidth, this->ViewportHeight);
this->TranslucentZTexture->CopyTexImage(this->ViewportX, this->ViewportY, this->ViewportWidth, this->ViewportHeight);
previousNbPixels = nbPixels;
#if GL_ES_VERSION_2_0 != 1
......@@ -389,19 +413,23 @@ void vtkOpenGLRenderer::DeviceRenderTranslucentPolygonalGeometry()
// blend the last two peels together
if (peelCount > 1)
{
this->CurrentRGBATexture->CopyTexImage(this, this->ViewportX, this->ViewportY, this->ViewportWidth, this->ViewportHeight);
this->CurrentRGBATexture->CopyTexImage(this->ViewportX, this->ViewportY, this->ViewportWidth, this->ViewportHeight);
this->TranslucentRGBATexture->Load(this);
this->CurrentRGBATexture->Load(this);
this->LastRenderingUsedDepthPeeling = 2;
// draw a full screen polygon that takes the TranslucentRGBA texture and blends it with the current frame buffer
this->DepthPeelingActor->RenderOverlay(this);
}
// update translucent RGBA
this->TranslucentRGBATexture->CopyTexImage(this, this->ViewportX, this->ViewportY, this->ViewportWidth, this->ViewportHeight);
this->TranslucentRGBATexture->CopyTexImage(this->ViewportX, this->ViewportY, this->ViewportWidth, this->ViewportHeight);
}
// blend in OpaqueRGBA
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
this->LastRenderingUsedDepthPeeling = 3;
this->OpaqueRGBATexture->Load(this);
this->TranslucentRGBATexture->Load(this);
this->DepthPeelingActor->RenderOverlay(this);
// unload the textures
......
......@@ -65,13 +65,13 @@ public:
vtkGetObjectMacro(Pass, vtkRenderPass);
// Description:
// get the various textures used for Depth Peeling
// get the various texture units used for Depth Peeling
// the Mappers make use of these
vtkGetObjectMacro(OpaqueZTexture,vtkOpenGLTexture);
vtkGetObjectMacro(OpaqueRGBATexture,vtkOpenGLTexture);
vtkGetObjectMacro(TranslucentZTexture,vtkOpenGLTexture);
vtkGetObjectMacro(TranslucentRGBATexture,vtkOpenGLTexture);
vtkGetObjectMacro(CurrentRGBATexture,vtkOpenGLTexture);
int GetOpaqueRGBATextureUnit();
int GetOpaqueZTextureUnit();
int GetTranslucentRGBATextureUnit();
int GetTranslucentZTextureUnit();
int GetCurrentRGBATextureUnit();
protected:
vtkOpenGLRenderer();
......
......@@ -13,6 +13,7 @@
=========================================================================*/
#include "vtkOpenGLTexture.h"
#include "vtkTextureObject.h"
#include "vtkglVBOHelper.h"
......@@ -34,13 +35,16 @@
// ----------------------------------------------------------------------------
vtkStandardNewMacro(vtkOpenGLTexture);
vtkCxxSetObjectMacro(vtkOpenGLTexture,TextureObject,vtkTextureObject)
// ----------------------------------------------------------------------------
vtkOpenGLTexture::vtkOpenGLTexture()
{
this->Index = 0;
this->RenderWindow = 0;
this->IsDepthTexture = 0;
this->TextureType = GL_TEXTURE_2D;
this->TextureObject = 0;
}
// ----------------------------------------------------------------------------
......@@ -51,63 +55,43 @@ vtkOpenGLTexture::~vtkOpenGLTexture()
this->ReleaseGraphicsResources(this->RenderWindow);
this->RenderWindow = 0;
}
}
// ----------------------------------------------------------------------------
void vtkOpenGLTexture::Initialize(vtkRenderer* vtkNotUsed(ren))
{
if (this->TextureObject)
{
this->TextureObject->Delete();
this->TextureObject = NULL;
}
}
// ----------------------------------------------------------------------------
// Release the graphics resources used by this texture.
void vtkOpenGLTexture::ReleaseGraphicsResources(vtkWindow *win)
{
if (this->Index && win && win->GetMapped())
if (this->TextureObject && win && win->GetMapped())
{
vtkRenderWindow *renWin = dynamic_cast<vtkRenderWindow *>(win);
renWin->MakeCurrent();
vtkOpenGLClearErrorMacro();
// free any textures
if (glIsTexture(static_cast<GLuint>(this->Index)))
{
GLuint tempIndex;
tempIndex = this->Index;