1 /****************************************************************************
2 * MeshLab                                                           o o     *
3 * A versatile mesh processing toolbox                             o     o   *
4 *                                                                _   O  _   *
5 * Copyright(C) 2005-2008                                           \/)\/    *
6 * Visual Computing Lab                                            /\/|      *
7 * ISTI - Italian National Research Council                           |      *
8 *                                                                    \      *
9 * All rights reserved.                                                      *
10 *                                                                           *
11 * This program is free software; you can redistribute it and/or modify      *
12 * it under the terms of the GNU General Public License as published by      *
13 * the Free Software Foundation; either version 2 of the License, or         *
14 * (at your option) any later version.                                       *
15 *                                                                           *
16 * This program is distributed in the hope that it will be useful,           *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
20 * for more details.                                                         *
21 *                                                                           *
22 ****************************************************************************/
23 /****************************************************************************
24 History
25 $Log$
26 Revision 1.3  2007/12/03 10:46:06  corsini
27 code restyling
28 
29 
30 ****************************************************************************/
31 #ifndef __UNIFORMVAR_H__
32 #define __UNIFORMVAR_H__
33 
34 // Local headers
35 #include "GlState.h"
36 
37 // Qt headers
38 #include <QList>
39 #include <QString>
40 #include <QStringList>
41 #include <QDomElement>
42 #include <QDebug>
43 
44 
45 class UniformVar
46 {
47 public:
48 
49 	enum UniformType {
50 		INT,
51 		FLOAT,
52 		BOOL,
53 		VEC2, VEC3, VEC4,
54 		IVEC2, IVEC3, IVEC4,
55 		BVEC2, BVEC3, BVEC4,
56 		MAT2, MAT3, MAT4,
57 		SAMPLER1D, SAMPLER2D, SAMPLER3D, SAMPLERCUBE,
58 		SAMPLER1DSHADOW, SAMPLER2DSHADOW,
59 		OTHER,
60 		NUM_TYPES
61 	};
62 
63 	UniformType type;
64 	QString name;
65 	QString typeString;
66 
67 	union {
68 		int ivalue;
69 		float fvalue;
70 		bool bvalue;
71 		float vec2[2], vec3[3], vec4[4];
72 		int ivec2[2], ivec3[3], ivec4[4];
73 		bool bvec2[2], bvec3[3], bvec4[4];
74 		float mat2[2][2], mat3[3][3], mat4[4][4];
75 	};
76 
77 	QString representerTagName;
78 	QString textureName;
79 	QString textureFilename;
80 	QList<GlState> textureGLStates;
81 
82 	union { int imin; float fmin; };
83 	union { int imax; float fmax; };
84 	union { int irealmin; float frealmin; };
85 	union { int irealmax; float frealmax; };
86 
87 	bool minSet;
88 	bool maxSet;
89 	bool realminSet;
90 	bool realmaxSet;
91 
92 	bool valid;
93 
94 	void setMin(int min);
95 	void setMin(float min);
96 	void setMax(int max);
97 	void setMax(float max);
98 	void testRealMin(int min);
99 	void testRealMin(float min);
100 	void testRealMax(int max);
101 	void testRealMax(float max);
102 
UniformVar()103 	UniformVar() { valid = false; }
104 	UniformVar(QString &_name, QString &_typeString, UniformType _type);
~UniformVar()105 	virtual ~UniformVar() {}
106 
isNull()107 	bool isNull() { return !valid; }
108 
109 
110 	//* we search the xml tag element that has the default value of a uniform
111 	//* variable. It can happened a multiple declaration, so first we search
112 	//* in the same RmOpenGLEffect (effectElement), and then in the global document root
113 	bool getValueFromXmlDocument(QDomElement &root, bool echoNotFound = true);
getValueFromXmlDocument(QDomElement & root,QDomElement & effectElement)114 	bool getValueFromXmlDocument(QDomElement &root, QDomElement &effectElement)
115 	{
116 		if (getValueFromXmlDocument(effectElement, false))
117 			return true;
118 		return getValueFromXmlDocument(root);
119 	}
120 
121 	bool getUniformKnownButUnimplementedTag(QDomElement &root, QString tag, QString tagname);
122 	bool getUniformBooleanVectorFromTag(QDomElement &root, QString tag, int vecsize, bool * vec, bool * found = NULL);
123 	bool getUniformNumberVectorFromTag(QDomElement &root, QString tag, int vecsize, void * vec, bool intOrFloat, bool * found = NULL);
124 	bool getUniformNumberVectorFromTag(QDomElement &root, QString tag, int vecsize, int * vec, bool * found = NULL)
125 	{
126 		return getUniformNumberVectorFromTag(root, tag, vecsize, (void*)vec, true, found);
127 	}
128 	bool getUniformNumberVectorFromTag(QDomElement &root, QString tag, int vecsize, float *vec, bool *found = NULL)
129 	{
130 		return getUniformNumberVectorFromTag(root, tag, vecsize, (void*)vec, false, found);
131 	}
132 	bool getUniformTextureFromTag(QDomElement &root, QString tag, bool *found = NULL);
133 
134 
135 	static enum UniformType getTypeFromString(QString &type);
136 	static QString getXmlTagRomUniformType(UniformType type);
137 	static QString getStringFromUniformType(UniformType type);
138 
139 	static bool getUniformNumberVectorFromXmlTag(QDomElement &el, int values, void *farr, bool intOrFloat, UniformVar *ptr);
140 	static bool getUniformBooleanVectorFromXmlTag(QDomElement &el, int values, bool *barr);
141 
142 	void VarDump(int indent = 0, bool extendedVarDump = false);
143 
144 private:
145 	static QString typeList[];
146 };
147 #endif /* __UNIFORMVAR_H__ */
148