-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix macos build and run issues #1777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
eab512c
85136da
050fa9b
0939770
f67bf1a
e72b2e1
4b9fb02
fa7e74b
48c56fb
a9864b3
c49eee7
a931495
e8026ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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_; | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better rename it
Suggested change
|
||||||
// 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); | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
Comment on lines
+22
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. switch statements should definitely work in this place, so I would revisit this shader once you have fixed all the other comments. |
||
} | ||
id = u_id; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
Comment on lines
+14
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
col = tex_val; | ||
break; | ||
} | ||
|
||
id = u_id; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
Comment on lines
+14
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
col = tex_val; | ||
break; | ||
} | ||
|
||
id = u_id; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)"); | ||
} | ||
Comment on lines
+57
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number is now no longer correct because simulation/presenter are started later. That's why I made the recommendation to start all threads in |
||
|
||
void Engine::loop() { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The structure with
|
||
// 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
/** | ||
Comment on lines
+119
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably better to store them in the presenter class and pass them in the constructor. |
||
* The threads used by the engine. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -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{ | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a static variable should not be necessary for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a constexpr as "texture" was used in more than one place. IMO it is better to have a constexpr/define rather than a hardcoded value, especially if it is used in more than one place. However if you rather want it hardcoded I will object to it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would agree in general, but for these WIP parts of the engine it's probably better to hardcode it for now. My reason would be that it then becomes more "visible" what is done with the shader until it's properly defined. For the more mature shaders, we have a solution that is similar to what you propose where we store the uniform ID and use that openage/libopenage/renderer/stages/world/object.h Lines 147 to 157 in 86d05c4
|
||||||||||||||||||||||||
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); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
afaik you don't need this statement since
gl_Position
by definition contains the current vertex position already. You can remove that line.