Skip to content

Commit

Permalink
Improved software renderer creation
Browse files Browse the repository at this point in the history
* Prefer the opengl driver
* Check whether the renderer could be created
* Ensure the window surface is destroyed when using the software driver
  • Loading branch information
0x1F9F1 committed Mar 13, 2024
1 parent 4e9851a commit 1de0706
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
13 changes: 13 additions & 0 deletions code/midtown/agisdl/sdlswpipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "eventq7/winevent.h"
#include "pcwindis/dxinit.h"

#include <SDL_hints.h>
#include <SDL_render.h>
#include <SDL_syswm.h>

Expand Down Expand Up @@ -304,6 +305,12 @@ i32 agiSDLSWPipeline::BeginGfx()
sdl_renderer_ = SDL_CreateRenderer(
window_, -1, SDL_RENDERER_ACCELERATED | ((device_flags_1_ & 0x1) ? SDL_RENDERER_PRESENTVSYNC : 0));

if (sdl_renderer_ == nullptr)
{
Errorf("Failed to create SDL renderer: %s", SDL_GetError());
return AGI_ERROR_NO_DEVICE;
}

// FIXME: SDL_CreateRenderer can silently recreate the underlying window
SDL_SysWMinfo wm_info {};
SDL_VERSION(&wm_info.version);
Expand Down Expand Up @@ -511,6 +518,12 @@ void agiSDLSWPipeline::EndGfx()
sdl_renderer_ = nullptr;
}

// The "software" renderer/driver creates a window surface, but doesn't destroy it afterwards
if (SDL_HasWindowSurface(window_))
{
SDL_DestroyWindowSurface(window_);
}

gfx_started_ = false;
}

Expand Down
11 changes: 9 additions & 2 deletions code/midtown/arts7/sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ define_dummy_symbol(arts7_sim);

#include "sim.h"

#include "agi/error.h"
#include "agi/getdlp.h"
#include "agi/light.h"
#include "agi/mtllib.h"
Expand Down Expand Up @@ -57,13 +58,16 @@ i32 InitPipeline(char* title, i32 argc, char** argv)
if (PipelineInitialized)
Quitf("Tried to InitPipeline twice.");

PipelineInitialized = true;

Argc = argc;
Argv = argv;

agiPipeline::CurrentPipe = as_raw CreatePipeline(argc, argv);

if (!agiPipeline::CurrentPipe)
return AGI_ERROR_NO_DEVICE;

PipelineInitialized = true;

if (Pipe()->Validate())
Quit("Couldn't start renderer");

Expand Down Expand Up @@ -95,7 +99,10 @@ void ShutdownPipeline()
PipelineInitialized = false;

if (SunLight)
{
SunLight->Release();
SunLight = nullptr;
}

agiPrintShutdown();

Expand Down
1 change: 1 addition & 0 deletions code/midtown/midtown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ void ApplicationHelper(i32 argc, char** argv)
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "1");
SDL_SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, "1");
SDL_SetHint(SDL_HINT_WINDOWS_DPI_AWARENESS, "permonitorv2");
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
SDL_SetHintWithPriority(SDL_HINT_WINDOWS_INTRESOURCE_ICON, arts_formatf<16>("%i", dxiIcon), SDL_HINT_OVERRIDE);

if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0)
Expand Down

0 comments on commit 1de0706

Please sign in to comment.