Skip to content

Commit

Permalink
Added custom native handle support to render system. Currently only i…
Browse files Browse the repository at this point in the history
…mplemented for GL backend on Windows and Linux.

- Added "nativeHandle" and "nativeHandleSize" fields to RenderSystemDescriptor struct.
- Implemented GetNativeHandle() function in GLRenderSystem.
- Updated Test_OpenGL project to test custom WGL context for Win32.
  • Loading branch information
LukasBanana committed Jan 21, 2024
1 parent 76ab650 commit 2028ee5
Show file tree
Hide file tree
Showing 42 changed files with 749 additions and 161 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ set( EXAMPLE_CSHARP_PROJECTS_DIR "${EXAMPLE_PROJECTS_ROOT_DIR}/CSharp" )
set( EXAMPLEBASE_PROJECT_DIR "${EXAMPLE_CPP_PROJECTS_DIR}/ExampleBase" )
set( EXAMPLE_MEDIA_DIR "${EXAMPLE_PROJECTS_ROOT_DIR}/Media" )
set( TEST_PROJECTS_DIR "${PROJECT_SOURCE_DIR}/tests" )
set( BACKEND_INCLUDE_DIR "${PROJECT_INCLUDE_DIR}/LLGL/Backend" )


# === Macros ===
Expand Down Expand Up @@ -122,6 +123,8 @@ function(find_source_files OUTPUT_LIST FILTERS)
set(FILTERS "*.c;*.cpp;*.h;*.inl;*.m;*.mm")
elseif("${FILTERS}" STREQUAL "RES")
set(FILTERS "*.c;*.cpp;*.h;*.inl;*.m;*.mm;*.metal;*.vert;*.frag")
elseif("${FILTERS}" STREQUAL "INC")
set(FILTERS "*.h;*.hpp;*.inl")
endif()

