Pass texture id to imgui, and assert during rendering

This commit is contained in:
Joonas Javanainen 2016-03-26 19:18:05 +02:00
parent 775bcbc04e
commit 19a838104f
2 changed files with 17 additions and 6 deletions

View File

@ -1,10 +1,12 @@
use glium::{ use glium::{
index, program, texture, vertex, index, program, texture, vertex,
Blend, DrawError, DrawParameters, IndexBuffer, Program, Rect, Surface, Texture2d, VertexBuffer Blend, DrawError, DrawParameters, GlObject, IndexBuffer, Program, Rect, Surface, Texture2d,
VertexBuffer
}; };
use glium::backend::{Context, Facade}; use glium::backend::{Context, Facade};
use glium::index::PrimitiveType; use glium::index::PrimitiveType;
use glium::texture::{ClientFormat, RawImage2d}; use glium::texture::{ClientFormat, RawImage2d};
use libc::uintptr_t;
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt; use std::fmt;
use std::rc::Rc; use std::rc::Rc;
@ -97,13 +99,16 @@ impl Renderer {
[ 0.0, 0.0, -1.0, 0.0 ], [ 0.0, 0.0, -1.0, 0.0 ],
[ -1.0, 1.0, 0.0, 1.0 ] [ -1.0, 1.0, 0.0, 1.0 ]
]; ];
let uniforms = uniform! { let font_texture_id = self.device_objects.texture.get_id() as uintptr_t;
matrix: matrix,
tex: &self.device_objects.texture
};
let mut idx_start = 0; let mut idx_start = 0;
for cmd in draw_list.cmd_buffer { for cmd in draw_list.cmd_buffer {
// We don't support custom textures...yet!
assert!(cmd.texture_id as uintptr_t == font_texture_id);
let uniforms = uniform! {
matrix: matrix,
tex: &self.device_objects.texture
};
let draw_params = DrawParameters { let draw_params = DrawParameters {
blend: Blend::alpha_blending(), blend: Blend::alpha_blending(),
scissor: Some(Rect { scissor: Some(Rect {
@ -165,6 +170,7 @@ impl DeviceObjects {
}; };
Texture2d::new(ctx, data) Texture2d::new(ctx, data)
})); }));
im_gui.set_texture_id(texture.get_id() as uintptr_t);
Ok(DeviceObjects { Ok(DeviceObjects {
vertex_buffer: vertex_buffer, vertex_buffer: vertex_buffer,

View File

@ -6,7 +6,7 @@ extern crate imgui_sys;
extern crate libc; extern crate libc;
use libc::{c_char, c_float, c_int, c_uchar}; use libc::{c_char, c_float, c_int, c_uchar, c_void, uintptr_t};
use std::borrow::Cow; use std::borrow::Cow;
use std::convert::From; use std::convert::From;
use std::ffi::CStr; use std::ffi::CStr;
@ -155,6 +155,11 @@ impl ImGui {
}) })
} }
} }
pub fn set_texture_id(&mut self, value: uintptr_t) {
unsafe {
(*self.io_mut().fonts).tex_id = value as *mut c_void;
}
}
pub fn set_ini_filename(&mut self, value: Option<ImStr<'static>>) { pub fn set_ini_filename(&mut self, value: Option<ImStr<'static>>) {
{ {
let io = self.io_mut(); let io = self.io_mut();