Blamite Game Engine - blam!  00296.01.12.21.0102.blamite
The core library for the Blamite Game Engine.
rendering.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <d3d11_1.h>
4 #include <d2d1_1.h>
5 #include <dwrite.h>
6 
7 #include <vulkan/vulkan.h>
8 #include <vulkan/vulkan_win32.h>
9 
10 #include <glew/glew.h>
11 #include <sdl2/SDL.h>
12 
13 #include <string>
14 #include <vector>
15 
16 #include "components/3rdparty/imgui/imgui.h"
18 
19 #ifndef BLAM
20 #define BLAM
21 #endif
22 
24 {
30 };
31 
35 namespace BlamRendering
36 {
40  namespace Vulkan
41  {
45  namespace DebugMessenger
46  {
50  BLAM void Initialize();
51 
55  BLAM void Shutdown();
56 
60  BLAM void PopulateCreateInfo(VkDebugUtilsMessengerCreateInfoEXT* create_info);
61  }
62 
66  namespace Device
67  {
73  BLAM std::vector<VkPhysicalDevice> GetDeviceList();
74 
82  BLAM bool IsDeviceSuitable(VkPhysicalDevice device);
83 
91  BLAM int RateDeviceSuitability(VkPhysicalDevice device);
92 
102  BLAM void SelectManualDevice(int device_index);
103 
113  BLAM void SelectBestDevice();
114 
122  BLAM void SelectDefaultDevice();
123 
127  BLAM void CreateLogicalDevice();
128 
132  BLAM void DestroyLogicalDevice();
133  }
134 
138  namespace Presentation
139  {
143  BLAM void CreateSurface();
144 
150  BLAM VkSurfaceKHR* GetSurface();
151 
155  BLAM void DestroySurface();
156 
162  BLAM VkQueue* GetPresentQueue();
163  }
164 
168  BLAM void Initialize();
169 
176  BLAM void RenderLoop();
177 
183  BLAM void Shutdown();
184 
191 
195  BLAM VkInstance* GetInstance();
196 
201 
205  BLAM std::vector<const char*> GetEnabledLayers();
206 
210  BLAM std::vector<VkExtensionProperties> GetAvailableExtensions();
211 
215  BLAM std::vector<VkLayerProperties> GetAvailableLayers();
216 
220  BLAM std::vector<const char*> GetRequiredExtensions();
221 
226  }
227 
233  namespace DirectX
234  {
238  namespace D2D
239  {
245  BLAM ID2D1DeviceContext* GetD2DRenderTarget();
246 
252  BLAM ID2D1Factory* GetD2DFactory();
253 
259  BLAM IDWriteFactory* GetDWriteFactory();
260 
269  BLAM HRESULT LoadFontFromFile(std::string id, std::string file_path);
270  }
271 
275  namespace WIC
276  {
282  BLAM IWICImagingFactory* GetWICFactory();
283 
293  BLAM HRESULT CreateD2DBitmapFromResource(int res_id, const char* res_type, ID2D1Bitmap **bitmap_pointer);
294 
303  BLAM HRESULT CreateD2DBitmapFromFile(std::wstring path, ID2D1Bitmap **bitmap_pointer);
304 
313  BLAM HRESULT CreateWICBitmapFromFile(std::wstring path, IWICBitmap** bitmap_pointer);
314 
324  BLAM HRESULT CreateWICBitmapFromMemory(void* data, int size, IWICBitmap** bitmap_pointer);
325 
334  BLAM HRESULT ConvertWICBitmapToD2D(IWICBitmap* wic_bitmap, ID2D1Bitmap** d2d_bitmap);
335 
345  BLAM HRESULT ConvertWICBitmapToD2D(IWICBitmap* wic_bitmap, ID2D1Bitmap** d2d_bitmap, ID2D1RenderTarget* render_target);
346 
355  BLAM HRESULT ConvertWICBitmapTo32bppPBGRA(IWICBitmap* source, IWICBitmap** destination);
356 
365  BLAM HRESULT Initialize();
366 
373  BLAM void Shutdown();
374  }
375 
381  BLAM ID3D11Device* GetD3DDevice();
382 
388  BLAM ID3D11DeviceContext* GetD3DContext();
389 
400  BLAM IDXGISwapChain* GetDXGISwapChain();
401 
407  BLAM ID3D11RenderTargetView* GetD3DRenderTargetView();
408 
414  BLAM DXGI_SWAP_CHAIN_DESC GetSwapChainDesc();
415 
426  BLAM HRESULT Initialize(HWND hWnd);
427 
434  BLAM void Cleanup();
435 
447  BLAM HRESULT HandleWindowResize(LPARAM lParam);
448 
456  BLAM bool* RenderTargetClearing();
457 
468  BLAM void RenderLoop(bool debug);
469 
477  BLAM void ShutdownRenderThread();
478 
489  BLAM void RenderThread(bool debug);
490 
500 
506  BLAM void SetClearColor(ImVec4 color);
507 
513  BLAM ImVec4* GetClearColor();
514 
523  BLAM HRESULT UpdateResolution(int x, int y);
524 
530  BLAM ID3D11Texture2D** GetLastFrameTexture();
531 
538  BLAM HRESULT GetLastFrameTextureAlt(ID3D11Texture2D* texture);
539 
546  BLAM void ScreenshotDone();
547 
554  BLAM HRESULT GetLastFrameHResult();
555 
565  BLAM void DisplayDetailedCrashScreen(const char* expression, const char* file, int line, std::string details);
566 
572 
577  BLAM void DisplaySignalCrashScreen(int signal);
578  }
579 
583  namespace OpenGL
584  {
590  BLAM BlamResult Initialize();
591 
595  BLAM void RenderLoop();
596 
600  BLAM void Shutdown();
601 
607  BLAM SDL_GLContext* GetGLContext();
608  }
609 
610  namespace BGFX
611  {
612  BLAM void SetPlatformData();
613 
614  BLAM void Initialize();
615  BLAM void RenderLoop();
616  BLAM void Shutdown();
617 
618  BLAM void HandleWindowReisze(int width, int height);
619 
620  BLAM void SetViewClearFlags(int new_flags);
621  }
622 
624  // Abstract/Shared Functions, these will usually interface with the active graphics API themselves //
626 
633 
639  BLAM void SetClearColor(ImVec4 color);
640 
646  BLAM ImVec4* GetClearColor();
647 
656  BLAM void ShowCrashScreen(const char* exc, const char* file, int line, std::string message);
657 
666  BLAM HRESULT SetDisplayRes(int x, int y); //Sets screen resolution
667 
668 
669  BLAM void HandleWindowResize(int width, int height, WPARAM wParam);
670 }
671 
672 namespace Blam
673 {
677  BLAM void TakeScreenshot();
678 }
Blam
Namespace surrounding all major engine components.
Definition: blam_api.h:18
BlamRendering::SetClearColor
BLAM void SetClearColor(ImVec4 color)
Changes the color to used to clear the render target.
Definition: rendering_abstraction.cpp:26
BlamRendering::DirectX::WIC::ConvertWICBitmapToD2D
BLAM HRESULT ConvertWICBitmapToD2D(IWICBitmap *wic_bitmap, ID2D1Bitmap **d2d_bitmap)
Converts a WIC bitmap to a D2D bitmap.
Definition: wic.cpp:91
BlamRendering::Vulkan::Presentation::GetPresentQueue
BLAM VkQueue * GetPresentQueue()
Retrieves the Vulkan presentation queue.
Definition: presentation.cpp:45
BlamRendering::DirectX::GetClearColor
BLAM ImVec4 * GetClearColor()
Retrieves the current color used to clear the render target.
Definition: render_manage.cpp:613
BlamRendering::Vulkan::GetInstance
BLAM VkInstance * GetInstance()
Retrieves the Vulkan instance.
Definition: vulkan.cpp:28
BlamRendering::Vulkan::Device::SelectManualDevice
BLAM void SelectManualDevice(int device_index)
Instructs Vulkan to try to select a specific device.
Definition: device.cpp:145
BlamRendering::BGFX::SetViewClearFlags
BLAM void SetViewClearFlags(int new_flags)
Definition: bgfx.cpp:137
BlamRendering::DirectX::ShutdownRenderThread
BLAM void ShutdownRenderThread()
Instructs the rendering thread to stop running.
Definition: render_manage.cpp:331
BlamRendering::DirectX::GetLastFrameTextureAlt
BLAM HRESULT GetLastFrameTextureAlt(ID3D11Texture2D *texture)
Retrieves the last frame that was rendered.
Definition: render_manage.cpp:647
width
int width
Definition: bgfx.cpp:18
BlamRendering::DirectX::WIC::ConvertWICBitmapTo32bppPBGRA
BLAM HRESULT ConvertWICBitmapTo32bppPBGRA(IWICBitmap *source, IWICBitmap **destination)
Converts a WIC bitmap to a WIC bitmap, with the 32 bits-per-pixe, PBGRA format.
Definition: wic.cpp:58
details
LPSTR details
Definition: error_notice.cpp:17
BlamRendering::GetCurrentRenderingEngine
BLAM BlamRenderingEngine GetCurrentRenderingEngine()
Retrieves the current rendering engine being used.
Definition: rendering_abstraction.cpp:103
BlamRendering::Vulkan::DebugMessenger::Shutdown
BLAM void Shutdown()
Shuts down the Vulkan debug messenger.
Definition: debug_messenger.cpp:158
BlamRendering::HandleWindowResize
BLAM void HandleWindowResize(int width, int height, WPARAM wParam)
Definition: rendering_abstraction.cpp:80
BlamRendering::Vulkan::Presentation::CreateSurface
BLAM void CreateSurface()
Prepares the Vulkan surface used for rendering.
Definition: presentation.cpp:9
BlamRendering::DirectX::D2D::GetDWriteFactory
BLAM IDWriteFactory * GetDWriteFactory()
Retrieves the DirectWrite factory.
Definition: render_manage.cpp:573
BlamRenderingEngine
BlamRenderingEngine
Definition: rendering.h:23
BlamRendering::OpenGL::Shutdown
BLAM void Shutdown()
Shuts down OpenGL.
Definition: opengl.cpp:157
BlamRendering::DirectX::D2D::GetD2DRenderTarget
BLAM ID2D1DeviceContext * GetD2DRenderTarget()
Retrieves the Direct2D render target.
Definition: render_manage.cpp:598
BlamRendering::ShowCrashScreen
BLAM void ShowCrashScreen(const char *exc, const char *file, int line, std::string message)
Displays the engine crash screen.
Definition: rendering_abstraction.cpp:61
BlamRendering::SetDisplayRes
BLAM HRESULT SetDisplayRes(int x, int y)
Changes the game's display resolution.
Definition: rendering_abstraction.cpp:7
BlamRendering::DirectX::DisplaySignalCrashScreen
BLAM void DisplaySignalCrashScreen(int signal)
Displays a signal-based engine crash screen.
Definition: render_manage.cpp:464
BlamRendering::DirectX::SetClearColor
BLAM void SetClearColor(ImVec4 color)
Changes the color to used to clear the render target.
Definition: render_manage.cpp:567
BlamRendering::Vulkan::Device::CreateLogicalDevice
BLAM void CreateLogicalDevice()
Definition: device.cpp:252
BlamRendering::DirectX::DisplayDetailedCrashScreen
BLAM void DisplayDetailedCrashScreen(const char *expression, const char *file, int line, std::string details)
Displays a detailed engine crash screen.
Definition: render_manage.cpp:443
BlamRendering::Vulkan::GetAvailableExtensions
BLAM std::vector< VkExtensionProperties > GetAvailableExtensions()
Retrieves the list of all extensions available to Vulkan.
Definition: vulkan.cpp:225
BlamRendering::DirectX::WIC::CreateWICBitmapFromMemory
BLAM HRESULT CreateWICBitmapFromMemory(void *data, int size, IWICBitmap **bitmap_pointer)
Creates a WIC bitmap from a block of memory.
Definition: wic.cpp:173
color
@ color
Definition: render_model.h:12
BlamRendering::BGFX::HandleWindowReisze
BLAM void HandleWindowReisze(int width, int height)
Definition: bgfx.cpp:127
BlamRendering::DirectX::GetLastFrameHResult
BLAM HRESULT GetLastFrameHResult()
Unused.
Definition: render_manage.cpp:642
BlamRendering::DirectX::Initialize
BLAM HRESULT Initialize(HWND hWnd)
Initializes DirectX 11.
Definition: render_manage.cpp:74
BlamRendering::DirectX::UpdateResolution
BLAM HRESULT UpdateResolution(int x, int y)
Changes the DirectX render target resolution.
Definition: resolution.cpp:9
BlamRendering::GetClearColor
BLAM ImVec4 * GetClearColor()
Retrieves the color used for render target clearing.
Definition: rendering_abstraction.cpp:45
BlamRendering::BGFX::Shutdown
BLAM void Shutdown()
Definition: bgfx.cpp:118
BlamRendering::Vulkan::RenderLoop
BLAM void RenderLoop()
Renders engine graphics onscreen.
Definition: vulkan.cpp:295
BlamRendering::DirectX::WIC::Initialize
BLAM HRESULT Initialize()
Initializes the Windows Imaging Component (WIC).
Definition: wic.cpp:12
BlamRendering::DirectX::GetLastFrameTexture
BLAM ID3D11Texture2D ** GetLastFrameTexture()
Retrieves the last frame that was rendered.
Definition: render_manage.cpp:626
BlamRendering::Vulkan::ValidationLayersEnabled
BLAM bool ValidationLayersEnabled()
Checks whether or not validation layers are enabled.
Definition: vulkan.cpp:33
BlamRendering::Vulkan::CheckValidationLayerSupport
BLAM bool CheckValidationLayerSupport()
Checks whether or not Vulkan's default validation layer is available.
Definition: vulkan.cpp:195
BlamRendering::DirectX::D2D::LoadFontFromFile
BLAM HRESULT LoadFontFromFile(std::string id, std::string file_path)
Loads a TrueType font from the specified file into the list of loaded font collections.
Definition: render_manage.cpp:555
errors.h
BlamRendering::DirectX::GetSwapChainDesc
BLAM DXGI_SWAP_CHAIN_DESC GetSwapChainDesc()
Retrieves the current Direct3D Swap Chain description.
Definition: render_manage.cpp:618
BlamRendering::Vulkan::Initialize
BLAM void Initialize()
Initializes Vulkan.
Definition: vulkan.cpp:247
BlamRendering::Vulkan::Device::SelectDefaultDevice
BLAM void SelectDefaultDevice()
Instructs Vulkan to select the first compatiable device.
Definition: device.cpp:213
BlamRendering::DirectX::HandleWindowResize
BLAM HRESULT HandleWindowResize(LPARAM lParam)
Handles a window resize event.
Definition: render_manage.cpp:306
Blam::TakeScreenshot
BLAM void TakeScreenshot()
Captures the current frame and saves it to a file.
Definition: screenshot.cpp:100
BlamRendering::DirectX::D2D::GetD2DFactory
BLAM ID2D1Factory * GetD2DFactory()
Retrieves the Direct2D factory.
Definition: render_manage.cpp:603
BlamRendering::Vulkan::Device::RateDeviceSuitability
BLAM int RateDeviceSuitability(VkPhysicalDevice device)
Rates a given physical device based on its capabilities and features.
Definition: device.cpp:117
BlamRendering::BGFX::RenderLoop
BLAM void RenderLoop()
Definition: bgfx.cpp:66
BlamRendering::BGFX::SetPlatformData
BLAM void SetPlatformData()
BlamRendering::Vulkan::Device::GetDeviceList
BLAM std::vector< VkPhysicalDevice > GetDeviceList()
Retrieves the list of physical devices available to Vulkan.
Definition: device.cpp:92
BlamRendering::DirectX::ScreenshotDone
BLAM void ScreenshotDone()
Informs DirectX that the screenshot has finished being captured.
Definition: render_manage.cpp:664
BlamRendering::Vulkan::DebugMessenger::PopulateCreateInfo
BLAM void PopulateCreateInfo(VkDebugUtilsMessengerCreateInfoEXT *create_info)
Populates debug messenger creation information.
Definition: debug_messenger.cpp:79
BlamRendering::Vulkan::GetRequiredExtensions
BLAM std::vector< const char * > GetRequiredExtensions()
Gets a list of required Vulkan extensions.
Definition: vulkan.cpp:178
BlamRendering::Vulkan::DebugMessenger::Initialize
BLAM void Initialize()
Initializes the Vulkan debug messenger.
Definition: debug_messenger.cpp:119
Vulkan
@ Vulkan
Definition: rendering.h:26
BlamRendering::DirectX::WIC::CreateD2DBitmapFromResource
BLAM HRESULT CreateD2DBitmapFromResource(int res_id, const char *res_type, ID2D1Bitmap **bitmap_pointer)
Creates a Direct2D bitmap from an application resource.
Definition: wic.cpp:262
BlamRendering::DirectX::GetD3DRenderTargetView
BLAM ID3D11RenderTargetView * GetD3DRenderTargetView()
Retrieves the current Direct3D Render Target.
Definition: render_manage.cpp:593
BlamRendering::DirectX::GetDXGISwapChain
BLAM IDXGISwapChain * GetDXGISwapChain()
Retrieves the current DXGI Swap Chain.
Definition: render_manage.cpp:588
BlamRendering::DirectX::DisplayBasicCrashScreen
BLAM void DisplayBasicCrashScreen()
Displays a basic engine crash screen.
Definition: render_manage.cpp:456
BlamRendering::DirectX::GetD3DDevice
BLAM ID3D11Device * GetD3DDevice()
Retrieves the current Direct3D device.
Definition: render_manage.cpp:578
NotReady
@ NotReady
Definition: rendering.h:29
BlamRendering::DirectX::WIC::CreateWICBitmapFromFile
BLAM HRESULT CreateWICBitmapFromFile(std::wstring path, IWICBitmap **bitmap_pointer)
Creates a WIC bitmap from a file.
Definition: wic.cpp:141
DirectX11
@ DirectX11
Definition: rendering.h:25
BlamRendering::Vulkan::Presentation::DestroySurface
BLAM void DestroySurface()
Destroys the Vulkan surface.
Definition: presentation.cpp:33
height
int height
Definition: bgfx.cpp:19
BlamRendering
Namespace for things relating to rendering.
Definition: models.h:150
BlamRendering::OpenGL::RenderLoop
BLAM void RenderLoop()
Renders a frame to the application window.
Definition: opengl.cpp:132
BlamRendering::Vulkan::GetAvailableLayers
BLAM std::vector< VkLayerProperties > GetAvailableLayers()
Retrieves the list of all validation layers available to Vulkan.
Definition: vulkan.cpp:236
BlamRendering::Vulkan::Device::DestroyLogicalDevice
BLAM void DestroyLogicalDevice()
Definition: device.cpp:308
BlamRendering::OpenGL::Initialize
BLAM BlamResult Initialize()
Initializes OpenGL.
Definition: opengl.cpp:69
BlamRendering::DirectX::RenderLoop
BLAM void RenderLoop(bool debug)
Renders everything to the screen.
Definition: render_manage.cpp:370
BlamRendering::DirectX::GetD3DContext
BLAM ID3D11DeviceContext * GetD3DContext()
Retrieves the current Direct3D context.
Definition: render_manage.cpp:583
BlamRendering::DirectX::WIC::GetWICFactory
BLAM IWICImagingFactory * GetWICFactory()
Retrieves the WIC Imaging Factory.
Definition: wic.cpp:53
BlamRendering::Vulkan::PrintVulkanAvailabilityInfo
BLAM void PrintVulkanAvailabilityInfo()
Prints lists of available Vulkan extensions and validation layers.
Definition: vulkan.cpp:43
BlamRendering::Vulkan::Device::IsDeviceSuitable
BLAM bool IsDeviceSuitable(VkPhysicalDevice device)
Determines whether or not a given Vulkan device is suitable for the engine's requirements.
Definition: device.cpp:103
BlamRendering::Vulkan::Device::SelectBestDevice
BLAM void SelectBestDevice()
Instructs Vulkan to select the best compatiable device.
Definition: device.cpp:169
BlamRendering::Vulkan::Shutdown
BLAM void Shutdown()
Shuts down Vulkan.
Definition: vulkan.cpp:300
BLAM
#define BLAM
Definition: rendering.h:20
BlamRendering::Vulkan::GetEnabledLayers
BLAM std::vector< const char * > GetEnabledLayers()
Retrieves the list of all enabled Vulkan layers.
Definition: vulkan.cpp:38
BlamRendering::DirectX::WIC::Shutdown
BLAM void Shutdown()
Shuts down the Windows Imaging Component (WIC).
Definition: wic.cpp:47
BlamRendering::DirectX::Cleanup
BLAM void Cleanup()
Cleans up all DirectX data.
Definition: render_manage.cpp:237
BlamRendering::BGFX::Initialize
BLAM void Initialize()
Definition: bgfx.cpp:26
BlamRendering::DirectX::HasRenderThreadStopped
BLAM bool HasRenderThreadStopped()
Determines whether or not the render thread has finished stopping.
Definition: render_manage.cpp:326
BlamRendering::DirectX::RenderTargetClearing
BLAM bool * RenderTargetClearing()
Retrieves whether or not to enable render target clearing.
Definition: render_manage.cpp:608
BGFX
@ BGFX
Definition: rendering.h:28
BlamRendering::OpenGL::GetGLContext
BLAM SDL_GLContext * GetGLContext()
Retrieves the current OpenGL context.
Definition: opengl.cpp:173
BlamRendering::Vulkan::Presentation::GetSurface
BLAM VkSurfaceKHR * GetSurface()
Retrieves the Vulkan window surface.
Definition: presentation.cpp:28
OpenGL3
@ OpenGL3
Definition: rendering.h:27
BlamRendering::DirectX::WIC::CreateD2DBitmapFromFile
BLAM HRESULT CreateD2DBitmapFromFile(std::wstring path, ID2D1Bitmap **bitmap_pointer)
Creates a Direct2D bitmap from a file.
Definition: wic.cpp:216
BlamRendering::DirectX::RenderThread
BLAM void RenderThread(bool debug)
Instructs the engine to start rendering on a separate thread.
Definition: render_manage.cpp:337