1
0
Fork 0
forked from wry/wry

Merge pull request #88 from mahkoh/jorth/vulkan-formats

render: fix vulkan formats for pre-multiplied alpha
This commit is contained in:
mahkoh 2024-02-15 01:30:35 +01:00 committed by GitHub
commit dc554a780e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 7 deletions

View file

@ -93,7 +93,7 @@ pub static ARGB8888: &Format = &Format {
bpp: 4, bpp: 4,
gl_format: GL_BGRA_EXT, gl_format: GL_BGRA_EXT,
gl_type: GL_UNSIGNED_BYTE, gl_type: GL_UNSIGNED_BYTE,
vk_format: vk::Format::B8G8R8A8_SRGB, vk_format: vk::Format::B8G8R8A8_UNORM,
drm: ARGB8888_DRM, drm: ARGB8888_DRM,
wl_id: Some(ARGB8888_ID), wl_id: Some(ARGB8888_ID),
external_only_guess: false, external_only_guess: false,
@ -107,7 +107,7 @@ pub static XRGB8888: &Format = &Format {
bpp: 4, bpp: 4,
gl_format: GL_BGRA_EXT, gl_format: GL_BGRA_EXT,
gl_type: GL_UNSIGNED_BYTE, gl_type: GL_UNSIGNED_BYTE,
vk_format: vk::Format::B8G8R8A8_SRGB, vk_format: vk::Format::B8G8R8A8_UNORM,
drm: XRGB8888_DRM, drm: XRGB8888_DRM,
wl_id: Some(XRGB8888_ID), wl_id: Some(XRGB8888_ID),
external_only_guess: false, external_only_guess: false,
@ -125,7 +125,7 @@ pub static FORMATS: &[Format] = &[
bpp: 4, bpp: 4,
gl_format: GL_RGBA, gl_format: GL_RGBA,
gl_type: GL_UNSIGNED_BYTE, gl_type: GL_UNSIGNED_BYTE,
vk_format: vk::Format::R8G8B8A8_SRGB, vk_format: vk::Format::R8G8B8A8_UNORM,
drm: fourcc_code('A', 'B', '2', '4'), drm: fourcc_code('A', 'B', '2', '4'),
wl_id: None, wl_id: None,
external_only_guess: false, external_only_guess: false,
@ -138,7 +138,7 @@ pub static FORMATS: &[Format] = &[
bpp: 4, bpp: 4,
gl_format: GL_RGBA, gl_format: GL_RGBA,
gl_type: GL_UNSIGNED_BYTE, gl_type: GL_UNSIGNED_BYTE,
vk_format: vk::Format::R8G8B8A8_SRGB, vk_format: vk::Format::R8G8B8A8_UNORM,
drm: fourcc_code('X', 'B', '2', '4'), drm: fourcc_code('X', 'B', '2', '4'),
wl_id: None, wl_id: None,
external_only_guess: false, external_only_guess: false,

View file

@ -338,7 +338,7 @@ impl VulkanRenderer {
rai = rai rai = rai
.clear_value(ClearValue { .clear_value(ClearValue {
color: ClearColorValue { color: ClearColorValue {
float32: clear.to_array_linear(), float32: clear.to_array_srgb(),
}, },
}) })
.load_op(AttachmentLoadOp::CLEAR); .load_op(AttachmentLoadOp::CLEAR);
@ -413,7 +413,7 @@ impl VulkanRenderer {
pos: r.rect.to_vk(width, height), pos: r.rect.to_vk(width, height),
}; };
let frag = FillFragPushConstants { let frag = FillFragPushConstants {
color: r.color.to_array_linear(), color: r.color.to_array_srgb(),
}; };
unsafe { unsafe {
dev.cmd_push_constants( dev.cmd_push_constants(

View file

@ -85,11 +85,11 @@ impl Color {
[to_u8(self.r), to_u8(self.g), to_u8(self.b), to_u8(self.a)] [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] { pub fn to_array_srgb(self) -> [f32; 4] {
[self.r, self.g, self.b, self.a] [self.r, self.g, self.b, self.a]
} }
#[allow(dead_code)]
pub fn to_array_linear(self) -> [f32; 4] { pub fn to_array_linear(self) -> [f32; 4] {
fn to_linear(srgb: f32) -> f32 { fn to_linear(srgb: f32) -> f32 {
if srgb <= 0.04045 { if srgb <= 0.04045 {