Encapsulate GL version and standard into a struct and enum.
Change-Id: I9f51971c1bfd51424605b2687b5fd107d58c9a67
Reviewed-on: https://chromium-review.googlesource.com/273139
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/273572
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/Version.h b/src/libANGLE/Version.h
new file mode 100644
index 0000000..1e18750
--- /dev/null
+++ b/src/libANGLE/Version.h
@@ -0,0 +1,32 @@
+//
+// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// Version.h: Encapsulation of a GL version.
+
+#ifndef LIBANGLE_VERSION_H_
+#define LIBANGLE_VERSION_H_
+
+#include <angle_gl.h>
+
+namespace gl
+{
+
+struct Version
+{
+ Version();
+ Version(GLuint major, GLuint minor);
+
+ GLuint major;
+ GLuint minor;
+};
+
+bool operator>=(const Version &a, const Version &b);
+
+}
+
+#include "Version.inl"
+
+#endif // LIBANGLE_VERSION_H_
diff --git a/src/libANGLE/Version.inl b/src/libANGLE/Version.inl
new file mode 100644
index 0000000..4ac4308
--- /dev/null
+++ b/src/libANGLE/Version.inl
@@ -0,0 +1,28 @@
+//
+// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// Version.inl: Encapsulation of a GL version.
+
+namespace gl
+{
+
+inline Version::Version()
+ : Version(0, 0)
+{
+}
+
+inline Version::Version(GLuint major_, GLuint minor_)
+{
+ major = major_;
+ minor = minor_;
+}
+
+inline bool operator>=(const Version &a, const Version &b)
+{
+ return a.major > b.major || (a.major == b.major && a.minor >= b.minor);
+}
+
+}
diff --git a/src/libANGLE/renderer/gl/FunctionsGL.cpp b/src/libANGLE/renderer/gl/FunctionsGL.cpp
index 035dde6..da08392 100644
--- a/src/libANGLE/renderer/gl/FunctionsGL.cpp
+++ b/src/libANGLE/renderer/gl/FunctionsGL.cpp
@@ -16,8 +16,7 @@
namespace rx
{
-static void GetGLVersion(PFNGLGETSTRINGPROC getStringFunction, GLuint *outMajorVersion, GLuint *outMinorVersion,
- bool *outIsES)
+static void GetGLVersion(PFNGLGETSTRINGPROC getStringFunction, gl::Version *outVersion, StandardGL *outStandard)
{
const std::string version = reinterpret_cast<const char*>(getStringFunction(GL_VERSION));
if (version.find("OpenGL ES") == std::string::npos)
@@ -27,17 +26,15 @@
// The version number is either of the form major number.minor number or major
// number.minor number.release number, where the numbers all have one or more
// digits
- *outIsES = false;
- *outMajorVersion = version[0] - '0';
- *outMinorVersion = version[2] - '0';
+ *outStandard = STANDARD_GL_DESKTOP;
+ *outVersion = gl::Version(version[0] - '0', version[2] - '0');
}
else
{
// ES spec states that the GL_VERSION string will be in the following format:
// "OpenGL ES N.M vendor-specific information"
- *outIsES = true;
- *outMajorVersion = version[10] - '0';
- *outMinorVersion = version[12] - '0';
+ *outStandard = STANDARD_GL_ES;
+ *outVersion = gl::Version(version[10] - '0', version[12] - '0');
}
}
@@ -83,9 +80,8 @@
}
FunctionsGL::FunctionsGL()
- : majorVersion(0),
- minorVersion(0),
- openGLES(false),
+ : version(),
+ standard(),
extensions(),
blendFunc(nullptr),
@@ -777,10 +773,10 @@
{
// Grab the version number
AssignGLEntryPoint(loadProcAddress("glGetString"), &getString);
- GetGLVersion(getString, &majorVersion, &minorVersion, &openGLES);
+ GetGLVersion(getString, &version, &standard);
// Grab the GL extensions
- if (majorVersion >= 3)
+ if (isAtLeastGL(gl::Version(3, 0)))
{
AssignGLEntryPoint(loadProcAddress("glGetIntegerv"), &getIntegerv);
AssignGLEntryPoint(loadProcAddress("glGetStringi"), &getStringi);
@@ -793,7 +789,7 @@
}
// 1.0
- if (majorVersion >= 1)
+ if (isAtLeastGL(gl::Version(1, 0)))
{
AssignGLEntryPoint(loadProcAddress("glBlendFunc"), &blendFunc);
AssignGLEntryPoint(loadProcAddress("glClear"), &clear);
@@ -846,7 +842,7 @@
}
// 1.1
- if (majorVersion > 1 || (majorVersion == 1 && minorVersion >= 1))
+ if (isAtLeastGL(gl::Version(1, 1)))
{
AssignGLEntryPoint(loadProcAddress("glBindTexture"), &bindTexture);
AssignGLEntryPoint(loadProcAddress("glCopyTexImage1D"), ©TexImage1D);
@@ -879,7 +875,7 @@
}
// 1.2
- if (majorVersion > 1 || (majorVersion == 1 && minorVersion >= 2))
+ if (isAtLeastGL(gl::Version(1, 2)))
{
AssignGLEntryPoint(loadProcAddress("glBlendColor"), &blendColor);
AssignGLEntryPoint(loadProcAddress("glBlendEquation"), &blendEquation);
@@ -906,7 +902,7 @@
}
// 1.3
- if (majorVersion > 1 || (majorVersion == 1 && minorVersion >= 3))
+ if (isAtLeastGL(gl::Version(1, 3)))
{
AssignGLEntryPoint(loadProcAddress("glActiveTexture"), &activeTexture);
AssignGLEntryPoint(loadProcAddress("glCompressedTexImage1D"), &compressedTexImage1D);
@@ -920,7 +916,7 @@
}
// 1.4
- if (majorVersion > 1 || (majorVersion == 1 && minorVersion >= 4))
+ if (isAtLeastGL(gl::Version(1, 4)))
{
AssignGLEntryPoint(loadProcAddress("glBlendFuncSeparate"), &blendFuncSeparate);
AssignGLEntryPoint(loadProcAddress("glMultiDrawArrays"), &multiDrawArrays);
@@ -932,7 +928,7 @@
}
// 1.5
- if (majorVersion > 1 || (majorVersion == 1 && minorVersion >= 5))
+ if (isAtLeastGL(gl::Version(1, 5)))
{
AssignGLEntryPoint(loadProcAddress("glBeginQuery"), &beginQuery);
AssignGLEntryPoint(loadProcAddress("glBindBuffer"), &bindBuffer);
@@ -956,7 +952,7 @@
}
// 2.0
- if (majorVersion >= 2)
+ if (isAtLeastGL(gl::Version(2, 0)))
{
AssignGLEntryPoint(loadProcAddress("glAttachShader"), &attachShader);
AssignGLEntryPoint(loadProcAddress("glBindAttribLocation"), &bindAttribLocation);
@@ -1054,7 +1050,7 @@
}
// 2.1
- if (majorVersion > 2 || (majorVersion == 2 && minorVersion >= 1))
+ if (isAtLeastGL(gl::Version(2, 1)))
{
AssignGLEntryPoint(loadProcAddress("glUniformMatrix2x3fv"), &uniformMatrix2x3fv);
AssignGLEntryPoint(loadProcAddress("glUniformMatrix2x4fv"), &uniformMatrix2x4fv);
@@ -1065,7 +1061,7 @@
}
// 3.0
- if (majorVersion >= 3)
+ if (isAtLeastGL(gl::Version(3, 0)))
{
AssignGLEntryPoint(loadProcAddress("glBeginConditionalRender"), &beginConditionalRender);
AssignGLEntryPoint(loadProcAddress("glBeginTransformFeedback"), &beginTransformFeedback);
@@ -1157,7 +1153,7 @@
}
// 3.1
- if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 1))
+ if (isAtLeastGL(gl::Version(3, 1)))
{
AssignGLEntryPoint(loadProcAddress("glCopyBufferSubData"), ©BufferSubData);
AssignGLEntryPoint(loadProcAddress("glDrawArraysInstanced"), &drawArraysInstanced);
@@ -1184,7 +1180,7 @@
}
// 3.2
- if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 2))
+ if (isAtLeastGL(gl::Version(3, 2)))
{
AssignGLEntryPoint(loadProcAddress("glClientWaitSync"), &clientWaitSync);
AssignGLEntryPoint(loadProcAddress("glDeleteSync"), &deleteSync);
@@ -1208,7 +1204,7 @@
}
// 3.3
- if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 3))
+ if (isAtLeastGL(gl::Version(3, 3)))
{
AssignGLEntryPoint(loadProcAddress("glBindFragDataLocationIndexed"), &bindFragDataLocationIndexed);
AssignGLEntryPoint(loadProcAddress("glBindSampler"), &bindSampler);
@@ -1241,7 +1237,7 @@
}
// 4.0
- if (majorVersion >= 4)
+ if (isAtLeastGL(gl::Version(4, 0)))
{
AssignGLEntryPoint(loadProcAddress("glBeginQueryIndexed"), &beginQueryIndexed);
AssignGLEntryPoint(loadProcAddress("glBindTransformFeedback"), &bindTransformFeedback);
@@ -1292,7 +1288,7 @@
}
// 4.1
- if (majorVersion > 4 || (majorVersion == 4 && minorVersion >= 1))
+ if (isAtLeastGL(gl::Version(4, 1)))
{
AssignGLEntryPoint(loadProcAddress("glActiveShaderProgram"), &activeShaderProgram);
AssignGLEntryPoint(loadProcAddress("glBindProgramPipeline"), &bindProgramPipeline);
@@ -1385,7 +1381,7 @@
}
// 4.2
- if (majorVersion > 4 || (majorVersion == 4 && minorVersion >= 2))
+ if (isAtLeastGL(gl::Version(4, 2)))
{
AssignGLEntryPoint(loadProcAddress("glBindImageTexture"), &bindImageTexture);
AssignGLEntryPoint(loadProcAddress("glDrawArraysInstancedBaseInstance"), &drawArraysInstancedBaseInstance);
@@ -1402,7 +1398,7 @@
}
// 4.3
- if (majorVersion > 4 || (majorVersion == 4 && minorVersion >= 3))
+ if (isAtLeastGL(gl::Version(4, 3)))
{
AssignGLEntryPoint(loadProcAddress("glBindVertexBuffer"), &bindVertexBuffer);
AssignGLEntryPoint(loadProcAddress("glClearBufferData"), &clearBufferData);
@@ -1451,7 +1447,7 @@
}
// 4.4
- if (majorVersion > 4 || (majorVersion == 4 && minorVersion >= 4))
+ if (isAtLeastGL(gl::Version(4, 4)))
{
AssignGLEntryPoint(loadProcAddress("glBindBuffersBase"), &bindBuffersBase);
AssignGLEntryPoint(loadProcAddress("glBindBuffersRange"), &bindBuffersRange);
@@ -1465,7 +1461,7 @@
}
// 4.5
- if (majorVersion > 4 || (majorVersion == 4 && minorVersion >= 5))
+ if (isAtLeastGL(gl::Version(4, 5)))
{
AssignGLEntryPoint(loadProcAddress("glBindTextureUnit"), &bindTextureUnit);
AssignGLEntryPoint(loadProcAddress("glBlitNamedFramebuffer"), &blitNamedFramebuffer);
@@ -1580,6 +1576,16 @@
}
}
+bool FunctionsGL::isAtLeastGL(const gl::Version &glVersion) const
+{
+ return standard == STANDARD_GL_DESKTOP && version >= glVersion;
+}
+
+bool FunctionsGL::isAtLeastGLES(const gl::Version &glesVersion) const
+{
+ return standard == STANDARD_GL_ES && version >= glesVersion;
+}
+
bool FunctionsGL::hasExtension(const std::string &ext) const
{
return std::find(extensions.begin(), extensions.end(), ext) != extensions.end();
diff --git a/src/libANGLE/renderer/gl/FunctionsGL.h b/src/libANGLE/renderer/gl/FunctionsGL.h
index 297d8b1..da9becb 100644
--- a/src/libANGLE/renderer/gl/FunctionsGL.h
+++ b/src/libANGLE/renderer/gl/FunctionsGL.h
@@ -10,12 +10,19 @@
#define LIBANGLE_RENDERER_GL_FUNCTIONSGL_H_
#include "common/debug.h"
+#include "libANGLE/Version.h"
#include "libANGLE/renderer/gl/functionsgl_enums.h"
#include "libANGLE/renderer/gl/functionsgl_typedefs.h"
namespace rx
{
+enum StandardGL
+{
+ STANDARD_GL_DESKTOP,
+ STANDARD_GL_ES,
+};
+
class FunctionsGL
{
public:
@@ -25,9 +32,10 @@
void initialize();
// Version information
- GLuint majorVersion;
- GLuint minorVersion;
- bool openGLES;
+ gl::Version version;
+ StandardGL standard;
+ bool isAtLeastGL(const gl::Version &glVersion) const;
+ bool isAtLeastGLES(const gl::Version &glesVersion) const;
// Extensions
std::vector<std::string> extensions;
diff --git a/src/libANGLE/renderer/gl/RendererGL.cpp b/src/libANGLE/renderer/gl/RendererGL.cpp
index e6a6e4c..50bc836 100644
--- a/src/libANGLE/renderer/gl/RendererGL.cpp
+++ b/src/libANGLE/renderer/gl/RendererGL.cpp
@@ -254,11 +254,11 @@
std::ostringstream rendererString;
rendererString << nativeVendorString << " " << nativeRendererString << " OpenGL";
- if (mFunctions->openGLES)
+ if (mFunctions->standard == STANDARD_GL_ES)
{
rendererString << " ES";
}
- rendererString << " " << mFunctions->majorVersion << "." << mFunctions->minorVersion;
+ rendererString << " " << mFunctions->version.major << "." << mFunctions->version.minor;
return rendererString.str();
}
diff --git a/src/libANGLE/renderer/gl/formatutilsgl.cpp b/src/libANGLE/renderer/gl/formatutilsgl.cpp
index 91ce015..a6256fe 100644
--- a/src/libANGLE/renderer/gl/formatutilsgl.cpp
+++ b/src/libANGLE/renderer/gl/formatutilsgl.cpp
@@ -21,8 +21,7 @@
{
SupportRequirement::SupportRequirement()
- : majorVersion(std::numeric_limits<GLuint>::max()),
- minorVersion(std::numeric_limits<GLuint>::max()),
+ : version(std::numeric_limits<GLuint>::max(), std::numeric_limits<GLuint>::max()),
versionExtensions(),
requiredExtensions()
{
@@ -39,8 +38,8 @@
static inline SupportRequirement VersionOrExts(GLuint major, GLuint minor, const std::string &versionExt)
{
SupportRequirement requirement;
- requirement.majorVersion = major;
- requirement.minorVersion = minor;
+ requirement.version.major = major;
+ requirement.version.minor = minor;
angle::SplitStringAlongWhitespace(versionExt, &requirement.versionExtensions);
return requirement;
}
@@ -48,8 +47,8 @@
static inline SupportRequirement VersionAndExts(GLuint major, GLuint minor, const std::string &requiredExt)
{
SupportRequirement requirement;
- requirement.majorVersion = major;
- requirement.minorVersion = minor;
+ requirement.version.major = major;
+ requirement.version.minor = minor;
angle::SplitStringAlongWhitespace(requiredExt, &requirement.requiredExtensions);
return requirement;
}
@@ -57,8 +56,8 @@
static inline SupportRequirement VersionOrExtsAndExts(GLuint major, GLuint minor, const std::string &versionExt,
const std::string &requiredExt)
{ SupportRequirement requirement;
- requirement.majorVersion = major;
- requirement.minorVersion = minor;
+ requirement.version.major = major;
+ requirement.version.minor = minor;
angle::SplitStringAlongWhitespace(versionExt, &requirement.versionExtensions);
angle::SplitStringAlongWhitespace(requiredExt, &requirement.requiredExtensions);
return requirement;
@@ -67,8 +66,8 @@
static inline SupportRequirement VersionOnly(GLuint major, GLuint minor)
{
SupportRequirement requirement;
- requirement.majorVersion = major;
- requirement.minorVersion = minor;
+ requirement.version.major = major;
+ requirement.version.minor = minor;
return requirement;
}
@@ -82,16 +81,16 @@
static inline SupportRequirement Always()
{
SupportRequirement requirement;
- requirement.majorVersion = 0;
- requirement.minorVersion = 0;
+ requirement.version.major = 0;
+ requirement.version.minor = 0;
return requirement;
}
static inline SupportRequirement Never()
{
SupportRequirement requirement;
- requirement.majorVersion = std::numeric_limits<GLuint>::max();
- requirement.minorVersion = std::numeric_limits<GLuint>::max();
+ requirement.version.major = std::numeric_limits<GLuint>::max();
+ requirement.version.minor = std::numeric_limits<GLuint>::max();
return requirement;
}
@@ -234,20 +233,23 @@
return formatMap;
}
-const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, bool es)
+const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, StandardGL standard)
{
const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
InternalFormatInfoMap::const_iterator iter = formatMap.find(internalFormat);
if (iter != formatMap.end())
{
const InternalFormatInfo &info = iter->second;
- return es ? info.glesInfo : info.glInfo;
+ switch (standard)
+ {
+ case STANDARD_GL_ES: return info.glesInfo;
+ case STANDARD_GL_DESKTOP: return info.glInfo;
+ default: UNREACHABLE(); break;
+ }
}
- else
- {
- static const InternalFormat defaultInternalFormat;
- return defaultInternalFormat;
- }
+
+ static const InternalFormat defaultInternalFormat;
+ return defaultInternalFormat;
}
}
diff --git a/src/libANGLE/renderer/gl/formatutilsgl.h b/src/libANGLE/renderer/gl/formatutilsgl.h
index 51f1976..dc5ab7f 100644
--- a/src/libANGLE/renderer/gl/formatutilsgl.h
+++ b/src/libANGLE/renderer/gl/formatutilsgl.h
@@ -14,6 +14,8 @@
#include <vector>
#include "angle_gl.h"
+#include "libANGLE/Version.h"
+#include "libANGLE/renderer/gl/FunctionsGL.h"
namespace rx
{
@@ -26,8 +28,7 @@
SupportRequirement();
// Version that this format became supported without extensions
- GLuint majorVersion;
- GLuint minorVersion;
+ gl::Version version;
// Extensions that are required if the minimum version is not met
std::vector<std::string> versionExtensions;
@@ -45,7 +46,7 @@
SupportRequirement renderbuffer;
SupportRequirement framebufferAttachment;
};
-const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, bool es);
+const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, StandardGL standard);
}
diff --git a/src/libANGLE/renderer/gl/renderergl_utils.cpp b/src/libANGLE/renderer/gl/renderergl_utils.cpp
index 7293b42..ec292d0 100644
--- a/src/libANGLE/renderer/gl/renderergl_utils.cpp
+++ b/src/libANGLE/renderer/gl/renderergl_utils.cpp
@@ -35,8 +35,7 @@
}
}
- if (functions->majorVersion > requirements.majorVersion ||
- (functions->majorVersion == requirements.majorVersion && functions->minorVersion >= requirements.minorVersion))
+ if (functions->version >= requirements.version)
{
return true;
}
@@ -61,7 +60,7 @@
{
gl::TextureCaps textureCaps;
- const nativegl::InternalFormat &formatInfo = nativegl::GetInternalFormatInfo(internalFormat, functions->openGLES);
+ const nativegl::InternalFormat &formatInfo = nativegl::GetInternalFormatInfo(internalFormat, functions->standard);
textureCaps.texturable = MeetsRequirements(functions, formatInfo.texture);
textureCaps.filterable = textureCaps.texturable && MeetsRequirements(functions, formatInfo.filter);
textureCaps.renderable = MeetsRequirements(functions, formatInfo.framebufferAttachment);
diff --git a/src/libGLESv2.gypi b/src/libGLESv2.gypi
index 464296c..8d72b3e 100644
--- a/src/libGLESv2.gypi
+++ b/src/libGLESv2.gypi
@@ -109,6 +109,8 @@
'libANGLE/TransformFeedback.h',
'libANGLE/Uniform.cpp',
'libANGLE/Uniform.h',
+ 'libANGLE/Version.h',
+ 'libANGLE/Version.inl',
'libANGLE/VertexArray.cpp',
'libANGLE/VertexArray.h',
'libANGLE/VertexAttribute.cpp',