<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>
{
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())
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);
}
}
+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
QSet<QString> identifiers() const;
+ bool isDesktopShader() const;
bool isVertexShader() const;
bool isFragmentShader() const;
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");
{
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)
;
}
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));
"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));
"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;
}
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)
~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);
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);
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")
<< 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")
<< 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;
}
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");
enum ShaderType
{
- VertexShader,
- FragmentShader
+ VertexShaderES,
+ FragmentShaderES,
+ VertexShaderDesktop,
+ FragmentShaderDesktop
};
explicit GLSLFileWizard(const BaseFileWizardParameters ¶meters,