Skip to content

Commit

Permalink
GLFW fixes, minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Dec 4, 2024
1 parent 7b8cfa8 commit 2380776
Show file tree
Hide file tree
Showing 24 changed files with 1,290 additions and 1,075 deletions.
Binary file modified Content/Translations/cs.mo
Binary file not shown.
207 changes: 111 additions & 96 deletions Content/Translations/cs.po

Large diffs are not rendered by default.

205 changes: 110 additions & 95 deletions Content/Translations/es.po

Large diffs are not rendered by default.

205 changes: 110 additions & 95 deletions Content/Translations/fr.po

Large diffs are not rendered by default.

205 changes: 110 additions & 95 deletions Content/Translations/gl.po

Large diffs are not rendered by default.

205 changes: 110 additions & 95 deletions Content/Translations/it.po

Large diffs are not rendered by default.

205 changes: 110 additions & 95 deletions Content/Translations/pl.po

Large diffs are not rendered by default.

205 changes: 110 additions & 95 deletions Content/Translations/pt.po

Large diffs are not rendered by default.

205 changes: 110 additions & 95 deletions Content/Translations/pt_BR.po

Large diffs are not rendered by default.

205 changes: 110 additions & 95 deletions Content/Translations/ro.po

Large diffs are not rendered by default.

205 changes: 110 additions & 95 deletions Content/Translations/ru.po

Large diffs are not rendered by default.

205 changes: 110 additions & 95 deletions Content/Translations/tr.po

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Sources/Jazz2/UI/Menu/ControlsOptionsSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Jazz2::UI::Menu
_items.emplace_back(ControlsOptionsItem { ControlsOptionsItemType::UseNativeBackButton, _("Native Back Button"), true });
#endif
_items.emplace_back(ControlsOptionsItem { ControlsOptionsItemType::InputDiagnostics, _("Input Diagnostics") });
_items.emplace_back(ControlsOptionsItem { ControlsOptionsItemType::ResetToDefault, _("Reset To Default") });
}

ControlsOptionsSection::~ControlsOptionsSection()
Expand Down Expand Up @@ -176,6 +177,7 @@ namespace Jazz2::UI::Menu
break;
#endif
case ControlsOptionsItemType::InputDiagnostics: _root->SwitchToSection<InputDiagnosticsSection>(); break;
case ControlsOptionsItemType::ResetToDefault: ControlScheme::Reset(); break;
}
}
}
3 changes: 2 additions & 1 deletion Sources/Jazz2/UI/Menu/ControlsOptionsSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace Jazz2::UI::Menu
#if defined(NCINE_HAS_NATIVE_BACK_BUTTON)
UseNativeBackButton,
#endif
InputDiagnostics
InputDiagnostics,
ResetToDefault
};

struct ControlsOptionsItem {
Expand Down
12 changes: 10 additions & 2 deletions Sources/Jazz2/UI/Menu/GraphicsOptionsSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Jazz2::UI::Menu
{
// TRANSLATORS: Menu item in Options > Graphics section
_items.emplace_back(GraphicsOptionsItem { GraphicsOptionsItemType::RescaleMode, _("Rescale Mode") });
// TRANSLATORS: Menu item in Options > Graphics section
_items.emplace_back(GraphicsOptionsItem { GraphicsOptionsItemType::Resolution, _("Resolution") });
#if defined(NCINE_HAS_WINDOWS)
# if defined(DEATH_TARGET_WINDOWS_RT)
// Xbox is always fullscreen
Expand Down Expand Up @@ -81,7 +83,7 @@ namespace Jazz2::UI::Menu

void GraphicsOptionsSection::OnLayoutItem(Canvas* canvas, ListViewItem& item)
{
item.Height = (item.Item.HasBooleanValue ? 52 : ItemHeight);
item.Height = (item.Item.HasBooleanValue || item.Item.Type == GraphicsOptionsItemType::Resolution ? 52 : ItemHeight);
}

void GraphicsOptionsSection::OnDrawItem(Canvas* canvas, ListViewItem& item, std::int32_t& charOffset, bool isSelected)
Expand All @@ -107,7 +109,13 @@ namespace Jazz2::UI::Menu
Alignment::Center, Font::DefaultColor, 0.9f);
}

