Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support wgpu skybox example on webgl #3773

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/backend/dx12/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,8 +1356,8 @@ impl hal::Instance<Backend> for Instance {
Features::UNSIZED_DESCRIPTOR_ARRAY |
Features::DRAW_INDIRECT_COUNT |
Features::INDEPENDENT_BLENDING |
Features::SAMPLE_RATE_SHADING |
Features::FRAGMENT_STORES_AND_ATOMICS |
Features::SAMPLE_RATE_SHADING |
Features::FRAGMENT_STORES_AND_ATOMICS |
tiled_resource_features |
conservative_faster_features,
properties: PhysicalDeviceProperties {
Expand Down
3 changes: 2 additions & 1 deletion src/backend/gl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ bitflags = "1"
fxhash = "0.2.1"
log = "0.4"
hal = { package = "gfx-hal", path = "../../hal", version = "0.8" }
glow = "0.9"
glow = "0.10"

parking_lot = "0.11"
raw-window-handle = "0.3"

Expand Down
37 changes: 18 additions & 19 deletions src/backend/gl/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub enum Command {
dst_texture: n::Texture,
texture_target: n::TextureTarget,
texture_format: n::TextureFormat,
internal_format: n::TextureFormat,
pixel_type: n::DataType,
data: command::BufferImageCopy,
},
Expand Down Expand Up @@ -908,21 +909,17 @@ impl command::CommandBuffer<Backend> for CommandBuffer {
level_count,
layer_count,
..
} => {
let is_3d = layer_count == 1; //TODO?
n::ImageView::Texture {
target,
raw,
is_3d,
sub: image::SubresourceRange {
aspects: Aspects::COLOR,
layer_start: 0,
layer_count: Some(layer_count),
level_start: 0,
level_count: Some(level_count),
},
}
}
} => n::ImageView::Texture {
target,
raw,
sub: image::SubresourceRange {
aspects: Aspects::COLOR,
layer_start: 0,
layer_count: Some(layer_count),
level_start: 0,
level_count: Some(level_count),
},
},
};
self.data.push_cmd(Command::BindFramebuffer {
target: glow::DRAW_FRAMEBUFFER,
Expand Down Expand Up @@ -1350,14 +1347,16 @@ impl command::CommandBuffer<Backend> for CommandBuffer {
n::ImageType::Texture {
raw,
target,
format,
format_external,
format_internal,
pixel_type,
..
} => Command::CopyBufferToTexture {
src_buffer: src_bounded_buffer.raw,
dst_texture: raw,
texture_target: target,
texture_format: format,
texture_format: format_external,
internal_format: format_internal,
pixel_type,
data: r,
},
Expand Down Expand Up @@ -1391,13 +1390,13 @@ impl command::CommandBuffer<Backend> for CommandBuffer {
n::ImageType::Texture {
raw,
target,
format,
format_external,
pixel_type,
..
} => Command::CopyTextureToBuffer {
src_texture: raw,
texture_target: target,
texture_format: format,
texture_format: format_external,
pixel_type: pixel_type,
dst_buffer: dst_bounded_buffer.raw,
data: r,
Expand Down
142 changes: 125 additions & 17 deletions src/backend/gl/src/conv.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
use crate::native::VertexAttribFunction;
use hal::{format::Format, image as i, pso};

/*
pub fn _image_kind_to_gl(kind: i::Kind) -> t::GLenum {
match kind {
i::Kind::D1(_) => glow::TEXTURE_1D,
i::Kind::D1Array(_, _) => glow::TEXTURE_1D_ARRAY,
i::Kind::D2(_, _, i::AaMode::Single) => glow::TEXTURE_2D,
i::Kind::D2(_, _, _) => glow::TEXTURE_2D_MULTISAMPLE,
i::Kind::D2Array(_, _, _, i::AaMode::Single) => glow::TEXTURE_2D_ARRAY,
i::Kind::D2Array(_, _, _, _) => glow::TEXTURE_2D_MULTISAMPLE_ARRAY,
i::Kind::D3(_, _, _) => glow::TEXTURE_3D,
i::Kind::Cube(_) => glow::TEXTURE_CUBE_MAP,
i::Kind::CubeArray(_, _) => glow::TEXTURE_CUBE_MAP_ARRAY,
}
}*/
use hal::{
format::Format,
image::{self as i, Extent},
pso,
};

pub fn filter_to_gl(mag: i::Filter, min: i::Filter, mip: i::Filter) -> (u32, u32) {
use hal::image::Filter::*;
Expand Down Expand Up @@ -87,6 +76,70 @@ impl FormatDescription {
}
}

pub const COMPRESSED_RGB_S3TC_DXT1_EXT: u32 = 0x83F0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to expose this on glow side.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 opened a PR grovesNL/glow#166

pub const COMPRESSED_RGBA_S3TC_DXT1_EXT: u32 = 0x83F1;
pub const COMPRESSED_SRGB_S3TC_DXT1_EXT: u32 = 0x8C4C;
pub const COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: u32 = 0x8C4D;
pub const COMPRESSED_RGBA_S3TC_DXT3_EXT: u32 = 0x83F2;
pub const COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: u32 = 0x8C4E;
pub const COMPRESSED_RGBA_S3TC_DXT5_EXT: u32 = 0x83F3;
pub const COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: u32 = 0x8C4F;

#[derive(Clone, Debug)]
pub struct CompressedFormatInfo {
pub internal_format: u32,
pub compressed_block_width: u32,
pub compressed_block_height: u32,
pub compressed_block_depth: u32,
pub compressed_block_size: u32,
pub component_count: u32,
pub srgb: bool,
}

impl CompressedFormatInfo {
const fn new(
internal_format: u32,
compressed_block_width: u32,
compressed_block_height: u32,
compressed_block_depth: u32,
compressed_block_size: u32,
component_count: u32,
srgb: bool,
) -> Self {
Self {
internal_format,
compressed_block_width,
compressed_block_height,
compressed_block_depth,
compressed_block_size,
component_count,
srgb,
}
}

pub const fn compute_compressed_image_size(&self, size: Extent) -> u32 {
let num_blocks_wide =
(size.width + self.compressed_block_width - 1) / self.compressed_block_width;
let num_blocks_high =
(size.height + self.compressed_block_height - 1) / self.compressed_block_height;
num_blocks_wide * num_blocks_high * (self.compressed_block_size / 8) * size.depth
}
}

pub const fn compressed_format_info(f: u32) -> Option<CompressedFormatInfo> {
Some(match f {
COMPRESSED_RGB_S3TC_DXT1_EXT => CompressedFormatInfo::new(f, 4, 4, 1, 64, 3, false),
COMPRESSED_RGBA_S3TC_DXT1_EXT => CompressedFormatInfo::new(f, 4, 4, 1, 64, 4, false),
COMPRESSED_SRGB_S3TC_DXT1_EXT => CompressedFormatInfo::new(f, 4, 4, 1, 64, 3, true),
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT => CompressedFormatInfo::new(f, 4, 4, 1, 64, 4, true),
COMPRESSED_RGBA_S3TC_DXT3_EXT => CompressedFormatInfo::new(f, 4, 4, 1, 128, 4, false),
COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT => CompressedFormatInfo::new(f, 4, 4, 1, 128, 4, true),
COMPRESSED_RGBA_S3TC_DXT5_EXT => CompressedFormatInfo::new(f, 4, 4, 1, 128, 4, false),
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT => CompressedFormatInfo::new(f, 4, 4, 1, 128, 4, true),
_ => return None,
})
}

pub fn describe_format(format: Format) -> Option<FormatDescription> {
use crate::native::VertexAttribFunction::*;
use hal::format::Format::*;
Expand Down Expand Up @@ -250,7 +303,62 @@ pub fn describe_format(format: Format) -> Option<FormatDescription> {
2,
Float,
),

Bc1RgbUnorm => FormatDescription::new(
COMPRESSED_RGB_S3TC_DXT1_EXT,
glow::RGB,
glow::INVALID_ENUM,
3,
Float,
),
Bc1RgbSrgb => FormatDescription::new(
COMPRESSED_SRGB_S3TC_DXT1_EXT,
glow::RGB,
glow::INVALID_ENUM,
3,
Float,
),
Bc1RgbaUnorm => FormatDescription::new(
COMPRESSED_RGBA_S3TC_DXT1_EXT,
glow::RGBA,
glow::INVALID_ENUM,
4,
Float,
),
Bc1RgbaSrgb => FormatDescription::new(
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
glow::RGBA,
glow::INVALID_ENUM,
4,
Float,
),
Bc2Unorm => FormatDescription::new(
COMPRESSED_RGBA_S3TC_DXT3_EXT,
glow::RGBA,
glow::INVALID_ENUM,
4,
Float,
),
Bc2Srgb => FormatDescription::new(
COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
glow::RGBA,
glow::INVALID_ENUM,
4,
Float,
),
Bc3Unorm => FormatDescription::new(
COMPRESSED_RGBA_S3TC_DXT5_EXT,
glow::RGBA,
glow::INVALID_ENUM,
4,
Float,
),
Bc3Srgb => FormatDescription::new(
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
glow::RGBA,
glow::INVALID_ENUM,
4,
Float,
),
_ => return None,
})
}
Expand Down
Loading