Skip to content
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
5 changes: 4 additions & 1 deletion Imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project(Diligent-Imgui CXX)
set(SOURCE
src/ImGuiDiligentRenderer.cpp
src/ImGuiImplDiligent.cpp
src/ImGuiDiligentFileIO.cpp
src/ImGuiUtils.cpp
)

Expand Down Expand Up @@ -126,7 +127,9 @@ if(PLATFORM_UNIVERSAL_WINDOWS)
target_compile_definitions(Diligent-Imgui PRIVATE IMGUI_DISABLE_WIN32_FUNCTIONS)
endif()

target_compile_definitions(Diligent-Imgui PUBLIC IMGUI_DEFINE_MATH_OPERATORS)
target_compile_definitions(Diligent-Imgui PUBLIC
IMGUI_USER_CONFIG="ImGuiDiligentConfig.h"
)

if(PLATFORM_WIN32 AND MINGW_BUILD)
# Link with dwmapi.lib as imgui_impl_win32.cpp skips
Expand Down
58 changes: 58 additions & 0 deletions Imgui/interface/ImGuiDiligentConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2026 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* In no event and under no legal theory, whether in tort (including negligence),
* contract, or otherwise, unless required by applicable law (such as deliberate
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
* liable for any damages, including any direct, indirect, special, incidental,
* or consequential damages of any character arising as a result of this License or
* out of the use or inability to use the software (including but not limited to damages
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
* all other commercial damages or losses), even if such Contributor has been advised
* of the possibility of such damages.
*/

#pragma once

#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS
#define IMGUI_DEFINE_MATH_OPERATORS

namespace Diligent
{

#if PLATFORM_WIN32
class WindowsFile;
using ImGuiFile = WindowsFile;
#elif PLATFORM_UNIVERSAL_WINDOWS
class WindowsStoreFile;
using ImGuiFile = WindowsStoreFile;
#elif PLATFORM_ANDROID
class AndroidFile;
using ImGuiFile = AndroidFile;
#else
class StandardFile;
using ImGuiFile = StandardFile;
#endif

} // namespace Diligent
Comment on lines +32 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


using ImFileHandle = Diligent::ImGuiFile*;
using ImU64 = unsigned long long;

ImFileHandle ImFileOpen(const char* pFileName, const char* pMode);
bool ImFileClose(ImFileHandle pFile);
ImU64 ImFileGetSize(ImFileHandle pFile);
ImU64 ImFileRead(void* pData, ImU64 Size, ImU64 Count, ImFileHandle pFile);
ImU64 ImFileWrite(const void* pData, ImU64 Size, ImU64 Count, ImFileHandle pFile);
87 changes: 87 additions & 0 deletions Imgui/src/ImGuiDiligentFileIO.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImGui changes seem to be unrelated to WebGPU on Mac?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn’t want to create a separate PR(we can use rebase instead squash). On macOS, ImGui runs into an issue when using ImIO.Fonts->AddFontFromFileTTF, since internally it uses fopen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be submitted separately - we need to merge this into development first and then try to build the main module to make sure all tests pass since it affects all platforms.

* Copyright 2026 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* In no event and under no legal theory, whether in tort (including negligence),
* contract, or otherwise, unless required by applicable law (such as deliberate
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
* liable for any damages, including any direct, indirect, special, incidental,
* or consequential damages of any character arising as a result of this License or
* out of the use or inability to use the software (including but not limited to damages
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
* all other commercial damages or losses), even if such Contributor has been advised
* of the possibility of such damages.
*/

#include "ImGuiDiligentConfig.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think ImGuiDiligentConfig.h is helpful (unless it needs to be included somewhere else).
The function definitions can be added right in the source file here - it will be cleaner

#include "imgui.h"
#include "imgui_internal.h"
#include "FileSystem.hpp"

using namespace Diligent;

ImFileHandle ImFileOpen(const char* pFileName, const char* pMode)
{
EFileAccessMode AccessMode = EFileAccessMode::Read;
if (pMode)
{
switch (pMode[0])
{
case 'w': AccessMode = (pMode[1] == '+') ? EFileAccessMode::OverwriteUpdate : EFileAccessMode::Overwrite; break;
case 'a': AccessMode = (pMode[1] == '+') ? EFileAccessMode::AppendUpdate : EFileAccessMode::Append; break;
case 'r':
default: AccessMode = (pMode[1] == '+') ? EFileAccessMode::ReadUpdate : EFileAccessMode::Read; break;
}
}

try
{
return static_cast<ImFileHandle>(FileSystem::OpenFile({pFileName, AccessMode}));
}
catch (...)
{
return nullptr;
}
}

bool ImFileClose(ImFileHandle pFile)
{
if (!pFile)
return false;
delete pFile;
return true;
}

ImU64 ImFileGetSize(ImFileHandle pFile)
{
if (!pFile)
return static_cast<ImU64>(-1);
return static_cast<ImU64>(pFile->GetSize());
}

ImU64 ImFileRead(void* pData, ImU64 ElemSize, ImU64 ElemCount, ImFileHandle pFile)
{
if (!pFile)
return 0;
const size_t TotalSize = static_cast<size_t>(ElemSize * ElemCount);
return pFile->Read(pData, TotalSize) ? ElemCount : 0;
}

ImU64 ImFileWrite(const void* pData, ImU64 ElemSize, ImU64 ElemCount, ImFileHandle pFile)
{
if (!pFile)
return 0;
const size_t TotalSize = static_cast<size_t>(ElemSize * ElemCount);
return pFile->Write(pData, TotalSize) ? ElemCount : 0;
}
26 changes: 25 additions & 1 deletion NativeApp/Apple/Data/OSX/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<objects>
<viewController id="lYj-9Z-eqp" customClass="ModeSelectionViewController" sceneMemberID="viewController">
<view key="view" autoresizesSubviews="NO" id="SPq-vc-rSb">
<rect key="frame" x="0.0" y="0.0" width="350" height="354"/>
<rect key="frame" x="0.0" y="0.0" width="350" height="464"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zEs-tf-G2z" userLabel="OpenGL">
Expand Down Expand Up @@ -210,6 +210,17 @@
<action selector="goMetal:" target="lYj-9Z-eqp" id="dg7-nT-7dm"/>
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wGp-Ub-8Xq" userLabel="WebGPU">
<rect key="frame" x="59" y="362" width="233" height="82"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="square" title="WebGPU" bezelStyle="shadowlessSquare" alignment="center" borderStyle="border" inset="2" id="kLm-Wn-3Pq">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" size="28" metaFont="system"/>
</buttonCell>
<connections>
<action selector="goWebGPU:" target="lYj-9Z-eqp" id="Hj8-Kp-2Lm"/>
</connections>
</button>
</subviews>
</view>
</viewController>
Expand All @@ -230,6 +241,19 @@
</objects>
<point key="canvasLocation" x="74" y="762"/>
</scene>
<!--View Controller - WebGPU-->
<scene sceneID="wGp-Xz-9Qr">
<objects>
<viewController storyboardIdentifier="WebGPUViewControllerID" id="wGp-Vc-8Xq" customClass="ViewController" sceneMemberID="viewController">
<view key="view" id="wGp-Vw-7Pm" customClass="WebGPUView">
<rect key="frame" x="0.0" y="0.0" width="800" height="600"/>
<autoresizingMask key="autoresizingMask"/>
</view>
</viewController>
<customObject id="wGp-Fr-5Lk" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="74" y="870"/>
</scene>
</scenes>
<resources>
<image name="metal-logo" width="650" height="650"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright 2015-2019 Egor Yusov
/* Copyright 2026 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +25,7 @@
#import "ModeSelectionViewController.h"
#import "GLView.h"
#import "MetalView.h"
#import "WebGPUView.h"
#import "ViewController.h"


Expand All @@ -50,6 +52,10 @@ - (void)viewDidLoad
#if !METAL_SUPPORTED
((NSButton*)self.view.subviews[2]).enabled = false;
#endif

#if !WEBGPU_SUPPORTED
((NSButton*)self.view.subviews[3]).enabled = false;
#endif
}

- (void) terminateApp:(NSString*) error
Expand Down Expand Up @@ -111,4 +117,20 @@ - (IBAction)goMetal:(id)sender
[self setWindowTitle:name];
}

- (IBAction)goWebGPU:(id)sender
{
ViewController* webgpuViewController = [self.storyboard instantiateControllerWithIdentifier:@"WebGPUViewControllerID"];
WebGPUView* webgpuView = (WebGPUView*)[webgpuViewController view];
self.view.window.contentViewController = webgpuViewController;

NSString* error = [webgpuView getError];
if(error != nil)
{
[self terminateApp:error];
}

NSString* name = [webgpuView getAppName];
[self setWindowTitle:name];
}

@end
30 changes: 30 additions & 0 deletions NativeApp/Apple/Source/Classes/OSX/WebGPUView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright 2026 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
*
* In no event and under no legal theory, whether in tort (including negligence),
* contract, or otherwise, unless required by applicable law (such as deliberate
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
* liable for any damages, including any direct, indirect, special, incidental,
* or consequential damages of any character arising as a result of this License or
* out of the use or inability to use the software (including but not limited to damages
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
* all other commercial damages or losses), even if such Contributor has been advised
* of the possibility of such damages.
*/

#import <AppKit/AppKit.h>

#include "ViewBase.h"

@interface WebGPUView : ViewBase

@end
Loading
Loading