Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3a19ad

Browse files
committed
Update glow to 0.12 and winit to 0.28.
1 parent a2ad8dd commit e3a19ad

File tree

5 files changed

+60
-43
lines changed

5 files changed

+60
-43
lines changed

imgui-glow-renderer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ categories = ["gui", "rendering"]
1010

1111
[dependencies]
1212
imgui = { version = "0.10.0", path = "../imgui" }
13-
glow = "0.10.0"
13+
glow = "0.12.0"
1414
memoffset = "0.6.4"
1515

1616
[dev-dependencies]

imgui-glow-renderer/src/lib.rs

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
//! is sRGB (if you don't know, it probably is) the `internal_format` is
4646
//! one of the `SRGB*` values.
4747
48-
use std::{borrow::Cow, error::Error, fmt::Display, mem::size_of};
48+
use std::{borrow::Cow, error::Error, fmt::Display, mem::size_of, num::NonZeroU32};
4949

5050
use imgui::{internal::RawWrapper, DrawCmd, DrawData, DrawVert};
5151

@@ -61,7 +61,7 @@ pub type GlBuffer = <Context as HasContext>::Buffer;
6161
pub type GlTexture = <Context as HasContext>::Texture;
6262
pub type GlVertexArray = <Context as HasContext>::VertexArray;
6363
type GlProgram = <Context as HasContext>::Program;
64-
type GlUniformLocation = <Context as HasContext>::Program;
64+
type GlUniformLocation = <Context as HasContext>::UniformLocation;
6565

