-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b734a91
commit eef9d80
Showing
18 changed files
with
1,080 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// dear imgui: Renderer Backend for Metal | ||
// This needs to be used along with a Platform Backend (e.g. OSX) | ||
|
||
// Implemented features: | ||
// [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID! | ||
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset). | ||
|
||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. | ||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. | ||
// Learn about Dear ImGui: | ||
// - FAQ https://dearimgui.com/faq | ||
// - Getting Started https://dearimgui.com/getting-started | ||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder). | ||
// - Introduction, links and more at the top of imgui.cpp | ||
|
||
#include "imgui.h" // IMGUI_IMPL_API | ||
#ifndef IMGUI_DISABLE | ||
|
||
//----------------------------------------------------------------------------- | ||
// ObjC API | ||
//----------------------------------------------------------------------------- | ||
|
||
#ifdef __OBJC__ | ||
|
||
@class MTLRenderPassDescriptor; | ||
@protocol MTLDevice, MTLCommandBuffer, MTLRenderCommandEncoder; | ||
|
||
// Follow "Getting Started" link and check examples/ folder to learn about using backends! | ||
IMGUI_IMPL_API bool ImGui_ImplMetal_Init(id<MTLDevice> device); | ||
IMGUI_IMPL_API void ImGui_ImplMetal_Shutdown(); | ||
IMGUI_IMPL_API void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor* renderPassDescriptor); | ||
IMGUI_IMPL_API void ImGui_ImplMetal_RenderDrawData(ImDrawData* drawData, | ||
id<MTLCommandBuffer> commandBuffer, | ||
id<MTLRenderCommandEncoder> commandEncoder); | ||
|
||
// Called by Init/NewFrame/Shutdown | ||
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateFontsTexture(id<MTLDevice> device); | ||
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyFontsTexture(); | ||
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(id<MTLDevice> device); | ||
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects(); | ||
|
||
#endif | ||
|
||
//----------------------------------------------------------------------------- | ||
// C++ API | ||
//----------------------------------------------------------------------------- | ||
|
||
// Enable Metal C++ binding support with '#define IMGUI_IMPL_METAL_CPP' in your imconfig.h file | ||
// More info about using Metal from C++: https://developer.apple.com/metal/cpp/ | ||
|
||
#ifdef IMGUI_IMPL_METAL_CPP | ||
#include <Metal/Metal.hpp> | ||
#ifndef __OBJC__ | ||
|
||
// Follow "Getting Started" link and check examples/ folder to learn about using backends! | ||
IMGUI_IMPL_API bool ImGui_ImplMetal_Init(MTL::Device* device); | ||
IMGUI_IMPL_API void ImGui_ImplMetal_Shutdown(); | ||
IMGUI_IMPL_API void ImGui_ImplMetal_NewFrame(MTL::RenderPassDescriptor* renderPassDescriptor); | ||
IMGUI_IMPL_API void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, | ||
MTL::CommandBuffer* commandBuffer, | ||
MTL::RenderCommandEncoder* commandEncoder); | ||
|
||
// Called by Init/NewFrame/Shutdown | ||
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateFontsTexture(MTL::Device* device); | ||
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyFontsTexture(); | ||
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device); | ||
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects(); | ||
|
||
#endif | ||
#endif | ||
|
||
//----------------------------------------------------------------------------- | ||
|
||
#endif // #ifndef IMGUI_DISABLE |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
Copyright 2024 flyinghead | ||
This file is part of Flycast. | ||
Flycast is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
Flycast is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Flycast. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
#include "metal_driver.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
Copyright 2024 flyinghead | ||
This file is part of Flycast. | ||
Flycast is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
Flycast is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Flycast. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
#pragma once | ||
#include "ui/imgui_driver.h" | ||
#include "imgui_impl_metal.h" | ||
#include "metal_context.h" | ||
#include <unordered_map> | ||
|
||
class MetalDriver final : public ImGuiDriver { | ||
public: | ||
void reset() override | ||
{ | ||
ImGuiDriver::reset(); | ||
ImGui_ImplMetal_Shutdown(); | ||
} | ||
|
||
void newFrame() override { | ||
|
||
} | ||
|
||
void renderDrawData(ImDrawData *drawData, bool gui_open) override { | ||
|
||
} | ||
|
||
void present() override { | ||
|
||
} | ||
|
||
ImTextureID getTexture(const std::string &name) override { | ||
auto it = textures.find(name); | ||
if (it != textures.end()) | ||
return &it->second.texture; | ||
else | ||
return ImTextureID{}; | ||
} | ||
|
||
ImTextureID updateTexture(const std::string &name, const u8 *data, int width, int height, bool nearestSampling) override { | ||
Texture& texture = textures[name]; | ||
texture.texture->setPurgeableState(MTL::PurgeableStateEmpty); | ||
|
||
MTL::TextureDescriptor *desc = MTL::TextureDescriptor::alloc()->init(); | ||
desc->setWidth(width); | ||
desc->setHeight(height); | ||
|
||
MTL::Region region = MTL::Region { 0, 0, static_cast<NS::UInteger>(width), static_cast<NS::UInteger>(height) }; | ||
texture.texture = MetalContext::Instance()->GetDevice()->newTexture(desc); | ||
texture.texture->replaceRegion(region, 0, data, width * 4); | ||
|
||
return texture.texture; | ||
} | ||
|
||
void deleteTexture(const std::string &name) override { | ||
auto it = textures.find(name); | ||
it->second.texture->setPurgeableState(MTL::PurgeableStateEmpty); | ||
textures.erase(name); | ||
} | ||
|
||
private: | ||
struct Texture { | ||
MTL::Texture *texture; | ||
}; | ||
|
||
bool frameRendered = false; | ||
std::unordered_map<std::string, Texture> textures; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.