From c2e8c5554dcb89099952037571fd9d715f982b6f Mon Sep 17 00:00:00 2001 From: Triang3l Date: Sun, 27 Sep 2020 16:30:53 +0300 Subject: [PATCH] [UI] Replace ImmediateTexture handles with pointers + small cleanup --- src/xenia/ui/d3d12/d3d12_immediate_drawer.cc | 3 +-- src/xenia/ui/imgui_drawer.cc | 8 ++------ src/xenia/ui/imgui_drawer.h | 2 -- src/xenia/ui/immediate_drawer.h | 12 +++--------- src/xenia/ui/microprofile_drawer.cc | 2 +- src/xenia/ui/vulkan/vulkan_immediate_drawer.cc | 4 +--- 6 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/xenia/ui/d3d12/d3d12_immediate_drawer.cc b/src/xenia/ui/d3d12/d3d12_immediate_drawer.cc index 3a1a09caa..b9e23dc93 100644 --- a/src/xenia/ui/d3d12/d3d12_immediate_drawer.cc +++ b/src/xenia/ui/d3d12/d3d12_immediate_drawer.cc @@ -40,7 +40,6 @@ D3D12ImmediateDrawer::D3D12ImmediateTexture::D3D12ImmediateTexture( if (resource_) { resource_->AddRef(); } - handle = reinterpret_cast(this); } D3D12ImmediateDrawer::D3D12ImmediateTexture::~D3D12ImmediateTexture() { @@ -544,7 +543,7 @@ void D3D12ImmediateDrawer::Draw(const ImmediateDraw& draw) { // index will be invalid initially, and the texture will be bound regardless // of what's in current_texture_. uint64_t current_fence_value = context_.GetSwapCurrentFenceValue(); - auto texture = reinterpret_cast(draw.texture_handle); + auto texture = static_cast(draw.texture); ID3D12Resource* texture_resource = texture ? texture->resource() : nullptr; bool bind_texture = current_texture_ != texture_resource; uint32_t texture_descriptor_index; diff --git a/src/xenia/ui/imgui_drawer.cc b/src/xenia/ui/imgui_drawer.cc index cc58994e0..158c9248a 100644 --- a/src/xenia/ui/imgui_drawer.cc +++ b/src/xenia/ui/imgui_drawer.cc @@ -163,7 +163,7 @@ void ImGuiDrawer::SetupFont() { width, height, ImmediateTextureFilter::kLinear, true, reinterpret_cast(pixels)); - io.Fonts->TexID = reinterpret_cast(font_texture_->handle); + io.Fonts->TexID = reinterpret_cast(font_texture_.get()); } void ImGuiDrawer::RenderDrawLists(ImDrawData* data) { @@ -198,11 +198,7 @@ void ImGuiDrawer::RenderDrawLists(ImDrawData* data) { draw.primitive_type = ImmediatePrimitiveType::kTriangles; draw.count = cmd.ElemCount; draw.index_offset = index_offset; - draw.texture_handle = - reinterpret_cast(cmd.TextureId) & ~kIgnoreAlpha; - draw.alpha_blend = - reinterpret_cast(cmd.TextureId) & kIgnoreAlpha ? false - : true; + draw.texture = reinterpret_cast(cmd.TextureId); draw.scissor = true; draw.scissor_rect[0] = static_cast(cmd.ClipRect.x); draw.scissor_rect[1] = static_cast(height - cmd.ClipRect.w); diff --git a/src/xenia/ui/imgui_drawer.h b/src/xenia/ui/imgui_drawer.h index e2038f1bf..7163e7a1a 100644 --- a/src/xenia/ui/imgui_drawer.h +++ b/src/xenia/ui/imgui_drawer.h @@ -36,8 +36,6 @@ class ImGuiDrawer : public WindowListener { ImGuiIO& GetIO(); void RenderDrawLists(); - static const uint64_t kIgnoreAlpha = (1ull << 63); - protected: void Initialize(); void SetupFont(); diff --git a/src/xenia/ui/immediate_drawer.h b/src/xenia/ui/immediate_drawer.h index 65606c134..544f16aa1 100644 --- a/src/xenia/ui/immediate_drawer.h +++ b/src/xenia/ui/immediate_drawer.h @@ -32,12 +32,10 @@ class ImmediateTexture { uint32_t width; // Texture height, in pixels. uint32_t height; - // Internal handle. Can be passed with the ImmediateDrawBatch. - uintptr_t handle; protected: ImmediateTexture(uint32_t width, uint32_t height) - : width(width), height(height), handle(0ULL) {} + : width(width), height(height) {} }; // Describes the primitive type used by a draw call. @@ -78,16 +76,12 @@ struct ImmediateDraw { int base_vertex = 0; // Texture used when drawing, or nullptr if color only. - // This is most commonly the handle of an ImmediateTexture. - uintptr_t texture_handle = 0; + ImmediateTexture* texture = nullptr; // True to enable scissoring using the region defined by scissor_rect. bool scissor = false; // Scissoring region in framebuffer pixels as (x, y, w, h). int scissor_rect[4] = {0}; - - // Blends this draw with the background depending on its alpha (if true). - bool alpha_blend = true; }; class ImmediateDrawer { @@ -97,7 +91,7 @@ class ImmediateDrawer { // Creates a new texture with the given attributes and R8G8B8A8 data. virtual std::unique_ptr CreateTexture( uint32_t width, uint32_t height, ImmediateTextureFilter filter, - bool repeat, const uint8_t* data) = 0; + bool is_repeated, const uint8_t* data) = 0; // Begins drawing in immediate mode using the given projection matrix. virtual void Begin(int render_target_width, int render_target_height) = 0; diff --git a/src/xenia/ui/microprofile_drawer.cc b/src/xenia/ui/microprofile_drawer.cc index de97e4a03..fb6588348 100644 --- a/src/xenia/ui/microprofile_drawer.cc +++ b/src/xenia/ui/microprofile_drawer.cc @@ -216,7 +216,7 @@ void MicroprofileDrawer::Flush() { ImmediateDraw draw; draw.primitive_type = current_primitive_type_; draw.count = vertex_count_; - draw.texture_handle = font_texture_->handle; + draw.texture = font_texture_.get(); drawer->Draw(draw); drawer->EndDrawBatch(); diff --git a/src/xenia/ui/vulkan/vulkan_immediate_drawer.cc b/src/xenia/ui/vulkan/vulkan_immediate_drawer.cc index 11211cf0f..a7aac5eae 100644 --- a/src/xenia/ui/vulkan/vulkan_immediate_drawer.cc +++ b/src/xenia/ui/vulkan/vulkan_immediate_drawer.cc @@ -152,7 +152,6 @@ class VulkanImmediateTexture : public ImmediateTexture { VkResult Initialize(VkDescriptorSetLayout descriptor_set_layout, VkImageView image_view) { - handle = reinterpret_cast(this); image_view_ = image_view; VkResult status; @@ -191,7 +190,6 @@ class VulkanImmediateTexture : public ImmediateTexture { } VkResult Initialize(VkDescriptorSetLayout descriptor_set_layout) { - handle = reinterpret_cast(this); VkResult status; // Create image object. @@ -824,7 +822,7 @@ void VulkanImmediateDrawer::Draw(const ImmediateDraw& draw) { } // Setup texture binding. - auto texture = reinterpret_cast(draw.texture_handle); + auto texture = static_cast(draw.texture); if (texture) { if (texture->layout() != VK_IMAGE_LAYOUT_GENERAL) { texture->TransitionLayout(current_cmd_buffer_, VK_IMAGE_LAYOUT_GENERAL);