anvil: Introduce RenderTextureSpec to simplify render_texture
This commit is contained in:
parent
64aedce01f
commit
35d8cea547
|
@ -239,26 +239,16 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_texture(
|
pub fn render_texture(&self, target: &mut Frame, spec: RenderTextureSpec<'_>) {
|
||||||
&self,
|
let xscale = 2.0 * (spec.surface_dimensions.0 as f32) / (spec.screen_size.0 as f32);
|
||||||
target: &mut Frame,
|
let mut yscale = -2.0 * (spec.surface_dimensions.1 as f32) / (spec.screen_size.1 as f32);
|
||||||
texture: &Texture2d,
|
|
||||||
texture_kind: usize,
|
|
||||||
y_inverted: bool,
|
|
||||||
surface_dimensions: (u32, u32),
|
|
||||||
surface_location: (i32, i32),
|
|
||||||
screen_size: (u32, u32),
|
|
||||||
blending: glium::Blend,
|
|
||||||
) {
|
|
||||||
let xscale = 2.0 * (surface_dimensions.0 as f32) / (screen_size.0 as f32);
|
|
||||||
let mut yscale = -2.0 * (surface_dimensions.1 as f32) / (screen_size.1 as f32);
|
|
||||||
|
|
||||||
let x = 2.0 * (surface_location.0 as f32) / (screen_size.0 as f32) - 1.0;
|
let x = 2.0 * (spec.surface_location.0 as f32) / (spec.screen_size.0 as f32) - 1.0;
|
||||||
let mut y = 1.0 - 2.0 * (surface_location.1 as f32) / (screen_size.1 as f32);
|
let mut y = 1.0 - 2.0 * (spec.surface_location.1 as f32) / (spec.screen_size.1 as f32);
|
||||||
|
|
||||||
if y_inverted {
|
if spec.y_inverted {
|
||||||
yscale = -yscale;
|
yscale = -yscale;
|
||||||
y -= surface_dimensions.1 as f32;
|
y -= spec.surface_dimensions.1 as f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
let uniforms = uniform! {
|
let uniforms = uniform! {
|
||||||
|
@ -268,17 +258,17 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
|
||||||
[ 0.0 , 0.0 , 1.0, 0.0],
|
[ 0.0 , 0.0 , 1.0, 0.0],
|
||||||
[ x , y , 0.0, 1.0]
|
[ x , y , 0.0, 1.0]
|
||||||
],
|
],
|
||||||
tex: texture,
|
tex: spec.texture,
|
||||||
};
|
};
|
||||||
|
|
||||||
target
|
target
|
||||||
.draw(
|
.draw(
|
||||||
&self.vertex_buffer,
|
&self.vertex_buffer,
|
||||||
&self.index_buffer,
|
&self.index_buffer,
|
||||||
&self.programs[texture_kind],
|
&self.programs[spec.texture_kind],
|
||||||
&uniforms,
|
&uniforms,
|
||||||
&glium::DrawParameters {
|
&glium::DrawParameters {
|
||||||
blend: blending,
|
blend: spec.blending,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -291,6 +281,16 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct RenderTextureSpec<'a> {
|
||||||
|
texture: &'a Texture2d,
|
||||||
|
texture_kind: usize,
|
||||||
|
y_inverted: bool,
|
||||||
|
surface_dimensions: (u32, u32),
|
||||||
|
surface_location: (i32, i32),
|
||||||
|
screen_size: (u32, u32),
|
||||||
|
blending: glium::Blend,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct TextureMetadata {
|
pub struct TextureMetadata {
|
||||||
pub texture: Texture2d,
|
pub texture: Texture2d,
|
||||||
pub fragment: usize,
|
pub fragment: usize,
|
||||||
|
@ -368,22 +368,24 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
|
||||||
}
|
}
|
||||||
self.render_texture(
|
self.render_texture(
|
||||||
frame,
|
frame,
|
||||||
&metadata.texture,
|
RenderTextureSpec {
|
||||||
metadata.fragment,
|
texture: &metadata.texture,
|
||||||
metadata.y_inverted,
|
texture_kind: metadata.fragment,
|
||||||
metadata.dimensions,
|
y_inverted: metadata.y_inverted,
|
||||||
(x, y),
|
surface_dimensions: metadata.dimensions,
|
||||||
screen_dimensions,
|
surface_location: (x, y),
|
||||||
::glium::Blend {
|
screen_size: screen_dimensions,
|
||||||
color: ::glium::BlendingFunction::Addition {
|
blending: ::glium::Blend {
|
||||||
source: ::glium::LinearBlendingFactor::One,
|
color: ::glium::BlendingFunction::Addition {
|
||||||
destination: ::glium::LinearBlendingFactor::OneMinusSourceAlpha,
|
source: ::glium::LinearBlendingFactor::One,
|
||||||
|
destination: ::glium::LinearBlendingFactor::OneMinusSourceAlpha,
|
||||||
|
},
|
||||||
|
alpha: ::glium::BlendingFunction::Addition {
|
||||||
|
source: ::glium::LinearBlendingFactor::One,
|
||||||
|
destination: ::glium::LinearBlendingFactor::OneMinusSourceAlpha,
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
alpha: ::glium::BlendingFunction::Addition {
|
|
||||||
source: ::glium::LinearBlendingFactor::One,
|
|
||||||
destination: ::glium::LinearBlendingFactor::OneMinusSourceAlpha,
|
|
||||||
},
|
|
||||||
..Default::default()
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue