convert textures to rgba

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>
Nicolas Adenis-Lamarre 3 years ago committed by jackun
parent eea9d9c3fd
commit e0736d97ed
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

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

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

@ -713,16 +713,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;
@ -744,8 +744,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);
}

Loading…
Cancel
Save