libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Fast3dGui.h
Go to the documentation of this file.
1#pragma once
2#include <SDL2/SDL.h>
4#include "fast/WindowEvent.h"
7
8namespace Ship {
9class Window;
10class ConsoleVariable;
11class ResourceManager;
12} // namespace Ship
13
14// Fixes issue #926: HandleWindowEvents is only ever called from Fast3D backend code
15// (gfx_sdl2.cpp, gfx_dxgi.cpp) and must not be a virtual method on Ship::Gui.
16// The WindowEvent type has been moved to the Fast namespace so that ship code does
17// not depend on any Fast3D or platform-specific types.
18
19namespace Fast {
20class Interpreter;
21
31typedef struct {
32 union {
33 struct {
34 void* Window;
36 void* Device;
37 } Dx11;
38 struct {
39 void* Window;
40 void* Context;
41 } Opengl;
42 struct {
43 void* Window;
44 SDL_Renderer* Renderer;
45 } Metal;
46 struct {
47 uint32_t Width;
48 uint32_t Height;
49 } Gx2;
50 };
51} GuiWindowInitData;
52
63class Fast3dGui : public Ship::Gui {
64 public:
66 Fast3dGui(std::vector<std::shared_ptr<Ship::GuiWindow>> guiWindows);
67 ~Fast3dGui() override = default;
68
69 bool SupportsViewports() override;
70
75 void Init(GuiWindowInitData windowImpl);
76
85
92 void LoadGuiTexture(const std::string& name, const std::string& path, const ImVec4& tint);
93
98 bool HasTextureByName(const std::string& name);
99
106 void LoadGuiTexture(const std::string& name, const Fast::Texture& tex, const ImVec4& tint);
107
112 void UnloadTexture(const std::string& name);
113
119 ImTextureID GetTextureByName(const std::string& name);
120
126 ImVec2 GetTextureSize(const std::string& name);
127
133 void LoadTextureFromRawImage(const std::string& name, const std::string& path);
134
140 void LoadTextureFromResource(const std::string& name, std::shared_ptr<Ship::GuiTexture> texture);
141
142 void RefreshImGuiGamepads() override;
143
144 protected:
145 void ImGuiWMInit() override;
146 void ImGuiWMShutdown() override;
147 void ImGuiBackendInit() override;
148 void ImGuiBackendShutdown() override;
149 void ImGuiBackendNewFrame() override;
150 void ImGuiWMNewFrame() override;
151 void ImGuiRenderDrawData(ImDrawData* data) override;
152 void DrawFloatingWindows() override;
153 void CalculateGameViewport() override;
154 void DrawGame() override;
155
161 ImTextureID GetTextureById(int32_t id);
162
163 std::weak_ptr<Interpreter> mInterpreter;
165 std::shared_ptr<Ship::Window> mWindow;
166 std::shared_ptr<Ship::ConsoleVariable>
168 std::shared_ptr<Ship::ResourceManager>
170
171 private:
173 void ApplyResolutionChanges();
174
179 int16_t GetIntegerScaleFactor();
180
181 std::unordered_map<std::string, Ship::GuiTextureMetadata> mGuiTextures;
182};
183} // namespace Fast
Concrete Gui subclass for the Fast3D rendering backend.
Definition Fast3dGui.h:63
void Init(GuiWindowInitData windowImpl)
Initialises the ImGui context with the given backend-specific handles.
void UnloadTexture(const std::string &name)
Removes the texture with the given name from the cache and frees GPU resources.
void DrawGame() override
Renders the game viewport inside the main docking space. The base implementation is a no-op....
void ImGuiBackendInit() override
Initialises the renderer ImGui backend (DX11 / OpenGL / Metal). The base implementation is a no-op.
void LoadGuiTexture(const std::string &name, const Fast::Texture &tex, const ImVec4 &tint)
Uploads a Fast::Texture object to the GPU and caches it under name.
GuiWindowInitData mImpl
Backend-specific window/context handles passed to Init().
Definition Fast3dGui.h:164
void DrawFloatingWindows() override
Draws all registered floating GuiWindow instances. The base implementation is a no-op....
void CalculateGameViewport() override
Recalculates the game viewport rect to account for the menu bar and window size. The base implementat...
void ImGuiBackendShutdown() override
Shuts down the renderer ImGui backend. The base implementation is a no-op.
void LoadTextureFromResource(const std::string &name, std::shared_ptr< Ship::GuiTexture > texture)
Uploads a pre-loaded GuiTexture resource to the GPU and caches it.
void ImGuiBackendNewFrame() override
Calls the appropriate ImGui backend New Frame function (DX11 / GL / Metal). The base implementation i...
~Fast3dGui() override=default
void ImGuiWMShutdown() override
Shuts down the platform/window-manager ImGui backend. The base implementation is a no-op.
void LoadGuiTexture(const std::string &name, const std::string &path, const ImVec4 &tint)
Loads an image from an archive path and caches it under the given name.
bool SupportsViewports() override
Returns true if the ImGui multi-viewport / docking feature is supported by the current backend.
Fast3dGui(std::vector< std::shared_ptr< Ship::GuiWindow > > guiWindows)
std::shared_ptr< Ship::ResourceManager > mResourceManager
Cached ResourceManager component.
Definition Fast3dGui.h:169
std::weak_ptr< Interpreter > mInterpreter
Weak reference to the Fast3D scripting interpreter.
Definition Fast3dGui.h:163
ImVec2 GetTextureSize(const std::string &name)
Returns the pixel dimensions of the cached texture.
void ImGuiRenderDrawData(ImDrawData *data) override
Submits the ImGui draw data to the active graphics backend. The base implementation is a no-op.
std::shared_ptr< Ship::Window > mWindow
Cached Window component.
Definition Fast3dGui.h:165
void HandleWindowEvents(Fast::WindowEvent event)
Forwards a platform window event to the active ImGui backend.
ImTextureID GetTextureByName(const std::string &name)
Returns the ImGui texture handle for the given cache key.
void ImGuiWMNewFrame() override
Calls ImGui_ImplSDL2_NewFrame() or the platform equivalent. The base implementation is a no-op.
ImTextureID GetTextureById(int32_t id)
Returns the ImTextureID for a texture identified by its integer ID.
std::shared_ptr< Ship::ConsoleVariable > mConsoleVariables
Cached ConsoleVariable component.
Definition Fast3dGui.h:167
void ImGuiWMInit() override
Initialises the platform/window-manager ImGui backend. The base implementation is a no-op.
void RefreshImGuiGamepads() override
Re-binds the ImGui platform backend's gamepad list to the currently connected controllers....
void LoadTextureFromRawImage(const std::string &name, const std::string &path)
Loads a raw image file from the filesystem (not the archive) and caches it.
bool HasTextureByName(const std::string &name)
Returns true if a texture with the given name is already cached.
Definition Texture.h:24
Owns and drives the ImGui context, all registered GuiWindows, and texture management.
Definition Gui.h:40
Definition gfx_direct3d_common.h:19
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
Backend-specific data required to initialise the ImGui rendering context.
Definition Fast3dGui.h:31
SDL_Renderer * Renderer
SDL_Renderer* (for Metal layer)
Definition Fast3dGui.h:44
uint32_t Width
Framebuffer width in pixels.
Definition Fast3dGui.h:47
void * Device
ID3D11Device*.
Definition Fast3dGui.h:36
void * Window
HWND.
Definition Fast3dGui.h:34
uint32_t Height
Framebuffer height in pixels.
Definition Fast3dGui.h:48
void * Context
SDL_GLContext.
Definition Fast3dGui.h:40
void * DeviceContext
ID3D11DeviceContext*.
Definition Fast3dGui.h:35
Platform-agnostic wrapper around a window system event.
Definition WindowEvent.h:17