Skip to content

Commit

Permalink
Convert GLuint/u32 to ImTextureID only to prevent precision loss
Browse files Browse the repository at this point in the history
  • Loading branch information
williamyang98 committed Sep 25, 2023
1 parent 9b2821f commit 712b27b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/render_dab_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ void RenderRadioService(DAB_Decoder_ImGui& ctx) {
static_cast<float>(texture->GetWidth()) * scale,
static_cast<float>(texture->GetHeight()) * scale
);
ImGui::Image(texture_id, texture_size);
ImGui::Image(ImTextureID(texture_id), texture_size);
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("%.*s", int(slideshow->name.length()), slideshow->name.c_str());
}
Expand All @@ -469,7 +469,7 @@ void RenderRadioService(DAB_Decoder_ImGui& ctx) {

if (texture != NULL) {
FIELD_MACRO("Resolution", "%u x %u", texture->GetWidth(), texture->GetHeight());
FIELD_MACRO("Internal Texture ID", "%" PRIuPTR, uintptr_t(texture->GetTextureID()));
FIELD_MACRO("Internal Texture ID", "%" PRIu32, texture->GetTextureID());
}

ImGui::EndTable();
Expand Down
6 changes: 3 additions & 3 deletions src/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define STBI_ONLY_JPEG
#include <imgui/stb_image.h>

Texture::Texture(ImTextureID id, int width, int height)
Texture::Texture(uint32_t id, int width, int height)
: m_id(id), m_width(width), m_height(height)
{}

Expand All @@ -28,7 +28,7 @@ std::unique_ptr<Texture> Texture::LoadFromMemory(const uint8_t* data, const size
int height = 0;
int bits_per_pixel = 0;
uint8_t* image_data = stbi_load_from_memory(
data, total_bytes,
data, int(total_bytes),
&width, &height, &bits_per_pixel, 4
);

Expand All @@ -55,5 +55,5 @@ std::unique_ptr<Texture> Texture::LoadFromMemory(const uint8_t* data, const size
// stbi_set_flip_vertically_on_load(1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
stbi_image_free(image_data);
return std::make_unique<Texture>((void*)(id), width, height);
return std::make_unique<Texture>(id, width, height);
}
6 changes: 3 additions & 3 deletions src/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
class Texture
{
private:
const ImTextureID m_id;
const uint32_t m_id;
const int m_width;
const int m_height;
public:
Texture(ImTextureID id, int width, int height);
Texture(uint32_t id, int width, int height);
~Texture();
Texture(Texture&) = delete;
Texture(Texture&&) = delete;
Texture& operator=(Texture&) = delete;
Texture& operator=(Texture&&) = delete;
ImTextureID GetTextureID() const { return m_id; }
uint32_t GetTextureID() const { return m_id; }
inline int GetWidth() const { return m_width; }
inline int GetHeight() const { return m_height; }
public:
Expand Down

0 comments on commit 712b27b

Please sign in to comment.