From d109954578b4948706577dfffb7bde139678370a Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Wed, 14 Oct 2009 17:29:01 +0200 Subject: Fixed the GLSL-to-assembly code generator to output enums correctly. Fixed the output of enums such that the last item in the enum is not followed by comma. Changed the output of the license to say that the file is part of the QtOpenGL module, not the test suite. Reviewed-by: Trond --- src/opengl/util/generator.cpp | 53 ++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/opengl/util/generator.cpp b/src/opengl/util/generator.cpp index 62d19ff..0202fe1 100644 --- a/src/opengl/util/generator.cpp +++ b/src/opengl/util/generator.cpp @@ -54,6 +54,8 @@ QT_BEGIN_NAMESPACE QT_USE_NAMESPACE +#define TAB " " + typedef QPair QStringPair; QString readSourceFile(const QString &sourceFile, bool fragmentProgram = false) @@ -243,6 +245,30 @@ QString trimmed(QString source) return result; } +void writeVariablesEnum(QTextStream &out, const char *name, const QSet &s) +{ + out << "enum " << name << " {"; + QSet::const_iterator it = s.begin(); + if (it != s.end()) { + out << "\n" TAB "VAR_" << it->toUpper(); + for (++it; it != s.end(); ++it) + out << ",\n" TAB "VAR_" << it->toUpper(); + } + out << "\n};\n\n"; +} + +void writeTypesEnum(QTextStream &out, const char *name, const QList &s) +{ + out << "enum " << name << " {"; + QList::const_iterator it = s.begin(); + if (it != s.end()) { + out << "\n" TAB << it->first; + for (++it; it != s.end(); ++it) + out << ",\n" TAB << it->first; + } + out << "\n};\n\n"; +} + void writeIncludeFile(const QSet &variables, const QList &brushes, const QList &compositionModes, @@ -257,7 +283,7 @@ void writeIncludeFile(const QSet &variables, QTextStream out(&includeFile); - QLatin1String tab(" "); + QLatin1String tab(TAB); out << "/****************************************************************************\n" "**\n" @@ -265,7 +291,7 @@ void writeIncludeFile(const QSet &variables, "** All rights reserved.\n" "** Contact: Nokia Corporation (qt-info@nokia.com)\n" "**\n" - "** This file is part of the test suite of the Qt Toolkit.\n" + "** This file is part of the QtOpenGL module of the Qt Toolkit.\n" "**\n" "** $QT_BEGIN_LICENSE:LGPL$\n" "** No Commercial Usage\n" @@ -315,25 +341,10 @@ void writeIncludeFile(const QSet &variables, "//\n" "\n"; - out << "enum FragmentVariable {\n"; - foreach (QString str, variables) - out << tab << "VAR_" << str.toUpper() << ",\n"; - out << "};\n\n"; - - out << "enum FragmentBrushType {\n"; - foreach (QStringPair brush, brushes) - out << tab << brush.first << ",\n"; - out << "};\n\n"; - - out << "enum FragmentCompositionModeType {\n"; - foreach (QStringPair mode, compositionModes) - out << tab << mode.first << ",\n"; - out << "};\n\n"; - - out << "enum FragmentMaskType {\n"; - foreach (QStringPair mask, masks) - out << tab << mask.first << ",\n"; - out << "};\n\n"; + writeVariablesEnum(out, "FragmentVariable", variables); + writeTypesEnum(out, "FragmentBrushType", brushes); + writeTypesEnum(out, "FragmentCompositionModeType", compositionModes); + writeTypesEnum(out, "FragmentMaskType", masks); out << "static const unsigned int num_fragment_variables = " << variables.size() << ";\n\n"; out << "static const unsigned int num_fragment_brushes = " << brushes.size() << ";\n"; -- cgit v0.12