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

hal/gles: fix setting filtering on integer textures #2222

Merged
merged 1 commit into from
Nov 29, 2021
Merged
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
119 changes: 53 additions & 66 deletions wgpu-hal/src/gles/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,82 +557,34 @@ impl crate::Device<super::Api> for super::Device {
super::TextureInner::Renderbuffer { raw }
} else {
let raw = gl.create_texture().unwrap();
//HACK: detect a cube map
let cube_count = if desc.size.width == desc.size.height
&& desc.size.depth_or_array_layers % 6 == 0
{
Some(desc.size.depth_or_array_layers / 6)
} else {
None
};
let target = match desc.dimension {
let (target, is_3d) = match desc.dimension {
wgt::TextureDimension::D1 | wgt::TextureDimension::D2 => {
if desc.sample_count > 1 {
let target = glow::TEXTURE_2D;
gl.bind_texture(target, Some(raw));
gl.tex_storage_2d_multisample(
target,
desc.sample_count as i32,
format_desc.internal,
desc.size.width as i32,
desc.size.height as i32,
true,
);
target
} else if desc.size.depth_or_array_layers > 1 && cube_count != Some(1) {
let target = match cube_count {
Some(_) => glow::TEXTURE_CUBE_MAP_ARRAY,
None => glow::TEXTURE_2D_ARRAY,
if desc.size.depth_or_array_layers > 1 {
//HACK: detect a cube map
let cube_count = if desc.size.width == desc.size.height
&& desc.size.depth_or_array_layers % 6 == 0
{
Some(desc.size.depth_or_array_layers / 6)
} else {
None
};
gl.bind_texture(target, Some(raw));
gl.tex_storage_3d(
target,
desc.mip_level_count as i32,
format_desc.internal,
desc.size.width as i32,
desc.size.height as i32,
desc.size.depth_or_array_layers as i32,
);
target
match cube_count {
None => (glow::TEXTURE_2D_ARRAY, true),
Some(1) => (glow::TEXTURE_CUBE_MAP, false),
Some(_) => (glow::TEXTURE_CUBE_MAP_ARRAY, true),
}
} else {
let target = match cube_count {
Some(_) => glow::TEXTURE_CUBE_MAP,
None => glow::TEXTURE_2D,
};
gl.bind_texture(target, Some(raw));
gl.tex_storage_2d(
target,
desc.mip_level_count as i32,
format_desc.internal,
desc.size.width as i32,
desc.size.height as i32,
);
target
(glow::TEXTURE_2D, false)
}
}
wgt::TextureDimension::D3 => {
copy_size.depth = desc.size.depth_or_array_layers;
let target = glow::TEXTURE_3D;
gl.bind_texture(target, Some(raw));
gl.tex_storage_3d(
target,
desc.mip_level_count as i32,
format_desc.internal,
desc.size.width as i32,
desc.size.height as i32,
desc.size.depth_or_array_layers as i32,
);
target
(glow::TEXTURE_3D, true)
}
};

#[cfg(not(target_arch = "wasm32"))]
if let Some(label) = desc.label {
if gl.supports_debug() {
gl.object_label(glow::TEXTURE, mem::transmute(raw), Some(label));
}
}

gl.bind_texture(target, Some(raw));
//Note: this has to be done before defining the storage!
match desc.format.describe().sample_type {
wgt::TextureSampleType::Float { filterable: false }
| wgt::TextureSampleType::Uint
Expand All @@ -645,6 +597,41 @@ impl crate::Device<super::Api> for super::Device {
| wgt::TextureSampleType::Depth => {}
}

if is_3d {
gl.tex_storage_3d(
target,
desc.mip_level_count as i32,
format_desc.internal,
desc.size.width as i32,
desc.size.height as i32,
desc.size.depth_or_array_layers as i32,
);
} else if desc.sample_count > 1 {
gl.tex_storage_2d_multisample(
target,
desc.sample_count as i32,
format_desc.internal,
desc.size.width as i32,
desc.size.height as i32,
true,
);
} else {
gl.tex_storage_2d(
target,
desc.mip_level_count as i32,
format_desc.internal,
desc.size.width as i32,
desc.size.height as i32,
);
}

#[cfg(not(target_arch = "wasm32"))]
if let Some(label) = desc.label {
if gl.supports_debug() {
gl.object_label(glow::TEXTURE, mem::transmute(raw), Some(label));
}
}

gl.bind_texture(target, None);
super::TextureInner::Texture { raw, target }
};
Expand Down