DrawCommand.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package imgui
  2. // #include "DrawCommandWrapper.h"
  3. import "C"
  4. // DrawCommand describes one GPU call (or a callback).
  5. type DrawCommand uintptr
  6. func (cmd DrawCommand) handle() C.IggDrawCmd {
  7. return C.IggDrawCmd(cmd)
  8. }
  9. func (cmd DrawCommand) IdxOffset() uint {
  10. return uint(C.iggDrawCommandIdxOffset(cmd.handle()))
  11. }
  12. // VertexOffset is the start offset in vertex buffer.
  13. // ImGuiBackendFlags_RendererHasVtxOffset: false always 0,
  14. // otherwise may be >0 to support meshes larger than 64K vertices with 16-bit indices.
  15. func (cmd DrawCommand) VertexOffset() int {
  16. var count C.uint
  17. C.iggDrawCommandGetVertexOffset(cmd.handle(), &count)
  18. return int(count)
  19. }
  20. // ElementCount is the number of indices (multiple of 3) to be rendered as triangles.
  21. // Vertices are stored in the callee DrawList's VertexBuffer, indices in IndexBuffer.
  22. func (cmd DrawCommand) ElementCount() int {
  23. var count C.uint
  24. C.iggDrawCommandGetElementCount(cmd.handle(), &count)
  25. return int(count)
  26. }
  27. // ClipRect defines the clipping rectangle (x1, y1, x2, y2).
  28. func (cmd DrawCommand) ClipRect() (rect Vec4) {
  29. rectArg, rectFin := rect.wrapped()
  30. defer rectFin()
  31. C.iggDrawCommandGetClipRect(cmd.handle(), rectArg)
  32. return
  33. }
  34. // TextureID is the user-provided texture ID.
  35. // Set by user in FontAtlas.SetTextureID() for fonts or passed to Image*() functions.
  36. // Ignore if never using images or multiple fonts atlas.
  37. func (cmd DrawCommand) TextureID() TextureID {
  38. var id C.IggTextureID
  39. C.iggDrawCommandGetTextureID(cmd.handle(), &id)
  40. return TextureID(id)
  41. }
  42. // HasUserCallback returns true if this handle command should be deferred.
  43. func (cmd DrawCommand) HasUserCallback() bool {
  44. return C.iggDrawCommandHasUserCallback(cmd.handle()) != 0
  45. }
  46. // CallUserCallback calls the user callback instead of rendering the vertices.
  47. // ClipRect and TextureID will be set normally.
  48. func (cmd DrawCommand) CallUserCallback(list DrawList) {
  49. C.iggDrawCommandCallUserCallback(cmd.handle(), list.handle())
  50. }