Commit 67cb974b authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

Removed the XML shaders and associated classes

These have not been used in quite some time, add dependencies on XML
in the core rendering API and have been superseded by their sequels.

Disabled GenericVertexAttributes tests for now due to use of XML
shader API, along with the materials object example.

Change-Id: I3c57c46b1d3cc7f550bd30e1abcd6e5d87347d36
parent 7980e4d0
......@@ -22,7 +22,7 @@ set(RENDERING_EXAMPLES_SRCS
SpecularSpheres
DiffuseSpheres
AmbientSpheres
MaterialObjects
#MaterialObjects
)
foreach(name ${RENDERING_EXAMPLES_SRCS})
......
......@@ -25,7 +25,6 @@
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkShaderProgram.h"
#include "vtkCamera.h"
#include "vtkLight.h"
......
......@@ -61,7 +61,6 @@ set(Module_SRCS
vtkMapper2D.cxx
vtkMapperCollection.cxx
vtkMapper.cxx
vtkMaterialLibrary.cxx
vtkObserverMediator.cxx
vtkPainter.cxx
vtkPainterDeviceAdapter.cxx
......@@ -79,7 +78,7 @@ set(Module_SRCS
vtkPropCollection.cxx
vtkProp.cxx
vtkProperty2D.cxx
vtkProperty.cxx # needs a load of image readers - IOImage, IOXML
vtkProperty.cxx
vtkRendererCollection.cxx
vtkRenderer.cxx
vtkRendererDelegate.cxx
......@@ -90,11 +89,7 @@ set(Module_SRCS
vtkRepresentationPainter.cxx
vtkScalarsToColorsPainter.cxx
vtkSelectVisiblePoints.cxx
vtkShader.cxx # vtkXMLShader
vtkShaderCodeLibrary.cxx
vtkShaderDeviceAdapter.cxx
vtkShaderDeviceAdapter2.cxx
vtkShaderProgram.cxx # vtkXMLShaderProgram
vtkStandardPolyDataPainter.cxx
vtkTexture.cxx
vtkTexturedActor2D.cxx
......@@ -108,10 +103,6 @@ set(Module_SRCS
vtkVolumeCollection.cxx
vtkVolume.cxx
vtkVolumeProperty.cxx
vtkXMLMaterial.cxx
vtkXMLMaterialParser.cxx
vtkXMLMaterialReader.cxx
vtkXMLShader.cxx
vtkWindowLevelLookupTable.cxx
vtkWindowToImageFilter.cxx
......
......@@ -9,7 +9,6 @@ vtk_module(vtkRenderingCore
vtkFiltersGeometry
vtkFiltersExtraction
vtkIOImage
vtkIOXMLParser
PRIVATE_DEPENDS
vtksys
COMPILE_DEPENDS
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkMaterialLibrary.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 "vtkMaterialLibrary.h"
#include "vtkObjectFactory.h"
#include "vtkMaterialLibraryMacro.h"
#ifndef vtkMaterialLibraryMacro
#define vtkMaterialLibraryMacro(name) \
vtkGenericWarningMacro("VTK is not built with shading support." \
"No materials are available.");
#endif
vtkStandardNewMacro(vtkMaterialLibrary);
//-----------------------------------------------------------------------------
vtkMaterialLibrary::vtkMaterialLibrary()
{
}
//-----------------------------------------------------------------------------
vtkMaterialLibrary::~vtkMaterialLibrary()
{
}
//-----------------------------------------------------------------------------
char* vtkMaterialLibrary::GetMaterial(const char* name)
{
if (!name || !*name)
{
return 0;
}
// CMake sets VTK_SHADER_CODE_LIBRARY_CHUNK to be the
// chunk of code that does name comparisons and
// call appropriate method from the vtk*ShaderLibrary.
vtkMaterialLibraryMacro(name)
return 0;
}
//-----------------------------------------------------------------------------
const char** vtkMaterialLibrary::GetListOfMaterialNames()
{
// defined in vtkMaterialLibraryMacro.h
return ::ListOfMaterialNames;
}
//-----------------------------------------------------------------------------
unsigned int vtkMaterialLibrary::GetNumberOfMaterials()
{
const char** names = vtkMaterialLibrary::GetListOfMaterialNames();
unsigned int cc ;
for (cc=0; names[cc]; cc++)
{
}
return cc;
}
//-----------------------------------------------------------------------------
void vtkMaterialLibrary::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkMaterialLibrary.h
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.
=========================================================================*/
// .NAME vtkMaterialLibrary - Library for Materials
// .SECTION Description
// This class provides the Material XMLs.
// .SECTION Thanks
// Shader support in VTK includes key contributions by Gary Templet at
// Sandia National Labs.
#ifndef __vtkMaterialLibrary_h
#define __vtkMaterialLibrary_h
#include "vtkRenderingCoreModule.h" // For export macro
#include "vtkObject.h"
class VTKRENDERINGCORE_EXPORT vtkMaterialLibrary : public vtkObject
{
public:
static vtkMaterialLibrary* New();
vtkTypeMacro(vtkMaterialLibrary, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Obtain the code for the shader with given name.
// Note that Cg shader names are prefixed with CG and
// GLSL shader names are prefixed with GLSL.
// This method allocates memory. It's the responsibility
// of the caller to free this memory.
static char* GetMaterial(const char* name);
// Description:
// Returns an array of pointers to char strings that are
// the names of the materials provided by the library.
// The end of the array is marked by a null pointer.
static const char** GetListOfMaterialNames();
// Description:
// Returns the number of materials provided by the library.
static unsigned int GetNumberOfMaterials();
protected:
vtkMaterialLibrary();
~vtkMaterialLibrary();
private:
vtkMaterialLibrary(const vtkMaterialLibrary&); // Not implemented.
void operator=(const vtkMaterialLibrary&); // Not implemented.
};
#endif
......@@ -30,8 +30,6 @@
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkShaderDeviceAdapter.h"
#include "vtkShaderProgram.h"
#include "vtkTimerLog.h"
#include "vtkUnsignedCharArray.h"
#include "vtkShaderDeviceAdapter2.h"
......@@ -295,15 +293,10 @@ void vtkPrimitivePainter::RenderInternal(vtkRenderer* renderer,
vtkErrorMacro("No actor");
}
vtkShaderDeviceAdapter *shaderDevice = NULL;
vtkShaderDeviceAdapter2 *shaderDevice2 = NULL;
if (prop->GetShading())
{
if (prop->GetShaderProgram())
{
shaderDevice = prop->GetShaderProgram()->GetShaderDeviceAdapter();
}
shaderDevice2 = prop->GetShaderDeviceAdapter2();
}
......@@ -315,11 +308,6 @@ void vtkPrimitivePainter::RenderInternal(vtkRenderer* renderer,
this->GetInformation()->Get(SHADER_DEVICE_ADAPTOR()));
}
if (shaderDevice && this->GenericVertexAttributes)
{
idx |= VTK_PDM_GENERIC_VERTEX_ATTRIBUTES;
}
if (shaderDevice2 && this->GenericVertexAttributes)
{
idx |= VTK_PDM_GENERIC_VERTEX_ATTRIBUTES;
......
......@@ -16,19 +16,11 @@
#include "vtkActor.h"
#include "vtkObjectFactory.h"
#include "vtkImageData.h"
#include "vtkImageReader2.h"
#include "vtkImageReader2Factory.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkShaderProgram.h"
#include "vtkSmartPointer.h"
#include "vtkStdString.h"
#include "vtkTexture.h"
#include "vtkXMLDataElement.h"
#include "vtkXMLMaterial.h"
#include "vtkXMLMaterialParser.h"
#include "vtkXMLShader.h"
#include <stdlib.h>
#include <vtksys/ios/sstream>
......@@ -48,121 +40,11 @@ public:
MapOfTextureNames TextureNames;
};
vtkCxxSetObjectMacro(vtkProperty, ShaderProgram, vtkShaderProgram);
//----------------------------------------------------------------------------
// Return NULL if no override is supplied.
vtkAbstractObjectFactoryNewMacro(vtkProperty)
//----------------------------------------------------------------------------
// Construct object with object color, ambient color, diffuse color,
enum IVarEnum {
IVarNone = 0,
IVarColor,
IVarAmbientColor,
IVarDiffuseColor,
IVarSpecularColor,
IVarEdgeColor,
IVarAmbient,
IVarDiffuse,
IVarSpecular,
IVarSpecularPower,
IVarOpacity,
IVarPointSize,
IVarLineWidth,
IVarLineStipplePattern,
IVarLineStippleRepeatFactor,
IVarInterpolation,
IVarRepresentation,
IVarEdgeVisibility,
IVarBackfaceCulling,
IVarFrontfaceCulling
};
static IVarEnum XMLMemberToIvar(const char* name)
{
if (!strcmp(name, "Color"))
{
return IVarColor;
}
if (!strcmp(name, "AmbientColor"))
{
return IVarAmbientColor;
}
if (!strcmp(name, "DiffuseColor"))
{
return IVarDiffuseColor;
}
if (!strcmp(name, "SpecularColor"))
{
return IVarSpecularColor;
}
if (!strcmp(name, "EdgeColor"))
{
return IVarEdgeColor;
}
if (!strcmp(name, "Ambient"))
{
return IVarAmbient;
}
if (!strcmp(name, "Diffuse"))
{
return IVarDiffuse;
}
if (!strcmp(name, "Specular"))
{
return IVarSpecular;
}
if (!strcmp(name, "SpecularPower"))
{
return IVarSpecularPower;
}
if (!strcmp(name, "Opacity"))
{
return IVarOpacity;
}
if (!strcmp(name, "PointSize"))
{
return IVarPointSize;
}
if (!strcmp(name, "LineWidth"))
{
return IVarLineWidth;
}
if (!strcmp(name, "LineStipplePattern"))
{
return IVarLineStipplePattern;
}
if (!strcmp(name, "LineStippleRepeatFactor"))
{
return IVarLineStippleRepeatFactor;
}
if (!strcmp(name, "Interpolation"))
{
return IVarInterpolation;
}
if (!strcmp(name, "Representation"))
{
return IVarRepresentation;
}
if (!strcmp(name, "EdgeVisibility"))
{
return IVarEdgeVisibility;
}
if (!strcmp(name, "BackfaceCulling"))
{
return IVarBackfaceCulling;
}
if (!strcmp(name, "FrontfaceCulling"))
{
return IVarFrontfaceCulling;
}
return IVarNone;
}
// specular color, and edge color white; ambient coefficient=0; diffuse
// coefficient=0; specular coefficient=0; specular power=1; Gouraud shading;
// and surface representation. Backface and frontface culling are off.
......@@ -206,8 +88,6 @@ vtkProperty::vtkProperty()
this->Lighting = true;
this->Shading = 0;
this->ShaderProgram = 0;
this->Material = 0;
this->MaterialName = 0;
this->Internals = new vtkPropertyInternals;
}
......@@ -215,12 +95,6 @@ vtkProperty::vtkProperty()
//----------------------------------------------------------------------------
vtkProperty::~vtkProperty()
{
if (this->Material)
{
this->Material->UnRegister(this);
this->Material = 0;
}
this->SetShaderProgram(0);
this->SetMaterialName(0);
delete this->Internals;
}
......@@ -251,7 +125,6 @@ void vtkProperty::DeepCopy(vtkProperty *p)
this->SetLineStipplePattern(p->GetLineStipplePattern());
this->SetLineStippleRepeatFactor(p->GetLineStippleRepeatFactor());
this->SetShading(p->GetShading());
this->LoadMaterial(p->GetMaterial());
this->RemoveAllTextures();
vtkPropertyInternals::MapOfTextures::iterator iter =
......@@ -486,407 +359,7 @@ int vtkProperty::GetTextureUnit(const char* name)
}
//----------------------------------------------------------------------------
void vtkProperty::LoadMaterial(const char* name)
{
this->SetMaterialName(0);
if( !name || strlen(name) == 0)
{
this->LoadMaterial(static_cast<vtkXMLMaterial*>(0));
return;
}
// vtkXMLMaterial::CreateInstance using library/absolute path/repository
// in that order.
vtkXMLMaterial* material = vtkXMLMaterial::CreateInstance(name);
if (!material)
{
vtkErrorMacro("Failed to create Material : " << name);
return;
}
this->LoadMaterial(material);
material->Delete();
return;
}
//----------------------------------------------------------------------------
void vtkProperty::LoadMaterialFromString(const char* materialxml)
{
this->SetMaterialName(0);
if (!materialxml)
{
this->LoadMaterial(static_cast<vtkXMLMaterial*>(0));
return;
}
vtkXMLMaterialParser* parser = vtkXMLMaterialParser::New();
vtkXMLMaterial* material = vtkXMLMaterial::New();
parser->SetMaterial(material);
parser->Parse(materialxml);
parser->Delete();
this->LoadMaterial(material);
material->Delete();
}
// ----------------------------------------------------------------------------
// Description:
// Read this->Material from new style shaders.
// Default implementation is empty.
void vtkProperty::ReadFrameworkMaterial()
{
// empty. See vtkOpenGLProperty.
}
//----------------------------------------------------------------------------
void vtkProperty::LoadMaterial(vtkXMLMaterial* material)
{
this->SetMaterialName(0);
vtkSetObjectBodyMacro(Material, vtkXMLMaterial, material);
if (this->Material)
{
this->SetMaterialName(this->Material->GetRootElement()->GetAttribute("name"));
this->LoadProperty();
this->LoadTextures();
int lang = this->Material->GetShaderLanguage();
int style = this->Material->GetShaderStyle();
if (style == 2) // TODO: use a constant instead of a literal
{
if (lang == vtkXMLShader::LANGUAGE_GLSL)
{
// ready-for-multipass
this->ReadFrameworkMaterial();
// vtkShader2Collection *shaders=vtkShader2Collection::New();
// this->SetShaderCollection(shaders);
// shaders->Delete();
}
else
{
vtkErrorMacro(<<"style 2 is only supported with GLSL. Failed to setup the shader.");
this->SetShaderProgram(0); // failed to create shaders.
}
}
else
{
vtkShaderProgram* shader = vtkShaderProgram::CreateShaderProgram(lang);
if (shader)
{
this->SetShaderProgram(shader);
shader->Delete();
this->ShaderProgram->SetMaterial(this->Material);
this->ShaderProgram->ReadMaterial();
}
// Some materials may have no shaders and only set ivars for vtkProperty.
else if ((material->GetNumberOfVertexShaders() != 0) ||
(material->GetNumberOfFragmentShaders() != 0))
{
vtkErrorMacro("Failed to setup the shader.");
this->SetShaderProgram(0); // failed to create shaders.
}
}
}
else
{
this->SetShaderProgram(0);
}
}
//----------------------------------------------------------------------------
void vtkProperty::LoadProperty()
{
vtkXMLDataElement* elem = this->Material->GetProperty();
if (elem == NULL )
{
return;
}
int numNested = elem->GetNumberOfNestedElements();
// Each element is a child node of <Property />
for (int iElem = 0; iElem < numNested; iElem++)
{
vtkXMLDataElement* currElement = elem->GetNestedElement(iElem);
const char* tagname = currElement->GetName();
if (!strcmp(tagname, "Member"))
{
this->LoadMember(currElement);
}
else
{
vtkErrorMacro("Unknown tag name '" << tagname << "'");
}
}
}
//----------------------------------------------------------------------------
void vtkProperty::LoadTextures()
{
int numTextures = this->Material->GetNumberOfTextures();
for (int i = 0; i < numTextures; i++)
{
this->LoadTexture(this->Material->GetTexture(i));
}
}
//----------------------------------------------------------------------------
void vtkProperty::LoadMember(vtkXMLDataElement* elem)
{
const char* name = elem->GetAttribute("name");
if (!name)
{
vtkErrorMacro("Element missing required attribute 'name'");
return;
}
if (!elem->GetAttribute("value"))
{
vtkErrorMacro("Element with name=" << name << " missing required attribute "
"'value'");
return;
}
int number_of_elements;
int* pint = 0;
double* pdouble = 0;
float* pfloat = 0;
int success = 0;
IVarEnum member = XMLMemberToIvar( name );
// Sort to find the correct number of ivar values
if ( member == IVarColor ||
member == IVarAmbientColor||
member == IVarDiffuseColor||
member == IVarSpecularColor||
member == IVarEdgeColor )
{
number_of_elements = 3;
}
else if ( member == IVarAmbient ||
member == IVarDiffuse ||
member == IVarSpecular ||
member == IVarSpecularPower ||
member == IVarSpecularColor||
member == IVarOpacity ||
member == IVarPointSize ||
member == IVarLineWidth ||
member == IVarLineStipplePattern ||
member == IVarLineStippleRepeatFactor ||
member == IVarInterpolation ||
member == IVarRepresentation ||
member == IVarEdgeVisibility ||
member == IVarBackfaceCulling ||
member == IVarFrontfaceCulling )
{
number_of_elements = 1;
}
else
{
vtkErrorMacro("Invalid name='" << name);
return;
}
if ( (member == IVarColor) ||
(member == IVarAmbientColor) ||
(member == IVarDiffuseColor) ||
(member == IVarSpecularColor) ||
(member == IVarEdgeColor) ||
(member == IVarAmbient) ||