N64ModernRuntime/ultramodern/include/ultramodern/renderer_context.hpp
Manuel Alfayate Corchete cea072b59b
Some checks failed
validate / ubuntu (arm64, Debug) (push) Has been cancelled
validate / ubuntu (arm64, Release) (push) Has been cancelled
validate / ubuntu (x64, Debug) (push) Has been cancelled
validate / ubuntu (x64, Release) (push) Has been cancelled
validate / windows (x64, Debug) (push) Has been cancelled
validate / windows (x64, Release) (push) Has been cancelled
validate / macos (arm64, Debug) (push) Has been cancelled
validate / macos (arm64, Release) (push) Has been cancelled
validate / macos (x64, Debug) (push) Has been cancelled
validate / macos (x64, Release) (push) Has been cancelled
Remove unnecessary x11 header include. (#122)
2025-07-24 15:00:45 -04:00

105 lines
3.2 KiB
C++

#ifndef __RENDERER_WRAPPER_HPP__
#define __RENDERER_WRAPPER_HPP__
#include <cstdint>
#include <memory>
#include <optional>
#include <span>
#if defined(_WIN32)
# define WIN32_LEAN_AND_MEAN
# include <Windows.h>
#elif defined(__ANDROID__)
# include "android/native_window.h"
#elif defined(__linux__)
# undef None
# undef Status
# undef LockMask
# undef Always
# undef Success
# undef False
# undef True
#endif
#include "ultra64.h"
#include "config.hpp"
struct SDL_Window;
namespace ultramodern {
namespace renderer {
#if defined(_WIN32)
// Native HWND handle to the target window.
struct WindowHandle {
HWND window;
DWORD thread_id = (DWORD)-1;
auto operator<=>(const WindowHandle&) const = default;
};
// TODO add a native window handle option here (Display/Window for x11 and ANativeWindow for Android) as a compile-time option.
#elif defined(__linux__) || defined(__ANDROID__)
using WindowHandle = SDL_Window*;
#elif defined(__APPLE__)
struct WindowHandle {
void* window;
void* view;
auto operator<=>(const WindowHandle&) const = default;
};
#endif
enum class SetupResult {
Success,
DynamicLibrariesNotFound,
InvalidGraphicsAPI,
GraphicsAPINotFound,
GraphicsDeviceNotFound
};
class RendererContext {
public:
virtual ~RendererContext() = default;
virtual bool valid() = 0;
virtual SetupResult get_setup_result() const { return setup_result; }
virtual GraphicsApi get_chosen_api() const { return chosen_api; }
virtual bool update_config(const GraphicsConfig& old_config, const GraphicsConfig& new_config) = 0;
virtual void enable_instant_present() = 0;
virtual void send_dl(const OSTask* task) = 0;
virtual void update_screen(uint32_t vi_origin) = 0;
virtual void shutdown() = 0;
virtual uint32_t get_display_framerate() const = 0;
virtual float get_resolution_scale() const = 0;
protected:
SetupResult setup_result;
GraphicsApi chosen_api;
};
struct callbacks_t {
using create_render_context_t = std::unique_ptr<RendererContext>(uint8_t* rdram, WindowHandle window_handle, bool developer_mode);
using get_graphics_api_name_t = std::string(GraphicsApi api);
/**
* Instances a subclass of RendererContext that is used to render the game.
*
* This callback is mandatory for using the library.
*/
create_render_context_t *create_render_context;
/**
* This callback is optional. If not provided a library default will be used.
*/
get_graphics_api_name_t *get_graphics_api_name = nullptr;
};
void set_callbacks(const callbacks_t& callbacks);
std::unique_ptr<RendererContext> create_render_context(uint8_t* rdram, WindowHandle window_handle, bool developer_mode);
std::string get_graphics_api_name(GraphicsApi api);
}
}
#endif