CommonLibVR
Renderer.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "RE/N/NiTexture.h"
7 
8 #include "REX/W32/D3D11_3.h"
9 #include "REX/W32/USER32.h"
10 
11 namespace RE
12 {
13  namespace BSGraphics
14  {
16  {
18  std::int32_t windowX; // 08
19  std::int32_t windowY; // 0C
20  std::int32_t windowWidth; // 10
21  std::int32_t windowHeight; // 14
22  REX::W32::IDXGISwapChain* swapChain; // 18
24  std::uint32_t unk24; // 24
25  std::uint64_t unk28; // 28
26  REX::W32::ID3D11RenderTargetView1* renderView; // 30
27  REX::W32::ID3D11ShaderResourceView1* resourceView; // 38
28  std::uint64_t unk40; // 40
29  std::uint64_t unk48; // 48
30  };
31  static_assert(sizeof(RendererWindow) == 0x50);
32 
33  struct RendererData
34  {
35  public:
36  // members
37  std::uint32_t uiAdapter; // 0000
42  std::uint32_t isNotWindowed; // 001C
43  bool fullScreen; // 0020
44  bool borderlessDisplay; // 0021
45  bool readOnlyDepth; // 0022
46  bool instantiated; // 0023
48  std::uint32_t newWidth; // 0028
49  std::uint32_t newHeight; // 002C
50  std::uint32_t presentInterval; // 0030
51  REX::W32::ID3D11Device* forwarder; // 0038
52  REX::W32::ID3D11DeviceContext* context; // 0040
54 #ifndef SKYRIMVR
55  RenderTargetData renderTargets[RENDER_TARGET::kTOTAL]; // 0A48
56  DepthStencilData depthStencils[RENDER_TARGET_DEPTHSTENCIL::kTOTAL]; // 1FA8
57 #else
58  RenderTargetData renderTargets[RENDER_TARGET::kVRTOTAL]; // 0A48
59  DepthStencilData depthStencils[RENDER_TARGET_DEPTHSTENCIL::kVRTOTAL]; // 1FA8, VR 0x21B8
60 #endif
61  CubemapRenderTargetData cubemapRenderTargets[RENDER_TARGET_CUBEMAP::kTOTAL]; // 26C8, VR 0x2E48
62  Texture3DTargetData texture3DRenderTargets[RENDER_TARGET_3D::kTOTAL]; // 2708
63  float clearColor[4]; // 2768
64  std::uint8_t clearStencil; // 2778
65  REX::W32::CRITICAL_SECTION lock; // 2780, VR 0x2F00
66  const char* className; // 27A8
68  };
69 #ifndef SKYRIMVR
70  static_assert(offsetof(RendererData, renderWindows) == 0x48);
71  static_assert(offsetof(RendererData, lock) == 0x2780);
72 #else
73  static_assert(offsetof(RendererData, renderWindows) == 0x48);
74  static_assert(offsetof(RendererData, renderTargets) == 0xA48);
75  static_assert(offsetof(RendererData, depthStencils) == 0x21B8);
76  static_assert(offsetof(RendererData, cubemapRenderTargets) == 0x2E30);
77  static_assert(offsetof(RendererData, lock) == 0x2EE8);
78 #endif
79 
81  {
86  const char* className; // 20
87  std::uint32_t adapter; // 28
88  std::uint32_t unk2C; // 2C
89  };
90  static_assert(sizeof(RendererInitOSData) == 0x30);
91 
92  struct ScreenSize
93  {
94  std::uint32_t width; // 00
95  std::uint32_t height; // 04
96  };
97  static_assert(sizeof(ScreenSize) == 0x8);
98 
100  {
102  int windowX; // 08
103  int windowY; // 0C
104  int refreshRate; // 10
105  int presentInterval; // 14
106  bool appFullScreen; // 18
107  bool borderlessWindow; // 19
108  bool vsync; // 1A
109  };
110  static_assert(sizeof(ApplicationWindowProperties) == 0x1C);
111 
112  class Renderer
113  {
114  public:
115  [[nodiscard]] static Renderer* GetSingleton() noexcept;
116 
117  void CreateSwapChain(REX::W32::HWND* a_window, bool a_setCurrent);
118  void KillWindow(std::uint32_t a_windowID);
119  void Lock();
120  void Unlock();
121  void ResizeWindow(std::uint32_t a_windowID, std::uint32_t a_width, std::uint32_t a_height, bool a_fullscreen, bool a_borderless);
122  void RequestWindowResize(std::uint32_t a_width, std::uint32_t a_height);
123  void SetWindowPosition(std::uint32_t a_windowID, std::int32_t a_x, std::int32_t a_y);
124  void SetWindowActiveState(bool a_show);
125  void WindowSizeChanged(std::uint32_t a_windowID);
126  void ResetWindow(std::uint32_t a_windowID);
127  void UpdateViewPort(std::uint32_t a_unk1, std::uint32_t a_unk2, bool a_unk3);
128 
129  [[nodiscard]] NiTexture::RendererData* CreateRenderTexture(std::uint32_t a_width, std::uint32_t a_height);
130  void SaveRenderTargetToFile(RENDER_TARGET a_renderTarget, const char* a_filePath, TextureFileFormat a_textureFileFormat);
131 
132  [[nodiscard]] static RendererData* GetRendererData();
133  [[nodiscard]] static ScreenSize GetScreenSize();
134  [[nodiscard]] static REX::W32::ID3D11Device* GetDevice();
135  [[nodiscard]] static RendererWindow* GetCurrentRenderWindow();
136 
137  // members
138  std::uint64_t unk00; // 00
139  std::uint64_t unk08; // 08
140 #ifdef SKYRIMVR
141  std::uint64_t unk010; // 0010
142 #endif
143  RendererData data; // 10, VR 18
144  private:
145  void Begin(std::uint32_t windowID);
146  void Init(RendererInitOSData* a_data, ApplicationWindowProperties* a_windowProps, REX::W32::HWND a_window);
147  void End();
148  void Shutdown();
149  };
150  }
151 }
Definition: Renderer.h:113
void RequestWindowResize(std::uint32_t a_width, std::uint32_t a_height)
static REX::W32::ID3D11Device * GetDevice()
void SetWindowPosition(std::uint32_t a_windowID, std::int32_t a_x, std::int32_t a_y)
std::uint64_t unk08
Definition: Renderer.h:139
static RendererData * GetRendererData()
static Renderer * GetSingleton() noexcept
static RendererWindow * GetCurrentRenderWindow()
void UpdateViewPort(std::uint32_t a_unk1, std::uint32_t a_unk2, bool a_unk3)
void SetWindowActiveState(bool a_show)
std::uint64_t unk00
Definition: Renderer.h:138
void KillWindow(std::uint32_t a_windowID)
void WindowSizeChanged(std::uint32_t a_windowID)
void CreateSwapChain(REX::W32::HWND *a_window, bool a_setCurrent)
RendererData data
Definition: Renderer.h:143
static ScreenSize GetScreenSize()
void SaveRenderTargetToFile(RENDER_TARGET a_renderTarget, const char *a_filePath, TextureFileFormat a_textureFileFormat)
void ResizeWindow(std::uint32_t a_windowID, std::uint32_t a_width, std::uint32_t a_height, bool a_fullscreen, bool a_borderless)
void ResetWindow(std::uint32_t a_windowID)
NiTexture::RendererData * CreateRenderTexture(std::uint32_t a_width, std::uint32_t a_height)
Definition: NiTexture.h:15
DXGI_MODE_SCALING
Definition: DXGI.h:201
DXGI_MODE_SCANLINE_ORDER
Definition: DXGI.h:208
std::intptr_t(*)(HWND, std::uint32_t, std::uintptr_t, std::intptr_t) WNDPROC
Definition: USER32.h:279
struct HICON__ * HICON
Definition: BASE.h:20
struct HWND__ * HWND
Definition: BASE.h:30
struct HINSTANCE__ * HINSTANCE
Definition: BASE.h:21
Definition: BSDirectInputManager.h:8
TextureFileFormat
Definition: TextureFileFormat.h:8
Definition: AbsorbEffect.h:6
Definition: EffectArchetypes.h:65
Definition: BASE.h:137
Definition: DXGI.h:342
int windowY
Definition: Renderer.h:103
ScreenSize screenSize
Definition: Renderer.h:101
int presentInterval
Definition: Renderer.h:105
bool vsync
Definition: Renderer.h:108
int windowX
Definition: Renderer.h:102
bool borderlessWindow
Definition: Renderer.h:107
bool appFullScreen
Definition: Renderer.h:106
int refreshRate
Definition: Renderer.h:104
Definition: RenderTargetData.h:35
Definition: RenderTargetData.h:25
Definition: RenderTargetData.h:14
Definition: Renderer.h:34
bool readOnlyDepth
Definition: Renderer.h:45
DepthStencilData depthStencils[RENDER_TARGET_DEPTHSTENCIL::kTOTAL]
Definition: Renderer.h:56
REX::W32::DXGI_MODE_SCANLINE_ORDER scanlineOrdering
Definition: Renderer.h:41
REX::W32::HINSTANCE hInstance
Definition: Renderer.h:67
REX::W32::DXGI_RATIONAL actualRefreshRate
Definition: Renderer.h:39
std::uint32_t newWidth
Definition: Renderer.h:48
REX::W32::ID3D11DeviceContext * context
Definition: Renderer.h:52
std::uint32_t newHeight
Definition: Renderer.h:49
std::uint8_t clearStencil
Definition: Renderer.h:64
RenderTargetData renderTargets[RENDER_TARGET::kTOTAL]
Definition: Renderer.h:55
const char * className
Definition: Renderer.h:66
bool borderlessDisplay
Definition: Renderer.h:44
bool instantiated
Definition: Renderer.h:46
float clearColor[4]
Definition: Renderer.h:63
bool fullScreen
Definition: Renderer.h:43
REX::W32::ID3D11Device * forwarder
Definition: Renderer.h:51
bool requestedWindowSizeChange
Definition: Renderer.h:47
Texture3DTargetData texture3DRenderTargets[RENDER_TARGET_3D::kTOTAL]
Definition: Renderer.h:62
REX::W32::CRITICAL_SECTION lock
Definition: Renderer.h:65
REX::W32::DXGI_RATIONAL desiredRefreshRate
Definition: Renderer.h:38
RendererWindow renderWindows[32]
Definition: Renderer.h:53
std::uint32_t isNotWindowed
Definition: Renderer.h:42
REX::W32::DXGI_MODE_SCALING scaleMode
Definition: Renderer.h:40
std::uint32_t uiAdapter
Definition: Renderer.h:37
CubemapRenderTargetData cubemapRenderTargets[RENDER_TARGET_CUBEMAP::kTOTAL]
Definition: Renderer.h:61
std::uint32_t presentInterval
Definition: Renderer.h:50
Definition: Renderer.h:81
const char * className
Definition: Renderer.h:86
REX::W32::HICON icon
Definition: Renderer.h:85
REX::W32::HINSTANCE instance
Definition: Renderer.h:83
std::uint32_t unk2C
Definition: Renderer.h:88
std::uint32_t adapter
Definition: Renderer.h:87
REX::W32::WNDPROC windowProcFunction
Definition: Renderer.h:84
REX::W32::HWND hwnd
Definition: Renderer.h:82
Definition: Renderer.h:16
RENDER_TARGET swapChainRenderTarget
Definition: Renderer.h:23
std::int32_t windowY
Definition: Renderer.h:19
std::uint64_t unk28
Definition: Renderer.h:25
REX::W32::HWND hWnd
Definition: Renderer.h:17
REX::W32::IDXGISwapChain * swapChain
Definition: Renderer.h:22
std::uint64_t unk40
Definition: Renderer.h:28
std::uint64_t unk48
Definition: Renderer.h:29
std::int32_t windowX
Definition: Renderer.h:18
std::int32_t windowWidth
Definition: Renderer.h:20
REX::W32::ID3D11RenderTargetView1 * renderView
Definition: Renderer.h:26
std::uint32_t unk24
Definition: Renderer.h:24
REX::W32::ID3D11ShaderResourceView1 * resourceView
Definition: Renderer.h:27
std::int32_t windowHeight
Definition: Renderer.h:21
Definition: Renderer.h:93
std::uint32_t width
Definition: Renderer.h:94
std::uint32_t height
Definition: Renderer.h:95
Definition: RenderTargetData.h:43
RENDER_TARGET
Definition: BSShaderRenderTargets.h:8