Blamite Game Engine - blam!  00263.10.17.20.0001.blamite
The core library for the Blamite Game Engine.
rendering.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Windows.h>
4 #include <d3d11_1.h>
5 #include <d2d1_1.h>
6 #include <dwrite.h>
7 
8 #include <vulkan/vulkan.h>
9 #include <vulkan/vulkan_win32.h>
10 
11 #include <glfw3/glfw3.h>
12 
13 #include <string>
14 #include <vector>
15 
16 #include "components/3rdparty/imgui/imgui.h"
17 
18 #ifndef BLAM
19 #define BLAM
20 #endif
21 
25 namespace BlamRendering
26 {
30  namespace Vulkan
31  {
35  namespace DebugMessenger
36  {
40  BLAM void Initialize();
41 
45  BLAM void Shutdown();
46 
50  BLAM void PopulateCreateInfo(VkDebugUtilsMessengerCreateInfoEXT* create_info);
51  }
52 
56  namespace Device
57  {
63  BLAM std::vector<VkPhysicalDevice> GetDeviceList();
64 
72  BLAM bool IsDeviceSuitable(VkPhysicalDevice device);
73 
81  BLAM int RateDeviceSuitability(VkPhysicalDevice device);
82 
92  BLAM void SelectManualDevice(int device_index);
93 
103  BLAM void SelectBestDevice();
104 
112  BLAM void SelectDefaultDevice();
113 
117  BLAM void CreateLogicalDevice();
118 
122  BLAM void DestroyLogicalDevice();
123  }
124 
128  namespace Presentation
129  {
133  BLAM void CreateSurface();
134 
140  BLAM VkSurfaceKHR* GetSurface();
141 
145  BLAM void DestroySurface();
146 
152  BLAM VkQueue* GetPresentQueue();
153  }
154 
158  BLAM void Initialize();
159 
166  BLAM void RenderLoop();
167 
173  BLAM void Shutdown();
174 
181 
185  BLAM VkInstance* GetInstance();
186 
191 
195  BLAM std::vector<const char*> GetEnabledLayers();
196 
200  BLAM std::vector<VkExtensionProperties> GetAvailableExtensions();
201 
205  BLAM std::vector<VkLayerProperties> GetAvailableLayers();
206 
210  BLAM std::vector<const char*> GetRequiredExtensions();
211 
216  }
217 
223  namespace DirectX
224  {
228  namespace D2D
229  {
235  BLAM ID2D1DeviceContext* GetD2DRenderTarget();
236 
242  BLAM ID2D1Factory* GetD2DFactory();
243 
249  BLAM IDWriteFactory* GetDWriteFactory();
250 
259  BLAM HRESULT LoadFontFromFile(std::string id, std::string file_path);
260  }
261 
265  namespace WIC
266  {
272  BLAM IWICImagingFactory* GetWICFactory();
273 
283  BLAM HRESULT CreateD2DBitmapFromResource(int res_id, const char* res_type, ID2D1Bitmap **bitmap_pointer);
284 
293  BLAM HRESULT CreateD2DBitmapFromFile(std::wstring path, ID2D1Bitmap **bitmap_pointer);
294 
303  BLAM HRESULT CreateWICBitmapFromFile(std::wstring path, IWICBitmap** bitmap_pointer);
304 
314  BLAM HRESULT CreateWICBitmapFromMemory(void* data, int size, IWICBitmap** bitmap_pointer);
315 
324  BLAM HRESULT ConvertWICBitmapToD2D(IWICBitmap* wic_bitmap, ID2D1Bitmap** d2d_bitmap);
325 
335  BLAM HRESULT ConvertWICBitmapToD2D(IWICBitmap* wic_bitmap, ID2D1Bitmap** d2d_bitmap, ID2D1RenderTarget* render_target);
336 
345  BLAM HRESULT ConvertWICBitmapTo32bppPBGRA(IWICBitmap* source, IWICBitmap** destination);
346 
355  BLAM HRESULT Initialize();
356 
363  BLAM void Shutdown();
364  }
365 
371  BLAM ID3D11Device* GetD3DDevice();
372 
378  BLAM ID3D11DeviceContext* GetD3DContext();
379 
390  BLAM IDXGISwapChain* GetDXGISwapChain();
391 
397  BLAM ID3D11RenderTargetView* GetD3DRenderTargetView();
398 
404  BLAM DXGI_SWAP_CHAIN_DESC GetSwapChainDesc();
405 
416  BLAM HRESULT Initialize(HWND hWnd);
417 
424  BLAM void Cleanup();
425 
437  BLAM HRESULT HandleWindowResize(LPARAM lParam);
438 
446  BLAM bool* RenderTargetClearing();
447 
458  BLAM void RenderLoop(bool debug);
459 
467  BLAM void ShutdownRenderThread();
468 
479  BLAM void RenderThread(bool debug);
480 
490 
496  BLAM void SetClearColor(ImVec4 color);
497 
503  BLAM ImVec4* GetClearColor();
504 
513  BLAM HRESULT UpdateResolution(int x, int y);
514 
520  BLAM ID3D11Texture2D** GetLastFrameTexture();
521 
528  BLAM HRESULT GetLastFrameTextureAlt(ID3D11Texture2D* texture);
529 
536  BLAM void ScreenshotDone();
537 
544  BLAM HRESULT GetLastFrameHResult();
545 
555  BLAM void DisplayDetailedCrashScreen(const char* expression, const char* file, int line, std::string details);
556 
562 
567  BLAM void DisplaySignalCrashScreen(int signal);
568  }
569 
573  namespace OpenGL
574  {
575  void Initialize();
576  void RenderLoop();
577  void Shutdown();
578  }
579 
581  // Abstract/Shared Functions, these will usually interface with the active graphics API themselves //
583 
589  BLAM void SetClearColor(ImVec4 color);
590 
599  BLAM void ShowCrashScreen(const char* exc, const char* file, int line, std::string message);
600 
609  BLAM HRESULT SetDisplayRes(int x, int y); //Sets screen resolution
610 
611 
612  BLAM void HandleWindowResize(WPARAM wParam, LPARAM lParam);
613 }
614 
615 namespace Blam
616 {
620  BLAM void TakeScreenshot();
621 }
Blam
Namespace surrounding all major engine components.
Definition: blam_api.h:17
BlamRendering::SetClearColor
BLAM void SetClearColor(ImVec4 color)
Changes the color to used to clear the render target.
Definition: rendering_abstraction.cpp:20
BlamRendering::DirectX::WIC::ConvertWICBitmapToD2D
BLAM HRESULT ConvertWICBitmapToD2D(IWICBitmap *wic_bitmap, ID2D1Bitmap **d2d_bitmap)
Converts a WIC bitmap to a D2D bitmap.
Definition: wic.cpp:81
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:603
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::DirectX::ShutdownRenderThread
BLAM void ShutdownRenderThread()
Instructs the rendering thread to stop running.
Definition: render_manage.cpp:321
BlamRendering::DirectX::GetLastFrameTextureAlt
BLAM HRESULT GetLastFrameTextureAlt(ID3D11Texture2D *texture)
Retrieves the last frame that was rendered.
Definition: render_manage.cpp:637
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:48
details
LPSTR details
Definition: error_notice.cpp:17
BlamRendering::Vulkan::DebugMessenger::Shutdown
BLAM void Shutdown()
Shuts down the Vulkan debug messenger.
Definition: debug_messenger.cpp:158
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:563
BlamRendering::OpenGL::Shutdown
void Shutdown()
Definition: opengl.cpp:34
BlamRendering::DirectX::D2D::GetD2DRenderTarget
BLAM ID2D1DeviceContext * GetD2DRenderTarget()
Retrieves the Direct2D render target.
Definition: render_manage.cpp:588
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:35
BlamRendering::SetDisplayRes
BLAM HRESULT SetDisplayRes(int x, int y)
Changes the game's display resolution.
Definition: rendering_abstraction.cpp:5
BlamRendering::DirectX::DisplaySignalCrashScreen
BLAM void DisplaySignalCrashScreen(int signal)
Displays a signal-based engine crash screen.
Definition: render_manage.cpp:454
BlamRendering::DirectX::SetClearColor
BLAM void SetClearColor(ImVec4 color)
Changes the color to used to clear the render target.
Definition: render_manage.cpp:557
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:433
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:163
BlamRendering::DirectX::GetLastFrameHResult
BLAM HRESULT GetLastFrameHResult()
Unused.
Definition: render_manage.cpp:632
BlamRendering::DirectX::Initialize
BLAM HRESULT Initialize(HWND hWnd)
Initializes DirectX 11.
Definition: render_manage.cpp:73
BlamRendering::DirectX::UpdateResolution
BLAM HRESULT UpdateResolution(int x, int y)
Changes the DirectX render target resolution.
Definition: resolution.cpp:9
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:11
BlamRendering::DirectX::GetLastFrameTexture
BLAM ID3D11Texture2D ** GetLastFrameTexture()
Retrieves the last frame that was rendered.
Definition: render_manage.cpp:616
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:545
BlamRendering::DirectX::GetSwapChainDesc
BLAM DXGI_SWAP_CHAIN_DESC GetSwapChainDesc()
Retrieves the current Direct3D Swap Chain description.
Definition: render_manage.cpp:608
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:296
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:593
BlamRendering::Vulkan::Device::RateDeviceSuitability
BLAM int RateDeviceSuitability(VkPhysicalDevice device)
Rates a given physical device based on its capabilities and features.
Definition: device.cpp:117
debug
bool debug
Stores value of debugMode config option, probably should be removed at some point.
Definition: main.cpp:83
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:654
BlamRendering::HandleWindowResize
BLAM void HandleWindowResize(WPARAM wParam, LPARAM lParam)
Definition: rendering_abstraction.cpp:50
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
BlamRendering::OpenGL::Initialize
void Initialize()
Definition: opengl.cpp:12
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:252
BlamRendering::DirectX::GetD3DRenderTargetView
BLAM ID3D11RenderTargetView * GetD3DRenderTargetView()
Retrieves the current Direct3D Render Target.
Definition: render_manage.cpp:583
BlamRendering::DirectX::GetDXGISwapChain
BLAM IDXGISwapChain * GetDXGISwapChain()
Retrieves the current DXGI Swap Chain.
Definition: render_manage.cpp:578
BlamRendering::DirectX::DisplayBasicCrashScreen
BLAM void DisplayBasicCrashScreen()
Displays a basic engine crash screen.
Definition: render_manage.cpp:446
BlamRendering::DirectX::GetD3DDevice
BLAM ID3D11Device * GetD3DDevice()
Retrieves the current Direct3D device.
Definition: render_manage.cpp:568
BlamRendering::DirectX::WIC::CreateWICBitmapFromFile
BLAM HRESULT CreateWICBitmapFromFile(std::wstring path, IWICBitmap **bitmap_pointer)
Creates a WIC bitmap from a file.
Definition: wic.cpp:131
BlamRendering::Vulkan::Presentation::DestroySurface
BLAM void DestroySurface()
Destroys the Vulkan surface.
Definition: presentation.cpp:33
BlamRendering
Namespace for things relating to rendering.
Definition: drawing.h:14
BlamRendering::OpenGL::RenderLoop
void RenderLoop()
Definition: opengl.cpp:28
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::DirectX::RenderLoop
BLAM void RenderLoop(bool debug)
Renders everything to the screen.
Definition: render_manage.cpp:360
BlamRendering::DirectX::GetD3DContext
BLAM ID3D11DeviceContext * GetD3DContext()
Retrieves the current Direct3D context.
Definition: render_manage.cpp:573
BlamRendering::DirectX::WIC::GetWICFactory
BLAM IWICImagingFactory * GetWICFactory()
Retrieves the WIC Imaging Factory.
Definition: wic.cpp:43
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:19
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:37
BlamRendering::DirectX::Cleanup
BLAM void Cleanup()
Cleans up all DirectX data.
Definition: render_manage.cpp:227
BlamRendering::DirectX::HasRenderThreadStopped
BLAM bool HasRenderThreadStopped()
Determines whether or not the render thread has finished stopping.
Definition: render_manage.cpp:316
BlamRendering::DirectX::RenderTargetClearing
BLAM bool * RenderTargetClearing()
Retrieves whether or not to enable render target clearing.
Definition: render_manage.cpp:598
BlamRendering::Vulkan::Presentation::GetSurface
BLAM VkSurfaceKHR * GetSurface()
Retrieves the Vulkan window surface.
Definition: presentation.cpp:28
BlamRendering::DirectX::WIC::CreateD2DBitmapFromFile
BLAM HRESULT CreateD2DBitmapFromFile(std::wstring path, ID2D1Bitmap **bitmap_pointer)
Creates a Direct2D bitmap from a file.
Definition: wic.cpp:206
BlamRendering::DirectX::RenderThread
BLAM void RenderThread(bool debug)
Instructs the engine to start rendering on a separate thread.
Definition: render_manage.cpp:326