# Collect all input directories for each filter
Expand Down
2 changes: 2 additions & 0 deletions include/LLGL-C/LLGLWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,8 @@ typedef struct LLGLRenderSystemDescriptor
LLGLRenderingDebugger debugger; /* = LLGL_NULL_OBJECT */
const void* rendererConfig; /* = NULL */
size_t rendererConfigSize; /* = 0 */
const void* nativeHandle; /* = NULL */
size_t nativeHandleSize; /* = 0 */
#if defined LLGL_OS_ANDROID
android_app* androidApp;
#endif /* defined LLGL_OS_ANDROID */
Expand Down
5 changes: 5 additions & 0 deletions include/LLGL/Backend/Direct3D11/NativeHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace Direct3D11
{


/**
\brief Native handle structure for the Direct3D 11 render system.
\see RenderSystem::GetNativeHandle
\see RenderSystemDescriptor::nativeHandle
*/
struct RenderSystemNativeHandle
{
ID3D11Device* device;
Expand Down
5 changes: 5 additions & 0 deletions include/LLGL/Backend/Direct3D12/NativeHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace Direct3D12
{


/**
\brief Native handle structure for the Direct3D 12 render system.
\see RenderSystem::GetNativeHandle
\see RenderSystemDescriptor::nativeHandle
*/
struct RenderSystemNativeHandle
{
ID3D12Device* device;
Expand Down
42 changes: 42 additions & 0 deletions include/LLGL/Backend/OpenGL/Android/AndroidNativeHandle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* AndroidNativeHandle.h (OpenGL)
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_OPENGL_ANDROID_NATIVE_HANDLE_H
#define LLGL_OPENGL_ANDROID_NATIVE_HANDLE_H


#include <EGL/egl.h>


namespace LLGL
{

namespace OpenGL
{


/**
\brief Android native handle structure for the OpenGL render system.
\see RenderSystem::GetNativeHandle
\see RenderSystemDescriptor::nativeHandle
*/
struct RenderSystemNativeHandle
{
EGLContext context;
};


} // /namespace OpenGL

} // /namespace LLGL


#endif



// ================================================================================
42 changes: 42 additions & 0 deletions include/LLGL/Backend/OpenGL/IOS/IOSNativeHandle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* IOSNativeHandle.h (OpenGL)
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_OPENGL_IOS_NATIVE_HANDLE_H
#define LLGL_OPENGL_IOS_NATIVE_HANDLE_H


#include <OpenGLES/EAGL.h>


namespace LLGL
{

namespace OpenGL
{


/**
\brief iOS native handle structure for the OpenGL render system.
\see RenderSystem::GetNativeHandle
\see RenderSystemDescriptor::nativeHandle
*/
struct RenderSystemNativeHandle
{
EAGLContext* context;
};


} // /namespace OpenGL

} // /namespace LLGL


#endif



// ================================================================================
42 changes: 42 additions & 0 deletions include/LLGL/Backend/OpenGL/Linux/LinuxNativeHandle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* LinuxNativeHandle.h (OpenGL)
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_OPENGL_LINUX_NATIVE_HANDLE_H
#define LLGL_OPENGL_LINUX_NATIVE_HANDLE_H


#include <GL/glx.h>


namespace LLGL
{

namespace OpenGL
{


/**
\brief GNU/Linux native handle structure for the OpenGL render system.
\see RenderSystem::GetNativeHandle
\see RenderSystemDescriptor::nativeHandle
*/
struct RenderSystemNativeHandle
{
GLXContext context;
};


} // /namespace OpenGL

} // /namespace LLGL


#endif



// ================================================================================
42 changes: 42 additions & 0 deletions include/LLGL/Backend/OpenGL/MacOS/MacOSNativeHandle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* MacOSNativeHandle.h (OpenGL)
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_OPENGL_MACOS_NATIVE_HANDLE_H
#define LLGL_OPENGL_MACOS_NATIVE_HANDLE_H


#include <Cocoa/Cocoa.h>


namespace LLGL
{

namespace OpenGL
{


/**
\brief macOS native handle structure for the OpenGL render system.
\see RenderSystem::GetNativeHandle
\see RenderSystemDescriptor::nativeHandle
*/
struct RenderSystemNativeHandle
{
NSOpenGLContext* context;
};


} // /namespace OpenGL

} // /namespace LLGL


#endif



// ================================================================================
31 changes: 31 additions & 0 deletions include/LLGL/Backend/OpenGL/NativeHandle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* NativeHandle.h (OpenGL)
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_OPENGL_NATIVE_HANDLE_H
#define LLGL_OPENGL_NATIVE_HANDLE_H


#include <LLGL/Platform/Platform.h>

#if defined(LLGL_OS_WIN32)
# include <LLGL/Backend/OpenGL/Win32/Win32NativeHandle.h>
#elif defined(LLGL_OS_MACOS)
# include <LLGL/Backend/OpenGL/MacOS/MacOSNativeHandle.h>
#elif defined(LLGL_OS_LINUX)
# include <LLGL/Backend/OpenGL/Linux/LinuxNativeHandle.h>
#elif defined(LLGL_OS_IOS)
# include <LLGL/Backend/OpenGL/IOS/IOSNativeHandle.h>
#elif defined(LLGL_OS_ANDROID)
# include <LLGL/Backend/OpenGL/Android/AndroidNativeHandle.h>
#endif


#endif



// ================================================================================
44 changes: 44 additions & 0 deletions include/LLGL/Backend/OpenGL/Win32/Win32NativeHandle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Win32NativeHandle.h (OpenGL)
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

#ifndef LLGL_OPENGL_WIN32_NATIVE_HANDLE_H
#define LLGL_OPENGL_WIN32_NATIVE_HANDLE_H


#include <Windows.h>
#include <GL/gl.h>
#include <GL/wglext.h>


namespace LLGL
{

namespace OpenGL
{


/**
\brief Windows native handle structure for the OpenGL render system.
\see RenderSystem::GetNativeHandle
\see RenderSystemDescriptor::nativeHandle
*/
struct RenderSystemNativeHandle
{
HGLRC context;
};


} // /namespace OpenGL

} // /namespace LLGL


#endif



// ================================================================================
5 changes: 5 additions & 0 deletions include/LLGL/Backend/Vulkan/NativeHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ namespace Vulkan
{


/**
\brief Native handle structure for the Vulkan render system.
\see RenderSystem::GetNativeHandle
\see RenderSystemDescriptor::nativeHandle
*/
struct RenderSystemNativeHandle
{
VkInstance instance;
Expand Down
1 change: 1 addition & 0 deletions include/LLGL/DisplayFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct DisplayMode
std::uint32_t refreshRate = 0;
};

//! \deprecated Since 0.04b; Use LLGL::DisplayMode instead!
LLGL_DEPRECATED("LLGL::DisplayModeDescriptor is deprecated since 0.04b; Use LLGL::DisplayMode instead!", "DisplayMode")
typedef DisplayMode DisplayModeDescriptor;

Expand Down
2 changes: 1 addition & 1 deletion include/LLGL/Platform/Android/AndroidNativeHandle.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AndroidNativeHandle.h
*
* This file is part of the "LLGL" project (Copyright (c) 2015 by Lukas Hermanns)
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

Expand Down
2 changes: 1 addition & 1 deletion include/LLGL/Platform/IOS/IOSNativeHandle.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* IOSNativeHandle.h
*
* This file is part of the "LLGL" project (Copyright (c) 2015 by Lukas Hermanns)
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

Expand Down
2 changes: 1 addition & 1 deletion include/LLGL/Platform/Linux/LinuxNativeHandle.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* LinuxNativeHandle.h
*
* This file is part of the "LLGL" project (Copyright (c) 2015 by Lukas Hermanns)
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/

Expand Down
37 changes: 35 additions & 2 deletions include/LLGL/RenderSystemFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,45 @@ struct RenderSystemDescriptor
const void* rendererConfig = nullptr;

/**
\brief Specifies the size (in bytes) of the structure where the \c rendererConfig member points to (use \c sizeof with the respective structure). By default 0.
\remarks If \c rendererConfig is null then this member is ignored.
\brief Specifies the size (in bytes) of the structure \c rendererConfig points to (use \c sizeof with the respective structure). By default 0.
\remarks If \c rendererConfig is null then this field is ignored.
\see rendererConfig
*/
std::size_t rendererConfigSize = 0;

/**
\brief Optional raw pointer to a backend specific native handle structure. If this is null (default), the render system will creates its own native handles.
These native handles can later be queried via RenderSystem::GetNativeHandle.
\remarks This can be used to pass the native device instance or render context for the respective backend if the application has created its own instance.
Example usage (for Direct3D12 renderer):
\code
// Create own D3D12 device object
ID3D12Device* myD3D12Device = D3D12CreateDevice(...);
// Initialize native handle for D3D12
LLGL::Direct3D12::RenderSystemNativeHandle nativeHandleD3D12;
nativeHandleD3D12.device = myD3D12Device;
// Load D3D12 render system
LLGL::RenderSystemDescriptor rendererDesc;
rendererDesc.moduleName = "Direct3D12";
rendererDesc.nativeHandle = &nativeHandleD3D12;
rendererDesc.nativeHandleSize = sizeof(nativeHandleD3D12);
auto renderer = LLGL::RenderSystem::Load(rendererDesc);
\endcode
\see RenderSystem::GetNativeHandle
\note Currently only supported for OpenGL on Windows and Linux.
\todo Add support for all other backends.
*/
const void* nativeHandle = nullptr;

/**
\brief Specifies the size (in bytes) of the structure \c nativeHandle points to (use \c sizeof with the respective structure). By default 0.
\remarks If \c nativeHandle is null then this field is ignored.
\see nativeHandle
*/
std::size_t nativeHandleSize = 0;

#ifdef LLGL_OS_ANDROID

/**
Expand Down
Loading

0 comments on commit 2028ee5

Please sign in to comment.