-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement runtime display (test) (#318)
* Implement runtime display (test) * Update runtime.cpp * [game display] add "-nodisplay" argument * style fixes * Update gfx.cpp * [deci2server] fix deadlock when killing a Deci2Server * add libxrandr to linux github test * correct package name to libxrandr-dev * set g_main_thread_id in exec_runtime * add libxinerama to linux test packages * correct the name * add libxcursor1 package * Update linux-workflow.yaml * add libxi-dev * fix constructor for g_main_thread_id * fix submodules + use -nodisplay during tests * move the gfx loop to its own function and use a lambda for exit conditions * fix include * fix include * fix includes (for real this time)
- Loading branch information
Showing
22 changed files
with
27,947 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*! | ||
* @file display.cpp | ||
* Display for graphics. This is the game window, distinct from the runtime console. | ||
*/ | ||
|
||
#include "display.h" | ||
|
||
#include "common/log/log.h" | ||
|
||
namespace Display { | ||
|
||
GLFWwindow* display = NULL; | ||
|
||
void InitDisplay(int width, int height, char* title, GLFWwindow*& d) { | ||
if (d) { | ||
lg::warn("InitDisplay has already created a display window"); | ||
return; | ||
} | ||
|
||
// request OpenGL 3.0 (placeholder) | ||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | ||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); | ||
d = glfwCreateWindow(width, height, title, NULL, NULL); | ||
|
||
if (!d) { | ||
lg::error("InitDisplay failed - Could not create display window"); | ||
return; | ||
} | ||
|
||
glfwMakeContextCurrent(d); | ||
if (!gladLoadGL()) { | ||
lg::error("GL init fail"); | ||
KillDisplay(d); | ||
return; | ||
} | ||
|
||
// enable vsync by default | ||
glfwSwapInterval(1); | ||
|
||
lg::debug("init display #x{}", (uintptr_t)d); | ||
} | ||
|
||
void KillDisplay(GLFWwindow*& d) { | ||
lg::debug("kill display #x{}", (uintptr_t)d); | ||
if (!d) { | ||
lg::warn("KillDisplay called when no display was available"); | ||
return; | ||
} | ||
|
||
glfwDestroyWindow(d); | ||
d = NULL; | ||
} | ||
|
||
} // namespace Display |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
/*! | ||
* @file display.h | ||
* Display for graphics. This is the game window, distinct from the runtime console. | ||
*/ | ||
|
||
#ifndef RUNTIME_DISPLAY_H | ||
#define RUNTIME_DISPLAY_H | ||
|
||
#include "opengl.h" | ||
|
||
namespace Display { | ||
|
||
// TODO - eventually we might actually want to support having multiple windows and viewpoints | ||
// so it would be nice if we didn't end up designing this system such that this MUST be | ||
// a single window. | ||
extern GLFWwindow* display; | ||
|
||
void InitDisplay(int width, int height, char* title, GLFWwindow*& d); | ||
void KillDisplay(GLFWwindow*& d); | ||
|
||
} // namespace Display | ||
|
||
#endif // RUNTIME_DISPLAY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*! | ||
* @file gfx.cpp | ||
* Graphics component for the runtime. Handles some low-level routines. | ||
*/ | ||
|
||
#include "gfx.h" | ||
#include "common/log/log.h" | ||
#include "game/runtime.h" | ||
#include "display.h" | ||
|
||
#include "opengl.h" | ||
|
||
namespace Gfx { | ||
|
||
void GlfwErrorCallback(int err, const char* msg) { | ||
lg::error("GLFW ERR {}: " + std::string(msg), err); | ||
} | ||
|
||
u32 Init() { | ||
if (glfwSetErrorCallback(GlfwErrorCallback) != NULL) { | ||
lg::warn("glfwSetErrorCallback has been re-set!"); | ||
} | ||
|
||
if (!glfwInit()) { | ||
lg::error("glfwInit error"); | ||
return 1; | ||
} | ||
|
||
if (g_main_thread_id != std::this_thread::get_id()) { | ||
lg::warn("ran Gfx::Init outside main thread. Init display elsewhere?"); | ||
} else { | ||
Display::InitDisplay(640, 480, "testy", Display::display); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
u32 Exit() { | ||
lg::debug("gfx exit"); | ||
Display::KillDisplay(Display::display); | ||
glfwTerminate(); | ||
glfwSetErrorCallback(NULL); | ||
return 0; | ||
} | ||
|
||
} // namespace Gfx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
/*! | ||
* @file gfx.h | ||
* Graphics component for the runtime. Handles some low-level routines. | ||
*/ | ||
|
||
#ifndef RUNTIME_GFX_H | ||
#define RUNTIME_GFX_H | ||
|
||
#include "common/common_types.h" | ||
#include "display.h" | ||
#include "game/kernel/kboot.h" | ||
|
||
namespace Gfx { | ||
|
||
u32 Init(); | ||
u32 Exit(); | ||
|
||
template <typename T> | ||
void Loop(T f) { | ||
while (f()) { | ||
// run display-specific things | ||
if (Display::display) { | ||
// lg::debug("run display"); | ||
glfwMakeContextCurrent(Display::display); | ||
|
||
// render graphics | ||
glClear(GL_COLOR_BUFFER_BIT); | ||
|
||
glfwSwapBuffers(Display::display); | ||
|
||
// poll events TODO integrate input with cpad | ||
glfwPollEvents(); | ||
|
||
// exit if display window was closed | ||
if (glfwWindowShouldClose(Display::display)) { | ||
// Display::KillDisplay(Display::display); | ||
MasterExit = 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} // namespace Gfx | ||
|
||
#endif // RUNTIME_GFX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
/*! | ||
* @file opengl.h | ||
* OpenGL includes. | ||
*/ | ||
|
||
#ifndef RUNTIME_OPENGL_H | ||
#define RUNTIME_OPENGL_H | ||
|
||
#define GLFW_INCLUDE_NONE | ||
#include <glad/glad.h> | ||
#include <GLFW/glfw3.h> | ||
|
||
#endif // RUNTIME_OPENGL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.