mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-13 22:48:34 +00:00
Merge pull request #346 from Gekkio/feature/renderer-vtx-offset
Add support for RENDERER_HAS_VTX_OFFSET
This commit is contained in:
commit
903092580a
@ -9,7 +9,10 @@ use gfx::texture::{FilterMethod, SamplerInfo, WrapMode};
|
||||
use gfx::traits::FactoryExt;
|
||||
use gfx::{CommandBuffer, Encoder, Factory, IntoIndexBuffer, Rect, Resources, Slice};
|
||||
use imgui::internal::RawWrapper;
|
||||
use imgui::{DrawCmd, DrawCmdParams, DrawData, DrawIdx, DrawVert, ImString, TextureId, Textures};
|
||||
use imgui::{
|
||||
BackendFlags, DrawCmd, DrawCmdParams, DrawData, DrawIdx, DrawVert, ImString, TextureId,
|
||||
Textures,
|
||||
};
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::usize;
|
||||
@ -179,6 +182,9 @@ where
|
||||
"imgui-gfx-renderer {}",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
))));
|
||||
ctx.io_mut()
|
||||
.backend_flags
|
||||
.insert(BackendFlags::RENDERER_HAS_VTX_OFFSET);
|
||||
Ok(Renderer {
|
||||
vertex_buffer,
|
||||
index_buffer,
|
||||
@ -242,6 +248,8 @@ where
|
||||
DrawCmdParams {
|
||||
clip_rect,
|
||||
texture_id,
|
||||
vtx_offset,
|
||||
idx_offset,
|
||||
..
|
||||
},
|
||||
} => {
|
||||
@ -252,7 +260,9 @@ where
|
||||
(clip_rect[3] - clip_off[1]) * clip_scale[1],
|
||||
];
|
||||
|
||||
self.slice.start = idx_offset as u32;
|
||||
self.slice.end = self.slice.start + count as u32;
|
||||
self.slice.base_vertex = vtx_offset as u32;
|
||||
|
||||
if clip_rect[0] < fb_width
|
||||
&& clip_rect[1] < fb_height
|
||||
@ -283,7 +293,6 @@ where
|
||||
};
|
||||
encoder.draw(&self.slice, &self.pso, &data);
|
||||
}
|
||||
self.slice.start = self.slice.end;
|
||||
}
|
||||
DrawCmd::ResetRenderState => (), // TODO
|
||||
DrawCmd::RawCallback { callback, raw_cmd } => unsafe {
|
||||
|
||||
@ -13,7 +13,7 @@ use glium::{
|
||||
Surface, Texture2d, VertexBuffer,
|
||||
};
|
||||
use imgui::internal::RawWrapper;
|
||||
use imgui::{DrawCmd, DrawCmdParams, DrawData, ImString, TextureId, Textures};
|
||||
use imgui::{BackendFlags, DrawCmd, DrawCmdParams, DrawData, ImString, TextureId, Textures};
|
||||
use std::borrow::Cow;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
@ -111,6 +111,9 @@ impl Renderer {
|
||||
"imgui-glium-renderer {}",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
))));
|
||||
ctx.io_mut()
|
||||
.backend_flags
|
||||
.insert(BackendFlags::RENDERER_HAS_VTX_OFFSET);
|
||||
Ok(Renderer {
|
||||
ctx: Rc::clone(facade.get_context()),
|
||||
program,
|
||||
@ -169,7 +172,6 @@ impl Renderer {
|
||||
PrimitiveType::TrianglesList,
|
||||
draw_list.idx_buffer(),
|
||||
)?;
|
||||
let mut idx_start = 0;
|
||||
for cmd in draw_list.commands() {
|
||||
match cmd {
|
||||
DrawCmd::Elements {
|
||||
@ -178,10 +180,11 @@ impl Renderer {
|
||||
DrawCmdParams {
|
||||
clip_rect,
|
||||
texture_id,
|
||||
vtx_offset,
|
||||
idx_offset,
|
||||
..
|
||||
},
|
||||
} => {
|
||||
let idx_end = idx_start + count;
|
||||
let clip_rect = [
|
||||
(clip_rect[0] - clip_off[0]) * clip_scale[0],
|
||||
(clip_rect[1] - clip_off[1]) * clip_scale[1],
|
||||
@ -197,9 +200,11 @@ impl Renderer {
|
||||
let texture = self.lookup_texture(texture_id)?;
|
||||
|
||||
target.draw(
|
||||
&vtx_buffer,
|
||||
&idx_buffer
|
||||
.slice(idx_start..idx_end)
|
||||
vtx_buffer
|
||||
.slice(vtx_offset..)
|
||||
.expect("Invalid vertex buffer range"),
|
||||
idx_buffer
|
||||
.slice(idx_offset..(idx_offset + count))
|
||||
.expect("Invalid index buffer range"),
|
||||
&self.program,
|
||||
&uniform! {
|
||||
@ -219,7 +224,6 @@ impl Renderer {
|
||||
},
|
||||
)?;
|
||||
}
|
||||
idx_start = idx_end;
|
||||
}
|
||||
DrawCmd::ResetRenderState => (), // TODO
|
||||
DrawCmd::RawCallback { callback, raw_cmd } => unsafe {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user