Skip to content

Commit

Permalink
Merge pull request #733 from lethal-guitar/fix-mac-hidpi-rendering-mo…
Browse files Browse the repository at this point in the history
…dded

Fix Mac high DPI rendering when modded
  • Loading branch information
lethal-guitar authored Aug 22, 2021
2 parents ee50189 + bc0e1aa commit d315e76
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 42 deletions.
30 changes: 6 additions & 24 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ docker run -ti --device=/dev/dri:/dev/dri --cap-add=SYS_PTRACE --security-opt se

### <a name="mac-build-instructions">OS X builds</a>

:exclamation: On Mojave (10.14) and older, non-Apple clang must be installed via Homebrew, Apple's clang does not have all required C++ library features. Starting with Catalina (10.15), Xcode's clang works fine.

The oldest OS/compiler combination that has worked for me is clang 7 on Sierra (10.12).
:exclamation: On Mojave (10.14), non-Apple clang must be installed via Homebrew, Apple's clang does not have all required C++ library features. Starting with Catalina (10.15), Xcode's clang works fine.

### <a name="mac-build-instructions-1015">Catalina (10.15) or newer</a>

Expand All @@ -266,6 +264,9 @@ mkdir build
cd build
cmake .. -DWARNINGS_AS_ERRORS=OFF
make
# Now run it!
./src/RigelEngine.app/Contents/MacOS/RigelEngine
```

### <a name="mac-build-instructions-1014">Mojave (10.14) using clang 8</a>
Expand All @@ -290,28 +291,9 @@ mkdir build
cd build
cmake .. -DWARNINGS_AS_ERRORS=OFF
make
```

### <a name="mac-build-instructions-1013">High Sierra (10.13) or older using clang 7</a>

```bash
# You might need to run brew update.
brew install llvm@7 cmake sdl2 sdl2_mixer boost

# Set up environment variables so that CMake picks up the newly installed clang -
# this is only necessary the first time.
export rigel_llvm_path=`brew --prefix llvm@7`;
export CC="$rigel_llvm_path/bin/clang";
export CXX="$CC++";
export CPPFLAGS="-I$rigel_llvm_path/include";
export LDFLAGS="-L$rigel_llvm_path/lib -Wl,-rpath,$rigel_llvm_path/lib";
unset rigel_llvm_path;

# Now, the regular build via CMake should work:
mkdir build
cd build
cmake .. -DWARNINGS_AS_ERRORS=OFF
make
# Now run it!
./src/RigelEngine.app/Contents/MacOS/RigelEngine
```

### <a name="windows-build-instructions">Windows builds</a>
Expand Down
5 changes: 4 additions & 1 deletion src/frontend/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ Game::Game(
, mIsMinimized(false)
, mCommandLineOptions(commandLineOptions)
, mpUserProfile(pUserProfile)
, mPreviousWindowSize(mRenderer.windowSize())
, mWidescreenModeWasActive(
pUserProfile->mOptions.mWidescreenModeOn &&
renderer::canUseWidescreenMode(&mRenderer))
Expand Down Expand Up @@ -637,7 +638,8 @@ void Game::applyChangedOptions()
if (
widescreenModeActive != mWidescreenModeWasActive ||
currentOptions.mPerElementUpscalingEnabled !=
mPreviousOptions.mPerElementUpscalingEnabled)
mPreviousOptions.mPerElementUpscalingEnabled ||
mPreviousWindowSize != mRenderer.windowSize())
{
mRenderTarget = renderer::createFullscreenRenderTarget(
&mRenderer, mpUserProfile->mOptions);
Expand All @@ -646,6 +648,7 @@ void Game::applyChangedOptions()

mPreviousOptions = mpUserProfile->mOptions;
mWidescreenModeWasActive = widescreenModeActive;
mPreviousWindowSize = mRenderer.windowSize();
}


