Elaztek Developer Hub
Blamite Game Engine - blam!  00346.12.11.21.0529.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 
18 
19 #ifndef BLAM
20 #define BLAM
21 #endif
22 
24 {
30 };
31 
35 namespace BlamRendering
36 {
42  namespace Vulkan
43  {
47  namespace DebugMessenger
48  {
52  BLAM void Initialize();
53 
57  BLAM void Shutdown();
58 
62  BLAM void PopulateCreateInfo(VkDebugUtilsMessengerCreateInfoEXT* create_info);
63  }
64 
68  namespace Device
69  {
75  BLAM std::vector<VkPhysicalDevice> GetDeviceList();
76 
84  BLAM bool IsDeviceSuitable(VkPhysicalDevice device);
85 
93  BLAM int RateDeviceSuitability(VkPhysicalDevice device);
94 
104  BLAM void SelectManualDevice(int device_index);
105 
115  BLAM void SelectBestDevice();
116 
124  BLAM void SelectDefaultDevice();
125 
129  BLAM void CreateLogicalDevice();
130 
134  BLAM void DestroyLogicalDevice();
135  }
136 
140  namespace Presentation
141  {
145  BLAM void CreateSurface();
146 
152  BLAM VkSurfaceKHR* GetSurface();
153 
157  BLAM void DestroySurface();
158 
164  BLAM VkQueue* GetPresentQueue();
165  }
166 
170  BLAM void Initialize();
171 
178  BLAM void RenderLoop();
179 
185  BLAM void Shutdown();
186 
193 
197  BLAM VkInstance* GetInstance();
198 
203 
207  BLAM std::vector<const char*> GetEnabledLayers();
208 
212  BLAM std::vector<VkExtensionProperties> GetAvailableExtensions();
213 
217  BLAM std::vector<VkLayerProperties> GetAvailableLayers();
218 
222  BLAM std::vector<const char*> GetRequiredExtensions();
223 
228  }
229 
235  namespace DirectX
236  {
240  namespace D2D
241  {
247  BLAM ID2D1DeviceContext* GetD2DRenderTarget();
248 
254  BLAM ID2D1Factory* GetD2DFactory();
255 
261  BLAM IDWriteFactory* GetDWriteFactory();
262 
271  BLAM HRESULT LoadFontFromFile(std::string id, std::string file_path);
272  }
273 
277  namespace WIC
278  {
284  BLAM IWICImagingFactory* GetWICFactory();
285 
297  BLAM HRESULT CreateD2DBitmapFromResource(int res_id, const char* res_type, ID2D1Bitmap **bitmap_pointer);
298 
307  BLAM HRESULT CreateD2DBitmapFromFile(std::wstring path, ID2D1Bitmap **bitmap_pointer);
308 
317  BLAM HRESULT CreateWICBitmapFromFile(std::wstring path, IWICBitmap** bitmap_pointer);
318 
328  BLAM HRESULT CreateWICBitmapFromMemory(void* data, int size, IWICBitmap** bitmap_pointer);
329 
338  BLAM HRESULT ConvertWICBitmapToD2D(IWICBitmap* wic_bitmap, ID2D1Bitmap** d2d_bitmap);
339 
349  BLAM HRESULT ConvertWICBitmapToD2D(IWICBitmap* wic_bitmap, ID2D1Bitmap** d2d_bitmap, ID2D1RenderTarget* render_target);
350 
359  BLAM HRESULT ConvertWICBitmapTo32bppPBGRA(IWICBitmap* source, IWICBitmap** destination);
360 
369  BLAM HRESULT Initialize();
370 
377  BLAM void Shutdown();
378  }
379 
385  BLAM ID3D11Device* GetD3DDevice();
386 
392  BLAM ID3D11DeviceContext* GetD3DContext();
393 
404  BLAM IDXGISwapChain* GetDXGISwapChain();
405 
411  BLAM ID3D11RenderTargetView* GetD3DRenderTargetView();
412 
418  BLAM DXGI_SWAP_CHAIN_DESC GetSwapChainDesc();
419 
430  BLAM HRESULT Initialize(HWND hWnd);
431 
438  BLAM void Cleanup();
439 
451  BLAM HRESULT HandleWindowResize(LPARAM lParam);
452 
460  BLAM bool* RenderTargetClearing();
461 
472  BLAM void RenderLoop(bool debug);
473 
481  BLAM void ShutdownRenderThread();
482 
493  BLAM void RenderThread(bool debug);
494 
504 
510  BLAM void SetClearColor(ImVec4 color);
511 
518 
527  BLAM HRESULT UpdateResolution(int x, int y);
528 
534  BLAM ID3D11Texture2D** GetLastFrameTexture();
535 
542  BLAM HRESULT GetLastFrameTextureAlt(ID3D11Texture2D* texture);
543 
550  BLAM void ScreenshotDone();
551 
558  BLAM HRESULT GetLastFrameHResult();
559 
569  BLAM void DisplayDetailedCrashScreen(const char* expression, const char* file, int line, std::string details);
570 
576 
581  BLAM void DisplaySignalCrashScreen(int signal);
582  }
583 
589  namespace OpenGL
590  {
596  BLAM BlamResult Initialize();
597 
601  BLAM void RenderLoop();
602 
606  BLAM void Shutdown();
607 
613  BLAM SDL_GLContext* GetGLContext();
614  }
615 
619  namespace BGFX
620  {
621  BLAM void SetPlatformData();
622 
623  BLAM void Initialize();
624  BLAM void RenderLoop();
625  BLAM void Shutdown();
626 
627  BLAM void HandleWindowReisze(int width, int height);
628 
629  BLAM void SetViewClearFlags(int new_flags);
630 
631  BLAM uint16_t Get3DViewID();
632  BLAM uint16_t Get2DViewID();
633 
634  BLAM int GetRenderWidth();
635  BLAM int GetRenderHeight();
636  }
637 
639  // Abstract/Shared Functions, these will usually interface with the active graphics API themselves //
641 
648 
654  BLAM void SetClearColor(ImVec4 color);
655 
662 
671  BLAM void ShowCrashScreen(const char* exc, const char* file, int line, std::string message);
672 
681  BLAM HRESULT SetDisplayRes(int x, int y); //Sets screen resolution
682 
683 
684  BLAM void HandleWindowResize(int width, int height, WPARAM wParam);
685 }
686 
687 namespace Blam
688 {
692  BLAM void TakeScreenshot();
693 }
Blam
Namespace surrounding all major engine components.
Definition: blam_api.h:21
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:171
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:19
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
imgui.h
BlamRendering::DirectX::D2D::GetDWriteFactory
BLAM IDWriteFactory * GetDWriteFactory()
Retrieves the DirectWrite factory.
Definition: render_manage.cpp:573
ImVec4
Definition: imgui.h:192
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
BlamRendering::BGFX::HandleWindowReisze
BLAM void HandleWindowReisze(int width, int height)
Definition: bgfx.cpp:151
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:144
BlamRendering::BGFX::GetRenderHeight
BLAM int GetRenderHeight()
Definition: bgfx.cpp:191
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
y
font DisplayOffset y
Definition: README.txt:68
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
BlamRendering::BGFX::GetRenderWidth
BLAM int GetRenderWidth()
Definition: bgfx.cpp:186
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:20
BlamRendering
Namespace for things relating to rendering.
Definition: primitives.h:24
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
BlamRendering::BGFX::Get3DViewID
BLAM uint16_t Get3DViewID()
Definition: bgfx.cpp:176
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
x
config GlyphExtraSpacing x
Definition: README.txt:30
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:28
BlamRendering::DirectX::HasRenderThreadStopped
BLAM bool HasRenderThreadStopped()
Determines whether or not the render thread has finished stopping.
Definition: render_manage.cpp:326
BlamRendering::BGFX::Get2DViewID
BLAM uint16_t Get2DViewID()
Definition: bgfx.cpp:181
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