ref: 7146288e9490c8ebb9ed29beba67df02f66be1a3
parent: 4afe7f4b119ae70ed902e0bad830ce7be91d275e
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri Aug 9 15:19:43 EDT 2019
Sod it, fall back on compatibility mode if it's available This way, I can use immediate mode, which is way faster than using buffers for some reason. Since I'm not using profiles anymore, I dropped the minimum requirement to OpenGL 3.1. If a driver doesn't support Legacy GL, then it can use the slow buffer code. But seriously, I need to figure out why using buffers is so slow. If this was a common problem, Modern OpenGL wouldn't have made it the only option.
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@
option(FIX_BUGS "Fix certain bugs (see src/Bug Fixes.txt)" OFF)
option(NONPORTABLE "Enable bits of code that aren't portable, but are what the original game used" OFF)
option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF)
-set(RENDERER "Texture" CACHE STRING "Which renderer the game should use: 'OpenGL3' for an OpenGL 3.2 renderer, 'Texture' for SDL2's hardware-accelerated Texture API, 'Surface' for SDL2's software-rendered Surface API, and 'Software' for a handwritten software renderer")
+set(RENDERER "Texture" CACHE STRING "Which renderer the game should use: 'OpenGL3' for an OpenGL 3.1 renderer, 'Texture' for SDL2's hardware-accelerated Texture API, 'Surface' for SDL2's software-rendered Surface API, and 'Software' for a handwritten software renderer")
project(CSE2 LANGUAGES C CXX)
--- a/README.md
+++ b/README.md
@@ -30,7 +30,7 @@
* `-DFIX_BUGS=ON` - Fix bugs in the game (see [src/Bug Fixes.txt](src/Bug%20Fixes.txt))
* `-DNONPORTABLE=ON` - Enable bits of code that aren't portable, but are what the original game used
* `-DFORCE_LOCAL_LIBS=ON` - Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones
-* `-DRENDERER=OpenGL3` - Use the hardware-accelerated OpenGL 3.2 renderer
+* `-DRENDERER=OpenGL3` - Use the hardware-accelerated OpenGL 3.1 renderer
* `-DRENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default)
* `-DRENDERER=Surface` - Use the software-rendered SDL2 Surface API renderer
* `-DRENDERER=Software` - Use a handwritten software renderer
@@ -58,7 +58,7 @@
* `WINDOWS=1` - Enable Windows-only features like a unique file/taskbar icon, and system font loading (needed for the font setting in Config.dat to do anything)
* `RASPBERRY_PI=1` - Enable tweaks to improve performance on Raspberry Pis
* `NONPORTABLE=1` - Enable bits of code that aren't portable, but are what the original game used
-* `RENDERER=OpenGL3` - Use the hardware-accelerated OpenGL 3.2 renderer
+* `RENDERER=OpenGL3` - Use the hardware-accelerated OpenGL 3.1 renderer
* `RENDERER=Texture` - Use the hardware-accelerated SDL2 Texture API renderer (default)
* `RENDERER=Surface` - Use the software-rendered SDL2 Surface API renderer
* `RENDERER=Software` - Use a hand-written software renderer
--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -63,7 +63,7 @@
static Backend_Surface framebuffer_surface;
static const GLchar *vertex_shader_plain = " \
-#version 150 core\n \
+#version 140\n \
in vec2 input_vertex_coordinates; \
void main() \
{ \
@@ -72,7 +72,7 @@
";
static const GLchar *vertex_shader_texture = " \
-#version 150 core\n \
+#version 140\n \
in vec2 input_vertex_coordinates; \
in vec2 input_texture_coordinates; \
out vec2 texture_coordinates; \
@@ -84,7 +84,7 @@
";
static const GLchar *fragment_shader_texture = " \
-#version 150 core\n \
+#version 140\n \
uniform sampler2D tex; \
in vec2 texture_coordinates; \
out vec4 fragment; \
@@ -95,7 +95,7 @@
";
static const GLchar *fragment_shader_texture_colour_key = " \
-#version 150 core\n \
+#version 140\n \
uniform sampler2D tex; \
in vec2 texture_coordinates; \
out vec4 fragment; \
@@ -111,7 +111,7 @@
";
static const GLchar *fragment_shader_colour_fill = " \
-#version 150 core\n \
+#version 140\n \
uniform vec4 colour; \
out vec4 fragment; \
void main() \
@@ -121,7 +121,7 @@
";
static const GLchar *fragment_shader_glyph_normal = " \
-#version 150 core\n \
+#version 140\n \
uniform sampler2D tex; \
uniform vec4 colour; \
in vec2 texture_coordinates; \
@@ -133,7 +133,7 @@
";
static const GLchar *fragment_shader_glyph_subpixel_part1 = " \
-#version 150 core\n \
+#version 140\n \
uniform sampler2D tex; \
in vec2 texture_coordinates; \
out vec4 fragment; \
@@ -144,7 +144,7 @@
";
static const GLchar *fragment_shader_glyph_subpixel_part2 = " \
-#version 150 core\n \
+#version 140\n \
uniform sampler2D tex; \
uniform vec4 colour; \
in vec2 texture_coordinates; \
@@ -218,10 +218,8 @@
SDL_Window* Backend_CreateWindow(const char *title, int width, int height)
{
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
return SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
}
@@ -238,8 +236,8 @@
if (glewInit() != GLEW_OK)
return FALSE;
- // Check if the platform supports OpenGL 3.2
- if (!GLEW_VERSION_3_2)
+ // Check if the platform supports OpenGL 3.1
+ if (!GLEW_VERSION_3_1)
return FALSE;
glEnable(GL_DEBUG_OUTPUT);
@@ -248,18 +246,27 @@
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
- // Set up Vertex Array Object
- glGenVertexArrays(1, &vertex_array_id);
- glBindVertexArray(vertex_array_id);
+ if (GLEW_ARB_compatibility)
+ {
+ glEnableVertexAttribArray(1);
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, vertex_buffer.vertexes);
+ glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, vertex_buffer.texture_coordinates);
+ }
+ else
+ {
+ // Set up Vertex Array Object
+ glGenVertexArrays(1, &vertex_array_id);
+ glBindVertexArray(vertex_array_id);
- // Set up Vertex Buffer Object
- glGenBuffers(1, &vertex_buffer_id);
- glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_id);
+ // Set up Vertex Buffer Object
+ glGenBuffers(1, &vertex_buffer_id);
+ glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_id);
- // Set up the vertex attributes
- glEnableVertexAttribArray(1);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)offsetof(VertexBuffer, vertexes));
- glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)offsetof(VertexBuffer, texture_coordinates));
+ // Set up the vertex attributes
+ glEnableVertexAttribArray(1);
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)offsetof(VertexBuffer, vertexes));
+ glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)offsetof(VertexBuffer, texture_coordinates));
+ }
// Set up our shaders
program_texture = CompileShader(vertex_shader_texture, fragment_shader_texture);
@@ -347,7 +354,9 @@
vertex_buffer.vertexes[3].x = -1.0f;
vertex_buffer.vertexes[3].y = 1.0f;
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), &vertex_buffer, GL_STREAM_DRAW);
+ if (!GLEW_ARB_compatibility)
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), &vertex_buffer, GL_STREAM_DRAW);
+
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
SDL_GL_SwapWindow(window);
@@ -461,7 +470,9 @@
vertex_buffer.vertexes[3].x = vertex_left;
vertex_buffer.vertexes[3].y = vertex_bottom;
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), &vertex_buffer, GL_STREAM_DRAW);
+ if (!GLEW_ARB_compatibility)
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), &vertex_buffer, GL_STREAM_DRAW);
+
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
@@ -510,7 +521,9 @@
vertex_buffer.vertexes[3].x = vertex_left;
vertex_buffer.vertexes[3].y = vertex_bottom;
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), &vertex_buffer, GL_STREAM_DRAW);
+ if (!GLEW_ARB_compatibility)
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), &vertex_buffer, GL_STREAM_DRAW);
+
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
@@ -640,7 +653,8 @@
vertex_buffer.vertexes[3].x = vertex_left;
vertex_buffer.vertexes[3].y = vertex_bottom;
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), &vertex_buffer, GL_STREAM_DRAW);
+ if (!GLEW_ARB_compatibility)
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_buffer), &vertex_buffer, GL_STREAM_DRAW);
if (glyph->pixel_mode == FONT_PIXEL_MODE_LCD)
{