if (item.Item.HasBooleanValue) {
if (item.Item.Type == GraphicsOptionsItemType::Resolution) {
Vector2i res = theApplication().GetGfxDevice().drawableResolution();
char customText[64];
formatString(customText, sizeof(customText), "%ix%i", res.X, res.Y);
_root->DrawStringShadow(customText, charOffset, centerX, item.Y + 22.0f, IMenuContainer::FontLayer - 10,
Alignment::Center, (isSelected ? Colorf(0.46f, 0.46f, 0.46f, 0.5f) : Font::DefaultColor), 0.8f);
} else if (item.Item.HasBooleanValue) {
StringView customText;
bool enabled = false;
switch (item.Item.Type) {
Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/UI/Menu/GraphicsOptionsSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Jazz2::UI::Menu
{
enum class GraphicsOptionsItemType {
RescaleMode,
Resolution,
#if defined(NCINE_HAS_WINDOWS)
Fullscreen,
#endif
Expand Down
7 changes: 6 additions & 1 deletion Sources/nCine/Backends/Android/EglGfxDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ namespace nCine
surface_ = EGL_NO_SURFACE;
}

const IGfxDevice::VideoMode &EglGfxDevice::currentVideoMode(unsigned int monitorIndex) const
void EglGfxDevice::update()
{
eglSwapBuffers(display_, surface_);
}

const IGfxDevice::VideoMode& EglGfxDevice::currentVideoMode(unsigned int monitorIndex) const
{
if (monitorIndex >= numMonitors_) {
monitorIndex = 0;
Expand Down
6 changes: 2 additions & 4 deletions Sources/nCine/Backends/Android/EglGfxDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ namespace nCine
void setWindowPosition(int x, int y) override { }
void setWindowSize(int width, int height) override { }

inline void update() override {
eglSwapBuffers(display_, surface_);
}
void update() override;

void setWindowTitle(const StringView& windowTitle) override { }
void setWindowIcon(const StringView& windowIconFilename) override { }

const VideoMode &currentVideoMode(unsigned int monitorIndex) const override;
const VideoMode& currentVideoMode(unsigned int monitorIndex) const override;
bool setVideoMode(unsigned int modeIndex) override;

/// Recreates a surface from a native window
Expand Down
29 changes: 24 additions & 5 deletions Sources/nCine/Backends/GlfwGfxDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "GlfwInputManager.h"
#include "../Graphics/ITextureLoader.h"

#if defined(DEATH_TARGET_EMSCRIPTEN) && defined(EMSCRIPTEN_USE_PORT_CONTRIB_GLFW3)
# include "GLFW/emscripten_glfw3.h"
#endif

#define GLFW_VERSION_COMBINED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 + GLFW_VERSION_REVISION)

namespace nCine
Expand All @@ -14,7 +18,7 @@ namespace nCine
int GlfwGfxDevice::fsModeIndex_ = -1;

GlfwGfxDevice::GlfwGfxDevice(const WindowMode& windowMode, const GLContextInfo& glContextInfo, const DisplayMode& displayMode)
: IGfxDevice(windowMode, glContextInfo, displayMode)
: IGfxDevice(windowMode, glContextInfo, displayMode)
{
initGraphics();
updateMonitors();
Expand All @@ -38,18 +42,24 @@ namespace nCine
// The windows goes in full screen on the same monitor
fsMonitorIndex_ = windowMonitorIndex();

#if !defined(DEATH_TARGET_EMSCRIPTEN)
GLFWmonitor* monitor = monitorPointers_[fsMonitorIndex_];
const GLFWvidmode* currentMode = glfwGetVideoMode(monitorPointers_[fsMonitorIndex_]);
#endif

bool wasFullscreen = isFullscreen_;
isFullscreen_ = fullscreen;

if (fullscreen) {
#if defined(DEATH_TARGET_EMSCRIPTEN)
# if defined(EMSCRIPTEN_USE_PORT_CONTRIB_GLFW3)
emscripten_glfw_request_fullscreen(nullptr, false, false);
# else
// On Emscripten, requesting full screen on GLFW is done by changing the window size to the screen size
EmscriptenFullscreenChangeEvent fsce;
emscripten_get_fullscreen_status(&fsce);
glfwSetWindowSize(windowHandle_, fsce.screenWidth, fsce.screenHeight);
# endif
#else
int width = (monitor != nullptr ? currentMode->width : width_);
int height = (monitor != nullptr ? currentMode->height : height_);
Expand Down Expand Up @@ -87,7 +97,7 @@ namespace nCine
glfwSetWindowMonitor(windowHandle_, nullptr, 0, 0, width_, height_, GLFW_DONT_CARE);
if (wasFullscreen) {
glfwSetWindowPos(windowHandle_, monitors_[fsMonitorIndex_].position.X + (currentMode->width - width_) / 2,
monitors_[fsMonitorIndex_].position.Y + (currentMode->height - height_) / 2);
monitors_[fsMonitorIndex_].position.Y + (currentMode->height - height_) / 2);
}
#endif
}
Expand All @@ -101,6 +111,13 @@ namespace nCine
}
}

void GlfwGfxDevice::update()
{
#if !defined(DEATH_TARGET_EMSCRIPTEN) // Buffers are swapped implicitly in WebGL
glfwSwapBuffers(windowHandle_);
#endif
}

void GlfwGfxDevice::setResolutionInternal(int width, int height)
{
glfwSetWindowSize(windowHandle_, width, height);
Expand All @@ -110,13 +127,15 @@ namespace nCine

void GlfwGfxDevice::setWindowIcon(const StringView& windowIconFilename)
{
#if !defined(DEATH_TARGET_EMSCRIPTEN)
std::unique_ptr<ITextureLoader> image = ITextureLoader::createFromFile(windowIconFilename);
GLFWimage glfwImage;
glfwImage.width = image->width();
glfwImage.height = image->height();
glfwImage.pixels = const_cast<unsigned char*>(image->pixels());

glfwSetWindowIcon(windowHandle_, 1, &glfwImage);
#endif
}

const Vector2i GlfwGfxDevice::windowPosition() const
Expand Down Expand Up @@ -158,7 +177,7 @@ namespace nCine

void GlfwGfxDevice::flashWindow() const
{
#if GLFW_VERSION_COMBINED >= 3300
#if GLFW_VERSION_COMBINED >= 3300 && !defined(DEATH_TARGET_EMSCRIPTEN)
glfwRequestWindowAttention(windowHandle_);
#endif
}
Expand Down Expand Up @@ -287,7 +306,7 @@ namespace nCine
glfwWindowHint(GLFW_STENCIL_BITS, static_cast<int>(displayMode_.stencilBits()));
#if defined(DEATH_TARGET_EMSCRIPTEN)
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
glfwWindowHint(GLFW_FOCUSED, 1);
glfwWindowHint(GLFW_FOCUSED, GLFW_TRUE);
#elif defined(WITH_OPENGLES)
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
Expand All @@ -312,7 +331,7 @@ namespace nCine

windowHandle_ = glfwCreateWindow(width_, height_, "", monitor, nullptr);
FATAL_ASSERT_MSG(windowHandle_, "glfwCreateWindow() failed");

#if GLFW_VERSION_COMBINED < 3400
//const bool ignoreBothWindowPosition = (windowMode.windowPositionX == AppConfiguration::WindowPositionIgnore &&
// windowMode.windowPositionY == AppConfiguration::WindowPositionIgnore);
Expand Down
4 changes: 1 addition & 3 deletions Sources/nCine/Backends/GlfwGfxDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ namespace nCine

void setResolution(bool fullscreen, int width = 0, int height = 0) override;

inline void update() override {
glfwSwapBuffers(windowHandle_);
}
void update() override;

void setWindowPosition(int x, int y) override;
void setWindowSize(int width, int height) override;
Expand Down
31 changes: 23 additions & 8 deletions Sources/nCine/Backends/GlfwInputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ namespace nCine
case Cursor::HiddenLocked: glfwSetInputMode(GlfwGfxDevice::windowHandle(), GLFW_CURSOR, GLFW_CURSOR_DISABLED); break;
}

#if GLFW_VERSION_COMBINED >= 3300
#if GLFW_VERSION_COMBINED >= 3300 && !defined(DEATH_TARGET_EMSCRIPTEN)
// Enable raw mouse motion (if supported) when disabling the cursor
const bool enableRawMouseMotion = (cursor == Cursor::HiddenLocked && glfwRawMouseMotionSupported() == GLFW_TRUE);
glfwSetInputMode(GlfwGfxDevice::windowHandle(), GLFW_RAW_MOUSE_MOTION, enableRawMouseMotion ? GLFW_TRUE : GLFW_FALSE);
Expand Down Expand Up @@ -401,31 +401,46 @@ namespace nCine
joyConnectionEvent_.joyId = joyId;

if (event == GLFW_CONNECTED) {
#if defined(DEATH_TARGET_EMSCRIPTEN) && defined(EMSCRIPTEN_USE_PORT_CONTRIB_GLFW3)
// `contrib.glfw3` is polling gamepads asynchronously, number of buttons/axes is usually 0 here, so skip these checks instead
# if defined(DEATH_TRACE)
# if GLFW_VERSION_COMBINED >= 3300
// It seems `glfwGetJoystickGUID` can cause crash if the gamepad is quickly disconnected
const char* guid = glfwGetJoystickGUID(joy);
# else
const char* guid = "default";
# endif
LOGI("Gamepad %d \"%s\" [%s] has been connected", joyId, glfwGetJoystickName(joy), guid);
# endif
#else
int numButtons = -1;
int numAxes = -1;
int numHats = -1;
glfwGetJoystickButtons(joy, &numButtons);
glfwGetJoystickAxes(joy, &numAxes);
#if !defined(DEATH_TARGET_EMSCRIPTEN) && GLFW_VERSION_COMBINED >= 3300
# if GLFW_VERSION_COMBINED >= 3300
glfwGetJoystickHats(joy, &numHats);
#else
# else
numHats = 0;
#endif
# endif

if (numButtons <= 0 && numAxes <= 0 && numHats <= 0) {
LOGI("Gamepad %d has been connected, but reports no axes/buttons/hats - skipping", joyId);
return;
}

#if defined(DEATH_TRACE)
# if !defined(DEATH_TARGET_EMSCRIPTEN) && GLFW_VERSION_COMBINED >= 3300
# if defined(DEATH_TRACE)
# if GLFW_VERSION_COMBINED >= 3300
// It seems `glfwGetJoystickGUID` can cause crash if the gamepad is quickly disconnected
const char* guid = glfwGetJoystickGUID(joy);
# else
# else
const char* guid = "default";
# endif
# endif
LOGI("Gamepad %d \"%s\" [%s] has been connected - %d axes, %d buttons, %d hats",
joyId, glfwGetJoystickName(joy), guid, numAxes, numButtons, numHats);
# endif
#endif

updateJoystickStates();

if (inputEventHandler_ != nullptr) {
Expand Down
5 changes: 5 additions & 0 deletions Sources/nCine/Backends/SdlGfxDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ namespace nCine
SDL_GL_GetDrawableSize(windowHandle_, &drawableWidth_, &drawableHeight_);
}

void SdlGfxDevice::update()
{
SDL_GL_SwapWindow(windowHandle_);
}

void SdlGfxDevice::setResolutionInternal(int width, int height)
{
width_ = width;
Expand Down
4 changes: 1 addition & 3 deletions Sources/nCine/Backends/SdlGfxDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ namespace nCine

void setResolution(bool fullscreen, int width = 0, int height = 0) override;

inline void update() override {
SDL_GL_SwapWindow(windowHandle_);
}
void update() override;

inline void setWindowPosition(int x, int y) override { SDL_SetWindowPosition(windowHandle_, x, y); }

Expand Down
4 changes: 2 additions & 2 deletions cmake/ncine_imported_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ if(EMSCRIPTEN)
# INTERFACE_LINK_OPTIONS "SHELL:-s USE_GLFW=3")

# Newer GLFW implementation supported since Emscripten 3.1.55
set_target_properties(GLFW::GLFW PROPERTIES
INTERFACE_LINK_OPTIONS "SHELL:--use-port=contrib.glfw3")
target_compile_options(GLFW::GLFW INTERFACE "--use-port=contrib.glfw3")
target_link_options(GLFW::GLFW INTERFACE "--use-port=contrib.glfw3")
set(GLFW_FOUND 1)
elseif(NCINE_PREFERRED_BACKEND STREQUAL "SDL2")
add_library(SDL2::SDL2 INTERFACE IMPORTED)
Expand Down

0 comments on commit 2380776

Please sign in to comment.