46 #include <QStringList> 53 #include <ACG/GL/gl.hh> 54 #include <ACG/Config/ACGDefines.hh> 64 #define SG_MAX_SHADER_LIGHTS 8 66 enum ShaderGenLightType
68 SG_LIGHT_DIRECTIONAL = 0,
71 SG_LIGHT_FORCE_DWORD = 0xFFFFFFFF
74 enum ShaderGenShadeMode
80 SG_SHADE_FORCE_DWORD = 0xFFFFFFFF
90 twoSidedLighting(
false),
91 shadeMode(SG_SHADE_UNLIT),
93 vertexTemplateFile(
""),
94 tessControlTemplateFile(
""),
95 tessEvaluationTemplateFile(
""),
96 geometryTemplateFile(
""),
97 fragmentTemplateFile(
""),
99 colorMaterialMode(GL_AMBIENT_AND_DIFFUSE),
103 texGenMode(GL_EYE_LINEAR),
104 texGenPerFragment(
false)
106 for (
unsigned int i = 0 ; i < SG_MAX_SHADER_LIGHTS ; ++i)
107 lightTypes[i] = SG_LIGHT_DIRECTIONAL;
114 macros.append(
"#extension GL_EXT_texture_buffer: enable");
154 ShaderGenLightType lightTypes[SG_MAX_SHADER_LIGHTS];
156 bool twoSidedLighting;
158 ShaderGenShadeMode shadeMode;
163 QString vertexTemplateFile;
164 QString tessControlTemplateFile;
165 QString tessEvaluationTemplateFile;
166 QString geometryTemplateFile;
167 QString fragmentTemplateFile;
170 std::vector<unsigned int> shaderMods;
191 GLenum colorMaterialMode;
196 uint clipDistanceMask;
209 const std::map<size_t,TextureType>& textureTypes()
const {
return textureTypes_;}
219 textureTypes_[_stage] = t;
225 bool textured()
const {
return !textureTypes_.empty();}
240 bool texGenPerFragment;
242 void enableTexGenObjectLinear(
int _dim = 2)
244 texGenDim = std::max(std::min(_dim, 4), 0);
245 texGenMode = GL_OBJECT_LINEAR;
248 void enableTexGenEyeLinear(
int _dim = 2)
250 texGenDim = std::max(std::min(_dim, 4), 0);
251 texGenMode = GL_EYE_LINEAR;
254 void enableTexGenSphericalMap(
int _dim = 2)
256 texGenDim = std::max(std::min(_dim, 2), 0);
257 texGenMode = GL_SPHERE_MAP;
260 void enableTexGenNormalMap(
int _dim = 3)
262 texGenDim = std::max(std::min(_dim, 3), 0);
263 texGenMode = GL_NORMAL_MAP;
266 void enableTexGenReflectionMap(
int _dim = 3)
268 texGenDim = std::max(std::min(_dim, 3), 0);
269 texGenMode = GL_REFLECTION_MAP;
272 void disableTexGen() { texGenDim = 0; }
278 if (numLights != _rhs.numLights)
281 if ( twoSidedLighting != _rhs.twoSidedLighting )
284 if (shadeMode != _rhs.shadeMode)
287 if (vertexColors != _rhs.vertexColors)
290 if (textured() != _rhs.textured())
298 if (colorMaterialMode != _rhs.colorMaterialMode)
302 if (!geometryTemplateFile.isEmpty())
305 if (clipDistanceMask != _rhs.clipDistanceMask)
309 if (fragmentTemplateFile != _rhs.fragmentTemplateFile)
312 if (geometryTemplateFile != _rhs.geometryTemplateFile)
315 if (vertexTemplateFile != _rhs.vertexTemplateFile)
318 if (tessControlTemplateFile != _rhs.tessControlTemplateFile)
321 if (tessEvaluationTemplateFile != _rhs.tessEvaluationTemplateFile)
324 if (macros != _rhs.macros)
327 if (texGenDim != _rhs.texGenDim)
332 if (texGenMode != _rhs.texGenMode)
335 if (texGenPerFragment != _rhs.texGenPerFragment)
339 if (shaderMods != _rhs.shaderMods)
346 return memcmp(lightTypes, _rhs.lightTypes, numLights *
sizeof(ShaderGenLightType)) == 0;
586 void setGLSLVersion(
int _version);
590 void addIncludeFile(QString _fileName);
619 void initDefaultUniforms();
629 void addInput(
const QString& _input);
639 void addInput(
const QString& _type,
const QString& _varname) {
addInput(_type + QString(
" ") + _varname); }
649 void addOutput(
const QString& _output);
659 void addOutput(
const QString& _type,
const QString& _varname) {
addOutput(_type + QString(
" ") + _varname); }
670 void addUniform(QString _uniform, QString _comment =
"");
679 void addDefine(
const QString& _define);
684 void addIODefine(
const QString& _macroName,
const QString& _resolvedName);
689 void addMacros(
const QStringList& _macros);
698 bool hasDefine(QString _define)
const;
707 void addLayout(QString _layout);
728 void addLight(
int lightIndex_, ShaderGenLightType _light);
735 void buildShaderCode(QStringList* _pMainCode,
const QStringList& _defaultLightingFunctions);
739 const QStringList& getShaderCode();
745 void saveToFile(
const char* _fileName);
760 void matchInputs(
const ShaderGenerator* _previousShaderStage,
bool _passToNextStage, QString _inputPrefix =
"outVertex", QString _outputPrefix =
"outGeometry");
772 void defineIOAbstraction(
const DefaultIODesc* _iodesc,
bool _vs,
bool _fs);
776 int getNumOutputs()
const;
782 QString getOutputName(
int _id)
const;
786 int getNumInputs()
const;
792 QString getInputName(
int _id)
const;
799 QString getIOMapName(
int _inId)
const;
811 QString macro_requestPosVS,
813 macro_requestTexcoord,
814 macro_requestVertexColor,
815 macro_requestNormalVS,
816 macro_requestNormalOS;
819 QString macro_inputPosVS,
825 macro_inputVertexColor,
830 macro_outputNormalVS,
831 macro_outputNormalOS,
832 macro_outputTexcoord,
833 macro_outputVertexColor;
845 QString vs_inputPrefix,
853 QString vs_inputPosition,
863 vs_outputVertexColor,
864 fs_outputFragmentColor;
875 void addStringToList(QString _str, QStringList* _list, QString _prefix =
"", QString _postfix =
"");
880 void addIOToCode(
const QStringList& _cmds);
891 QStringList outputs_;
892 QStringList uniforms_;
893 QStringList genDefines_;
894 QStringList layouts_;
1132 unsigned int getID() {
return modifierID_;}
1171 operator std::vector<unsigned int>()
const {
return std::vector<unsigned int>(1,modifierID_);}
1173 std::vector<unsigned int> operator | (
const std::vector<unsigned int>& _v)
const 1175 std::vector<unsigned int> r(1 + _v.size(), modifierID_);
1176 for (
size_t i = 0; i < _v.size(); ++i)
1182 unsigned int modifierID_;
1197 static void setShaderDir(QString _dir);
1202 static QString getShaderDir();
1250 void saveVertexShToFile(
const char* _fileName);
1251 void saveGeometryShToFile(
const char* _fileName);
1252 void saveFragmentShToFile(
const char* _fileName);
1256 const QStringList& getVertexShaderCode();
1260 const QStringList& getTessControlShaderCode();
1264 const QStringList& getTessEvaluationShaderCode();
1268 const QStringList& getGeometryShaderCode();
1272 const QStringList& getFragmentShaderCode();
1277 int getNumActiveModifiers()
const;
1294 bool hasGeometryShader()
const;
1298 bool hasTessControlShader()
const;
1302 bool hasTessEvaluationShader()
const;
1306 void generateShaders();
1313 static bool loadStringListFromFile(QString _fileName, QStringList* _out);
1318 static QString getAbsFilePath(QString _fileName);
1324 void loadShaderTemplateFromFile();
1328 void scanShaderTemplate(QStringList& _templateSrc, QString _templateFilename, QStringList* _outLayoutDirectives = 0);
1333 void init(
const ShaderGenDesc* _desc,
const unsigned int* _modifiers,
unsigned int _numActiveMods);
1335 void buildVertexShader();
1336 void buildTessControlShader();
1337 void buildTessEvalShader();
1338 void buildGeometryShader();
1339 void buildFragmentShader();
1341 void addVertexBeginCode(QStringList* _code);
1342 void addVertexEndCode(QStringList* _code);
1344 void addFragmentBeginCode(QStringList* _code);
1345 void addFragmentEndCode(QStringList* _code);
1351 void addLightingFunctions(QStringList* _code);
1355 void addLightingCode(QStringList* _code);
1359 void modifyLightingCode(QStringList* _code,
ShaderModifier* _modifier);
1363 void addTexGenCode(QStringList* _code,
bool _fragmentShader);
1366 static QString getPathName(QString _strFileName);
1370 int checkForIncludes(QString _str,
ShaderGenerator* _gen, QString _includePath);
1374 int checkForIncludes(QString _str, QStringList* _outImport, QString _includePath);
1380 static void loadLightingFunctions();
1388 QStringList vertexTemplate_;
1389 QStringList tessControlTemplate_;
1390 QStringList tessEvalTemplate_;
1391 QStringList geometryTemplate_;
1392 QStringList fragmentTemplate_;
1395 std::vector<ShaderModifier*> activeMods_;
1400 static std::vector<ShaderModifier*> registeredModifiers_;
1404 QString tessControlShaderFile_;
1405 QString tessEvalShaderFile_;
1406 QString geometryShaderFile_;
1407 QString fragmentShaderFile_;
1411 QStringList tessEvalLayout_;
1418 static QString shaderDir_;
1419 static QStringList lightingCode_;
Namespace providing different geometric functions concerning angles.
void clearTextures()
disables texture support and removes all texture types
bool normalizeTexColors
Defines if the textureVariable is normalized or not, if multiple textures are used.
virtual bool replaceDefaultLightingCode()
Specify whether this modifier replaces or extends the default lighting code.
virtual void modifyLightingCode(QStringList *_code, int _lightId, ShaderGenLightType _lightType)
Modify the default lighting code of the shader generator.
virtual void modifyTessEvalIO(ShaderGenerator *_shader)
Add your own inputs/outputs to the tessellation evaluation shader.
void addRawIOBlock(QStringList _codeBlock)
Add a raw glsl IO code block.
virtual void modifyFragmentBeginCode(QStringList *_code)
Append code the the fragment shader.
bool passPosVS_
default attributes that should be passed down from vertex shader
void addInput(const QString &_type, const QString &_varname)
Add one GLSL input specifier.
virtual void modifyVertexEndCode(QStringList *_code)
Append code the the vertex shader.
QString vertexShaderFile_
path + filename to shader templates
bool inputArrays_
inputs of shader are arrays (tess-control, tess-eval, geometry)
virtual void modifyFragmentIO(ShaderGenerator *_shader)
Add your own inputs/outputs to the fragment shader.
virtual void modifyFragmentEndCode(QStringList *_code)
Append code the the fragment shader.
unsigned int getID()
Returns the modifier ID.
void addOutput(const QString &_type, const QString &_varname)
Add one GLSL output specifier.
virtual void modifyTessControlIO(ShaderGenerator *_shader)
Add your own inputs/outputs to the tessellation control shader.
static int numRegisteredModifiers_
registered shader modifier
bool ACGDLLEXPORT openGLVersionTest(const int _major, const int _minor)
void addTextureType(GLenum _type, bool _shadow, size_t _stage)
adds a texture type to the shader and enables texturing.
virtual void modifyVertexIO(ShaderGenerator *_shader)
Add your own inputs/outputs to the vertex shader.
QStringList imports_
glsl code imports (with #include )
bool outputArrays_
outputs of shader are arrays (tess-control)
bool checkExtensionSupported(const std::string &_extension)
QString toString() const
convert ShaderGenDesc to string format for debugging
QString vertexColorsInterpolator
interpolation qualifier for input vertex colors: "flat", "smooth", "noperspective" ...
virtual void modifyVertexBeginCode(QStringList *_code)
Append code the the vertex shader.
std::map< size_t, TextureType > textureTypes_
holds the texture types (second) and the stage id (first). if empty, shader does not support textures...
bool inputTexCoord_
default attributes that should be imported in vertex shader
QString vertexNormalInterpolator
interpolation qualifier for vertex shader normal outputs: "flat", "smooth", "noperspective" ...
virtual void modifyGeometryIO(ShaderGenerator *_shader)
Add your own inputs/outputs to the geometry shader.
QStringList tessControlLayout_
layout() directives scanned from loaded templates
QString inputPrefix_
prefix of inputs to this shader, same as prefix of ouputs of previous stage
QStringList rawIO_
io block as glsl code
QString outputPrefix_
prefix of outputs of this shader
ShaderGenerator::DefaultIODesc ioDesc_
default IO descriptor for the vertex shader