igwrap: support DrawCmd::VtxOffset

This commit is contained in:
Edgaru089 2022-02-17 12:00:26 +08:00
parent ff838b8e85
commit 057e8907a9

View File

@ -56,6 +56,8 @@ func renderInit() {
gl.BindTexture(gl.TEXTURE_2D, uint32(lastTexture)) gl.BindTexture(gl.TEXTURE_2D, uint32(lastTexture))
gl.BindBuffer(gl.ARRAY_BUFFER, uint32(lastArrayBuffer)) gl.BindBuffer(gl.ARRAY_BUFFER, uint32(lastArrayBuffer))
gl.BindVertexArray(uint32(lastVertexArray)) gl.BindVertexArray(uint32(lastVertexArray))
io.SetBackendFlags(imgui.BackendFlagsRendererHasVtxOffset)
} }
func CreateFontsTexture() { func CreateFontsTexture() {
@ -190,7 +192,6 @@ func Render(win *glfw.Window) {
// Draw // Draw
for _, list := range draw.CommandLists() { for _, list := range draw.CommandLists() {
var indexBufferOffset uintptr
vertexBuffer, vertexBufferSize := list.VertexBuffer() vertexBuffer, vertexBufferSize := list.VertexBuffer()
gl.BindBuffer(gl.ARRAY_BUFFER, vbo) gl.BindBuffer(gl.ARRAY_BUFFER, vbo)
@ -208,9 +209,14 @@ func Render(win *glfw.Window) {
gl.BindTexture(gl.TEXTURE_2D, uint32(cmd.TextureID())) gl.BindTexture(gl.TEXTURE_2D, uint32(cmd.TextureID()))
clipRect := cmd.ClipRect() clipRect := cmd.ClipRect()
gl.Scissor(int32(clipRect.X), int32(fbHeight)-int32(clipRect.W), int32(clipRect.Z-clipRect.X), int32(clipRect.W-clipRect.Y)) 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) gl.DeleteVertexArrays(1, &vao)