Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DirectX 12] Backend #648

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion Backends/RmlUi_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,61 @@ using KeyDownCallback = bool (*)(Rml::Context* context, Rml::Input::KeyIdentifie
*/
namespace Backend {

/// @brief This class defines information for not initializating renderers fully. Fully initialization means that renderer on RmlUi side will
/// initialize device, queues and other things by its own (in case of OpenGL it will load functions & will init OpenGL) so in case where you already
/// have own renderer and that renderer is initialized you want to prevent a such initialization and thus RmlUi needs to know user data.
class RmlRenderInitInfo {
public:
/// @brief This is constructor for initializing class
/// @param p_user_device ID3D12Device raw pointer (e.g. ID3D12Device* don't pass ComPtr instance!) or you pass VkDevice instance.
RmlRenderInitInfo(void* p_window_handle, void* p_user_device, bool use_vsync) :
m_is_full_initialization{true}, m_is_use_vsync{use_vsync}, m_p_native_window_handle{p_window_handle}, m_p_user_device{p_user_device}
{
RMLUI_ASSERT(p_user_device &&
"if you want to initialize renderer by system you don't need to pass this parameter as nullptr just use second constructor and set "
"is_full_initialization to true!");
}

/// @brief This is constructor for older graphics API where don't require Devices, Queues etc...
/// @param p_window_handle HWND or similar types to OS's window handle
RmlRenderInitInfo(void* p_window_handle, bool is_full_initialization, bool use_vsync) :
m_is_full_initialization{is_full_initialization}, m_is_use_vsync{use_vsync}, m_p_native_window_handle{p_window_handle}, m_p_user_device{}
{}

~RmlRenderInitInfo() {}

/// @brief Returns hidden type of ID3D12Device* or VkDevice; It is user's responsibility to pass a valid type for it otherwise system will be
/// broken and renderer couldn't be initialized!
/// @return you need to use reinterpret_cast to ID3D12Device* type or VkDevice. Depends on what user wants to initialize.
void* Get_UserDevice() { return this->m_p_user_device; }

/// @brief Returns hidden type of native window handle (on Windows e.g. HWND)
/// @return window native type of handle (HWND etc depends on OS)
void* Get_WindowHandle() { return this->m_p_native_window_handle; }

/// @brief returns flag of full initialization. It means that if user wants full initialization that system will create and initialize GAPI and
/// renderer by its own. In case of OpenGL system loads functions and initialize renderer, io case of DirectX 12 and Vulkan system initializes
/// Device, Queues and etc. Otherwise it is not full initialization and user passed own Device, Queues or set is_full_initialize to false in
/// the second constructor for older GAPIs like OpenGL
/// @param nothing, because it is getter
/// @return field of class m_is_full_initialization if it is true it means that user didn't passed Device, Queues from user's renderer or set
/// is_full_initialization to true
bool Is_FullInitialization(void) const { return this->m_is_full_initialization; }

bool Is_UseVSync() const { return this->m_is_use_vsync; }

private:
bool m_is_full_initialization;
/// @brief use vsync feature of render api (if supports at all); true = means enable feature; false = disable feature.
bool m_is_use_vsync;
/// @brief it is user's handle of OS's handle, so if it is Windows you pass HWND* here
void* m_p_native_window_handle;
/// @brief Type that hides ID3D12Device*, VkDevice or something else depends on context and which renderer user initializes
void* m_p_user_device;
};

// Initializes the backend, including the custom system and render interfaces, and opens a window for rendering the RmlUi context.
bool Initialize(const char* window_name, int width, int height, bool allow_resize);
bool Initialize(const char* window_name, int width, int height, bool allow_resize, RmlRenderInitInfo* p_info = nullptr);
// Closes the window and release all resources owned by the backend, including the system and render interfaces.
void Shutdown();

Expand Down
2 changes: 1 addition & 1 deletion Backends/RmlUi_Backend_SDL_GL3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct BackendData {
};
static Rml::UniquePtr<BackendData> data;

bool Backend::Initialize(const char* window_name, int width, int height, bool allow_resize)
bool Backend::Initialize(const char* window_name, int width, int height, bool allow_resize, RmlRenderInitInfo* p_info)
{
RMLUI_ASSERT(!data);

Expand Down
Loading