gl: fix image size change

This commit is contained in:
chyyran 2022-11-24 02:08:34 -05:00
parent f6a862339c
commit daea19b5a2
5 changed files with 12 additions and 16 deletions

View file

@ -8,7 +8,6 @@ edition = "2021"
[features]
default = []
opengl = ["gl"]
directx = ["windows"]
[dependencies]
gl = { version = "0.14.0", optional = true }

View file

@ -266,7 +266,7 @@ impl FilterChain {
for (index, texture) in textures.iter().enumerate() {
let image = Image::load(&texture.path)?;
let levels = if texture.mipmap {
util::calc_miplevel(image.width, image.height)
util::calc_miplevel(image.size)
} else {
1u32
};
@ -279,8 +279,8 @@ impl FilterChain {
gl::TEXTURE_2D,
levels as GLsizei,
gl::RGBA8,
image.width as GLsizei,
image.height as GLsizei,
image.size.width as GLsizei,
image.size.height as GLsizei,
);
gl::PixelStorei(gl::UNPACK_ROW_LENGTH, 0);
@ -291,8 +291,8 @@ impl FilterChain {
0,
0,
0,
image.width as GLsizei,
image.height as GLsizei,
image.size.width as GLsizei,
image.size.height as GLsizei,
gl::RGBA,
gl::UNSIGNED_BYTE,
image.bytes.as_ptr().cast(),
@ -347,10 +347,7 @@ impl FilterChain {
image: GlImage {
handle,
format: gl::RGBA8,
size: Size {
width: image.width,
height: image.height,
},
size: image.size,
padded_size: Size::default(),
},
filter: texture.filter_mode,

View file

@ -248,7 +248,7 @@ impl Framebuffer {
size.height = 1;
}
self.levels = util::calc_miplevel(size.width, size.height);
self.levels = util::calc_miplevel(size);
if self.levels > self.max_levels {
self.levels = self.max_levels;
}
@ -288,7 +288,7 @@ impl Framebuffer {
gl::GenTextures(1, &mut 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 {
self.levels = self.max_levels;
}

View file

@ -27,7 +27,7 @@ mod tests {
fn triangle_gl() {
let (glfw, window, events, shader, vao) = hello_triangle::setup();
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();
hello_triangle::do_loop(glfw, window, events, shader, vao, &mut filter);
}

View file

@ -1,9 +1,9 @@
use crate::framebuffer::GlImage;
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 {
let mut size = std::cmp::max(width, height);
pub fn calc_miplevel(size: Size<u32>) -> u32 {
let mut size = std::cmp::max(size.width, size.height);
let mut levels = 0;
while size != 0 {
levels += 1;