Skip to content

Commit

Permalink
requestFloatBuffer option
Browse files Browse the repository at this point in the history
  • Loading branch information
wkjarosz committed Jan 12, 2024
1 parent cd4de2c commit b28e630
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 23 deletions.
17 changes: 17 additions & 0 deletions src/hello_imgui/internal/backend_impls/rendering_metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,26 @@
#include <backends/imgui_impl_metal.h>
#include "hello_imgui/hello_imgui.h"

#import <Cocoa/Cocoa.h>

namespace HelloImGui
{
bool hasEdrSupport()
{
NSArray<NSScreen *> * screens = [NSScreen screens];
bool buffer_edr = false;

for (NSScreen * screen in screens) {
if ([screen respondsToSelector:@selector
(maximumPotentialExtendedDynamicRangeColorComponentValue)]) {
if ([screen maximumPotentialExtendedDynamicRangeColorComponentValue] >= 2.f)
buffer_edr = true;
}
}

return buffer_edr;
}

MetalGlobals& GetMetalGlobals()
{
static MetalGlobals sMetalGlobals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void PrepareGlfwForMetal(GLFWwindow* glfwWindow, const RendererBackendOptions& r
gMetalGlobals.caMetalLayer = [CAMetalLayer layer];
gMetalGlobals.caMetalLayer.device = gMetalGlobals.mtlDevice;

if (rendererBackendOptions.metalOptions.fixmeDummyOptionName)
if (rendererBackendOptions.requestFloatBuffer)
{
gMetalGlobals.caMetalLayer.pixelFormat = MTLPixelFormatRGBA16Float;
gMetalGlobals.caMetalLayer.wantsExtendedDynamicRangeContent = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void PrepareSdlForMetal(SDL_Window* sdlWindow, const RendererBackendOptions& ren
// Setup Platform/Renderer backends
gMetalGlobals.caMetalLayer = (__bridge CAMetalLayer*)SDL_RenderGetMetalLayer(gSdlMetalGlobals.sdlRenderer);

if (rendererBackendOptions.metalOptions.fixmeDummyOptionName)
if (rendererBackendOptions.requestFloatBuffer)
{
gMetalGlobals.caMetalLayer.pixelFormat = MTLPixelFormatRGBA16Float;
gMetalGlobals.caMetalLayer.wantsExtendedDynamicRangeContent = YES;
Expand Down
11 changes: 11 additions & 0 deletions src/hello_imgui/renderer_backend_options.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "renderer_backend_options.h"

namespace HelloImGui
{

// currently, only the metal backend has support for this
#ifndef HELLOIMGUI_HAS_METAL
bool hasEdrSupport() { return false; }
#endif

} // namespace HelloImGui
40 changes: 19 additions & 21 deletions src/hello_imgui/renderer_backend_options.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
#pragma once


namespace HelloImGui
{

/**
@@md#RendererBackendOptions
Check whether extended dynamic range (EDR), i.e. the ability to reproduce intensities exceeding the
standard dynamic range from 0.0-1.0, is supported.
**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)
To leverage EDR support, you will need to set `floatBuffer=true` in `RendererBackendOptions`.
Only the macOS Metal backend currently supports this.
\return This currently returns false on all backends except Metal, where it checks whether this is
supported on the current displays.
*/
bool hasEdrSupport();

/**
@@md#RendererBackendOptions
**MetalOptions** is a struct that contains options for the Metal backend.
Members:
* `fixmeDummyOptionName`: _bool, default=false_. Dummy option for Metal backend (to be completed)
**RendererBackendOptions** is a struct that contains options for the renderer backend (Metal, Vulkan, DirectX,
...). Members:
* `requestFloatBuffer`: _bool, default=false_. Set to true to request a floating-point framebuffer.
Before setting this to true, first check `hasEdrSupport`
Note: If using the Metal, Vulkan or DirectX rendering backend, you can find some interesting pointers inside
Expand All @@ -25,20 +33,10 @@ Note: If using the Metal, Vulkan or DirectX rendering backend, you can find some
@@md
*/


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

struct RendererBackendOptions
{
#ifdef HELLOIMGUI_HAS_METAL
MetalOptions metalOptions;
#endif

bool requestFloatBuffer = false;
};

} // namespace HelloImGui
} // namespace HelloImGui
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ It demonstrates how to:
*/

#include "hello_imgui/hello_imgui.h"
#include "hello_imgui/renderer_backend_options.h"
#include "imgui.h"
#include "misc/cpp/imgui_stdlib.h"
#include "imgui_internal.h"
Expand Down Expand Up @@ -629,6 +630,13 @@ int main(int, char**)
runnerParams.appWindowParams.borderlessResizable = true;
runnerParams.appWindowParams.borderlessClosable = true;

// test EDR support on macOS/Metal
bool requestEDR = HelloImGui::hasEdrSupport();
runnerParams.rendererBackendOptions.requestFloatBuffer = requestEDR;
HelloImGui::Log(HelloImGui::LogLevel::Info,
"Creating a %s framebuffer.",
requestEDR ? "floating-point precision" : "standard precision");

// Load additional font
runnerParams.callbacks.LoadAdditionalFonts = [&appState]() { LoadFonts(appState); };

Expand Down

0 comments on commit b28e630

Please sign in to comment.