Downgrade OpenGL and GLSL for glow renderer
This commit is contained in:
parent
e4b626b91f
commit
3a5f866782
@ -6,6 +6,13 @@ use iced_native::Rectangle;
|
|||||||
|
|
||||||
const MAX_INSTANCES: usize = 100_000;
|
const MAX_INSTANCES: usize = 100_000;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
pub struct QuadWithQPos(layer::Quad, [f32; 2]);
|
||||||
|
|
||||||
|
unsafe impl bytemuck::Zeroable for QuadWithQPos {}
|
||||||
|
unsafe impl bytemuck::Pod for QuadWithQPos {}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Pipeline {
|
pub struct Pipeline {
|
||||||
program: <glow::Context as HasContext>::Program,
|
program: <glow::Context as HasContext>::Program,
|
||||||
@ -133,23 +140,39 @@ impl Pipeline {
|
|||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let total = instances.len();
|
let total = instances.len();
|
||||||
|
|
||||||
|
let mut tagged_instances: Vec<QuadWithQPos> = Vec::new();
|
||||||
|
|
||||||
|
let pos_map = [[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]];
|
||||||
|
|
||||||
while i < total {
|
while i < total {
|
||||||
let end = (i + MAX_INSTANCES).min(total);
|
let end = (i + MAX_INSTANCES).min(total);
|
||||||
let amount = end - i;
|
let amount = end - i;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
tagged_instances.clear();
|
||||||
|
tagged_instances.extend(
|
||||||
|
instances[i..end]
|
||||||
|
.iter()
|
||||||
|
.map(|v| {
|
||||||
|
[
|
||||||
|
QuadWithQPos(*v, pos_map[0]),
|
||||||
|
QuadWithQPos(*v, pos_map[1]),
|
||||||
|
QuadWithQPos(*v, pos_map[2]),
|
||||||
|
QuadWithQPos(*v, pos_map[3]),
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.flatten(),
|
||||||
|
);
|
||||||
|
|
||||||
gl.buffer_sub_data_u8_slice(
|
gl.buffer_sub_data_u8_slice(
|
||||||
glow::ARRAY_BUFFER,
|
glow::ARRAY_BUFFER,
|
||||||
0,
|
0,
|
||||||
bytemuck::cast_slice(&instances[i..end]),
|
bytemuck::cast_slice(&tagged_instances),
|
||||||
);
|
);
|
||||||
|
|
||||||
gl.draw_arrays_instanced(
|
for j in 0..amount as i32 {
|
||||||
glow::TRIANGLE_STRIP,
|
gl.draw_arrays(glow::TRIANGLE_STRIP, j * 4, 4);
|
||||||
0,
|
}
|
||||||
4,
|
|
||||||
amount as i32,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i += MAX_INSTANCES;
|
i += MAX_INSTANCES;
|
||||||
@ -177,23 +200,20 @@ unsafe fn create_instance_buffer(
|
|||||||
gl.bind_buffer(glow::ARRAY_BUFFER, Some(buffer));
|
gl.bind_buffer(glow::ARRAY_BUFFER, Some(buffer));
|
||||||
gl.buffer_data_size(
|
gl.buffer_data_size(
|
||||||
glow::ARRAY_BUFFER,
|
glow::ARRAY_BUFFER,
|
||||||
(size * std::mem::size_of::<layer::Quad>()) as i32,
|
(size * std::mem::size_of::<QuadWithQPos>()) as i32,
|
||||||
glow::DYNAMIC_DRAW,
|
glow::DYNAMIC_DRAW,
|
||||||
);
|
);
|
||||||
|
|
||||||
let stride = std::mem::size_of::<layer::Quad>() as i32;
|
let stride = std::mem::size_of::<QuadWithQPos>() as i32;
|
||||||
|
|
||||||
gl.enable_vertex_attrib_array(0);
|
gl.enable_vertex_attrib_array(0);
|
||||||
gl.vertex_attrib_pointer_f32(0, 2, glow::FLOAT, false, stride, 0);
|
gl.vertex_attrib_pointer_f32(0, 2, glow::FLOAT, false, stride, 0);
|
||||||
gl.vertex_attrib_divisor(0, 1);
|
|
||||||
|
|
||||||
gl.enable_vertex_attrib_array(1);
|
gl.enable_vertex_attrib_array(1);
|
||||||
gl.vertex_attrib_pointer_f32(1, 2, glow::FLOAT, false, stride, 4 * 2);
|
gl.vertex_attrib_pointer_f32(1, 2, glow::FLOAT, false, stride, 4 * 2);
|
||||||
gl.vertex_attrib_divisor(1, 1);
|
|
||||||
|
|
||||||
gl.enable_vertex_attrib_array(2);
|
gl.enable_vertex_attrib_array(2);
|
||||||
gl.vertex_attrib_pointer_f32(2, 4, glow::FLOAT, false, stride, 4 * (2 + 2));
|
gl.vertex_attrib_pointer_f32(2, 4, glow::FLOAT, false, stride, 4 * (2 + 2));
|
||||||
gl.vertex_attrib_divisor(2, 1);
|
|
||||||
|
|
||||||
gl.enable_vertex_attrib_array(3);
|
gl.enable_vertex_attrib_array(3);
|
||||||
gl.vertex_attrib_pointer_f32(
|
gl.vertex_attrib_pointer_f32(
|
||||||
@ -204,7 +224,6 @@ unsafe fn create_instance_buffer(
|
|||||||
stride,
|
stride,
|
||||||
4 * (2 + 2 + 4),
|
4 * (2 + 2 + 4),
|
||||||
);
|
);
|
||||||
gl.vertex_attrib_divisor(3, 1);
|
|
||||||
|
|
||||||
gl.enable_vertex_attrib_array(4);
|
gl.enable_vertex_attrib_array(4);
|
||||||
gl.vertex_attrib_pointer_f32(
|
gl.vertex_attrib_pointer_f32(
|
||||||
@ -215,7 +234,6 @@ unsafe fn create_instance_buffer(
|
|||||||
stride,
|
stride,
|
||||||
4 * (2 + 2 + 4 + 4),
|
4 * (2 + 2 + 4 + 4),
|
||||||
);
|
);
|
||||||
gl.vertex_attrib_divisor(4, 1);
|
|
||||||
|
|
||||||
gl.enable_vertex_attrib_array(5);
|
gl.enable_vertex_attrib_array(5);
|
||||||
gl.vertex_attrib_pointer_f32(
|
gl.vertex_attrib_pointer_f32(
|
||||||
@ -226,7 +244,17 @@ unsafe fn create_instance_buffer(
|
|||||||
stride,
|
stride,
|
||||||
4 * (2 + 2 + 4 + 4 + 1),
|
4 * (2 + 2 + 4 + 4 + 1),
|
||||||
);
|
);
|
||||||
gl.vertex_attrib_divisor(5, 1);
|
|
||||||
|
// q_Pos
|
||||||
|
gl.enable_vertex_attrib_array(6);
|
||||||
|
gl.vertex_attrib_pointer_f32(
|
||||||
|
6,
|
||||||
|
2,
|
||||||
|
glow::FLOAT,
|
||||||
|
false,
|
||||||
|
stride,
|
||||||
|
4 * (2 + 2 + 4 + 4 + 1 + 1),
|
||||||
|
);
|
||||||
|
|
||||||
gl.bind_vertex_array(None);
|
gl.bind_vertex_array(None);
|
||||||
gl.bind_buffer(glow::ARRAY_BUFFER, None);
|
gl.bind_buffer(glow::ARRAY_BUFFER, None);
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
#version 330
|
#version 120
|
||||||
|
|
||||||
uniform float u_ScreenHeight;
|
uniform float u_ScreenHeight;
|
||||||
|
|
||||||
in vec4 v_Color;
|
varying vec4 v_Color;
|
||||||
in vec4 v_BorderColor;
|
varying vec4 v_BorderColor;
|
||||||
in vec2 v_Pos;
|
varying vec2 v_Pos;
|
||||||
in vec2 v_Scale;
|
varying vec2 v_Scale;
|
||||||
in float v_BorderRadius;
|
varying float v_BorderRadius;
|
||||||
in float v_BorderWidth;
|
varying float v_BorderWidth;
|
||||||
|
|
||||||
out vec4 o_Color;
|
|
||||||
|
|
||||||
float distance(in vec2 frag_coord, in vec2 position, in vec2 size, float radius)
|
float distance(in vec2 frag_coord, in vec2 position, in vec2 size, float radius)
|
||||||
{
|
{
|
||||||
@ -66,5 +64,5 @@ void main() {
|
|||||||
float radius_alpha =
|
float radius_alpha =
|
||||||
1.0 - smoothstep(max(v_BorderRadius - 0.5, 0.0), v_BorderRadius + 0.5, d);
|
1.0 - smoothstep(max(v_BorderRadius - 0.5, 0.0), v_BorderRadius + 0.5, d);
|
||||||
|
|
||||||
o_Color = vec4(mixed_color.xyz, mixed_color.w * radius_alpha);
|
gl_FragColor = vec4(mixed_color.xyz, mixed_color.w * radius_alpha);
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,24 @@
|
|||||||
#version 330
|
#version 120
|
||||||
|
|
||||||
uniform mat4 u_Transform;
|
uniform mat4 u_Transform;
|
||||||
uniform float u_Scale;
|
uniform float u_Scale;
|
||||||
|
|
||||||
layout(location = 0) in vec2 i_Pos;
|
attribute vec2 i_Pos;
|
||||||
layout(location = 1) in vec2 i_Scale;
|
attribute vec2 i_Scale;
|
||||||
layout(location = 2) in vec4 i_Color;
|
attribute vec4 i_Color;
|
||||||
layout(location = 3) in vec4 i_BorderColor;
|
attribute vec4 i_BorderColor;
|
||||||
layout(location = 4) in float i_BorderRadius;
|
attribute float i_BorderRadius;
|
||||||
layout(location = 5) in float i_BorderWidth;
|
attribute float i_BorderWidth;
|
||||||
|
attribute vec2 q_Pos;
|
||||||
|
|
||||||
out vec4 v_Color;
|
varying vec4 v_Color;
|
||||||
out vec4 v_BorderColor;
|
varying vec4 v_BorderColor;
|
||||||
out vec2 v_Pos;
|
varying vec2 v_Pos;
|
||||||
out vec2 v_Scale;
|
varying vec2 v_Scale;
|
||||||
out float v_BorderRadius;
|
varying float v_BorderRadius;
|
||||||
out float v_BorderWidth;
|
varying float v_BorderWidth;
|
||||||
|
|
||||||
const vec2 positions[4] = vec2[](
|
|
||||||
vec2(0.0, 0.0),
|
|
||||||
vec2(0.0, 1.0),
|
|
||||||
vec2(1.0, 0.0),
|
|
||||||
vec2(1.0, 1.0)
|
|
||||||
);
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec2 q_Pos = positions[gl_VertexID];
|
|
||||||
vec2 p_Pos = i_Pos * u_Scale;
|
vec2 p_Pos = i_Pos * u_Scale;
|
||||||
vec2 p_Scale = i_Scale * u_Scale;
|
vec2 p_Scale = i_Scale * u_Scale;
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
#version 330
|
#version 120
|
||||||
|
|
||||||
in vec4 v_Color;
|
varying vec4 v_Color;
|
||||||
|
|
||||||
out vec4 o_Color;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
o_Color = v_Color;
|
gl_FragColor = v_Color;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#version 330
|
#version 120
|
||||||
|
|
||||||
uniform mat4 u_Transform;
|
uniform mat4 u_Transform;
|
||||||
|
|
||||||
layout(location = 0) in vec2 i_Position;
|
attribute vec2 i_Position;
|
||||||
layout(location = 1) in vec4 i_Color;
|
attribute vec4 i_Color;
|
||||||
|
|
||||||
out vec4 v_Color;
|
varying vec4 v_Color;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = u_Transform * vec4(i_Position, 0.0, 1.0);
|
gl_Position = u_Transform * vec4(i_Position, 0.0, 1.0);
|
||||||
|
Loading…
Reference in New Issue
Block a user