we need to be able to query the version before creating OpenGLDriver.
This commit is contained in:
committed by
Mathias Agopian
parent
35753bc6c2
commit
3c3320a2ba
@@ -23,6 +23,20 @@ using namespace utils;
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
bool OpenGLContext::queryOpenGLVersion(GLint* major, GLint* minor) noexcept {
|
||||
if constexpr (BACKEND_OPENGL_VERSION == BACKEND_OPENGL_VERSION_GLES) {
|
||||
char const* version = (char const*)glGetString(GL_VERSION);
|
||||
// This works on all versions of GLES
|
||||
int n = version ? sscanf(version, "OpenGL ES %d.%d", major, minor) : 0;
|
||||
return n == 2;
|
||||
} else if constexpr (BACKEND_OPENGL_VERSION == BACKEND_OPENGL_VERSION_GL) {
|
||||
// OpenGL version
|
||||
glGetIntegerv(GL_MAJOR_VERSION, major);
|
||||
glGetIntegerv(GL_MINOR_VERSION, minor);
|
||||
return (glGetError() != GL_NO_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
OpenGLContext::OpenGLContext() noexcept {
|
||||
state.vao.p = &mDefaultVAO;
|
||||
|
||||
@@ -39,9 +53,10 @@ OpenGLContext::OpenGLContext() noexcept {
|
||||
* Figure out GL / GLES version and available features
|
||||
*/
|
||||
|
||||
queryOpenGLVersion(&state.major, &state.minor);
|
||||
|
||||
if constexpr (BACKEND_OPENGL_VERSION == BACKEND_OPENGL_VERSION_GLES) {
|
||||
// This works on all versions of GLES
|
||||
sscanf(state.version, "OpenGL ES %d.%d", &state.major, &state.minor);
|
||||
if (state.major == 3 && state.minor >= 0) {
|
||||
mShaderModel = ShaderModel::GL_ES_30;
|
||||
}
|
||||
@@ -51,8 +66,6 @@ OpenGLContext::OpenGLContext() noexcept {
|
||||
initExtensionsGLES();
|
||||
} else if constexpr (BACKEND_OPENGL_VERSION == BACKEND_OPENGL_VERSION_GL) {
|
||||
// OpenGL version
|
||||
glGetIntegerv(GL_MAJOR_VERSION, &state.major);
|
||||
glGetIntegerv(GL_MINOR_VERSION, &state.minor);
|
||||
if (state.major == 4 && state.minor >= 1) {
|
||||
mShaderModel = ShaderModel::GL_CORE_41;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,8 @@ public:
|
||||
}
|
||||
} gl;
|
||||
|
||||
static bool queryOpenGLVersion(GLint* major, GLint* minor) noexcept;
|
||||
|
||||
OpenGLContext() noexcept;
|
||||
|
||||
constexpr static inline size_t getIndexForTextureTarget(GLuint target) noexcept;
|
||||
|
||||
@@ -115,10 +115,9 @@ Driver* OpenGLDriver::create(
|
||||
|
||||
// here we check we're on a supported version of GL before initializing the driver
|
||||
GLint major = 0, minor = 0;
|
||||
glGetIntegerv(GL_MAJOR_VERSION, &major);
|
||||
glGetIntegerv(GL_MINOR_VERSION, &minor);
|
||||
bool success = OpenGLContext::queryOpenGLVersion(&major, &minor);
|
||||
|
||||
if (UTILS_UNLIKELY(glGetError() != GL_NO_ERROR)) {
|
||||
if (UTILS_UNLIKELY(!success)) {
|
||||
PANIC_LOG("Can't get OpenGL version");
|
||||
cleanup:
|
||||
ec->terminate();
|
||||
|
||||
Reference in New Issue
Block a user