[UI] Replace ImmediateTexture handles with pointers + small cleanup

This commit is contained in:
Triang3l 2020-09-27 16:30:53 +03:00
parent f5f8714c3f
commit c2e8c5554d
6 changed files with 8 additions and 23 deletions

View File

@ -40,7 +40,6 @@ D3D12ImmediateDrawer::D3D12ImmediateTexture::D3D12ImmediateTexture(
if (resource_) {
resource_->AddRef();
}
handle = reinterpret_cast<uintptr_t>(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<D3D12ImmediateTexture*>(draw.texture_handle);
auto texture = static_cast<D3D12ImmediateTexture*>(draw.texture);
ID3D12Resource* texture_resource = texture ? texture->resource() : nullptr;
bool bind_texture = current_texture_ != texture_resource;
uint32_t texture_descriptor_index;

View File

@ -163,7 +163,7 @@ void ImGuiDrawer::SetupFont() {
width, height, ImmediateTextureFilter::kLinear, true,
reinterpret_cast<uint8_t*>(pixels));
io.Fonts->TexID = reinterpret_cast<void*>(font_texture_->handle);
io.Fonts->TexID = reinterpret_cast<ImTextureID>(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<uintptr_t>(cmd.TextureId) & ~kIgnoreAlpha;
draw.alpha_blend =
reinterpret_cast<uintptr_t>(cmd.TextureId) & kIgnoreAlpha ? false
: true;
draw.texture = reinterpret_cast<ImmediateTexture*>(cmd.TextureId);
draw.scissor = true;
draw.scissor_rect[0] = static_cast<int>(cmd.ClipRect.x);
draw.scissor_rect[1] = static_cast<int>(height - cmd.ClipRect.w);

View File

@ -36,8 +36,6 @@ class ImGuiDrawer : public WindowListener {
ImGuiIO& GetIO();
void RenderDrawLists();
static const uint64_t kIgnoreAlpha = (1ull << 63);
protected:
void Initialize();
void SetupFont();

View File

@ -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<ImmediateTexture> 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;

View File

@ -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();

View File

@ -152,7 +152,6 @@ class VulkanImmediateTexture : public ImmediateTexture {
VkResult Initialize(VkDescriptorSetLayout descriptor_set_layout,
VkImageView image_view) {
handle = reinterpret_cast<uintptr_t>(this);
image_view_ = image_view;
VkResult status;
@ -191,7 +190,6 @@ class VulkanImmediateTexture : public ImmediateTexture {
}
VkResult Initialize(VkDescriptorSetLayout descriptor_set_layout) {
handle = reinterpret_cast<uintptr_t>(this);
VkResult status;
// Create image object.
@ -824,7 +822,7 @@ void VulkanImmediateDrawer::Draw(const ImmediateDraw& draw) {
}
// Setup texture binding.
auto texture = reinterpret_cast<VulkanImmediateTexture*>(draw.texture_handle);
auto texture = static_cast<VulkanImmediateTexture*>(draw.texture);
if (texture) {
if (texture->layout() != VK_IMAGE_LAYOUT_GENERAL) {
texture->TransitionLayout(current_cmd_buffer_, VK_IMAGE_LAYOUT_GENERAL);