Skip to content

Commit d8dc2c8

Browse files
committed
Get OpenGL demo to draw something
1 parent ecee8b1 commit d8dc2c8

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

azul-core/src/gl.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ use crate::{
3030
};
3131
use azul_css::{AzString, StringVec, U8Vec, ColorU, ColorF};
3232

33+
pub const GL_RESTART_INDEX: u32 = core::u32::MAX;
34+
3335
/// Passing *const c_void is not easily possible when generating APIs,
3436
/// so this wrapper struct is for easier API generation
3537
#[repr(C)]
@@ -665,33 +667,29 @@ static SVG_VERTEX_SHADER: &[u8] = b"#version 150
665667
#define attribute in
666668
#endif
667669
668-
precision mediump float;
669-
670670
uniform vec2 vBboxSize;
671-
uniform mat4 vTransformMatrix;
672671
673-
in vec2 vAttrXY;
674-
out vec4 vPosition;
672+
attribute vec2 vAttrXY;
675673
676674
void main() {
677-
vPosition = vec4(vAttrXY / vBboxSize - vec2(1.0), 1.0, 1.0) * vTransformMatrix;
675+
gl_Position = vec4(vAttrXY / vBboxSize - vec2(1.0), 1.0, 1.0);
676+
gl_PointSize = 1.0;
678677
}";
679678

680679
static SVG_FRAGMENT_SHADER: &[u8] = b"#version 150
681680
682-
#if __VERSION__ != 100
683-
#define varying in
684-
#endif
685-
686-
precision mediump float;
681+
precision highp float;
687682
688683
uniform vec4 fDrawColor;
689684
690-
in vec4 vPosition;
691-
out vec4 fOutColor;
685+
#if __VERSION__ == 100
686+
#define oFragColor gl_FragColor
687+
#else
688+
out vec4 oFragColor;
689+
#endif
692690
693691
void main() {
694-
fOutColor = fDrawColor;
692+
oFragColor = fDrawColor;
695693
}";
696694

697695
impl GlContextPtr {
@@ -1894,6 +1892,8 @@ impl GlShader {
18941892
let mut current_framebuffers = [0_i32];
18951893
let mut current_renderbuffers = [0_i32];
18961894
let mut current_texture_2d = [0_i32];
1895+
let mut current_blend_enabled = [0_u8];
1896+
let mut current_primitive_restart_fixed_index_enabled = [0_u8];
18971897

18981898
gl_context.get_boolean_v(gl::MULTISAMPLE, (&mut current_multisample[..]).into());
18991899
gl_context.get_integer_v(gl::ARRAY_BUFFER_BINDING, (&mut current_vertex_buffer[..]).into());
@@ -1903,6 +1903,8 @@ impl GlShader {
19031903
gl_context.get_integer_v(gl::RENDERBUFFER, (&mut current_renderbuffers[..]).into());
19041904
gl_context.get_integer_v(gl::FRAMEBUFFER, (&mut current_framebuffers[..]).into());
19051905
gl_context.get_integer_v(gl::TEXTURE_2D, (&mut current_texture_2d[..]).into());
1906+
gl_context.get_boolean_v(gl::BLEND, (&mut current_blend_enabled[..]).into());
1907+
gl_context.get_boolean_v(gl::PRIMITIVE_RESTART_FIXED_INDEX, (&mut current_primitive_restart_fixed_index_enabled[..]).into());
19061908

19071909
// 1. Create the framebuffer
19081910
let framebuffers = gl_context.gen_framebuffers(1);
@@ -1952,8 +1954,11 @@ impl GlShader {
19521954
}
19531955

19541956
gl_context.viewport(0, 0, texture_size.width as i32, texture_size.height as i32);
1955-
gl_context.use_program(shader_program_id);
1957+
gl_context.enable(gl::BLEND);
1958+
gl_context.enable(gl::PRIMITIVE_RESTART_FIXED_INDEX);
19561959
gl_context.disable(gl::MULTISAMPLE);
1960+
gl_context.blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); // TODO: enable / disable
1961+
gl_context.use_program(shader_program_id);
19571962

19581963
// Avoid multiple calls to get_uniform_location by caching the uniform locations
19591964
let mut uniform_locations: BTreeMap<AzString, i32> = BTreeMap::new();
@@ -1998,6 +2003,12 @@ impl GlShader {
19982003
if u32::from(current_multisample[0]) == gl::TRUE {
19992004
gl_context.enable(gl::MULTISAMPLE);
20002005
}
2006+
if u32::from(current_blend_enabled[0]) == gl::FALSE {
2007+
gl_context.disable(gl::BLEND);
2008+
}
2009+
if u32::from(current_primitive_restart_fixed_index_enabled[0]) == gl::FALSE {
2010+
gl_context.disable(gl::PRIMITIVE_RESTART_FIXED_INDEX);
2011+
}
20012012
gl_context.bind_framebuffer(gl::FRAMEBUFFER, current_framebuffers[0] as u32);
20022013
gl_context.bind_texture(gl::TEXTURE_2D, current_texture_2d[0] as u32);
20032014
gl_context.bind_buffer(gl::RENDERBUFFER, current_renderbuffers[0] as u32);

azul-core/src/svg.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl VertexLayoutDescription for SvgVertex {
184184
fields: vec![
185185
VertexAttribute {
186186
name: String::from("vAttrXY").into(),
187-
layout_location: Some(0).into(), // crate::gl::OptionUsize::None,
187+
layout_location: None.into(),
188188
attribute_type: VertexAttributeType::Float,
189189
item_count: 2,
190190
},
@@ -300,6 +300,7 @@ impl TessellatedGPUSvgNode {
300300
use crate::gl::{GlShader, Uniform, UniformType};
301301
use azul_css::PixelValue;
302302

303+
/*
303304
let transform_origin = StyleTransformOrigin {
304305
x: PixelValue::px(target_size.width as f32 / 2.0),
305306
y: PixelValue::px(target_size.height as f32 / 2.0),
@@ -311,7 +312,7 @@ impl TessellatedGPUSvgNode {
311312
target_size.width as f32,
312313
target_size.height as f32,
313314
RotationMode::ForWebRender
314-
);
315+
);*/
315316

316317
let color: ColorF = color.into();
317318

@@ -321,17 +322,18 @@ impl TessellatedGPUSvgNode {
321322
name: "vBboxSize".into(),
322323
uniform_type: UniformType::FloatVec2([target_size.width as f32, target_size.height as f32])
323324
},
325+
Uniform {
326+
name: "fDrawColor".into(),
327+
uniform_type: UniformType::FloatVec4([color.r, color.g, color.b, color.a])
328+
},
329+
/*
324330
Uniform {
325331
name: "vTransformMatrix".into(),
326332
uniform_type: UniformType::Matrix4 {
327333
transpose: false,
328334
matrix: unsafe { core::mem::transmute(computed_transform.m) }
329335
}
330-
},
331-
Uniform {
332-
name: "fDrawColor".into(),
333-
uniform_type: UniformType::FloatVec4([color.r, color.g, color.b, color.a])
334-
},
336+
},*/
335337
];
336338

337339
GlShader::draw(

azulc/src/svg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub use azul_core::svg::{
5353
#[cfg(feature = "svg")]
5454
extern crate tiny_skia;
5555

56-
const GL_RESTART_INDEX: u32 = core::u32::MAX;
56+
use azul_core::gl::GL_RESTART_INDEX;
5757

5858
#[cfg(feature = "svg")]
5959
fn translate_svg_line_join(e: SvgLineJoin) -> lyon::tessellation::LineJoin {

0 commit comments

Comments
 (0)