DrawCommands.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. --[[
  2. MIT License
  3. Copyright (c) 2019 Mitchell Davis <coding.jackalope@gmail.com>
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. --]]
  20. local Stats = require(SLAB_PATH .. ".Internal.Core.Stats")
  21. local DrawCommands = {}
  22. local LayerTable = {}
  23. local PendingBatches = {}
  24. local ActiveBatch = nil
  25. local Types =
  26. {
  27. Rect = 1,
  28. Triangle = 2,
  29. Text = 3,
  30. Scissor = 4,
  31. TransformPush = 5,
  32. TransformPop = 6,
  33. ApplyTransform = 7,
  34. Check = 8,
  35. Line = 9,
  36. TextFormatted = 10,
  37. IntersectScissor = 11,
  38. Cross = 12,
  39. Image = 13,
  40. SubImage = 14,
  41. Circle = 15,
  42. DrawCanvas = 16,
  43. Mesh = 17,
  44. TextObject = 18,
  45. Curve = 19,
  46. Polygon = 20
  47. }
  48. local Layers =
  49. {
  50. Normal = 1,
  51. ContextMenu = 2,
  52. MainMenuBar = 3,
  53. Dialog = 4,
  54. Debug = 5
  55. }
  56. local ActiveLayer = Layers.Normal
  57. local StatsCategory = 'Slab Draw'
  58. local function AddArc(Verts, CenterX, CenterY, Radius, Angle1, Angle2, Segments, X, Y)
  59. if Radius == 0 then
  60. table.insert(Verts, CenterX + X)
  61. table.insert(Verts, CenterY + Y)
  62. return
  63. end
  64. local Step = (Angle2 - Angle1) / Segments
  65. for Theta = Angle1, Angle2, Step do
  66. local Radians = math.rad(Theta)
  67. table.insert(Verts, math.sin(Radians) * Radius + CenterX + X)
  68. table.insert(Verts, math.cos(Radians) * Radius + CenterY + Y)
  69. end
  70. end
  71. local function GetLayerDebugInfo(Layer)
  72. local Result = {}
  73. Result['Channel Count'] = #Layer
  74. local Channels = {}
  75. for K, Channel in pairs(Layer) do
  76. local Collection = {}
  77. Collection['Batch Count'] = #Channel
  78. table.insert(Channels, Collection)
  79. end
  80. Result['Channels'] = Channels
  81. return Result
  82. end
  83. local function DrawRect(Rect)
  84. local StatHandle = Stats.Begin('DrawRect', StatsCategory)
  85. love.graphics.setColor(Rect.Color)
  86. love.graphics.rectangle(Rect.Mode, Rect.X, Rect.Y, Rect.Width, Rect.Height, Rect.Radius, Rect.Radius)
  87. Stats.End(StatHandle)
  88. end
  89. local function GetTriangleVertices(X, Y, Radius, Rotation)
  90. local Result = {}
  91. local Radians = math.rad(Rotation)
  92. local X1, Y1 = 0, -Radius
  93. local X2, Y2 = -Radius, Radius
  94. local X3, Y3 = Radius, Radius
  95. local PX1 = X1 * math.cos(Radians) - Y1 * math.sin(Radians)
  96. local PY1 = Y1 * math.cos(Radians) + X1 * math.sin(Radians)
  97. local PX2 = X2 * math.cos(Radians) - Y2 * math.sin(Radians)
  98. local PY2 = Y2 * math.cos(Radians) + X2 * math.sin(Radians)
  99. local PX3 = X3 * math.cos(Radians) - Y3 * math.sin(Radians)
  100. local PY3 = Y3 * math.cos(Radians) + X3 * math.sin(Radians)
  101. Result =
  102. {
  103. X + PX1, Y + PY1,
  104. X + PX2, Y + PY2,
  105. X + PX3, Y + PY3
  106. }
  107. return Result
  108. end
  109. local function DrawTriangle(Triangle)
  110. local StatHandle = Stats.Begin('DrawTriangle', StatsCategory)
  111. love.graphics.setColor(Triangle.Color)
  112. local Vertices = GetTriangleVertices(Triangle.X, Triangle.Y, Triangle.Radius, Triangle.Rotation)
  113. love.graphics.polygon(Triangle.Mode, Vertices)
  114. Stats.End(StatHandle)
  115. end
  116. local function DrawCheck(Check)
  117. local StatHandle = Stats.Begin('DrawCheck', StatsCategory)
  118. love.graphics.setColor(Check.Color)
  119. local Vertices =
  120. {
  121. Check.X - Check.Radius * 0.5, Check.Y,
  122. Check.X, Check.Y + Check.Radius,
  123. Check.X + Check.Radius, Check.Y - Check.Radius
  124. }
  125. love.graphics.line(Vertices)
  126. Stats.End(StatHandle)
  127. end
  128. local function DrawText(Text)
  129. local StatHandle = Stats.Begin('DrawText', StatsCategory)
  130. love.graphics.setFont(Text.Font)
  131. love.graphics.setColor(Text.Color)
  132. love.graphics.print(Text.Text, Text.X, Text.Y)
  133. Stats.End(StatHandle)
  134. end
  135. local function DrawTextFormatted(Text)
  136. local StatHandle = Stats.Begin('DrawTextFormatted', StatsCategory)
  137. love.graphics.setFont(Text.Font)
  138. love.graphics.setColor(Text.Color)
  139. love.graphics.printf(Text.Text, Text.X, Text.Y, Text.W, Text.Align)
  140. Stats.End(StatHandle)
  141. end
  142. local function DrawTextObject(Text)
  143. local StatHandle = Stats.Begin('DrawTextObject', StatsCategory)
  144. love.graphics.setColor(1, 1, 1, 1)
  145. love.graphics.draw(Text.Text, Text.X, Text.Y)
  146. Stats.End(StatHandle)
  147. end
  148. local function DrawLine(Line)
  149. local StatHandle = Stats.Begin('DrawLine', StatsCategory)
  150. love.graphics.setColor(Line.Color)
  151. local LineW = love.graphics.getLineWidth()
  152. love.graphics.setLineWidth(Line.Width)
  153. love.graphics.line(Line.X1, Line.Y1, Line.X2, Line.Y2)
  154. love.graphics.setLineWidth(LineW)
  155. Stats.End(StatHandle)
  156. end
  157. local function DrawCross(Cross)
  158. local StatHandle = Stats.Begin('DrawCross', StatsCategory)
  159. local X, Y = Cross.X, Cross.Y
  160. local R = Cross.Radius
  161. love.graphics.setColor(Cross.Color)
  162. love.graphics.line(X - R, Y - R, X + R, Y + R)
  163. love.graphics.line(X - R, Y + R, X + R, Y - R)
  164. Stats.End(StatHandle)
  165. end
  166. local function DrawImage(Image)
  167. local StatHandle = Stats.Begin('DrawImage', StatsCategory)
  168. love.graphics.setColor(Image.Color)
  169. love.graphics.draw(Image.Image, Image.X, Image.Y, Image.Rotation, Image.ScaleX, Image.ScaleY)
  170. Stats.End(StatHandle)
  171. end
  172. local function DrawSubImage(Image)
  173. local StatHandle = Stats.Begin('DrawSubImage', StatsCategory)
  174. love.graphics.setColor(Image.Color)
  175. love.graphics.draw(Image.Image, Image.Quad, Image.Transform)
  176. Stats.End(StatHandle)
  177. end
  178. local function DrawCircle(Circle)
  179. local StatHandle = Stats.Begin('DrawCircle', StatsCategory)
  180. love.graphics.setColor(Circle.Color)
  181. love.graphics.circle(Circle.Mode, Circle.X, Circle.Y, Circle.Radius, Circle.Segments)
  182. Stats.End(StatHandle)
  183. end
  184. local function DrawCurve(Curve)
  185. local StatHandle = Stats.Begin('DrawCurve', StatsCategory)
  186. love.graphics.setColor(Curve.Color)
  187. love.graphics.line(Curve.Points)
  188. Stats.End(StatHandle)
  189. end
  190. local function DrawPolygon(Polygon)
  191. local StatHandle = Stats.Begin('DrawPolygon', StatsCategory)
  192. love.graphics.setColor(Polygon.Color)
  193. love.graphics.polygon(Polygon.Mode, Polygon.Points)
  194. Stats.End(StatHandle)
  195. end
  196. local function DrawCanvas(Canvas)
  197. local StatHandle = Stats.Begin('DrawCanvas', StatsCategory)
  198. love.graphics.setBlendMode('alpha', 'premultiplied')
  199. love.graphics.setColor(1.0, 1.0, 1.0, 1.0)
  200. love.graphics.draw(Canvas.Canvas, Canvas.X, Canvas.Y)
  201. love.graphics.setBlendMode('alpha')
  202. Stats.End(StatHandle)
  203. end
  204. local function DrawMesh(Mesh)
  205. local StatHandle = Stats.Begin('DrawMesh', StatsCategory)
  206. love.graphics.setColor(1.0, 1.0, 1.0, 1.0)
  207. love.graphics.draw(Mesh.Mesh, Mesh.X, Mesh.Y)
  208. Stats.End(StatHandle)
  209. end
  210. local function DrawElements(Elements)
  211. local StatHandle = Stats.Begin('Draw Elements', StatsCategory)
  212. for K, V in pairs(Elements) do
  213. if V.Type == Types.Rect then
  214. DrawRect(V)
  215. elseif V.Type == Types.Triangle then
  216. DrawTriangle(V)
  217. elseif V.Type == Types.Text then
  218. DrawText(V)
  219. elseif V.Type == Types.Scissor then
  220. love.graphics.setScissor(V.X, V.Y, V.W, V.H)
  221. elseif V.Type == Types.TransformPush then
  222. love.graphics.push()
  223. elseif V.Type == Types.TransformPop then
  224. love.graphics.pop()
  225. elseif V.Type == Types.ApplyTransform then
  226. love.graphics.applyTransform(V.Transform)
  227. elseif V.Type == Types.Check then
  228. DrawCheck(V)
  229. elseif V.Type == Types.Line then
  230. DrawLine(V)
  231. elseif V.Type == Types.TextFormatted then
  232. DrawTextFormatted(V)
  233. elseif V.Type == Types.IntersectScissor then
  234. love.graphics.intersectScissor(V.X, V.Y, V.W, V.H)
  235. elseif V.Type == Types.Cross then
  236. DrawCross(V)
  237. elseif V.Type == Types.Image then
  238. DrawImage(V)
  239. elseif V.Type == Types.SubImage then
  240. DrawSubImage(V)
  241. elseif V.Type == Types.Circle then
  242. DrawCircle(V)
  243. elseif V.Type == Types.DrawCanvas then
  244. DrawCanvas(V)
  245. elseif V.Type == Types.Mesh then
  246. DrawMesh(V)
  247. elseif V.Type == Types.TextObject then
  248. DrawTextObject(V)
  249. elseif V.Type == Types.Curve then
  250. DrawCurve(V)
  251. elseif V.Type == Types.Polygon then
  252. DrawPolygon(V)
  253. end
  254. end
  255. Stats.End(StatHandle)
  256. end
  257. local function AssertActiveBatch()
  258. assert(ActiveBatch ~= nil, "DrawCommands.Begin was not called before commands were issued!")
  259. end
  260. local function DrawLayer(Layer, Name)
  261. if Layer.Channels == nil then
  262. return
  263. end
  264. local StatHandle = Stats.Begin('Draw Layer ' .. Name, StatsCategory)
  265. local Keys = {}
  266. for K, Channel in pairs(Layer.Channels) do
  267. table.insert(Keys, K)
  268. end
  269. table.sort(Keys)
  270. for Index, C in ipairs(Keys) do
  271. local Channel = Layer.Channels[C]
  272. if Channel ~= nil then
  273. for I, V in ipairs(Channel) do
  274. DrawElements(V.Elements)
  275. end
  276. end
  277. end
  278. Stats.End(StatHandle)
  279. end
  280. function DrawCommands.Reset()
  281. LayerTable = {}
  282. LayerTable[Layers.Normal] = {}
  283. LayerTable[Layers.ContextMenu] = {}
  284. LayerTable[Layers.MainMenuBar] = {}
  285. LayerTable[Layers.Dialog] = {}
  286. LayerTable[Layers.Debug] = {}
  287. ActiveLayer = Layers.Normal
  288. PendingBatches = {}
  289. ActiveBatch = nil
  290. end
  291. function DrawCommands.Begin(Options)
  292. Options = Options == nil and {} or Options
  293. Options.Channel = Options.Channel == nil and 1 or Options.Channel
  294. if LayerTable[ActiveLayer].Channels == nil then
  295. LayerTable[ActiveLayer].Channels = {}
  296. end
  297. if LayerTable[ActiveLayer].Channels[Options.Channel] == nil then
  298. LayerTable[ActiveLayer].Channels[Options.Channel] = {}
  299. end
  300. local Channel = LayerTable[ActiveLayer].Channels[Options.Channel]
  301. ActiveBatch = {}
  302. ActiveBatch.Elements = {}
  303. table.insert(Channel, ActiveBatch)
  304. table.insert(PendingBatches, 1, ActiveBatch)
  305. end
  306. function DrawCommands.End()
  307. if ActiveBatch ~= nil then
  308. love.graphics.setScissor()
  309. table.remove(PendingBatches, 1)
  310. ActiveBatch = nil
  311. if #PendingBatches > 0 then
  312. ActiveBatch = PendingBatches[1]
  313. end
  314. end
  315. end
  316. function DrawCommands.SetLayer(Layer)
  317. if Layer == 'Normal' then
  318. ActiveLayer = Layers.Normal
  319. elseif Layer == 'ContextMenu' then
  320. ActiveLayer = Layers.ContextMenu
  321. elseif Layer == 'MainMenuBar' then
  322. ActiveLayer = Layers.MainMenuBar
  323. elseif Layer == 'Dialog' then
  324. ActiveLayer = Layers.Dialog
  325. elseif Layer == 'Debug' then
  326. ActiveLayer = Layers.Debug
  327. end
  328. end
  329. function DrawCommands.Rectangle(Mode, X, Y, Width, Height, Color, Radius, Segments)
  330. AssertActiveBatch()
  331. if type(Radius) == 'table' then
  332. Segments = Segments == nil and 10 or Segments
  333. local Verts = {}
  334. local TL = Radius[1]
  335. local TR = Radius[2]
  336. local BR = Radius[3]
  337. local BL = Radius[4]
  338. TL = TL == nil and 0 or TL
  339. TR = TR == nil and 0 or TR
  340. BR = BR == nil and 0 or BR
  341. BL = BL == nil and 0 or BL
  342. AddArc(Verts, Width - BR, Height - BR, BR, 0, 90, Segments, X, Y)
  343. AddArc(Verts, Width - TR, TR, TR, 90, 180, Segments, X, Y)
  344. AddArc(Verts, TL, TL, TL, 180, 270, Segments, X, Y)
  345. AddArc(Verts, BL, Height - BL, BL, 270, 360, Segments, X, Y)
  346. DrawCommands.Polygon(Mode, Verts, Color)
  347. else
  348. local Item = {}
  349. Item.Type = Types.Rect
  350. Item.Mode = Mode
  351. Item.X = X
  352. Item.Y = Y
  353. Item.Width = Width
  354. Item.Height = Height
  355. Item.Color = Color and Color or {0.0, 0.0, 0.0, 1.0}
  356. Item.Radius = Radius and Radius or 0.0
  357. table.insert(ActiveBatch.Elements, Item)
  358. end
  359. end
  360. function DrawCommands.Triangle(Mode, X, Y, Radius, Rotation, Color)
  361. AssertActiveBatch()
  362. local Item = {}
  363. Item.Type = Types.Triangle
  364. Item.Mode = Mode
  365. Item.X = X
  366. Item.Y = Y
  367. Item.Radius = Radius
  368. Item.Rotation = Rotation
  369. Item.Color = Color and Color or {0.0, 0.0, 0.0, 1.0}
  370. table.insert(ActiveBatch.Elements, Item)
  371. end
  372. function DrawCommands.Print(Text, X, Y, Color, Font)
  373. AssertActiveBatch()
  374. local Item = {}
  375. Item.Type = Types.Text
  376. Item.Text = Text
  377. Item.X = X
  378. Item.Y = Y
  379. Item.Color = Color and Color or {1.0, 1.0, 1.0, 1.0}
  380. Item.Font = Font
  381. table.insert(ActiveBatch.Elements, Item)
  382. end
  383. function DrawCommands.Printf(Text, X, Y, W, Align, Color, Font)
  384. AssertActiveBatch()
  385. local Item = {}
  386. Item.Type = Types.TextFormatted
  387. Item.Text = Text
  388. Item.X = X
  389. Item.Y = Y
  390. Item.W = W
  391. Item.Align = Align and Align or 'left'
  392. Item.Color = Color and Color or {1.0, 1.0, 1.0, 1.0}
  393. Item.Font = Font
  394. table.insert(ActiveBatch.Elements, Item)
  395. end
  396. function DrawCommands.Scissor(X, Y, W, H)
  397. AssertActiveBatch()
  398. if W ~= nil then
  399. assert(W >= 0.0, "Cannot set scissor with negative width.")
  400. end
  401. if H ~= nil then
  402. assert(H >= 0.0, "Cannot set scissor with negative height.")
  403. end
  404. local Item = {}
  405. Item.Type = Types.Scissor
  406. Item.X = X
  407. Item.Y = Y
  408. Item.W = W
  409. Item.H = H
  410. table.insert(ActiveBatch.Elements, Item)
  411. end
  412. function DrawCommands.IntersectScissor(X, Y, W, H)
  413. AssertActiveBatch()
  414. local Item = {}
  415. Item.Type = Types.IntersectScissor
  416. Item.X = X and X or 0.0
  417. Item.Y = Y and Y or 0.0
  418. Item.W = W and W or 0.0
  419. Item.H = H and H or 0.0
  420. table.insert(ActiveBatch.Elements, Item)
  421. end
  422. function DrawCommands.TransformPush()
  423. AssertActiveBatch()
  424. local Item = {}
  425. Item.Type = Types.TransformPush
  426. table.insert(ActiveBatch.Elements, Item)
  427. end
  428. function DrawCommands.TransformPop()
  429. AssertActiveBatch()
  430. local Item = {}
  431. Item.Type = Types.TransformPop
  432. table.insert(ActiveBatch.Elements, Item)
  433. end
  434. function DrawCommands.ApplyTransform(Transform)
  435. AssertActiveBatch()
  436. local Item = {}
  437. Item.Type = Types.ApplyTransform
  438. Item.Transform = Transform
  439. table.insert(ActiveBatch.Elements, Item)
  440. end
  441. function DrawCommands.Check(X, Y, Radius, Color)
  442. AssertActiveBatch()
  443. local Item = {}
  444. Item.Type = Types.Check
  445. Item.X = X
  446. Item.Y = Y
  447. Item.Radius = Radius
  448. Item.Color = Color and Color or {0.0, 0.0, 0.0, 1.0}
  449. table.insert(ActiveBatch.Elements, Item)
  450. end
  451. function DrawCommands.Line(X1, Y1, X2, Y2, Width, Color)
  452. AssertActiveBatch()
  453. local Item = {}
  454. Item.Type = Types.Line
  455. Item.X1 = X1
  456. Item.Y1 = Y1
  457. Item.X2 = X2
  458. Item.Y2 = Y2
  459. Item.Width = Width
  460. Item.Color = Color and Color or {0.0, 0.0, 0.0, 1.0}
  461. table.insert(ActiveBatch.Elements, Item)
  462. end
  463. function DrawCommands.Cross(X, Y, Radius, Color)
  464. AssertActiveBatch()
  465. local Item = {}
  466. Item.Type = Types.Cross
  467. Item.X = X
  468. Item.Y = Y
  469. Item.Radius = Radius
  470. Item.Color = Color and Color or {0.0, 0.0, 0.0, 1.0}
  471. table.insert(ActiveBatch.Elements, Item)
  472. end
  473. function DrawCommands.Image(X, Y, Image, Rotation, ScaleX, ScaleY, Color)
  474. AssertActiveBatch()
  475. local Item = {}
  476. Item.Type = Types.Image
  477. Item.X = X
  478. Item.Y = Y
  479. Item.Image = Image
  480. Item.Rotation = Rotation
  481. Item.ScaleX = ScaleX
  482. Item.ScaleY = ScaleY
  483. Item.Color = Color and Color or {1.0, 1.0, 1.0, 1.0}
  484. table.insert(ActiveBatch.Elements, Item)
  485. end
  486. function DrawCommands.SubImage(X, Y, Image, SX, SY, SW, SH, Rotation, ScaleX, ScaleY, Color)
  487. AssertActiveBatch()
  488. local Item = {}
  489. Item.Type = Types.SubImage
  490. Item.Transform = love.math.newTransform(X, Y, Rotation, ScaleX, ScaleY)
  491. Item.Image = Image
  492. Item.Quad = love.graphics.newQuad(SX, SY, SW, SH, Image:getWidth(), Image:getHeight())
  493. Item.Color = Color and Color or {1.0, 1.0, 1.0, 1.0}
  494. table.insert(ActiveBatch.Elements, Item)
  495. end
  496. function DrawCommands.Circle(Mode, X, Y, Radius, Color, Segments)
  497. AssertActiveBatch()
  498. local Item = {}
  499. Item.Type = Types.Circle
  500. Item.Mode = Mode
  501. Item.X = X
  502. Item.Y = Y
  503. Item.Radius = Radius
  504. Item.Color = Color and Color or {0.0, 0.0, 0.0, 1.0}
  505. Item.Segments = Segments and Segments or 24
  506. table.insert(ActiveBatch.Elements, Item)
  507. end
  508. function DrawCommands.DrawCanvas(Canvas, X, Y)
  509. AssertActiveBatch()
  510. local Item = {}
  511. Item.Type = Types.DrawCanvas
  512. Item.Canvas = Canvas
  513. Item.X = X
  514. Item.Y = Y
  515. table.insert(ActiveBatch.Elements, Item)
  516. end
  517. function DrawCommands.Mesh(Mesh, X, Y)
  518. AssertActiveBatch()
  519. local Item = {}
  520. Item.Type = Types.Mesh
  521. Item.Mesh = Mesh
  522. Item.X = X
  523. Item.Y = Y
  524. table.insert(ActiveBatch.Elements, Item)
  525. end
  526. function DrawCommands.Text(Text, X, Y)
  527. AssertActiveBatch()
  528. local Item = {}
  529. Item.Type = Types.TextObject
  530. Item.Text = Text
  531. Item.X = X
  532. Item.Y = Y
  533. Item.Color = {0, 0, 0, 1}
  534. table.insert(ActiveBatch.Elements, Item)
  535. end
  536. function DrawCommands.Curve(Points, Color)
  537. AssertActiveBatch()
  538. local Item = {}
  539. Item.Type = Types.Curve
  540. Item.Points = Points
  541. Item.Color = Color ~= nil and Color or {0, 0, 0, 1}
  542. table.insert(ActiveBatch.Elements, Item)
  543. end
  544. function DrawCommands.Polygon(Mode, Points, Color)
  545. AssertActiveBatch()
  546. local Item = {}
  547. Item.Type = Types.Polygon
  548. Item.Mode = Mode
  549. Item.Points = Points
  550. Item.Color = Color ~= nil and Color or {0, 0, 0, 1}
  551. table.insert(ActiveBatch.Elements, Item)
  552. end
  553. function DrawCommands.Execute()
  554. local StatHandle = Stats.Begin('Execute', StatsCategory)
  555. DrawLayer(LayerTable[Layers.Normal], 'Normal')
  556. DrawLayer(LayerTable[Layers.ContextMenu], 'ContextMenu')
  557. DrawLayer(LayerTable[Layers.MainMenuBar], 'MainMenuBar')
  558. DrawLayer(LayerTable[Layers.Dialog], 'Dialog')
  559. DrawLayer(LayerTable[Layers.Debug], 'Debug')
  560. Stats.End(StatHandle)
  561. end
  562. function DrawCommands.GetDebugInfo()
  563. local Result = {}
  564. Result['Normal'] = GetLayerDebugInfo(LayerTable[Layers.Normal])
  565. Result['ContextMenu'] = GetLayerDebugInfo(LayerTable[Layers.ContextMenu])
  566. Result['MainMenuBar'] = GetLayerDebugInfo(LayerTable[Layers.MainMenuBar])
  567. Result['Dialog'] = GetLayerDebugInfo(LayerTable[Layers.Dialog])
  568. Result['Debug'] = GetLayerDebugInfo(LayerTable[Layers.Debug])
  569. return Result
  570. end
  571. return DrawCommands