Fix iOS rendering (hopefully) by avoiding infinities
This commit is contained in:
parent
0b8351b9af
commit
44d93d3701
1 changed files with 13 additions and 7 deletions
|
@ -4,7 +4,7 @@ use {
|
||||||
web_sys::{WebGlBuffer, WebGlProgram, WebGlRenderingContext, WebGlShader, WebGlTexture},
|
web_sys::{WebGlBuffer, WebGlProgram, WebGlRenderingContext, WebGlShader, WebGlTexture},
|
||||||
};
|
};
|
||||||
|
|
||||||
use emigui::{Color, Mesh, PaintBatches, Texture};
|
use emigui::{vec2, Color, Mesh, PaintBatches, Pos2, Texture};
|
||||||
|
|
||||||
type Gl = WebGlRenderingContext;
|
type Gl = WebGlRenderingContext;
|
||||||
|
|
||||||
|
@ -178,10 +178,12 @@ impl Painter {
|
||||||
let u_screen_size_loc = gl
|
let u_screen_size_loc = gl
|
||||||
.get_uniform_location(&self.program, "u_screen_size")
|
.get_uniform_location(&self.program, "u_screen_size")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let screen_size_pixels = vec2(self.canvas.width() as f32, self.canvas.height() as f32);
|
||||||
|
let screen_size_points = screen_size_pixels / pixels_per_point;
|
||||||
gl.uniform2f(
|
gl.uniform2f(
|
||||||
Some(&u_screen_size_loc),
|
Some(&u_screen_size_loc),
|
||||||
self.canvas.width() as f32 / pixels_per_point,
|
screen_size_points.x,
|
||||||
self.canvas.height() as f32 / pixels_per_point,
|
screen_size_points.y,
|
||||||
);
|
);
|
||||||
|
|
||||||
let u_tex_size_loc = gl
|
let u_tex_size_loc = gl
|
||||||
|
@ -211,12 +213,16 @@ impl Painter {
|
||||||
gl.clear(Gl::COLOR_BUFFER_BIT);
|
gl.clear(Gl::COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
for (clip_rect, mesh) in batches {
|
for (clip_rect, mesh) in batches {
|
||||||
|
// Avoid infinities in shader:
|
||||||
|
let clip_min = clip_rect.min().max(Pos2::default());
|
||||||
|
let clip_max = clip_rect.max().min(Pos2::default() + screen_size_points);
|
||||||
|
|
||||||
gl.uniform4f(
|
gl.uniform4f(
|
||||||
Some(&u_clip_rect_loc),
|
Some(&u_clip_rect_loc),
|
||||||
clip_rect.min().x,
|
clip_min.x,
|
||||||
clip_rect.min().y,
|
clip_min.y,
|
||||||
clip_rect.max().x,
|
clip_max.x,
|
||||||
clip_rect.max().y,
|
clip_max.y,
|
||||||
);
|
);
|
||||||
|
|
||||||
for mesh in mesh.split_to_u16() {
|
for mesh in mesh.split_to_u16() {
|
||||||
|
|
Loading…
Reference in a new issue