Commit 140d8d35 authored by Christopher Tenter's avatar Christopher Tenter

dynamic shaders now support preprocessor macros

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20580 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 9049316a
......@@ -486,6 +486,18 @@ void ShaderGenerator::addDefine(QString _def)
addStringToList(_def, &genDefines_, "#define ");
}
void ShaderGenerator::addMacros(const QStringList& _macros)
{
// prepend macros to the "defines" list
// QStringList reverse_iterator:
typedef std::reverse_iterator<QStringList::const_iterator> QStringListReverseIterator;
QStringListReverseIterator rbegin( _macros.end() ), rend( _macros.begin() );
for (QStringListReverseIterator it = rbegin; it != rend; ++it)
genDefines_.push_front(*it);
}
bool ShaderGenerator::hasDefine(QString _define) const
{
if (genDefines_.contains(_define))
......@@ -1048,6 +1060,9 @@ void ShaderProgGenerator::initGenDefines(ShaderGenerator* _gen)
}
_gen->addDefine("SG_ALPHA g_vMaterial.y");
_gen->addMacros(desc_.macros);
}
......@@ -1147,7 +1162,7 @@ void ShaderProgGenerator::addVertexBeginCode(QStringList* _code)
// this can be done via shader modifiers or templates
if (ioDesc_.inputTexCoord_)
{
if (desc_.textureTypes().begin()->second.type == GL_TEXTURE_3D) {
if (!desc_.textureTypes().empty() && desc_.textureTypes().begin()->second.type == GL_TEXTURE_3D) {
_code->push_back("vec3 sg_vTexCoord = inTexCoord;");
} else {
_code->push_back("vec2 sg_vTexCoord = inTexCoord;");
......
......@@ -145,6 +145,10 @@ public:
QString geometryTemplateFile;
QString fragmentTemplateFile;
// preprocessor macros for the shaders
// these are added to all shaders directly after the #version directive
QStringList macros;
/// convert ShaderGenDesc to string format for debugging
QString toString() const;
......@@ -226,7 +230,10 @@ public:
if (tessControlTemplateFile != _rhs.tessControlTemplateFile)
return false;
if (_rhs.tessEvaluationTemplateFile != _rhs.tessEvaluationTemplateFile)
if (tessEvaluationTemplateFile != _rhs.tessEvaluationTemplateFile)
return false;
if (macros != _rhs.macros)
return false;
if (numLights)
......@@ -544,6 +551,11 @@ public:
*/
void addDefine(QString _define);
/** \brief Add a list of preprocessor macros
*
*/
void addMacros(const QStringList& _macros);
/** \brief Check for define
*
* Example:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment