34 #include "vtkObjectFactory.h"
35 #include "vtkSmartPointer.h"
36 #include "vtkXMLDataElement.h"
43 class vtkXMLMaterialInternals
46 typedef std::vector<vtkXMLDataElement *> VectorOfElements;
47 typedef std::vector<vtkSmartPointer<vtkXMLShader>> VectorOfShaders;
48 VectorOfElements Properties;
49 VectorOfShaders VertexShaders;
50 VectorOfShaders FragmentShaders;
51 VectorOfShaders GeometryShaders;
52 VectorOfElements Textures;
55 this->Properties.clear();
56 this->VertexShaders.clear();
57 this->FragmentShaders.clear();
58 this->GeometryShaders.clear();
59 this->Textures.clear();
69 this->
Internals =
new vtkXMLMaterialInternals;
96 parser->SetFileName(filename);
113 vtkSetObjectBodyMacro(
RootElement, vtkXMLDataElement, root);
118 int numElems = this->
RootElement->GetNumberOfNestedElements();
119 for (
int i = 0; i < numElems; i++)
121 vtkXMLDataElement *elem = this->
RootElement->GetNestedElement(i);
122 const char *name = elem->GetName();
127 if (strcmp(name,
"Property") == 0)
129 this->
Internals->Properties.push_back(elem);
131 else if (strcmp(name,
"Shader") == 0)
139 this->
Internals->VertexShaders.push_back(shader);
142 this->
Internals->FragmentShaders.push_back(shader);
145 this->
Internals->GeometryShaders.push_back(shader);
148 vtkErrorMacro(
"Invalid scope for shader: " << shader->
GetName());
153 else if (strcmp(name,
"Texture") == 0)
155 this->
Internals->Textures.push_back(elem);
164 return static_cast<int>(this->
Internals->Properties.size());
170 return static_cast<int>(this->
Internals->Textures.size());
176 return static_cast<int>(this->
Internals->VertexShaders.size());
182 return static_cast<int>(this->
Internals->FragmentShaders.size());
187 return static_cast<int>(this->
Internals->GeometryShaders.size());
215 return this->
Internals->VertexShaders[id].GetPointer();
225 return this->
Internals->FragmentShaders[id].GetPointer();
234 return this->
Internals->GeometryShaders[id].GetPointer();
263 if (vStyle != 0 && fStyle != 0 && !gStyle && vStyle != fStyle)
265 vtkErrorMacro(<<
"vertex shader and fragment shader style differ.");
279 assert(
"post: valid_result" && (result == 1 || result == 2));
286 this->Superclass::PrintSelf(os, indent);
290 os << indent <<
"RootElement: ";
294 this->
RootElement->PrintSelf(os, indent.GetNextIndent());
298 os <<
"(null)" << endl;
int GetNumberOfVertexShaders()
vtkXMLMaterialInternals * Internals
int GetNumberOfTextures()
void SetRootElement(vtkXMLDataElement *)
vtkXMLDataElement * GetTexture(int id=0)
vtkXMLShader * GetVertexShader(int id=0)
void SetMaterial(vtkXMLMaterial *)
vtkXMLDataElement * GetProperty(int id=0)
static vtkXMLShader * New()
int GetNumberOfProperties()
static vtkXMLMaterial * New()
vtkStandardNewMacro(vtkXMLMaterial)
vtkXMLShader * GetGeometryShader(int id=0)
void PrintSelf(ostream &os, vtkIndent indent) override
int GetNumberOfFragmentShaders()
static const std::string filename
static vtkXMLMaterial * CreateInstance(const char *name)
virtual int Parse() override
void SetRootElement(vtkXMLDataElement *)
vtkXMLShader * GetFragmentShader(int id=0)
static char * LocateFile(const char *filename)
static vtkXMLMaterialParser * New()
int GetNumberOfGeometryShaders()
vtkXMLDataElement * RootElement