Add support for RENDERER_HAS_VTX_OFFSET

This commit is contained in:
Joonas Javanainen 2020-07-08 00:18:53 +03:00
parent c575dec15b
commit fad0f5811b
No known key found for this signature in database
GPG Key ID: D39CCA5CB19B9179
2 changed files with 22 additions and 9 deletions

View File

@ -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 {

View File

@ -11,7 +11,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;
@ -104,6 +104,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,
@ -162,7 +165,6 @@ impl Renderer {
PrimitiveType::TrianglesList,
draw_list.idx_buffer(),
)?;
let mut idx_start = 0;
for cmd in draw_list.commands() {
match cmd {
DrawCmd::Elements {
@ -171,10 +173,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],
@ -188,9 +191,11 @@ impl Renderer {
&& clip_rect[3] >= 0.0
{
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! {
@ -213,7 +218,6 @@ impl Renderer {
},
)?;
}
idx_start = idx_end;
}
DrawCmd::ResetRenderState => (), // TODO
DrawCmd::RawCallback { callback, raw_cmd } => unsafe {