mirror of
https://github.com/rt64/rt64.git
synced 2025-03-14 04:19:02 +00:00
Add the remaining SDL2 implementation that was required.
This commit is contained in:
parent
df28e32ab5
commit
384a7d6bf6
@ -61,13 +61,14 @@ namespace RT64 {
|
||||
|
||||
// Inspector
|
||||
|
||||
Inspector::Inspector(RenderDevice *device, const RenderSwapChain *swapChain, UserConfiguration::GraphicsAPI graphicsAPI) {
|
||||
Inspector::Inspector(RenderDevice *device, const RenderSwapChain *swapChain, UserConfiguration::GraphicsAPI graphicsAPI, SDL_Window *sdlWindow) {
|
||||
assert(device != nullptr);
|
||||
assert(swapChain != nullptr);
|
||||
|
||||
this->device = device;
|
||||
this->swapChain = swapChain;
|
||||
this->graphicsAPI = graphicsAPI;
|
||||
this->sdlWindow = sdlWindow;
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
|
||||
@ -75,10 +76,15 @@ namespace RT64 {
|
||||
ImPlot::CreateContext();
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
# ifdef _WIN32
|
||||
RenderWindow renderWindow = swapChain->getWindow();
|
||||
ImGui_ImplWin32_Init(renderWindow);
|
||||
# endif
|
||||
if (sdlWindow != nullptr) {
|
||||
ImGui_ImplSDL2_InitForOther(sdlWindow);
|
||||
}
|
||||
else {
|
||||
# ifdef _WIN32
|
||||
RenderWindow renderWindow = swapChain->getWindow();
|
||||
ImGui_ImplWin32_Init(renderWindow);
|
||||
# endif
|
||||
}
|
||||
|
||||
switch (graphicsAPI) {
|
||||
case UserConfiguration::GraphicsAPI::D3D12: {
|
||||
@ -155,11 +161,14 @@ namespace RT64 {
|
||||
break;
|
||||
}
|
||||
|
||||
# ifdef _WIN32
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
# else
|
||||
assert(false && "Unimplemented.");
|
||||
# endif
|
||||
if (sdlWindow != nullptr) {
|
||||
ImGui_ImplSDL2_Shutdown();
|
||||
}
|
||||
else {
|
||||
# ifdef _WIN32
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
# endif
|
||||
}
|
||||
|
||||
ImPlot::DestroyContext();
|
||||
ImGui::DestroyContext();
|
||||
@ -175,12 +184,15 @@ namespace RT64 {
|
||||
assert(worker != nullptr);
|
||||
|
||||
frameMutex.lock();
|
||||
|
||||
# ifdef _WIN32
|
||||
ImGui_ImplWin32_NewFrame();
|
||||
# else
|
||||
assert(false && "Unimplemented.");
|
||||
# endif
|
||||
|
||||
if (sdlWindow != nullptr) {
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
}
|
||||
else {
|
||||
# ifdef _WIN32
|
||||
ImGui_ImplWin32_NewFrame();
|
||||
# endif
|
||||
}
|
||||
|
||||
switch (graphicsAPI) {
|
||||
case UserConfiguration::GraphicsAPI::D3D12: {
|
||||
@ -244,6 +256,8 @@ namespace RT64 {
|
||||
#endif
|
||||
|
||||
bool Inspector::handleSdlEvent(SDL_Event *event) {
|
||||
assert((sdlWindow != nullptr) && "SDL Events shouldn't be handled if SDL was not used.");
|
||||
|
||||
bool processed = ImGui_ImplSDL2_ProcessEvent(event);
|
||||
if (processed) {
|
||||
if ((event->type == SDL_KEYDOWN) || (event->type == SDL_KEYUP)) {
|
||||
|
@ -23,12 +23,13 @@ namespace RT64 {
|
||||
struct Inspector {
|
||||
RenderDevice *device = nullptr;
|
||||
const RenderSwapChain *swapChain = nullptr;
|
||||
UserConfiguration::GraphicsAPI graphicsAPI;
|
||||
SDL_Window *sdlWindow = nullptr;
|
||||
std::unique_ptr<RenderDescriptorSet> descriptorSet;
|
||||
std::unique_ptr<VulkanContext> vulkanContext;
|
||||
UserConfiguration::GraphicsAPI graphicsAPI;
|
||||
std::mutex frameMutex;
|
||||
|
||||
Inspector(RenderDevice *device, const RenderSwapChain *swapChain, UserConfiguration::GraphicsAPI graphicsAPI);
|
||||
Inspector(RenderDevice *device, const RenderSwapChain *swapChain, UserConfiguration::GraphicsAPI graphicsAPI, SDL_Window *sdlWindow);
|
||||
~Inspector();
|
||||
void setIniPath(const std::filesystem::path &path);
|
||||
void newFrame(RenderWorker *worker);
|
||||
|
@ -513,7 +513,7 @@ namespace RT64 {
|
||||
if (userConfig.developerMode) {
|
||||
const std::lock_guard<std::mutex> lock(presentQueue->inspectorMutex);
|
||||
if (presentQueue->inspector == nullptr) {
|
||||
presentQueue->inspector = std::make_unique<Inspector>(device.get(), swapChain.get(), createdGraphicsAPI);
|
||||
presentQueue->inspector = std::make_unique<Inspector>(device.get(), swapChain.get(), createdGraphicsAPI, appWindow->sdlWindow);
|
||||
if (!userPaths.isEmpty()) {
|
||||
presentQueue->inspector->setIniPath(userPaths.imguiPath);
|
||||
}
|
||||
|
@ -44,21 +44,24 @@ namespace RT64 {
|
||||
this->listener = listener;
|
||||
|
||||
windowHandle = window;
|
||||
usingSdl = SDL_WasInit(SDL_INIT_VIDEO);
|
||||
|
||||
if (listener->usesWindowMessageFilter()) {
|
||||
if (usingSdl) {
|
||||
if ((sdlWindow == nullptr) && SDL_WasInit(SDL_INIT_VIDEO)) {
|
||||
// We'd normally install the event filter here, but Mupen does not set its own event filter
|
||||
// until much later. Instead, we delegate this to the first time a screen update is sent.
|
||||
// FIXME: We attempt to get the first window created by SDL2. This can be improved later
|
||||
// by actually passing the SDL_Window handle through as a parameter.
|
||||
sdlWindow = SDL_GetWindowFromID(1);
|
||||
}
|
||||
# ifdef _WIN32
|
||||
else {
|
||||
|
||||
if (sdlWindow == nullptr) {
|
||||
# ifdef _WIN32
|
||||
assert(HookedApplicationWindow == nullptr);
|
||||
assert(threadId != 0);
|
||||
windowHook = SetWindowsHookEx(WH_GETMESSAGE, &windowHookCallback, NULL, threadId);
|
||||
HookedApplicationWindow = this;
|
||||
# endif
|
||||
}
|
||||
# endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,9 +112,11 @@ namespace RT64 {
|
||||
# endif
|
||||
|
||||
// Create window.
|
||||
SDL_Window *sdlWindow = SDL_CreateWindow(windowTitle, bounds.left, bounds.top, bounds.width, bounds.height, SDL_WINDOW_RESIZABLE);
|
||||
sdlWindow = SDL_CreateWindow(windowTitle, bounds.left, bounds.top, bounds.width, bounds.height, SDL_WINDOW_RESIZABLE);
|
||||
assert((sdlWindow != nullptr) && "Failed to open window with SDL");
|
||||
|
||||
// Get native window handles from the window.
|
||||
SDL_SysWMinfo wmInfo;
|
||||
assert(sdlWindow && "Failed to open window with SDL");
|
||||
SDL_VERSION(&wmInfo.version);
|
||||
SDL_GetWindowWMInfo(sdlWindow, &wmInfo);
|
||||
# if defined(_WIN32)
|
||||
@ -323,7 +328,7 @@ namespace RT64 {
|
||||
#endif
|
||||
|
||||
void ApplicationWindow::sdlCheckFilterInstallation() {
|
||||
if (!sdlEventFilterInstalled && usingSdl) {
|
||||
if (!sdlEventFilterInstalled && (sdlWindow != nullptr)) {
|
||||
if (!SDL_GetEventFilter(&sdlEventFilterStored, &sdlEventFilterUserdata)) {
|
||||
sdlEventFilterStored = nullptr;
|
||||
sdlEventFilterUserdata = nullptr;
|
||||
|
@ -36,9 +36,9 @@ namespace RT64 {
|
||||
uint32_t refreshRate = 0;
|
||||
bool fullScreen = false;
|
||||
bool lastMaximizedState = false;
|
||||
bool usingSdl = false;
|
||||
int32_t windowLeft = INT32_MAX;
|
||||
int32_t windowTop = INT32_MAX;
|
||||
SDL_Window *sdlWindow = nullptr;
|
||||
SDL_EventFilter sdlEventFilterStored = nullptr;
|
||||
void *sdlEventFilterUserdata = nullptr;
|
||||
bool sdlEventFilterInstalled = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user