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-03-09 23:51:28 -05:00
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "game/kernel/kboot.h"
|
|
|
|
|
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 {
|
|
|
|
std::function<int()> init;
|
|
|
|
std::function<std::shared_ptr<GfxDisplay>(int w, int h, const char* title, GfxSettings& settings)>
|
|
|
|
make_main_display;
|
|
|
|
std::function<void(GfxDisplay* display)> kill_display;
|
|
|
|
std::function<void(GfxDisplay* display)> render_display;
|
|
|
|
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;
|
|
|
|
std::function<void(u32, u32)> texture_relocate;
|
2021-08-09 19:16:39 -04:00
|
|
|
|
|
|
|
GfxPipeline pipeline;
|
|
|
|
const char* name;
|
|
|
|
};
|
|
|
|
|
|
|
|
// store settings related to the gfx systems
|
|
|
|
struct GfxSettings {
|
|
|
|
const GfxRendererModule* renderer; // which rendering pipeline to use.
|
|
|
|
|
|
|
|
int vsync; // (temp) number of screen update per frame
|
|
|
|
};
|
|
|
|
|
|
|
|
// struct for a single vertex. this should in theory be renderer-agnostic
|
|
|
|
struct GfxVertex {
|
|
|
|
// x y z
|
|
|
|
float x, y, z;
|
|
|
|
|
|
|
|
// rgba or the full u32 thing.
|
|
|
|
union {
|
|
|
|
u32 rgba;
|
|
|
|
struct {
|
|
|
|
u8 r, g, b, a;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-03-09 23:51:28 -05:00
|
|
|
namespace Gfx {
|
|
|
|
|
2021-08-09 19:16:39 -04:00
|
|
|
static constexpr int VERTEX_BUFFER_LENGTH_TEMP = 4096;
|
|
|
|
extern GfxVertex g_vertices_temp[VERTEX_BUFFER_LENGTH_TEMP];
|
|
|
|
|
|
|
|
extern GfxSettings g_settings;
|
|
|
|
// extern const std::vector<const GfxRendererModule*> renderers;
|
|
|
|
|
|
|
|
const GfxRendererModule* GetRenderer(GfxPipeline pipeline);
|
|
|
|
|
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-08 20:46:14 -04:00
|
|
|
void texture_relocate(u32 destination, u32 source);
|
2021-08-04 21:30:08 -04:00
|
|
|
|
2021-03-09 23:51:28 -05:00
|
|
|
} // namespace Gfx
|