diff --git a/Rendering/OpenGL2/Testing/Cxx/CMakeLists.txt b/Rendering/OpenGL2/Testing/Cxx/CMakeLists.txt index 5e33c5c7a31482d6d35cba4d3fcea2d569c9d925..de90b11151eeec56055e8be2153699d1262fd856 100644 --- a/Rendering/OpenGL2/Testing/Cxx/CMakeLists.txt +++ b/Rendering/OpenGL2/Testing/Cxx/CMakeLists.txt @@ -12,6 +12,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests TestEDLPass.cxx TestFXAAFilter.cxx TestGaussianBlurPass.cxx + TestGlyph3DMapperEdges.cxx TestGlyph3DMapperCellPicking.cxx TestLightingMapLuminancePass.cxx TestLightingMapNormalsPass.cxx diff --git a/Rendering/OpenGL2/Testing/Cxx/TestGlyph3DMapperEdges.cxx b/Rendering/OpenGL2/Testing/Cxx/TestGlyph3DMapperEdges.cxx new file mode 100644 index 0000000000000000000000000000000000000000..03ed19d9a65fbdd09250d6be634860f4c011eb69 --- /dev/null +++ b/Rendering/OpenGL2/Testing/Cxx/TestGlyph3DMapperEdges.cxx @@ -0,0 +1,89 @@ +/*========================================================================= + + Program: Visualization Toolkit + + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ + + +#include "vtkTestUtilities.h" +#include "vtkRegressionTestImage.h" + +#include "vtkActor.h" +#include "vtkCamera.h" +#include "vtkElevationFilter.h" +#include "vtkGlyph3DMapper.h" +#include "vtkNew.h" +#include "vtkPlaneSource.h" +#include "vtkPointData.h" +#include "vtkProperty.h" +#include "vtkRenderWindow.h" +#include "vtkRenderWindowInteractor.h" +#include "vtkRenderer.h" +#include "vtkSphereSource.h" + +int TestGlyph3DMapperEdges(int argc, char* argv[]) +{ + int res=1; + vtkNew<vtkPlaneSource> plane; + plane->SetResolution(res,res); + + vtkNew<vtkElevationFilter> colors; + colors->SetInputConnection(plane->GetOutputPort()); + colors->SetLowPoint(-1,-1,-1); + colors->SetHighPoint(0.5,0.5,0.5); + + vtkNew<vtkSphereSource> squad; + squad->SetPhiResolution(5); + squad->SetThetaResolution(9); + + vtkNew<vtkGlyph3DMapper> glypher; + glypher->SetInputConnection(colors->GetOutputPort()); + glypher->SetScaleFactor(1.2); + glypher->SetSourceConnection(squad->GetOutputPort()); + + vtkNew<vtkActor> glyphActor1; + glyphActor1->SetMapper(glypher.Get()); + glyphActor1->GetProperty()->SetEdgeVisibility(1); + glyphActor1->GetProperty()->SetEdgeColor(1.0,0.5,0.5); + // glyphActor1->GetProperty()->SetRenderLinesAsTubes(1); + // glyphActor1->GetProperty()->SetLineWidth(5); + + // Standard rendering classes + vtkNew<vtkRenderer> renderer; + vtkNew<vtkRenderWindow> renWin; + renWin->AddRenderer(renderer.Get()); + renWin->SetMultiSamples(0); + vtkNew<vtkRenderWindowInteractor> iren; + iren->SetRenderWindow(renWin.Get()); + + //set up the view + renderer->SetBackground(0.2,0.2,0.2); + renWin->SetSize(300,300); + + renderer->AddActor(glyphActor1.Get()); + + //////////////////////////////////////////////////////////// + + //run the test + + renderer->ResetCamera(); + renderer->GetActiveCamera()->Zoom(1.3); + + renWin->Render(); + + int retVal = vtkRegressionTestImage( renWin.Get() ); + if ( retVal == vtkRegressionTester::DO_INTERACTOR) + { + iren->Start(); + } + + return !retVal; +} diff --git a/Rendering/OpenGL2/Testing/Data/Baseline/TestGlyph3DMapperEdges.png.md5 b/Rendering/OpenGL2/Testing/Data/Baseline/TestGlyph3DMapperEdges.png.md5 new file mode 100644 index 0000000000000000000000000000000000000000..3ea979726a6500a844a55b10e15fbf5ac9db7751 --- /dev/null +++ b/Rendering/OpenGL2/Testing/Data/Baseline/TestGlyph3DMapperEdges.png.md5 @@ -0,0 +1 @@ +0c0a7f1f60555c3a9631a56e6b2e8e7c diff --git a/Rendering/OpenGL2/vtkOpenGLGlyph3DHelper.cxx b/Rendering/OpenGL2/vtkOpenGLGlyph3DHelper.cxx index bc80a8de42ab84f6f553366d83881d0c0363dc11..130a4a65175be2eb676621c7a5e352bb590b7528 100644 --- a/Rendering/OpenGL2/vtkOpenGLGlyph3DHelper.cxx +++ b/Rendering/OpenGL2/vtkOpenGLGlyph3DHelper.cxx @@ -49,10 +49,6 @@ vtkOpenGLGlyph3DHelper::vtkOpenGLGlyph3DHelper() this->NormalMatrixBuffer = vtkOpenGLBufferObject::New(); this->MatrixBuffer = vtkOpenGLBufferObject::New(); this->ColorBuffer = vtkOpenGLBufferObject::New(); - this->ModelTransformMatrix = NULL; - this->ModelNormalMatrix = NULL; - this->ModelColor = NULL; - this->UseFastPath = false; this->UsingInstancing = false; this->PopulateSelectionSettings = 0; } @@ -122,6 +118,7 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderColor( { std::string VSSource = shaders[vtkShader::Vertex]->GetSource(); std::string FSSource = shaders[vtkShader::Fragment]->GetSource(); + std::string GSSource = shaders[vtkShader::Geometry]->GetSource(); // deal with color if (this->UsingInstancing) @@ -130,133 +127,63 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderColor( "//VTK::Color::Dec", "attribute vec4 glyphColor;\n" "varying vec4 vertexColorVSOutput;"); + vtkShaderProgram::Substitute(GSSource, + "//VTK::Color::Dec", + "in vec4 vertexColorVSOutput[];\n" + "out vec4 vertexColorGSOutput;"); + vtkShaderProgram::Substitute(GSSource, + "//VTK::Color::Impl", + "vertexColorGSOutput = vertexColorVSOutput[i];"); + vtkShaderProgram::Substitute(VSSource,"//VTK::Color::Impl", + "vertexColorVSOutput = glyphColor;"); + vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Dec", + "varying vec4 vertexColorVSOutput;\n" + "//VTK::Color::Dec", false); } else { vtkShaderProgram::Substitute(VSSource, + "//VTK::Color::Dec", ""); + vtkShaderProgram::Substitute(FSSource, "//VTK::Color::Dec", "uniform vec4 glyphColor;\n" - "varying vec4 vertexColorVSOutput;"); - } - vtkShaderProgram::Substitute(VSSource,"//VTK::Color::Impl", - "vertexColorVSOutput = glyphColor;"); - - // crate the material/color property declarations, and VS implementation - // these are always defined - std::string colorDec = - "uniform float opacityUniform; // the fragment opacity\n" - "uniform vec3 ambientColorUniform; // intensity weighted color\n" - "uniform vec3 diffuseColorUniform; // intensity weighted color\n"; - // add some if we have a backface property - if (actor->GetBackfaceProperty()) - { - colorDec += - "uniform float opacityUniformBF; // the fragment opacity\n" - "uniform vec3 ambientColorUniformBF; // intensity weighted color\n" - "uniform vec3 diffuseColorUniformBF; // intensity weighted color\n"; + "//VTK::Color::Dec", false); + vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl", + "vec4 vertexColorVSOutput = glyphColor;\n" + "//VTK::Color::Impl", false); } - // add more for specular - if (this->LastLightComplexity[this->LastBoundBO]) + + // now handle scalar coloring + if(!this->DrawingEdgesOrVertices) { - colorDec += - "uniform vec3 specularColorUniform; // intensity weighted color\n" - "uniform float specularPowerUniform;\n"; - if (actor->GetBackfaceProperty()) + if (this->ScalarMaterialMode == VTK_MATERIALMODE_AMBIENT || + (this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT && + actor->GetProperty()->GetAmbient() > actor->GetProperty()->GetDiffuse())) { - colorDec += - "uniform vec3 specularColorUniformBF; // intensity weighted color\n" - "uniform float specularPowerUniformBF;\n"; + vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl", + "//VTK::Color::Impl\n" + " ambientColor = vertexColorVSOutput.rgb;\n" + " opacity = opacity*vertexColorVSOutput.a;", false); } - } - colorDec += "varying vec4 vertexColorVSOutput;\n"; - vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Dec", colorDec); - - // now handle the more complex fragment shader implementation - // the following are always defined variables. We start - // by assiging a default value from the uniform - std::string colorImpl = - "vec3 ambientColor;\n" - " vec3 diffuseColor;\n" - " float opacity;\n"; - if (this->LastLightComplexity[this->LastBoundBO]) - { - colorImpl += - " vec3 specularColor;\n" - " float specularPower;\n"; - } - if (actor->GetBackfaceProperty()) - { - if (this->LastLightComplexity[this->LastBoundBO]) + else if (this->ScalarMaterialMode == VTK_MATERIALMODE_DIFFUSE || + (this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT && + actor->GetProperty()->GetAmbient() <= actor->GetProperty()->GetDiffuse())) { - colorImpl += - " if (int(gl_FrontFacing) == 0) {\n" - " ambientColor = ambientColorUniformBF;\n" - " diffuseColor = diffuseColorUniformBF;\n" - " specularColor = specularColorUniformBF;\n" - " specularPower = specularPowerUniformBF;\n" - " opacity = opacityUniformBF; }\n" - " else {\n" - " ambientColor = ambientColorUniform;\n" - " diffuseColor = diffuseColorUniform;\n" - " specularColor = specularColorUniform;\n" - " specularPower = specularPowerUniform;\n" - " opacity = opacityUniform; }\n"; + vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl", + "//VTK::Color::Impl\n" + " diffuseColor = vertexColorVSOutput.rgb;\n" + " opacity = opacity*vertexColorVSOutput.a;"); } else { - colorImpl += - " if (int(gl_FrontFacing) == 0) {\n" - " ambientColor = ambientColorUniformBF;\n" - " diffuseColor = diffuseColorUniformBF;\n" - " opacity = opacityUniformBF; }\n" - " else {\n" - " ambientColor = ambientColorUniform;\n" - " diffuseColor = diffuseColorUniform;\n" - " opacity = opacityUniform; }\n"; - } - } - else - { - colorImpl += - " ambientColor = ambientColorUniform;\n" - " diffuseColor = diffuseColorUniform;\n" - " opacity = opacityUniform;\n"; - if (this->LastLightComplexity[this->LastBoundBO]) - { - colorImpl += - " specularColor = specularColorUniform;\n" - " specularPower = specularPowerUniform;\n"; + vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl", + "//VTK::Color::Impl\n" + " diffuseColor = vertexColorVSOutput.rgb;\n" + " ambientColor = vertexColorVSOutput.rgb;\n" + " opacity = opacity*vertexColorVSOutput.a;"); } } - // now handle scalar coloring - if (this->ScalarMaterialMode == VTK_MATERIALMODE_AMBIENT || - (this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT && - actor->GetProperty()->GetAmbient() > actor->GetProperty()->GetDiffuse())) - { - vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl", - colorImpl + - " ambientColor = vertexColorVSOutput.rgb;\n" - " opacity = vertexColorVSOutput.a;"); - } - else if (this->ScalarMaterialMode == VTK_MATERIALMODE_DIFFUSE || - (this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT && - actor->GetProperty()->GetAmbient() <= actor->GetProperty()->GetDiffuse())) - { - vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl", - colorImpl + - " diffuseColor = vertexColorVSOutput.rgb;\n" - " opacity = vertexColorVSOutput.a;"); - } - else - { - vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl", - colorImpl + - " diffuseColor = vertexColorVSOutput.rgb;\n" - " ambientColor = vertexColorVSOutput.rgb;\n" - " opacity = vertexColorVSOutput.a;"); - } - if (this->UsingInstancing) { vtkShaderProgram::Substitute(VSSource, @@ -275,6 +202,7 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderColor( shaders[vtkShader::Vertex]->SetSource(VSSource); shaders[vtkShader::Fragment]->SetSource(FSSource); + shaders[vtkShader::Geometry]->SetSource(GSSource); this->Superclass::ReplaceShaderColor(shaders,ren,actor); } @@ -385,14 +313,8 @@ void vtkOpenGLGlyph3DHelper::GlyphRender( this->UsingInstancing = false; vtkHardwareSelector* selector = ren->GetSelector(); - bool selecting_points = selector && (selector->GetFieldAssociation() == - vtkDataObject::FIELD_ASSOCIATION_POINTS); - int representation = actor->GetProperty()->GetRepresentation(); - - - if (actor->GetProperty()->GetRepresentation() == VTK_SURFACE && - !selector && !ren->GetRenderWindow()->GetIsPicking() + if (!selector && !ren->GetRenderWindow()->GetIsPicking() && GLEW_ARB_instanced_arrays) { this->GlyphRenderInstances(ren, actor, numPts, @@ -400,110 +322,76 @@ void vtkOpenGLGlyph3DHelper::GlyphRender( return; } - bool primed = false; + bool selecting_points = selector && (selector->GetFieldAssociation() == + vtkDataObject::FIELD_ASSOCIATION_POINTS); + + int representation = actor->GetProperty()->GetRepresentation(); + + this->RenderPieceStart(ren,actor); - // First we do the triangles, update the shader, set uniforms, etc. - GLenum mode = (representation == VTK_POINTS) ? GL_POINTS : - (representation == VTK_WIREFRAME) ? GL_LINES : GL_TRIANGLES; if (selecting_points) { #if GL_ES_VERSION_3_0 != 1 glPointSize(6.0); #endif - mode = GL_POINTS; + representation = GL_POINTS; } - for (vtkIdType inPtId = 0; inPtId < numPts; inPtId++) + bool draw_surface_with_edges = + (actor->GetProperty()->GetEdgeVisibility() && representation == VTK_SURFACE) && !selector; + int numVerts = this->VBOs->GetNumberOfTuples("vertexMC"); + for (int i = PrimitiveStart; + i < (draw_surface_with_edges ? PrimitiveEnd : PrimitiveTriStrips + 1); i++) { - if (selector) - { - selector->RenderAttributeId(pickIds[inPtId]); - } - if (!primed) - { - this->RenderPieceStart(ren,actor); - this->UpdateShaders(this->Primitives[PrimitiveTris], ren, actor); - this->Primitives[PrimitiveTris].IBO->Bind(); - primed = true; - } - - // handle the middle - vtkShaderProgram *program = this->Primitives[PrimitiveTris].Program; - - if (!program) - { - return; - } - - // Apply the extra transform - program->SetUniformMatrix4x4("GCMCMatrix", &(matrices[inPtId*16])); - - // for lit shaders set normal matrix - if (this->LastLightComplexity[this->LastBoundBO] > 0 && - this->VBOs->GetNumberOfComponents("normalMC") == 3 && - !this->UsingInstancing) - { - program->SetUniformMatrix3x3("glyphNormalMatrix", &(normalMatrices[inPtId*9])); - } - - program->SetUniform4uc("glyphColor", &(colors[inPtId*4])); - - if (selector) + this->DrawingEdgesOrVertices = (i > PrimitiveTriStrips ? true : false); + if (this->Primitives[i].IBO->IndexCount) { - program->SetUniform3f("mapperIndex", selector->GetPropColorValue()); + this->UpdateShaders(this->Primitives[i], ren, actor); + GLenum mode = this->GetOpenGLMode(representation, i); + this->Primitives[i].IBO->Bind(); + for (vtkIdType inPtId = 0; inPtId < numPts; inPtId++) + { + if (selector) + { + selector->RenderAttributeId(pickIds[inPtId]); + } + + // handle the middle + vtkShaderProgram *program = this->Primitives[i].Program; + + if (!program) + { + return; + } + + // Apply the extra transform + program->SetUniformMatrix4x4("GCMCMatrix", &(matrices[inPtId*16])); + + // for lit shaders set normal matrix + if (this->LastLightComplexity[this->LastBoundBO] > 0 && + this->VBOs->GetNumberOfComponents("normalMC") == 3 && + !this->UsingInstancing) + { + program->SetUniformMatrix3x3("glyphNormalMatrix", &(normalMatrices[inPtId*9])); + } + + program->SetUniform4uc("glyphColor", &(colors[inPtId*4])); + + if (selector) + { + program->SetUniform3f("mapperIndex", selector->GetPropColorValue()); + } + + glDrawRangeElements(mode, 0, + static_cast<GLuint>(numVerts - 1), + static_cast<GLsizei>(this->Primitives[i].IBO->IndexCount), + GL_UNSIGNED_INT, + reinterpret_cast<const GLvoid *>(NULL)); + } + this->Primitives[i].IBO->Release(); } - - glDrawRangeElements(mode, 0, - static_cast<GLuint>(this->VBOs->GetNumberOfTuples("vertexMC") - 1), - static_cast<GLsizei>(this->Primitives[PrimitiveTris].IBO->IndexCount), - GL_UNSIGNED_INT, - reinterpret_cast<const GLvoid *>(NULL)); - } - if (primed) - { - this->Primitives[PrimitiveTris].IBO->Release(); - this->RenderPieceFinish(ren,actor); - } -} - -//----------------------------------------------------------------------------- -void vtkOpenGLGlyph3DHelper::SetCameraShaderParameters(vtkOpenGLHelper &cellBO, - vtkRenderer* ren, vtkActor *actor) -{ - // do the superclass and then reset a couple values - this->Superclass::SetCameraShaderParameters(cellBO,ren,actor); - - vtkShaderProgram *program = cellBO.Program; - - // Apply the extra transform - if (this->ModelTransformMatrix) - { - program->SetUniformMatrix4x4("GCMCMatrix", this->ModelTransformMatrix); - } - - // for lit shaders set normal matrix - if (this->LastLightComplexity[&cellBO] > 0 && - this->ModelNormalMatrix && - this->VBOs->GetNumberOfComponents("normalMC") == 3 && - !this->UsingInstancing) - { - program->SetUniformMatrix3x3("glyphNormalMatrix", this->ModelNormalMatrix); - } -} - -//----------------------------------------------------------------------------- -void vtkOpenGLGlyph3DHelper::SetPropertyShaderParameters(vtkOpenGLHelper &cellBO, - vtkRenderer *ren, vtkActor *actor) -{ - // do the superclass and then reset a couple values - this->Superclass::SetPropertyShaderParameters(cellBO,ren,actor); - - vtkShaderProgram *program = cellBO.Program; - - if (this->ModelColor) - { - program->SetUniform4uc("glyphColor", this->ModelColor); } + this->RenderPieceFinish(ren,actor); } //----------------------------------------------------------------------------- @@ -527,81 +415,104 @@ void vtkOpenGLGlyph3DHelper::GlyphRenderInstances( { this->UsingInstancing = true; this->RenderPieceStart(ren,actor); - this->UpdateShaders(this->Primitives[PrimitiveTris], ren, actor); - if (!this->Primitives[PrimitiveTris].Program) - { - return; - } + int representation = actor->GetProperty()->GetRepresentation(); - // do the superclass and then reset a couple values - if (this->Primitives[PrimitiveTris].IBO->IndexCount && // we have points and one of - (this->VBOBuildTime > this->InstanceBuffersLoadTime || - this->Primitives[PrimitiveTris].ShaderSourceTime > this->InstanceBuffersLoadTime || - pointMTime > this->InstanceBuffersLoadTime.GetMTime())) + // update the VBOs if needed + if (pointMTime > this->InstanceBuffersBuildTime.GetMTime()) { - this->Primitives[PrimitiveTris].VAO->Bind(); - // add 3 new BOs? - this->MatrixBuffer->Bind(); this->MatrixBuffer->Upload(matrices, vtkOpenGLBufferObject::ArrayBuffer); - if (!this->Primitives[PrimitiveTris].VAO->AddAttributeMatrixWithDivisor( - this->Primitives[PrimitiveTris].Program, this->MatrixBuffer, - "GCMCMatrix", 0, 16*sizeof(float), VTK_FLOAT, 4, false, 1)) - { - vtkErrorMacro(<< "Error setting 'GCMCMatrix' in shader VAO."); - } - this->MatrixBuffer->Release(); - if (this->VBOs->GetNumberOfComponents("normalMC") == 3 && - this->LastLightComplexity[this->LastBoundBO] > 0) + if (this->VBOs->GetNumberOfComponents("normalMC") == 3) { - this->NormalMatrixBuffer->Bind(); this->NormalMatrixBuffer->Upload( normalMatrices, vtkOpenGLBufferObject::ArrayBuffer); - if (!this->Primitives[PrimitiveTris].VAO->AddAttributeMatrixWithDivisor( - this->Primitives[PrimitiveTris].Program, this->NormalMatrixBuffer, - "glyphNormalMatrix", 0, 9*sizeof(float), VTK_FLOAT, 3, false, 1)) - { - vtkErrorMacro(<< "Error setting 'glyphNormalMatrix' in shader VAO."); - } - this->NormalMatrixBuffer->Release(); } - if (this->Primitives[PrimitiveTris].Program->IsAttributeUsed("glyphColor")) + this->ColorBuffer->Upload(colors, vtkOpenGLBufferObject::ArrayBuffer); + this->InstanceBuffersBuildTime.Modified(); + } + + bool draw_surface_with_edges = + (actor->GetProperty()->GetEdgeVisibility() && representation == VTK_SURFACE); + for (int i = PrimitiveStart; + i < (draw_surface_with_edges ? PrimitiveEnd : PrimitiveTriStrips + 1); i++) + { + this->DrawingEdgesOrVertices = (i > PrimitiveTriStrips ? true : false); + if (this->Primitives[i].IBO->IndexCount) { - this->ColorBuffer->Bind(); - this->ColorBuffer->Upload(colors, vtkOpenGLBufferObject::ArrayBuffer); - if (!this->Primitives[PrimitiveTris].VAO->AddAttributeArrayWithDivisor( - this->Primitives[PrimitiveTris].Program, this->ColorBuffer, - "glyphColor", 0, 4*sizeof(unsigned char), VTK_UNSIGNED_CHAR, 4, true, 1, false)) + this->UpdateShaders(this->Primitives[i], ren, actor); + if (!this->Primitives[i].Program) { - vtkErrorMacro(<< "Error setting 'diffuse color' in shader VAO."); + return; } - this->ColorBuffer->Release(); - } - this->InstanceBuffersLoadTime.Modified(); - } + GLenum mode = this->GetOpenGLMode(representation, i); + + + // do the superclass and then reset a couple values + if ((this->InstanceBuffersBuildTime > this->InstanceBuffersLoadTime || + this->Primitives[i].ShaderSourceTime > this->InstanceBuffersLoadTime)) + { + this->Primitives[i].VAO->Bind(); + this->MatrixBuffer->Bind(); + if (!this->Primitives[i].VAO->AddAttributeMatrixWithDivisor( + this->Primitives[i].Program, this->MatrixBuffer, + "GCMCMatrix", 0, 16*sizeof(float), VTK_FLOAT, 4, false, 1)) + { + vtkErrorMacro(<< "Error setting 'GCMCMatrix' in shader VAO."); + } + this->MatrixBuffer->Release(); + + if (this->VBOs->GetNumberOfComponents("normalMC") == 3 && + this->LastLightComplexity[this->LastBoundBO] > 0) + { + this->NormalMatrixBuffer->Bind(); + if (!this->Primitives[i].VAO->AddAttributeMatrixWithDivisor( + this->Primitives[i].Program, this->NormalMatrixBuffer, + "glyphNormalMatrix", 0, 9*sizeof(float), VTK_FLOAT, 3, false, 1)) + { + vtkErrorMacro(<< "Error setting 'glyphNormalMatrix' in shader VAO."); + } + this->NormalMatrixBuffer->Release(); + } + + if (this->Primitives[i].Program->IsAttributeUsed("glyphColor")) + { + this->ColorBuffer->Bind(); + if (!this->Primitives[i].VAO->AddAttributeArrayWithDivisor( + this->Primitives[i].Program, this->ColorBuffer, + "glyphColor", 0, 4*sizeof(unsigned char), VTK_UNSIGNED_CHAR, 4, true, 1, false)) + { + vtkErrorMacro(<< "Error setting 'diffuse color' in shader VAO."); + } + this->ColorBuffer->Release(); + } + this->InstanceBuffersLoadTime.Modified(); + } + + this->Primitives[i].IBO->Bind(); - this->Primitives[PrimitiveTris].IBO->Bind(); #if GL_ES_VERSION_3_0 == 1 - glDrawElementsInstanced(GL_TRIANGLES, - static_cast<GLsizei>(this->Primitives[PrimitiveTris].IBO->IndexCount), - GL_UNSIGNED_INT, - reinterpret_cast<const GLvoid *>(NULL), - numPts); + glDrawElementsInstanced(mode, + static_cast<GLsizei>(this->Primitives[i].IBO->IndexCount), + GL_UNSIGNED_INT, + reinterpret_cast<const GLvoid *>(NULL), + numPts); #else - if (GLEW_ARB_instanced_arrays && - this->Primitives[PrimitiveTris].IBO->IndexCount > 0) - { - glDrawElementsInstancedARB(GL_TRIANGLES, - static_cast<GLsizei>(this->Primitives[PrimitiveTris].IBO->IndexCount), - GL_UNSIGNED_INT, - reinterpret_cast<const GLvoid *>(NULL), - numPts); - } + if (GLEW_ARB_instanced_arrays) + { + glDrawElementsInstancedARB(mode, + static_cast<GLsizei>(this->Primitives[i].IBO->IndexCount), + GL_UNSIGNED_INT, + reinterpret_cast<const GLvoid *>(NULL), + numPts); + } #endif - vtkOpenGLCheckErrorMacro("failed after Render"); - this->Primitives[PrimitiveTris].IBO->Release(); + this->Primitives[i].IBO->Release(); + } + } + + vtkOpenGLCheckErrorMacro("failed after Render"); this->RenderPieceFinish(ren, actor); } diff --git a/Rendering/OpenGL2/vtkOpenGLGlyph3DHelper.h b/Rendering/OpenGL2/vtkOpenGLGlyph3DHelper.h index cb6a71a4e5854e2f224bb89ba372f577d0d3a254..c3c4951fcb8e980230fa28646bb7410e26d9d334 100644 --- a/Rendering/OpenGL2/vtkOpenGLGlyph3DHelper.h +++ b/Rendering/OpenGL2/vtkOpenGLGlyph3DHelper.h @@ -33,27 +33,6 @@ public: vtkTypeMacro(vtkOpenGLGlyph3DHelper, vtkOpenGLPolyDataMapper) void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE; - void SetModelTransform(float *matrix) - { - this->ModelTransformMatrix = matrix; - } - - void SetModelNormalTransform(float *matrix) - { - this->ModelNormalMatrix = matrix; - } - - void SetModelColor(unsigned char *color) - { - this->ModelColor = color; - } - - void SetUseFastPath(bool fastpath) - { - this->UseFastPath = fastpath; - this->UsingInstancing = false; - } - /** * Fast path for rendering glyphs comprised of only one type of primitive * Must set this->CurrentInput explicitly before calling. @@ -108,34 +87,18 @@ protected: vtkRenderer *ren, vtkActor *act) VTK_OVERRIDE; //@} - /** - * Set the shader parameteres related to the Camera - */ - void SetCameraShaderParameters( - vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act) VTK_OVERRIDE; - - /** - * Set the shader parameteres related to the property - */ - void SetPropertyShaderParameters( - vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act) VTK_OVERRIDE; - /** * Set the shader parameteres related to the actor/mapper */ void SetMapperShaderParameters( vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act) VTK_OVERRIDE; - bool UseFastPath; bool UsingInstancing; - float* ModelTransformMatrix; - float* ModelNormalMatrix; - unsigned char* ModelColor; - vtkOpenGLBufferObject *NormalMatrixBuffer; vtkOpenGLBufferObject *MatrixBuffer; vtkOpenGLBufferObject *ColorBuffer; + vtkTimeStamp InstanceBuffersBuildTime; vtkTimeStamp InstanceBuffersLoadTime; diff --git a/Rendering/OpenGL2/vtkOpenGLGlyph3DMapper.cxx b/Rendering/OpenGL2/vtkOpenGLGlyph3DMapper.cxx index 2dd7c36953824e0e06e2267cc7121cde50a3ebf4..d0a43e88be83c56f4931524d3a7e8251f9610f19 100644 --- a/Rendering/OpenGL2/vtkOpenGLGlyph3DMapper.cxx +++ b/Rendering/OpenGL2/vtkOpenGLGlyph3DMapper.cxx @@ -474,8 +474,6 @@ void vtkOpenGLGlyph3DMapper::Render( sTTIter = NULL; } - vtkHardwareSelector* selector = ren->GetSelector(); - // rebuild all entries for this DataSet if it // has been modified if (subarray->BuildTime < dataset->GetMTime() || @@ -548,50 +546,9 @@ void vtkOpenGLGlyph3DMapper::Render( { vtkOpenGLGlyph3DHelper *gh = entry->Mappers[mapperIdx]; gh->CurrentInput = pd; - - // now draw, there is a fast path for a special case of - // only triangles - bool fastPath = false; - - if (pd->GetNumberOfVerts() == 0 && - pd->GetNumberOfLines() == 0 && - pd->GetNumberOfStrips() == 0) - { - fastPath = true; - } - - // use fast path - gh->SetUseFastPath(fastPath); - if (fastPath) - { - gh->GlyphRender(ren, actor, entry->NumberOfPoints, - entry->Colors, entry->Matrices, entry->NormalMatrices, - entry->PickIds, subarray->BuildTime); - } - else - { - bool primed = false; - for (vtkIdType inPtId = 0; inPtId < entry->NumberOfPoints; inPtId++) - { - if (selector) - { - selector->RenderAttributeId(entry->PickIds[inPtId]); - } - if (!primed) - { - gh->RenderPieceStart(ren, actor); - primed = true; - } - gh->SetModelColor(&(entry->Colors[inPtId*4])); - gh->SetModelTransform(&(entry->Matrices[inPtId*16])); - gh->SetModelNormalTransform(&(entry->NormalMatrices[inPtId*9])); - gh->RenderPieceDraw(ren, actor); - } - if (primed) - { - gh->RenderPieceFinish(ren, actor); - } - } + gh->GlyphRender(ren, actor, entry->NumberOfPoints, + entry->Colors, entry->Matrices, entry->NormalMatrices, + entry->PickIds, subarray->BuildTime); } if (!cdsIter || cdsIter->IsDoneWithTraversal())