2021-03-09 23:51:28 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @file gfx.h
|
2021-08-09 19:16:39 -04:00
|
|
|
* Graphics component for the runtime. Abstraction layer for the main graphics routines.
|
2021-03-09 23:51:28 -05:00
|
|
|
*/
|
|
|
|
|
2022-06-22 23:37:46 -04:00
|
|
|
#include <array>
|
2021-06-23 22:07:17 -04:00
|
|
|
#include <functional>
|
2021-08-09 19:16:39 -04:00
|
|
|
#include <memory>
|
2021-08-14 16:00:50 -04:00
|
|
|
|
2021-03-09 23:51:28 -05:00
|
|
|
#include "common/common_types.h"
|
2023-01-02 09:45:38 -05:00
|
|
|
#include "common/util/FileUtil.h"
|
2022-06-30 21:11:58 -04:00
|
|
|
#include "common/versions.h"
|
2022-06-22 23:37:46 -04:00
|
|
|
|
2022-06-26 18:17:11 -04:00
|
|
|
#include "game/kernel/common/kboot.h"
|
2021-08-14 16:00:50 -04:00
|
|
|
#include "game/system/newpad.h"
|
2023-01-02 09:45:38 -05:00
|
|
|
#include "game/tools/filter_menu/filter_menu.h"
|
2021-03-09 23:51:28 -05:00
|
|
|
|
2021-08-09 19:16:39 -04:00
|
|
|
// forward declarations
|
|
|
|
struct GfxSettings;
|
|
|
|
class GfxDisplay;
|
|
|
|
|
|
|
|
// enum for rendering pipeline
|
|
|
|
enum class GfxPipeline { Invalid = 0, OpenGL };
|
2022-08-21 18:13:27 -04:00
|
|
|
enum GfxDisplayMode { ForceUpdate = -1, Windowed = 0, Fullscreen = 1, Borderless = 2 };
|
2021-08-09 19:16:39 -04:00
|
|
|
|
|
|
|
// module for the different rendering pipelines
|
|
|
|
struct GfxRendererModule {
|
2021-08-13 20:06:16 -04:00
|
|
|
std::function<int(GfxSettings&)> init;
|
2022-06-30 21:11:58 -04:00
|
|
|
std::function<std::shared_ptr<GfxDisplay>(int width,
|
|
|
|
int height,
|
|
|
|
const char* title,
|
|
|
|
GfxSettings& settings,
|
|
|
|
GameVersion version,
|
|
|
|
bool is_main)>
|
2022-06-16 22:46:12 -04:00
|
|
|
make_display;
|
2021-08-09 19:16:39 -04:00
|
|
|
std::function<void()> exit;
|
2021-08-09 21:42:05 -04:00
|
|
|
std::function<u32()> vsync;
|
2021-08-10 21:31:15 -04:00
|
|
|
std::function<u32()> sync_path;
|
2021-08-09 21:42:05 -04:00
|
|
|
std::function<void(const void*, u32)> send_chain;
|
|
|
|
std::function<void(const u8*, int, u32)> texture_upload_now;
|
2021-08-11 19:36:15 -04:00
|
|
|
std::function<void(u32, u32, u32)> texture_relocate;
|
2021-08-15 22:50:36 -04:00
|
|
|
std::function<void()> poll_events;
|
2022-03-02 20:01:37 -05:00
|
|
|
std::function<void(const std::vector<std::string>&)> set_levels;
|
2022-03-26 15:53:44 -04:00
|
|
|
std::function<void(float)> set_pmode_alp;
|
2021-08-09 19:16:39 -04:00
|
|
|
GfxPipeline pipeline;
|
|
|
|
const char* name;
|
|
|
|
};
|
|
|
|
|
|
|
|
// store settings related to the gfx systems
|
2022-06-16 22:46:12 -04:00
|
|
|
// TODO merge with globalsettings
|
2021-08-09 19:16:39 -04:00
|
|
|
struct GfxSettings {
|
2021-08-13 20:06:16 -04:00
|
|
|
// current version of the settings. this should be set up so that newer versions are always higher
|
|
|
|
// than older versions
|
2021-08-16 10:43:12 -04:00
|
|
|
// increment this whenever you change this struct.
|
|
|
|
// there's probably a smarter way to do this (automatically deduce size etc.)
|
|
|
|
static constexpr u64 CURRENT_VERSION = 0x0000'0000'0004'0001;
|
2021-08-16 02:44:05 -04:00
|
|
|
|
2021-08-16 10:43:12 -04:00
|
|
|
u64 version; // the version of this settings struct. MUST ALWAYS BE THE FIRST THING!
|
2021-08-14 16:00:50 -04:00
|
|
|
|
2021-08-14 16:05:38 -04:00
|
|
|
Pad::MappingInfo pad_mapping_info; // button mapping
|
|
|
|
Pad::MappingInfo pad_mapping_info_backup; // button mapping backup (see newpad.h)
|
2021-08-16 10:43:12 -04:00
|
|
|
|
|
|
|
int vsync; // (temp) number of screen update per frame
|
|
|
|
bool debug; // graphics debugging
|
|
|
|
|
2021-12-30 18:48:37 -05:00
|
|
|
GfxPipeline renderer = GfxPipeline::Invalid; // which rendering pipeline to use.
|
|
|
|
};
|
|
|
|
|
|
|
|
// runtime settings
|
2022-04-30 14:48:24 -04:00
|
|
|
static constexpr int PAT_MOD_COUNT = 3;
|
|
|
|
static constexpr int PAT_EVT_COUNT = 7;
|
|
|
|
static constexpr int PAT_MAT_COUNT = 23;
|
2021-12-30 18:48:37 -05:00
|
|
|
struct GfxGlobalSettings {
|
|
|
|
// note: this is actually the size of the display that ISN'T letterboxed
|
|
|
|
// the excess space is what will be letterboxed away.
|
2022-07-15 18:59:13 -04:00
|
|
|
int lbox_w = 640;
|
|
|
|
int lbox_h = 480;
|
2021-12-30 18:48:37 -05:00
|
|
|
|
2022-07-14 21:37:03 -04:00
|
|
|
// actual game resolution
|
|
|
|
int game_res_w = 640;
|
|
|
|
int game_res_h = 480;
|
|
|
|
|
|
|
|
// multi-sampled anti-aliasing sample count. 1 = disabled.
|
|
|
|
int msaa_samples = 4;
|
|
|
|
|
2021-12-30 18:48:37 -05:00
|
|
|
// current renderer
|
|
|
|
const GfxRendererModule* renderer;
|
2022-02-15 18:42:48 -05:00
|
|
|
|
|
|
|
// lod settings, used by bucket renderers
|
|
|
|
int lod_tfrag = 0;
|
|
|
|
int lod_tie = 0;
|
2022-04-30 14:48:24 -04:00
|
|
|
|
2022-06-25 11:05:20 -04:00
|
|
|
// vsync enable
|
|
|
|
bool vsync = true;
|
|
|
|
bool old_vsync = false;
|
|
|
|
// target frame rate
|
|
|
|
float target_fps = 60;
|
|
|
|
// use custom frame limiter
|
|
|
|
bool framelimiter = true;
|
|
|
|
|
2022-08-20 10:30:37 -04:00
|
|
|
// frame timing things
|
2022-06-25 11:05:20 -04:00
|
|
|
bool experimental_accurate_lag = false;
|
|
|
|
bool sleep_in_frame_limiter = true;
|
|
|
|
|
2022-08-20 10:30:37 -04:00
|
|
|
// fancy effect things
|
|
|
|
bool hack_no_tex = false;
|
|
|
|
|
|
|
|
// collision renderer settings
|
|
|
|
bool collision_enable = false;
|
|
|
|
bool collision_wireframe = true;
|
|
|
|
|
2022-04-30 14:48:24 -04:00
|
|
|
// matching enum in kernel-defs.gc !!
|
|
|
|
enum CollisionRendererMode { None, Mode, Event, Material, Skip } collision_mode = Mode;
|
|
|
|
std::array<u32, (PAT_MOD_COUNT + 31) / 32> collision_mode_mask = {UINT32_MAX};
|
|
|
|
std::array<u32, (PAT_EVT_COUNT + 31) / 32> collision_event_mask = {UINT32_MAX};
|
|
|
|
std::array<u32, (PAT_MAT_COUNT + 31) / 32> collision_material_mask = {UINT32_MAX};
|
|
|
|
u32 collision_skip_mask = UINT32_MAX;
|
2021-08-09 19:16:39 -04:00
|
|
|
};
|
|
|
|
|
2021-03-09 23:51:28 -05:00
|
|
|
namespace Gfx {
|
|
|
|
|
2021-12-30 18:48:37 -05:00
|
|
|
extern GfxGlobalSettings g_global_settings;
|
2021-08-09 19:16:39 -04:00
|
|
|
extern GfxSettings g_settings;
|
|
|
|
|
2023-01-02 09:45:38 -05:00
|
|
|
struct DebugSettings {
|
|
|
|
bool show_imgui = false;
|
|
|
|
bool ignore_imgui_hide_keybind = false;
|
|
|
|
std::vector<DebugTextFilter> debug_text_filters = {};
|
|
|
|
bool debug_text_check_range = false;
|
|
|
|
float debug_text_max_range = 0;
|
|
|
|
|
|
|
|
void load_settings(const ghc::filesystem::path& filepath);
|
|
|
|
void save_settings();
|
|
|
|
};
|
|
|
|
|
|
|
|
extern DebugSettings g_debug_settings;
|
|
|
|
|
2021-12-30 18:48:37 -05:00
|
|
|
const GfxRendererModule* GetCurrentRenderer();
|
2021-08-09 19:16:39 -04:00
|
|
|
|
2022-06-30 21:11:58 -04:00
|
|
|
u32 Init(GameVersion version);
|
2021-06-23 22:07:17 -04:00
|
|
|
void Loop(std::function<bool()> f);
|
2021-03-09 23:51:28 -05:00
|
|
|
u32 Exit();
|
|
|
|
|
2022-08-19 11:28:06 -04:00
|
|
|
Pad::MappingInfo& get_button_mapping();
|
|
|
|
|
2021-08-04 21:30:08 -04:00
|
|
|
u32 vsync();
|
2022-08-14 17:21:02 -04:00
|
|
|
void register_vsync_callback(std::function<void()> f);
|
|
|
|
void clear_vsync_callback();
|
2021-08-10 21:31:15 -04:00
|
|
|
u32 sync_path();
|
2021-08-06 22:30:02 -04:00
|
|
|
void send_chain(const void* data, u32 offset);
|
2021-08-08 13:12:44 -04:00
|
|
|
void texture_upload_now(const u8* tpage, int mode, u32 s7_ptr);
|
2021-08-11 19:36:15 -04:00
|
|
|
void texture_relocate(u32 destination, u32 source, u32 format);
|
2022-03-02 20:01:37 -05:00
|
|
|
void set_levels(const std::vector<std::string>& levels);
|
2021-08-15 22:50:36 -04:00
|
|
|
void poll_events();
|
2021-12-30 18:48:37 -05:00
|
|
|
u64 get_window_width();
|
|
|
|
u64 get_window_height();
|
|
|
|
void set_window_size(u64 w, u64 h);
|
|
|
|
void get_window_scale(float* x, float* y);
|
2022-11-19 23:28:20 -05:00
|
|
|
std::tuple<double, double> get_mouse_pos();
|
2022-06-16 22:46:12 -04:00
|
|
|
GfxDisplayMode get_fullscreen();
|
2022-06-25 11:05:20 -04:00
|
|
|
int get_screen_vmode_count();
|
|
|
|
int get_screen_rate(s64 vmode_idx);
|
2022-07-31 13:31:17 -04:00
|
|
|
int get_monitor_count();
|
2022-06-25 11:05:20 -04:00
|
|
|
void get_screen_size(s64 vmode_idx, s32* w, s32* h);
|
|
|
|
void set_frame_rate(int rate);
|
|
|
|
void set_vsync(bool vsync);
|
2021-12-30 18:48:37 -05:00
|
|
|
void set_letterbox(int w, int h);
|
2022-06-16 22:46:12 -04:00
|
|
|
void set_fullscreen(GfxDisplayMode mode, int screen);
|
2022-06-21 19:21:51 -04:00
|
|
|
void set_window_lock(bool lock);
|
2022-07-14 21:37:03 -04:00
|
|
|
void set_game_resolution(int w, int h);
|
|
|
|
void set_msaa(int samples);
|
2021-08-16 02:44:05 -04:00
|
|
|
void input_mode_set(u32 enable);
|
2021-08-16 09:57:15 -04:00
|
|
|
void input_mode_save();
|
|
|
|
s64 get_mapped_button(s64 pad, s64 button);
|
2021-08-04 21:30:08 -04:00
|
|
|
|
2021-08-14 16:00:50 -04:00
|
|
|
int PadIsPressed(Pad::Button button, int port);
|
2022-08-19 11:28:06 -04:00
|
|
|
int PadGetAnalogValue(Pad::Analog analog, int port);
|
2021-08-14 16:00:50 -04:00
|
|
|
|
2022-02-15 18:42:48 -05:00
|
|
|
// matching enum in kernel-defs.gc !!
|
|
|
|
enum class RendererTreeType { NONE = 0, TFRAG3 = 1, TIE3 = 2, INVALID };
|
|
|
|
void SetLod(RendererTreeType tree, int lod);
|
2022-04-30 14:48:24 -04:00
|
|
|
bool CollisionRendererGetMask(GfxGlobalSettings::CollisionRendererMode mode, int mask_id);
|
|
|
|
void CollisionRendererSetMask(GfxGlobalSettings::CollisionRendererMode mode, int mask_id);
|
|
|
|
void CollisionRendererClearMask(GfxGlobalSettings::CollisionRendererMode mode, int mask_id);
|
|
|
|
void CollisionRendererSetMode(GfxGlobalSettings::CollisionRendererMode mode);
|
2022-02-15 18:42:48 -05:00
|
|
|
|
2021-03-09 23:51:28 -05:00
|
|
|
} // namespace Gfx
|