Expand Down
1 change: 1 addition & 0 deletions src/frontend/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class Game : public IGameServiceProvider
CommandLineOptions mCommandLineOptions;
UserProfile* mpUserProfile;
data::GameOptions mPreviousOptions;
base::Size<int> mPreviousWindowSize;
bool mWidescreenModeWasActive;
std::filesystem::path mGamePathToSwitchTo;

Expand Down
5 changes: 4 additions & 1 deletion src/game_logic/game_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ GameWorld::GameWorld(
mpRenderer,
renderer::determineWidescreenViewPort(mpRenderer).mWidthPx,
data::GameTraits::viewPortHeightPx)
, mPreviousWindowSize(mpRenderer->windowSize())
, mWidescreenModeWasOn(widescreenModeOn())
, mPerElementUpscalingWasEnabled(mpOptions->mPerElementUpscalingEnabled)
{
Expand Down Expand Up @@ -703,7 +704,8 @@ void GameWorld::render()
{
if (
widescreenModeOn() != mWidescreenModeWasOn ||
mpOptions->mPerElementUpscalingEnabled != mPerElementUpscalingWasEnabled)
mpOptions->mPerElementUpscalingEnabled != mPerElementUpscalingWasEnabled ||
mPreviousWindowSize != mpRenderer->windowSize())
{
mWaterEffectBuffer =
renderer::createFullscreenRenderTarget(mpRenderer, *mpOptions);
Expand Down Expand Up @@ -843,6 +845,7 @@ void GameWorld::render()

mWidescreenModeWasOn = widescreenModeOn();
mPerElementUpscalingWasEnabled = mpOptions->mPerElementUpscalingEnabled;
mPreviousWindowSize = mpRenderer->windowSize();
}


Expand Down
1 change: 1 addition & 0 deletions src/game_logic/game_world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class GameWorld : public entityx::Receiver<GameWorld>
ui::IngameMessageDisplay mMessageDisplay;
renderer::RenderTargetTexture mWaterEffectBuffer;
renderer::RenderTargetTexture mLowResLayer;
base::Size<int> mPreviousWindowSize;
bool mWidescreenModeWasOn;
bool mPerElementUpscalingWasEnabled;

Expand Down
12 changes: 0 additions & 12 deletions src/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ struct Renderer::Impl
RenderMode mLastKnownRenderMode = RenderMode::SpriteBatch;

// cold
base::Size<int> mMaxWindowSize;
int mNumTextures = 0;
int mNumInternalTextures = 0;
TextureId mWaterSurfaceAnimTexture = 0;
Expand Down Expand Up @@ -429,11 +428,6 @@ struct Renderer::Impl
{"position", "texCoordMask"})
, mWindowSize(getSize(pWindow))
, mpWindow(pWindow)
, mMaxWindowSize([pWindow]() {
SDL_DisplayMode displayMode;
sdl_utils::check(SDL_GetDesktopDisplayMode(0, &displayMode));
return base::Size<int>{displayMode.w, displayMode.h};
}())
{
// General configuration
glDisable(GL_DEPTH_TEST);
Expand Down Expand Up @@ -1323,12 +1317,6 @@ base::Size<int> Renderer::windowSize() const
}


base::Size<int> Renderer::maxWindowSize() const
{
return mpImpl->mMaxWindowSize;
}


void Renderer::setRenderTarget(const TextureId target)
{
mpImpl->setRenderTarget(target);
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/upscaling_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ RenderTargetTexture createFullscreenRenderTarget(
if (options.mPerElementUpscalingEnabled)
{
return RenderTargetTexture{
pRenderer,
pRenderer->maxWindowSize().width,
pRenderer->maxWindowSize().height};
pRenderer, pRenderer->windowSize().width, pRenderer->windowSize().height};
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/ui/options_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ void OptionsMenu::drawCreditsBox(const engine::TimeDelta dt)

ImGui::NewLine();

centeredText("OpenSUSE package by mnhauke (https://github.com/mnhauke)");
centeredText("openSUSE package by mnhauke (https://github.com/mnhauke)");

ImGui::NewLine();

Expand Down

0 comments on commit d315e76

Please sign in to comment.