diff --git a/docs/tr1/CHANGELOG.md b/docs/tr1/CHANGELOG.md index 875b975f6..72e27e189 100644 --- a/docs/tr1/CHANGELOG.md +++ b/docs/tr1/CHANGELOG.md @@ -1,6 +1,7 @@ ## [Unreleased](https://github.com/LostArtefacts/TRX/compare/tr1-4.5.1...develop) - ××××-××-×× - added support for wading, similar to TR2+ (#1537) - added the ability to pause during cutscenes (#1673) +- changed OpenGL backend to use version 3.3, with fallback to 2.1 if initialization fails (#1738) - fixed missing pushblock SFX in Natla's Mines (#1714) - fixed crash reports not working in certain circumstances (#1738) - fixed missing trapdoor triggers in City of Khamoon (#1744) @@ -45,7 +46,6 @@ - added `/exit` command (#1462) - added reflections to Midas Hand death animation and savegame crystals (#154) - added an option to use PS1 tinted savegame crystals (#1506) -- changed the target change functionality from the look key to a new, standalone key (default `z` on keyboard, `left analog click` on controller) (#1503) - fixed `/play`, `/load`, `/demo` and similar commands not working in stats, credits, cinematics and fmvs (#1477) - fixed console commands being able to interfere with demos, cutscenes and the title screen (#1489, regression from 3.0) - fixed reopening the compass not resetting its needle (#1472, regression from 4.0) @@ -69,6 +69,7 @@ - fixed Bacon Lara re-spawning after saving and loading (#1500, regression from 0.7) - fixed config JSON not sanitizing some numeric values (#1515) - fixed potential crashes in custom levels if hybrid creature objects are not present in the level (#1444) +- changed the target change functionality from the look key to a new, standalone key (default `z` on keyboard, `left analog click` on controller) (#1503) - changed `/heal` console command to also extinguish Lara - changed `/tp` console command to look for the closest place to teleport to when targeting items (#1484) - changed `/set` console command output to always use fully-qualified option names diff --git a/src/libtrx/gfx/2d/2d_renderer.c b/src/libtrx/gfx/2d/2d_renderer.c index 6124e00c6..361245f28 100644 --- a/src/libtrx/gfx/2d/2d_renderer.c +++ b/src/libtrx/gfx/2d/2d_renderer.c @@ -6,10 +6,11 @@ #include -void GFX_2D_Renderer_Init(GFX_2D_RENDERER *renderer) +void GFX_2D_Renderer_Init( + GFX_2D_RENDERER *renderer, const GFX_CONFIG *const config) { LOG_INFO(""); - assert(renderer); + assert(renderer != NULL); GFX_GL_Buffer_Init(&renderer->surface_buffer, GL_ARRAY_BUFFER); GFX_GL_Buffer_Bind(&renderer->surface_buffer); @@ -38,9 +39,11 @@ void GFX_2D_Renderer_Init(GFX_2D_RENDERER *renderer) GFX_GL_Program_Init(&renderer->program); GFX_GL_Program_AttachShader( - &renderer->program, GL_VERTEX_SHADER, "shaders/2d.glsl"); + &renderer->program, GL_VERTEX_SHADER, "shaders/2d.glsl", + config->backend); GFX_GL_Program_AttachShader( - &renderer->program, GL_FRAGMENT_SHADER, "shaders/2d.glsl"); + &renderer->program, GL_FRAGMENT_SHADER, "shaders/2d.glsl", + config->backend); GFX_GL_Program_Link(&renderer->program); GFX_GL_Program_FragmentData(&renderer->program, "fragColor"); @@ -50,7 +53,7 @@ void GFX_2D_Renderer_Init(GFX_2D_RENDERER *renderer) void GFX_2D_Renderer_Close(GFX_2D_RENDERER *renderer) { LOG_INFO(""); - assert(renderer); + assert(renderer != NULL); GFX_GL_VertexArray_Close(&renderer->surface_format); GFX_GL_Buffer_Close(&renderer->surface_buffer); @@ -62,6 +65,7 @@ void GFX_2D_Renderer_Close(GFX_2D_RENDERER *renderer) void GFX_2D_Renderer_Upload( GFX_2D_RENDERER *renderer, GFX_2D_SURFACE_DESC *desc, const uint8_t *data) { + assert(renderer != NULL); const uint32_t width = desc->width; const uint32_t height = desc->height; @@ -87,6 +91,7 @@ void GFX_2D_Renderer_Upload( void GFX_2D_Renderer_Render(GFX_2D_RENDERER *renderer) { + assert(renderer != NULL); GFX_GL_Program_Bind(&renderer->program); GFX_GL_Buffer_Bind(&renderer->surface_buffer); GFX_GL_VertexArray_Bind(&renderer->surface_format); diff --git a/src/libtrx/gfx/3d/3d_renderer.c b/src/libtrx/gfx/3d/3d_renderer.c index 5626fe633..bb3018813 100644 --- a/src/libtrx/gfx/3d/3d_renderer.c +++ b/src/libtrx/gfx/3d/3d_renderer.c @@ -11,7 +11,7 @@ static void M_SelectTextureImpl(GFX_3D_RENDERER *renderer, int texture_num); static void M_SelectTextureImpl(GFX_3D_RENDERER *renderer, int texture_num) { - assert(renderer); + assert(renderer != NULL); GFX_GL_TEXTURE *texture = NULL; if (texture_num == GFX_ENV_MAP_TEXTURE) { @@ -35,7 +35,7 @@ void GFX_3D_Renderer_Init( GFX_3D_RENDERER *renderer, const GFX_CONFIG *const config) { LOG_INFO(""); - assert(renderer); + assert(renderer != NULL); renderer->config = config; @@ -55,9 +55,11 @@ void GFX_3D_Renderer_Init( GFX_GL_Program_Init(&renderer->program); GFX_GL_Program_AttachShader( - &renderer->program, GL_VERTEX_SHADER, "shaders/3d.glsl"); + &renderer->program, GL_VERTEX_SHADER, "shaders/3d.glsl", + config->backend); GFX_GL_Program_AttachShader( - &renderer->program, GL_FRAGMENT_SHADER, "shaders/3d.glsl"); + &renderer->program, GL_FRAGMENT_SHADER, "shaders/3d.glsl", + config->backend); GFX_GL_Program_Link(&renderer->program); renderer->loc_mat_projection = @@ -93,7 +95,7 @@ void GFX_3D_Renderer_Init( void GFX_3D_Renderer_Close(GFX_3D_RENDERER *renderer) { LOG_INFO(""); - assert(renderer); + assert(renderer != NULL); GFX_3D_VertexStream_Close(&renderer->vertex_stream); GFX_GL_Program_Close(&renderer->program); @@ -102,7 +104,7 @@ void GFX_3D_Renderer_Close(GFX_3D_RENDERER *renderer) void GFX_3D_Renderer_RenderBegin(GFX_3D_RENDERER *renderer) { - assert(renderer); + assert(renderer != NULL); glEnable(GL_BLEND); glLineWidth(renderer->config->line_width); @@ -145,7 +147,7 @@ void GFX_3D_Renderer_RenderBegin(GFX_3D_RENDERER *renderer) void GFX_3D_Renderer_RenderEnd(GFX_3D_RENDERER *renderer) { - assert(renderer); + assert(renderer != NULL); GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream); GFX_GL_CheckError(); @@ -213,8 +215,8 @@ void GFX_3D_Renderer_FillEnvironmentMap(GFX_3D_RENDERER *const renderer) int GFX_3D_Renderer_RegisterTexturePage( GFX_3D_RENDERER *renderer, const void *data, int width, int height) { - assert(renderer); - assert(data); + assert(renderer != NULL); + assert(data != NULL); GFX_GL_TEXTURE *texture = GFX_GL_Texture_Create(GL_TEXTURE_2D); GFX_GL_Texture_Load(texture, data, width, height, GL_RGBA, GL_RGBA); @@ -236,7 +238,7 @@ int GFX_3D_Renderer_RegisterTexturePage( bool GFX_3D_Renderer_UnregisterTexturePage( GFX_3D_RENDERER *renderer, int texture_num) { - assert(renderer); + assert(renderer != NULL); assert(texture_num >= 0); assert(texture_num < GFX_MAX_TEXTURES); @@ -260,8 +262,8 @@ bool GFX_3D_Renderer_UnregisterTexturePage( void GFX_3D_Renderer_RenderPrimStrip( GFX_3D_RENDERER *renderer, GFX_3D_VERTEX *vertices, int count) { - assert(renderer); - assert(vertices); + assert(renderer != NULL); + assert(vertices != NULL); GFX_3D_VertexStream_PushPrimStrip( &renderer->vertex_stream, vertices, count); } @@ -269,22 +271,22 @@ void GFX_3D_Renderer_RenderPrimStrip( void GFX_3D_Renderer_RenderPrimFan( GFX_3D_RENDERER *renderer, GFX_3D_VERTEX *vertices, int count) { - assert(renderer); - assert(vertices); + assert(renderer != NULL); + assert(vertices != NULL); GFX_3D_VertexStream_PushPrimFan(&renderer->vertex_stream, vertices, count); } void GFX_3D_Renderer_RenderPrimList( GFX_3D_RENDERER *renderer, GFX_3D_VERTEX *vertices, int count) { - assert(renderer); - assert(vertices); + assert(renderer != NULL); + assert(vertices != NULL); GFX_3D_VertexStream_PushPrimList(&renderer->vertex_stream, vertices, count); } void GFX_3D_Renderer_SelectTexture(GFX_3D_RENDERER *renderer, int texture_num) { - assert(renderer); + assert(renderer != NULL); GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream); renderer->selected_texture_num = texture_num; M_SelectTextureImpl(renderer, texture_num); @@ -292,14 +294,14 @@ void GFX_3D_Renderer_SelectTexture(GFX_3D_RENDERER *renderer, int texture_num) void GFX_3D_Renderer_RestoreTexture(GFX_3D_RENDERER *renderer) { - assert(renderer); + assert(renderer != NULL); M_SelectTextureImpl(renderer, renderer->selected_texture_num); } void GFX_3D_Renderer_SetPrimType( GFX_3D_RENDERER *renderer, GFX_3D_PRIM_TYPE value) { - assert(renderer); + assert(renderer != NULL); GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream); GFX_3D_VertexStream_SetPrimType(&renderer->vertex_stream, value); } @@ -307,7 +309,7 @@ void GFX_3D_Renderer_SetPrimType( void GFX_3D_Renderer_SetTextureFilter( GFX_3D_RENDERER *renderer, GFX_TEXTURE_FILTER filter) { - assert(renderer); + assert(renderer != NULL); GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream); GFX_GL_Sampler_Parameteri( &renderer->sampler, GL_TEXTURE_MAG_FILTER, @@ -323,7 +325,7 @@ void GFX_3D_Renderer_SetTextureFilter( void GFX_3D_Renderer_SetDepthWritesEnabled( GFX_3D_RENDERER *const renderer, const bool is_enabled) { - assert(renderer); + assert(renderer != NULL); GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream); if (is_enabled) { glDepthMask(GL_TRUE); @@ -335,7 +337,7 @@ void GFX_3D_Renderer_SetDepthWritesEnabled( void GFX_3D_Renderer_SetDepthTestEnabled( GFX_3D_RENDERER *renderer, bool is_enabled) { - assert(renderer); + assert(renderer != NULL); GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream); if (is_enabled) { glEnable(GL_DEPTH_TEST); @@ -366,7 +368,7 @@ void GFX_3D_Renderer_SetBlendingMode( void GFX_3D_Renderer_SetTexturingEnabled( GFX_3D_RENDERER *renderer, bool is_enabled) { - assert(renderer); + assert(renderer != NULL); GFX_3D_VertexStream_RenderPending(&renderer->vertex_stream); GFX_GL_Program_Uniform1i( &renderer->program, renderer->loc_texturing_enabled, is_enabled); diff --git a/src/libtrx/gfx/context.c b/src/libtrx/gfx/context.c index a30e25ad0..3a4ca7767 100644 --- a/src/libtrx/gfx/context.c +++ b/src/libtrx/gfx/context.c @@ -10,6 +10,7 @@ #include "memory.h" #include +#include #include typedef struct { @@ -99,33 +100,23 @@ void GFX_Context_SwitchToDisplayViewport(void) GFX_GL_CheckError(); } -void GFX_Context_SetupEnvironment(void) -{ - switch (GFX_GL_DEFAULT_BACKEND) { - case GFX_GL_21: - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); - break; - - case GFX_GL_33C: - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); - SDL_GL_SetAttribute( - SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - break; - } -} - -void GFX_Context_Attach(void *window_handle) +bool GFX_Context_Attach(void *window_handle, GFX_GL_BACKEND backend) { const char *shading_ver; if (m_Context.window_handle) { - return; + LOG_ERROR("Context already attached"); + return false; } LOG_INFO("Attaching to window %p", window_handle); + m_Context.context = SDL_GL_CreateContext(window_handle); + if (m_Context.context == NULL) { + LOG_ERROR("Can't create OpenGL context: %s", SDL_GetError()); + return false; + } + m_Context.config.backend = backend; m_Context.config.line_width = 1; m_Context.config.enable_wireframe = false; m_Context.render_mode = -1; @@ -136,12 +127,6 @@ void GFX_Context_Attach(void *window_handle) m_Context.window_handle = window_handle; - m_Context.context = SDL_GL_CreateContext(m_Context.window_handle); - - if (m_Context.context == NULL) { - Shell_ExitSystemFmt("Can't create OpenGL context: %s", SDL_GetError()); - } - if (SDL_GL_MakeCurrent(m_Context.window_handle, m_Context.context)) { Shell_ExitSystemFmt( "Can't activate OpenGL context: %s", SDL_GetError()); @@ -159,7 +144,7 @@ void GFX_Context_Attach(void *window_handle) } // Check the availability of non-Core Profile extensions for OpenGL 2.1 - if (GFX_GL_DEFAULT_BACKEND == GFX_GL_21) { + if (m_Context.config.backend == GFX_GL_21) { M_CheckExtensionSupport("GL_ARB_explicit_attrib_location"); M_CheckExtensionSupport("GL_EXT_gpu_shader4"); } @@ -171,8 +156,9 @@ void GFX_Context_Attach(void *window_handle) // VSync defaults to on unless user disabled it in runtime json SDL_GL_SetSwapInterval(1); - GFX_2D_Renderer_Init(&m_Context.renderer_2d); + GFX_2D_Renderer_Init(&m_Context.renderer_2d, &m_Context.config); GFX_3D_Renderer_Init(&m_Context.renderer_3d, &m_Context.config); + return true; } void GFX_Context_Detach(void) diff --git a/src/libtrx/gfx/gl/program.c b/src/libtrx/gfx/gl/program.c index c45c182bf..01217f1f1 100644 --- a/src/libtrx/gfx/gl/program.c +++ b/src/libtrx/gfx/gl/program.c @@ -87,7 +87,8 @@ char *GFX_GL_Program_PreprocessShader( } void GFX_GL_Program_AttachShader( - GFX_GL_PROGRAM *program, GLenum type, const char *path) + GFX_GL_PROGRAM *program, GLenum type, const char *path, + const GFX_GL_BACKEND backend) { assert(program != NULL); assert(path != NULL); @@ -104,7 +105,7 @@ void GFX_GL_Program_AttachShader( } char *processed_content = - GFX_GL_Program_PreprocessShader(content, type, GFX_GL_DEFAULT_BACKEND); + GFX_GL_Program_PreprocessShader(content, type, backend); Memory_FreePointer(&content); if (!processed_content) { Shell_ExitSystemFmt("Failed to pre-process shader source: %s", path); diff --git a/src/libtrx/gfx/renderers/fbo_renderer.c b/src/libtrx/gfx/renderers/fbo_renderer.c index b9736dfa4..68e0f8a05 100644 --- a/src/libtrx/gfx/renderers/fbo_renderer.c +++ b/src/libtrx/gfx/renderers/fbo_renderer.c @@ -100,9 +100,10 @@ static void M_Init(GFX_RENDERER *const renderer, const GFX_CONFIG *const config) GFX_GL_Program_Init(&priv->program); GFX_GL_Program_AttachShader( - &priv->program, GL_VERTEX_SHADER, "shaders/fbo.glsl"); + &priv->program, GL_VERTEX_SHADER, "shaders/fbo.glsl", config->backend); GFX_GL_Program_AttachShader( - &priv->program, GL_FRAGMENT_SHADER, "shaders/fbo.glsl"); + &priv->program, GL_FRAGMENT_SHADER, "shaders/fbo.glsl", + config->backend); GFX_GL_Program_Link(&priv->program); GFX_GL_Program_FragmentData(&priv->program, "fragColor"); diff --git a/src/libtrx/include/libtrx/gfx/2d/2d_renderer.h b/src/libtrx/include/libtrx/gfx/2d/2d_renderer.h index 661a40760..162dfdd33 100644 --- a/src/libtrx/include/libtrx/gfx/2d/2d_renderer.h +++ b/src/libtrx/include/libtrx/gfx/2d/2d_renderer.h @@ -1,5 +1,6 @@ #pragma once +#include "../config.h" #include "../gl/buffer.h" #include "../gl/program.h" #include "../gl/sampler.h" @@ -20,7 +21,7 @@ typedef struct { GFX_GL_PROGRAM program; } GFX_2D_RENDERER; -void GFX_2D_Renderer_Init(GFX_2D_RENDERER *renderer); +void GFX_2D_Renderer_Init(GFX_2D_RENDERER *renderer, const GFX_CONFIG *config); void GFX_2D_Renderer_Close(GFX_2D_RENDERER *renderer); void GFX_2D_Renderer_Upload( diff --git a/src/libtrx/include/libtrx/gfx/common.h b/src/libtrx/include/libtrx/gfx/common.h index b2d5d310f..7ced70725 100644 --- a/src/libtrx/include/libtrx/gfx/common.h +++ b/src/libtrx/include/libtrx/gfx/common.h @@ -14,6 +14,7 @@ typedef enum { } GFX_RENDER_MODE; typedef enum { + GFX_GL_INVALID_BACKEND, GFX_GL_21, GFX_GL_33C, } GFX_GL_BACKEND; diff --git a/src/libtrx/include/libtrx/gfx/config.h b/src/libtrx/include/libtrx/gfx/config.h index ec1f4963f..c7354d206 100644 --- a/src/libtrx/include/libtrx/gfx/config.h +++ b/src/libtrx/include/libtrx/gfx/config.h @@ -6,6 +6,8 @@ #include typedef struct { + GFX_GL_BACKEND backend; + GFX_TEXTURE_FILTER display_filter; bool enable_wireframe; int32_t line_width; diff --git a/src/libtrx/include/libtrx/gfx/context.h b/src/libtrx/include/libtrx/gfx/context.h index 8295b1539..94feab3e3 100644 --- a/src/libtrx/include/libtrx/gfx/context.h +++ b/src/libtrx/include/libtrx/gfx/context.h @@ -8,8 +8,7 @@ #include #include -void GFX_Context_SetupEnvironment(void); -void GFX_Context_Attach(void *window_handle); +bool GFX_Context_Attach(void *window_handle, GFX_GL_BACKEND backend); void GFX_Context_Detach(void); void GFX_Context_SetDisplayFilter(GFX_TEXTURE_FILTER filter); diff --git a/src/libtrx/include/libtrx/gfx/gl/program.h b/src/libtrx/include/libtrx/gfx/gl/program.h index 0ab22dae7..145666ac4 100644 --- a/src/libtrx/include/libtrx/gfx/gl/program.h +++ b/src/libtrx/include/libtrx/gfx/gl/program.h @@ -17,7 +17,8 @@ void GFX_GL_Program_Bind(GFX_GL_PROGRAM *program); char *GFX_GL_Program_PreprocessShader( const char *content, GLenum type, GFX_GL_BACKEND backend); void GFX_GL_Program_AttachShader( - GFX_GL_PROGRAM *program, GLenum type, const char *path); + GFX_GL_PROGRAM *program, GLenum type, const char *path, + GFX_GL_BACKEND backend); void GFX_GL_Program_Link(GFX_GL_PROGRAM *program); void GFX_GL_Program_FragmentData(GFX_GL_PROGRAM *program, const char *name); GLint GFX_GL_Program_UniformLocation(GFX_GL_PROGRAM *program, const char *name); diff --git a/src/libtrx/meson.build b/src/libtrx/meson.build index a341f262d..e1bdc3a63 100644 --- a/src/libtrx/meson.build +++ b/src/libtrx/meson.build @@ -9,7 +9,6 @@ project( staticdeps = get_option('staticdeps') tr_version = get_option('tr_version') -gfx_gl_default_backend = get_option('gfx_gl_default_backend') fs = import('fs') c_compiler = meson.get_compiler('c') @@ -23,7 +22,6 @@ build_opts = [ '-DPCRE2_STATIC', '-DPCRE2_CODE_UNIT_WIDTH=8', '-DTR_VERSION=' + tr_version.to_string(), - '-DGFX_GL_DEFAULT_BACKEND=' + gfx_gl_default_backend, ] set_variable('defines', ['-DTR_VERSION=' + tr_version.to_string()]) diff --git a/src/libtrx/meson.options b/src/libtrx/meson.options index 557d1ba27..6eb2c463e 100644 --- a/src/libtrx/meson.options +++ b/src/libtrx/meson.options @@ -12,9 +12,3 @@ option( max: 2, description: 'Which engine version to compile for' ) - -option( - 'gfx_gl_default_backend', - type: 'string', - description: 'Which OpenGL version to target' -) diff --git a/src/tr1/meson.build b/src/tr1/meson.build index 12c77ab0b..a15a23a04 100644 --- a/src/tr1/meson.build +++ b/src/tr1/meson.build @@ -7,15 +7,8 @@ project( ], ) -if host_machine.system() == 'darwin' - gfx_gl_default_backend = 'GFX_GL_33C' -else - gfx_gl_default_backend = 'GFX_GL_21' -endif - trx = subproject('libtrx', default_options: { 'tr_version': '1', - 'gfx_gl_default_backend': gfx_gl_default_backend, }) c_compiler = meson.get_compiler('c') diff --git a/src/tr1/specific/s_output.c b/src/tr1/specific/s_output.c index 756d5b32c..3bf47d40d 100644 --- a/src/tr1/specific/s_output.c +++ b/src/tr1/specific/s_output.c @@ -854,7 +854,6 @@ bool S_Output_Init(void) m_TextureSurfaces[i] = NULL; } - GFX_Context_Attach(S_Shell_GetWindowHandle()); m_Renderer2D = GFX_Context_GetRenderer2D(); m_Renderer3D = GFX_Context_GetRenderer3D(); diff --git a/src/tr1/specific/s_shell.c b/src/tr1/specific/s_shell.c index 9e9abc3db..af6eefc7a 100644 --- a/src/tr1/specific/s_shell.c +++ b/src/tr1/specific/s_shell.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -32,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -159,6 +161,7 @@ void S_Shell_Init(void) g_Config.rendering.window_width, g_Config.rendering.window_height, true); M_SetWindowMaximized(g_Config.rendering.enable_maximized, true); + SDL_ShowWindow(m_Window); } void S_Shell_ShowFatalError(const char *message) @@ -321,21 +324,66 @@ int main(int argc, char **argv) return 0; } -void S_Shell_CreateWindow(void) +static void M_SetGLBackend(const GFX_GL_BACKEND backend) { - GFX_Context_SetupEnvironment(); + switch (backend) { + case GFX_GL_21: + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0); + break; + + case GFX_GL_33C: + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); + SDL_GL_SetAttribute( + SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + break; + + case GFX_GL_INVALID_BACKEND: + assert(false); + break; + } +} - m_Window = SDL_CreateWindow( - "TR1X", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, - SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_RESIZABLE - | SDL_WINDOW_OPENGL); +void S_Shell_CreateWindow(void) +{ + const GFX_GL_BACKEND backends_to_try[] = { + // clang-format off + GFX_GL_33C, + GFX_GL_21, + GFX_GL_INVALID_BACKEND, // guard + // clang-format on + }; + + for (int32_t i = 0; backends_to_try[i] != GFX_GL_INVALID_BACKEND; i++) { + const GFX_GL_BACKEND backend = backends_to_try[i]; + + M_SetGLBackend(backend); + + SDL_Window *const window = SDL_CreateWindow( + "TR1X", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, + SDL_WINDOW_HIDDEN | SDL_WINDOW_FULLSCREEN_DESKTOP + | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL); + + if (window == NULL) { + Shell_ExitSystem("System Error: cannot create window"); + return; + } - if (!m_Window) { - S_Shell_ShowFatalError("System Error: cannot create window"); - return; + int32_t major; + int32_t minor; + SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major); + SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor); + LOG_DEBUG("Trying GL backend %d.%d", major, minor); + if (GFX_Context_Attach(window, backend)) { + m_Window = window; + S_Shell_HandleWindowResize(); + return; + } } - S_Shell_HandleWindowResize(); + Shell_ExitSystem("System Error: cannot attach opengl context"); } bool S_Shell_GetCommandLine(int *arg_count, char ***args) diff --git a/src/tr2/meson.build b/src/tr2/meson.build index 04511c943..77f58a316 100644 --- a/src/tr2/meson.build +++ b/src/tr2/meson.build @@ -5,15 +5,8 @@ project('TR2X', ['c'], ], ) -if host_machine.system() == 'darwin' - gfx_gl_default_backend = 'GFX_GL_33C' -else - gfx_gl_default_backend = 'GFX_GL_21' -endif - trx = subproject('libtrx', default_options: { 'tr_version': '2', - 'gfx_gl_default_backend': gfx_gl_default_backend, }) c_compiler = meson.get_compiler('c')