Commit 9b3af2f4 authored by Ken Martin's avatar Ken Martin

add option to show vertices, like edge visibility

also clean up some of the rendering code
as the Primitive IBOs where getting out of hand.
add two new tests to test vertex visibility
parent 7ce4d3b3
......@@ -71,6 +71,10 @@ vtkProperty::vtkProperty()
this->EdgeColor[1] = 0;
this->EdgeColor[2] = 0;
this->VertexColor[0] = 0.5;
this->VertexColor[1] = 1.0;
this->VertexColor[2] = 0.5;
this->Ambient = 0.0;
this->Diffuse = 1.0;
this->Specular = 0.0;
......@@ -79,6 +83,7 @@ vtkProperty::vtkProperty()
this->Interpolation = VTK_GOURAUD;
this->Representation = VTK_SURFACE;
this->EdgeVisibility = 0;
this->VertexVisibility = 0;
this->BackfaceCulling = 0;
this->FrontfaceCulling = 0;
this->PointSize = 1.0;
......@@ -112,6 +117,7 @@ void vtkProperty::DeepCopy(vtkProperty *p)
this->SetDiffuseColor(p->GetDiffuseColor());
this->SetSpecularColor(p->GetSpecularColor());
this->SetEdgeColor(p->GetEdgeColor());
this->SetVertexColor(p->GetVertexColor());
this->SetAmbient(p->GetAmbient());
this->SetDiffuse(p->GetDiffuse());
this->SetSpecular(p->GetSpecular());
......@@ -120,6 +126,7 @@ void vtkProperty::DeepCopy(vtkProperty *p)
this->SetInterpolation(p->GetInterpolation());
this->SetRepresentation(p->GetRepresentation());
this->SetEdgeVisibility(p->GetEdgeVisibility());
this->SetVertexVisibility(p->GetVertexVisibility());
this->SetBackfaceCulling(p->GetBackfaceCulling());
this->SetFrontfaceCulling(p->GetFrontfaceCulling());
this->SetPointSize(p->GetPointSize());
......@@ -443,6 +450,10 @@ void vtkProperty::PrintSelf(ostream& os, vtkIndent indent)
<< this->EdgeColor[1] << ", " << this->EdgeColor[2] << ")\n";
os << indent << "Edge Visibility: "
<< (this->EdgeVisibility ? "On\n" : "Off\n");
os << indent << "Vertex Color: (" << this->VertexColor[0] << ", "
<< this->VertexColor[1] << ", " << this->VertexColor[2] << ")\n";
os << indent << "Vertex Visibility: "
<< (this->VertexVisibility ? "On\n" : "Off\n");
os << indent << "Interpolation: ";
switch (this->Interpolation)
{
......
......@@ -262,6 +262,25 @@ public:
vtkGetVector3Macro(EdgeColor, double);
//@}
//@{
/**
* Turn on/off the visibility of vertices. On some renderers it is
* possible to render the vertices of geometric primitives separately
* from the interior.
*/
vtkGetMacro(VertexVisibility, int);
vtkSetMacro(VertexVisibility, int);
vtkBooleanMacro(VertexVisibility, int);
//@}
//@{
/**
* Set/Get the color of primitive vertices (if vertex visibility is enabled).
*/
vtkSetVector3Macro(VertexColor, double);
vtkGetVector3Macro(VertexColor, double);
//@}
//@{
/**
* Set/Get the width of a Line. The width is expressed in screen units.
......@@ -480,6 +499,7 @@ protected:
double DiffuseColor[3];
double SpecularColor[3];
double EdgeColor[3];
double VertexColor[3];
double Ambient;
double Diffuse;
double Specular;
......@@ -492,6 +512,7 @@ protected:
int Interpolation;
int Representation;
int EdgeVisibility;
int VertexVisibility;
int BackfaceCulling;
int FrontfaceCulling;
bool Lighting;
......
......@@ -210,7 +210,6 @@ void vtkSurfaceLICMapper::RenderPiece(
this->LICInterface->PrepareForGeometry();
this->RenderPieceStart(renderer, actor);
this->RenderPieceDraw(renderer, actor);
this->RenderEdges(renderer,actor);
this->RenderPieceFinish(renderer, actor);
this->LICInterface->CompletedGeometry();
......
......@@ -3,6 +3,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestBlurAndSobelPasses.cxx
TestCoincident.cxx
TestCompositePolyDataMapper2Spheres.cxx,NO_DATA
TestCompositePolyDataMapper2Vertices.cxx,NO_DATA
TestCubeMap.cxx
TestDepthOfFieldPass.cxx
TestDepthPeelingPass.cxx
......@@ -22,6 +23,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestShadowMapPass.cxx
TestSobelGradientMagnitudePass.cxx
TestSpherePoints.cxx
TestSphereVertex.cxx
TestUserShader.cxx
TestUserShader2.cxx
TestVBOPLYMapper.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCompositePolyDataMapper2.cxx
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 "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCompositeDataSet.h"
#include "vtkCompositeDataDisplayAttributes.h"
#include "vtkCompositePolyDataMapper2.h"
#include "vtkCullerCollection.h"
#include "vtkInformation.h"
#include "vtkMath.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkNew.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkTimerLog.h"
#include "vtkTrivialProducer.h"
#include <vtkTestUtilities.h>
#include <vtkRegressionTestImage.h>
#include "vtkCylinderSource.h"
int TestCompositePolyDataMapper2Vertices(int argc, char* argv[])
{
bool timeit = false;
if (argc > 1 && argv[1] && !strcmp(argv[1], "-timeit"))
{
timeit = true;
}
vtkSmartPointer<vtkRenderWindow> win =
vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkRenderer> ren =
vtkSmartPointer<vtkRenderer>::New();
win->AddRenderer(ren);
win->SetInteractor(iren);
vtkSmartPointer<vtkCompositePolyDataMapper2> mapper =
vtkSmartPointer<vtkCompositePolyDataMapper2>::New();
vtkNew<vtkCompositeDataDisplayAttributes> cdsa;
mapper->SetCompositeDataDisplayAttributes(cdsa.GetPointer());
int resolution = 10;
vtkNew<vtkCylinderSource> cyl;
cyl->CappingOn();
cyl->SetRadius(0.2);
cyl->SetHeight(0.6);
cyl->SetResolution(resolution);
// build a composite dataset
vtkNew<vtkMultiBlockDataSet> data;
int blocksPerLevel[3] = {1,4,8};
if (timeit)
{
blocksPerLevel[1] = 32;
blocksPerLevel[2] = 64;
}
std::vector<vtkSmartPointer<vtkMultiBlockDataSet> > blocks;
blocks.push_back(data.GetPointer());
unsigned levelStart = 0;
unsigned levelEnd = 1;
int numLevels = sizeof(blocksPerLevel) / sizeof(blocksPerLevel[0]);
int numLeaves = 0;
int numNodes = 0;
vtkStdString blockName("Rolf");
for (int level = 1; level < numLevels; ++level)
{
int nblocks=blocksPerLevel[level];
for (unsigned parent = levelStart; parent < levelEnd; ++parent)
{
blocks[parent]->SetNumberOfBlocks(nblocks);
for (int block=0; block < nblocks; ++block, ++numNodes)
{
if (level == numLevels - 1)
{
vtkNew<vtkPolyData> child;
cyl->SetCenter(block*0.25, 0.0, parent*0.5);
cyl->Update();
child->DeepCopy(cyl->GetOutput(0));
blocks[parent]->SetBlock(
block, (block % 2) ? NULL : child.GetPointer());
blocks[parent]->GetMetaData(block)->Set(
vtkCompositeDataSet::NAME(), blockName.c_str());
// test not setting it on some
if (block % 11)
{
mapper->SetBlockColor(parent+numLeaves+1,
vtkMath::HSVToRGB(0.8*block/nblocks, 0.2 + 0.8*((parent - levelStart) % 8)/7.0, 1.0));
mapper->SetBlockVisibility(parent+numLeaves, (block % 7) != 0);
}
++numLeaves;
}
else
{
vtkNew<vtkMultiBlockDataSet> child;
blocks[parent]->SetBlock(block, child.GetPointer());
blocks.push_back(child.GetPointer());
}
}
}
levelStart = levelEnd;
levelEnd = static_cast<unsigned>(blocks.size());
}
mapper->SetInputData((vtkPolyData *)(data.GetPointer()));
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->RenderLinesAsTubesOn();
actor->GetProperty()->EdgeVisibilityOn();
actor->GetProperty()->SetEdgeColor(0.7, 0.7, 0.7);
actor->GetProperty()->SetLineWidth(7.0);
actor->GetProperty()->RenderPointsAsSpheresOn();
actor->GetProperty()->VertexVisibilityOn();
actor->GetProperty()->SetVertexColor(1.0, 0.5, 0.5);
actor->GetProperty()->SetPointSize(14.0);
ren->AddActor(actor);
win->SetSize(400,400);
ren->RemoveCuller(ren->GetCullers()->GetLastItem());
ren->ResetCamera();
vtkSmartPointer<vtkTimerLog> timer = vtkSmartPointer<vtkTimerLog>::New();
win->Render(); // get the window up
// modify the data to force a rebuild of OpenGL structs
// after rendering set one cylinder to white
mapper->SetBlockColor(1011,1.0,1.0,1.0);
mapper->SetBlockOpacity(1011,1.0);
mapper->SetBlockVisibility(1011,1.0);
win->SetMultiSamples(0);
timer->StartTimer();
win->Render();
timer->StopTimer();
cout << "First frame time: " << timer->GetElapsedTime() << "\n";
timer->StartTimer();
int numFrames = (timeit ? 300 : 2);
for (int i = 0; i <= numFrames; i++)
{
ren->GetActiveCamera()->Elevation(20.0/numFrames);
// ren->GetActiveCamera()->Zoom(pow(2.0,1.0/numFrames));
ren->GetActiveCamera()->Roll(20.0/numFrames);
win->Render();
}
timer->StopTimer();
if (timeit)
{
double t = timer->GetElapsedTime();
cout << "Avg Frame time: " << t/numFrames << " Frame Rate: " << numFrames / t << "\n";
}
int retVal = vtkRegressionTestImageThreshold( win.GetPointer(),15);
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
/*=========================================================================
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 "vtkCamera.h"
#include "vtkRenderer.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkActor.h"
#include "vtkPolyDataMapper.h"
#include "vtkNew.h"
#include "vtkProperty.h"
#include "vtkSphereSource.h"
#include "vtkRegressionTestImage.h"
#include "vtkTestUtilities.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkOpenGLRenderWindow.h"
//----------------------------------------------------------------------------
int TestSphereVertex(int argc, char *argv[])
{
vtkNew<vtkRenderer> renderer;
renderer->SetBackground(0.0, 0.0, 0.0);
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(300, 300);
renderWindow->AddRenderer(renderer.Get());
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renderWindow.Get());
vtkNew<vtkSphereSource> sphere;
sphere->SetThetaResolution(16);
sphere->SetPhiResolution(16);
sphere->SetEndTheta(270.0);
{
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(sphere->GetOutputPort());
vtkNew<vtkActor> actor;
renderer->AddActor(actor.Get());
actor->SetMapper(mapper.Get());
actor->GetProperty()->SetDiffuseColor(0.4, 1.0, 1.0);
vtkNew<vtkProperty> backProp;
backProp->SetDiffuseColor(0.4, 0.65, 0.8);
actor->SetBackfaceProperty(backProp.Get());
actor->GetProperty()->EdgeVisibilityOn();
actor->GetProperty()->SetEdgeColor(1.0, 1.0, 1.0);
actor->GetProperty()->SetLineWidth(7.0);
actor->GetProperty()->RenderLinesAsTubesOn();
actor->GetProperty()->VertexVisibilityOn();
actor->GetProperty()->SetVertexColor(1.0, 0.5, 1.0);
actor->GetProperty()->SetPointSize(14.0);
actor->GetProperty()->RenderPointsAsSpheresOn();
}
renderWindow->SetMultiSamples(0);
renderer->ResetCamera();
renderer->GetActiveCamera()->Elevation(-45);
renderer->GetActiveCamera()->OrthogonalizeViewUp();
renderer->GetActiveCamera()->Zoom(1.5);
renderer->ResetCameraClippingRange();
renderWindow->Render();
int retVal = vtkRegressionTestImage( renderWindow.Get() );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
......@@ -64,8 +64,8 @@ public:
unsigned int NextVertex;
// point line poly strip edge stripedge
unsigned int StartIndex[6];
unsigned int NextIndex[6];
unsigned int StartIndex[vtkOpenGLPolyDataMapper::PrimitiveEnd];
unsigned int NextIndex[vtkOpenGLPolyDataMapper::PrimitiveEnd];
// Point Line Poly Strip end
size_t PrimOffsets[5];
......@@ -167,10 +167,9 @@ protected:
std::vector<unsigned int> VertexOffsets;
// vert line poly strip edge stripedge
std::vector<unsigned int> IndexArray[6];
std::vector<unsigned int> IndexArray[PrimitiveEnd];
virtual void RenderPieceDraw(vtkRenderer *ren, vtkActor *act);
virtual void RenderEdges(vtkRenderer *ren, vtkActor *act);
bool PrimIDUsed;
bool OverideColorUsed;
......@@ -367,7 +366,6 @@ void vtkCompositeMapperHelper2::RenderPiece(vtkRenderer* ren, vtkActor *actor)
this->RenderPieceStart(ren, actor);
this->RenderPieceDraw(ren, actor);
this->RenderEdges(ren,actor);
this->RenderPieceFinish(ren, actor);
}
......@@ -472,15 +470,21 @@ void vtkCompositeMapperHelper2::RenderPieceDraw(
this->PrimitiveIDOffset = 0;
GLenum mode = (representation == VTK_POINTS) ? GL_POINTS :
(representation == VTK_WIREFRAME) ? GL_LINES : GL_TRIANGLES;
vtkProperty *prop = actor->GetProperty();
bool draw_surface_with_edges =
(prop->GetEdgeVisibility() && prop->GetRepresentation() == VTK_SURFACE);
// draw IBOs
this->DrawIBO(ren, actor, 0, this->Points, GL_POINTS, pointPicking ? 2 : 0);
this->DrawIBO(ren, actor, 1, this->Lines,
representation == VTK_POINTS ? GL_POINTS : GL_LINES, pointPicking ? 4 : 0);
this->DrawIBO(ren, actor, 2, this->Tris, mode, pointPicking ? 6 : 0);
this->DrawIBO(ren, actor, 3, this->TriStrips, mode, pointPicking ? 6 : 0);
for (int i = PrimitiveStart;
i < (this->CurrentSelector ? PrimitiveTriStrips + 1 : PrimitiveEnd); i++)
{
this->DrawingEdges =
draw_surface_with_edges && (i == PrimitiveTrisEdges
|| i == PrimitiveTriStripsEdges);
GLenum mode = this->GetOpenGLMode(representation, i);
this->DrawIBO(ren, actor, i, this->Primitives[i], mode,
pointPicking ? this->GetPointPickingPrimitiveSize(i) : 0);
}
if (this->CurrentSelector && (
this->CurrentSelector->GetCurrentPass() == vtkHardwareSelector::ID_LOW24 ||
......@@ -492,27 +496,6 @@ void vtkCompositeMapperHelper2::RenderPieceDraw(
}
//-----------------------------------------------------------------------------
void vtkCompositeMapperHelper2::RenderEdges(
vtkRenderer* ren, vtkActor *actor)
{
vtkProperty *prop = actor->GetProperty();
bool draw_surface_with_edges =
(prop->GetEdgeVisibility() && prop->GetRepresentation() == VTK_SURFACE);
if (!draw_surface_with_edges || this->CurrentSelector)
{
return;
}
this->DrawingEdges = true;
this->DrawIBO(ren, actor, 4, this->TrisEdges, GL_LINES, 0);
this->DrawIBO(ren, actor, 5, this->TriStripsEdges, GL_LINES, 0);
this->DrawingEdges = false;
}
vtkCompositeMapperHelperData *vtkCompositeMapperHelper2::AddData(
vtkPolyData *pd, unsigned int flatIndex)
{
......@@ -578,7 +561,7 @@ void vtkCompositeMapperHelper2::BuildBufferObjects(
vtkCompositeMapperHelperData *hdata = iter->second;
hdata->StartVertex =
static_cast<unsigned int>(this->VBO->VertexCount);
for (int i = 0; i < 6; i++)
for (int i = 0; i < PrimitiveEnd; i++)
{
hdata->StartIndex[i] =
static_cast<unsigned int>(this->IndexArray[i].size());
......@@ -588,7 +571,7 @@ void vtkCompositeMapperHelper2::BuildBufferObjects(
hdata->NextVertex =
static_cast<unsigned int>(this->VBO->VertexCount);
voffset = static_cast<unsigned int>(this->VBO->VertexCount);
for (int i = 0; i < 6; i++)
for (int i = 0; i < PrimitiveEnd; i++)
{
hdata->NextIndex[i] =
static_cast<unsigned int>(this->IndexArray[i].size());
......@@ -598,47 +581,15 @@ void vtkCompositeMapperHelper2::BuildBufferObjects(
this->VBO->Upload(this->VBO->PackedVBO, vtkOpenGLBufferObject::ArrayBuffer);
this->VBO->PackedVBO.resize(0);
this->Points.IBO->IndexCount = this->IndexArray[0].size();
if (this->Points.IBO->IndexCount)
for (int i = PrimitiveStart; i < PrimitiveEnd; i++)
{
this->Points.IBO->Upload(this->IndexArray[0],
vtkOpenGLBufferObject::ElementArrayBuffer);
this->IndexArray[0].resize(0);
}
this->Lines.IBO->IndexCount = this->IndexArray[1].size();
if (this->Lines.IBO->IndexCount)
{
this->Lines.IBO->Upload(this->IndexArray[1],
vtkOpenGLBufferObject::ElementArrayBuffer);
this->IndexArray[1].resize(0);
}
this->Tris.IBO->IndexCount = this->IndexArray[2].size();
if (this->Tris.IBO->IndexCount)
{
this->Tris.IBO->Upload(this->IndexArray[2],
vtkOpenGLBufferObject::ElementArrayBuffer);
this->IndexArray[2].resize(0);
}
this->TriStrips.IBO->IndexCount = this->IndexArray[3].size();
if (this->TriStrips.IBO->IndexCount)
{
this->TriStrips.IBO->Upload(this->IndexArray[3],
vtkOpenGLBufferObject::ElementArrayBuffer);
this->IndexArray[3].resize(0);
}
this->TrisEdges.IBO->IndexCount = this->IndexArray[4].size();
if (this->TrisEdges.IBO->IndexCount)
{
this->TrisEdges.IBO->Upload(this->IndexArray[4],
vtkOpenGLBufferObject::ElementArrayBuffer);
this->IndexArray[4].resize(0);
}
this->TriStripsEdges.IBO->IndexCount = this->IndexArray[5].size();
if (this->TriStripsEdges.IBO->IndexCount)
{
this->TriStripsEdges.IBO->Upload(this->IndexArray[5],
vtkOpenGLBufferObject::ElementArrayBuffer);
this->IndexArray[5].resize(0);
this->Primitives[i].IBO->IndexCount = this->IndexArray[i].size();
if (this->Primitives[i].IBO->IndexCount)
{
this->Primitives[i].IBO->Upload(this->IndexArray[i],
vtkOpenGLBufferObject::ElementArrayBuffer);
this->IndexArray[i].resize(0);
}
}
// allocate as needed
......@@ -1002,6 +953,12 @@ void vtkCompositeMapperHelper2::AppendOneBufferObject(
this->IndexArray[5], prims[3], voffset, false);
}
if (prop->GetVertexVisibility())
{
vtkOpenGLIndexBufferObject::AppendVertexIndexBuffer(
this->IndexArray[PrimitiveVertices], prims, voffset);
}
// free up polydata if allocated due to apple bug
if (poly != hdata->Data)
{
......
......@@ -377,7 +377,7 @@ void vtkOpenGLGlyph3DHelper::GlyphRender(
// have opngl 3.2 to be safe
// this is because it seems that GLEW_ARB_vertex_array_object
// does not always handle the attributes for GLEW_ARB_instanced_arrays
this->Tris.VAO->SetForceEmulation(
this->Primitives[PrimitiveTris].VAO->SetForceEmulation(
!vtkOpenGLRenderWindow::GetContextSupportsOpenGL32());
this->CurrentInput = this->GetInput();
......@@ -422,13 +422,13 @@ void vtkOpenGLGlyph3DHelper::GlyphRender(
if (!primed)
{
this->RenderPieceStart(ren,actor);
this->UpdateShaders(this->Tris, ren, actor);
this->Tris.IBO->Bind();
this->UpdateShaders(this->Primitives[PrimitiveTris], ren, actor);
this->Primitives[PrimitiveTris].IBO->Bind();
primed = true;
}
// handle the middle
vtkShaderProgram *program = this->Tris.Program;
vtkShaderProgram *program = this->Primitives[PrimitiveTris].Program;
// Apply the extra transform
program->SetUniformMatrix4x4("GCMCMatrix", &(matrices[inPtId*16]));
......@@ -449,13 +449,13 @@ void vtkOpenGLGlyph3DHelper::GlyphRender(
glDrawRangeElements(mode, 0,
static_cast<GLuint>(this->VBO->VertexCount - 1),
static_cast<GLsizei>(this->Tris.IBO->IndexCount),
static_cast<GLsizei>(this->Primitives[PrimitiveTris].IBO->IndexCount),
GL_UNSIGNED_INT,
reinterpret_cast<const GLvoid *>(NULL));
}
if (primed)
{
this->Tris.IBO->Release();
this->Primitives[PrimitiveTris].IBO->Release();
this->RenderPieceFinish(ren,actor);
}
}
......@@ -520,19 +520,20 @@ void vtkOpenGLGlyph3DHelper::GlyphRenderInstances(
{
this->UsingInstancing = true;
this->RenderPieceStart(ren,actor);
this->UpdateShaders(this->Tris, ren, actor);
this->UpdateShaders(this->Primitives[PrimitiveTris], ren, actor);
// do the superclass and then reset a couple values
if (this->Tris.IBO->IndexCount && // we have points and one of
if (this->Primitives[PrimitiveTris].IBO->IndexCount && // we have points and one of
(this->VBOBuildTime > this->InstanceBuffersLoadTime ||
this->Tris.ShaderSourceTime > this->InstanceBuffersLoadTime ||
this->Primitives[PrimitiveTris].ShaderSourceTime > this->InstanceBuffersLoadTime ||
pointMTime > this->InstanceBuffersLoadTime.GetMTime()))
{
this->Tris.VAO->Bind();
this->Primitives[PrimitiveTris].VAO->Bind();
// add 3 new BOs?
this->MatrixBuffer->Bind();
this->MatrixBuffer->Upload(matrices, vtkOpenGLBufferObject::ArrayBuffer);
if (!this->Tris.VAO->AddAttributeMatrixWithDivisor(this->Tris.Program, this->MatrixBuffer,
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.");
......@@ -544,8 +545,8 @@ void vtkOpenGLGlyph3DHelper::GlyphRenderInstances(
this->NormalMatrixBuffer->Bind();
this->NormalMatrixBuffer->Upload(
normalMatrices, vtkOpenGLBufferObject::ArrayBuffer);
if (!this->Tris.VAO->AddAttributeMatrixWithDivisor(
this->Tris.Program, this->NormalMatrixBuffer,
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.");
......@@ -555,8 +556,8 @@ void vtkOpenGLGlyph3DHelper::GlyphRenderInstances(
this->ColorBuffer->Bind();
this->ColorBuffer->Upload(colors, vtkOpenGLBufferObject::ArrayBuffer);
if (!this->Tris.VAO->AddAttributeArrayWithDivisor(
this->Tris.Program, this->ColorBuffer,
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))
{
vtkErrorMacro(<< "Error setting 'diffuse color' in shader VAO.");
......@@ -566,26 +567,26 @@ void vtkOpenGLGlyph3DHelper::GlyphRenderInstances(
this->InstanceBuffersLoadTime.Modified();
}
this->Tris.IBO->Bind();
this->Primitives[PrimitiveTris].IBO->Bind();
#if GL_ES_VERSION_3_0 == 1
glDrawElementsInstanced(GL_TRIANGLES,
static_cast<GLsizei>(this->Tris.IBO->IndexCount),
GL_UNSIGNED_INT,
reinterpret_cast<const GLvoid *>(NULL),
numPts);
static_cast<GLsizei>(this->Tris.IBO->IndexCount),
GL_UNSIGNED_INT,
reinterpret_cast<const GLvoid *>(NULL),
numPts);
#else
if (GLEW_ARB_instanced_arrays)
{
glDrawElementsInstancedARB(GL_TRIANGLES,
static_cast<GLsizei>(this->Tris.IBO->IndexCount),
GL_UNSIGNED_INT,
reinterpret_cast<const GLvoid *>(NULL),
numPts);
static_cast<GLsizei>(this->Primitives[PrimitiveTris].IBO->IndexCount),
GL_UNSIGNED_INT,
reinterpret_cast<const GLvoid *>(NULL),
numPts);
}
#endif
vtkOpenGLCheckErrorMacro("failed after Render");
this->Tris.IBO->Release();
this->Primitives[PrimitiveTris].IBO->Release();
this->RenderPieceFinish(ren, actor);
}
#endif
......
......@@ -34,6 +34,7 @@ public:
vtkTimeStamp ShaderSourceTime;
vtkOpenGLVertexArrayObject *VAO;
vtkTimeStamp AttributeUpdateTime;
int PrimitiveType;
vtkOpenGLIndexBufferObject *IBO;
......