diff --git a/src/plugins/glsleditor/GLSLEditor.mimetypes.xml b/src/plugins/glsleditor/GLSLEditor.mimetypes.xml index 5d63307c03d4a08579552b31d1fa7df6cea9973b..9d2eb6c7db318c060701e2027c5c163c4892a2d2 100644 --- a/src/plugins/glsleditor/GLSLEditor.mimetypes.xml +++ b/src/plugins/glsleditor/GLSLEditor.mimetypes.xml @@ -13,13 +13,23 @@ <sub-class-of type="text/x-glsl"/> <comment>GLSL Fragment Shader file</comment> <glob pattern="*.frag"/> + </mime-type> + + <mime-type type="text/x-glsl-es-frag"> + <sub-class-of type="text/x-glsl"/> + <comment>GLSL/ES Fragment Shader file</comment> <glob pattern="*.fsh"/> </mime-type> <mime-type type="text/x-glsl-vert"> <sub-class-of type="text/x-glsl"/> - <comment>GLSL Fragment Shader file</comment> + <comment>GLSL Vertex Shader file</comment> <glob pattern="*.vert"/> + </mime-type> + + <mime-type type="text/x-glsl-es-vert"> + <sub-class-of type="text/x-glsl"/> + <comment>GLSL/ES Vertex Shader file</comment> <glob pattern="*.vsh"/> </mime-type> diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index 760636d9c56cd958bf097ecc763f39e17f34dda2..1350512c23b751cda184ac513773f75b43e9ba1f 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -316,8 +316,12 @@ void GLSLTextEditor::updateDocumentNow() { m_updateDocumentTimer->stop(); - int variant = Lexer::Variant_GLSL_Qt; // ### hardcoded + int variant = 0; + if (isDesktopShader()) + variant |= Lexer::Variant_GLSL_120; + else + variant |= Lexer::Variant_GLSL_Qt; if (isVertexShader()) variant |= Lexer::Variant_VertexShader; if (isFragmentShader()) @@ -336,11 +340,11 @@ void GLSLTextEditor::updateDocumentNow() Semantic sem; Scope *globalScope = engine->newNamespace(); doc->_globalScope = globalScope; - sem.translationUnit(plugin->shaderInit()->ast, globalScope, plugin->shaderInit()->engine); + sem.translationUnit(plugin->shaderInit(variant)->ast, globalScope, plugin->shaderInit(variant)->engine); if (variant & Lexer::Variant_VertexShader) - sem.translationUnit(plugin->vertexShaderInit()->ast, globalScope, plugin->vertexShaderInit()->engine); + sem.translationUnit(plugin->vertexShaderInit(variant)->ast, globalScope, plugin->vertexShaderInit(variant)->engine); if (variant & Lexer::Variant_FragmentShader) - sem.translationUnit(plugin->fragmentShaderInit()->ast, globalScope, plugin->fragmentShaderInit()->engine); + sem.translationUnit(plugin->fragmentShaderInit(variant)->ast, globalScope, plugin->fragmentShaderInit(variant)->engine); sem.translationUnit(ast, globalScope, engine); CreateRanges createRanges(document(), doc); @@ -380,14 +384,28 @@ void GLSLTextEditor::updateDocumentNow() } } +bool GLSLTextEditor::isDesktopShader() const +{ + return mimeType() == QLatin1String("text/x-glsl-vert") || + mimeType() == QLatin1String("text/x-glsl-frag") || + mimeType() == QLatin1String("text/x-glsl") || // Could be either. + mimeType() == QLatin1String("application/x-glsl"); +} + bool GLSLTextEditor::isVertexShader() const { - return mimeType() == QLatin1String("text/x-glsl-vert"); + return mimeType() == QLatin1String("text/x-glsl-vert") || + mimeType() == QLatin1String("text/x-glsl-es-vert") || + mimeType() == QLatin1String("text/x-glsl") || // Could be either. + mimeType() == QLatin1String("application/x-glsl"); } bool GLSLTextEditor::isFragmentShader() const { - return mimeType() == QLatin1String("text/x-glsl-frag"); + return mimeType() == QLatin1String("text/x-glsl-frag") || + mimeType() == QLatin1String("text/x-glsl-es-frag") || + mimeType() == QLatin1String("text/x-glsl") || // Could be either. + mimeType() == QLatin1String("application/x-glsl"); } Document::Ptr GLSLTextEditor::glslDocument() const diff --git a/src/plugins/glsleditor/glsleditor.h b/src/plugins/glsleditor/glsleditor.h index c5e822e8ce057448ca66b1e8f8b71dd22980c631..cc5826314ecf4aff6e6667cbda8aeab5b277acc6 100644 --- a/src/plugins/glsleditor/glsleditor.h +++ b/src/plugins/glsleditor/glsleditor.h @@ -97,6 +97,7 @@ public: QSet<QString> identifiers() const; + bool isDesktopShader() const; bool isVertexShader() const; bool isFragmentShader() const; diff --git a/src/plugins/glsleditor/glsleditorconstants.h b/src/plugins/glsleditor/glsleditorconstants.h index 05748725c229b8a33b0c04a65896a69739eb0157..e9d1f045d23d6555306cd7f21797bb46b6684b04 100644 --- a/src/plugins/glsleditor/glsleditorconstants.h +++ b/src/plugins/glsleditor/glsleditorconstants.h @@ -50,6 +50,10 @@ const char * const TASK_INDEX = "GLSLEditor.TaskIndex"; const char * const TASK_SEARCH = "GLSLEditor.TaskSearch"; const char * const GLSL_MIMETYPE = "application/x-glsl"; +const char * const GLSL_MIMETYPE_VERT = "text/x-glsl-vert"; +const char * const GLSL_MIMETYPE_FRAG = "text/x-glsl-frag"; +const char * const GLSL_MIMETYPE_VERT_ES = "text/x-glsl-es-vert"; +const char * const GLSL_MIMETYPE_FRAG_ES = "text/x-glsl-es-frag"; const char * const WIZARD_CATEGORY_GLSL = "U.GLSL"; const char * const WIZARD_TR_CATEGORY_GLSL = QT_TRANSLATE_NOOP("GLSLEditor", "GLSL"); diff --git a/src/plugins/glsleditor/glsleditorfactory.cpp b/src/plugins/glsleditor/glsleditorfactory.cpp index 216dbf5d6cd239413672a575be559aa75d31e6dd..06cd4edf7d9080ca901b7c1c434aa9112039d072 100644 --- a/src/plugins/glsleditor/glsleditorfactory.cpp +++ b/src/plugins/glsleditor/glsleditorfactory.cpp @@ -55,6 +55,10 @@ GLSLEditorFactory::GLSLEditorFactory(QObject *parent) { m_mimeTypes << QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE) + << QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_VERT) + << QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG) + << QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_VERT_ES) + << QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG_ES) ; } diff --git a/src/plugins/glsleditor/glsleditorplugin.cpp b/src/plugins/glsleditor/glsleditorplugin.cpp index 825b245cb91d18b928afd113eaa83e753044fdc8..6c47328aa4361d518ab581fa48e6ab1fba8a2e03 100644 --- a/src/plugins/glsleditor/glsleditorplugin.cpp +++ b/src/plugins/glsleditor/glsleditorplugin.cpp @@ -173,6 +173,14 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er Core::MimeDatabase *mimeDatabase = Core::ICore::instance()->mimeDatabase(); iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")), mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE))); + iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")), + mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_VERT))); + iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")), + mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG))); + iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")), + mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_VERT_ES))); + iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")), + mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG_ES))); Core::BaseFileWizardParameters fragWizardParameters(Core::IWizard::FileWizard); fragWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL)); @@ -182,9 +190,9 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er "Language (GLSL/ES). Fragment shaders generate the final " "pixel colors for triangles, points, and lines rendered " "with OpenGL.")); - fragWizardParameters.setDisplayName(tr("Fragment shader")); + fragWizardParameters.setDisplayName(tr("Fragment shader (OpenGL/ES 2.0)")); fragWizardParameters.setId(QLatin1String("F.GLSL")); - addAutoReleasedObject(new GLSLFileWizard(fragWizardParameters, GLSLFileWizard::FragmentShader, core)); + addAutoReleasedObject(new GLSLFileWizard(fragWizardParameters, GLSLFileWizard::FragmentShaderES, core)); Core::BaseFileWizardParameters vertWizardParameters(Core::IWizard::FileWizard); vertWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL)); @@ -194,9 +202,27 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er "Language (GLSL/ES). Vertex shaders transform the " "positions, normals, and texture co-ordinates of " "triangles, points, and lines rendered with OpenGL.")); - vertWizardParameters.setDisplayName(tr("Vertex shader")); - vertWizardParameters.setId(QLatin1String("V.GLSL")); - addAutoReleasedObject(new GLSLFileWizard(vertWizardParameters, GLSLFileWizard::VertexShader, core)); + vertWizardParameters.setDisplayName(tr("Vertex shader (OpenGL/ES 2.0)")); + vertWizardParameters.setId(QLatin1String("G.GLSL")); + addAutoReleasedObject(new GLSLFileWizard(vertWizardParameters, GLSLFileWizard::VertexShaderES, core)); + + fragWizardParameters.setDescription + (tr("Creates a fragment shader in the Desktop OpenGL Shading " + "Language (GLSL). Fragment shaders generate the final " + "pixel colors for triangles, points, and lines rendered " + "with OpenGL.")); + fragWizardParameters.setDisplayName(tr("Fragment shader (Desktop OpenGL)")); + fragWizardParameters.setId(QLatin1String("J.GLSL")); + addAutoReleasedObject(new GLSLFileWizard(fragWizardParameters, GLSLFileWizard::FragmentShaderDesktop, core)); + + vertWizardParameters.setDescription + (tr("Creates a vertex shader in the Desktop OpenGL Shading " + "Language (GLSL). Vertex shaders transform the " + "positions, normals, and texture co-ordinates of " + "triangles, points, and lines rendered with OpenGL.")); + vertWizardParameters.setDisplayName(tr("Vertex shader (Desktop OpenGL)")); + vertWizardParameters.setId(QLatin1String("K.GLSL")); + addAutoReleasedObject(new GLSLFileWizard(vertWizardParameters, GLSLFileWizard::VertexShaderDesktop, core)); return true; } @@ -263,23 +289,28 @@ void GLSLEditorPlugin::parseGlslFile(const QString &fileName, InitFile *initFile initFile->ast = parser.parse(); } -const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::fragmentShaderInit() const +const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::fragmentShaderInit(int variant) const { - // TODO: select the correct language variant - //return &m_glsl_120_frag; - return &m_glsl_es_100_frag; + if (variant & GLSL::Lexer::Variant_GLSL_120) + return &m_glsl_120_frag; + else + return &m_glsl_es_100_frag; } -const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::vertexShaderInit() const +const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::vertexShaderInit(int variant) const { - //return &m_glsl_120_vert; - return &m_glsl_es_100_vert; + if (variant & GLSL::Lexer::Variant_GLSL_120) + return &m_glsl_120_vert; + else + return &m_glsl_es_100_vert; } -const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::shaderInit() const +const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::shaderInit(int variant) const { - //return &m_glsl_120_common; - return &m_glsl_es_100_common; + if (variant & GLSL::Lexer::Variant_GLSL_120) + return &m_glsl_120_common; + else + return &m_glsl_es_100_common; } Q_EXPORT_PLUGIN(GLSLEditorPlugin) diff --git a/src/plugins/glsleditor/glsleditorplugin.h b/src/plugins/glsleditor/glsleditorplugin.h index 6561d64335a1785f4dee35576daa43e61cf880c4..d9ddbfb0d7cef13cf28a22a7d2c263f05e5433da 100644 --- a/src/plugins/glsleditor/glsleditorplugin.h +++ b/src/plugins/glsleditor/glsleditorplugin.h @@ -94,9 +94,9 @@ public: ~InitFile(); }; - const InitFile *fragmentShaderInit() const; - const InitFile *vertexShaderInit() const; - const InitFile *shaderInit() const; + const InitFile *fragmentShaderInit(int variant) const; + const InitFile *vertexShaderInit(int variant) const; + const InitFile *shaderInit(int variant) const; private: QByteArray glslFile(const QString &fileName); diff --git a/src/plugins/glsleditor/glslfilewizard.cpp b/src/plugins/glsleditor/glslfilewizard.cpp index 5dc020a67e2eaebe92575de2d7cd9dfe94c8657e..35759badcb20376ec9fcbfd004c7f328a5beccf6 100644 --- a/src/plugins/glsleditor/glslfilewizard.cpp +++ b/src/plugins/glsleditor/glslfilewizard.cpp @@ -67,7 +67,6 @@ Core::GeneratedFiles GLSLFileWizard::generateFiles(const QWizard *w, const QString path = wizardDialog->path(); const QString name = wizardDialog->fileName(); - const QString mimeType = QLatin1String(Constants::GLSL_MIMETYPE); const QString fileName = Core::BaseFileWizard::buildFileName(path, name, preferredSuffix(m_shaderType)); Core::GeneratedFile file(fileName); @@ -82,7 +81,7 @@ QString GLSLFileWizard::fileContents(const QString &, ShaderType shaderType) con QTextStream str(&contents); switch (shaderType) { - case GLSLFileWizard::VertexShader: + case GLSLFileWizard::VertexShaderES: str << QLatin1String("attribute highp vec4 qgl_Vertex;\n") << QLatin1String("attribute highp vec4 qgl_TexCoord0;\n") << QLatin1String("uniform highp mat4 qgl_ModelViewProjectionMatrix;\n") @@ -94,7 +93,7 @@ QString GLSLFileWizard::fileContents(const QString &, ShaderType shaderType) con << QLatin1String(" qTexCoord0 = qgl_TexCoord0;\n") << QLatin1String("}\n"); break; - case GLSLFileWizard::FragmentShader: + case GLSLFileWizard::FragmentShaderES: str << QLatin1String("uniform sampler2D qgl_Texture0;\n") << QLatin1String("varying highp vec4 qTexCoord0;\n") << QLatin1String("\n") @@ -103,6 +102,27 @@ QString GLSLFileWizard::fileContents(const QString &, ShaderType shaderType) con << QLatin1String(" gl_FragColor = texture2D(qgl_Texture0, qTexCoord0.st);\n") << QLatin1String("}\n"); break; + case GLSLFileWizard::VertexShaderDesktop: + str << QLatin1String("attribute vec4 qgl_Vertex;\n") + << QLatin1String("attribute vec4 qgl_TexCoord0;\n") + << QLatin1String("uniform mat4 qgl_ModelViewProjectionMatrix;\n") + << QLatin1String("varying vec4 qTexCoord0;\n") + << QLatin1String("\n") + << QLatin1String("void main(void)\n") + << QLatin1String("{\n") + << QLatin1String(" gl_Position = qgl_ModelViewProjectionMatrix * qgl_Vertex;\n") + << QLatin1String(" qTexCoord0 = qgl_TexCoord0;\n") + << QLatin1String("}\n"); + break; + case GLSLFileWizard::FragmentShaderDesktop: + str << QLatin1String("uniform sampler2D qgl_Texture0;\n") + << QLatin1String("varying vec4 qTexCoord0;\n") + << QLatin1String("\n") + << QLatin1String("void main(void)\n") + << QLatin1String("{\n") + << QLatin1String(" gl_FragColor = texture2D(qgl_Texture0, qTexCoord0.st);\n") + << QLatin1String("}\n"); + break; default: break; } @@ -124,9 +144,13 @@ QWizard *GLSLFileWizard::createWizardDialog(QWidget *parent, const QString &defa QString GLSLFileWizard::preferredSuffix(ShaderType shaderType) const { switch (shaderType) { - case GLSLFileWizard::VertexShader: + case GLSLFileWizard::VertexShaderES: + return QLatin1String("vsh"); + case GLSLFileWizard::FragmentShaderES: + return QLatin1String("fsh"); + case GLSLFileWizard::VertexShaderDesktop: return QLatin1String("vert"); - case GLSLFileWizard::FragmentShader: + case GLSLFileWizard::FragmentShaderDesktop: return QLatin1String("frag"); default: return QLatin1String("glsl"); diff --git a/src/plugins/glsleditor/glslfilewizard.h b/src/plugins/glsleditor/glslfilewizard.h index 9823dcca6b4fd58a163b81502bdb8f2a47b89ce7..2133ef26a5499710cea5af30b4577a32a9cec8b5 100644 --- a/src/plugins/glsleditor/glslfilewizard.h +++ b/src/plugins/glsleditor/glslfilewizard.h @@ -43,8 +43,10 @@ public: enum ShaderType { - VertexShader, - FragmentShader + VertexShaderES, + FragmentShaderES, + VertexShaderDesktop, + FragmentShaderDesktop }; explicit GLSLFileWizard(const BaseFileWizardParameters ¶meters,