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

Switch to using R8 on all GL implementations. #2276

Merged
merged 1 commit into from Jan 12, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Switch to using R8 on all GL implementations.

Fixes #2134.
Fixes #788.
  • Loading branch information
gw3583 committed Jan 10, 2018
commit fb5394208d77d79dca6144d9abf89f38e402863c
@@ -212,7 +212,7 @@ impl Example for App {
let image_mask_key = api.generate_image_key();
resources.add_image(
image_mask_key,
ImageDescriptor::new(2, 2, ImageFormat::A8, true),
ImageDescriptor::new(2, 2, ImageFormat::R8, true),
ImageData::new(vec![0, 80, 180, 255]),
None,
);
@@ -85,7 +85,7 @@ fn render_blob(
texels.push(color.r * checker + tc);
texels.push(color.a * checker + tc);
}
api::ImageFormat::A8 => {
api::ImageFormat::R8 => {
texels.push(color.a * checker + tc);
}
_ => {
@@ -192,7 +192,7 @@ impl Example for App {
let yuv_chanel3 = api.generate_image_key();
resources.add_image(
yuv_chanel1,
ImageDescriptor::new(100, 100, ImageFormat::A8, true),
ImageDescriptor::new(100, 100, ImageFormat::R8, true),
ImageData::new(vec![127; 100 * 100]),
None,
);
@@ -204,13 +204,13 @@ impl Example for App {
);
resources.add_image(
yuv_chanel2_1,
ImageDescriptor::new(100, 100, ImageFormat::A8, true),
ImageDescriptor::new(100, 100, ImageFormat::R8, true),
ImageData::new(vec![127; 100 * 100]),
None,
);
resources.add_image(
yuv_chanel3,
ImageDescriptor::new(100, 100, ImageFormat::A8, true),
ImageDescriptor::new(100, 100, ImageFormat::R8, true),
ImageData::new(vec![127; 100 * 100]),
None,
);
@@ -121,7 +121,7 @@ impl DebugRenderer {
&mut font_texture,
debug_font_data::BMP_WIDTH,
debug_font_data::BMP_HEIGHT,
ImageFormat::A8,
ImageFormat::R8,
TextureFilter::Linear,
None,
1,
@@ -12,7 +12,6 @@ use smallvec::SmallVec;
use std::cell::RefCell;
use std::fs::File;
use std::io::Read;
use std::iter::repeat;
use std::marker::PhantomData;
use std::mem;
use std::ops::Add;
@@ -38,12 +37,6 @@ impl Add<usize> for FrameId {
}
}

#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
const GL_FORMAT_A: gl::GLuint = gl::RED;

#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
const GL_FORMAT_A: gl::GLuint = gl::ALPHA;

const GL_FORMAT_BGRA_GL: gl::GLuint = gl::BGRA;

const GL_FORMAT_BGRA_GLES: gl::GLuint = gl::BGRA_EXT;
@@ -457,7 +450,7 @@ impl Texture {

pub fn get_bpp(&self) -> u32 {
match self.format {
ImageFormat::A8 => 1,
ImageFormat::R8 => 1,
ImageFormat::BGRA8 => 4,
ImageFormat::RG8 => 2,
ImageFormat::RGBAF32 => 16,
@@ -1011,20 +1004,6 @@ impl Device {
let (internal_format, gl_format) = gl_texture_formats_for_image_format(self.gl(), format);
let type_ = gl_type_for_texture_format(format);

let expanded_data: Vec<u8>;
let actual_pixels = if pixels.is_some() && format == ImageFormat::A8 &&
cfg!(any(target_arch = "arm", target_arch = "aarch64"))
{
expanded_data = pixels
.unwrap()
.iter()
.flat_map(|&byte| repeat(byte).take(4))
.collect();
Some(expanded_data.as_slice())
} else {
pixels
};

match texture.target {
gl::TEXTURE_2D_ARRAY => {
self.gl.tex_image_3d(
@@ -1037,7 +1016,7 @@ impl Device {
0,
gl_format,
type_,
actual_pixels,
pixels,
);
}
gl::TEXTURE_2D | gl::TEXTURE_RECTANGLE | gl::TEXTURE_EXTERNAL_OES => {
@@ -1050,7 +1029,7 @@ impl Device {
0,
gl_format,
type_,
actual_pixels,
pixels,
);
}
_ => panic!("BUG: Unexpected texture target!"),
@@ -1924,11 +1903,7 @@ fn gl_texture_formats_for_image_format(
format: ImageFormat,
) -> (gl::GLint, gl::GLuint) {
match format {
ImageFormat::A8 => if cfg!(any(target_arch = "arm", target_arch = "aarch64")) {
(get_gl_format_bgra(gl) as gl::GLint, get_gl_format_bgra(gl))
} else {
(GL_FORMAT_A as gl::GLint, GL_FORMAT_A)
},
ImageFormat::R8 => (gl::RED as gl::GLint, gl::RED),
ImageFormat::BGRA8 => match gl.get_type() {
gl::GlType::Gl => (gl::RGBA as gl::GLint, get_gl_format_bgra(gl)),
gl::GlType::Gles => (get_gl_format_bgra(gl) as gl::GLint, get_gl_format_bgra(gl)),
@@ -2053,7 +2028,7 @@ impl<'a, T> TextureUploader<'a, T> {
impl<'a> UploadTarget<'a> {
fn update_impl(&mut self, chunk: UploadChunk) {
let (gl_format, bpp, data_type) = match self.texture.format {
ImageFormat::A8 => (GL_FORMAT_A, 1, gl::UNSIGNED_BYTE),
ImageFormat::R8 => (gl::RED, 1, gl::UNSIGNED_BYTE),
ImageFormat::BGRA8 => (get_gl_format_bgra(self.gl), 4, gl::UNSIGNED_BYTE),
ImageFormat::RG8 => (gl::RG, 2, gl::UNSIGNED_BYTE),
ImageFormat::RGBAF32 => (gl::RGBA, 16, gl::FLOAT),
@@ -2099,7 +2099,7 @@ impl Renderer {
&mut texture,
8,
8,
ImageFormat::A8,
ImageFormat::R8,
TextureFilter::Nearest,
None,
1,
@@ -206,7 +206,7 @@ impl TextureCache {
TextureCache {
max_texture_size,
array_a8_linear: TextureArray::new(
ImageFormat::A8,
ImageFormat::R8,
TextureFilter::Linear,
TEXTURE_ARRAY_LAYERS_LINEAR,
),
@@ -365,13 +365,13 @@ impl TextureCache {
region_index: u16
) -> &mut TextureRegion {
let texture_array = match (format, filter) {
(ImageFormat::A8, TextureFilter::Linear) => &mut self.array_a8_linear,
(ImageFormat::R8, TextureFilter::Linear) => &mut self.array_a8_linear,
(ImageFormat::BGRA8, TextureFilter::Linear) => &mut self.array_rgba8_linear,
(ImageFormat::BGRA8, TextureFilter::Nearest) => &mut self.array_rgba8_nearest,
(ImageFormat::Invalid, _) |
(ImageFormat::RGBAF32, _) |
(ImageFormat::RG8, _) |
(ImageFormat::A8, TextureFilter::Nearest) => unreachable!(),
(ImageFormat::R8, TextureFilter::Nearest) => unreachable!(),
};

&mut texture_array.regions[region_index as usize]
@@ -537,12 +537,12 @@ impl TextureCache {
) -> Option<CacheEntry> {
// Work out which cache it goes in, based on format.
let texture_array = match (descriptor.format, filter) {
(ImageFormat::A8, TextureFilter::Linear) => &mut self.array_a8_linear,
(ImageFormat::R8, TextureFilter::Linear) => &mut self.array_a8_linear,
(ImageFormat::BGRA8, TextureFilter::Linear) => &mut self.array_rgba8_linear,
(ImageFormat::BGRA8, TextureFilter::Nearest) => &mut self.array_rgba8_nearest,
(ImageFormat::Invalid, _) |
(ImageFormat::RGBAF32, _) |
(ImageFormat::A8, TextureFilter::Nearest) |
(ImageFormat::R8, TextureFilter::Nearest) |
(ImageFormat::RG8, _) => unreachable!(),
};

@@ -559,7 +559,7 @@ impl RenderPass {
RenderPass {
kind: RenderPassKind::OffScreen {
color: RenderTargetList::new(screen_size, ImageFormat::BGRA8),
alpha: RenderTargetList::new(screen_size, ImageFormat::A8),
alpha: RenderTargetList::new(screen_size, ImageFormat::R8),
},
tasks: vec![],
dynamic_tasks: FastHashMap::default(),
@@ -51,7 +51,7 @@ pub struct ExternalImageData {
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum ImageFormat {
Invalid = 0,
A8 = 1,
R8 = 1,
BGRA8 = 3,
RGBAF32 = 4,
RG8 = 5,
@@ -60,7 +60,7 @@ pub enum ImageFormat {
impl ImageFormat {
pub fn bytes_per_pixel(self) -> u32 {
match self {
ImageFormat::A8 => 1,
ImageFormat::R8 => 1,
ImageFormat::BGRA8 => 4,
ImageFormat::RGBAF32 => 16,
ImageFormat::RG8 => 2,
@@ -65,7 +65,7 @@ fn render_blob(
texels.push(color.r * checker + tc);
texels.push(color.a * checker + tc);
}
ImageFormat::A8 => {
ImageFormat::R8 => {
texels.push(color.a * checker + tc);
}
_ => {
@@ -234,7 +234,7 @@ impl JsonFrameWriter {
} else {
false
},
ImageFormat::A8 => if data.stride == data.width {
ImageFormat::R8 => if data.stride == data.width {
save_buffer(
&path_file,
&bytes,
@@ -169,7 +169,7 @@ fn is_image_opaque(format: ImageFormat, bytes: &[u8]) -> bool {
is_opaque
}
ImageFormat::RG8 => true,
ImageFormat::A8 => false,
ImageFormat::R8 => false,
ImageFormat::Invalid | ImageFormat::RGBAF32 => unreachable!(),
}
}
@@ -343,7 +343,7 @@ impl YamlFrameReader {
let image_dims = image.dimensions();
let (format, bytes) = match image {
image::ImageLuma8(_) => {
(ImageFormat::A8, image.raw_pixels())
(ImageFormat::R8, image.raw_pixels())
}
image::ImageRgba8(_) => {
let mut pixels = image.raw_pixels();
@@ -555,7 +555,7 @@ impl YamlFrameWriter {
assert!(data.stride > 0);
let (color_type, bpp) = match data.format {
ImageFormat::BGRA8 => (ColorType::RGBA(8), 4),
ImageFormat::A8 => (ColorType::Gray(8), 1),
ImageFormat::R8 => (ColorType::Gray(8), 1),
_ => {
println!(
"Failed to write image with format {:?}, dimensions {}x{}, stride {}",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.