Blamite Game Engine - Blam (Core)
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 #include <vulkan/vulkan.h>
8 #include <string>
9 #include <vector>
10 
11 #include "components/3rdparty/imgui/imgui.h"
12 
13 #ifndef BLAM
14 #define BLAM
15 #endif
16 
20 namespace BlamRendering
21 {
25  namespace Vulkan
26  {
30  namespace DebugMessenger
31  {
35  void Initialize();
36 
40  void Shutdown();
41 
45  void PopulateCreateInfo(VkDebugUtilsMessengerCreateInfoEXT* create_info);
46  }
47 
51  namespace Device
52  {
58  std::vector<VkPhysicalDevice> GetDeviceList();
59 
67  bool IsDeviceSuitable(VkPhysicalDevice device);
68 
76  int RateDeviceSuitability(VkPhysicalDevice device);
77 
87  void SelectManualDevice(int device_index);
88 
98  void SelectBestDevice();
99 
107  void SelectDefaultDevice();
108  }
109 
113  void Initialize();
114 
121  void RenderLoop();
122 
128  void Shutdown();
129 
136 
140  VkInstance* GetInstance();
141 
145  std::vector<VkExtensionProperties> GetAvailableExtensions();
146 
150  std::vector<const char*> GetRequiredExtensions();
151  }
152 
158  namespace DirectX
159  {
163  namespace D2D
164  {
170  BLAM ID2D1DeviceContext* GetD2DRenderTarget();
171 
177  BLAM ID2D1Factory* GetD2DFactory();
178 
184  BLAM IDWriteFactory* GetDWriteFactory();
185 
194  BLAM HRESULT LoadFontFromFile(std::string id, std::string file_path);
195  }
196 
200  namespace WIC
201  {
207  BLAM IWICImagingFactory* GetWICFactory();
208 
218  BLAM HRESULT CreateD2DBitmapFromResource(int res_id, const char* res_type, ID2D1Bitmap **bitmap_pointer);
219 
228  BLAM HRESULT CreateD2DBitmapFromFile(std::wstring path, ID2D1Bitmap **bitmap_pointer);
229 
238  BLAM HRESULT CreateWICBitmapFromFile(std::wstring path, IWICBitmap** bitmap_pointer);
239 
249  BLAM HRESULT CreateWICBitmapFromMemory(void* data, int size, IWICBitmap** bitmap_pointer);
250 
259  BLAM HRESULT ConvertWICBitmapToD2D(IWICBitmap* wic_bitmap, ID2D1Bitmap** d2d_bitmap);
260 
270  BLAM HRESULT ConvertWICBitmapToD2D(IWICBitmap* wic_bitmap, ID2D1Bitmap** d2d_bitmap, ID2D1RenderTarget* render_target);
271 
280  BLAM HRESULT ConvertWICBitmapTo32bppPBGRA(IWICBitmap* source, IWICBitmap** destination);
281 
290  BLAM HRESULT Initialize();
291 
298  BLAM void Shutdown();
299  }
300 
306  BLAM ID3D11Device* GetD3DDevice();
307 
313  BLAM ID3D11DeviceContext* GetD3DContext();
314 
325  BLAM IDXGISwapChain* GetDXGISwapChain();
326 
332  BLAM ID3D11RenderTargetView* GetD3DRenderTargetView();
333 
339  BLAM DXGI_SWAP_CHAIN_DESC GetSwapChainDesc();
340 
351  BLAM HRESULT Initialize(HWND hWnd);
352 
359  BLAM void Cleanup();
360 
372  BLAM HRESULT HandleWindowResize(LPARAM lParam);
373 
381  BLAM bool* RenderTargetClearing();
382 
393  BLAM void RenderLoop(bool debug);
394 
402  BLAM void ShutdownRenderThread();
403 
414  BLAM void RenderThread(bool debug);
415 
425 
431  BLAM void SetClearColor(ImVec4 color);
432 
438  BLAM ImVec4* GetClearColor();
439 
448  BLAM HRESULT UpdateResolution(int x, int y);
449 
455  BLAM ID3D11Texture2D** GetLastFrameTexture();
456 
463  BLAM HRESULT GetLastFrameTextureAlt(ID3D11Texture2D* texture);
464 
471  BLAM void ScreenshotDone();
472 
479  BLAM HRESULT GetLastFrameHResult();
480 
490  BLAM void DisplayDetailedCrashScreen(const char* expression, const char* file, int line, std::string details);
491 
497 
502  BLAM void DisplaySignalCrashScreen(int signal);
503  }
504 
508  namespace OpenGL
509  {
510  //TBA
511  }
512 
514  // Abstract/Shared Functions, these will usually interface with the active graphics API themselves //
516 
522  BLAM void SetClearColor(ImVec4 color);
523 
532  BLAM void ShowCrashScreen(const char* exc, const char* file, int line, std::string message);
533 
542  BLAM HRESULT SetDisplayRes(int x, int y); //Sets screen resolution
543 
544 
545  BLAM void HandleWindowResize(WPARAM wParam, LPARAM lParam);
546 }
547 
548 namespace Blam
549 {
553  BLAM void TakeScreenshot();
554 }
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::DirectX::GetClearColor
BLAM ImVec4 * GetClearColor()
Retrieves the current color used to clear the render target.
Definition: render_manage.cpp:602
BlamRendering::Vulkan::GetInstance
VkInstance * GetInstance()
Retrieves the Vulkan instance.
Definition: vulkan.cpp:26
BlamRendering::Vulkan::Device::SelectManualDevice
void SelectManualDevice(int device_index)
Instructs Vulkan to try to select a specific device.
Definition: device.cpp:68
BlamRendering::DirectX::ShutdownRenderThread
BLAM void ShutdownRenderThread()
Instructs the rendering thread to stop running.
Definition: render_manage.cpp:320
BlamRendering::DirectX::GetLastFrameTextureAlt
BLAM HRESULT GetLastFrameTextureAlt(ID3D11Texture2D *texture)
Retrieves the last frame that was rendered.
Definition: render_manage.cpp:636
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:15
BlamRendering::Vulkan::DebugMessenger::Shutdown
void Shutdown()
Shuts down the Vulkan debug messenger.
Definition: debug_messenger.cpp:158
BlamRendering::DirectX::D2D::GetDWriteFactory
BLAM IDWriteFactory * GetDWriteFactory()
Retrieves the DirectWrite factory.
Definition: render_manage.cpp:562
BlamRendering::DirectX::D2D::GetD2DRenderTarget
BLAM ID2D1DeviceContext * GetD2DRenderTarget()
Retrieves the Direct2D render target.
Definition: render_manage.cpp:587
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:453
BlamRendering::DirectX::SetClearColor
BLAM void SetClearColor(ImVec4 color)
Changes the color to used to clear the render target.
Definition: render_manage.cpp:556
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:432
BlamRendering::Vulkan::GetAvailableExtensions
std::vector< VkExtensionProperties > GetAvailableExtensions()
Retrieves the list of all extensions available to Vulkan.
Definition: vulkan.cpp:193
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:631
BlamRendering::DirectX::Initialize
BLAM HRESULT Initialize(HWND hWnd)
Initializes DirectX 11.
Definition: render_manage.cpp:72
BlamRendering::DirectX::UpdateResolution
BLAM HRESULT UpdateResolution(int x, int y)
Changes the DirectX render target resolution.
Definition: resolution.cpp:9
BlamRendering::Vulkan::RenderLoop
void RenderLoop()
Renders engine graphics onscreen.
Definition: vulkan.cpp:237
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:615
BlamRendering::Vulkan::CheckValidationLayerSupport
bool CheckValidationLayerSupport()
Checks whether or not Vulkan's default validation layer is available.
Definition: vulkan.cpp:163
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:544
BlamRendering::DirectX::GetSwapChainDesc
BLAM DXGI_SWAP_CHAIN_DESC GetSwapChainDesc()
Retrieves the current Direct3D Swap Chain description.
Definition: render_manage.cpp:607
BlamRendering::Vulkan::Initialize
void Initialize()
Initializes Vulkan.
Definition: vulkan.cpp:204
BlamRendering::Vulkan::Device::SelectDefaultDevice
void SelectDefaultDevice()
Instructs Vulkan to select the first compatiable device.
Definition: device.cpp:136
BlamRendering::DirectX::HandleWindowResize
BLAM HRESULT HandleWindowResize(LPARAM lParam)
Handles a window resize event.
Definition: render_manage.cpp:295
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:592
BlamRendering::Vulkan::Device::RateDeviceSuitability
int RateDeviceSuitability(VkPhysicalDevice device)
Rates a given physical device based on its capabilities and features.
Definition: device.cpp:40
debug
bool debug
Stores value of debugMode config option, probably should be removed at some point.
Definition: main.cpp:79
BlamRendering::Vulkan::Device::GetDeviceList
std::vector< VkPhysicalDevice > GetDeviceList()
Retrieves the list of physical devices available to Vulkan.
Definition: device.cpp:15
BlamRendering::DirectX::ScreenshotDone
BLAM void ScreenshotDone()
Informs DirectX that the screenshot has finished being captured.
Definition: render_manage.cpp:653
BlamRendering::HandleWindowResize
BLAM void HandleWindowResize(WPARAM wParam, LPARAM lParam)
Definition: rendering_abstraction.cpp:50
BlamRendering::Vulkan::DebugMessenger::PopulateCreateInfo
void PopulateCreateInfo(VkDebugUtilsMessengerCreateInfoEXT *create_info)
Populates debug messenger creation information.
Definition: debug_messenger.cpp:79
BlamRendering::Vulkan::GetRequiredExtensions
std::vector< const char * > GetRequiredExtensions()
Gets a list of required Vulkan extensions.
Definition: vulkan.cpp:147
BlamRendering::Vulkan::DebugMessenger::Initialize
void Initialize()
Initializes the Vulkan debug messenger.
Definition: debug_messenger.cpp:119
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:582
BlamRendering::DirectX::GetDXGISwapChain
BLAM IDXGISwapChain * GetDXGISwapChain()
Retrieves the current DXGI Swap Chain.
Definition: render_manage.cpp:577
BlamRendering::DirectX::DisplayBasicCrashScreen
BLAM void DisplayBasicCrashScreen()
Displays a basic engine crash screen.
Definition: render_manage.cpp:445
BlamRendering::DirectX::GetD3DDevice
BLAM ID3D11Device * GetD3DDevice()
Retrieves the current Direct3D device.
Definition: render_manage.cpp:567
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
Namespace for things relating to rendering.
Definition: drawing.h:14
BlamRendering::DirectX::RenderLoop
BLAM void RenderLoop(bool debug)
Renders everything to the screen.
Definition: render_manage.cpp:359
BlamRendering::DirectX::GetD3DContext
BLAM ID3D11DeviceContext * GetD3DContext()
Retrieves the current Direct3D context.
Definition: render_manage.cpp:572
BlamRendering::DirectX::WIC::GetWICFactory
BLAM IWICImagingFactory * GetWICFactory()
Retrieves the WIC Imaging Factory.
Definition: wic.cpp:43
BlamRendering::Vulkan::Device::IsDeviceSuitable
bool IsDeviceSuitable(VkPhysicalDevice device)
Determines whether or not a given Vulkan device is suitable for the engine's requirements.
Definition: device.cpp:26
BlamRendering::Vulkan::Device::SelectBestDevice
void SelectBestDevice()
Instructs Vulkan to select the best compatiable device.
Definition: device.cpp:92
BlamRendering::Vulkan::Shutdown
void Shutdown()
Shuts down Vulkan.
Definition: vulkan.cpp:242
BLAM
#define BLAM
Definition: rendering.h:14
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:226
BlamRendering::DirectX::HasRenderThreadStopped
BLAM bool HasRenderThreadStopped()
Determines whether or not the render thread has finished stopping.
Definition: render_manage.cpp:315
BlamRendering::DirectX::RenderTargetClearing
BLAM bool * RenderTargetClearing()
Retrieves whether or not to enable render target clearing.
Definition: render_manage.cpp:597
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:325