Skip to content

Commit

Permalink
convert textures to rgba
Browse files Browse the repository at this point in the history
images textures need rgba (to load alpha for example for decorations).
thus, this commit globally convert gl textures in rgba

Signed-off-by: Nicolas Adenis-Lamarre <nicolas.adenis.lamarre@gmail.com>
  • Loading branch information
nadenislamarre authored and jackun committed Jun 15, 2024
1 parent 88d34c3 commit 44917b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/gl/gl_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bool ImGui_ImplOpenGL3_CreateFontsTexture()
ImGuiIO& io = ImGui::GetIO();
unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height);
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);

GLint last_texture, last_unpack_buffer;

Expand All @@ -128,7 +128,7 @@ bool ImGui_ImplOpenGL3_CreateFontsTexture()
if (g_IsGLES || g_GlVersion >= 200)
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);

glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, pixels);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

// Store our identifier
io.Fonts->SetTexID((ImTextureID)(intptr_t)g_FontTexture);
Expand Down Expand Up @@ -269,7 +269,7 @@ static bool ImGui_ImplOpenGL3_CreateDeviceObjects()
"out vec4 Out_Color;\n"
"void main()\n"
"{\n"
" Out_Color = Frag_Color * vec4(1, 1, 1, texture(Texture, Frag_UV.st).r);\n"
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
"}\n";

const GLchar* fragment_shader_glsl_300_es =
Expand All @@ -280,7 +280,7 @@ static bool ImGui_ImplOpenGL3_CreateDeviceObjects()
"layout (location = 0) out vec4 Out_Color;\n"
"void main()\n"
"{\n"
" Out_Color = Frag_Color * vec4(1, 1, 1, texture(Texture, Frag_UV.st).r);\n"
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
"}\n";

const GLchar* fragment_shader_glsl_410_core =
Expand All @@ -290,7 +290,7 @@ static bool ImGui_ImplOpenGL3_CreateDeviceObjects()
"layout (location = 0) out vec4 Out_Color;\n"
"void main()\n"
"{\n"
" Out_Color = Frag_Color * vec4(1, 1, 1, texture(Texture, Frag_UV.st).r);\n"
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
"}\n";

SPDLOG_DEBUG("glsl_version: {}", glsl_version);
Expand Down
2 changes: 1 addition & 1 deletion src/overlay.frag
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ layout(location = 0) in struct{

void main()
{
fColor = In.Color * vec4(1, 1, 1, texture(sTexture, In.UV.st).r);
fColor = In.Color * texture(sTexture, In.UV.st);
}
10 changes: 5 additions & 5 deletions src/vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,16 +722,16 @@ static void check_fonts(struct swapchain_data* data)
create_fonts(data->font_atlas, instance_data->params, data->sw_stats.font1, data->sw_stats.font_text);
unsigned char* pixels;
int width, height;
data->font_atlas->GetTexDataAsAlpha8(&pixels, &width, &height);
data->font_atlas->GetTexDataAsRGBA32(&pixels, &width, &height);

// wait for rendering to complete, if any
device_data->vtable.DeviceWaitIdle(device_data->device);
shutdown_swapchain_font(data);

if (desc_set)
create_image(data, desc_set, width, height, VK_FORMAT_R8_UNORM, data->font_image, data->font_mem, data->font_image_view);
create_image(data, desc_set, width, height, VK_FORMAT_R8G8B8A8_UNORM, data->font_image, data->font_mem, data->font_image_view);
else
desc_set = create_image_with_desc(data, width, height, VK_FORMAT_R8_UNORM, data->font_image, data->font_mem, data->font_image_view);
desc_set = create_image_with_desc(data, width, height, VK_FORMAT_R8G8B8A8_UNORM, data->font_image, data->font_mem, data->font_image_view);

data->font_atlas->SetTexID((ImTextureID)desc_set);
data->font_uploaded = false;
Expand All @@ -753,8 +753,8 @@ static void ensure_swapchain_fonts(struct swapchain_data *data,
data->font_uploaded = true;
unsigned char* pixels;
int width, height;
data->font_atlas->GetTexDataAsAlpha8(&pixels, &width, &height);
size_t upload_size = width * height * 1 * sizeof(char);
data->font_atlas->GetTexDataAsRGBA32(&pixels, &width, &height);
size_t upload_size = width * height * 4 * sizeof(char);
upload_image_data(device_data, command_buffer, pixels, upload_size, width, height, data->upload_font_buffer, data->upload_font_buffer_mem, data->font_image);
}

Expand Down

0 comments on commit 44917b7

Please sign in to comment.