Duckstation/src/pse-sdl/sdl_interface.h

79 lines
1.9 KiB
C
Raw Normal View History

2019-09-09 07:01:26 +00:00
#pragma once
2019-09-12 14:18:13 +00:00
#include "YBaseLib/String.h"
#include "YBaseLib/Timer.h"
#include "common/gl_program.h"
#include "common/gl_texture.h"
#include "pse/host_interface.h"
#include <SDL.h>
2019-09-09 07:01:26 +00:00
#include <array>
#include <deque>
#include <mutex>
class System;
2019-09-12 14:18:13 +00:00
class SDLInterface : public HostInterface
2019-09-09 07:01:26 +00:00
{
public:
2019-09-12 14:18:13 +00:00
SDLInterface();
2019-09-09 07:01:26 +00:00
~SDLInterface();
2019-09-12 14:18:13 +00:00
static std::unique_ptr<SDLInterface> Create();
2019-09-09 07:01:26 +00:00
2019-09-12 14:18:13 +00:00
void SetDisplayTexture(GL::Texture* texture, u32 offset_x, u32 offset_y, u32 width, u32 height) override;
2019-09-09 07:01:26 +00:00
2019-09-12 14:18:13 +00:00
void ReportMessage(const char* message) override;
2019-09-09 07:01:26 +00:00
2019-09-12 14:18:13 +00:00
// Adds OSD messages, duration is in seconds.
void AddOSDMessage(const char* message, float duration = 2.0f) override;
2019-09-09 07:01:26 +00:00
2019-09-12 14:18:13 +00:00
bool InitializeSystem(const char* filename, s32 save_state_index /* = -1 */);
2019-09-09 07:01:26 +00:00
void Run();
2019-09-12 14:18:13 +00:00
private:
2019-09-09 07:01:26 +00:00
struct OSDMessage
{
String text;
Timer time;
float duration;
};
2019-09-12 14:18:13 +00:00
bool CreateSDLWindow();
bool CreateGLContext();
bool CreateImGuiContext();
bool CreateGLResources();
2019-09-09 07:01:26 +00:00
// We only pass mouse input through if it's grabbed
bool IsWindowFullscreen() const;
void RenderImGui();
void DoLoadState(u32 index);
void DoSaveState(u32 index);
bool HandleSDLEvent(const SDL_Event* event);
bool PassEventToImGui(const SDL_Event* event);
void Render();
2019-09-12 14:18:13 +00:00
void RenderDisplay();
2019-09-09 07:01:26 +00:00
void RenderMainMenuBar();
void RenderOSDMessages();
2019-09-12 14:18:13 +00:00
SDL_Window* m_window = nullptr;
SDL_GLContext m_gl_context = nullptr;
int m_window_width = 0;
int m_window_height = 0;
2019-09-09 07:01:26 +00:00
std::unique_ptr<System> m_system;
2019-09-12 14:18:13 +00:00
GL::Program m_display_program;
GLuint m_display_vao = 0;
GL::Texture* m_display_texture = nullptr;
u32 m_display_texture_offset_x = 0;
u32 m_display_texture_offset_y = 0;
u32 m_display_texture_width = 0;
u32 m_display_texture_height = 0;
bool m_display_texture_changed = false;
2019-09-09 07:01:26 +00:00
std::deque<OSDMessage> m_osd_messages;
std::mutex m_osd_messages_lock;
bool m_running = false;
};