opengl: move glsl version to OpenGlContext
This commit is contained in:
parent
c5cd8d1318
commit
605401dcfc
6 changed files with 27 additions and 13 deletions
|
@ -742,8 +742,8 @@ void GLPlatform::detect(OpenGLPlatformInterface platformInterface)
|
|||
m_mesaVersion = Version::parseString(versionTokens.at(mesaIndex + 1));
|
||||
}
|
||||
|
||||
m_glsl_version = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||
m_glslVersion = Version::parseString(m_glsl_version);
|
||||
m_glsl_version = m_context->glslVersionString().toByteArray();
|
||||
m_glslVersion = m_context->glslVersion();
|
||||
|
||||
m_chipset = QByteArrayLiteral("Unknown");
|
||||
m_preferBufferSubData = false;
|
||||
|
|
|
@ -96,11 +96,11 @@ const QByteArray GLShader::prepareSource(GLenum shaderType, const QByteArray &so
|
|||
// Prepare the source code
|
||||
QByteArray ba;
|
||||
const auto context = OpenGlContext::currentContext();
|
||||
if (context->isOpenglES() && GLPlatform::instance()->glslVersion() < Version(3, 0)) {
|
||||
if (context->isOpenglES() && context->glslVersion() < Version(3, 0)) {
|
||||
ba.append("precision highp float;\n");
|
||||
}
|
||||
ba.append(source);
|
||||
if (context->isOpenglES() && GLPlatform::instance()->glslVersion() >= Version(3, 0)) {
|
||||
if (context->isOpenglES() && context->glslVersion() >= Version(3, 0)) {
|
||||
ba.replace("#version 140", "#version 300 es\n\nprecision highp float;\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -41,12 +41,11 @@ QByteArray ShaderManager::generateVertexSource(ShaderTraits traits) const
|
|||
QByteArray source;
|
||||
QTextStream stream(&source);
|
||||
|
||||
GLPlatform *const gl = GLPlatform::instance();
|
||||
const auto context = OpenGlContext::currentContext();
|
||||
QByteArray attribute, varying;
|
||||
|
||||
if (!context->isOpenglES()) {
|
||||
const bool glsl_140 = gl->glslVersion() >= Version(1, 40);
|
||||
const bool glsl_140 = context->glslVersion() >= Version(1, 40);
|
||||
|
||||
attribute = glsl_140 ? QByteArrayLiteral("in") : QByteArrayLiteral("attribute");
|
||||
varying = glsl_140 ? QByteArrayLiteral("out") : QByteArrayLiteral("varying");
|
||||
|
@ -55,7 +54,7 @@ QByteArray ShaderManager::generateVertexSource(ShaderTraits traits) const
|
|||
stream << "#version 140\n\n";
|
||||
}
|
||||
} else {
|
||||
const bool glsl_es_300 = gl->glslVersion() >= Version(3, 0);
|
||||
const bool glsl_es_300 = context->glslVersion() >= Version(3, 0);
|
||||
|
||||
attribute = glsl_es_300 ? QByteArrayLiteral("in") : QByteArrayLiteral("attribute");
|
||||
varying = glsl_es_300 ? QByteArrayLiteral("out") : QByteArrayLiteral("varying");
|
||||
|
@ -92,12 +91,11 @@ QByteArray ShaderManager::generateFragmentSource(ShaderTraits traits) const
|
|||
QByteArray source;
|
||||
QTextStream stream(&source);
|
||||
|
||||
GLPlatform *const gl = GLPlatform::instance();
|
||||
const auto context = OpenGlContext::currentContext();
|
||||
QByteArray varying, output, textureLookup;
|
||||
|
||||
if (!context->isOpenglES()) {
|
||||
const bool glsl_140 = gl->glslVersion() >= Version(1, 40);
|
||||
const bool glsl_140 = context->glslVersion() >= Version(1, 40);
|
||||
|
||||
if (glsl_140) {
|
||||
stream << "#version 140\n\n";
|
||||
|
@ -107,7 +105,7 @@ QByteArray ShaderManager::generateFragmentSource(ShaderTraits traits) const
|
|||
textureLookup = glsl_140 ? QByteArrayLiteral("texture") : QByteArrayLiteral("texture2D");
|
||||
output = glsl_140 ? QByteArrayLiteral("fragColor") : QByteArrayLiteral("gl_FragColor");
|
||||
} else {
|
||||
const bool glsl_es_300 = GLPlatform::instance()->glslVersion() >= Version(3, 0);
|
||||
const bool glsl_es_300 = context->glslVersion() >= Version(3, 0);
|
||||
|
||||
if (glsl_es_300) {
|
||||
stream << "#version 300 es\n\n";
|
||||
|
@ -260,7 +258,7 @@ static QString resolveShaderFilePath(const QString &filePath)
|
|||
|
||||
const auto context = OpenGlContext::currentContext();
|
||||
const Version coreVersionNumber = context->isOpenglES() ? Version(3, 0) : Version(1, 40);
|
||||
if (GLPlatform::instance()->glslVersion() >= coreVersionNumber) {
|
||||
if (context->glslVersion() >= coreVersionNumber) {
|
||||
suffix = QStringLiteral("_core");
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,8 @@ static bool checkIndexedQuads(OpenGlContext *context)
|
|||
OpenGlContext::OpenGlContext()
|
||||
: m_versionString((const char *)glGetString(GL_VERSION))
|
||||
, m_version(Version::parseString(m_versionString))
|
||||
, m_glslVersionString((const char *)glGetString(GL_SHADING_LANGUAGE_VERSION))
|
||||
, m_glslVersion(Version::parseString(m_glslVersionString))
|
||||
, m_vendor((const char *)glGetString(GL_VENDOR))
|
||||
, m_renderer((const char *)glGetString(GL_RENDERER))
|
||||
, m_isOpenglES(m_versionString.startsWith("OpenGL ES"))
|
||||
|
@ -123,6 +125,16 @@ Version OpenGlContext::openglVersion() const
|
|||
return m_version;
|
||||
}
|
||||
|
||||
QByteArrayView OpenGlContext::glslVersionString() const
|
||||
{
|
||||
return m_glslVersionString;
|
||||
}
|
||||
|
||||
Version OpenGlContext::glslVersion() const
|
||||
{
|
||||
return m_glslVersion;
|
||||
}
|
||||
|
||||
QByteArrayView OpenGlContext::vendor() const
|
||||
{
|
||||
return m_vendor;
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
|
||||
QByteArrayView openglVersionString() const;
|
||||
Version openglVersion() const;
|
||||
QByteArrayView glslVersionString() const;
|
||||
Version glslVersion() const;
|
||||
QByteArrayView vendor() const;
|
||||
QByteArrayView renderer() const;
|
||||
bool isOpenglES() const;
|
||||
|
@ -74,6 +76,8 @@ protected:
|
|||
|
||||
const QByteArrayView m_versionString;
|
||||
const Version m_version;
|
||||
const QByteArrayView m_glslVersionString;
|
||||
const Version m_glslVersion;
|
||||
const QByteArrayView m_vendor;
|
||||
const QByteArrayView m_renderer;
|
||||
const bool m_isOpenglES;
|
||||
|
|
|
@ -97,8 +97,8 @@ void ContrastShader::init()
|
|||
|
||||
const auto context = OpenGlContext::currentContext();
|
||||
const bool gles = context->isOpenglES();
|
||||
const bool glsl_140 = !gles && GLPlatform::instance()->glslVersion() >= Version(1, 40);
|
||||
const bool core = glsl_140 || (gles && GLPlatform::instance()->glslVersion() >= Version(3, 0));
|
||||
const bool glsl_140 = !gles && context->glslVersion() >= Version(1, 40);
|
||||
const bool core = glsl_140 || (gles && context->glslVersion() >= Version(3, 0));
|
||||
|
||||
QByteArray vertexSource;
|
||||
QByteArray fragmentSource;
|
||||
|
|
Loading…
Reference in a new issue