Skip to content

Commit

Permalink
Added support for software rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmicro committed Jan 5, 2024
1 parent ded0980 commit c321074
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion emulator/include/Emulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ class OswEmulator {

static OswEmulator* instance; // "Singleton"
const bool isHeadless;
const bool isSoftwareRenderer;
bool autoWakeUp = true;

OswEmulator(bool headless, std::string configPath = "config.json", std::string imguiPath = "imgui.ini");
OswEmulator(bool softwareRenderer, bool headless, std::string configPath = "config.json", std::string imguiPath = "imgui.ini");
~OswEmulator();

void run();
Expand Down
5 changes: 3 additions & 2 deletions emulator/src/Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void shutdownEmulatorByInterruptSignal(int s) {
called = true;
}

OswEmulator::OswEmulator(bool headless, std::string configPath, std::string imguiPath): isHeadless(headless) {
OswEmulator::OswEmulator(bool softwareRenderer, bool headless, std::string configPath, std::string imguiPath): isHeadless(headless), isSoftwareRenderer(softwareRenderer) {
// Initialize variables
for(size_t i = 0; i < BTN_NUMBER; i++)
this->buttonCheckboxes[i] = false;
Expand All @@ -58,6 +58,7 @@ OswEmulator::OswEmulator(bool headless, std::string configPath, std::string imgu
if(this->isHeadless) {
this->mainSurface = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0);
assert(this->mainSurface && "Never fail surface creation");
assert(this->isSoftwareRenderer && "Software renderer is required in headless mode");
this->mainRenderer = SDL_CreateSoftwareRenderer(this->mainSurface);
} else {
// Init the SDL window and renderer
Expand All @@ -70,7 +71,7 @@ OswEmulator::OswEmulator(bool headless, std::string configPath, std::string imgu
SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI
);
assert(this->mainWindow && "Never fail window creation");
this->mainRenderer = SDL_CreateRenderer(this->mainWindow, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
this->mainRenderer = SDL_CreateRenderer(this->mainWindow, -1, this-isSoftwareRenderer ? SDL_RENDERER_SOFTWARE : (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED));
}
assert(this->mainRenderer && "Never fail renderer creation");
fakeDisplayInstance = std::make_unique<FakeDisplay>(DISP_W, DISP_H, this->mainRenderer);
Expand Down
7 changes: 5 additions & 2 deletions emulator/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ int main(int argc, char** argv) {
const std::string argRunUnitTests = "unit_tests";
const std::string argListAllTests = "list_tests";
const std::string argUiTests = "ui_tests";
const std::string argHeadless = "headless";
const std::string argSoftwareRenderer = "software_renderer";
a.add(argRunUnitTests, '\0', "run the unit test framework");
a.add(argListAllTests, '\0', "list all unit and UI tests, one per line");
a.add(argUiTests, '\0', "run emulator with UI tests window");
a.add("headless", '\0', "do not open a window; use software-rendering only"); // Warning: This parameter name is also used in the unit-tests!
a.add(argHeadless, '\0', "do not open a window; also implies --software_renderer"); // Warning: This parameter name is also used in the unit-tests!
a.add(argSoftwareRenderer, '\0', "use software-rendering only");
a.parse_check(argc, argv);

// Initialize SDL
Expand Down Expand Up @@ -60,7 +63,7 @@ int main(int argc, char** argv) {
returnval = UiTests_main();
} else {
// Create and run the emulator
std::unique_ptr<OswEmulator> oswEmu = std::make_unique<OswEmulator>(a.exist("headless"));
std::unique_ptr<OswEmulator> oswEmu = std::make_unique<OswEmulator>(a.exist(argSoftwareRenderer) or a.exist(argHeadless), a.exist(argHeadless));
OswEmulator::instance = oswEmu.get();
oswEmu->run();
OswEmulator::instance = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion emulator/src/tests/uiTests/UiTests_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int UiTests_main(UiTests_Mode mode = UiTests_Mode::Run) {

const bool isListMode = mode == UiTests_Mode::List;
// Create and run the emulator
std::unique_ptr<OswEmulator> oswEmu = std::make_unique<OswEmulator>(isListMode);
std::unique_ptr<OswEmulator> oswEmu = std::make_unique<OswEmulator>(isListMode, isListMode);
OswEmulator::instance = oswEmu.get();

// Setup test engine
Expand Down
2 changes: 1 addition & 1 deletion emulator/src/tests/unitTests/fixtures/EmulatorFixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EmulatorFixture {
// Create and run the (headless) emulator
this->configPath = "config_" + std::to_string(rand()) + ".json";
this->imguiPath = "imgui_" + std::to_string(rand()) + ".ini";
oswEmu = std::make_unique<OswEmulator>(headless, this->configPath, this->imguiPath);
oswEmu = std::make_unique<OswEmulator>(headless, headless, this->configPath, this->imguiPath);
OswEmulator::instance = oswEmu.get();
std::thread t([&]() {
try {
Expand Down

0 comments on commit c321074

Please sign in to comment.