Polyphase Game Engine
Loading...
Searching...
No Matches
GamePreview.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include <cstdint>
6#include <string>
7#include <vector>
8#include "imgui.h"
9#include "EngineTypes.h"
10
11class Image;
12class Buffer;
13class Camera3D;
14
15struct ResolutionPreset
16{
17 std::string mName;
18 uint32_t mWidth;
19 uint32_t mHeight;
20};
21
22class GamePreview
23{
24public:
25 void Enable();
26 void Disable();
27 void Render();
28 void DrawPanel();
29
30 bool IsEnabled() const { return mEnabled; }
31 uint32_t GetCurrentWidth() const { return mCurrentWidth; }
32 uint32_t GetCurrentHeight() const { return mCurrentHeight; }
33
34 // Capture the current color target into RGBA bytes (no disk write).
35 // Returns false if the preview is not currently rendered (no color target).
36 // Must be called from the main thread.
37 bool CaptureScreenshotToMemory(std::vector<uint8_t>& outRgba,
38 uint32_t& outWidth,
39 uint32_t& outHeight);
40
41 void BeginInputRemap();
42 void EndInputRemap();
43
44 // Hook support for addon resolution presets
45 void AddResolutionPreset(const std::string& name, uint32_t w, uint32_t h);
46 void RemoveResolutionPreset(const std::string& name);
47 const std::vector<ResolutionPreset>& GetAddonPresets() const { return mAddonPresets; }
48
49 // Returns the canonical preview resolution for a target platform.
50 // Used by Game Preview's "Target Platform" preset and the Canvas inspector's
51 // "Set Size To Build Profile Resolution" button.
52 static void GetPlatformResolution(Platform platform, uint32_t& outWidth, uint32_t& outHeight, const char*& outName);
53
54private:
55 bool mEnabled = true;
56 int32_t mSelectedPresetIndex = 0;
57 int32_t mSelectedCameraIndex = 0;
58 bool mShowGizmos = false;
59
60 // Render targets (recreated on resolution change)
61 Image* mColorTarget = nullptr;
62 Image* mDepthTarget = nullptr;
63 ImTextureID mImGuiTexId = 0;
64 uint32_t mCurrentWidth = 0;
65 uint32_t mCurrentHeight = 0;
66
67 // Screenshot
68 bool mScreenshotRequested = false;
69
70 // Built-in presets
71 static const std::vector<ResolutionPreset> sBuiltInPresets;
72
73 // Addon presets (populated by hooks)
74 std::vector<ResolutionPreset> mAddonPresets;
75
76 // Custom user presets (persisted to editor preferences)
77 std::vector<ResolutionPreset> mCustomPresets;
78 bool mCustomPresetsLoaded = false;
79
80 // UI state for add-preset popup
81 char mNewPresetName[128] = {};
82 int32_t mNewPresetWidth = 1280;
83 int32_t mNewPresetHeight = 720;
84
85 // Cached camera list
86 std::vector<Camera3D*> mCachedCameras;
87
88 // Image display rect in window coords (captured by DrawPanel, used next frame)
89 ImVec2 mImageMin = {0, 0};
90 ImVec2 mImageMax = {0, 0};
91
92 // Saved state for input remap
93 int32_t mSavedMouseX = 0;
94 int32_t mSavedMouseY = 0;
95 uint32_t mSavedVpX = 0;
96 uint32_t mSavedVpY = 0;
97 uint32_t mSavedVpW = 0;
98 uint32_t mSavedVpH = 0;
99 bool mInputRemapActive = false;
100
101 void CreateRenderTargets(uint32_t w, uint32_t h);
102 void DestroyRenderTargets();
103 void RefreshCameraList();
104 void CaptureScreenshot();
105 void LoadCustomPresets();
106 void SaveCustomPresets();
107 ResolutionPreset GetCurrentPreset();
108 std::vector<ResolutionPreset> GetAllPresets();
109};
110
111GamePreview* GetGamePreview();
112
113#endif
Platform
Definition EngineTypes.h:31
Definition Camera3d.h:12
void Enable(bool enable)
Definition ImGuizmo.cpp:1055