Skip to content

Commit

Permalink
Merge pull request #88 from mahkoh/jorth/vulkan-formats
Browse files Browse the repository at this point in the history
render: fix vulkan formats for pre-multiplied alpha
  • Loading branch information
mahkoh authored Feb 15, 2024
2 parents 30fb0f0 + 1a024ba commit dc554a7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub static ARGB8888: &Format = &Format {
bpp: 4,
gl_format: GL_BGRA_EXT,
gl_type: GL_UNSIGNED_BYTE,
vk_format: vk::Format::B8G8R8A8_SRGB,
vk_format: vk::Format::B8G8R8A8_UNORM,
drm: ARGB8888_DRM,
wl_id: Some(ARGB8888_ID),
external_only_guess: false,
Expand All @@ -107,7 +107,7 @@ pub static XRGB8888: &Format = &Format {
bpp: 4,
gl_format: GL_BGRA_EXT,
gl_type: GL_UNSIGNED_BYTE,
vk_format: vk::Format::B8G8R8A8_SRGB,
vk_format: vk::Format::B8G8R8A8_UNORM,
drm: XRGB8888_DRM,
wl_id: Some(XRGB8888_ID),
external_only_guess: false,
Expand All @@ -125,7 +125,7 @@ pub static FORMATS: &[Format] = &[
bpp: 4,
gl_format: GL_RGBA,
gl_type: GL_UNSIGNED_BYTE,
vk_format: vk::Format::R8G8B8A8_SRGB,
vk_format: vk::Format::R8G8B8A8_UNORM,
drm: fourcc_code('A', 'B', '2', '4'),
wl_id: None,
external_only_guess: false,
Expand All @@ -138,7 +138,7 @@ pub static FORMATS: &[Format] = &[
bpp: 4,
gl_format: GL_RGBA,
gl_type: GL_UNSIGNED_BYTE,
vk_format: vk::Format::R8G8B8A8_SRGB,
vk_format: vk::Format::R8G8B8A8_UNORM,
drm: fourcc_code('X', 'B', '2', '4'),
wl_id: None,
external_only_guess: false,
Expand Down
4 changes: 2 additions & 2 deletions src/gfx_apis/vulkan/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl VulkanRenderer {
rai = rai
.clear_value(ClearValue {
color: ClearColorValue {
float32: clear.to_array_linear(),
float32: clear.to_array_srgb(),
},
})
.load_op(AttachmentLoadOp::CLEAR);
Expand Down Expand Up @@ -413,7 +413,7 @@ impl VulkanRenderer {
pos: r.rect.to_vk(width, height),
};
let frag = FillFragPushConstants {
color: r.color.to_array_linear(),
color: r.color.to_array_srgb(),
};
unsafe {
dev.cmd_push_constants(
Expand Down
2 changes: 1 addition & 1 deletion src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ impl Color {
[to_u8(self.r), to_u8(self.g), to_u8(self.b), to_u8(self.a)]
}

#[allow(dead_code)]
pub fn to_array_srgb(self) -> [f32; 4] {
[self.r, self.g, self.b, self.a]
}

#[allow(dead_code)]
pub fn to_array_linear(self) -> [f32; 4] {
fn to_linear(srgb: f32) -> f32 {
if srgb <= 0.04045 {
Expand Down

0 comments on commit dc554a7

Please sign in to comment.