6666
/// Renderer which owns the OpenGL context and handles textures itself. Also
6767
/// converts all output colors to sRGB for display. Useful for simple applications,
@@ -135,11 +135,11 @@ impl Drop for AutoRenderer {
135135
pub struct Renderer {
136136
shaders: Shaders,
137137
state_backup: GlStateBackup,
138-
pub vbo_handle: GlBuffer,
139-
pub ebo_handle: GlBuffer,
140-
pub font_atlas_texture: GlTexture,
138+
pub vbo_handle: Option<GlBuffer>,
139+
pub ebo_handle: Option<GlBuffer>,
140+
pub font_atlas_texture: Option<GlTexture>,
141141
#[cfg(feature = "bind_vertex_array_support")]
142-
pub vertex_array_object: GlVertexArray,
142+
pub vertex_array_object: Option<GlVertexArray>,
143143
pub gl_version: GlVersion,
144144
pub has_clip_origin_support: bool,
145145
pub is_destroyed: bool,
@@ -205,11 +205,13 @@ impl Renderer {
205205
let mut state_backup = GlStateBackup::default();
206206
state_backup.pre_init(gl);
207207

208-
let font_atlas_texture = prepare_font_atlas(gl, imgui_context.fonts(), texture_map)?;
208+
let font_atlas_texture = Some(prepare_font_atlas(gl, imgui_context.fonts(), texture_map)?);
209209

210210
let shaders = Shaders::new(gl, gl_version, output_srgb)?;
211-
let vbo_handle = unsafe { gl.create_buffer() }.map_err(InitError::CreateBufferObject)?;
212-
let ebo_handle = unsafe { gl.create_buffer() }.map_err(InitError::CreateBufferObject)?;
211+
let vbo_handle =
212+
Some(unsafe { gl.create_buffer() }.map_err(InitError::CreateBufferObject)?);
213+
let ebo_handle =
214+
Some(unsafe { gl.create_buffer() }.map_err(InitError::CreateBufferObject)?);
213215

214216
state_backup.post_init(gl);
215217

@@ -220,7 +222,7 @@ impl Renderer {
220222
ebo_handle,
221223
font_atlas_texture,
222224
#[cfg(feature = "bind_vertex_array_support")]
223-
vertex_array_object: 0,
225+
vertex_array_object: None,
224226
gl_version,
225227
has_clip_origin_support,
226228
is_destroyed: false,
@@ -240,21 +242,17 @@ impl Renderer {
240242
return;
241243
}
242244

243-
if self.vbo_handle != 0 {
244-
unsafe { gl.delete_buffer(self.vbo_handle) };
245-
self.vbo_handle = 0;
245+
if let Some(vbo) = self.vbo_handle.take() {
246+
unsafe { gl.delete_buffer(vbo) };
246247
}
247-
if self.ebo_handle != 0 {
248-
unsafe { gl.delete_buffer(self.ebo_handle) };
249-
self.ebo_handle = 0;
248+
if let Some(ebo) = self.ebo_handle.take() {
249+
unsafe { gl.delete_buffer(ebo) };
250250
}
251-
let program = self.shaders.program;
252-
if program != 0 {
251+
if let Some(program) = self.shaders.program.take() {
253252
unsafe { gl.delete_program(program) };
254253
}
255-
if self.font_atlas_texture != 0 {
256-
unsafe { gl.delete_texture(self.font_atlas_texture) };
257-
self.font_atlas_texture = 0;
254+
if let Some(atlas) = self.font_atlas_texture.take() {
255+
unsafe { gl.delete_texture(atlas) };
258256
}
259257

260258
self.is_destroyed = true;
@@ -285,10 +283,11 @@ impl Renderer {
285283
#[cfg(feature = "bind_vertex_array_support")]
286284
if self.gl_version.bind_vertex_array_support() {
287285
unsafe {
288-
self.vertex_array_object = gl
286+
let vao = gl
289287
.create_vertex_array()
290288
.map_err(|err| format!("Error creating vertex array object: {}", err))?;
291-
gl.bind_vertex_array(Some(self.vertex_array_object));
289+
self.vertex_array_object = Some(vao);
290+
gl.bind_vertex_array(self.vertex_array_object);
292291
}
293292
}
294293

@@ -333,7 +332,9 @@ impl Renderer {
333332

334333
#[cfg(feature = "bind_vertex_array_support")]
335334
if self.gl_version.bind_vertex_array_support() {
336-
unsafe { gl.delete_vertex_array(self.vertex_array_object) };
335+
if let Some(vao) = self.vertex_array_object.take() {
336+
unsafe { gl.delete_vertex_array(vao) };
337+
}
337338
}
338339

339340
self.state_backup.post_render(gl, self.gl_version);
@@ -398,7 +399,7 @@ impl Renderer {
398399
let projection_matrix = calculate_matrix(draw_data, clip_origin_is_lower_left);
399400

400401
unsafe {
401-
gl.use_program(Some(self.shaders.program));
402+
gl.use_program(self.shaders.program);
402403
gl.uniform_1_i32(Some(&self.shaders.texture_uniform_location), 0);
403404
gl.uniform_matrix_4_f32_slice(
404405
Some(&self.shaders.matrix_uniform_location),
@@ -418,8 +419,8 @@ impl Renderer {
418419
let color_field_offset = memoffset::offset_of!(DrawVert, col) as _;
419420

420421
unsafe {
421-
gl.bind_buffer(glow::ARRAY_BUFFER, Some(self.vbo_handle));
422-
gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, Some(self.ebo_handle));
422+
gl.bind_buffer(glow::ARRAY_BUFFER, self.vbo_handle);
423+
gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, self.ebo_handle);
423424
gl.enable_vertex_attrib_array(self.shaders.position_attribute_index);
424425
gl.vertex_attrib_pointer_f32(
425426
self.shaders.position_attribute_index,
@@ -483,7 +484,13 @@ impl Renderer {
483484
let clip_x2 = (clip_rect[2] - clip_off[0]) * scale[0];
484485
let clip_y2 = (clip_rect[3] - clip_off[1]) * scale[1];
485486

486-
if clip_x1 >= fb_width || clip_y1 >= fb_height || clip_x2 < 0.0 || clip_y2 < 0.0 {
487+
if clip_x1 >= fb_width
488+
|| clip_y1 >= fb_height
489+
|| clip_x2 < 0.0
490+
|| clip_y2 < 0.0
491+
|| clip_x2 <= clip_x1
492+
|| clip_y2 <= clip_y1
493+
{
487494
return;
488495
}
489496

@@ -565,13 +572,13 @@ pub struct SimpleTextureMap();
565572
impl TextureMap for SimpleTextureMap {
566573
#[inline(always)]
567574
fn register(&mut self, gl_texture: glow::Texture) -> Option<imgui::TextureId> {
568-
Some(imgui::TextureId::new(gl_texture as _))
575+
Some(imgui::TextureId::new(gl_texture.0.get() as usize))
569576
}
570577

571578
#[inline(always)]
572579
fn gl_texture(&self, imgui_texture: imgui::TextureId) -> Option<glow::Texture> {
573580
#[allow(clippy::cast_possible_truncation)]
574-
Some(imgui_texture.id() as _)
581+
NonZeroU32::new(imgui_texture.id() as u32).map(glow::NativeTexture)
575582
}
576583
}
577584

@@ -637,7 +644,10 @@ impl GlStateBackup {
637644
fn post_init(&mut self, gl: &Context) {
638645
#[allow(clippy::cast_sign_loss)]
639646
unsafe {
640-
gl.bind_texture(glow::TEXTURE_2D, Some(self.texture as _));
647+
gl.bind_texture(
648+
glow::TEXTURE_2D,
649+
NonZeroU32::new(self.texture as u32).map(glow::NativeTexture),
650+
);
641651
}
642652
}
643653

@@ -658,7 +668,8 @@ impl GlStateBackup {
658668
#[cfg(feature = "bind_vertex_array_support")]
659669
if gl_version.bind_vertex_array_support() {
660670
self.vertex_array_object =
661-
Some(gl.get_parameter_i32(glow::VERTEX_ARRAY_BINDING) as _);
671+
NonZeroU32::new(gl.get_parameter_i32(glow::VERTEX_ARRAY_BINDING) as _)
672+
.map(glow::NativeVertexArray)
662673
}
663674

664675
#[cfg(feature = "polygon_mode_support")]
@@ -695,18 +706,24 @@ impl GlStateBackup {
695706
fn post_render(&mut self, gl: &Context, _gl_version: GlVersion) {
696707
#![allow(clippy::cast_sign_loss)]
697708
unsafe {
698-
gl.use_program(Some(self.program as _));
699-
gl.bind_texture(glow::TEXTURE_2D, Some(self.texture as _));
709+
gl.use_program(NonZeroU32::new(self.program as _).map(glow::NativeProgram));
710+
gl.bind_texture(
711+
glow::TEXTURE_2D,
712+
NonZeroU32::new(self.texture as _).map(glow::NativeTexture),
713+
);
700714
#[cfg(feature = "bind_sampler_support")]
701715
if let Some(sampler) = self.sampler {
702-
gl.bind_sampler(0, Some(sampler as _));
716+
gl.bind_sampler(0, NonZeroU32::new(sampler as _).map(glow::NativeSampler));
703717
}
704718
gl.active_texture(self.active_texture as _);
705719
#[cfg(feature = "bind_vertex_array_support")]
706720
if let Some(vao) = self.vertex_array_object {
707721
gl.bind_vertex_array(Some(vao));
708722
}
709-
gl.bind_buffer(glow::ARRAY_BUFFER, Some(self.array_buffer as _));
723+
gl.bind_buffer(
724+
glow::ARRAY_BUFFER,
725+
NonZeroU32::new(self.array_buffer as _).map(glow::NativeBuffer),
726+
);
710727
gl.blend_equation_separate(
711728
self.blend_equation_rgb as _,
712729
self.blend_equation_alpha as _,
@@ -774,7 +791,7 @@ impl GlStateBackup {
774791
/// generate shaders which should work on a wide variety of modern devices
775792
/// (GL >= 3.3 and GLES >= 2.0 are expected to work).
776793
struct Shaders {
777-
program: GlProgram,
794+
program: Option<GlProgram>,
778795
texture_uniform_location: GlUniformLocation,
779796
matrix_uniform_location: GlUniformLocation,
780797
position_attribute_index: u32,
@@ -829,7 +846,7 @@ impl Shaders {
829846

830847
Ok(unsafe {
831848
Self {
832-
program,
849+
program: Some(program),
833850
texture_uniform_location: gl
834851
.get_uniform_location(program, "tex")
835852
.ok_or_else(|| ShaderError::UniformNotFound("tex".into()))?,

imgui-sdl2-support/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ imgui = { version = "0.10.0", path = "../imgui" }
1515
sdl2 = "0.34.5"
1616

1717
[dev-dependencies]
18-
glow = "0.10.0"
18+
glow = "0.12.0"
1919
imgui-glow-renderer = { version = "0.10.0", path = "../imgui-glow-renderer" }
2020
sdl2 = { version = "0.34.5", features = ["bundled", "static-link"] }

imgui-winit-glow-renderer-viewports/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ edition = "2021"
88
[dependencies]
99
imgui = { version="0.10.0", path="../imgui", features=["docking"] }
1010

11-
glow = "0.11.2"
11+
glow = "0.12.0"
1212
glutin = "0.30.3"
1313
raw-window-handle = "0.5.0"
14-
winit = "0.27.5"
14+
winit = "0.28.0"
1515
thiserror = "1.0.38"
1616
glutin-winit = "0.2.1"

imgui-winit-support/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ categories = ["gui"]
1111

1212
[dependencies]
1313
imgui = { version = "0.10.0", path = "../imgui" }
14-
winit = { version = "0.27.2", default-features = false }
14+
winit = { version = "0.28.0", default-features = false }

0 commit comments

Comments
 (0)