Commit d4326fa1 authored by Ken Martin's avatar Ken Martin Committed by Code Review

Merge topic 'volume_geometry_fixes' into master

746fbdd7 Added second baseline to fix failing test on some systems
5948b78d Attempt to fix failing test by removing calls to interactor
4ef33909 Let shader cache invoke release graphics resources on shader
e3eb4735 Removed unnecessary call and added notes
652d7369 ShaderCache should release its graphics resources
454e0db7 Fixed volume tests failing because of shader cache
f1826bea Using render window shader cache
c5e5788d Added error checks for volume render calls
0c38ee5c Updated volume rendering to use shader cache
7bd46535 Updated API to force use of vtkShaderCache
parents 8cf5d8ac 746fbdd7
......@@ -15,7 +15,6 @@
#include "vtkCamera.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkActor.h"
#include "vtkCellArray.h"
#include "vtkPointData.h"
......@@ -46,8 +45,6 @@ int TestVBOPLYMapper(int argc, char *argv[])
const char* fileName = vtkTestUtilities::ExpandDataFileName(argc, argv,
"Data/dragon.ply");
//const char* fileName = "C:\\Users\\ken.martin\\Documents\\vtk\\VTKData\\Data\\lucy.ply";
vtkNew<vtkPLYReader> reader;
reader->SetFileName(fileName);
reader->Update();
......@@ -69,8 +66,6 @@ int TestVBOPLYMapper(int argc, char *argv[])
actor->GetProperty()->SetOpacity(1.0);
//actor->GetProperty()->SetRepresentationToWireframe();
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(renderWindow.Get());
renderWindow->SetMultiSamples(0);
vtkNew<vtkTimerLog> timer;
......@@ -102,10 +97,7 @@ int TestVBOPLYMapper(int argc, char *argv[])
renderer->ResetCamera();
renderWindow->SetSize(300, 300);
interactor->Start();
//delete [] fileName;
renderWindow->Render();
return EXIT_SUCCESS;
}
......@@ -125,4 +125,4 @@ void vtkOpenGLActor::GetKeyMatrices(vtkMatrix4x4 *&mcwc, vtkMatrix3x3 *&normMat)
mcwc = this->MCWCMatrix;
normMat = this->NormalMatrix;
}
\ No newline at end of file
}
......@@ -202,9 +202,24 @@ vtkShaderProgram *vtkOpenGLShaderCache::GetShader(
}
}
void vtkOpenGLShaderCache::ReleaseGraphicsResources(vtkWindow *vtkNotUsed(win))
void vtkOpenGLShaderCache::ReleaseGraphicsResources(vtkWindow *win)
{
// NOTE:
// In the current implementation as of October 26th, if a shader
// program is created by ShaderCache then it should make sure
// that it releases the graphics resouces used by these programs.
// It is not wisely for callers to do that since then they would
// have to loop over all the programs were in use and invoke
// release graphics resources individually.
this->LastShaderBound = NULL;
typedef std::map<std::string,vtkShaderProgram*>::const_iterator SMapIter;
SMapIter iter = this->Internal->ShaderPrograms.begin();
for ( ; iter != this->Internal->ShaderPrograms.end(); iter++)
{
iter->second->ReleaseGraphicsResources(win);
}
}
......
......@@ -61,10 +61,6 @@ public:
vtkSetMacro(Compiled, bool);
vtkBooleanMacro(Compiled, bool);
// Description:
// Compile this shader program and attached shaders
virtual int CompileShader();
// Description:
// Set/Get the md5 hash of this program
std::string GetMD5Hash() const { return this->MD5Hash; }
......@@ -87,43 +83,12 @@ public:
};
/**
* Attach the supplied shader to this program.
* @note A maximum of one Vertex shader and one Fragment shader can be
* attached to a shader program.
* @return true on success.
*/
bool AttachShader(const vtkShader *shader);
/** Detach the supplied shader from this program.
* @note A maximum of one Vertex shader and one Fragment shader can be
* attached to a shader program.
* @return true on success.
*/
bool DetachShader(const vtkShader *shader);
/**
* Attempt to link the shader program.
* @return false on failure. Query error to get the reason.
* @note The shaders attached to the program must have been compiled.
*/
bool Link();
/**
* Bind the program in order to use it. If the program has not been linked
* then link() will be called.
*/
bool Bind();
/**
* Check if the program is currently bound, or not.
* @return True if the program is bound, false otherwise.
*/
bool isBound() const { return this->Bound; }
/** Releases the shader program from the current context. */
void Release();
// Description:
// release any graphics resources this class is using.
void ReleaseGraphicsResources(vtkWindow *win);
......@@ -211,6 +176,51 @@ protected:
vtkShaderProgram();
~vtkShaderProgram();
/***************************************************************
* The following functions are only for use by the shader cache
* which is why they are protected and that class is a friend
* you need to use the shader cache to compile/link/bind your shader
* do not try to do it yourself as it will screw up the cache
***************************************************************/
friend class vtkOpenGLShaderCache;
/**
* Attach the supplied shader to this program.
* @note A maximum of one Vertex shader and one Fragment shader can be
* attached to a shader program.
* @return true on success.
*/
bool AttachShader(const vtkShader *shader);
/** Detach the supplied shader from this program.
* @note A maximum of one Vertex shader and one Fragment shader can be
* attached to a shader program.
* @return true on success.
*/
bool DetachShader(const vtkShader *shader);
// Description:
// Compile this shader program and attached shaders
virtual int CompileShader();
/**
* Attempt to link the shader program.
* @return false on failure. Query error to get the reason.
* @note The shaders attached to the program must have been compiled.
*/
bool Link();
/**
* Bind the program in order to use it. If the program has not been linked
* then link() will be called.
*/
bool Bind();
/** Releases the shader program from the current context. */
void Release();
/************* end **************************************/
vtkShader *VertexShader;
vtkShader *FragmentShader;
vtkShader *GeometryShader;
......
......@@ -544,11 +544,12 @@ void CreateCellSupportArrays(vtkPolyData *poly, vtkCellArray *prims[4],
void CellBO::ReleaseGraphicsResources(vtkWindow *win)
void CellBO::ReleaseGraphicsResources(vtkWindow * vtkNotUsed(win))
{
if (this->Program)
{
this->Program->ReleaseGraphicsResources(win);
// Let ShaderCache release the graphics resources as it is
// responsible for creation and deletion.
this->Program = 0;
}
this->ibo.ReleaseGraphicsResources();
......@@ -557,4 +558,4 @@ void CellBO::ReleaseGraphicsResources(vtkWindow *win)
this->elementsArray.clear();
}
}
\ No newline at end of file
}
......@@ -41,6 +41,9 @@
#include <vtkMatrix4x4.h>
#include <vtkNew.h>
#include <vtkObjectFactory.h>
#include <vtkOpenGLError.h>
#include <vtkOpenGLShaderCache.h>
#include <vtkOpenGLRenderWindow.h>
#include <vtkPerlinNoise.h>
#include <vtkPlaneCollection.h>
#include <vtkPointData.h>
......@@ -57,6 +60,7 @@
#include <vtkUnsignedIntArray.h>
#include <vtkVolumeMask.h>
#include <vtkVolumeProperty.h>
#include <vtkWeakPointer.h>
// C/C++ includes
#include <cassert>
......@@ -302,7 +306,8 @@ public:
vtkImageData* PrevInput;
vtkNew<vtkShaderProgram> ShaderProgram;
vtkShaderProgram* ShaderProgram;
vtkOpenGLShaderCache* ShaderCache;
};
//----------------------------------------------------------------------------
......@@ -1688,10 +1693,8 @@ void vtkOpenGLGPUVolumeRayCastMapper::BuildShader(vtkRenderer* ren,
this->Impl->CurrentMask,
this->MaskType), true);
this->Impl->ShaderProgram->GetVertexShader()->SetSource(vertexShader);
this->Impl->ShaderProgram->GetFragmentShader()->SetSource(fragmentShader);
this->Impl->ShaderProgram->CompileShader();
this->Impl->ShaderProgram = this->Impl->ShaderCache->ReadyShader(
vertexShader.c_str(), fragmentShader.c_str(), "");
if (!this->Impl->ShaderProgram->GetCompiled())
{
vtkErrorMacro("Shader failed to compile");
......@@ -1704,6 +1707,8 @@ void vtkOpenGLGPUVolumeRayCastMapper::BuildShader(vtkRenderer* ren,
void vtkOpenGLGPUVolumeRayCastMapper::GPURender(vtkRenderer* ren,
vtkVolume* vol)
{
vtkOpenGLClearErrorMacro();
// Make sure the context is current
ren->GetRenderWindow()->MakeCurrent();
......@@ -1787,7 +1792,22 @@ void vtkOpenGLGPUVolumeRayCastMapper::GPURender(vtkRenderer* ren,
this->Impl->UpdateSamplingDistance(input, ren, vol);
// Build shader
// Build shader now
// First get the shader cache from the render window. This is important
// to make sure that shader cache knows the state of various shader programs
// in use.
vtkOpenGLRenderWindow* renWin =
vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow());
this->Impl->ShaderCache = renWin->GetShaderCache();
// Use the shader program now. Clear the last one
// if it is not the same as ours.
if (this->Impl->ShaderCache->GetLastShaderBound() !=
this->Impl->ShaderProgram)
{
this->Impl->ShaderCache->ClearLastShaderBound();
}
if (vol->GetProperty()->GetMTime() >
this->Impl->ShaderBuildTime.GetMTime() ||
this->GetMTime() > this->Impl->ShaderBuildTime.GetMTime() ||
......@@ -1800,9 +1820,12 @@ void vtkOpenGLGPUVolumeRayCastMapper::GPURender(vtkRenderer* ren,
this->BuildShader(ren, vol, numberOfScalarComponents);
}
// Now use the shader
this->Impl->ShaderProgram->Bind();
// Bind the shader
this->Impl->ShaderCache->ReadyShader(
this->Impl->ShaderProgram);
// And now update the geometry that will be used
// to render the 3D texture
this->Impl->UpdateVolumeGeometry(ren, vol, input);
// Update opacity transfer function
......@@ -1877,7 +1900,6 @@ void vtkOpenGLGPUVolumeRayCastMapper::GPURender(vtkRenderer* ren,
this->Impl->ShaderProgram->SetUniformf("m_sample_distance",
this->Impl->ActualSampleDistance);
vtkInternal::ToFloat(this->Impl->ScalarsRange, fvalue2);
this->Impl->ShaderProgram->SetUniform2fv("m_scalars_range", 1, &fvalue2);
......@@ -2080,7 +2102,7 @@ void vtkOpenGLGPUVolumeRayCastMapper::GPURender(vtkRenderer* ren,
this->Impl->BBoxPolyData->GetNumberOfCells() * 3,
GL_UNSIGNED_INT, 0);
this->Impl->ShaderProgram->Release();
this->Impl->PrevInput = input;
vtkOpenGLCheckErrorMacro("failed after Render");
}
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