gl: fix image size change
This commit is contained in:
parent
f6a862339c
commit
daea19b5a2
|
@ -8,7 +8,6 @@ edition = "2021"
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
opengl = ["gl"]
|
opengl = ["gl"]
|
||||||
directx = ["windows"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
gl = { version = "0.14.0", optional = true }
|
gl = { version = "0.14.0", optional = true }
|
||||||
|
|
|
@ -266,7 +266,7 @@ impl FilterChain {
|
||||||
for (index, texture) in textures.iter().enumerate() {
|
for (index, texture) in textures.iter().enumerate() {
|
||||||
let image = Image::load(&texture.path)?;
|
let image = Image::load(&texture.path)?;
|
||||||
let levels = if texture.mipmap {
|
let levels = if texture.mipmap {
|
||||||
util::calc_miplevel(image.width, image.height)
|
util::calc_miplevel(image.size)
|
||||||
} else {
|
} else {
|
||||||
1u32
|
1u32
|
||||||
};
|
};
|
||||||
|
@ -279,8 +279,8 @@ impl FilterChain {
|
||||||
gl::TEXTURE_2D,
|
gl::TEXTURE_2D,
|
||||||
levels as GLsizei,
|
levels as GLsizei,
|
||||||
gl::RGBA8,
|
gl::RGBA8,
|
||||||
image.width as GLsizei,
|
image.size.width as GLsizei,
|
||||||
image.height as GLsizei,
|
image.size.height as GLsizei,
|
||||||
);
|
);
|
||||||
|
|
||||||
gl::PixelStorei(gl::UNPACK_ROW_LENGTH, 0);
|
gl::PixelStorei(gl::UNPACK_ROW_LENGTH, 0);
|
||||||
|
@ -291,8 +291,8 @@ impl FilterChain {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
image.width as GLsizei,
|
image.size.width as GLsizei,
|
||||||
image.height as GLsizei,
|
image.size.height as GLsizei,
|
||||||
gl::RGBA,
|
gl::RGBA,
|
||||||
gl::UNSIGNED_BYTE,
|
gl::UNSIGNED_BYTE,
|
||||||
image.bytes.as_ptr().cast(),
|
image.bytes.as_ptr().cast(),
|
||||||
|
@ -347,10 +347,7 @@ impl FilterChain {
|
||||||
image: GlImage {
|
image: GlImage {
|
||||||
handle,
|
handle,
|
||||||
format: gl::RGBA8,
|
format: gl::RGBA8,
|
||||||
size: Size {
|
size: image.size,
|
||||||
width: image.width,
|
|
||||||
height: image.height,
|
|
||||||
},
|
|
||||||
padded_size: Size::default(),
|
padded_size: Size::default(),
|
||||||
},
|
},
|
||||||
filter: texture.filter_mode,
|
filter: texture.filter_mode,
|
||||||
|
|
|
@ -248,7 +248,7 @@ impl Framebuffer {
|
||||||
size.height = 1;
|
size.height = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.levels = util::calc_miplevel(size.width, size.height);
|
self.levels = util::calc_miplevel(size);
|
||||||
if self.levels > self.max_levels {
|
if self.levels > self.max_levels {
|
||||||
self.levels = self.max_levels;
|
self.levels = self.max_levels;
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,7 @@ impl Framebuffer {
|
||||||
gl::GenTextures(1, &mut self.image);
|
gl::GenTextures(1, &mut self.image);
|
||||||
gl::BindTexture(1, self.image);
|
gl::BindTexture(1, self.image);
|
||||||
|
|
||||||
self.levels = util::calc_miplevel(size.width, size.height);
|
self.levels = util::calc_miplevel(size);
|
||||||
if self.levels > self.max_levels {
|
if self.levels > self.max_levels {
|
||||||
self.levels = self.max_levels;
|
self.levels = self.max_levels;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ mod tests {
|
||||||
fn triangle_gl() {
|
fn triangle_gl() {
|
||||||
let (glfw, window, events, shader, vao) = hello_triangle::setup();
|
let (glfw, window, events, shader, vao) = hello_triangle::setup();
|
||||||
let mut filter =
|
let mut filter =
|
||||||
FilterChain::load_from_path("../test/slang-shaders/vhs/VHSPro.slangp")
|
FilterChain::load_from_path("../test/slang-shaders/crt/crt-royale.slangp")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
hello_triangle::do_loop(glfw, window, events, shader, vao, &mut filter);
|
hello_triangle::do_loop(glfw, window, events, shader, vao, &mut filter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::framebuffer::GlImage;
|
use crate::framebuffer::GlImage;
|
||||||
use gl::types::{GLenum, GLuint};
|
use gl::types::{GLenum, GLuint};
|
||||||
use librashader_common::{FilterMode, WrapMode};
|
use librashader_common::{FilterMode, Size, WrapMode};
|
||||||
|
|
||||||
pub fn calc_miplevel(width: u32, height: u32) -> u32 {
|
pub fn calc_miplevel(size: Size<u32>) -> u32 {
|
||||||
let mut size = std::cmp::max(width, height);
|
let mut size = std::cmp::max(size.width, size.height);
|
||||||
let mut levels = 0;
|
let mut levels = 0;
|
||||||
while size != 0 {
|
while size != 0 {
|
||||||
levels += 1;
|
levels += 1;
|
||||||
|
|
Loading…
Reference in a new issue