mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 13:38:35 +00:00
Go back to unprefixed *Renderer and *RendererError names
Prefixing wasn't supposed to end up in master
This commit is contained in:
parent
3f6bc12e0b
commit
0132ab5207
@ -1,7 +1,7 @@
|
||||
use glium::glutin::{self, Event, WindowEvent};
|
||||
use glium::{Display, Surface};
|
||||
use imgui::{Context, FontConfig, FontGlyphRanges, FontSource, Ui};
|
||||
use imgui_glium_renderer::GliumRenderer;
|
||||
use imgui_glium_renderer::Renderer;
|
||||
use imgui_winit_support::{HiDpiMode, WinitPlatform};
|
||||
use std::time::Instant;
|
||||
|
||||
@ -12,7 +12,7 @@ pub struct System {
|
||||
pub display: glium::Display,
|
||||
pub imgui: Context,
|
||||
pub platform: WinitPlatform,
|
||||
pub renderer: GliumRenderer,
|
||||
pub renderer: Renderer,
|
||||
pub font_size: f32,
|
||||
}
|
||||
|
||||
@ -67,8 +67,7 @@ pub fn init(title: &str) -> System {
|
||||
|
||||
imgui.io_mut().font_global_scale = (1.0 / hidpi_factor) as f32;
|
||||
|
||||
let renderer =
|
||||
GliumRenderer::init(&mut imgui, &display).expect("Failed to initialize renderer");
|
||||
let renderer = Renderer::init(&mut imgui, &display).expect("Failed to initialize renderer");
|
||||
|
||||
System {
|
||||
events_loop,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use gfx::Device;
|
||||
use glutin::{Event, WindowEvent};
|
||||
use imgui::{Context, FontConfig, FontGlyphRanges, FontSource, Ui};
|
||||
use imgui_gfx_renderer::{GfxRenderer, Shaders};
|
||||
use imgui_gfx_renderer::{Renderer, Shaders};
|
||||
use imgui_winit_support::{HiDpiMode, WinitPlatform};
|
||||
use std::time::Instant;
|
||||
|
||||
@ -125,7 +125,7 @@ mod types {
|
||||
|
||||
#[cfg(feature = "opengl")]
|
||||
pub struct RenderSystem {
|
||||
pub renderer: GfxRenderer<ColorFormat, types::Resources>,
|
||||
pub renderer: Renderer<ColorFormat, types::Resources>,
|
||||
pub windowed_context: glutin::WindowedContext<glutin::PossiblyCurrent>,
|
||||
pub device: types::Device,
|
||||
pub factory: types::Factory,
|
||||
@ -181,7 +181,7 @@ impl RenderSystem {
|
||||
}
|
||||
};
|
||||
let renderer =
|
||||
GfxRenderer::init(imgui, &mut factory, shaders).expect("Failed to initialize renderer");
|
||||
Renderer::init(imgui, &mut factory, shaders).expect("Failed to initialize renderer");
|
||||
RenderSystem {
|
||||
renderer,
|
||||
windowed_context,
|
||||
@ -217,7 +217,7 @@ mod types {
|
||||
|
||||
#[cfg(feature = "directx")]
|
||||
pub struct RenderSystem {
|
||||
pub renderer: GfxRenderer<ColorFormat, types::Resources>,
|
||||
pub renderer: Renderer<ColorFormat, types::Resources>,
|
||||
pub window: gfx_window_dxgi::Window,
|
||||
pub device: types::Device,
|
||||
pub factory: types::Factory,
|
||||
@ -233,7 +233,7 @@ impl RenderSystem {
|
||||
) -> RenderSystem {
|
||||
let (window, device, mut factory, main_color) =
|
||||
gfx_window_dxgi::init(builder, &events_loop).expect("Failed to initialize graphics");
|
||||
let renderer = GfxRenderer::init(imgui, &mut factory, Shaders::HlslSm40)
|
||||
let renderer = Renderer::init(imgui, &mut factory, Shaders::HlslSm40)
|
||||
.expect("Failed to initialize renderer");
|
||||
RenderSystem {
|
||||
renderer,
|
||||
|
||||
@ -10,7 +10,7 @@ use imgui::{DrawCmd, DrawCmdParams, DrawData, DrawIdx, DrawVert, ImString, Textu
|
||||
use std::usize;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum GfxRendererError {
|
||||
pub enum RendererError {
|
||||
Update(gfx::UpdateError<usize>),
|
||||
Buffer(gfx::buffer::CreationError),
|
||||
Pipeline(gfx::PipelineStateError<String>),
|
||||
@ -18,27 +18,27 @@ pub enum GfxRendererError {
|
||||
BadTexture(TextureId),
|
||||
}
|
||||
|
||||
impl From<gfx::UpdateError<usize>> for GfxRendererError {
|
||||
fn from(e: gfx::UpdateError<usize>) -> GfxRendererError {
|
||||
GfxRendererError::Update(e)
|
||||
impl From<gfx::UpdateError<usize>> for RendererError {
|
||||
fn from(e: gfx::UpdateError<usize>) -> RendererError {
|
||||
RendererError::Update(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<gfx::buffer::CreationError> for GfxRendererError {
|
||||
fn from(e: gfx::buffer::CreationError) -> GfxRendererError {
|
||||
GfxRendererError::Buffer(e)
|
||||
impl From<gfx::buffer::CreationError> for RendererError {
|
||||
fn from(e: gfx::buffer::CreationError) -> RendererError {
|
||||
RendererError::Buffer(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<gfx::PipelineStateError<String>> for GfxRendererError {
|
||||
fn from(e: gfx::PipelineStateError<String>) -> GfxRendererError {
|
||||
GfxRendererError::Pipeline(e)
|
||||
impl From<gfx::PipelineStateError<String>> for RendererError {
|
||||
fn from(e: gfx::PipelineStateError<String>) -> RendererError {
|
||||
RendererError::Pipeline(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<gfx::CombinedError> for GfxRendererError {
|
||||
fn from(e: gfx::CombinedError) -> GfxRendererError {
|
||||
GfxRendererError::Combined(e)
|
||||
impl From<gfx::CombinedError> for RendererError {
|
||||
fn from(e: gfx::CombinedError) -> RendererError {
|
||||
RendererError::Combined(e)
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ pub type Texture<R> = (
|
||||
gfx::handle::Sampler<R>,
|
||||
);
|
||||
|
||||
pub struct GfxRenderer<Cf: BlendFormat, R: Resources> {
|
||||
pub struct Renderer<Cf: BlendFormat, R: Resources> {
|
||||
vertex_buffer: Buffer<R, DrawVert>,
|
||||
index_buffer: Buffer<R, DrawIdx>,
|
||||
slice: Slice<R>,
|
||||
@ -112,7 +112,7 @@ pub struct GfxRenderer<Cf: BlendFormat, R: Resources> {
|
||||
constants: Buffer<R, constants::Constants>,
|
||||
}
|
||||
|
||||
impl<Cf, R> GfxRenderer<Cf, R>
|
||||
impl<Cf, R> Renderer<Cf, R>
|
||||
where
|
||||
Cf: BlendFormat,
|
||||
R: Resources,
|
||||
@ -121,7 +121,7 @@ where
|
||||
ctx: &mut imgui::Context,
|
||||
factory: &mut F,
|
||||
shaders: Shaders,
|
||||
) -> Result<GfxRenderer<Cf, R>, GfxRendererError> {
|
||||
) -> Result<Renderer<Cf, R>, RendererError> {
|
||||
let (vs_code, ps_code) = shaders.get_program_code();
|
||||
let pso = factory.create_pipeline_simple(vs_code, ps_code, pipeline::new::<Cf>())?;
|
||||
let vertex_buffer = factory.create_buffer::<DrawVert>(
|
||||
@ -148,7 +148,7 @@ where
|
||||
"imgui-gfx-renderer {}",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
))));
|
||||
Ok(GfxRenderer {
|
||||
Ok(Renderer {
|
||||
vertex_buffer,
|
||||
index_buffer,
|
||||
slice,
|
||||
@ -163,7 +163,7 @@ where
|
||||
&mut self,
|
||||
ctx: &mut imgui::Context,
|
||||
factory: &mut F,
|
||||
) -> Result<(), GfxRendererError> {
|
||||
) -> Result<(), RendererError> {
|
||||
self.font_texture = upload_font_texture(ctx.fonts(), factory)?;
|
||||
Ok(())
|
||||
}
|
||||
@ -176,7 +176,7 @@ where
|
||||
encoder: &mut Encoder<R, C>,
|
||||
target: &mut RenderTargetView<R, Cf>,
|
||||
draw_data: &DrawData,
|
||||
) -> Result<(), GfxRendererError> {
|
||||
) -> Result<(), RendererError> {
|
||||
let fb_width = draw_data.display_size[0] * draw_data.framebuffer_scale[0];
|
||||
let fb_height = draw_data.display_size[1] * draw_data.framebuffer_scale[1];
|
||||
if !(fb_width > 0.0 && fb_height > 0.0) {
|
||||
@ -268,7 +268,7 @@ where
|
||||
factory: &mut F,
|
||||
encoder: &mut Encoder<R, C>,
|
||||
vtx_buffer: &[DrawVert],
|
||||
) -> Result<(), GfxRendererError> {
|
||||
) -> Result<(), RendererError> {
|
||||
if self.vertex_buffer.len() < vtx_buffer.len() {
|
||||
self.vertex_buffer = factory.create_buffer::<DrawVert>(
|
||||
vtx_buffer.len(),
|
||||
@ -285,7 +285,7 @@ where
|
||||
factory: &mut F,
|
||||
encoder: &mut Encoder<R, C>,
|
||||
idx_buffer: &[DrawIdx],
|
||||
) -> Result<(), GfxRendererError> {
|
||||
) -> Result<(), RendererError> {
|
||||
if self.index_buffer.len() < idx_buffer.len() {
|
||||
self.index_buffer = factory.create_buffer::<DrawIdx>(
|
||||
idx_buffer.len(),
|
||||
@ -298,13 +298,13 @@ where
|
||||
encoder.update_buffer(&self.index_buffer, idx_buffer, 0)?;
|
||||
Ok(())
|
||||
}
|
||||
fn lookup_texture(&self, texture_id: TextureId) -> Result<&Texture<R>, GfxRendererError> {
|
||||
fn lookup_texture(&self, texture_id: TextureId) -> Result<&Texture<R>, RendererError> {
|
||||
if texture_id.id() == usize::MAX {
|
||||
Ok(&self.font_texture)
|
||||
} else if let Some(texture) = self.textures.get(texture_id) {
|
||||
Ok(texture)
|
||||
} else {
|
||||
Err(GfxRendererError::BadTexture(texture_id))
|
||||
Err(RendererError::BadTexture(texture_id))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -312,7 +312,7 @@ where
|
||||
fn upload_font_texture<R: Resources, F: Factory<R>>(
|
||||
mut fonts: imgui::FontAtlasRefMut,
|
||||
factory: &mut F,
|
||||
) -> Result<Texture<R>, GfxRendererError> {
|
||||
) -> Result<Texture<R>, RendererError> {
|
||||
let texture = fonts.build_rgba32_texture();
|
||||
let (_, texture_view) = factory.create_texture_immutable_u8::<gfx::format::Srgba8>(
|
||||
gfx::texture::Kind::D2(
|
||||
|
||||
@ -15,7 +15,7 @@ use std::rc::Rc;
|
||||
use std::usize;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum GliumRendererError {
|
||||
pub enum RendererError {
|
||||
Vertex(vertex::BufferCreationError),
|
||||
Index(index::BufferCreationError),
|
||||
Program(ProgramChooserCreationError),
|
||||
@ -24,9 +24,9 @@ pub enum GliumRendererError {
|
||||
BadTexture(TextureId),
|
||||
}
|
||||
|
||||
impl fmt::Display for GliumRendererError {
|
||||
impl fmt::Display for RendererError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::GliumRendererError::*;
|
||||
use self::RendererError::*;
|
||||
match *self {
|
||||
Vertex(_) => write!(f, "Vertex buffer creation failed"),
|
||||
Index(_) => write!(f, "Index buffer creation failed"),
|
||||
@ -38,85 +38,82 @@ impl fmt::Display for GliumRendererError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<vertex::BufferCreationError> for GliumRendererError {
|
||||
fn from(e: vertex::BufferCreationError) -> GliumRendererError {
|
||||
GliumRendererError::Vertex(e)
|
||||
impl From<vertex::BufferCreationError> for RendererError {
|
||||
fn from(e: vertex::BufferCreationError) -> RendererError {
|
||||
RendererError::Vertex(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<index::BufferCreationError> for GliumRendererError {
|
||||
fn from(e: index::BufferCreationError) -> GliumRendererError {
|
||||
GliumRendererError::Index(e)
|
||||
impl From<index::BufferCreationError> for RendererError {
|
||||
fn from(e: index::BufferCreationError) -> RendererError {
|
||||
RendererError::Index(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProgramChooserCreationError> for GliumRendererError {
|
||||
fn from(e: ProgramChooserCreationError) -> GliumRendererError {
|
||||
GliumRendererError::Program(e)
|
||||
impl From<ProgramChooserCreationError> for RendererError {
|
||||
fn from(e: ProgramChooserCreationError) -> RendererError {
|
||||
RendererError::Program(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TextureCreationError> for GliumRendererError {
|
||||
fn from(e: TextureCreationError) -> GliumRendererError {
|
||||
GliumRendererError::Texture(e)
|
||||
impl From<TextureCreationError> for RendererError {
|
||||
fn from(e: TextureCreationError) -> RendererError {
|
||||
RendererError::Texture(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DrawError> for GliumRendererError {
|
||||
fn from(e: DrawError) -> GliumRendererError {
|
||||
GliumRendererError::Draw(e)
|
||||
impl From<DrawError> for RendererError {
|
||||
fn from(e: DrawError) -> RendererError {
|
||||
RendererError::Draw(e)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GliumRenderer {
|
||||
pub struct Renderer {
|
||||
ctx: Rc<Context>,
|
||||
program: Program,
|
||||
font_texture: Texture2d,
|
||||
textures: Textures<Rc<Texture2d>>,
|
||||
}
|
||||
|
||||
impl GliumRenderer {
|
||||
impl Renderer {
|
||||
pub fn init<F: Facade>(
|
||||
ctx: &mut imgui::Context,
|
||||
facade: &F,
|
||||
) -> Result<GliumRenderer, GliumRendererError> {
|
||||
) -> Result<Renderer, RendererError> {
|
||||
let program = compile_default_program(facade)?;
|
||||
let font_texture = upload_font_texture(ctx.fonts(), facade.get_context())?;
|
||||
ctx.set_renderer_name(Some(ImString::from(format!(
|
||||
"imgui-glium-renderer {}",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
))));
|
||||
Ok(GliumRenderer {
|
||||
Ok(Renderer {
|
||||
ctx: Rc::clone(facade.get_context()),
|
||||
program,
|
||||
font_texture,
|
||||
textures: Textures::new(),
|
||||
})
|
||||
}
|
||||
pub fn reload_font_texture(
|
||||
&mut self,
|
||||
ctx: &mut imgui::Context,
|
||||
) -> Result<(), GliumRendererError> {
|
||||
pub fn reload_font_texture(&mut self, ctx: &mut imgui::Context) -> Result<(), RendererError> {
|
||||
self.font_texture = upload_font_texture(ctx.fonts(), &self.ctx)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn textures(&mut self) -> &mut Textures<Rc<Texture2d>> {
|
||||
&mut self.textures
|
||||
}
|
||||
fn lookup_texture(&self, texture_id: TextureId) -> Result<&Texture2d, GliumRendererError> {
|
||||
fn lookup_texture(&self, texture_id: TextureId) -> Result<&Texture2d, RendererError> {
|
||||
if texture_id.id() == usize::MAX {
|
||||
Ok(&self.font_texture)
|
||||
} else if let Some(texture) = self.textures.get(texture_id) {
|
||||
Ok(texture)
|
||||
} else {
|
||||
Err(GliumRendererError::BadTexture(texture_id))
|
||||
Err(RendererError::BadTexture(texture_id))
|
||||
}
|
||||
}
|
||||
pub fn render<T: Surface>(
|
||||
&mut self,
|
||||
target: &mut T,
|
||||
draw_data: &DrawData,
|
||||
) -> Result<(), GliumRendererError> {
|
||||
) -> Result<(), RendererError> {
|
||||
let fb_width = draw_data.display_size[0] * draw_data.framebuffer_scale[0];
|
||||
let fb_height = draw_data.display_size[1] * draw_data.framebuffer_scale[1];
|
||||
if !(fb_width > 0.0 && fb_height > 0.0) {
|
||||
@ -214,7 +211,7 @@ impl GliumRenderer {
|
||||
fn upload_font_texture(
|
||||
mut fonts: imgui::FontAtlasRefMut,
|
||||
ctx: &Rc<Context>,
|
||||
) -> Result<Texture2d, GliumRendererError> {
|
||||
) -> Result<Texture2d, RendererError> {
|
||||
let texture = fonts.build_rgba32_texture();
|
||||
let data = RawImage2d {
|
||||
data: Cow::Borrowed(texture.data),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user