Commit 2b37b7fe authored by Ken Martin's avatar Ken Martin Committed by Kitware Robot

Merge topic 'more_edge_fixes'

63a993a7 Suppress warning in system file
04a92914 Warning fix for win32
27762850 Keep track of what shader uniforms were being used in the shader
67c0a8a8 Fixes related to surface with edges
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Tested-by: Utkarsh Ayachit's avatarUtkarsh Ayachit <utkarsh.ayachit@kitware.com>
Merge-request: !643
parents 97cc8760 63a993a7
......@@ -17,6 +17,12 @@
#include "vtkObjectFactory.h"
#include "vtkWindows.h"
#pragma warning(push)
#pragma warning(disable:4091)
#include "DbgHelp.h"
#pragma warning(pop)
#pragma comment(lib, "Dbghelp.lib")
vtkStandardNewMacro(vtkWin32OutputWindow);
HWND vtkWin32OutputWindowOutputWindow = 0;
......@@ -339,3 +345,35 @@ void vtkWin32OutputWindow::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "SendToStdErr: " << this->SendToStdErr << "\n";
}
// super useful function to have sometimes
void vtkWin32OutputWindow::PrintStack( void )
{
unsigned int i;
void * stack[ 100 ];
unsigned short frames;
SYMBOL_INFO * symbol;
HANDLE process;
DWORD dwDisplacement;
IMAGEHLP_LINE64 line;
process = GetCurrentProcess();
SymSetOptions(SYMOPT_LOAD_LINES);
SymInitialize( process, NULL, TRUE );
frames = CaptureStackBackTrace( 0, 30, stack, NULL );
symbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 );
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof( SYMBOL_INFO );
for( i = 0; i < frames; i++ )
{
SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol );
SymGetLineFromAddr64(process, (DWORD64)stack[i], &dwDisplacement, &line);
printf( "%i: %s at line %d\n",
frames - i - 1, symbol->Name, line.LineNumber );
}
free( symbol );
}
......@@ -51,6 +51,9 @@ public:
vtkSetMacro(SendToStdErr, bool);
vtkBooleanMacro(SendToStdErr, bool);
// print a stack trace
static void PrintStack();
protected:
vtkWin32OutputWindow();
virtual ~vtkWin32OutputWindow();
......
......@@ -2508,8 +2508,6 @@ void vtkSurfaceLICMapper::ReplaceShaderValues(
// " gl_FragData[2] = vec4(19.0, 19.0, tcoordVC.x, gl_FragCoord.z);\n"
, false);
this->ShaderVariablesUsed.push_back("normalMatrix");
shaders[vtkShader::Vertex]->SetSource(VSSource);
shaders[vtkShader::Fragment]->SetSource(FSSource);
......
......@@ -94,7 +94,7 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderPositionVC(
{
std::string VSSource = shaders[vtkShader::Vertex]->GetSource();
if (this->LastLightComplexity > 0)
if (this->LastLightComplexity[this->LastBoundBO] > 0)
{
// we use vertex instead of vertexMC
vtkShaderProgram::Substitute(VSSource,
......@@ -154,7 +154,7 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderColor(
"uniform vec3 diffuseColorUniformBF; // intensity weighted color\n";
}
// add more for specular
if (this->LastLightComplexity)
if (this->LastLightComplexity[this->LastBoundBO])
{
colorDec +=
"uniform vec3 specularColorUniform; // intensity weighted color\n"
......@@ -176,7 +176,7 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderColor(
"vec3 ambientColor;\n"
" vec3 diffuseColor;\n"
" float opacity;\n";
if (this->LastLightComplexity)
if (this->LastLightComplexity[this->LastBoundBO])
{
colorImpl +=
" vec3 specularColor;\n"
......@@ -184,7 +184,7 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderColor(
}
if (actor->GetBackfaceProperty())
{
if (this->LastLightComplexity)
if (this->LastLightComplexity[this->LastBoundBO])
{
colorImpl +=
" if (int(gl_FrontFacing) == 0) {\n"
......@@ -219,7 +219,7 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderColor(
" ambientColor = ambientColorUniform;\n"
" diffuseColor = diffuseColorUniform;\n"
" opacity = opacityUniform;\n";
if (this->LastLightComplexity)
if (this->LastLightComplexity[this->LastBoundBO])
{
colorImpl +=
" specularColor = specularColorUniform;\n"
......@@ -307,7 +307,6 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderNormal(
}
vtkShaderProgram::Substitute(VSSource, "//VTK::Normal::Impl",
"normalVCVSOutput = normalMatrix * glyphNormalMatrix * normalMC;");
this->ShaderVariablesUsed.push_back("normalMatrix");
}
shaders[vtkShader::Vertex]->SetSource(VSSource);
......@@ -404,7 +403,7 @@ void vtkOpenGLGlyph3DHelper::GlyphRender(
program->SetUniformMatrix4x4("GCMCMatrix", &(matrices[inPtId*16]));
// for lit shaders set normal matrix
if (this->LastLightComplexity > 0 && this->VBO->NormalOffset &&
if (this->LastLightComplexity[this->LastBoundBO] > 0 && this->VBO->NormalOffset &&
!this->UsingInstancing)
{
program->SetUniformMatrix3x3("glyphNormalMatrix", &(normalMatrices[inPtId*9]));
......@@ -469,7 +468,7 @@ void vtkOpenGLGlyph3DHelper::SetCameraShaderParameters(vtkOpenGLHelper &cellBO,
}
// for lit shaders set normal matrix
if (this->LastLightComplexity > 0 && this->ModelNormalMatrix &&
if (this->LastLightComplexity[&cellBO] > 0 && this->ModelNormalMatrix &&
this->VBO->NormalOffset && !this->UsingInstancing)
{
program->SetUniformMatrix3x3("glyphNormalMatrix", this->ModelNormalMatrix);
......@@ -532,7 +531,7 @@ void vtkOpenGLGlyph3DHelper::GlyphRenderInstances(
}
this->MatrixBuffer->Release();
if (this->VBO->NormalOffset && this->LastLightComplexity > 0)
if (this->VBO->NormalOffset && this->LastLightComplexity[this->LastBoundBO] > 0)
{
this->NormalMatrixBuffer->Bind();
this->NormalMatrixBuffer->Upload(
......
......@@ -203,7 +203,7 @@ void vtkOpenGLPointGaussianMapperHelper::ReplaceShaderColor(
bool vtkOpenGLPointGaussianMapperHelper::GetNeedToRebuildShaders(
vtkOpenGLHelper &cellBO, vtkRenderer* ren, vtkActor *actor)
{
this->LastLightComplexity = 0;
this->LastLightComplexity[&cellBO] = 0;
vtkHardwareSelector* selector = ren->GetSelector();
int picking = selector ? selector->GetCurrentPass() : -1;
......@@ -223,8 +223,7 @@ bool vtkOpenGLPointGaussianMapperHelper::GetNeedToRebuildShaders(
cellBO.ShaderSourceTime < actor->GetMTime() ||
cellBO.ShaderSourceTime < this->CurrentInput->GetMTime() ||
cellBO.ShaderSourceTime < this->SelectionStateChanged ||
cellBO.ShaderSourceTime < this->DepthPeelingChanged ||
cellBO.ShaderSourceTime < this->LightComplexityChanged)
cellBO.ShaderSourceTime < this->DepthPeelingChanged)
{
return true;
}
......
......@@ -70,7 +70,6 @@ vtkOpenGLPolyDataMapper::vtkOpenGLPolyDataMapper()
{
this->InternalColorTexture = 0;
this->PopulateSelectionSettings = 1;
this->LastLightComplexity = -1;
this->LastSelectionState = vtkHardwareSelector::MIN_KNOWN_PASS - 1;
this->LastDepthPeeling = 0;
this->CurrentInput = 0;
......@@ -101,6 +100,13 @@ vtkOpenGLPolyDataMapper::vtkOpenGLPolyDataMapper()
this->VertexShaderCode = 0;
this->FragmentShaderCode = 0;
this->GeometryShaderCode = 0;
this->LastLightComplexity[&this->Points] = -1;
this->LastLightComplexity[&this->Lines] = -1;
this->LastLightComplexity[&this->Tris] = -1;
this->LastLightComplexity[&this->TriStrips] = -1;
this->LastLightComplexity[&this->TrisEdges] = -1;
this->LastLightComplexity[&this->TriStripsEdges] = -1;
}
......@@ -192,12 +198,6 @@ void vtkOpenGLPolyDataMapper::ReleaseGraphicsResources(vtkWindow* win)
this->Modified();
}
bool vtkOpenGLPolyDataMapper::IsShaderVariableUsed(const char *name)
{
return std::binary_search(this->ShaderVariablesUsed.begin(),
this->ShaderVariablesUsed.end(), name);
}
void vtkOpenGLPolyDataMapper::AddShaderReplacement(
vtkShader::Type shaderType, // vertex, fragment, etc
std::string originalValue,
......@@ -241,7 +241,6 @@ void vtkOpenGLPolyDataMapper::BuildShaders(
std::map<vtkShader::Type, vtkShader *> shaders,
vtkRenderer *ren, vtkActor *actor)
{
this->ShaderVariablesUsed.clear();
this->GetShaderTemplate(shaders, ren, actor);
typedef std::map<const vtkOpenGLPolyDataMapper::ReplacementSpec,
......@@ -278,8 +277,6 @@ void vtkOpenGLPolyDataMapper::BuildShaders(
shaders[i->first.ShaderType]->SetSource(ssrc);
}
}
std::sort(this->ShaderVariablesUsed.begin(),this->ShaderVariablesUsed.end());
}
bool vtkOpenGLPolyDataMapper::HaveWideLines(
......@@ -368,7 +365,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderColor(
"uniform vec3 diffuseColorUniformBF; // intensity weighted color\n";
}
// add more for specular
if (this->LastLightComplexity)
if (this->LastLightComplexity[this->LastBoundBO])
{
colorDec +=
"uniform vec3 specularColorUniform; // intensity weighted color\n"
......@@ -381,7 +378,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderColor(
}
}
// add scalar vertex coloring
if (this->VBO->ColorComponents != 0)
if (this->VBO->ColorComponents != 0 && !this->DrawingEdges)
{
colorDec += "varying vec4 vertexColorVSOutput;\n";
vtkShaderProgram::Substitute(VSSource,"//VTK::Color::Dec",
......@@ -411,7 +408,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderColor(
"vec3 ambientColor;\n"
" vec3 diffuseColor;\n"
" float opacity;\n";
if (this->LastLightComplexity)
if (this->LastLightComplexity[this->LastBoundBO])
{
colorImpl +=
" vec3 specularColor;\n"
......@@ -419,7 +416,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderColor(
}
if (actor->GetBackfaceProperty())
{
if (this->LastLightComplexity)
if (this->LastLightComplexity[this->LastBoundBO])
{
colorImpl +=
" if (int(gl_FrontFacing) == 0) {\n"
......@@ -454,7 +451,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderColor(
" ambientColor = ambientColorUniform;\n"
" diffuseColor = diffuseColorUniform;\n"
" opacity = opacityUniform;\n";
if (this->LastLightComplexity)
if (this->LastLightComplexity[this->LastBoundBO])
{
colorImpl +=
" specularColor = specularColorUniform;\n"
......@@ -463,7 +460,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderColor(
}
// now handle scalar coloring
if (this->VBO->ColorComponents != 0)
if (this->VBO->ColorComponents != 0 && !this->DrawingEdges)
{
if (this->ScalarMaterialMode == VTK_MATERIALMODE_AMBIENT ||
(this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT &&
......@@ -493,7 +490,9 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderColor(
else
{
// are we doing scalar coloring by texture?
if (this->InterpolateScalarsBeforeMapping && this->ColorCoordinates)
if (this->InterpolateScalarsBeforeMapping &&
this->ColorCoordinates &&
!this->DrawingEdges)
{
if (this->ScalarMaterialMode == VTK_MATERIALMODE_AMBIENT ||
(this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT &&
......@@ -655,7 +654,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderLight(
shadowFactor = "*factors[lightNum]";
}
switch (this->LastLightComplexity)
switch (this->LastLightComplexity[this->LastBoundBO])
{
case 0: // no lighting
vtkShaderProgram::Substitute(FSSource,"//VTK::Light::Impl",
......@@ -772,6 +771,11 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderTCoord(
std::map<vtkShader::Type, vtkShader *> shaders,
vtkRenderer *, vtkActor *actor)
{
if (this->DrawingEdges)
{
return;
}
std::string VSSource = shaders[vtkShader::Vertex]->GetSource();
std::string GSSource = shaders[vtkShader::Geometry]->GetSource();
std::string FSSource = shaders[vtkShader::Fragment]->GetSource();
......@@ -1012,7 +1016,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderNormal(
std::map<vtkShader::Type, vtkShader *> shaders,
vtkRenderer *, vtkActor *actor)
{
if (this->LastLightComplexity > 0)
if (this->LastLightComplexity[this->LastBoundBO] > 0)
{
std::string VSSource = shaders[vtkShader::Vertex]->GetSource();
std::string GSSource = shaders[vtkShader::Geometry]->GetSource();
......@@ -1020,14 +1024,11 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderNormal(
if (this->VBO->NormalOffset)
{
if (vtkShaderProgram::Substitute(VSSource,
vtkShaderProgram::Substitute(VSSource,
"//VTK::Normal::Dec",
"attribute vec3 normalMC;\n"
"uniform mat3 normalMatrix;\n"
"varying vec3 normalVCVSOutput;"))
{
this->ShaderVariablesUsed.push_back("normalMatrix");
}
"varying vec3 normalVCVSOutput;");
vtkShaderProgram::Substitute(VSSource,
"//VTK::Normal::Impl",
"normalVCVSOutput = normalMatrix * normalMC;");
......@@ -1054,13 +1055,10 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderNormal(
{
if (this->HaveCellNormals)
{
if (vtkShaderProgram::Substitute(FSSource,
"//VTK::Normal::Dec",
"uniform mat3 normalMatrix;\n"
"uniform samplerBuffer textureN;\n"))
{
this->ShaderVariablesUsed.push_back("normalMatrix");
}
vtkShaderProgram::Substitute(FSSource,
"//VTK::Normal::Dec",
"uniform mat3 normalMatrix;\n"
"uniform samplerBuffer textureN;\n");
vtkShaderProgram::Substitute(FSSource,
"//VTK::Normal::Impl",
"vec3 normalVCVSOutput = normalize(normalMatrix *\n"
......@@ -1106,7 +1104,6 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderNormal(
vtkShaderProgram::Substitute(FSSource,
"//VTK::Normal::Dec",
"uniform int cameraParallel;");
this->ShaderVariablesUsed.push_back("cameraParallel");
vtkShaderProgram::Substitute(FSSource,"//VTK::Normal::Impl",
"vec3 fdx = normalize(vec3(dFdx(vertexVC.x),dFdx(vertexVC.y),dFdx(vertexVC.z)));\n"
......@@ -1136,7 +1133,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderPositionVC(
std::string FSSource = shaders[vtkShader::Fragment]->GetSource();
// do we need the vertex in the shader in View Coordinates
if (this->LastLightComplexity > 0)
if (this->LastLightComplexity[this->LastBoundBO] > 0)
{
vtkShaderProgram::Substitute(VSSource,
"//VTK::PositionVC::Dec",
......@@ -1145,13 +1142,10 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderPositionVC(
"//VTK::PositionVC::Impl",
"vertexVCVSOutput = MCVCMatrix * vertexMC;\n"
" gl_Position = MCDCMatrix * vertexMC;\n");
if (vtkShaderProgram::Substitute(VSSource,
"//VTK::Camera::Dec",
"uniform mat4 MCDCMatrix;\n"
"uniform mat4 MCVCMatrix;"))
{
this->ShaderVariablesUsed.push_back("MCVCMatrix");
}
vtkShaderProgram::Substitute(VSSource,
"//VTK::Camera::Dec",
"uniform mat4 MCDCMatrix;\n"
"uniform mat4 MCVCMatrix;");
vtkShaderProgram::Substitute(GSSource,
"//VTK::PositionVC::Dec",
"in vec4 vertexVCVSOutput[];\n"
......@@ -1304,10 +1298,10 @@ bool vtkOpenGLPolyDataMapper::GetNeedToRebuildShaders(
}
}
if (this->LastLightComplexity != lightComplexity)
if (this->LastLightComplexity[&cellBO] != lightComplexity)
{
this->LightComplexityChanged.Modified();
this->LastLightComplexity = lightComplexity;
this->LightComplexityChanged[&cellBO].Modified();
this->LastLightComplexity[&cellBO] = lightComplexity;
}
if (this->LastDepthPeeling !=
......@@ -1328,7 +1322,7 @@ bool vtkOpenGLPolyDataMapper::GetNeedToRebuildShaders(
cellBO.ShaderSourceTime < this->CurrentInput->GetMTime() ||
cellBO.ShaderSourceTime < this->SelectionStateChanged ||
cellBO.ShaderSourceTime < this->DepthPeelingChanged ||
cellBO.ShaderSourceTime < this->LightComplexityChanged)
cellBO.ShaderSourceTime < this->LightComplexityChanged[&cellBO])
{
return true;
}
......@@ -1413,7 +1407,7 @@ void vtkOpenGLPolyDataMapper::SetMapperShaderParameters(vtkOpenGLHelper &cellBO,
{
vtkErrorMacro(<< "Error setting 'vertexMC' in shader VAO.");
}
if (this->VBO->NormalOffset && this->LastLightComplexity > 0)
if (this->VBO->NormalOffset && this->LastLightComplexity[&cellBO] > 0)
{
if (!cellBO.VAO->AddAttributeArray(cellBO.Program, this->VBO,
"normalMC", this->VBO->NormalOffset,
......@@ -1422,7 +1416,7 @@ void vtkOpenGLPolyDataMapper::SetMapperShaderParameters(vtkOpenGLHelper &cellBO,
vtkErrorMacro(<< "Error setting 'normalMC' in shader VAO.");
}
}
if (this->VBO->TCoordComponents)
if (this->VBO->TCoordComponents && !this->DrawingEdges)
{
if (!cellBO.VAO->AddAttributeArray(cellBO.Program, this->VBO,
"tcoordMC", this->VBO->TCoordOffset,
......@@ -1431,7 +1425,7 @@ void vtkOpenGLPolyDataMapper::SetMapperShaderParameters(vtkOpenGLHelper &cellBO,
vtkErrorMacro(<< "Error setting 'tcoordMC' in shader VAO.");
}
}
if (this->VBO->ColorComponents != 0)
if (this->VBO->ColorComponents != 0 && !this->DrawingEdges)
{
if (!cellBO.VAO->AddAttributeArray(cellBO.Program, this->VBO,
"scalarColor", this->VBO->ColorOffset,
......@@ -1590,7 +1584,7 @@ void vtkOpenGLPolyDataMapper::SetLightingShaderParameters(
vtkActor *actor)
{
// for unlit and headlight there are no lighting parameters
if (this->LastLightComplexity < 2 || this->DrawingEdges)
if (this->LastLightComplexity[&cellBO] < 2 || this->DrawingEdges)
{
return;
}
......@@ -1676,7 +1670,7 @@ void vtkOpenGLPolyDataMapper::SetLightingShaderParameters(
program->SetUniformi("numberOfLights", numberOfLights);
// we are done unless we have positional lights
if (this->LastLightComplexity < 3)
if (this->LastLightComplexity[&cellBO] < 3)
{
return;
}
......@@ -1737,12 +1731,12 @@ void vtkOpenGLPolyDataMapper::SetCameraShaderParameters(vtkOpenGLHelper &cellBO,
((vtkOpenGLActor *)actor)->GetKeyMatrices(mcwc,anorms);
vtkMatrix4x4::Multiply4x4(mcwc, wcdc, this->TempMatrix4);
program->SetUniformMatrix("MCDCMatrix", this->TempMatrix4);
if (this->IsShaderVariableUsed("MCVCMatrix"))
if (program->IsUniformUsed("MCVCMatrix"))
{
vtkMatrix4x4::Multiply4x4(mcwc, wcvc, this->TempMatrix4);
program->SetUniformMatrix("MCVCMatrix", this->TempMatrix4);
}
if (this->IsShaderVariableUsed("normalMatrix"))
if (program->IsUniformUsed("normalMatrix"))
{
vtkMatrix3x3::Multiply3x3(anorms, norms, this->TempMatrix3);
program->SetUniformMatrix("normalMatrix", this->TempMatrix3);
......@@ -1751,17 +1745,17 @@ void vtkOpenGLPolyDataMapper::SetCameraShaderParameters(vtkOpenGLHelper &cellBO,
else
{
program->SetUniformMatrix("MCDCMatrix", wcdc);
if (this->IsShaderVariableUsed("MCVCMatrix"))
if (program->IsUniformUsed("MCVCMatrix"))
{
program->SetUniformMatrix("MCVCMatrix", wcvc);
}
if (this->IsShaderVariableUsed("normalMatrix"))
if (program->IsUniformUsed("normalMatrix"))
{
program->SetUniformMatrix("normalMatrix", norms);
}
}
if (this->IsShaderVariableUsed("cameraParallel"))
if (program->IsUniformUsed("cameraParallel"))
{
program->SetUniformi("cameraParallel", cam->GetParallelProjection());
}
......@@ -1800,7 +1794,7 @@ void vtkOpenGLPolyDataMapper::SetPropertyShaderParameters(vtkOpenGLHelper &cellB
program->SetUniform3f("ambientColorUniform", ambientColor);
program->SetUniform3f("diffuseColorUniform", diffuseColor);
// we are done unless we have lighting
if (this->LastLightComplexity < 1)
if (this->LastLightComplexity[&cellBO] < 1)
{
return;
}
......@@ -1835,7 +1829,7 @@ void vtkOpenGLPolyDataMapper::SetPropertyShaderParameters(vtkOpenGLHelper &cellB
program->SetUniform3f("ambientColorUniformBF", ambientColor);
program->SetUniform3f("diffuseColorUniformBF", diffuseColor);
// we are done unless we have lighting
if (this->LastLightComplexity < 1)
if (this->LastLightComplexity[&cellBO] < 1)
{
return;
}
......
......@@ -275,9 +275,9 @@ protected:
// do we have wide lines that require special handling
virtual bool HaveWideLines(vtkRenderer *, vtkActor *);
// values we use to determine if we need to rebuild
int LastLightComplexity;
vtkTimeStamp LightComplexityChanged;
// values we use to determine if we need to rebuild shaders
std::map<const vtkOpenGLHelper *, int> LastLightComplexity;
std::map<const vtkOpenGLHelper *, vtkTimeStamp> LightComplexityChanged;
int LastSelectionState;
vtkTimeStamp SelectionStateChanged;
......@@ -295,19 +295,6 @@ protected:
vtkMatrix4x4 *TempMatrix4;
vtkMatrix3x3 *TempMatrix3;
// this vector can be used while building
// the shader program to record specific variables
// that are being used by the program. This is
// useful later on when setting uniforms. At
// that point IsShaderVariableUsed can be called
// to see if the uniform should be set or not.
std::vector<std::string> ShaderVariablesUsed;
// used to see if the shader building code indicated that
// a specific variable is being used. Only some variables
// are currently populated.
bool IsShaderVariableUsed(const char *);
// if set to true, tcoords will be passed to the
// VBO even if the mapper knows of no texture maps
// normally tcoords are only added to the VBO if the
......
......@@ -285,6 +285,9 @@ bool vtkShaderProgram::Link()
return false;
}
// clear out the list of uniforms used
this->UniformsUsed.clear();
#if GL_ES_VERSION_2_0 != 1
// bind the outputs if specified
if (this->NumberOfOutputs)
......@@ -781,6 +784,36 @@ inline int vtkShaderProgram::FindUniform(const char *name)
return location;
}
bool vtkShaderProgram::IsUniformUsed(const char *name)
{
if (name == NULL)
{
return false;
}
// see if we have cached the result
typedef std::map<std::string, bool>::iterator iter;
iter found = this->UniformsUsed.find(name);
// if not, go query openGL
if (found == this->UniformsUsed.end())
{
if (!this->Linked)
{
vtkErrorMacro("attempt to find uniform when the shader program is not linked");
return false;
}
GLint location =
static_cast<int>(glGetUniformLocation(static_cast<GLuint>(Handle),
(const GLchar *)name));
this->UniformsUsed[name] = (location == -1 ? false : true);
return (location == -1 ? false : true);
}
return found->second;
}
// ----------------------------------------------------------------------------
void vtkShaderProgram::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -191,7 +191,11 @@ public:
const std::string replace,
bool all = true);
// Description:
// methods to inquire as to what uniforms/attributes are used by
// this shader. This can save some compute time if the uniforms
// or attributes are expensive to compute
bool IsUniformUsed(const char *);
protected:
vtkShaderProgram();
......@@ -271,6 +275,9 @@ protected:
std::map<std::string, int> Attributes;
std::map<std::string, bool> UniformsUsed;
friend class VertexArrayObject;
private:
......
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