diff --git a/assets/shaders/identity.vert.glsl b/assets/shaders/identity.vert.glsl index e9602ca5f9..546186b4a3 100644 --- a/assets/shaders/identity.vert.glsl +++ b/assets/shaders/identity.vert.glsl @@ -1,16 +1,14 @@ -#version 120 +#version 330 core -// no-transformation texture mapping vertex shader +// Input vertex position +layout(location = 0) in vec4 vertex_position; -// the position of this vertex -attribute vec4 vertex_position; - -// interpolated texture coordinates sent to fragment shader -varying vec2 tex_position; +// Output to fragment shader +out vec2 tex_position; void main(void) { - gl_Position = vertex_position; + gl_Position = vertex_position; - // convert from screen coordinates (-1, 1) to texture coordinates (0, 1) - tex_position = (vertex_position.xy + vec2(1.f)) / 2.f; + // Convert from clip space (-1, 1) to texture space (0, 1) + tex_position = (vertex_position.xy + vec2(1.0)) * 0.5; } diff --git a/assets/shaders/maptexture.frag.glsl b/assets/shaders/maptexture.frag.glsl index a92f7a8644..81c484ab55 100644 --- a/assets/shaders/maptexture.frag.glsl +++ b/assets/shaders/maptexture.frag.glsl @@ -1,13 +1,10 @@ -#version 120 -// total basic standard texture drawing fragment shader +#version 330 core -// the texture data -uniform sampler2D texture; +uniform sampler2D texture_; -// interpolated texture coordinates received from vertex shader -varying vec2 tex_position; +in vec2 tex_position; +out vec4 frag_color; -void main (void) { - // this sets the fragment color to the corresponding texel. - gl_FragColor = texture2D(texture, tex_position); +void main(void) { + frag_color = texture(texture_, tex_position); } diff --git a/assets/shaders/maptexture.vert.glsl b/assets/shaders/maptexture.vert.glsl index b685462a0b..0ede82bd4c 100644 --- a/assets/shaders/maptexture.vert.glsl +++ b/assets/shaders/maptexture.vert.glsl @@ -1,21 +1,16 @@ -//total basic standard texture mapping vertex shader +#version 330 core -//modelview*projection matrix -uniform mat4 mvp_matrix; - -//the position of this vertex -attribute vec4 vertex_position; +// Input attributes (set via glVertexAttribPointer) +layout(location = 0) in vec4 vertex_position; +layout(location = 1) in vec2 tex_coordinates; -//the texture coordinates assigned to this vertex -attribute vec2 tex_coordinates; +// Output to fragment shader +out vec2 tex_position; -//interpolated texture coordinates sent to fragment shader -varying vec2 tex_position; +// Uniform matrix +uniform mat4 mvp_matrix; void main(void) { - //transform the vertex coordinates - gl_Position = gl_ModelViewProjectionMatrix * vertex_position; - - //pass the fix points for texture coordinates set at this vertex - tex_position = tex_coordinates; + gl_Position = mvp_matrix * vertex_position; + tex_position = tex_coordinates; } diff --git a/assets/shaders/world2d.frag.glsl b/assets/shaders/world2d.frag.glsl index 98d323e0f6..af555ed761 100644 --- a/assets/shaders/world2d.frag.glsl +++ b/assets/shaders/world2d.frag.glsl @@ -19,25 +19,18 @@ vec2 uv = vec2( void main() { vec4 tex_val = texture(tex, uv); int alpha = int(round(tex_val.a * 255)); - switch (alpha) { - case 0: - col = tex_val; - discard; - - // do not save the ID - return; - case 254: - col = vec4(1.0f, 0.0f, 0.0f, 1.0f); - break; - case 252: - col = vec4(0.0f, 1.0f, 0.0f, 1.0f); - break; - case 250: - col = vec4(0.0f, 0.0f, 1.0f, 1.0f); - break; - default: - col = tex_val; - break; + if (alpha == 0) { + col = tex_val; + discard; + return; + } else if (alpha == 254) { + col = vec4(1.0f, 0.0f, 0.0f, 1.0f); + } else if (alpha == 252) { + col = vec4(0.0f, 1.0f, 0.0f, 1.0f); + } else if (alpha == 250) { + col = vec4(0.0f, 0.0f, 1.0f, 1.0f); + } else { + col = tex_val; } id = u_id; } diff --git a/assets/test/shaders/demo_2_obj.frag.glsl b/assets/test/shaders/demo_2_obj.frag.glsl index 9beca4b88f..f2fd55d786 100644 --- a/assets/test/shaders/demo_2_obj.frag.glsl +++ b/assets/test/shaders/demo_2_obj.frag.glsl @@ -10,22 +10,18 @@ layout(location=1) out uint id; void main() { vec4 tex_val = texture(tex, v_uv); int alpha = int(round(tex_val.a * 255)); - switch (alpha) { - case 0: - discard; - break; - case 254: - col = vec4(1.0f, 0.0f, 0.0f, 1.0f); - break; - case 252: - col = vec4(0.0f, 1.0f, 0.0f, 1.0f); - break; - case 250: - col = vec4(0.0f, 0.0f, 1.0f, 1.0f); - break; - default: + + if (alpha == 0) { + discard; + } else if (alpha == 254) { + col = vec4(1.0, 0.0, 0.0, 1.0); + } else if (alpha == 252) { + col = vec4(0.0, 1.0, 0.0, 1.0); + } else if (alpha == 250) { + col = vec4(0.0, 0.0, 1.0, 1.0); + } else { col = tex_val; - break; } + id = u_id; } diff --git a/assets/test/shaders/demo_4_obj.frag.glsl b/assets/test/shaders/demo_4_obj.frag.glsl index 9beca4b88f..f2fd55d786 100644 --- a/assets/test/shaders/demo_4_obj.frag.glsl +++ b/assets/test/shaders/demo_4_obj.frag.glsl @@ -10,22 +10,18 @@ layout(location=1) out uint id; void main() { vec4 tex_val = texture(tex, v_uv); int alpha = int(round(tex_val.a * 255)); - switch (alpha) { - case 0: - discard; - break; - case 254: - col = vec4(1.0f, 0.0f, 0.0f, 1.0f); - break; - case 252: - col = vec4(0.0f, 1.0f, 0.0f, 1.0f); - break; - case 250: - col = vec4(0.0f, 0.0f, 1.0f, 1.0f); - break; - default: + + if (alpha == 0) { + discard; + } else if (alpha == 254) { + col = vec4(1.0, 0.0, 0.0, 1.0); + } else if (alpha == 252) { + col = vec4(0.0, 1.0, 0.0, 1.0); + } else if (alpha == 250) { + col = vec4(0.0, 0.0, 1.0, 1.0); + } else { col = tex_val; - break; } + id = u_id; } diff --git a/copying.md b/copying.md index 8c61b294e2..15762b7100 100644 --- a/copying.md +++ b/copying.md @@ -167,6 +167,8 @@ _the openage authors_ are: | Jordan Sutton | jsutCodes | jsutcodes à gmail dawt com | | Daniel Wieczorek | Danio | danielwieczorek96 à gmail dawt com | | | bytegrrrl | bytegrrrl à proton dawt me | +| | hellvoid | hell à void dawt lan | + If you're a first-time committer, add yourself to the above list. This is not just for legal reasons, but also to keep an overview of all those nicknames. diff --git a/libopenage/engine/engine.cpp b/libopenage/engine/engine.cpp index 02c0dd87d3..985f6a13fa 100644 --- a/libopenage/engine/engine.cpp +++ b/libopenage/engine/engine.cpp @@ -1,4 +1,4 @@ -// Copyright 2023-2024 the openage authors. See copying.md for legal info. +// Copyright 2023-2025 the openage authors. See copying.md for legal info. #include "engine.h" @@ -20,6 +20,7 @@ Engine::Engine(mode mode, running{true}, run_mode{mode}, root_dir{root_dir}, + window_settings{window_settings}, threads{} { log::log(INFO << "launching engine with root directory" @@ -53,31 +54,40 @@ Engine::Engine(mode mode, this->time_loop.reset(); }); - // if presenter is used, run it in a separate thread + log::log(INFO << "Using " << this->threads.size() + 1 << " threads " + << "(" << std::jthread::hardware_concurrency() << " available)"); +} + +void Engine::loop() { + + // if presenter is used, run the simulation in a separate thread if (this->run_mode == mode::FULL) { - this->threads.emplace_back([&]() { - this->presenter->run(window_settings); - // Make sure that the presenter gets destructed in the same thread - // otherwise OpenGL complains about missing contexts - this->presenter.reset(); - this->running = false; + this->threads.emplace_back([&]() { + this->loop_simulation(); }); - } - log::log(INFO << "Using " << this->threads.size() + 1 << " threads " - << "(" << std::jthread::hardware_concurrency() << " available)"); + this->presenter->run(this->window_settings); + log::log(MSG(info) << "presenter exited"); + // Make sure that the presenter gets destructed in the same thread + // otherwise OpenGL complains about missing contexts + this->presenter.reset(); + this->running = false; + } + else { + this->loop_simulation(); + } } -void Engine::loop() { +void Engine::loop_simulation() { // Run the main game simulation loop: this->simulation->run(); - // After stopping, clean up the simulation this->simulation.reset(); if (this->run_mode != mode::FULL) { this->running = false; } + } } // namespace openage::engine diff --git a/libopenage/engine/engine.h b/libopenage/engine/engine.h index 0231054628..7f30c2b2c3 100644 --- a/libopenage/engine/engine.h +++ b/libopenage/engine/engine.h @@ -1,4 +1,4 @@ -// Copyright 2023-2024 the openage authors. See copying.md for legal info. +// Copyright 2023-2025 the openage authors. See copying.md for legal info. #pragma once @@ -100,6 +100,12 @@ class Engine { bool running; private: + + /** + * Run the simulation loop + */ + void loop_simulation(); + /** * The run mode to use. */ @@ -110,6 +116,11 @@ class Engine { */ util::Path root_dir; + /** + * Window settings + */ + const renderer::window_settings window_settings; + /** * The threads used by the engine. */ diff --git a/libopenage/main.cpp b/libopenage/main.cpp index 2147cbe4e0..5d34ba2048 100644 --- a/libopenage/main.cpp +++ b/libopenage/main.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2024 the openage authors. See copying.md for legal info. +// Copyright 2015-2025 the openage authors. See copying.md for legal info. #include "main.h" diff --git a/libopenage/main/demo/pong/gui.cpp b/libopenage/main/demo/pong/gui.cpp index bc2d334b3e..3130100d75 100644 --- a/libopenage/main/demo/pong/gui.cpp +++ b/libopenage/main/demo/pong/gui.cpp @@ -1,4 +1,4 @@ -// Copyright 2019-2024 the openage authors. See copying.md for legal info. +// Copyright 2019-2025 the openage authors. See copying.md for legal info. #include "gui.h" diff --git a/libopenage/renderer/gui/gui.cpp b/libopenage/renderer/gui/gui.cpp index 879a709d0c..1bb15e73b1 100644 --- a/libopenage/renderer/gui/gui.cpp +++ b/libopenage/renderer/gui/gui.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2024 the openage authors. See copying.md for legal info. +// Copyright 2015-2025 the openage authors. See copying.md for legal info. #include "gui.h" @@ -16,6 +16,7 @@ #include "renderer/window.h" #include "util/path.h" +static constexpr const char* texture_ = "texture_"; namespace openage::renderer::gui { @@ -87,7 +88,7 @@ void GUI::initialize_render_pass(size_t width, resources::Texture2dInfo(width, height, resources::pixel_format::rgba8)); auto fbo = this->renderer->create_texture_target({output_texture}); - this->texture_unif = maptex_shader->new_uniform_input("texture", this->texture); + this->texture_unif = maptex_shader->new_uniform_input(texture_, this->texture); Renderable display_obj{ this->texture_unif, quad, @@ -119,7 +120,7 @@ void GUI::resize(size_t width, size_t height) { auto fbo = renderer->create_texture_target({output_texture}); // pass the new texture to shader uniform - this->texture_unif->update("texture", this->texture); + this->texture_unif->update(texture_, this->texture); this->render_pass->set_target(fbo); } diff --git a/libopenage/renderer/gui/guisys/private/gui_application_impl.cpp b/libopenage/renderer/gui/guisys/private/gui_application_impl.cpp index fb8674b69e..00739d7654 100644 --- a/libopenage/renderer/gui/guisys/private/gui_application_impl.cpp +++ b/libopenage/renderer/gui/guisys/private/gui_application_impl.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2023 the openage authors. See copying.md for legal info. +// Copyright 2015-2025 the openage authors. See copying.md for legal info. #include "gui_application_impl.h" @@ -35,9 +35,7 @@ GuiApplicationImpl::~GuiApplicationImpl() { void GuiApplicationImpl::processEvents() { assert(std::this_thread::get_id() == this->owner); -#ifndef __APPLE__ this->app.processEvents(); -#endif } namespace {