mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
webgl: Fix support for float/half-float texture formats.
This commit is contained in:
parent
8789a6a8d8
commit
29ab55d076
10 changed files with 88 additions and 56 deletions
|
@ -2773,7 +2773,8 @@ fn image_to_tex_image_data(
|
|||
}
|
||||
|
||||
match (format, data_type) {
|
||||
(TexFormat::RGBA, TexDataType::UnsignedByte) => pixels,
|
||||
(TexFormat::RGBA, TexDataType::UnsignedByte) |
|
||||
(TexFormat::RGBA8, TexDataType::UnsignedByte) => pixels,
|
||||
(TexFormat::RGB, TexDataType::UnsignedByte) => {
|
||||
for i in 0..pixel_count {
|
||||
let rgb = {
|
||||
|
@ -2854,7 +2855,8 @@ fn image_to_tex_image_data(
|
|||
pixels.truncate(pixel_count * 2);
|
||||
pixels
|
||||
},
|
||||
(TexFormat::RGBA, TexDataType::Float) => {
|
||||
(TexFormat::RGBA, TexDataType::Float) |
|
||||
(TexFormat::RGBA32f, TexDataType::Float) => {
|
||||
let mut rgbaf32 = Vec::<u8>::with_capacity(pixel_count * 16);
|
||||
for rgba8 in pixels.chunks(4) {
|
||||
rgbaf32.write_f32::<NativeEndian>(rgba8[0] as f32).unwrap();
|
||||
|
@ -2865,7 +2867,8 @@ fn image_to_tex_image_data(
|
|||
rgbaf32
|
||||
},
|
||||
|
||||
(TexFormat::RGB, TexDataType::Float) => {
|
||||
(TexFormat::RGB, TexDataType::Float) |
|
||||
(TexFormat::RGB32f, TexDataType::Float) => {
|
||||
let mut rgbf32 = Vec::<u8>::with_capacity(pixel_count * 12);
|
||||
for rgba8 in pixels.chunks(4) {
|
||||
rgbf32.write_f32::<NativeEndian>(rgba8[0] as f32).unwrap();
|
||||
|
@ -2875,7 +2878,8 @@ fn image_to_tex_image_data(
|
|||
rgbf32
|
||||
},
|
||||
|
||||
(TexFormat::Alpha, TexDataType::Float) => {
|
||||
(TexFormat::Alpha, TexDataType::Float) |
|
||||
(TexFormat::Alpha32f, TexDataType::Float) => {
|
||||
for rgba8 in pixels.chunks_mut(4) {
|
||||
let p = rgba8[3] as f32;
|
||||
NativeEndian::write_f32(rgba8, p);
|
||||
|
@ -2883,7 +2887,8 @@ fn image_to_tex_image_data(
|
|||
pixels
|
||||
},
|
||||
|
||||
(TexFormat::Luminance, TexDataType::Float) => {
|
||||
(TexFormat::Luminance, TexDataType::Float) |
|
||||
(TexFormat::Luminance32f, TexDataType::Float) => {
|
||||
for rgba8 in pixels.chunks_mut(4) {
|
||||
let p = rgba8[0] as f32;
|
||||
NativeEndian::write_f32(rgba8, p);
|
||||
|
@ -2891,7 +2896,8 @@ fn image_to_tex_image_data(
|
|||
pixels
|
||||
},
|
||||
|
||||
(TexFormat::LuminanceAlpha, TexDataType::Float) => {
|
||||
(TexFormat::LuminanceAlpha, TexDataType::Float) |
|
||||
(TexFormat::LuminanceAlpha32f, TexDataType::Float) => {
|
||||
let mut data = Vec::<u8>::with_capacity(pixel_count * 8);
|
||||
for rgba8 in pixels.chunks(4) {
|
||||
data.write_f32::<NativeEndian>(rgba8[0] as f32).unwrap();
|
||||
|
@ -2900,7 +2906,8 @@ fn image_to_tex_image_data(
|
|||
data
|
||||
},
|
||||
|
||||
(TexFormat::RGBA, TexDataType::HalfFloat) => {
|
||||
(TexFormat::RGBA, TexDataType::HalfFloat) |
|
||||
(TexFormat::RGBA16f, TexDataType::HalfFloat) => {
|
||||
let mut rgbaf16 = Vec::<u8>::with_capacity(pixel_count * 8);
|
||||
for rgba8 in pixels.chunks(4) {
|
||||
rgbaf16
|
||||
|
@ -2919,7 +2926,8 @@ fn image_to_tex_image_data(
|
|||
rgbaf16
|
||||
},
|
||||
|
||||
(TexFormat::RGB, TexDataType::HalfFloat) => {
|
||||
(TexFormat::RGB, TexDataType::HalfFloat) |
|
||||
(TexFormat::RGB16f, TexDataType::HalfFloat) => {
|
||||
let mut rgbf16 = Vec::<u8>::with_capacity(pixel_count * 6);
|
||||
for rgba8 in pixels.chunks(4) {
|
||||
rgbf16
|
||||
|
@ -2934,7 +2942,8 @@ fn image_to_tex_image_data(
|
|||
}
|
||||
rgbf16
|
||||
},
|
||||
(TexFormat::Alpha, TexDataType::HalfFloat) => {
|
||||
(TexFormat::Alpha, TexDataType::HalfFloat) |
|
||||
(TexFormat::Alpha16f, TexDataType::HalfFloat) => {
|
||||
for i in 0..pixel_count {
|
||||
let p = f16::from_f32(pixels[i * 4 + 3] as f32).as_bits();
|
||||
NativeEndian::write_u16(&mut pixels[i * 2..i * 2 + 2], p);
|
||||
|
@ -2942,7 +2951,8 @@ fn image_to_tex_image_data(
|
|||
pixels.truncate(pixel_count * 2);
|
||||
pixels
|
||||
},
|
||||
(TexFormat::Luminance, TexDataType::HalfFloat) => {
|
||||
(TexFormat::Luminance, TexDataType::HalfFloat) |
|
||||
(TexFormat::Luminance16f, TexDataType::HalfFloat) => {
|
||||
for i in 0..pixel_count {
|
||||
let p = f16::from_f32(pixels[i * 4] as f32).as_bits();
|
||||
NativeEndian::write_u16(&mut pixels[i * 2..i * 2 + 2], p);
|
||||
|
@ -2950,7 +2960,8 @@ fn image_to_tex_image_data(
|
|||
pixels.truncate(pixel_count * 2);
|
||||
pixels
|
||||
},
|
||||
(TexFormat::LuminanceAlpha, TexDataType::HalfFloat) => {
|
||||
(TexFormat::LuminanceAlpha, TexDataType::HalfFloat) |
|
||||
(TexFormat::LuminanceAlpha16f, TexDataType::HalfFloat) => {
|
||||
for rgba8 in pixels.chunks_mut(4) {
|
||||
let lum = f16::from_f32(rgba8[0] as f32).as_bits();
|
||||
let a = f16::from_f32(rgba8[3] as f32).as_bits();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue