From 057e8907a9649d38edd3140ad866cfc59078dc3b Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Thu, 17 Feb 2022 12:00:26 +0800 Subject: [PATCH] igwrap: support DrawCmd::VtxOffset --- internal/igwrap/backend/render.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/igwrap/backend/render.go b/internal/igwrap/backend/render.go index ef76278..ad7f522 100644 --- a/internal/igwrap/backend/render.go +++ b/internal/igwrap/backend/render.go @@ -56,6 +56,8 @@ func renderInit() { gl.BindTexture(gl.TEXTURE_2D, uint32(lastTexture)) gl.BindBuffer(gl.ARRAY_BUFFER, uint32(lastArrayBuffer)) gl.BindVertexArray(uint32(lastVertexArray)) + + io.SetBackendFlags(imgui.BackendFlagsRendererHasVtxOffset) } func CreateFontsTexture() { @@ -190,7 +192,6 @@ func Render(win *glfw.Window) { // Draw for _, list := range draw.CommandLists() { - var indexBufferOffset uintptr vertexBuffer, vertexBufferSize := list.VertexBuffer() gl.BindBuffer(gl.ARRAY_BUFFER, vbo) @@ -208,9 +209,14 @@ func Render(win *glfw.Window) { gl.BindTexture(gl.TEXTURE_2D, uint32(cmd.TextureID())) clipRect := cmd.ClipRect() gl.Scissor(int32(clipRect.X), int32(fbHeight)-int32(clipRect.W), int32(clipRect.Z-clipRect.X), int32(clipRect.W-clipRect.Y)) - gl.DrawElementsWithOffset(gl.TRIANGLES, int32(cmd.ElementCount()), uint32(drawType), indexBufferOffset) + gl.DrawElementsBaseVertexWithOffset( + gl.TRIANGLES, + int32(cmd.ElementCount()), + uint32(drawType), + uintptr(cmd.IndexOffset()*indexSize), + int32(cmd.VertexOffset()), + ) } - indexBufferOffset += uintptr(cmd.ElementCount() * indexSize) } } gl.DeleteVertexArrays(1, &vao)