mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-19 17:38:28 +00:00
commit
52820dbb3e
@ -10,7 +10,7 @@ categories = ["gui", "rendering"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
imgui = { version = "0.10.0", path = "../imgui" }
|
imgui = { version = "0.10.0", path = "../imgui" }
|
||||||
glow = "0.10.0"
|
glow = "0.12.0"
|
||||||
memoffset = "0.6.4"
|
memoffset = "0.6.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|||||||
@ -104,8 +104,8 @@ void main() {
|
|||||||
"#;
|
"#;
|
||||||
|
|
||||||
let mut shaders = [
|
let mut shaders = [
|
||||||
(glow::VERTEX_SHADER, VERTEX_SHADER_SOURCE, 0),
|
(glow::VERTEX_SHADER, VERTEX_SHADER_SOURCE, None),
|
||||||
(glow::FRAGMENT_SHADER, FRAGMENT_SHADER_SOURCE, 0),
|
(glow::FRAGMENT_SHADER, FRAGMENT_SHADER_SOURCE, None),
|
||||||
];
|
];
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -123,7 +123,7 @@ void main() {
|
|||||||
panic!("{}", gl.get_shader_info_log(shader));
|
panic!("{}", gl.get_shader_info_log(shader));
|
||||||
}
|
}
|
||||||
gl.attach_shader(program, shader);
|
gl.attach_shader(program, shader);
|
||||||
*handle = shader;
|
*handle = Some(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
gl.link_program(program);
|
gl.link_program(program);
|
||||||
@ -132,8 +132,8 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for &(_, _, shader) in &shaders {
|
for &(_, _, shader) in &shaders {
|
||||||
gl.detach_shader(program, shader);
|
gl.detach_shader(program, shader.unwrap());
|
||||||
gl.delete_shader(shader);
|
gl.delete_shader(shader.unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@ -45,7 +45,7 @@
|
|||||||
//! is sRGB (if you don't know, it probably is) the `internal_format` is
|
//! is sRGB (if you don't know, it probably is) the `internal_format` is
|
||||||
//! one of the `SRGB*` values.
|
//! one of the `SRGB*` values.
|
||||||
|
|
||||||
use std::{borrow::Cow, error::Error, fmt::Display, mem::size_of};
|
use std::{borrow::Cow, error::Error, fmt::Display, mem::size_of, num::NonZeroU32};
|
||||||
|
|
||||||
use imgui::{internal::RawWrapper, DrawCmd, DrawData, DrawVert};
|
use imgui::{internal::RawWrapper, DrawCmd, DrawData, DrawVert};
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ pub type GlBuffer = <Context as HasContext>::Buffer;
|
|||||||
pub type GlTexture = <Context as HasContext>::Texture;
|
pub type GlTexture = <Context as HasContext>::Texture;
|
||||||
pub type GlVertexArray = <Context as HasContext>::VertexArray;
|
pub type GlVertexArray = <Context as HasContext>::VertexArray;
|
||||||
type GlProgram = <Context as HasContext>::Program;
|
type GlProgram = <Context as HasContext>::Program;
|
||||||
type GlUniformLocation = <Context as HasContext>::Program;
|
type GlUniformLocation = <Context as HasContext>::UniformLocation;
|
||||||
|
|
||||||
/// Renderer which owns the OpenGL context and handles textures itself. Also
|
/// Renderer which owns the OpenGL context and handles textures itself. Also
|
||||||
/// converts all output colors to sRGB for display. Useful for simple applications,
|
/// converts all output colors to sRGB for display. Useful for simple applications,
|
||||||
@ -135,11 +135,11 @@ impl Drop for AutoRenderer {
|
|||||||
pub struct Renderer {
|
pub struct Renderer {
|
||||||
shaders: Shaders,
|
shaders: Shaders,
|
||||||
state_backup: GlStateBackup,
|
state_backup: GlStateBackup,
|
||||||
pub vbo_handle: GlBuffer,
|
pub vbo_handle: Option<GlBuffer>,
|
||||||
pub ebo_handle: GlBuffer,
|
pub ebo_handle: Option<GlBuffer>,
|
||||||
pub font_atlas_texture: GlTexture,
|
pub font_atlas_texture: Option<GlTexture>,
|
||||||
#[cfg(feature = "bind_vertex_array_support")]
|
#[cfg(feature = "bind_vertex_array_support")]
|
||||||
pub vertex_array_object: GlVertexArray,
|
pub vertex_array_object: Option<GlVertexArray>,
|
||||||
pub gl_version: GlVersion,
|
pub gl_version: GlVersion,
|
||||||
pub has_clip_origin_support: bool,
|
pub has_clip_origin_support: bool,
|
||||||
pub is_destroyed: bool,
|
pub is_destroyed: bool,
|
||||||
@ -216,11 +216,11 @@ impl Renderer {
|
|||||||
let out = Self {
|
let out = Self {
|
||||||
shaders,
|
shaders,
|
||||||
state_backup,
|
state_backup,
|
||||||
vbo_handle,
|
vbo_handle: Some(vbo_handle),
|
||||||
ebo_handle,
|
ebo_handle: Some(ebo_handle),
|
||||||
font_atlas_texture,
|
font_atlas_texture: Some(font_atlas_texture),
|
||||||
#[cfg(feature = "bind_vertex_array_support")]
|
#[cfg(feature = "bind_vertex_array_support")]
|
||||||
vertex_array_object: 0,
|
vertex_array_object: None,
|
||||||
gl_version,
|
gl_version,
|
||||||
has_clip_origin_support,
|
has_clip_origin_support,
|
||||||
is_destroyed: false,
|
is_destroyed: false,
|
||||||
@ -240,21 +240,21 @@ impl Renderer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.vbo_handle != 0 {
|
if let Some(h) = self.vbo_handle {
|
||||||
unsafe { gl.delete_buffer(self.vbo_handle) };
|
unsafe { gl.delete_buffer(h) };
|
||||||
self.vbo_handle = 0;
|
self.vbo_handle = None;
|
||||||
}
|
}
|
||||||
if self.ebo_handle != 0 {
|
if let Some(h) = self.ebo_handle {
|
||||||
unsafe { gl.delete_buffer(self.ebo_handle) };
|
unsafe { gl.delete_buffer(h) };
|
||||||
self.ebo_handle = 0;
|
self.ebo_handle = None;
|
||||||
}
|
}
|
||||||
let program = self.shaders.program;
|
if let Some(p) = self.shaders.program {
|
||||||
if program != 0 {
|
unsafe { gl.delete_program(p) };
|
||||||
unsafe { gl.delete_program(program) };
|
self.shaders.program = None;
|
||||||
}
|
}
|
||||||
if self.font_atlas_texture != 0 {
|
if let Some(h) = self.font_atlas_texture {
|
||||||
unsafe { gl.delete_texture(self.font_atlas_texture) };
|
unsafe { gl.delete_texture(h) };
|
||||||
self.font_atlas_texture = 0;
|
self.font_atlas_texture = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.is_destroyed = true;
|
self.is_destroyed = true;
|
||||||
@ -285,10 +285,10 @@ impl Renderer {
|
|||||||
#[cfg(feature = "bind_vertex_array_support")]
|
#[cfg(feature = "bind_vertex_array_support")]
|
||||||
if self.gl_version.bind_vertex_array_support() {
|
if self.gl_version.bind_vertex_array_support() {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.vertex_array_object = gl
|
self.vertex_array_object = Some(gl
|
||||||
.create_vertex_array()
|
.create_vertex_array()
|
||||||
.map_err(|err| format!("Error creating vertex array object: {}", err))?;
|
.map_err(|err| format!("Error creating vertex array object: {}", err))?);
|
||||||
gl.bind_vertex_array(Some(self.vertex_array_object));
|
gl.bind_vertex_array(self.vertex_array_object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +333,8 @@ impl Renderer {
|
|||||||
|
|
||||||
#[cfg(feature = "bind_vertex_array_support")]
|
#[cfg(feature = "bind_vertex_array_support")]
|
||||||
if self.gl_version.bind_vertex_array_support() {
|
if self.gl_version.bind_vertex_array_support() {
|
||||||
unsafe { gl.delete_vertex_array(self.vertex_array_object) };
|
unsafe { gl.delete_vertex_array(self.vertex_array_object.unwrap()) };
|
||||||
|
self.vertex_array_object = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.state_backup.post_render(gl, self.gl_version);
|
self.state_backup.post_render(gl, self.gl_version);
|
||||||
@ -398,7 +399,7 @@ impl Renderer {
|
|||||||
let projection_matrix = calculate_matrix(draw_data, clip_origin_is_lower_left);
|
let projection_matrix = calculate_matrix(draw_data, clip_origin_is_lower_left);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
gl.use_program(Some(self.shaders.program));
|
gl.use_program(self.shaders.program);
|
||||||
gl.uniform_1_i32(Some(&self.shaders.texture_uniform_location), 0);
|
gl.uniform_1_i32(Some(&self.shaders.texture_uniform_location), 0);
|
||||||
gl.uniform_matrix_4_f32_slice(
|
gl.uniform_matrix_4_f32_slice(
|
||||||
Some(&self.shaders.matrix_uniform_location),
|
Some(&self.shaders.matrix_uniform_location),
|
||||||
@ -418,8 +419,8 @@ impl Renderer {
|
|||||||
let color_field_offset = memoffset::offset_of!(DrawVert, col) as _;
|
let color_field_offset = memoffset::offset_of!(DrawVert, col) as _;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
gl.bind_buffer(glow::ARRAY_BUFFER, Some(self.vbo_handle));
|
gl.bind_buffer(glow::ARRAY_BUFFER, self.vbo_handle);
|
||||||
gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, Some(self.ebo_handle));
|
gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, self.ebo_handle);
|
||||||
gl.enable_vertex_attrib_array(self.shaders.position_attribute_index);
|
gl.enable_vertex_attrib_array(self.shaders.position_attribute_index);
|
||||||
gl.vertex_attrib_pointer_f32(
|
gl.vertex_attrib_pointer_f32(
|
||||||
self.shaders.position_attribute_index,
|
self.shaders.position_attribute_index,
|
||||||
@ -565,13 +566,13 @@ pub struct SimpleTextureMap();
|
|||||||
impl TextureMap for SimpleTextureMap {
|
impl TextureMap for SimpleTextureMap {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn register(&mut self, gl_texture: glow::Texture) -> Option<imgui::TextureId> {
|
fn register(&mut self, gl_texture: glow::Texture) -> Option<imgui::TextureId> {
|
||||||
Some(imgui::TextureId::new(gl_texture as _))
|
Some(imgui::TextureId::new(gl_texture.0.get() as _))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn gl_texture(&self, imgui_texture: imgui::TextureId) -> Option<glow::Texture> {
|
fn gl_texture(&self, imgui_texture: imgui::TextureId) -> Option<glow::Texture> {
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
Some(imgui_texture.id() as _)
|
Some(glow::NativeTexture(NonZeroU32::new(imgui_texture.id() as _).unwrap()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -602,12 +603,12 @@ impl TextureMap for imgui::Textures<glow::Texture> {
|
|||||||
#[allow(clippy::struct_excessive_bools)]
|
#[allow(clippy::struct_excessive_bools)]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct GlStateBackup {
|
pub struct GlStateBackup {
|
||||||
active_texture: i32,
|
active_texture: u32,
|
||||||
program: i32,
|
program: u32,
|
||||||
texture: i32,
|
texture: u32,
|
||||||
#[cfg(feature = "bind_sampler_support")]
|
#[cfg(feature = "bind_sampler_support")]
|
||||||
sampler: Option<i32>,
|
sampler: Option<u32>,
|
||||||
array_buffer: i32,
|
array_buffer: u32,
|
||||||
#[cfg(feature = "polygon_mode_support")]
|
#[cfg(feature = "polygon_mode_support")]
|
||||||
polygon_mode: Option<[i32; 2]>,
|
polygon_mode: Option<[i32; 2]>,
|
||||||
viewport: [i32; 4],
|
viewport: [i32; 4],
|
||||||
@ -626,34 +627,42 @@ pub struct GlStateBackup {
|
|||||||
#[cfg(feature = "primitive_restart_support")]
|
#[cfg(feature = "primitive_restart_support")]
|
||||||
primitive_restart_enabled: Option<bool>,
|
primitive_restart_enabled: Option<bool>,
|
||||||
#[cfg(feature = "bind_vertex_array_support")]
|
#[cfg(feature = "bind_vertex_array_support")]
|
||||||
vertex_array_object: Option<glow::VertexArray>,
|
vertex_array_object: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_native_gl<T>(handle: u32, constructor: fn(NonZeroU32) -> T) -> Option<T> {
|
||||||
|
if handle != 0 {
|
||||||
|
Some(constructor(NonZeroU32::new(handle).unwrap()))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlStateBackup {
|
impl GlStateBackup {
|
||||||
fn pre_init(&mut self, gl: &Context) {
|
fn pre_init(&mut self, gl: &Context) {
|
||||||
self.texture = unsafe { gl.get_parameter_i32(glow::TEXTURE_BINDING_2D) };
|
self.texture = unsafe { gl.get_parameter_i32(glow::TEXTURE_BINDING_2D) as _ };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn post_init(&mut self, gl: &Context) {
|
fn post_init(&mut self, gl: &Context) {
|
||||||
#[allow(clippy::cast_sign_loss)]
|
#[allow(clippy::cast_sign_loss)]
|
||||||
unsafe {
|
unsafe {
|
||||||
gl.bind_texture(glow::TEXTURE_2D, Some(self.texture as _));
|
gl.bind_texture(glow::TEXTURE_2D, to_native_gl(self.texture, glow::NativeTexture));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pre_render(&mut self, gl: &Context, gl_version: GlVersion) {
|
fn pre_render(&mut self, gl: &Context, gl_version: GlVersion) {
|
||||||
#[allow(clippy::cast_sign_loss)]
|
#[allow(clippy::cast_sign_loss)]
|
||||||
unsafe {
|
unsafe {
|
||||||
self.active_texture = gl.get_parameter_i32(glow::ACTIVE_TEXTURE);
|
self.active_texture = gl.get_parameter_i32(glow::ACTIVE_TEXTURE) as _;
|
||||||
self.program = gl.get_parameter_i32(glow::CURRENT_PROGRAM);
|
self.program = gl.get_parameter_i32(glow::CURRENT_PROGRAM) as _;
|
||||||
self.texture = gl.get_parameter_i32(glow::TEXTURE_BINDING_2D);
|
self.texture = gl.get_parameter_i32(glow::TEXTURE_BINDING_2D) as _;
|
||||||
#[cfg(feature = "bind_sampler_support")]
|
#[cfg(feature = "bind_sampler_support")]
|
||||||
if gl_version.bind_sampler_support() {
|
if gl_version.bind_sampler_support() {
|
||||||
self.sampler = Some(gl.get_parameter_i32(glow::SAMPLER_BINDING));
|
self.sampler = Some(gl.get_parameter_i32(glow::SAMPLER_BINDING) as _);
|
||||||
} else {
|
} else {
|
||||||
self.sampler = None;
|
self.sampler = None;
|
||||||
}
|
}
|
||||||
self.array_buffer = gl.get_parameter_i32(glow::ARRAY_BUFFER_BINDING);
|
self.array_buffer = gl.get_parameter_i32(glow::ARRAY_BUFFER_BINDING) as _;
|
||||||
|
|
||||||
#[cfg(feature = "bind_vertex_array_support")]
|
#[cfg(feature = "bind_vertex_array_support")]
|
||||||
if gl_version.bind_vertex_array_support() {
|
if gl_version.bind_vertex_array_support() {
|
||||||
@ -695,18 +704,18 @@ impl GlStateBackup {
|
|||||||
fn post_render(&mut self, gl: &Context, _gl_version: GlVersion) {
|
fn post_render(&mut self, gl: &Context, _gl_version: GlVersion) {
|
||||||
#![allow(clippy::cast_sign_loss)]
|
#![allow(clippy::cast_sign_loss)]
|
||||||
unsafe {
|
unsafe {
|
||||||
gl.use_program(Some(self.program as _));
|
gl.use_program(to_native_gl(self.program, glow::NativeProgram));
|
||||||
gl.bind_texture(glow::TEXTURE_2D, Some(self.texture as _));
|
gl.bind_texture(glow::TEXTURE_2D, to_native_gl(self.texture, glow::NativeTexture));
|
||||||
#[cfg(feature = "bind_sampler_support")]
|
#[cfg(feature = "bind_sampler_support")]
|
||||||
if let Some(sampler) = self.sampler {
|
if let Some(sampler) = self.sampler {
|
||||||
gl.bind_sampler(0, Some(sampler as _));
|
gl.bind_sampler(0, to_native_gl(sampler, glow::NativeSampler));
|
||||||
}
|
}
|
||||||
gl.active_texture(self.active_texture as _);
|
gl.active_texture(self.active_texture as _);
|
||||||
#[cfg(feature = "bind_vertex_array_support")]
|
#[cfg(feature = "bind_vertex_array_support")]
|
||||||
if let Some(vao) = self.vertex_array_object {
|
if let Some(vao) = self.vertex_array_object {
|
||||||
gl.bind_vertex_array(Some(vao));
|
gl.bind_vertex_array(to_native_gl(vao, glow::NativeVertexArray));
|
||||||
}
|
}
|
||||||
gl.bind_buffer(glow::ARRAY_BUFFER, Some(self.array_buffer as _));
|
gl.bind_buffer(glow::ARRAY_BUFFER, to_native_gl(self.array_buffer, glow::NativeBuffer));
|
||||||
gl.blend_equation_separate(
|
gl.blend_equation_separate(
|
||||||
self.blend_equation_rgb as _,
|
self.blend_equation_rgb as _,
|
||||||
self.blend_equation_alpha as _,
|
self.blend_equation_alpha as _,
|
||||||
@ -774,7 +783,7 @@ impl GlStateBackup {
|
|||||||
/// generate shaders which should work on a wide variety of modern devices
|
/// generate shaders which should work on a wide variety of modern devices
|
||||||
/// (GL >= 3.3 and GLES >= 2.0 are expected to work).
|
/// (GL >= 3.3 and GLES >= 2.0 are expected to work).
|
||||||
struct Shaders {
|
struct Shaders {
|
||||||
program: GlProgram,
|
program: Option<GlProgram>,
|
||||||
texture_uniform_location: GlUniformLocation,
|
texture_uniform_location: GlUniformLocation,
|
||||||
matrix_uniform_location: GlUniformLocation,
|
matrix_uniform_location: GlUniformLocation,
|
||||||
position_attribute_index: u32,
|
position_attribute_index: u32,
|
||||||
@ -829,7 +838,7 @@ impl Shaders {
|
|||||||
|
|
||||||
Ok(unsafe {
|
Ok(unsafe {
|
||||||
Self {
|
Self {
|
||||||
program,
|
program: Some(program),
|
||||||
texture_uniform_location: gl
|
texture_uniform_location: gl
|
||||||
.get_uniform_location(program, "tex")
|
.get_uniform_location(program, "tex")
|
||||||
.ok_or_else(|| ShaderError::UniformNotFound("tex".into()))?,
|
.ok_or_else(|| ShaderError::UniformNotFound("tex".into()))?,
|
||||||
|
|||||||
@ -15,6 +15,6 @@ imgui = { version = "0.10.0", path = "../imgui" }
|
|||||||
sdl2 = "0.34.5"
|
sdl2 = "0.34.5"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
glow = "0.10.0"
|
glow = "0.12.0"
|
||||||
imgui-glow-renderer = { version = "0.10.0", path = "../imgui-glow-renderer" }
|
imgui-glow-renderer = { version = "0.10.0", path = "../imgui-glow-renderer" }
|
||||||
sdl2 = { version = "0.34.5", features = ["bundled", "static-link"] }
|
sdl2 = { version = "0.34.5", features = ["bundled", "static-link"] }
|
||||||
|
|||||||
@ -8,7 +8,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
imgui = { version="0.10.0", path="../imgui", features=["docking"] }
|
imgui = { version="0.10.0", path="../imgui", features=["docking"] }
|
||||||
|
|
||||||
glow = "0.11.2"
|
glow = "0.12.0"
|
||||||
glutin = "0.30.3"
|
glutin = "0.30.3"
|
||||||
raw-window-handle = "0.5.0"
|
raw-window-handle = "0.5.0"
|
||||||
winit = "0.27.5"
|
winit = "0.27.5"
|
||||||
|
|||||||
@ -226,12 +226,20 @@ struct GlStateBackup {
|
|||||||
blend_func_dst: i32,
|
blend_func_dst: i32,
|
||||||
scissor_enabled: bool,
|
scissor_enabled: bool,
|
||||||
scissor: [i32; 4],
|
scissor: [i32; 4],
|
||||||
vao: i32,
|
vao: u32,
|
||||||
vbo: i32,
|
vbo: u32,
|
||||||
ibo: i32,
|
ibo: u32,
|
||||||
active_texture: i32,
|
active_texture: u32,
|
||||||
texture: i32,
|
texture: u32,
|
||||||
program: i32,
|
program: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_native_gl<T>(handle: u32, constructor: fn(NonZeroU32) -> T) -> Option<T> {
|
||||||
|
if handle != 0 {
|
||||||
|
Some(constructor(NonZeroU32::new(handle).unwrap()))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlStateBackup {
|
impl GlStateBackup {
|
||||||
@ -248,15 +256,15 @@ impl GlStateBackup {
|
|||||||
let mut scissor = [0; 4];
|
let mut scissor = [0; 4];
|
||||||
context.get_parameter_i32_slice(glow::SCISSOR_BOX, &mut scissor);
|
context.get_parameter_i32_slice(glow::SCISSOR_BOX, &mut scissor);
|
||||||
|
|
||||||
let vao = context.get_parameter_i32(glow::VERTEX_ARRAY_BINDING);
|
let vao = context.get_parameter_i32(glow::VERTEX_ARRAY_BINDING) as _;
|
||||||
let vbo = context.get_parameter_i32(glow::ARRAY_BUFFER_BINDING);
|
let vbo = context.get_parameter_i32(glow::ARRAY_BUFFER_BINDING) as _;
|
||||||
let ibo = context.get_parameter_i32(glow::ELEMENT_ARRAY_BUFFER_BINDING);
|
let ibo = context.get_parameter_i32(glow::ELEMENT_ARRAY_BUFFER_BINDING) as _;
|
||||||
|
|
||||||
let active_texture = context.get_parameter_i32(glow::ACTIVE_TEXTURE);
|
let active_texture = context.get_parameter_i32(glow::ACTIVE_TEXTURE) as _;
|
||||||
context.active_texture(0);
|
context.active_texture(0);
|
||||||
let texture = context.get_parameter_i32(glow::TEXTURE_BINDING_2D);
|
let texture = context.get_parameter_i32(glow::TEXTURE_BINDING_2D) as _;
|
||||||
|
|
||||||
let program = context.get_parameter_i32(glow::CURRENT_PROGRAM);
|
let program = context.get_parameter_i32(glow::CURRENT_PROGRAM) as _;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
viewport,
|
viewport,
|
||||||
@ -295,41 +303,15 @@ impl GlStateBackup {
|
|||||||
self.scissor[3],
|
self.scissor[3],
|
||||||
);
|
);
|
||||||
|
|
||||||
if self.vao != 0 {
|
context.bind_vertex_array(to_native_gl(self.vao, glow::NativeVertexArray));
|
||||||
let vao = std::mem::transmute(self.vao);
|
|
||||||
context.bind_vertex_array(Some(vao));
|
|
||||||
} else {
|
|
||||||
context.bind_vertex_array(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.vbo != 0 {
|
context.bind_buffer(glow::ARRAY_BUFFER, to_native_gl(self.vbo, glow::NativeBuffer));
|
||||||
let vbo = std::mem::transmute(self.vbo);
|
context.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, to_native_gl(self.ibo, glow::NativeBuffer));
|
||||||
context.bind_buffer(glow::ARRAY_BUFFER, Some(vbo));
|
|
||||||
} else {
|
|
||||||
context.bind_buffer(glow::ARRAY_BUFFER, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.ibo != 0 {
|
context.bind_texture(glow::TEXTURE_2D, to_native_gl(self.texture, glow::NativeTexture));
|
||||||
let ibo = std::mem::transmute(self.ibo);
|
context.active_texture(self.active_texture);
|
||||||
context.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, Some(ibo));
|
|
||||||
} else {
|
|
||||||
context.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.texture != 0 {
|
context.use_program(to_native_gl(self.program, glow::NativeProgram));
|
||||||
let texture = std::mem::transmute(self.texture);
|
|
||||||
context.bind_texture(glow::TEXTURE_2D, Some(texture));
|
|
||||||
} else {
|
|
||||||
context.bind_texture(glow::TEXTURE_2D, None);
|
|
||||||
}
|
|
||||||
context.active_texture(self.active_texture as _);
|
|
||||||
|
|
||||||
if self.program != 0 {
|
|
||||||
let program = std::mem::transmute(self.program);
|
|
||||||
context.use_program(Some(program));
|
|
||||||
} else {
|
|
||||||
context.use_program(None);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -54,12 +54,24 @@ fn test_texture_id_memory_layout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Generic texture mapping for use by renderers.
|
/// Generic texture mapping for use by renderers.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug)]
|
||||||
pub struct Textures<T> {
|
pub struct Textures<T> {
|
||||||
textures: HashMap<usize, T>,
|
textures: HashMap<usize, T>,
|
||||||
next: usize,
|
next: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// We manually impl Default as `#[derive(Default)]`
|
||||||
|
/// incorrectly requires `T: Default` which is
|
||||||
|
/// not necessary at all.
|
||||||
|
impl<T> Default for Textures<T> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
textures: Default::default(),
|
||||||
|
next: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> Textures<T> {
|
impl<T> Textures<T> {
|
||||||
// TODO: hasher like rustc_hash::FxHashMap or something would let this be
|
// TODO: hasher like rustc_hash::FxHashMap or something would let this be
|
||||||
// `const fn`
|
// `const fn`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user