Skip to content

Turn off vsync for renderer stresstest #1638

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

Merged
merged 4 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions libopenage/input/tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2023 the openage authors. See copying.md for legal info.
// Copyright 2023-2024 the openage authors. See copying.md for legal info.

#include "error/error.h"
#include "log/log.h"
Expand All @@ -14,7 +14,8 @@ void action_demo() {
auto qtapp = std::make_shared<renderer::gui::GuiApplicationWithLogger>();

// create a window where we get our inputs from
renderer::opengl::GlWindow window("openage input test", 800, 600);

renderer::opengl::GlWindow window("openage input test");

// manager that receives window inputs
// the manager creates its own global context with ID "main"
Expand Down
10 changes: 5 additions & 5 deletions libopenage/main/demo/pong/gui.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright 2019-2023 the openage authors. See copying.md for legal info.
// Copyright 2019-2024 the openage authors. See copying.md for legal info.

#include "gui.h"

#include <algorithm>
#include <eigen3/Eigen/Dense>
#include <vector>

#include "main/demo/pong/gamestate.h"
#include "log/log.h"
#include "main/demo/pong/gamestate.h"
#include "renderer/geometry.h"
#include "renderer/opengl/context.h"
#include "renderer/opengl/shader.h"
Expand All @@ -34,7 +34,7 @@ const std::vector<PongEvent> &Gui::get_inputs(const std::shared_ptr<PongPlayer>

/*
for (all inputs from window) {
add key to inputs vector;
add key to inputs vector;
}
*/

Expand Down Expand Up @@ -78,7 +78,7 @@ constexpr const int max_log_msgs = 10;


Gui::Gui() :
window{"openage engine test", 800, 600},
window{"openage engine test", {800, 600}},
renderer{window.make_renderer()} {
auto vshader_src = renderer::resources::ShaderSource(
renderer::resources::shader_lang_t::glsl,
Expand Down Expand Up @@ -199,7 +199,7 @@ void Gui::draw(const std::shared_ptr<PongState> &state, const time::time_t &now)
auto ball_pos = state->ball->position->get(now);
auto ball_pos_matrix = Eigen::Affine3f::Identity();
ball_pos_matrix.prescale(Eigen::Vector3f(ball_size, ball_size, 1.0f));
//ball_pos_matrix.prerotate(Eigen::AngleAxisf(45.0f * math::PI / 180.0f, Eigen::Vector3f::UnitZ()));
// ball_pos_matrix.prerotate(Eigen::AngleAxisf(45.0f * math::PI / 180.0f, Eigen::Vector3f::UnitZ()));
ball_pos_matrix.pretranslate(Eigen::Vector3f(ball_pos[0], ball_pos[1], 0.0f));
this->ball.uniform->update("pos", ball_pos_matrix.matrix());

Expand Down
17 changes: 12 additions & 5 deletions libopenage/presenter/presenter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2023 the openage authors. See copying.md for legal info.
// Copyright 2019-2024 the openage authors. See copying.md for legal info.

#include "presenter.h"

Expand Down Expand Up @@ -93,8 +93,15 @@ std::shared_ptr<qtgui::GuiApplication> Presenter::init_window_system() {
void Presenter::init_graphics(bool debug) {
log::log(INFO << "Presenter: Initializing graphics subsystems...");

// Start up rendering framework
this->gui_app = this->init_window_system();
this->window = renderer::Window::create("openage presenter test", 1024, 768, debug);

// Window and renderer
renderer::window_settings settings;
settings.width = 1024;
settings.height = 768;
settings.debug = debug;
this->window = renderer::Window::create("openage presenter test", settings);
this->renderer = this->window->make_renderer();

// Asset mangement
Expand Down Expand Up @@ -190,10 +197,10 @@ void Presenter::init_gui() {

this->gui = std::make_shared<renderer::gui::GUI>(
this->gui_app, // Qt application wrapper
this->window, // window for the gui
this->window, // window for the gui
qml_root_file, // entry qml file, absolute path.
qml_root, // directory to watch for qml file changes
qml_assets, // qml data: Engine *, the data directory, ...
qml_root, // directory to watch for qml file changes
qml_assets, // qml data: Engine *, the data directory, ...
this->renderer // openage renderer
);

Expand Down
8 changes: 6 additions & 2 deletions libopenage/renderer/demo/demo_0.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2023 the openage authors. See copying.md for legal info.
// Copyright 2015-2024 the openage authors. See copying.md for legal info.

#include "demo_0.h"

Expand All @@ -13,7 +13,11 @@ namespace openage::renderer::tests {
void renderer_demo_0(const util::Path &path) {
auto qtapp = std::make_shared<gui::GuiApplicationWithLogger>();

opengl::GlWindow window("openage renderer test", 800, 600, true);
window_settings settings;
settings.width = 800;
settings.height = 600;
settings.debug = true;
opengl::GlWindow window("openage renderer test", settings);
auto renderer = window.make_renderer();

auto shaderdir = path / "assets" / "test" / "shaders";
Expand Down
8 changes: 6 additions & 2 deletions libopenage/renderer/demo/demo_1.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2023 the openage authors. See copying.md for legal info.
// Copyright 2015-2024 the openage authors. See copying.md for legal info.

#include "demo_1.h"

Expand All @@ -19,7 +19,11 @@ namespace openage::renderer::tests {
void renderer_demo_1(const util::Path &path) {
auto qtapp = std::make_shared<gui::GuiApplicationWithLogger>();

opengl::GlWindow window("openage renderer test", 800, 600, true);
window_settings settings;
settings.width = 800;
settings.height = 600;
settings.debug = true;
opengl::GlWindow window("openage renderer test", settings);
auto renderer = window.make_renderer();

auto shaderdir = path / "assets" / "test" / "shaders";
Expand Down
16 changes: 10 additions & 6 deletions libopenage/renderer/demo/demo_2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2023 the openage authors. See copying.md for legal info.
// Copyright 2015-2024 the openage authors. See copying.md for legal info.

#include "demo_2.h"

Expand All @@ -22,7 +22,11 @@ namespace openage::renderer::tests {
void renderer_demo_2(const util::Path &path) {
auto qtapp = std::make_shared<gui::GuiApplicationWithLogger>();

opengl::GlWindow window("openage renderer test", 800, 600, true);
window_settings settings;
settings.width = 800;
settings.height = 600;
settings.debug = true;
opengl::GlWindow window("openage renderer test", settings);
auto renderer = window.make_renderer();

/* Load texture file standalone. */
Expand Down Expand Up @@ -150,10 +154,10 @@ void renderer_demo_2(const util::Path &path) {
1.0f));

/* Pass uniforms to the shaders.
mv : The upscaling matrix
offset_tile : Subtexture coordinates (as floats relative to texture image size)
u_id : Identifier
tex : OpenGL texture reference
mv : The upscaling matrix
offset_tile : Subtexture coordinates (as floats relative to texture image size)
u_id : Identifier
tex : OpenGL texture reference
*/
auto obj1_unifs = obj_shader->new_uniform_input(
"mv",
Expand Down
8 changes: 6 additions & 2 deletions libopenage/renderer/demo/demo_3.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2023 the openage authors. See copying.md for legal info.
// Copyright 2015-2024 the openage authors. See copying.md for legal info.

#include "demo_3.h"

Expand Down Expand Up @@ -28,7 +28,11 @@ namespace openage::renderer::tests {
void renderer_demo_3(const util::Path &path) {
auto qtapp = std::make_shared<gui::GuiApplicationWithLogger>();

auto window = std::make_shared<opengl::GlWindow>("openage renderer test", 800, 600, true);
window_settings settings;
settings.width = 800;
settings.height = 600;
settings.debug = true;
auto window = std::make_shared<opengl::GlWindow>("openage renderer test", settings);
auto renderer = window->make_renderer();

// Clock required by world renderer for timing animation frames
Expand Down
16 changes: 10 additions & 6 deletions libopenage/renderer/demo/demo_4.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2023 the openage authors. See copying.md for legal info.
// Copyright 2015-2024 the openage authors. See copying.md for legal info.

#include "demo_4.h"

Expand All @@ -20,7 +20,11 @@ namespace openage::renderer::tests {
void renderer_demo_4(const util::Path &path) {
auto qtapp = std::make_shared<gui::GuiApplicationWithLogger>();

opengl::GlWindow window("openage renderer test", 800, 600, true);
window_settings settings;
settings.width = 800;
settings.height = 600;
settings.debug = true;
opengl::GlWindow window("openage renderer test", settings);
auto renderer = window.make_renderer();

/* Clock for timed display */
Expand Down Expand Up @@ -97,10 +101,10 @@ void renderer_demo_4(const util::Path &path) {
1.0f));

/* Pass uniforms to the shaders.
mv : The upscaling matrix
offset_tile : Subtexture coordinates (as floats relative to texture image size)
u_id : Identifier
tex : OpenGL texture reference
mv : The upscaling matrix
offset_tile : Subtexture coordinates (as floats relative to texture image size)
u_id : Identifier
tex : OpenGL texture reference
*/
auto obj1_unifs = obj_shader->new_uniform_input(
"mv",
Expand Down
8 changes: 6 additions & 2 deletions libopenage/renderer/demo/demo_5.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2023 the openage authors. See copying.md for legal info.
// Copyright 2023-2024 the openage authors. See copying.md for legal info.

#include "demo_5.h"

Expand All @@ -22,7 +22,11 @@ namespace openage::renderer::tests {
void renderer_demo_5(const util::Path &path) {
auto qtapp = std::make_shared<gui::GuiApplicationWithLogger>();

opengl::GlWindow window("openage renderer test", 800, 600, true);
window_settings settings;
settings.width = 800;
settings.height = 600;
settings.debug = true;
opengl::GlWindow window("openage renderer test", settings);
auto renderer = window.make_renderer();
auto size = window.get_size();

Expand Down
9 changes: 7 additions & 2 deletions libopenage/renderer/demo/stresstest_0.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2023 the openage authors. See copying.md for legal info.
// Copyright 2023-2024 the openage authors. See copying.md for legal info.

#include "stresstest_0.h"

Expand Down Expand Up @@ -28,7 +28,12 @@ namespace openage::renderer::tests {
void renderer_stresstest_0(const util::Path &path) {
auto qtapp = std::make_shared<gui::GuiApplicationWithLogger>();

auto window = std::make_shared<opengl::GlWindow>("openage renderer test", 1024, 768, true);
window_settings settings;
settings.width = 1024;
settings.height = 768;
settings.vsync = false;
settings.debug = true;
auto window = std::make_shared<opengl::GlWindow>("openage renderer test", settings);
auto renderer = window->make_renderer();

// Clock required by world renderer for timing animation frames
Expand Down
2 changes: 1 addition & 1 deletion libopenage/renderer/opengl/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class GlContext {
* Activate or deactivate VSync for this context.
*
* TODO: This currently does not work at runtime. vsync must be set before
* the QApplication is created.
* the QWindow is created.
*
* @param on \p true to activate VSync, \p false to deactivate.
*/
Expand Down
18 changes: 10 additions & 8 deletions libopenage/renderer/opengl/window.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2023 the openage authors. See copying.md for legal info.
// Copyright 2018-2024 the openage authors. See copying.md for legal info.

#include "window.h"

Expand All @@ -18,10 +18,8 @@
namespace openage::renderer::opengl {

GlWindow::GlWindow(const std::string &title,
size_t width,
size_t height,
bool debug) :
Window{width, height} {
window_settings settings) :
Window{settings.width, settings.height} {
if (QGuiApplication::instance() == nullptr) {
// Qt windows need to attach to a QtGuiApplication
throw Error{MSG(err) << "Failed to create Qt window: QGuiApplication has not been created yet."};
Expand All @@ -31,7 +29,7 @@ GlWindow::GlWindow(const std::string &title,
this->window = std::make_shared<QWindow>();

this->window->setTitle(QString::fromStdString(title));
this->window->resize(width, height);
this->window->resize(settings.width, settings.height);

this->window->setSurfaceType(QSurface::OpenGLSurface);

Expand All @@ -40,22 +38,26 @@ GlWindow::GlWindow(const std::string &title,
format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
format.setSwapBehavior(QSurfaceFormat::SwapBehavior::DoubleBuffer);

if (not settings.vsync) {
format.setSwapInterval(0);
}

format.setMajorVersion(gl_specs.major_version);
format.setMinorVersion(gl_specs.minor_version);

format.setAlphaBufferSize(8);
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);

if (debug) {
if (settings.debug) {
format.setOption(QSurfaceFormat::DebugContext);
}

// TODO: Set format as default for all windows with QSurface::setDefaultFormat()
this->window->setFormat(format);
this->window->create();

this->context = std::make_shared<GlContext>(this->window, debug);
this->context = std::make_shared<GlContext>(this->window, settings.debug);
if (not this->context->get_raw_context()->isValid()) {
throw Error{MSG(err) << "Failed to create Qt OpenGL context."};
}
Expand Down
10 changes: 3 additions & 7 deletions libopenage/renderer/opengl/window.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2023 the openage authors. See copying.md for legal info.
// Copyright 2018-2024 the openage authors. See copying.md for legal info.

#pragma once

Expand All @@ -25,14 +25,10 @@ class GlWindow final : public Window {
* Create a shiny window with the given title.
*
* @param title The window title.
* @param width Width (in pixels).
* @param height Height (in pixels).
* @param debug If true, enable OpenGL debug logging.
* @param settings Settings for creating the window.
*/
GlWindow(const std::string &title,
size_t width,
size_t height,
bool debug = false);
window_settings settings = {});
~GlWindow();

void set_size(size_t width, size_t height) override;
Expand Down
10 changes: 10 additions & 0 deletions libopenage/renderer/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ namespace openage::renderer {
*/
using uniform_id_t = uint32_t;

/**
* Graphics API types.
*/
enum class graphics_api_t {
DEFAULT,
OPENGL,
VULKAN,
};


} // namespace openage::renderer
8 changes: 3 additions & 5 deletions libopenage/renderer/window.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2023 the openage authors. See copying.md for legal info.
// Copyright 2015-2024 the openage authors. See copying.md for legal info.

#include "window.h"

Expand All @@ -11,13 +11,11 @@
namespace openage::renderer {

std::shared_ptr<Window> Window::create(const std::string &title,
size_t width,
size_t height,
bool debug) {
window_settings settings) {
// currently we only have a functional GL window
// TODO: support other renderer windows
// and add some selection mechanism.
return std::make_shared<opengl::GlWindow>(title, width, height, debug);
return std::make_shared<opengl::GlWindow>(title, settings);
}


Expand Down
Loading