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
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
#include "game/kernel/kboot.h"
|
2021-08-14 16:00:50 -04:00
|
|
|
#include "game/system/newpad.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 };
|
|
|
|
|
|
|
|
// module for the different rendering pipelines
|
|
|
|
struct GfxRendererModule {
|
2021-08-13 20:06:16 -04:00
|
|
|
std::function<int(GfxSettings&)> init;
|
2021-08-09 19:16:39 -04:00
|
|
|
std::function<std::shared_ptr<GfxDisplay>(int w, int h, const char* title, GfxSettings& settings)>
|
|
|
|
make_main_display;
|
2021-08-13 20:06:16 -04:00
|
|
|
std::function<void(GfxDisplay*)> kill_display;
|
|
|
|
std::function<void(GfxDisplay*)> render_display;
|
2021-12-30 18:48:37 -05:00
|
|
|
std::function<void(GfxDisplay*, int*, int*)> display_position;
|
|
|
|
std::function<void(GfxDisplay*, int*, int*)> display_size;
|
|
|
|
std::function<void(GfxDisplay*, int, int)> display_set_size;
|
|
|
|
std::function<void(GfxDisplay*, float*, float*)> display_scale;
|
|
|
|
std::function<void(GfxDisplay*, int, int)> set_fullscreen;
|
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;
|
2021-08-09 19:16:39 -04:00
|
|
|
|
|
|
|
GfxPipeline pipeline;
|
|
|
|
const char* name;
|
|
|
|
};
|
|
|
|
|
|
|
|
// store settings related to the gfx systems
|
|
|
|
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
|
|
|
|
struct GfxGlobalSettings {
|
|
|
|
// note: this is actually the size of the display that ISN'T letterboxed
|
|
|
|
// the excess space is what will be letterboxed away.
|
|
|
|
int lbox_w;
|
|
|
|
int lbox_h;
|
|
|
|
|
|
|
|
// 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;
|
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;
|
|
|
|
// extern const std::vector<const GfxRendererModule*> renderers;
|
|
|
|
|
|
|
|
const GfxRendererModule* GetRenderer(GfxPipeline pipeline);
|
2021-12-30 18:48:37 -05:00
|
|
|
const GfxRendererModule* GetCurrentRenderer();
|
2021-08-09 19:16:39 -04:00
|
|
|
|
2021-03-09 23:51:28 -05:00
|
|
|
u32 Init();
|
2021-06-23 22:07:17 -04:00
|
|
|
void Loop(std::function<bool()> f);
|
2021-03-09 23:51:28 -05:00
|
|
|
u32 Exit();
|
|
|
|
|
2021-08-04 21:30:08 -04:00
|
|
|
u32 vsync();
|
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);
|
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);
|
|
|
|
void set_letterbox(int w, int h);
|
|
|
|
void set_fullscreen(int mode, int screen);
|
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);
|
2021-11-13 22:41:15 -05:00
|
|
|
int PadAnalogValue(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);
|
|
|
|
|
2021-03-09 23:51:28 -05:00
|
|
|
} // namespace Gfx
|