Skip to content

Commit

Permalink
fix logic
Browse files Browse the repository at this point in the history
[skip travis] why doesn't appveyor restart?

[skip apveyor] fix non-GL
  • Loading branch information
archibate committed Apr 25, 2020
1 parent b3ace2e commit d0c07e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions taichi/backends/opengl/opengl_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,16 @@ struct GLSSBO {
}
};

bool initialize_opengl(bool noerr) {
static bool gl_inited = false;
static bool gl_supp = false;
bool initialize_opengl(bool error_tolerance) {
static std::optional<bool> supported; // std::nullopt


if (gl_inited) {
if (!gl_supp) {
TI_ASSERT_INFO(noerr, "OpenGL not supported");
return false;
} else {
if (supported.has_value()) { // this function has been called before
if (supported.value()) { // detected to be true in last call
return true;
} else {
if (!error_tolerance) // not called from with_opengl
TI_ERROR("OpenGL not supported");
return false;
}
}

Expand All @@ -270,8 +269,11 @@ bool initialize_opengl(bool noerr) {
if (!window) {
const char *desc = nullptr;
int status = glfwGetError(&desc);
if (noerr && status == GLFW_API_UNAVAILABLE) {
if (error_tolerance && status == GLFW_API_UNAVAILABLE) {
// error tolerated, returning false
// note that we only tolerate GLFW_API_UNAVAILABLE
TI_TRACE("GLFW: OpenGL API unavailable");
supported = std::make_optional<bool>(false);
return false;
}
if (!desc)
Expand All @@ -290,14 +292,15 @@ bool initialize_opengl(bool noerr) {
#include "taichi/inc/opengl_extension.inc.h"
#undef PER_OPENGL_EXTENSION
if (!opengl_has_GL_ARB_compute_shader) {
if (noerr) {
if (error_tolerance) {
TI_INFO("Your OpenGL does not support GL_ARB_compute_shader extension");
supported = std::make_optional<bool>(false);
return false;
}
TI_ERROR("Your OpenGL does not support GL_ARB_compute_shader extension");
}

gl_supp = true;
supported = std::make_optional<bool>(true);
return true;
}

Expand Down Expand Up @@ -542,7 +545,7 @@ bool is_opengl_api_available() {
return false;
}

void initialize_opengl() {
bool initialize_opengl(bool error_tolerance) {
TI_NOT_IMPLEMENTED;
}

Expand Down
2 changes: 1 addition & 1 deletion taichi/backends/opengl/opengl_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class OffloadedStmt;

namespace opengl {

bool initialize_opengl(bool noerr = false);
bool initialize_opengl(bool error_tolerance = false);
bool is_opengl_api_available();
int opengl_get_threads_per_group();
#define PER_OPENGL_EXTENSION(x) extern bool opengl_has_##x;
Expand Down

0 comments on commit d0c07e6

Please sign in to comment.