Skip to content

Commit

Permalink
Scaffolding to add Renderer Options
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Jan 4, 2024
1 parent 9b1569a commit 2a0a25f
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 21 deletions.
5 changes: 0 additions & 5 deletions src/hello_imgui/backend_pointers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ your application behavior using the selected backend.
* `sdlGlContext`: _void *, default=nullptr_. Pointer to SDL's GlContext (of type `SDL_GLContext`).
Only filled if the backend is SDL (or emscripten + sdl)
Note: If using the Metal, Vulkan or DirectX rendering backend, you can find some interesting pointers inside
`src/hello_imgui/internal/backend_impls/rendering_metal.h`
`src/hello_imgui/internal/backend_impls/rendering_vulkan.h`
`src/hello_imgui/internal/backend_impls/rendering_dx11.h`
`src/hello_imgui/internal/backend_impls/rendering_dx12.h`
@@md
*/
struct BackendPointers
Expand Down
22 changes: 21 additions & 1 deletion src/hello_imgui/hello_imgui_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* [Display images](#display-images)
* [HelloImGui::ImageFromAsset](#helloimguiimagefromasset)
* [Backend Pointers](#backend-pointers)
* [Renderer Backend Options](#renderer-backend-options)
* [Store user settings in the ini file](#store-user-settings-in-the-ini-file)
* [Switch between several layouts](#switch-between-several-layouts)

Expand Down Expand Up @@ -128,12 +129,16 @@ int main(){
List of possible additional layout for the applications. Only used in advanced cases when several layouts are available.
* `rememberSelectedAlternativeLayout`: _bool, default=true_
Shall the application remember the last selected layout. Only used in advanced cases when several layouts are available.
* `backendPointers`: _see [backend_pointers.h](backend_pointers.h)_.

* `backendPointers`: _see [backend_pointers.h](backend_pointers.h)_.
A struct that contains optional pointers to the backend implementations. These pointers will be filled
when the application starts
* `backendType`: _enum BackendType, default=BackendType::FirstAvailable_
Select the wanted platform backend type between `Sdl`, `Glfw`. Only useful when multiple backend are compiled
and available.
* `rendererBackendOptions`: _see [renderer_backend_options.h](renderer_backend_options.h)_.
Options for the renderer backend (with specific options for each renderer backend. Currently used for Metal)

* `fpsIdling`: _FpsIdling_. Idling parameters (set fpsIdling.enableIdling to false to disable Idling)
* `useImGuiTestEngine`: _bool, default=false_.
Set this to true if you intend to use imgui_test_engine (please read note below)
Expand Down Expand Up @@ -865,12 +870,27 @@ your application behavior using the selected backend.
* `sdlGlContext`: _void *, default=nullptr_. Pointer to SDL's GlContext (of type `SDL_GLContext`).
Only filled if the backend is SDL (or emscripten + sdl)


## Renderer Backend Options


**RendererBackendOptions** is a struct that contains options for the renderer backend (Metal, Vulkan, DirectX, ...).
Members:
* `metalOptions`: _MetalOptions_. Options for the Metal backend (only filled if the Metal backend is available)


**MetalOptions** is a struct that contains options for the Metal backend.
Members:
* `fixmeDummyOptionName`: _bool, default=false_. Dummy option for Metal backend (to be completed)


Note: If using the Metal, Vulkan or DirectX rendering backend, you can find some interesting pointers inside
`src/hello_imgui/internal/backend_impls/rendering_metal.h`
`src/hello_imgui/internal/backend_impls/rendering_vulkan.h`
`src/hello_imgui/internal/backend_impls/rendering_dx11.h`
`src/hello_imgui/internal/backend_impls/rendering_dx12.h`


## Store user settings in the ini file

See [hello_imgui.h](hello_imgui.h).
Expand Down
4 changes: 4 additions & 0 deletions src/hello_imgui/hello_imgui_api.src.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ See [image_from_asset.h](image_from_asset.h).

@import "backend_pointers.h" {md_id=BackendPointers}

## Renderer Backend Options

@import "renderer_backend_options.h" {md_id=RendererBackendOptions}

## Store user settings in the ini file

See [hello_imgui.h](hello_imgui.h).
Expand Down
5 changes: 3 additions & 2 deletions src/hello_imgui/internal/backend_impls/rendering_metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct GLFWwindow;
#endif

#include "hello_imgui/internal/backend_impls/rendering_callbacks.h"
#include "hello_imgui/renderer_backend_options.h"

#import <Metal/Metal.h>
#import <QuartzCore/QuartzCore.h>
Expand Down Expand Up @@ -39,7 +40,7 @@ namespace HelloImGui
#ifdef HELLOIMGUI_USE_SDL2
RenderingCallbacksPtr CreateBackendCallbacks_SdlMetal();

void PrepareSdlForMetal(SDL_Window* window);
void PrepareSdlForMetal(SDL_Window* window, const RendererBackendOptions& rendererBackendOptions);

struct SdlMetalGlobals
{
Expand All @@ -52,7 +53,7 @@ namespace HelloImGui
#ifdef HELLOIMGUI_USE_GLFW3
RenderingCallbacksPtr CreateBackendCallbacks_GlfwMetal();

void PrepareGlfwForMetal(GLFWwindow* window);
void PrepareGlfwForMetal(GLFWwindow* window, const RendererBackendOptions& rendererBackendOptions);

struct GlfwMetalGlobals
{
Expand Down
14 changes: 9 additions & 5 deletions src/hello_imgui/internal/backend_impls/rendering_metal_glfw.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}

// Below is implementation of RenderingCallbacks_LinkWindowingToRenderingBackend
void PrepareGlfwForMetal(GLFWwindow* glfwWindow)
void PrepareGlfwForMetal(GLFWwindow* glfwWindow, const RendererBackendOptions& rendererBackendOptions)
{
auto& gMetalGlobals = GetMetalGlobals();
auto& gGlfwMetalGlobals = GetGlfwMetalGlobals();
Expand All @@ -44,10 +44,14 @@ void PrepareGlfwForMetal(GLFWwindow* glfwWindow)
gMetalGlobals.caMetalLayer = [CAMetalLayer layer];
gMetalGlobals.caMetalLayer.device = gMetalGlobals.mtlDevice;

// gMetalGlobals.caMetalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
gMetalGlobals.caMetalLayer.pixelFormat = MTLPixelFormatRGBA16Float;
gMetalGlobals.caMetalLayer.wantsExtendedDynamicRangeContent = YES;
gMetalGlobals.caMetalLayer.colorspace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
if (rendererBackendOptions.metalOptions.fixmeDummyOptionName)
{
gMetalGlobals.caMetalLayer.pixelFormat = MTLPixelFormatRGBA16Float;
gMetalGlobals.caMetalLayer.wantsExtendedDynamicRangeContent = YES;
gMetalGlobals.caMetalLayer.colorspace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
}
else
gMetalGlobals.caMetalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;

nswin.contentView.layer = gMetalGlobals.caMetalLayer;
nswin.contentView.wantsLayer = YES;
Expand Down
16 changes: 11 additions & 5 deletions src/hello_imgui/internal/backend_impls/rendering_metal_sdl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

// Below is implementation of RenderingCallbacks_LinkWindowingToRenderingBackend
void PrepareSdlForMetal(SDL_Window* sdlWindow)
void PrepareSdlForMetal(SDL_Window* sdlWindow, const RendererBackendOptions& rendererBackendOptions)
{
auto& gMetalGlobals = GetMetalGlobals();
auto& gSdlMetalGlobals = GetSdlMetalGlobals();
Expand All @@ -41,10 +41,16 @@ void PrepareSdlForMetal(SDL_Window* sdlWindow)

// Setup Platform/Renderer backends
gMetalGlobals.caMetalLayer = (__bridge CAMetalLayer*)SDL_RenderGetMetalLayer(gSdlMetalGlobals.sdlRenderer);
// gMetalGlobals.caMetalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
gMetalGlobals.caMetalLayer.pixelFormat = MTLPixelFormatRGBA16Float;
gMetalGlobals.caMetalLayer.wantsExtendedDynamicRangeContent = YES;
gMetalGlobals.caMetalLayer.colorspace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);

if (rendererBackendOptions.metalOptions.fixmeDummyOptionName)
{
gMetalGlobals.caMetalLayer.pixelFormat = MTLPixelFormatRGBA16Float;
gMetalGlobals.caMetalLayer.wantsExtendedDynamicRangeContent = YES;
gMetalGlobals.caMetalLayer.colorspace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
}
else
gMetalGlobals.caMetalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;

}
{
ImGui_ImplMetal_Init(gMetalGlobals.caMetalLayer.device);
Expand Down
2 changes: 1 addition & 1 deletion src/hello_imgui/internal/backend_impls/runner_glfw3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace HelloImGui
}
void RunnerGlfw3::Impl_LinkPlatformAndRenderBackends()
{
PrepareGlfwForMetal((GLFWwindow *) mWindow);
PrepareGlfwForMetal((GLFWwindow *) mWindow, params.rendererBackendOptions);
}

#elif defined(HELLOIMGUI_HAS_VULKAN)
Expand Down
2 changes: 1 addition & 1 deletion src/hello_imgui/internal/backend_impls/runner_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ namespace HelloImGui
}
void RunnerSdl2::Impl_LinkPlatformAndRenderBackends()
{
PrepareSdlForMetal((SDL_Window*)mWindow);
PrepareSdlForMetal((SDL_Window*)mWindow, params.rendererBackendOptions);
}
#endif
#ifdef HELLOIMGUI_HAS_VULKAN
Expand Down
44 changes: 44 additions & 0 deletions src/hello_imgui/renderer_backend_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once


namespace HelloImGui
{
/**
@@md#RendererBackendOptions
**RendererBackendOptions** is a struct that contains options for the renderer backend (Metal, Vulkan, DirectX, ...).
Members:
* `metalOptions`: _MetalOptions_. Options for the Metal backend (only filled if the Metal backend is available)
**MetalOptions** is a struct that contains options for the Metal backend.
Members:
* `fixmeDummyOptionName`: _bool, default=false_. Dummy option for Metal backend (to be completed)
Note: If using the Metal, Vulkan or DirectX rendering backend, you can find some interesting pointers inside
`src/hello_imgui/internal/backend_impls/rendering_metal.h`
`src/hello_imgui/internal/backend_impls/rendering_vulkan.h`
`src/hello_imgui/internal/backend_impls/rendering_dx11.h`
`src/hello_imgui/internal/backend_impls/rendering_dx12.h`
@@md
*/


#ifdef HELLOIMGUI_HAS_METAL
struct MetalOptions
{
// to be completed
bool fixmeDummyOptionName = false;
};
#endif

struct RendererBackendOptions
{
#ifdef HELLOIMGUI_HAS_METAL
MetalOptions metalOptions;
#endif
};

} // namespace HelloImGui
9 changes: 8 additions & 1 deletion src/hello_imgui/runner_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "hello_imgui/runner_callbacks.h"
#include "hello_imgui/docking_params.h"
#include "hello_imgui/backend_pointers.h"
#include "hello_imgui/renderer_backend_options.h"


#include <vector>

Expand Down Expand Up @@ -103,12 +105,16 @@ struct FpsIdling
List of possible additional layout for the applications. Only used in advanced cases when several layouts are available.
* `rememberSelectedAlternativeLayout`: _bool, default=true_
Shall the application remember the last selected layout. Only used in advanced cases when several layouts are available.
* `backendPointers`: _see [backend_pointers.h](backend_pointers.h)_.
* `backendPointers`: _see [backend_pointers.h](backend_pointers.h)_.
A struct that contains optional pointers to the backend implementations. These pointers will be filled
when the application starts
* `backendType`: _enum BackendType, default=BackendType::FirstAvailable_
Select the wanted platform backend type between `Sdl`, `Glfw`. Only useful when multiple backend are compiled
and available.
* `rendererBackendOptions`: _see [renderer_backend_options.h](renderer_backend_options.h)_.
Options for the renderer backend (with specific options for each renderer backend. Currently used for Metal)
* `fpsIdling`: _FpsIdling_. Idling parameters (set fpsIdling.enableIdling to false to disable Idling)
* `useImGuiTestEngine`: _bool, default=false_.
Set this to true if you intend to use imgui_test_engine (please read note below)
Expand Down Expand Up @@ -152,6 +158,7 @@ struct RunnerParams

BackendPointers backendPointers;
BackendType backendType = BackendType::FirstAvailable;
RendererBackendOptions rendererBackendOptions;

FpsIdling fpsIdling;

Expand Down

0 comments on commit 2a0a25f

Please sign in to comment.