Added support for OpenGL 2.1 and OpenGL ES 3.0 with no modifications to the code necessary by the user

This commit is contained in:
Ryzerth 2021-08-21 17:45:21 +02:00
parent 53cb328c2c
commit f01cb4af9f
3 changed files with 72 additions and 26 deletions

View File

@ -37,6 +37,32 @@
#endif
#endif
const char* OPENGL_VERSIONS_GLSL[] = {
"#version 120",
"#version 300 es",
"#version 120"
};
const int OPENGL_VERSIONS_MAJOR[] = {
3,
3,
2
};
const int OPENGL_VERSIONS_MINOR[] = {
0,
1,
1
};
const bool OPENGL_VERSIONS_IS_ES[] = {
false,
true,
false
};
#define OPENGL_VERSION_COUNT (sizeof(OPENGL_VERSIONS_GLSL) / sizeof(char*))
namespace core {
ConfigManager configManager;
ModuleManager moduleManager;
@ -258,26 +284,6 @@ int sdrpp_main(int argc, char *argv[]) {
if (options::opts.serverMode) { return server_main(); }
// Setup window
glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit()) {
return 1;
}
#ifdef __APPLE__
// GL 3.2 + GLSL 150
const char* glsl_version = "#version 150";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
#else
// GL 3.0 + GLSL 120
const char* glsl_version = "#version 120";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
#endif
core::configManager.acquire();
int winWidth = core::configManager.conf["windowSize"]["w"];
int winHeight = core::configManager.conf["windowSize"]["h"];
@ -291,13 +297,53 @@ int sdrpp_main(int argc, char *argv[]) {
return 1;
}
// Setup window
glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit()) {
return 1;
}
#ifdef __APPLE__
// GL 3.2 + GLSL 150
const char* glsl_version = "#version 150";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
// Create window with graphics context
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
core::window = glfwCreateWindow(winWidth, winHeight, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL);
if (core::window == NULL)
return 1;
glfwMakeContextCurrent(core::window);
#else
const char* glsl_version = "#version 120";
GLFWmonitor* monitor = NULL;
for (int i = 0; i < OPENGL_VERSION_COUNT; i++) {
glsl_version = OPENGL_VERSIONS_GLSL[i];
if (OPENGL_VERSIONS_IS_ES[i]) {
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_VERSIONS_MAJOR[i]);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OPENGL_VERSIONS_MINOR[i]);
// Create window with graphics context
monitor = glfwGetPrimaryMonitor();
core::window = glfwCreateWindow(winWidth, winHeight, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL);
if (core::window == NULL) {
spdlog::info("OpenGL {0}.{1} {2}was not supported", OPENGL_VERSIONS_MAJOR[i], OPENGL_VERSIONS_MINOR[i], OPENGL_VERSIONS_IS_ES[i] ? "ES ": "");
continue;
}
spdlog::info("Using OpenGL {0}.{1}{2}", OPENGL_VERSIONS_MAJOR[i], OPENGL_VERSIONS_MINOR[i], OPENGL_VERSIONS_IS_ES[i] ? " ES": "");
glfwMakeContextCurrent(core::window);
break;
}
#endif
// Add callback for max/min if GLFW supports it
#if (GLFW_VERSION_MAJOR == 3) && (GLFW_VERSION_MINOR >= 3)
if (maximized) {
glfwMaximizeWindow(core::window);

View File

@ -1,3 +1,3 @@
#pragma once
#define VERSION_STR "1.0.3"
#define VERSION_STR "1.0.4"

View File

@ -1,6 +1,6 @@
{
"name": "Grey",
"author": "Paul (PD0SWL)",
"name": "Marine Grey",
"author": "PD0SWL",
"Border": "#6D6D7F7F",
"BorderShadow": "#00000000",
"Button": "#00000066",
@ -10,11 +10,11 @@
"ChildBg": "#FFFFFF00",
"DragDropTarget": "#0000FFE5",
"FrameBg": "#33353889",
"FrameBgActive": "#00000089",
"FrameBgHovered": "#00000089",
"FrameBgActive": "#70707089",
"FrameBgHovered": "#70707089",
"Header": "#5E5E4C4F",
"HeaderActive": "#5E5E4C4F",
"HeaderHovered": "#5E5E4C66",
"HeaderHovered": "#70707089",
"MenuBarBg": "#232323FF",
"ModalWindowDimBg": "#33333359",
"NavHighlight": "#666666FF",