diff --git a/Filters/Core/Testing/Cxx/TestTubeFilter.cxx b/Filters/Core/Testing/Cxx/TestTubeFilter.cxx index f47b7ac8449..e241a60a99c 100644 --- a/Filters/Core/Testing/Cxx/TestTubeFilter.cxx +++ b/Filters/Core/Testing/Cxx/TestTubeFilter.cxx @@ -27,6 +27,7 @@ #include #include #include +#include #include namespace diff --git a/Geovis/Core/Testing/Cxx/TestGlobeSource.cxx b/Geovis/Core/Testing/Cxx/TestGlobeSource.cxx index 68fa40c1c30..b9fa201a746 100644 --- a/Geovis/Core/Testing/Cxx/TestGlobeSource.cxx +++ b/Geovis/Core/Testing/Cxx/TestGlobeSource.cxx @@ -31,6 +31,7 @@ #include "vtkSmartPointer.h" #include "vtkStdString.h" #include "vtkTestUtilities.h" +#include "vtkTexture.h" #include "vtkTransform.h" #include diff --git a/Geovis/Core/vtkGeoTerrain.cxx b/Geovis/Core/vtkGeoTerrain.cxx index 91867d01578..c75b9286429 100644 --- a/Geovis/Core/vtkGeoTerrain.cxx +++ b/Geovis/Core/vtkGeoTerrain.cxx @@ -50,6 +50,7 @@ #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkSmartPointer.h" +#include "vtkTexture.h" #include "vtkTimerLog.h" #include "vtkTransformFilter.h" #include "vtkXMLPolyDataWriter.h" @@ -341,11 +342,11 @@ void vtkGeoTerrain::AddActors( sameTexture = ( !textureNode1 || actor->GetProperty()->GetNumberOfTextures() < 1 || - actor->GetProperty()->GetTexture(vtkProperty::VTK_TEXTURE_UNIT_0) == textureNode1->GetTexture() + actor->GetProperty()->GetTexture("VTK_TEXTURE_UNIT_0") == textureNode1->GetTexture() ) && ( !textureNode2 || actor->GetProperty()->GetNumberOfTextures() < 2 || - actor->GetProperty()->GetTexture(vtkProperty::VTK_TEXTURE_UNIT_1) == textureNode2->GetTexture() + actor->GetProperty()->GetTexture("VTK_TEXTURE_UNIT_1") == textureNode2->GetTexture() ); } else @@ -387,17 +388,17 @@ void vtkGeoTerrain::AddActors( if (multiTexturing && textureUnits > 1) { // Multi texturing - mapper->MapDataArrayToMultiTextureAttribute(vtkProperty::VTK_TEXTURE_UNIT_0, + mapper->MapDataArrayToMultiTextureAttribute("VTK_TEXTURE_UNIT_0", "LatLong", vtkDataObject::FIELD_ASSOCIATION_POINTS); textureNode1->GetTexture()->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_REPLACE); - actor->GetProperty()->SetTexture(vtkProperty::VTK_TEXTURE_UNIT_0, textureNode1->GetTexture()); + actor->GetProperty()->SetTexture("VTK_TEXTURE_UNIT_0", textureNode1->GetTexture()); if (textureNode2) { - mapper->MapDataArrayToMultiTextureAttribute(vtkProperty::VTK_TEXTURE_UNIT_1, + mapper->MapDataArrayToMultiTextureAttribute("VTK_TEXTURE_UNIT_1", "LatLong", vtkDataObject::FIELD_ASSOCIATION_POINTS); textureNode2->GetTexture()->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_ADD); - actor->GetProperty()->SetTexture(vtkProperty::VTK_TEXTURE_UNIT_1, textureNode2->GetTexture()); + actor->GetProperty()->SetTexture("VTK_TEXTURE_UNIT_1", textureNode2->GetTexture()); } } else @@ -438,11 +439,11 @@ void vtkGeoTerrain::AddActors( sameTexture = ( !textureNode1 || actor->GetProperty()->GetNumberOfTextures() < 1 || - actor->GetProperty()->GetTexture(vtkProperty::VTK_TEXTURE_UNIT_0) == textureNode1->GetTexture() + actor->GetProperty()->GetTexture("VTK_TEXTURE_UNIT_0") == textureNode1->GetTexture() ) && ( !textureNode2 || actor->GetProperty()->GetNumberOfTextures() < 2 || - actor->GetProperty()->GetTexture(vtkProperty::VTK_TEXTURE_UNIT_1) == textureNode2->GetTexture() + actor->GetProperty()->GetTexture("VTK_TEXTURE_UNIT_1") == textureNode2->GetTexture() ); } else diff --git a/IO/Export/vtkSingleVTPExporter.cxx b/IO/Export/vtkSingleVTPExporter.cxx index 1c655a27201..13c969b8677 100644 --- a/IO/Export/vtkSingleVTPExporter.cxx +++ b/IO/Export/vtkSingleVTPExporter.cxx @@ -36,6 +36,7 @@ #include "vtkProperty.h" #include "vtkRenderWindow.h" #include "vtkRendererCollection.h" +#include "vtkTexture.h" #include "vtkTransform.h" #include "vtkTriangleFilter.h" #include "vtkXMLPolyDataWriter.h" diff --git a/IO/Import/vtkOBJImporterInternals.cxx b/IO/Import/vtkOBJImporterInternals.cxx index ac1201d39a6..5b76e36cc60 100644 --- a/IO/Import/vtkOBJImporterInternals.cxx +++ b/IO/Import/vtkOBJImporterInternals.cxx @@ -20,6 +20,7 @@ #include "vtkProperty.h" #include "vtkRenderer.h" #include "vtkRenderWindow.h" +#include "vtkTexture.h" #include "vtksys/SystemTools.hxx" #include "vtkTransform.h" diff --git a/Rendering/Annotation/vtkLegendBoxActor.cxx b/Rendering/Annotation/vtkLegendBoxActor.cxx index 07bb305b4b3..9196b3116ff 100644 --- a/Rendering/Annotation/vtkLegendBoxActor.cxx +++ b/Rendering/Annotation/vtkLegendBoxActor.cxx @@ -28,6 +28,7 @@ #include "vtkTexturedActor2D.h" #include "vtkTextMapper.h" #include "vtkTextProperty.h" +#include "vtkTexture.h" #include "vtkTransform.h" #include "vtkTransformPolyDataFilter.h" #include "vtkViewport.h" diff --git a/Rendering/Core/Testing/Cxx/TestTStripsColorsTCoords.cxx b/Rendering/Core/Testing/Cxx/TestTStripsColorsTCoords.cxx index 76ab7bc9c6f..e1081e40ffa 100644 --- a/Rendering/Core/Testing/Cxx/TestTStripsColorsTCoords.cxx +++ b/Rendering/Core/Testing/Cxx/TestTStripsColorsTCoords.cxx @@ -89,7 +89,7 @@ int TestTStripsColorsTCoords(int argc, char *argv[]) polyData->Delete(); vtkActor *actor = vtkActor::New(); - actor->GetProperty()->SetTexture("texture",texture); + actor->GetProperty()->SetTexture("mytexture",texture); texture->Delete(); actor->SetMapper(mapper); mapper->Delete(); diff --git a/Rendering/Core/Testing/Cxx/TestTStripsNormalsColorsTCoords.cxx b/Rendering/Core/Testing/Cxx/TestTStripsNormalsColorsTCoords.cxx index dd64e7dc00c..922b01aaaf6 100644 --- a/Rendering/Core/Testing/Cxx/TestTStripsNormalsColorsTCoords.cxx +++ b/Rendering/Core/Testing/Cxx/TestTStripsNormalsColorsTCoords.cxx @@ -88,7 +88,7 @@ int TestTStripsNormalsColorsTCoords(int argc, char *argv[]) polyData->Delete(); vtkActor *actor = vtkActor::New(); - actor->GetProperty()->SetTexture("texture",texture); + actor->GetProperty()->SetTexture("mytexture",texture); texture->Delete(); actor->SetMapper(mapper); mapper->Delete(); diff --git a/Rendering/Core/Testing/Cxx/TestTStripsNormalsTCoords.cxx b/Rendering/Core/Testing/Cxx/TestTStripsNormalsTCoords.cxx index a5f5a3fbad7..5b2cd040d09 100644 --- a/Rendering/Core/Testing/Cxx/TestTStripsNormalsTCoords.cxx +++ b/Rendering/Core/Testing/Cxx/TestTStripsNormalsTCoords.cxx @@ -71,7 +71,7 @@ int TestTStripsNormalsTCoords(int argc, char *argv[]) polyData->Delete(); vtkActor *actor = vtkActor::New(); - actor->GetProperty()->SetTexture("texture",texture); + actor->GetProperty()->SetTexture("mytexture",texture); texture->Delete(); actor->SetMapper(mapper); mapper->Delete(); diff --git a/Rendering/Core/Testing/Cxx/TestTStripsTCoords.cxx b/Rendering/Core/Testing/Cxx/TestTStripsTCoords.cxx index 61c85bb7544..fdea0095c7b 100644 --- a/Rendering/Core/Testing/Cxx/TestTStripsTCoords.cxx +++ b/Rendering/Core/Testing/Cxx/TestTStripsTCoords.cxx @@ -72,7 +72,7 @@ int TestTStripsTCoords(int argc, char *argv[]) polyData->Delete(); vtkActor *actor = vtkActor::New(); - actor->GetProperty()->SetTexture("texture",texture); + actor->GetProperty()->SetTexture("mytexture",texture); texture->Delete(); actor->SetMapper(mapper); mapper->Delete(); diff --git a/Rendering/Core/vtkPolyDataMapper.cxx b/Rendering/Core/vtkPolyDataMapper.cxx index 99ef8087fb5..33e6ed85e7d 100644 --- a/Rendering/Core/vtkPolyDataMapper.cxx +++ b/Rendering/Core/vtkPolyDataMapper.cxx @@ -183,13 +183,25 @@ void vtkPolyDataMapper::MapDataArrayToVertexAttribute( vtkErrorMacro("Not implemented at this level..."); } -//---------------------------------------------------------------------------- +#ifndef VTK_LEGACY_REMOVE void vtkPolyDataMapper::MapDataArrayToMultiTextureAttribute( int vtkNotUsed(unit), const char* vtkNotUsed(dataArrayName), int vtkNotUsed(fieldAssociation), int vtkNotUsed(componentno) ) +{ + VTK_LEGACY_BODY(vtkPolyDataMapper::MapDataArrayToMultiTextureAttribute, "VTK 8.2"); +} +#endif + +//---------------------------------------------------------------------------- +void vtkPolyDataMapper::MapDataArrayToMultiTextureAttribute( + const char* vtkNotUsed(tname), + const char* vtkNotUsed(dataArrayName), + int vtkNotUsed(fieldAssociation), + int vtkNotUsed(componentno) + ) { vtkErrorMacro("Not implemented at this level..."); } diff --git a/Rendering/Core/vtkPolyDataMapper.h b/Rendering/Core/vtkPolyDataMapper.h index 10cd232a5a7..6ce9624ff68 100644 --- a/Rendering/Core/vtkPolyDataMapper.h +++ b/Rendering/Core/vtkPolyDataMapper.h @@ -27,7 +27,7 @@ #include "vtkRenderingCoreModule.h" // For export macro #include "vtkMapper.h" -#include "vtkTexture.h" // used to include texture unit enum. +//#include "vtkTexture.h" // used to include texture unit enum. class vtkPolyData; class vtkRenderer; @@ -111,15 +111,24 @@ class VTKRENDERINGCORE_EXPORT vtkPolyDataMapper : public vtkMapper * (vtkDataObject::FIELD_ASSOCIATION_CELLS). * componentno indicates which component from the data array must be passed as * the attribute. If -1, then all components are passed. + * Currently only point data is supported. */ virtual void MapDataArrayToVertexAttribute( const char* vertexAttributeName, const char* dataArrayName, int fieldAssociation, int componentno = -1); + // Specify a data array to use as the texture coordinate + // for a named texture. See vtkProperty.h for how to + // name textures. virtual void MapDataArrayToMultiTextureAttribute( - int unit, + const char *textureName, const char* dataArrayName, int fieldAssociation, int componentno = -1); + // deprecated in favor of the const char * signature + VTK_LEGACY(virtual void MapDataArrayToMultiTextureAttribute( + int unit, + const char* dataArrayName, int fieldAssociation, int componentno = -1)); + /** * Remove a vertex attribute mapping. */ diff --git a/Rendering/Core/vtkProperty.cxx b/Rendering/Core/vtkProperty.cxx index 12406044608..465f8c0785e 100644 --- a/Rendering/Core/vtkProperty.cxx +++ b/Rendering/Core/vtkProperty.cxx @@ -25,21 +25,8 @@ #include #include -#include #include -class vtkPropertyInternals -{ -public: - // key==texture unit, value==texture - typedef std::map > MapOfTextures; - MapOfTextures Textures; - - // key==texture name, value==texture-unit. - typedef std::map MapOfTextureNames; - MapOfTextureNames TextureNames; -}; - vtkCxxSetObjectMacro(vtkProperty, Information, vtkInformation); //---------------------------------------------------------------------------- @@ -98,7 +85,6 @@ vtkProperty::vtkProperty() this->Shading = 0; this->MaterialName = nullptr; - this->Internals = new vtkPropertyInternals; this->Information = vtkInformation::New(); this->Information->Register(this); @@ -108,8 +94,8 @@ vtkProperty::vtkProperty() //---------------------------------------------------------------------------- vtkProperty::~vtkProperty() { + this->RemoveAllTextures(); this->SetMaterialName(nullptr); - delete this->Internals; this->SetInformation(nullptr); } @@ -147,11 +133,10 @@ void vtkProperty::DeepCopy(vtkProperty *p) this->SetShading(p->GetShading()); this->RemoveAllTextures(); - vtkPropertyInternals::MapOfTextures::iterator iter = - p->Internals->Textures.begin(); - for (;iter != p->Internals->Textures.end(); ++iter) + auto iter = p->Textures.begin(); + for (;iter != p->Textures.end(); ++iter) { - this->Internals->Textures[iter->first] = iter->second; + this->Textures[iter->first] = iter->second; } // TODO: need to pass shader variables. } @@ -252,149 +237,86 @@ void vtkProperty::GetColor(double &r, double &g, double &b) //---------------------------------------------------------------------------- void vtkProperty::SetTexture(const char* name, vtkTexture* tex) { - vtkPropertyInternals::MapOfTextureNames::iterator iter = - this->Internals->TextureNames.find(std::string(name)); - if (iter != this->Internals->TextureNames.end()) - { - vtkWarningMacro("Texture with name " << name - << " exists. It will be replaced."); - } - - // Locate a free texture unit. - int texture_unit = -1; - for (int cc=0; ; cc++) + auto iter = + this->Textures.find(std::string(name)); + if (iter != this->Textures.end()) { - if (this->Internals->Textures.find(cc) == this->Internals->Textures.end()) + // same value? + if (iter->second == tex) { - texture_unit = cc; - break; + return; } + vtkWarningMacro("Texture with name " << name + << " exists. It will be replaced."); + iter->second->UnRegister(this); } - this->Internals->TextureNames[name] = texture_unit; - this->SetTexture(texture_unit, tex); + tex->Register(this); + this->Textures[name] = tex; } //---------------------------------------------------------------------------- vtkTexture* vtkProperty::GetTexture(const char* name) { - vtkPropertyInternals::MapOfTextureNames::iterator iter = - this->Internals->TextureNames.find(std::string(name)); - if (iter == this->Internals->TextureNames.end()) + auto iter = + this->Textures.find(std::string(name)); + if (iter == this->Textures.end()) { return nullptr; } - return this->GetTexture(iter->second); + return iter->second; } +#ifndef VTK_LEGACY_REMOVE //---------------------------------------------------------------------------- -void vtkProperty::SetTexture(int unit, vtkTexture* tex) +void vtkProperty::SetTexture(int, vtkTexture*) { - vtkPropertyInternals::MapOfTextures::iterator iter = - this->Internals->Textures.find(unit); - if (iter != this->Internals->Textures.end()) - { - vtkWarningMacro("Replacing texture previously assigned to unit " << unit); - } - this->Internals->Textures[unit] = tex; + VTK_LEGACY_BODY(vtkProperty::SetTexture, "VTK 8.2"); } //---------------------------------------------------------------------------- -vtkTexture* vtkProperty::GetTexture(int unit) +vtkTexture* vtkProperty::GetTexture(int) { - vtkPropertyInternals::MapOfTextures::iterator iter = - this->Internals->Textures.find(unit); - if (iter != this->Internals->Textures.end()) - { - return iter->second; - } - vtkErrorMacro("No texture assigned to texture unit " << unit << " exists."); + VTK_LEGACY_BODY(vtkProperty::GetTexture, "VTK 8.2"); return nullptr; } //---------------------------------------------------------------------------- -int vtkProperty::GetNumberOfTextures() +void vtkProperty::RemoveTexture(int) { - return static_cast(this->Internals->Textures.size()); + VTK_LEGACY_BODY(vtkProperty::RemoveTexture, "VTK 8.2"); } -//---------------------------------------------------------------------------- -void vtkProperty::RemoveTexture(const char* name) -{ - vtkPropertyInternals::MapOfTextureNames::iterator iter = - this->Internals->TextureNames.find(std::string(name)); - if (iter != this->Internals->TextureNames.end()) - { - this->RemoveTexture(iter->second); - this->Internals->TextureNames.erase(iter); - } -} +#endif //---------------------------------------------------------------------------- -void vtkProperty::RemoveTexture(int unit) -{ - vtkPropertyInternals::MapOfTextures::iterator iter = - this->Internals->Textures.find(unit); - if (iter != this->Internals->Textures.end()) - { - this->Internals->Textures.erase(unit); - } -} - -//---------------------------------------------------------------------------- -void vtkProperty::RemoveAllTextures() -{ - this->Internals->TextureNames.clear(); - this->Internals->Textures.clear(); -} - -//---------------------------------------------------------------------------- -vtkTexture* vtkProperty::GetTextureAtIndex(int index) +int vtkProperty::GetNumberOfTextures() { - vtkPropertyInternals::MapOfTextures::iterator iter = - this->Internals->Textures.begin(); - for (int id = 0; iter != this->Internals->Textures.end(); ++iter, ++id) - { - if (id == index) - { - return iter->second; - } - } - - vtkErrorMacro("No texture at index " << index ); - return nullptr; + return static_cast(this->Textures.size()); } //---------------------------------------------------------------------------- -int vtkProperty::GetTextureUnitAtIndex(int index) +void vtkProperty::RemoveTexture(const char* name) { - vtkPropertyInternals::MapOfTextures::iterator iter = - this->Internals->Textures.begin(); - for (int id = 0; iter != this->Internals->Textures.end(); ++iter, ++id) + auto iter = + this->Textures.find(std::string(name)); + if (iter != this->Textures.end()) { - if (id == index) - { - return iter->first; - } + iter->second->UnRegister(this); + this->Textures.erase(iter); } - - vtkErrorMacro("No texture at index " << index ); - return -1; } //---------------------------------------------------------------------------- -int vtkProperty::GetTextureUnit(const char* name) +void vtkProperty::RemoveAllTextures() { - vtkPropertyInternals::MapOfTextureNames::iterator iter = - this->Internals->TextureNames.find(name); - if (iter != this->Internals->TextureNames.end()) + while (this->Textures.size()) { - return iter->second; + auto iter = this->Textures.begin(); + iter->second->UnRegister(this); + this->Textures.erase(iter); } - - vtkErrorMacro("No texture with name " << name); - return -1; } //---------------------------------------------------------------------------- diff --git a/Rendering/Core/vtkProperty.h b/Rendering/Core/vtkProperty.h index 73c6ec0e2ca..0c914c3cdc0 100644 --- a/Rendering/Core/vtkProperty.h +++ b/Rendering/Core/vtkProperty.h @@ -33,6 +33,7 @@ #include "vtkRenderingCoreModule.h" // For export macro #include "vtkObject.h" +#include // used for ivar // shading models #define VTK_FLAT 0 @@ -427,7 +428,9 @@ class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject * Set/Get the texture object to control rendering texture maps. This will * be a vtkTexture object. A property does not need to have an associated * texture map and multiple properties can share one texture. Textures - * must be assigned unique names. + * must be assigned unique names. Note that for texture blending the + * textures will be rendering is alphabetical order and after any texture + * defined in the actor. */ void SetTexture(const char* name, vtkTexture* texture); vtkTexture* GetTexture(const char* name); @@ -440,14 +443,13 @@ class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject * texture map and multiple properties can share one texture. Textures * must be assigned unique names. */ - void SetTexture(int unit, vtkTexture* texture); - vtkTexture* GetTexture(int unit); - void RemoveTexture(int unit); + VTK_LEGACY(void SetTexture(int unit, vtkTexture* texture)); + VTK_LEGACY(vtkTexture* GetTexture(int unit)); + VTK_LEGACY(void RemoveTexture(int unit)); //@} /** - * Remove a texture from the collection. Note that the - * indices of all the subsequent textures, if any, will change. + * Remove a texture from the collection. */ void RemoveTexture(const char* name); @@ -461,6 +463,12 @@ class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject */ int GetNumberOfTextures(); + /** + * Returns all the textures in this property and their names + */ + std::map &GetAllTextures() { + return this->Textures; } + /** * Release any graphics resources that are being consumed by this * property. The parameter window could be used to determine which graphic @@ -468,10 +476,9 @@ class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject */ virtual void ReleaseGraphicsResources(vtkWindow *win); - /** - * Used to specify which texture unit a texture will use. - * Only relevant when multitexturing. - */ + +#ifndef VTK_LEGACY_REMOVE + // deprecated. Textures should use names not units enum VTKTextureUnit { VTK_TEXTURE_UNIT_0 = 0, @@ -483,6 +490,7 @@ class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject VTK_TEXTURE_UNIT_6, VTK_TEXTURE_UNIT_7 }; +#endif //@{ /** @@ -533,12 +541,8 @@ class VTKRENDERINGCORE_EXPORT vtkProperty : public vtkObject char* MaterialName; - // FIXME: - // Don't use these methods. They will be removed. They are provided only - // for the time-being. - vtkTexture* GetTextureAtIndex(int index); - int GetTextureUnitAtIndex(int index); - int GetTextureUnit(const char* name); + typedef std::map MapOfTextures; + MapOfTextures Textures; // Arbitrary extra information associated with this Property. vtkInformation* Information; diff --git a/Rendering/OpenGL2/Testing/Cxx/CMakeLists.txt b/Rendering/OpenGL2/Testing/Cxx/CMakeLists.txt index c13d0e220fc..a47d5f02d88 100644 --- a/Rendering/OpenGL2/Testing/Cxx/CMakeLists.txt +++ b/Rendering/OpenGL2/Testing/Cxx/CMakeLists.txt @@ -21,6 +21,7 @@ vtk_add_test_cxx(vtkRenderingOpenGL2CxxTests tests TestGlyph3DMapperPickability.cxx,NO_DATA TestLightingMapLuminancePass.cxx TestLightingMapNormalsPass.cxx + TestMultiTexturing.cxx TestOffscreenRenderingResize.cxx TestPointFillPass.cxx TestPropPicker2Renderers.cxx,NO_DATA diff --git a/Rendering/OpenGL2/Testing/Cxx/TestCubeMap2.cxx b/Rendering/OpenGL2/Testing/Cxx/TestCubeMap2.cxx index 813569b107f..894bcc610a9 100644 --- a/Rendering/OpenGL2/Testing/Cxx/TestCubeMap2.cxx +++ b/Rendering/OpenGL2/Testing/Cxx/TestCubeMap2.cxx @@ -32,6 +32,7 @@ #include "vtkSkybox.h" #include "vtkSmartPointer.h" #include "vtkTestUtilities.h" +#include "vtkTexture.h" #include "vtkLight.h" @@ -141,7 +142,7 @@ int TestCubeMap2(int argc, char *argv[]) vtkShader::Fragment, "//VTK::Light::Impl", // replace true, // before the standard replacements - " vec3 cubeColor = texture(texture_0, normalize(TexCoords)).xyz;\n" + " vec3 cubeColor = texture(actortexture, normalize(TexCoords)).xyz;\n" "//VTK::Light::Impl\n" " gl_FragData[0] = vec4(ambientColor + diffuse + specular + specularColor*cubeColor, opacity);\n" , // we still want the default diff --git a/Rendering/OpenGL2/Testing/Cxx/TestMultiTexturing.cxx b/Rendering/OpenGL2/Testing/Cxx/TestMultiTexturing.cxx new file mode 100644 index 00000000000..cbd464849bf --- /dev/null +++ b/Rendering/OpenGL2/Testing/Cxx/TestMultiTexturing.cxx @@ -0,0 +1,95 @@ +#include "vtkActor.h" +#include "vtkCamera.h" +#include "vtkFloatArray.h" +#include "vtkJPEGReader.h" +#include "vtkNew.h" +#include "vtkOpenGLRenderWindow.h" +#include "vtkPointData.h" +#include "vtkPolyDataMapper.h" +#include "vtkProperty.h" +#include "vtkRegressionTestImage.h" +#include "vtkRenderer.h" +#include "vtkRenderWindowInteractor.h" +#include "vtkTestUtilities.h" +#include "vtkTexture.h" +#include "vtkTexturedSphereSource.h" +#include "vtkTIFFReader.h" + +//---------------------------------------------------------------------------- +int TestMultiTexturing(int argc, char* argv[]) +{ + vtkNew renderer; + renderer->SetBackground(0.5, 0.5, 0.5); + vtkNew renderWindow; + renderWindow->SetSize(300, 300); + renderWindow->AddRenderer(renderer); + vtkNew iren; + iren->SetRenderWindow(renderWindow); + + vtkNew sphere; + sphere->SetThetaResolution(64); + sphere->SetPhiResolution(32); + sphere->Update(); + vtkPolyData *pd = sphere->GetOutput(); + + vtkFloatArray *tcoord = + vtkFloatArray::SafeDownCast(pd->GetPointData()->GetTCoords()); + vtkNew tcoord2; + tcoord2->SetNumberOfComponents(2); + tcoord2->SetNumberOfTuples(tcoord->GetNumberOfTuples()); + for (int i = 0; i < tcoord->GetNumberOfTuples(); ++i) + { + float tmp[2]; + tcoord->GetTypedTuple(i, tmp); + // mess with the tcoords to make sure + // this array is getting used + tcoord2->SetTuple2(i, tmp[0], tmp[1]*2.0); + } + tcoord2->SetName("tcoord2"); + pd->GetPointData()->AddArray(tcoord2); + + vtkNew mapper; + mapper->SetInputData(pd); + vtkNew actor; + renderer->AddActor(actor); + actor->SetMapper(mapper); + + std::string file1 = vtkTestUtilities::ExpandDataFileName(argc, argv, + "Data/GIS/raster.tif"); + vtkNew reader1; + reader1->SetFileName(file1.c_str()); + vtkNew tex1; + tex1->InterpolateOn(); + tex1->SetInputConnection(reader1->GetOutputPort()); + actor->GetProperty()->SetTexture("earth_color", tex1); + + std::string file2 = vtkTestUtilities::ExpandDataFileName(argc, argv, + "Data/clouds.jpeg"); + vtkNew reader2; + reader2->SetFileName(file2.c_str()); + vtkNew tex2; + tex2->InterpolateOn(); + tex2->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_MODULATE); + tex2->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_ADD); + tex2->SetInputConnection(reader2->GetOutputPort()); + actor->GetProperty()->SetTexture("skyclouds", tex2); + + mapper->MapDataArrayToMultiTextureAttribute( + "skyclouds", "tcoord2", vtkDataObject::FIELD_ASSOCIATION_POINTS); + + 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 ); + if ( retVal == vtkRegressionTester::DO_INTERACTOR) + { + iren->Start(); + } + + return !retVal; +} diff --git a/Rendering/OpenGL2/Testing/Cxx/TestSRGB.cxx b/Rendering/OpenGL2/Testing/Cxx/TestSRGB.cxx index 9865afd2409..9def3c7ab81 100644 --- a/Rendering/OpenGL2/Testing/Cxx/TestSRGB.cxx +++ b/Rendering/OpenGL2/Testing/Cxx/TestSRGB.cxx @@ -24,6 +24,7 @@ #include "vtkRenderer.h" #include "vtkOpenGLRenderWindow.h" #include "vtkRenderWindowInteractor.h" +#include "vtkTexture.h" #include "vtkTestUtilities.h" #include "vtkLight.h" diff --git a/Rendering/OpenGL2/Testing/Cxx/TestSphereMap.cxx b/Rendering/OpenGL2/Testing/Cxx/TestSphereMap.cxx index 88ba05fb0d7..c5bf4d78023 100644 --- a/Rendering/OpenGL2/Testing/Cxx/TestSphereMap.cxx +++ b/Rendering/OpenGL2/Testing/Cxx/TestSphereMap.cxx @@ -31,6 +31,7 @@ #include "vtkSkybox.h" #include "vtkSmartPointer.h" #include "vtkTestUtilities.h" +#include "vtkTexture.h" #include "vtkLight.h" @@ -123,7 +124,7 @@ int TestSphereMap(int argc, char *argv[]) true, // before the standard replacements "//VTK::Light::Impl\n" " float phix = length(vec2(TexCoords.x, TexCoords.z));\n" - " vec3 skyColor = texture(texture_0, vec2(0.5*atan(TexCoords.z, TexCoords.x)/3.1415927 + 0.5, atan(TexCoords.y,phix)/3.1415927 + 0.5)).xyz;\n" + " vec3 skyColor = texture(actortexture, vec2(0.5*atan(TexCoords.z, TexCoords.x)/3.1415927 + 0.5, atan(TexCoords.y,phix)/3.1415927 + 0.5)).xyz;\n" " gl_FragData[0] = vec4(ambientColor + diffuse + specular + specularColor*skyColor, opacity);\n" , // we still want the default false // only do it once diff --git a/Rendering/OpenGL2/Testing/Data/Baseline/TestMultiTexturing.png.md5 b/Rendering/OpenGL2/Testing/Data/Baseline/TestMultiTexturing.png.md5 new file mode 100644 index 00000000000..5cf18a1b350 --- /dev/null +++ b/Rendering/OpenGL2/Testing/Data/Baseline/TestMultiTexturing.png.md5 @@ -0,0 +1 @@ +5d668a43f546defc64022ed13ad30dc3 diff --git a/Rendering/OpenGL2/vtkCompositePolyDataMapper2.cxx b/Rendering/OpenGL2/vtkCompositePolyDataMapper2.cxx index 08d0237f8a2..8d16d5ffb8b 100644 --- a/Rendering/OpenGL2/vtkCompositePolyDataMapper2.cxx +++ b/Rendering/OpenGL2/vtkCompositePolyDataMapper2.cxx @@ -838,7 +838,7 @@ void vtkCompositeMapperHelper2::AppendOneBufferObject( "vertexMC", poly->GetPoints()->GetData(), VTK_FLOAT); this->VBOs->AppendDataArray("normalMC", n, VTK_FLOAT); this->VBOs->AppendDataArray("scalarColor", c, VTK_UNSIGNED_CHAR); - this->VBOs->AppendDataArray("tcoordMC", tcoords, VTK_FLOAT); + this->VBOs->AppendDataArray("tcoord", tcoords, VTK_FLOAT); // now create the IBOs vtkOpenGLIndexBufferObject::AppendPointIndexBuffer( diff --git a/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx b/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx index 5fce6163519..ddc5180938b 100644 --- a/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx +++ b/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx @@ -432,12 +432,26 @@ vtkMTimeType vtkOpenGLPolyDataMapper::GetRenderPassStageMTime(vtkActor *actor) return renderPassMTime; } +std::string vtkOpenGLPolyDataMapper::GetTextureCoordinateName(const char *tname) +{ + for (auto it : this->ExtraAttributes) + { + if (it.second.TextureName == tname) + { + return it.first; + } + } + return std::string("tcoord"); +} + //----------------------------------------------------------------------------- bool vtkOpenGLPolyDataMapper::HaveTextures(vtkActor *actor) { return (this->GetNumberOfTextures(actor) > 0); } +typedef std::pair texinfo; + //----------------------------------------------------------------------------- unsigned int vtkOpenGLPolyDataMapper::GetNumberOfTextures(vtkActor *actor) { @@ -455,21 +469,22 @@ unsigned int vtkOpenGLPolyDataMapper::GetNumberOfTextures(vtkActor *actor) } //----------------------------------------------------------------------------- -std::vector vtkOpenGLPolyDataMapper::GetTextures(vtkActor *actor) +std::vector vtkOpenGLPolyDataMapper::GetTextures(vtkActor *actor) { - std::vector res; + std::vector res; if (this->ColorTextureMap) { - res.push_back(this->InternalColorTexture); + res.push_back(texinfo(this->InternalColorTexture, "colortexture")); } if (actor->GetTexture()) { - res.push_back(actor->GetTexture()); + res.push_back(texinfo(actor->GetTexture(), "actortexture")); } - for (int i = 0; i < actor->GetProperty()->GetNumberOfTextures(); i++) + auto textures = actor->GetProperty()->GetAllTextures(); + for (auto ti : textures) { - res.push_back(actor->GetProperty()->GetTexture(i)); + res.push_back(texinfo(ti.second,ti.first)); } return res; } @@ -625,7 +640,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderColor( !this->DrawingEdgesOrVertices) { colorImpl += - " vec4 texColor = texture(texture_0, tcoordVCVSOutput.st);\n" + " vec4 texColor = texture(colortexture, tcoordVCVSOutput.st);\n" " vec3 ambientColor = ambientIntensity * texColor.rgb;\n" " vec3 diffuseColor = diffuseIntensity * texColor.rgb;\n" " float opacity = opacityUniform * texColor.a;"; @@ -886,7 +901,8 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderTCoord( return; } - if (!this->HaveTextures(actor)) + std::vector textures = this->GetTextures(actor); + if (textures.size() == 0) { return; } @@ -895,29 +911,37 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderTCoord( std::string GSSource = shaders[vtkShader::Geometry]->GetSource(); std::string FSSource = shaders[vtkShader::Fragment]->GetSource(); - // define texture maps if we have them + // always define texture maps if we have them std::string tMapDecFS; - std::vector textures = this->GetTextures(actor); - for (size_t i = 0; i < textures.size(); ++i) + for (auto it : textures) { - vtkTexture *texture = textures[i]; - - std::stringstream ss; - if (texture->GetCubeMap()) + if (it.first->GetCubeMap()) { - ss << "uniform samplerCube texture_" << i << ";\n"; + tMapDecFS += "uniform samplerCube "; } else { - ss << "uniform sampler2D texture_" << i << ";\n"; + tMapDecFS += "uniform sampler2D "; } - tMapDecFS += ss.str(); + tMapDecFS += it.second + ";\n"; } vtkShaderProgram::Substitute(FSSource, "//VTK::TMap::Dec", tMapDecFS); + // now handle each texture coordinate + std::set tcoordnames; + for (auto it : textures) + { + // do we have special tcoords for this texture? + std::string tcoordname = this->GetTextureCoordinateName(it.second.c_str()); + int tcoordComps = this->VBOs->GetNumberOfComponents(tcoordname.c_str()); + if (tcoordComps == 1 || tcoordComps == 2) + { + tcoordnames.insert(tcoordname); + } + } + // if no texture coordinates then we are done - int tcoordComps = this->VBOs->GetNumberOfComponents("tcoordMC"); - if (tcoordComps != 1 && tcoordComps != 2) + if (tcoordnames.size() == 0) { shaders[vtkShader::Vertex]->SetSource(VSSource); shaders[vtkShader::Geometry]->SetSource(GSSource); @@ -925,60 +949,99 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderTCoord( return; } - // handle texture transformation matrix + // handle texture transformation matrix and create the + // vertex shader texture coordinate implementation + // code for all texture coordinates. vtkInformation *info = actor->GetPropertyKeys(); + std::string vsimpl; if (info && info->Has(vtkProp::GeneralTextureTransform())) { vtkShaderProgram::Substitute(VSSource, "//VTK::TCoord::Dec", "//VTK::TCoord::Dec\n" "uniform mat4 tcMatrix;", false); - if (tcoordComps == 1) - { - vtkShaderProgram::Substitute(VSSource, "//VTK::TCoord::Impl", - "vec4 tcoordTmp = tcMatrix*vec4(tcoordMC,0.0,0.0,1.0);\n" - "tcoordVCVSOutput = tcoordTmp.x/tcoordTmp.w;"); - } - else + for (auto it : tcoordnames) { - vtkShaderProgram::Substitute(VSSource, "//VTK::TCoord::Impl", - "vec4 tcoordTmp = tcMatrix*vec4(tcoordMC,0.0,1.0);\n" - "tcoordVCVSOutput = tcoordTmp.xy/tcoordTmp.w;"); + int tcoordComps = this->VBOs->GetNumberOfComponents(it.c_str()); + if (tcoordComps == 1) + { + vsimpl = vsimpl + "vec4 " + it + "Tmp = tcMatrix*vec4(" + it + ",0.0,0.0,1.0);\n" + + it + "VCVSOutput = " + it + "Tmp.x/" + it + "Tmp.w;\n"; + } + else + { + vsimpl = vsimpl + "vec4 " + it + "Tmp = tcMatrix*vec4(" + it + ",0.0,1.0);\n" + + it + "VCVSOutput = " + it + "Tmp.xy/" + it + "Tmp.w;\n"; + } } } else { - vtkShaderProgram::Substitute(VSSource, "//VTK::TCoord::Impl", - "tcoordVCVSOutput = tcoordMC;"); + for (auto it : tcoordnames) + { + vsimpl = vsimpl + it + "VCVSOutput = " + it + ";\n"; + } } + vtkShaderProgram::Substitute(VSSource, "//VTK::TCoord::Impl", vsimpl); - // handle texture maps if we have them (coords may be computed) - std::string tCoordType; - std::string tCoordImpFSPre; - std::string tCoordImpFSPost; - if (tcoordComps == 1) + // now create the rest of the vertex and geometry shader code + std::string vsdec; + std::string gsdec; + std::string gsimpl; + std::string fsdec; + for (auto it : tcoordnames) { - tCoordType = "float"; - tCoordImpFSPre = "vec2("; - tCoordImpFSPost = ", 0.0)"; - } - else - { - tCoordType = "vec2"; - tCoordImpFSPre = ""; - tCoordImpFSPost = ""; + int tcoordComps = this->VBOs->GetNumberOfComponents(it.c_str()); + std::string tCoordType; + if (tcoordComps == 1) + { + tCoordType = "float"; + } + else + { + tCoordType = "vec2"; + } + vsdec = vsdec + "attribute " + tCoordType + " " + it + ";\n"; + vsdec = vsdec + "varying " + tCoordType + " " + it + "VCVSOutput;\n"; + gsdec = gsdec + "in " + tCoordType + " " + it + "VCVSOutput[];\n"; + gsdec = gsdec + "out " + tCoordType + " " + it + "VCGSOutput;\n"; + gsimpl = gsimpl + it + "VCGSOuput = " + it + "VCVSOutput[i];\n"; + fsdec = fsdec + "varying " + tCoordType + " " + it + "VCVSOutput;\n"; } + vtkShaderProgram::Substitute(VSSource, "//VTK::TCoord::Dec", vsdec); + vtkShaderProgram::Substitute(GSSource, "//VTK::TCoord::Dec", gsdec); + vtkShaderProgram::Substitute(GSSource, "//VTK::TCoord::Impl", gsimpl); + vtkShaderProgram::Substitute(FSSource, "//VTK::TCoord::Dec", fsdec); - std::string tCoordDecFS; + // OK now handle the fragment shader implementation + // everything else has been done. std::string tCoordImpFS; for (size_t i = 0; i < textures.size(); ++i) { - vtkTexture *texture = textures[i]; + vtkTexture *texture = textures[i].first; std::stringstream ss; + // do we have special tcoords for this texture? + std::string tcoordname = this->GetTextureCoordinateName(textures[i].second.c_str()); + int tcoordComps = this->VBOs->GetNumberOfComponents(tcoordname.c_str()); + + std::string tCoordImpFSPre; + std::string tCoordImpFSPost; + if (tcoordComps == 1) + { + tCoordImpFSPre = "vec2("; + tCoordImpFSPost = ", 0.0)"; + } + else + { + tCoordImpFSPre = ""; + tCoordImpFSPost = ""; + } + + // Read texture color - ss << "vec4 tcolor_" << i << " = texture(texture_" << i << ", " - << tCoordImpFSPre << "tcoordVCVSOutput" << tCoordImpFSPost << "); // Read texture color\n"; + ss << "vec4 tcolor_" << i << " = texture(" << textures[i].second << ", " + << tCoordImpFSPre << tcoordname << "VCVSOutput" << tCoordImpFSPost << "); // Read texture color\n"; // Update color based on texture number of components int tNumComp = vtkOpenGLTexture::SafeDownCast(texture)->GetTextureObject()->GetComponents(); @@ -1037,20 +1100,8 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderTCoord( tCoordImpFS += ss.str(); } - // Substitute in shader files - vtkShaderProgram::Substitute(VSSource, "//VTK::TCoord::Dec", - "attribute " + tCoordType + " tcoordMC;\n" + - "varying " + tCoordType + " tcoordVCVSOutput;"); - vtkShaderProgram::Substitute(GSSource, "//VTK::TCoord::Dec", - "in " + tCoordType + " tcoordVCVSOutput[];\n" + - "out " + tCoordType + " tcoordVCGSOutput;"); - vtkShaderProgram::Substitute(GSSource, "//VTK::TCoord::Impl", - "tcoordVCGSOutput = tcoordVCVSOutput[i];"); - vtkShaderProgram::Substitute(FSSource, "//VTK::TCoord::Dec", - "varying " + tCoordType + " tcoordVCVSOutput;\n" + tCoordDecFS); - // do texture mapping except for scalar coloring case which is - // handled above + // handled in the scalar coloring code if (!this->InterpolateScalarsBeforeMapping || !this->ColorCoordinates) { vtkShaderProgram::Substitute(FSSource, "//VTK::TCoord::Impl", @@ -1717,7 +1768,7 @@ bool vtkOpenGLPolyDataMapper::GetNeedToRebuildShaders( + ((factor != 0.0) ? 0x10 : 0) + ((offset != 0.0) ? 0x20 : 0) + (this->VBOs->GetNumberOfComponents("scalarColor") ? 0x40 : 0) - + ((this->VBOs->GetNumberOfComponents("tcoordMC") % 4) << 7); + + ((this->VBOs->GetNumberOfComponents("tcoord") % 4) << 7); if (cellBO.Program == nullptr || cellBO.ShaderSourceTime < this->GetMTime() || @@ -1732,13 +1783,13 @@ bool vtkOpenGLPolyDataMapper::GetNeedToRebuildShaders( } // if texturing then texture components/blend funcs may have changed - if (this->VBOs->GetNumberOfComponents("tcoordMC")) + if (this->VBOs->GetNumberOfComponents("tcoord")) { vtkMTimeType texMTime = 0; - std::vector textures = this->GetTextures(actor); + std::vector textures = this->GetTextures(actor); for (size_t i = 0; i < textures.size(); ++i) { - vtkTexture *texture = textures[i]; + vtkTexture *texture = textures[i].first; texMTime = (texture->GetMTime() > texMTime ? texture->GetMTime() : texMTime); if (cellBO.ShaderSourceTime < texMTime) { @@ -1846,16 +1897,14 @@ void vtkOpenGLPolyDataMapper::SetMapperShaderParameters(vtkOpenGLHelper &cellBO, if (this->HaveTextures(actor)) { - std::vector textures = this->GetTextures(actor); + std::vector textures = this->GetTextures(actor); for (size_t i = 0; i < textures.size(); ++i) { - vtkTexture *texture = textures[i]; - std::stringstream ss; ss << "texture_" << i; - std::string s = ss.str(); - if (texture && cellBO.Program->IsUniformUsed(s.c_str())) + vtkTexture *texture = textures[i].first; + if (texture && cellBO.Program->IsUniformUsed(textures[i].second.c_str())) { int tunit = vtkOpenGLTexture::SafeDownCast(texture)->GetTextureUnit(); - cellBO.Program->SetUniformi(s.c_str(), tunit); + cellBO.Program->SetUniformi(textures[i].second.c_str(), tunit); } } @@ -3243,7 +3292,7 @@ void vtkOpenGLPolyDataMapper::BuildBufferObjects(vtkRenderer *ren, vtkActor *act this->VBOs->CacheDataArray("normalMC", n, cache, VTK_FLOAT); this->VBOs->CacheDataArray("scalarColor", c, cache, VTK_UNSIGNED_CHAR); - this->VBOs->CacheDataArray("tcoordMC", tcoords, cache, VTK_FLOAT); + this->VBOs->CacheDataArray("tcoord", tcoords, cache, VTK_FLOAT); this->VBOs->BuildAllVBOs(cache); // get it again as it may have been freed @@ -3506,7 +3555,32 @@ void vtkOpenGLPolyDataMapper::MapDataArrayToVertexAttribute( int componentno ) { - if (!vertexAttributeName) + this->MapDataArray(vertexAttributeName, + dataArrayName, "", fieldAssociation, componentno); +} + +void vtkOpenGLPolyDataMapper::MapDataArrayToMultiTextureAttribute( + const char *tname, + const char* dataArrayName, + int fieldAssociation, + int componentno + ) +{ + std::string coordname = tname; + coordname += "_coord"; + this->MapDataArray(coordname.c_str(), + dataArrayName, tname, fieldAssociation, componentno); +} + +void vtkOpenGLPolyDataMapper::MapDataArray( + const char* vertexAttributeName, + const char* dataArrayName, + const char *tname, + int fieldAssociation, + int componentno + ) +{ + if (!vertexAttributeName) { return; } @@ -3522,6 +3596,7 @@ void vtkOpenGLPolyDataMapper::MapDataArrayToVertexAttribute( aval.DataArrayName = dataArrayName; aval.FieldAssociation = fieldAssociation; aval.ComponentNumber = componentno; + aval.TextureName = tname; this->ExtraAttributes.insert( std::make_pair(vertexAttributeName, aval)); diff --git a/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.h b/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.h index 4f03c0416c1..2b47cce46c9 100644 --- a/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.h +++ b/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.h @@ -41,6 +41,7 @@ class vtkOpenGLBufferObject; class vtkOpenGLVertexBufferObject; class vtkOpenGLVertexBufferObjectGroup; class vtkPoints; +class vtkTexture; class vtkTextureObject; class vtkTransform; @@ -256,6 +257,15 @@ class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMap int fieldAssociation, int componentno = -1) override; + // This method will Map the specified data array for use as + // a texture coordinate for texture tname. The actual + // attribute will be named tname_coord so as to not + // conflict with the texture sampler definition which will + // be tname. + void MapDataArrayToMultiTextureAttribute( + const char *tname, + const char* dataArrayName, int fieldAssociation, int componentno = -1) override; + /** * Remove a vertex attribute mapping. */ @@ -272,6 +282,16 @@ class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMap vtkGenericOpenGLResourceFreeCallback *ResourceCallback; + void MapDataArray( + const char* vertexAttributeName, + const char* dataArrayName, + const char *texturename, + int fieldAssociation, + int componentno); + + // what coordinate shoudl be used for this texture + std::string GetTextureCoordinateName(const char *tname); + // the following is all extra stuff to work around the // fact that gl_PrimitiveID does not work correctly on // Apple devices with AMD graphics hardware. See apple @@ -430,7 +450,7 @@ class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMap // ColorInternalTexture // Actors texture // Properties textures - virtual std::vector GetTextures(vtkActor *actor); + virtual std::vector > GetTextures(vtkActor *actor); // do we have textures coordinates that require special handling virtual bool HaveTCoords(vtkPolyData *poly); @@ -512,6 +532,7 @@ class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLPolyDataMapper : public vtkPolyDataMap std::string DataArrayName; int FieldAssociation; int ComponentNumber; + std::string TextureName; }; std::map ExtraAttributes; diff --git a/Rendering/OpenGL2/vtkOpenGLProperty.cxx b/Rendering/OpenGL2/vtkOpenGLProperty.cxx index b9e7c69d9f0..0bd97b71243 100644 --- a/Rendering/OpenGL2/vtkOpenGLProperty.cxx +++ b/Rendering/OpenGL2/vtkOpenGLProperty.cxx @@ -64,15 +64,15 @@ void vtkOpenGLProperty::Render(vtkActor *anActor, vtkRenderer *ren) bool vtkOpenGLProperty::RenderTextures(vtkActor*, vtkRenderer* ren) { // render any textures. - int numTextures = this->GetNumberOfTextures(); - for (int t = 0; t < numTextures; t++) + auto textures = this->GetAllTextures(); + for (auto ti : textures) { - this->GetTextureAtIndex(t)->Render(ren); + ti.second->Render(ren); } vtkOpenGLCheckErrorMacro("failed after Render"); - return (numTextures > 0); + return (textures.size() > 0); } //----------------------------------------------------------------------------- @@ -86,12 +86,11 @@ void vtkOpenGLProperty::PostRender(vtkActor *actor, vtkRenderer *renderer) glDisable(GL_CULL_FACE); } - // deactivate any textures. - int numTextures = this->GetNumberOfTextures(); - for (int t = 0; t < numTextures; t++) + auto textures = this->GetAllTextures(); + for (auto ti : textures) { - this->GetTextureAtIndex(t)->PostRender(renderer); + ti.second->PostRender(renderer); } this->Superclass::PostRender(actor, renderer); @@ -109,13 +108,10 @@ void vtkOpenGLProperty::BackfaceRender(vtkActor *vtkNotUsed(anActor), vtkRendere void vtkOpenGLProperty::ReleaseGraphicsResources(vtkWindow *win) { // release any textures. - int numTextures = this->GetNumberOfTextures(); - if (numTextures > 0) + auto textures = this->GetAllTextures(); + for (auto ti : textures) { - for (int i = 0; i < numTextures; i++) - { - this->GetTextureAtIndex(i)->ReleaseGraphicsResources(win); - } + ti.second->ReleaseGraphicsResources(win); } this->Superclass::ReleaseGraphicsResources(win); diff --git a/Views/Infovis/vtkRenderedGraphRepresentation.cxx b/Views/Infovis/vtkRenderedGraphRepresentation.cxx index 3bb8a048086..3c83a695b00 100644 --- a/Views/Infovis/vtkRenderedGraphRepresentation.cxx +++ b/Views/Infovis/vtkRenderedGraphRepresentation.cxx @@ -74,6 +74,7 @@ #include "vtkSphereSource.h" #include "vtkTable.h" #include "vtkTextProperty.h" +#include "vtkTexture.h" #include "vtkTexturedActor2D.h" #include "vtkTransformCoordinateSystems.h" #include "vtkTreeLayoutStrategy.h"