| 1 | Upstream-status: <https://github.com/OpenBoardView/OpenBoardView/pull/372>
|
| 2 |
|
| 3 | diff --git a/.gitmodules b/.gitmodules
|
| 4 | index ce80999..dd529f0 100644
|
| 5 | |
| 6 | |
| 7 | @@ -5,9 +5,6 @@
|
| 8 | path = src/utf8
|
| 9 | url = https://github.com/sheredom/utf8.h.git
|
| 10 | branch = master
|
| 11 | -[submodule "src/glad"]
|
| 12 | - path = src/glad
|
| 13 | - url = https://github.com/Dav1dde/glad.git
|
| 14 | [submodule "src/imgui"]
|
| 15 | path = src/imgui
|
| 16 | url = https://github.com/ocornut/imgui
|
| 17 | diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
|
| 18 | index af8fdd4..b359dde 100644
|
| 19 | |
| 20 | |
| 21 | @@ -1,5 +1,4 @@
|
| 22 | ## COMMON ##
|
| 23 | -option(ENABLE_GL1 "Build OpenGL 1 renderer." ON)
|
| 24 | option(ENABLE_GL3 "Build OpenGL 3 renderer." ON)
|
| 25 | option(ENABLE_GLES2 "Configure OpenGL 3 renderer to be OpenGL ES 2.0 compatible." OFF)
|
| 26 |
|
| 27 | @@ -52,21 +51,6 @@ if(NOT SQLITE3_FOUND)
|
| 28 | add_subdirectory(sqlite3)
|
| 29 | endif()
|
| 30 |
|
| 31 | -## glad ##
|
| 32 | -execute_process(
|
| 33 | - COMMAND git submodule update --init src/glad
|
| 34 | - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
| 35 | -)
|
| 36 | -set(GLAD_SOURCES_DIR "${PROJECT_SOURCE_DIR}/src/glad")
|
| 37 | -add_subdirectory(glad/cmake glad_cmake)
|
| 38 | -
|
| 39 | -if(ENABLE_GL1 OR ENABLE_GL3)
|
| 40 | -glad_add_library(glad_gl REPRODUCIBLE API gl:compatibility=3.2 EXTENSIONS NONE)
|
| 41 | -endif()
|
| 42 | -if(ENABLE_GLES2)
|
| 43 | -glad_add_library(glad_gles REPRODUCIBLE API gles2=2.0 EXTENSIONS GL_OES_element_index_uint GL_EXT_texture_format_BGRA8888)
|
| 44 | -endif()
|
| 45 | -
|
| 46 | ## SDL2 ##
|
| 47 | find_package(SDL2 REQUIRED CONFIG)
|
| 48 | add_definitions(-DENABLE_SDL2)
|
| 49 | @@ -89,27 +73,34 @@ if(NOT TARGET SDL2::SDL2)
|
| 50 | endif()
|
| 51 | endif()
|
| 52 |
|
| 53 | +## OpenGL ##
|
| 54 | +add_library(opengl_target INTERFACE IMPORTED)
|
| 55 | +if(ENABLE_GL3)
|
| 56 | + find_package(OpenGL REQUIRED)
|
| 57 | + set_target_properties(opengl_target PROPERTIES
|
| 58 | + INTERFACE_COMPILE_DEFINITIONS ENABLE_GL3
|
| 59 | + )
|
| 60 | + if(ENABLE_GLES2)
|
| 61 | + set_target_properties(opengl_target PROPERTIES
|
| 62 | + INTERFACE_LINK_LIBRARIES OpenGL::GLES2
|
| 63 | + INTERFACE_COMPILE_DEFINITIONS ENABLE_GLES2
|
| 64 | + )
|
| 65 | + else()
|
| 66 | + set_target_properties(opengl_target PROPERTIES
|
| 67 | + INTERFACE_LINK_LIBRARIES OpenGL::GL
|
| 68 | + )
|
| 69 | + endif()
|
| 70 | +endif()
|
| 71 | +
|
| 72 | ## imgui ##
|
| 73 | # note: in the future there may be integrated CMake support into imgui
|
| 74 | # see: https://github.com/ocornut/imgui/pull/1713
|
| 75 | -# for now do it manually, after glad and SDL2 because we use the includes for the sdl_opengl examples
|
| 76 | +# for now do it manually, after SDL2 because we use the includes for the sdl_opengl examples
|
| 77 | execute_process(
|
| 78 | COMMAND git submodule update --init src/imgui
|
| 79 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
| 80 | )
|
| 81 |
|
| 82 | -# workaround for OpenGL include for OpenGL2, need to be glad rather than gl itself
|
| 83 | -file(READ "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl2.cpp" input)
|
| 84 | -string(REPLACE "OpenGL/gl.h" "glad/gl.h" input "${input}")
|
| 85 | -string(REPLACE "GL/gl.h" "glad/gl.h" input "${input}")
|
| 86 | -file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl2.cpp" "${input}")
|
| 87 | -
|
| 88 | -# workaround for OpenGLES includes, need to be glad rather than gles itself
|
| 89 | -file(READ "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl3.cpp" input)
|
| 90 | -string(REPLACE "GLES2/gl2.h" "glad/gles.h" input "${input}")
|
| 91 | -string(REPLACE "GLES3/gl3.h" "glad/gles.h" input "${input}")
|
| 92 | -file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/imgui/backends/imgui_impl_opengl3.cpp" "${input}")
|
| 93 | -
|
| 94 | set(SOURCES
|
| 95 | imgui/imgui.cpp
|
| 96 | imgui/imgui_draw.cpp
|
| 97 | @@ -119,11 +110,6 @@ set(SOURCES
|
| 98 | imgui/backends/imgui_impl_sdl2.cpp)
|
| 99 |
|
| 100 |
|
| 101 | -if(ENABLE_GL1)
|
| 102 | - LIST(APPEND SOURCES
|
| 103 | - imgui/backends/imgui_impl_opengl2.cpp
|
| 104 | - )
|
| 105 | -endif()
|
| 106 | if(ENABLE_GL3)
|
| 107 | LIST(APPEND SOURCES
|
| 108 | imgui/backends/imgui_impl_opengl3.cpp
|
| 109 | @@ -132,7 +118,6 @@ endif()
|
| 110 |
|
| 111 | add_library(imgui STATIC ${SOURCES})
|
| 112 | target_compile_definitions(imgui PUBLIC "-DImDrawIdx=unsigned int") # short is not enough for us
|
| 113 | -target_compile_definitions(imgui PUBLIC "-DIMGUI_IMPL_OPENGL_LOADER_GLAD") # We use glad
|
| 114 | # Configure GL3 renderer to be GLES2 compatible if GLES2 is enabled
|
| 115 | if(ENABLE_GLES2)
|
| 116 | target_compile_definitions(imgui PUBLIC "-DIMGUI_IMPL_OPENGL_ES2")
|
| 117 | @@ -142,15 +127,7 @@ target_include_directories(imgui PUBLIC
|
| 118 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/examples
|
| 119 | ${CMAKE_CURRENT_SOURCE_DIR}/imgui/misc/cpp
|
| 120 | )
|
| 121 | -if(ENABLE_GLES2)
|
| 122 | -target_link_libraries(imgui
|
| 123 | - glad_gles
|
| 124 | -)
|
| 125 | -elseif(ENABLE_GL1 OR ENABLE_GL3)
|
| 126 | - target_link_libraries(imgui
|
| 127 | - glad_gl
|
| 128 | - )
|
| 129 | -endif()
|
| 130 | +
|
| 131 | if(MINGW)
|
| 132 | target_link_libraries(imgui
|
| 133 | SDL2::SDL2-static
|
| 134 | diff --git a/src/openboardview/CMakeLists.txt b/src/openboardview/CMakeLists.txt
|
| 135 | index 7f8fbc0..470a145 100644
|
| 136 | |
| 137 | |
| 138 | @@ -1,13 +1,3 @@
|
| 139 | -if(ENABLE_GL1)
|
| 140 | - add_definitions(-DENABLE_GL1)
|
| 141 | -endif()
|
| 142 | -if(ENABLE_GL3)
|
| 143 | - add_definitions(-DENABLE_GL3)
|
| 144 | -endif()
|
| 145 | -if(ENABLE_GLES2)
|
| 146 | - add_definitions(-DENABLE_GLES2)
|
| 147 | -endif()
|
| 148 | -
|
| 149 | # Platform-specific configuration
|
| 150 | if(WIN32)
|
| 151 | add_definitions(-DUNICODE)
|
| 152 | @@ -15,8 +5,6 @@ if(WIN32)
|
| 153 | else()
|
| 154 | if(APPLE)
|
| 155 | find_library(COCOA_LIBRARY Cocoa)
|
| 156 | - find_package(OpenGL REQUIRED)
|
| 157 | - set(OPENGL_INCLUDE_DIR ${OPENGL_INCLUDE_DIR}/Headers)
|
| 158 | else(APPLE)
|
| 159 | find_package(PkgConfig REQUIRED)
|
| 160 |
|
| 161 | @@ -113,11 +101,6 @@ set(SOURCES
|
| 162 | main_opengl.cpp
|
| 163 | )
|
| 164 |
|
| 165 | -if(ENABLE_GL1)
|
| 166 | - LIST(APPEND SOURCES
|
| 167 | - Renderers/ImGuiRendererSDLGL1.cpp
|
| 168 | - )
|
| 169 | -endif()
|
| 170 | if(ENABLE_GL3)
|
| 171 | LIST(APPEND SOURCES
|
| 172 | Renderers/ImGuiRendererSDLGL3.cpp
|
| 173 | @@ -191,9 +174,8 @@ target_include_directories(${PROJECT_NAME_LOWER} PRIVATE
|
| 174 | ${CMAKE_CURRENT_BINARY_DIR} # for build-generated
|
| 175 | ${IMGUI_INCLUDE_DIRS}
|
| 176 | ${UTF8_INCLUDE_DIR}
|
| 177 | - ${GLAD_INCLUDE_DIRS}
|
| 178 | ${GTK_INCLUDE_DIRS}
|
| 179 | - ${OPENGL_INCLUDE_DIR}
|
| 180 | + opengl_target
|
| 181 | ${ZLIB_INCLUDE_DIRS}
|
| 182 | ${FONTCONFIG_INCLUDE_DIRS}
|
| 183 | )
|
| 184 | @@ -202,7 +184,7 @@ target_link_libraries(${PROJECT_NAME_LOWER}
|
| 185 | imgui
|
| 186 | SQLite::SQLite3
|
| 187 | mpc
|
| 188 | - ${GLAD_LIBRARIES}
|
| 189 | + opengl_target
|
| 190 | ${COCOA_LIBRARY}
|
| 191 | ${ZLIB_LIBRARIES}
|
| 192 | ${FILESYSTEM_LIBRARIES}
|
| 193 | diff --git a/src/openboardview/Renderers/ImGuiRendererSDL.cpp b/src/openboardview/Renderers/ImGuiRendererSDL.cpp
|
| 194 | index 73f8fe8..1de05f1 100644
|
| 195 | |
| 196 | |
| 197 | @@ -3,16 +3,19 @@
|
| 198 | #include <sstream>
|
| 199 | #include <vector>
|
| 200 |
|
| 201 | -#ifdef ENABLE_GLES2
|
| 202 | -#include <glad/gles2.h>
|
| 203 | -#else
|
| 204 | -#include <glad/gl.h>
|
| 205 | -#endif
|
| 206 | -
|
| 207 | #define STB_IMAGE_IMPLEMENTATION
|
| 208 | #include <stb_image.h>
|
| 209 |
|
| 210 | #include "filesystem_impl.h"
|
| 211 | +
|
| 212 | +#ifdef ENABLE_GLES2
|
| 213 | +#include <SDL_opengles2.h>
|
| 214 | +#else
|
| 215 | +#define GL_GLEXT_PROTOTYPES 1
|
| 216 | +#include <SDL_opengl.h>
|
| 217 | +#include <SDL2/SDL_opengl_glext.h>
|
| 218 | +#endif
|
| 219 | +#include "backends/imgui_impl_opengl3.h"
|
| 220 | #include "backends/imgui_impl_sdl2.h"
|
| 221 | #include "../utils.h"
|
| 222 |
|
| 223 | @@ -71,13 +74,9 @@ bool ImGuiRendererSDL::init() {
|
| 224 | return false;
|
| 225 | }
|
| 226 |
|
| 227 | -#ifdef ENABLE_GLES2
|
| 228 | - this->version = gladLoadGLES2(reinterpret_cast<GLADloadfunc>(SDL_GL_GetProcAddress));
|
| 229 | -#else
|
| 230 | - this->version = gladLoadGL(reinterpret_cast<GLADloadfunc>(SDL_GL_GetProcAddress));
|
| 231 | -#endif
|
| 232 | + SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &this->version);
|
| 233 | if (!version) {
|
| 234 | - SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s: glad failed to load OpenGL\n", this->name().c_str());
|
| 235 | + SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s: imgui failed to load OpenGL\n", this->name().c_str());
|
| 236 | shutdown();
|
| 237 | return false;
|
| 238 | }
|
| 239 | @@ -104,7 +103,7 @@ bool ImGuiRendererSDL::init() {
|
| 240 | SDL_LogWarn(SDL_LOG_CATEGORY_RENDER, "%s: Unable to enable VSync: %s\n", this->name().c_str(), SDL_GetError());
|
| 241 |
|
| 242 | // check if we got the correct OpenGL context version
|
| 243 | - if (!this->checkGLVersion(this->version)) {
|
| 244 | + if (!this->checkGLVersion()) {
|
| 245 | shutdown();
|
| 246 | return false;
|
| 247 | }
|
| 248 | diff --git a/src/openboardview/Renderers/ImGuiRendererSDL.h b/src/openboardview/Renderers/ImGuiRendererSDL.h
|
| 249 | index bb058ef..d1d4f33 100644
|
| 250 | |
| 251 | |
| 252 | @@ -3,12 +3,9 @@
|
| 253 |
|
| 254 | #include <string>
|
| 255 |
|
| 256 | -// SDL, glad
|
| 257 | -#ifdef ENABLE_GLES2
|
| 258 | -#include <glad/gles2.h>
|
| 259 | -#else
|
| 260 | -#include <glad/gl.h>
|
| 261 | -#endif
|
| 262 | +#include "backends/imgui_impl_opengl3.h"
|
| 263 | +#include "backends/imgui_impl_sdl2.h"
|
| 264 | +
|
| 265 | #include <SDL.h>
|
| 266 |
|
| 267 | #include <imgui.h>
|
| 268 | @@ -23,7 +20,7 @@ public:
|
| 269 | virtual ~ImGuiRendererSDL();
|
| 270 |
|
| 271 | virtual std::string name();
|
| 272 | - virtual bool checkGLVersion(int version) = 0;
|
| 273 | + virtual bool checkGLVersion() = 0;
|
| 274 | virtual bool init();
|
| 275 | virtual void processEvent(SDL_Event &event);
|
| 276 | virtual void initFrame();
|
| 277 | diff --git a/src/openboardview/Renderers/ImGuiRendererSDLGL1.cpp b/src/openboardview/Renderers/ImGuiRendererSDLGL1.cpp
|
| 278 | deleted file mode 100644
|
| 279 | index 7e75f6d..0000000
|
| 280 | |
| 281 | |
| 282 | @@ -1,104 +0,0 @@
|
| 283 | -#include "ImGuiRendererSDLGL1.h"
|
| 284 | -
|
| 285 | -#include <glad/gl.h>
|
| 286 | -#include "backends/imgui_impl_opengl2.h"
|
| 287 | -
|
| 288 | -std::string ImGuiRendererSDLGL1::name() {
|
| 289 | - return "ImGuiRendererSDLGL1";
|
| 290 | -}
|
| 291 | -
|
| 292 | -bool ImGuiRendererSDLGL1::checkGLVersion(int version) {
|
| 293 | - int major = GLAD_VERSION_MAJOR(version);
|
| 294 | - int minor = GLAD_VERSION_MINOR(version);
|
| 295 | -
|
| 296 | - if (major < 1 || (major == 1 && minor < 1)) {
|
| 297 | - SDL_LogError(SDL_LOG_CATEGORY_RENDER,
|
| 298 | - "Minimal OpenGL version required is %d.%d. Got %d.%d.",
|
| 299 | - 1,
|
| 300 | - 1,
|
| 301 | - major,
|
| 302 | - minor);
|
| 303 | - return false;
|
| 304 | - }
|
| 305 | - return true;
|
| 306 | -}
|
| 307 | -
|
| 308 | -void ImGuiRendererSDLGL1::setGLVersion() {
|
| 309 | - ImGuiRendererSDL::setGLVersion();
|
| 310 | - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
|
| 311 | - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
| 312 | -}
|
| 313 | -
|
| 314 | -bool ImGuiRendererSDLGL1::init() {
|
| 315 | - return ImGuiRendererSDL::init() && ImGui_ImplOpenGL2_Init();
|
| 316 | -}
|
| 317 | -
|
| 318 | -void ImGuiRendererSDLGL1::initFrame() {
|
| 319 | - ImGui_ImplOpenGL2_NewFrame();
|
| 320 | - ImGuiRendererSDL::initFrame();
|
| 321 | -}
|
| 322 | -
|
| 323 | -void ImGuiRendererSDLGL1::renderDrawData() {
|
| 324 | - ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
|
| 325 | -}
|
| 326 | -
|
| 327 | -void ImGuiRendererSDLGL1::shutdown() {
|
| 328 | - if (ImGui::GetIO().BackendRendererUserData != nullptr) {
|
| 329 | - ImGui_ImplOpenGL2_Shutdown();
|
| 330 | - }
|
| 331 | - ImGuiRendererSDL::shutdown();
|
| 332 | -}
|
| 333 | -
|
| 334 | -std::string ImGuiRendererSDLGL1::createTexture(ImTextureID* out_texture, uint8_t* data, int w, int h, char fmt) {
|
| 335 | - GLuint tex;
|
| 336 | - GLenum format;
|
| 337 | -
|
| 338 | - if (w > glMaxTextureSize) {
|
| 339 | - return "width of " + std::to_string(w) + "px is too large for this GPU. Maximum allowed: " + std::to_string(glMaxTextureSize);
|
| 340 | - }
|
| 341 | -
|
| 342 | - if (h > glMaxTextureSize) {
|
| 343 | - return "height of " + std::to_string(h) + "px is too large for this GPU. Maximum allowed: " + std::to_string(glMaxTextureSize);
|
| 344 | - }
|
| 345 | -
|
| 346 | - switch (fmt) {
|
| 347 | - default:
|
| 348 | - case 0:
|
| 349 | - format = GL_BGRA;
|
| 350 | - break;
|
| 351 | - case 1:
|
| 352 | - format = GL_RGBA;
|
| 353 | - break;
|
| 354 | - case 2:
|
| 355 | - format = GL_RGB;
|
| 356 | - break;
|
| 357 | - }
|
| 358 | -
|
| 359 | - glGenTextures(1, &tex);
|
| 360 | - glBindTexture(GL_TEXTURE_2D, tex);
|
| 361 | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
| 362 | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
| 363 | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
| 364 | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
| 365 | -
|
| 366 | - int major = GLAD_VERSION_MAJOR(version);
|
| 367 | - int minor = GLAD_VERSION_MINOR(version);
|
| 368 | - if (major == 2 || (major == 1 && minor >= 4)) {
|
| 369 | - glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
| 370 | - }
|
| 371 | - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, format, GL_UNSIGNED_BYTE, data);
|
| 372 | -
|
| 373 | - GLenum code = glGetError();
|
| 374 | - if (code == GL_OUT_OF_MEMORY) {
|
| 375 | - return "image too large to fit in the GPU memory.";
|
| 376 | - }
|
| 377 | - if (code != GL_NO_ERROR) {
|
| 378 | - return "error " + std::to_string(code) + " when loading the image into GPU memory.";
|
| 379 | - }
|
| 380 | -
|
| 381 | - glBindTexture(GL_TEXTURE_2D, 0);
|
| 382 | -
|
| 383 | - *out_texture = tex;
|
| 384 | -
|
| 385 | - return {};
|
| 386 | -}
|
| 387 | diff --git a/src/openboardview/Renderers/ImGuiRendererSDLGL1.h b/src/openboardview/Renderers/ImGuiRendererSDLGL1.h
|
| 388 | deleted file mode 100644
|
| 389 | index 0f66c16..0000000
|
| 390 | |
| 391 | |
| 392 | @@ -1,22 +0,0 @@
|
| 393 | -#ifndef _IMGUIRENDERERSDLGL1_H_
|
| 394 | -#define _IMGUIRENDERERSDLGL1_H_
|
| 395 | -
|
| 396 | -#include <string>
|
| 397 | -
|
| 398 | -#include "ImGuiRendererSDL.h"
|
| 399 | -
|
| 400 | -class ImGuiRendererSDLGL1 : public ImGuiRendererSDL {
|
| 401 | - using ImGuiRendererSDL::ImGuiRendererSDL;
|
| 402 | -
|
| 403 | -public:
|
| 404 | - std::string name();
|
| 405 | - bool checkGLVersion(int version);
|
| 406 | - void setGLVersion();
|
| 407 | - bool init();
|
| 408 | - void initFrame();
|
| 409 | - void renderDrawData();
|
| 410 | - void shutdown();
|
| 411 | - std::string createTexture(ImTextureID* out_texture, uint8_t* data, int w, int h, char fmt);
|
| 412 | -};
|
| 413 | -
|
| 414 | -#endif
|
| 415 | diff --git a/src/openboardview/Renderers/ImGuiRendererSDLGL3.cpp b/src/openboardview/Renderers/ImGuiRendererSDLGL3.cpp
|
| 416 | index 1810e7a..2c5d79b 100644
|
| 417 | |
| 418 | |
| 419 | @@ -1,20 +1,38 @@
|
| 420 | #include "ImGuiRendererSDLGL3.h"
|
| 421 |
|
| 422 | -
|
| 423 | #ifdef ENABLE_GLES2
|
| 424 | -#include <glad/gles2.h>
|
| 425 | +#include <SDL_opengles2.h>
|
| 426 | #else
|
| 427 | -#include <glad/gl.h>
|
| 428 | +#include <SDL_opengl.h>
|
| 429 | +#include <SDL_opengl_glext.h> // for extension typedefs like PFNGLGENERATEMIPMAPPROC
|
| 430 | #endif
|
| 431 | #include "backends/imgui_impl_opengl3.h"
|
| 432 | +#include "backends/imgui_impl_sdl2.h"
|
| 433 | +
|
| 434 | +#ifdef ENABLE_GLES2
|
| 435 | +#define GLEXT_MIPMAP_FUNC "glGenerateMipmapOES"
|
| 436 | +#else
|
| 437 | +#define GLEXT_MIPMAP_FUNC "glGenerateMipmap"
|
| 438 | +#endif
|
| 439 | +
|
| 440 | +#ifndef PFNGLGENERATEMIPMAPPROC // fallback for GLES2
|
| 441 | +typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target);
|
| 442 | +#endif
|
| 443 | +
|
| 444 | +static inline void portable_glGenerateMipmap(GLenum target) {
|
| 445 | + static auto pfn = (PFNGLGENERATEMIPMAPPROC)SDL_GL_GetProcAddress(GLEXT_MIPMAP_FUNC);
|
| 446 | + if (pfn) pfn(target);
|
| 447 | +}
|
| 448 |
|
| 449 | std::string ImGuiRendererSDLGL3::name() {
|
| 450 | return "ImGuiRendererSDLGL3";
|
| 451 | }
|
| 452 |
|
| 453 | -bool ImGuiRendererSDLGL3::checkGLVersion(int version) {
|
| 454 | - int major = GLAD_VERSION_MAJOR(version);
|
| 455 | - int minor = GLAD_VERSION_MINOR(version);
|
| 456 | +bool ImGuiRendererSDLGL3::checkGLVersion() {
|
| 457 | + int major, minor;
|
| 458 | +
|
| 459 | + SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
|
| 460 | + SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
|
| 461 |
|
| 462 | if (major < GL_VERSION_MAJOR || (major == GL_VERSION_MAJOR && minor < GL_VERSION_MINOR)) {
|
| 463 | SDL_LogError(SDL_LOG_CATEGORY_RENDER,
|
| 464 | @@ -129,7 +147,7 @@ std::string ImGuiRendererSDLGL3::createTexture(ImTextureID* out_texture, uint8_t
|
| 465 | return "error " + std::to_string(code) + " when loading the image into GPU memory.";
|
| 466 | }
|
| 467 |
|
| 468 | - glGenerateMipmap(GL_TEXTURE_2D);
|
| 469 | + portable_glGenerateMipmap(GL_TEXTURE_2D);
|
| 470 | glBindTexture(GL_TEXTURE_2D, 0);
|
| 471 |
|
| 472 | *out_texture = tex;
|
| 473 | diff --git a/src/openboardview/Renderers/ImGuiRendererSDLGL3.h b/src/openboardview/Renderers/ImGuiRendererSDLGL3.h
|
| 474 | index af84011..2e47e0b 100644
|
| 475 | |
| 476 | |
| 477 | @@ -21,7 +21,7 @@ class ImGuiRendererSDLGL3 : public ImGuiRendererSDL {
|
| 478 |
|
| 479 | public:
|
| 480 | std::string name();
|
| 481 | - bool checkGLVersion(int version);
|
| 482 | + bool checkGLVersion();
|
| 483 | void setGLVersion();
|
| 484 | bool init();
|
| 485 | void initFrame();
|
| 486 | diff --git a/src/openboardview/Renderers/Renderers.cpp b/src/openboardview/Renderers/Renderers.cpp
|
| 487 | index 1fb549d..94d5dd6 100644
|
| 488 | |
| 489 | |
| 490 | @@ -22,10 +22,6 @@ namespace Renderers {
|
| 491 |
|
| 492 | std::unique_ptr<ImGuiRendererSDL> newInstance(Renderer r) {
|
| 493 | switch (r) {
|
| 494 | -#ifdef ENABLE_GL1
|
| 495 | - case Renderer::OPENGL1:
|
| 496 | - return std::unique_ptr<ImGuiRendererSDL>(new ImGuiRendererSDLGL1());
|
| 497 | -#endif
|
| 498 | #ifdef ENABLE_GL3
|
| 499 | case Renderer::OPENGL3:
|
| 500 | return std::unique_ptr<ImGuiRendererSDL>(new ImGuiRendererSDLGL3());
|
| 501 | diff --git a/src/openboardview/Renderers/Renderers.h b/src/openboardview/Renderers/Renderers.h
|
| 502 | index f88c15b..f1d86cf 100644
|
| 503 | |
| 504 | |
| 505 | @@ -1,7 +1,6 @@
|
| 506 | #ifndef _RENDERERS_H_
|
| 507 | #define _RENDERERS_H_
|
| 508 |
|
| 509 | -#include "ImGuiRendererSDLGL1.h"
|
| 510 | #include "ImGuiRendererSDLGL3.h"
|
| 511 |
|
| 512 | #include <memory>
|
| 513 | diff --git a/src/openboardview/confparse.cpp b/src/openboardview/confparse.cpp
|
| 514 | index 4f7fd26..c6000c2 100644
|
| 515 | |
| 516 | |
| 517 | @@ -18,7 +18,6 @@ char default_conf[] =
|
| 518 | " configuration\r\n\
|
| 519 | #\r\n\
|
| 520 | # Renderer options\r\n\
|
| 521 | -# 1 = OpenGL1\r\n\
|
| 522 | # 2 = OpenGL3\r\n\
|
| 523 | # 3 = OpenGLES2\r\n\
|
| 524 | renderer=2\r\n\
|
| 525 | diff --git a/src/openboardview/main_opengl.cpp b/src/openboardview/main_opengl.cpp
|
| 526 | index 366cdef..14dc5a8 100644
|
| 527 | |
| 528 | |
| 529 | @@ -76,7 +76,7 @@ char help[] =
|
| 530 | -y <height> : Set window height\n\
|
| 531 | -z <pixels> : Set font size\n\
|
| 532 | -p <dpi> : Set the dpi\n\
|
| 533 | - -r <renderer> : Set the renderer [ OPENGL1 = 1; OPENGL3 = 2; OPENGLES2 = 3 ]\n\
|
| 534 | + -r <renderer> : Set the renderer [ OPENGL3 = 2; OPENGLES2 = 3 ]\n\
|
| 535 | -d : Debug mode\n\
|
| 536 | ";
|
| 537 |
|
| 538 | @@ -317,7 +317,7 @@ int main(int argc, char **argv) {
|
| 539 | // Setup renderer
|
| 540 | bool initialized = Renderers::initBestRenderer(g.renderer);
|
| 541 | if (!initialized) {
|
| 542 | - SDL_LogError(SDL_LOG_CATEGORY_RENDER, "%s", "No renderer not available. Exiting.");
|
| 543 | + SDL_LogError(SDL_LOG_CATEGORY_RENDER, "%s", "No renderer available. Exiting.");
|
| 544 | cleanupAndExit(1);
|
| 545 | }
|
| 546 |
|