graphics.lua 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899
  1. -- love.graphics
  2. --------------------------------------------------------------------------------
  3. --------------------------------------------------------------------------------
  4. ------------------------------------OBJECTS-------------------------------------
  5. --------------------------------------------------------------------------------
  6. --------------------------------------------------------------------------------
  7. -- GraphicsBuffer (love.graphics.newBuffer)
  8. love.test.graphics.Buffer = function(test)
  9. local vertexformat = {
  10. {name="VertexPosition", format="floatvec2"},
  11. {name="VertexTexCoord", format="floatvec2"},
  12. {name="VertexColor", format="unorm8vec4"},
  13. }
  14. local vertexdata = {
  15. {0, 0, 0, 0, 1, 0, 1, 1},
  16. {10, 0, 1, 0, 0, 1, 1, 1},
  17. {10, 10, 1, 1, 0, 0, 1, 1},
  18. {0, 10, 0, 1, 1, 0, 0, 1},
  19. }
  20. local flatvertexdata = {}
  21. for i, vert in ipairs(vertexdata) do
  22. for j, v in ipairs(vert) do
  23. table.insert(flatvertexdata, v)
  24. end
  25. end
  26. local vertexbuffer1 = love.graphics.newBuffer(vertexformat, 4, {vertex=true, debugname='testvertexbuffer'})
  27. local vertexbuffer2 = love.graphics.newBuffer(vertexformat, vertexdata, {vertex=true})
  28. test:assertObject(vertexbuffer1)
  29. test:assertObject(vertexbuffer2)
  30. test:assertEquals(4, vertexbuffer1:getElementCount(), 'check vertex count 1')
  31. test:assertEquals(4, vertexbuffer2:getElementCount(), 'check vertex count 2')
  32. -- vertex buffers have their elements tightly packed.
  33. test:assertEquals(20, vertexbuffer1:getElementStride(), 'check vertex array stride')
  34. test:assertEquals(20 * 4, vertexbuffer1:getSize(), 'check vertex buffer size')
  35. vertexbuffer1:setArrayData(vertexdata)
  36. vertexbuffer1:setArrayData(flatvertexdata)
  37. vertexbuffer1:clear(8, 8) -- partial clear (the first texcoord)
  38. test:assertTrue(vertexbuffer1:isBufferType('vertex'), 'check is vertex buffer')
  39. test:assertFalse(vertexbuffer1:isBufferType('index'), 'check is not index buffer')
  40. test:assertFalse(vertexbuffer1:isBufferType('texel'), 'check is not texel buffer')
  41. test:assertFalse(vertexbuffer1:isBufferType('shaderstorage'), 'check is not shader storage buffer')
  42. test:assertEquals('testvertexbuffer', vertexbuffer1:getDebugName(), 'check buffer debug name')
  43. local format = vertexbuffer1:getFormat()
  44. test:assertEquals('table', type(format), 'check buffer format is table')
  45. test:assertEquals(#vertexformat, #format, 'check buffer format length')
  46. for i, v in ipairs(vertexformat) do
  47. test:assertEquals(v.name, format[i].name, string.format('check buffer format %d name', i))
  48. test:assertEquals(v.format, format[i].format, string.format('check buffer format %d format', i))
  49. test:assertEquals(0, format[i].arraylength, string.format('check buffer format %d array length', i))
  50. test:assertNotNil(format[i].offset)
  51. end
  52. local indexbuffer = love.graphics.newBuffer('uint16', 128, {index=true})
  53. test:assertTrue(indexbuffer:isBufferType('index'), 'check is index buffer')
  54. end
  55. -- Shader Storage GraphicsBuffer (love.graphics.newBuffer)
  56. -- Separated from the above test so we can skip it when they aren't supported.
  57. love.test.graphics.ShaderStorageBuffer = function(test)
  58. if not love.graphics.getSupported().glsl4 then
  59. test:skipTest('GLSL 4 and shader storage buffers are not supported on this system')
  60. return
  61. end
  62. local format = {
  63. { name="1", format="float" },
  64. { name="2", format="floatmat4x4" },
  65. { name="3", format="floatvec2" }
  66. }
  67. local buffer = love.graphics.newBuffer(format, 1, {shaderstorage = true})
  68. test:assertEquals(96, buffer:getElementStride(), 'check shader storage buffer element stride')
  69. local data = {}
  70. for i = 1, 19 do
  71. data[i] = 0
  72. end
  73. buffer:setArrayData(data)
  74. end
  75. -- Canvas (love.graphics.newCanvas)
  76. love.test.graphics.Canvas = function(test)
  77. -- create canvas with defaults
  78. local canvas = love.graphics.newCanvas(100, 100, {
  79. type = '2d',
  80. format = 'normal',
  81. readable = true,
  82. msaa = 0,
  83. dpiscale = love.graphics.getDPIScale(),
  84. mipmaps = 'auto',
  85. debugname = 'testcanvas'
  86. })
  87. test:assertObject(canvas)
  88. test:assertTrue(canvas:isCanvas(), 'check is canvas')
  89. test:assertFalse(canvas:isComputeWritable(), 'check not compute writable')
  90. -- check dpi
  91. test:assertEquals(love.graphics.getDPIScale(), canvas:getDPIScale(), 'check dpi scale')
  92. -- check depth
  93. test:assertEquals(1, canvas:getDepth(), 'check depth is 2d')
  94. test:assertEquals(nil, canvas:getDepthSampleMode(), 'check depth sample nil')
  95. -- check fliter
  96. local min1, mag1, ani1 = canvas:getFilter()
  97. test:assertEquals('nearest', min1, 'check filter def min')
  98. test:assertEquals('nearest', mag1, 'check filter def mag')
  99. test:assertEquals(1, ani1, 'check filter def ani')
  100. canvas:setFilter('linear', 'linear', 2)
  101. local min2, mag2, ani2 = canvas:getFilter()
  102. test:assertEquals('linear', min2, 'check filter changed min')
  103. test:assertEquals('linear', mag2, 'check filter changed mag')
  104. test:assertEquals(2, ani2, 'check filter changed ani')
  105. -- check layer
  106. test:assertEquals(1, canvas:getLayerCount(), 'check 1 layer for 2d')
  107. -- check texture type
  108. test:assertEquals('2d', canvas:getTextureType(), 'check 2d')
  109. -- check texture wrap
  110. local horiz1, vert1 = canvas:getWrap()
  111. test:assertEquals('clamp', horiz1, 'check def wrap h')
  112. test:assertEquals('clamp', vert1, 'check def wrap v')
  113. canvas:setWrap('repeat', 'repeat')
  114. local horiz2, vert2 = canvas:getWrap()
  115. test:assertEquals('repeat', horiz2, 'check changed wrap h')
  116. test:assertEquals('repeat', vert2, 'check changed wrap v')
  117. -- check readable
  118. test:assertTrue(canvas:isReadable(), 'check canvas readable')
  119. -- check msaa
  120. test:assertEquals(1, canvas:getMSAA(), 'check samples match')
  121. -- check dimensions
  122. local cw, ch = canvas:getDimensions()
  123. test:assertEquals(100, cw, 'check canvas dim w')
  124. test:assertEquals(100, ch, 'check canvas dim h')
  125. test:assertEquals(cw, canvas:getWidth(), 'check canvas w matches dim')
  126. test:assertEquals(ch, canvas:getHeight(), 'check canvas h matches dim')
  127. local pw, ph = canvas:getPixelDimensions()
  128. test:assertEquals(100*love.graphics.getDPIScale(), pw, 'check pixel dim w')
  129. test:assertEquals(100*love.graphics.getDPIScale(), ph, 'check pixel dim h')
  130. test:assertEquals(pw, canvas:getPixelWidth(), 'check pixel w matches dim')
  131. test:assertEquals(ph, canvas:getPixelHeight(), 'check pixel h matches dim')
  132. -- check mipmaps
  133. local mode, sharpness = canvas:getMipmapFilter()
  134. test:assertEquals('linear', mode, 'check def minmap filter mode')
  135. test:assertEquals(0, sharpness, 'check def minmap filter sharpness')
  136. local name, version, vendor, device = love.graphics.getRendererInfo()
  137. canvas:setMipmapFilter('nearest', 1)
  138. mode, sharpness = canvas:getMipmapFilter()
  139. test:assertEquals('nearest', mode, 'check changed minmap filter mode')
  140. -- @NOTE mipmap sharpness wont work on opengl/metal
  141. if string.match(name, 'OpenGL ES') == nil and string.match(name, 'Metal') == nil then
  142. test:assertEquals(1, sharpness, 'check changed minmap filter sharpness')
  143. end
  144. test:assertGreaterEqual(2, canvas:getMipmapCount()) -- docs say no mipmaps should return 1
  145. test:assertEquals('auto', canvas:getMipmapMode())
  146. -- check debug name
  147. test:assertEquals('testcanvas', canvas:getDebugName())
  148. -- check basic rendering
  149. canvas:renderTo(function()
  150. love.graphics.setColor(1, 0, 0)
  151. love.graphics.rectangle('fill', 0, 0, 200, 200)
  152. love.graphics.setColor(1, 1, 1, 1)
  153. end)
  154. local imgdata1 = love.graphics.readbackTexture(canvas)
  155. test:assertPixels(imgdata1, {
  156. red = {{0, 0},{0,99},{99,0},{99,99}},
  157. }, 'font draw check')
  158. test:compareImg(imgdata1)
  159. -- check using canvas in love.graphics.draw()
  160. local xcanvas = love.graphics.newCanvas()
  161. love.graphics.setCanvas(xcanvas)
  162. love.graphics.draw(canvas, 0, 0)
  163. love.graphics.setCanvas()
  164. local imgdata2 = love.graphics.readbackTexture(canvas)
  165. test:assertPixels(imgdata2, {
  166. red = {{0, 0},{0,99},{99,0},{99,99}},
  167. }, 'font draw check')
  168. test:compareImg(imgdata2)
  169. -- check depth samples
  170. local dcanvas = love.graphics.newCanvas(100, 100, {
  171. type = '2d',
  172. format = 'depth16',
  173. readable = true
  174. })
  175. test:assertEquals(nil, dcanvas:getDepthSampleMode(), 'check depth sample mode nil by def')
  176. dcanvas:setDepthSampleMode('equal')
  177. test:assertEquals('equal', dcanvas:getDepthSampleMode(), 'check depth sample mode set')
  178. -- check compute writeable (wont work on opengl mac)
  179. if love.graphics.getSupported().glsl4 then
  180. local ccanvas = love.graphics.newCanvas(100, 100, {
  181. type = '2d',
  182. format = 'rgba8',
  183. computewrite = true
  184. })
  185. test:assertTrue(ccanvas:isComputeWritable())
  186. end
  187. end
  188. -- Font (love.graphics.newFont)
  189. love.test.graphics.Font = function(test)
  190. -- create obj
  191. local font = love.graphics.newFont('resources/font.ttf', 8)
  192. test:assertObject(font)
  193. -- check ascent/descent
  194. test:assertEquals(6, font:getAscent(), 'check ascent')
  195. test:assertEquals(-2, font:getDescent(), 'check descent')
  196. -- check baseline
  197. test:assertEquals(6, font:getBaseline(), 'check baseline')
  198. -- check dpi
  199. test:assertEquals(1, font:getDPIScale(), 'check dpi')
  200. -- check filter
  201. test:assertEquals('nearest', font:getFilter(), 'check filter def')
  202. font:setFilter('linear', 'linear')
  203. test:assertEquals('linear', font:getFilter(), 'check filter change')
  204. font:setFilter('nearest', 'nearest')
  205. -- check height + lineheight
  206. test:assertEquals(8, font:getHeight(), 'check height')
  207. test:assertEquals(1, font:getLineHeight(), 'check line height')
  208. font:setLineHeight(2)
  209. test:assertEquals(2, font:getLineHeight(), 'check changed line height')
  210. font:setLineHeight(1) -- reset for drawing + wrap later
  211. -- check width + kerning
  212. test:assertEquals(0, font:getKerning('a', 'b'), 'check kerning')
  213. test:assertEquals(24, font:getWidth('test'), 'check data size')
  214. -- check specific glyphs
  215. test:assertTrue(font:hasGlyphs('test'), 'check data size')
  216. -- check font wrapping
  217. local width, wrappedtext = font:getWrap('LÖVE is an *awesome* framework you can use to make 2D games in Lua.', 50)
  218. test:assertEquals(48, width, 'check actual wrap width')
  219. test:assertEquals(8, #wrappedtext, 'check wrapped lines')
  220. test:assertEquals('LÖVE is an ', wrappedtext[1], 'check wrapped line')
  221. -- check drawing font
  222. local canvas = love.graphics.newCanvas(16, 16)
  223. love.graphics.setCanvas(canvas)
  224. love.graphics.setFont(font)
  225. love.graphics.print('Aa', 0, 5)
  226. love.graphics.setCanvas()
  227. local imgdata = love.graphics.readbackTexture(canvas)
  228. test:assertPixels(imgdata, {
  229. white = {{0,3},{4,3},{7,4},{9,4},{10,5},{0,8},{4,8},{10,8}},
  230. }, 'font draw check')
  231. test:compareImg(imgdata)
  232. -- check font substitution
  233. local fontab = love.graphics.newImageFont('resources/font-letters-ab.png', 'AB')
  234. local fontcd = love.graphics.newImageFont('resources/font-letters-cd.png', 'CD')
  235. fontab:setFallbacks(fontcd)
  236. love.graphics.setCanvas(canvas)
  237. love.graphics.clear(0, 0, 0, 0)
  238. love.graphics.setFont(fontab)
  239. love.graphics.print('AB', 0, 0) -- should come from fontab
  240. love.graphics.print('CD', 0, 9) -- should come from fontcd
  241. love.graphics.setCanvas()
  242. local imgdata2 = love.graphics.readbackTexture(canvas)
  243. test:assertPixels(imgdata2, {
  244. green = {{1,8},{6,8},{2,10},{5,10},{9,10}},
  245. black = {{9,9},{14,8},{14,10},{14,1},{1,10}}
  246. }, 'font draw check')
  247. test:compareImg(imgdata2)
  248. end
  249. -- Image (love.graphics.newImage)
  250. love.test.graphics.Image = function(test)
  251. -- create object
  252. local image = love.graphics.newImage('resources/love.png', {
  253. dpiscale = 1,
  254. mipmaps = true
  255. })
  256. test:assertObject(image)
  257. test:assertFalse(image:isCanvas(), 'check not canvas')
  258. test:assertFalse(image:isComputeWritable(), 'check not compute writable')
  259. -- check dpi
  260. test:assertEquals(love.graphics.getDPIScale(), image:getDPIScale(), 'check dpi scale')
  261. -- check depth
  262. test:assertEquals(1, image:getDepth(), 'check depth is 2d')
  263. test:assertEquals(nil, image:getDepthSampleMode(), 'check depth sample nil')
  264. -- check filter
  265. local min1, mag1, ani1 = image:getFilter()
  266. test:assertEquals('nearest', min1, 'check filter def min')
  267. test:assertEquals('nearest', mag1, 'check filter def mag')
  268. test:assertEquals(1, ani1, 'check filter def ani')
  269. image:setFilter('linear', 'linear', 2)
  270. local min2, mag2, ani2 = image:getFilter()
  271. test:assertEquals('linear', min2, 'check filter changed min')
  272. test:assertEquals('linear', mag2, 'check filter changed mag')
  273. test:assertEquals(2, ani2, 'check filter changed ani')
  274. image:setFilter('nearest', 'nearest', 1)
  275. -- check layers
  276. test:assertEquals(1, image:getLayerCount(), 'check 1 layer for 2d')
  277. -- check texture type
  278. test:assertEquals('2d', image:getTextureType(), 'check 2d')
  279. -- check texture wrapping
  280. local horiz1, vert1 = image:getWrap()
  281. test:assertEquals('clamp', horiz1, 'check def wrap h')
  282. test:assertEquals('clamp', vert1, 'check def wrap v')
  283. image:setWrap('repeat', 'repeat')
  284. local horiz2, vert2 = image:getWrap()
  285. test:assertEquals('repeat', horiz2, 'check changed wrap h')
  286. test:assertEquals('repeat', vert2, 'check changed wrap v')
  287. -- check readable
  288. test:assertTrue(image:isReadable(), 'check canvas readable')
  289. -- check msaa
  290. test:assertEquals(1, image:getMSAA(), 'check samples match')
  291. -- check dimensions
  292. local cw, ch = image:getDimensions()
  293. test:assertEquals(64, cw, 'check canvas dim w')
  294. test:assertEquals(64, ch, 'check canvas dim h')
  295. test:assertEquals(cw, image:getWidth(), 'check canvas w matches dim')
  296. test:assertEquals(ch, image:getHeight(), 'check canvas h matches dim')
  297. local pw, ph = image:getPixelDimensions()
  298. test:assertEquals(64*love.graphics.getDPIScale(), pw, 'check pixel dim w')
  299. test:assertEquals(64*love.graphics.getDPIScale(), ph, 'check pixel dim h')
  300. test:assertEquals(pw, image:getPixelWidth(), 'check pixel w matches dim')
  301. test:assertEquals(ph, image:getPixelHeight(), 'check pixel h matches dim')
  302. -- check mipmaps
  303. local mode, sharpness = image:getMipmapFilter()
  304. test:assertEquals('linear', mode, 'check def minmap filter mode')
  305. test:assertEquals(0, sharpness, 'check def minmap filter sharpness')
  306. local name, version, vendor, device = love.graphics.getRendererInfo()
  307. -- @note mipmap sharpness wont work on opengl/metal
  308. image:setMipmapFilter('nearest', 1)
  309. mode, sharpness = image:getMipmapFilter()
  310. test:assertEquals('nearest', mode, 'check changed minmap filter mode')
  311. if string.match(name, 'OpenGL ES') == nil and string.match(name, 'Metal') == nil then
  312. test:assertEquals(1, sharpness, 'check changed minmap filter sharpness')
  313. end
  314. test:assertGreaterEqual(2, image:getMipmapCount()) -- docs say no mipmaps should return 1?
  315. -- check image properties
  316. test:assertFalse(image:isCompressed(), 'check not compressed')
  317. test:assertFalse(image:isFormatLinear(), 'check not linear')
  318. local cimage = love.graphics.newImage('resources/love.dxt1')
  319. test:assertObject(cimage)
  320. test:assertTrue(cimage:isCompressed(), 'check is compressed')
  321. -- check pixel replacement
  322. local rimage = love.image.newImageData('resources/loveinv.png')
  323. image:replacePixels(rimage)
  324. local canvas = love.graphics.newCanvas(64, 64)
  325. love.graphics.setCanvas(canvas)
  326. love.graphics.draw(image, 0, 0)
  327. love.graphics.setCanvas()
  328. local imgdata = love.graphics.readbackTexture(canvas)
  329. local r1, g1, b1 = imgdata:getPixel(25, 25)
  330. test:assertEquals(3, r1+g1+b1, 'check back to white')
  331. test:compareImg(imgdata)
  332. end
  333. -- Mesh (love.graphics.newMesh)
  334. love.test.graphics.Mesh = function(test)
  335. -- create 2d mesh with pretty colors
  336. local image = love.graphics.newImage('resources/love.png')
  337. local vertices = {
  338. { 0, 0, 0, 0, 1, 0, 0 },
  339. { image:getWidth(), 0, 1, 0, 0, 1, 0 },
  340. { image:getWidth(), image:getHeight(), 1, 1, 0, 0, 1 },
  341. { 0, image:getHeight(), 0, 1, 1, 1, 0 },
  342. }
  343. local mesh1 = love.graphics.newMesh(vertices, 'fan')
  344. test:assertObject(mesh1)
  345. -- check draw mode
  346. test:assertEquals('fan', mesh1:getDrawMode(), 'check draw mode')
  347. mesh1:setDrawMode('triangles')
  348. test:assertEquals('triangles', mesh1:getDrawMode(), 'check draw mode set')
  349. -- check draw range
  350. local min1, max1 = mesh1:getDrawRange()
  351. test:assertEquals(nil, min1, 'check draw range not set')
  352. mesh1:setDrawRange(1, 10)
  353. local min2, max2 = mesh1:getDrawRange()
  354. test:assertEquals(1, min2, 'check draw range set min')
  355. test:assertEquals(10, max2, 'check draw range set max')
  356. -- check texture pointer
  357. test:assertEquals(nil, mesh1:getTexture(), 'check no texture')
  358. mesh1:setTexture(image)
  359. test:assertEquals(image:getHeight(), mesh1:getTexture():getHeight(), 'check texture match w')
  360. test:assertEquals(image:getWidth(), mesh1:getTexture():getWidth(), 'check texture match h')
  361. -- check vertext count
  362. test:assertEquals(4, mesh1:getVertexCount(), 'check vertex count')
  363. -- check def vertex format
  364. local format = mesh1:getVertexFormat()
  365. test:assertEquals('floatvec2', format[2][2], 'check def vertex format 2')
  366. test:assertEquals('VertexColor', format[3][1], 'check def vertex format 3')
  367. -- check vertext attributes
  368. test:assertTrue(mesh1:isAttributeEnabled('VertexPosition'), 'check def attribute VertexPosition')
  369. test:assertTrue(mesh1:isAttributeEnabled('VertexTexCoord'), 'check def attribute VertexTexCoord')
  370. test:assertTrue(mesh1:isAttributeEnabled('VertexColor'), 'check def attribute VertexColor')
  371. mesh1:setAttributeEnabled('VertexPosition', false)
  372. mesh1:setAttributeEnabled('VertexTexCoord', false)
  373. mesh1:setAttributeEnabled('VertexColor', false)
  374. test:assertFalse(mesh1:isAttributeEnabled('VertexPosition'), 'check disable attribute VertexPosition')
  375. test:assertFalse(mesh1:isAttributeEnabled('VertexTexCoord'), 'check disable attribute VertexTexCoord')
  376. test:assertFalse(mesh1:isAttributeEnabled('VertexColor'), 'check disable attribute VertexColor')
  377. -- check vertex itself
  378. local x1, y1, u1, v1, r1, g1, b1, a1 = mesh1:getVertex(1)
  379. test:assertEquals(0, x1, 'check vertex props x')
  380. test:assertEquals(0, y1, 'check vertex props y')
  381. test:assertEquals(0, u1, 'check vertex props u')
  382. test:assertEquals(0, v1, 'check vertex props v')
  383. test:assertEquals(1, r1, 'check vertex props r')
  384. test:assertEquals(0, g1, 'check vertex props g')
  385. test:assertEquals(0, b1, 'check vertex props b')
  386. test:assertEquals(1, a1, 'check vertex props a')
  387. -- check setting a specific vertex
  388. mesh1:setVertex(2, image:getWidth(), 0, 1, 0, 0, 1, 1, 1)
  389. local x2, y2, u2, v2, r2, g2, b2, a2 = mesh1:getVertex(2)
  390. test:assertEquals(image:getWidth(), x2, 'check changed vertex props x')
  391. test:assertEquals(0, y2, 'check changed vertex props y')
  392. test:assertEquals(1, u2, 'check changed vertex props u')
  393. test:assertEquals(0, v2, 'check changed vertex props v')
  394. test:assertEquals(0, r2, 'check changed vertex props r')
  395. test:assertEquals(1, g2, 'check changed vertex props g')
  396. test:assertEquals(1, b2, 'check changed vertex props b')
  397. test:assertEquals(1, a2, 'check changed vertex props a')
  398. -- check setting a specific vertex attribute
  399. local r3, g3, b3, a3 = mesh1:getVertexAttribute(3, 3)
  400. test:assertEquals(1, b3, 'check specific vertex color')
  401. mesh1:setVertexAttribute(4, 3, 1, 0, 1)
  402. local r4, g4, b4, a4 = mesh1:getVertexAttribute(4, 3)
  403. test:assertEquals(0, g4, 'check changed vertex color')
  404. -- check setting a vertice
  405. mesh1:setVertices(vertices)
  406. local r5, g5, b5, a5 = mesh1:getVertexAttribute(4, 3)
  407. local x6, y6, u6, v6, r6, g6, b6, a6 = mesh1:getVertex(2)
  408. test:assertEquals(1, g5, 'check reset vertex color 1')
  409. test:assertEquals(0, b5, 'check reset vertex color 2')
  410. -- check setting the vertex map
  411. local vmap1 = mesh1:getVertexMap()
  412. test:assertEquals(nil, vmap1, 'check no map by def')
  413. mesh1:setVertexMap({4, 1, 2, 3})
  414. local vmap2 = mesh1:getVertexMap()
  415. test:assertEquals(4, #vmap2, 'check set map len')
  416. test:assertEquals(2, vmap2[3], 'check set map val')
  417. -- check using custom attributes
  418. local mesh2 = love.graphics.newMesh({
  419. { name = 'VertexPosition', format = 'floatvec2'},
  420. { name = 'VertexTexCoord', format = 'floatvec2'},
  421. { name = 'VertexColor', format = 'floatvec4'},
  422. { name = 'CustomValue1', format = 'floatvec2'},
  423. { name = 'CustomValue2', format = 'uint16'}
  424. }, {
  425. { 0, 0, 0, 0, 1, 0, 0, 1, 2, 1, 1005 },
  426. { image:getWidth(), 0, 1, 0, 0, 1, 0, 0, 2, 2, 2005 },
  427. { image:getWidth(), image:getHeight(), 1, 1, 0, 0, 1, 0, 2, 3, 3005 },
  428. { 0, image:getHeight(), 0, 1, 1, 1, 0, 0, 2, 4, 4005 },
  429. }, 'fan')
  430. local c1, c2 = mesh2:getVertexAttribute(1, 4)
  431. local c3 = mesh2:getVertexAttribute(1, 5)
  432. test:assertEquals(2, c1, 'check custom attribute val 1')
  433. test:assertEquals(1, c2, 'check custom attribute val 2')
  434. test:assertEquals(1005, c3, 'check custom attribute val 3')
  435. -- check attaching custom attribute + detaching
  436. mesh1:attachAttribute('CustomValue1', mesh2)
  437. test:assertTrue(mesh1:isAttributeEnabled('CustomValue1'), 'check custom attribute attached')
  438. mesh1:detachAttribute('CustomValue1')
  439. local obj, err = pcall(mesh1.isAttributeEnabled, mesh1, 'CustomValue1')
  440. test:assertNotEquals(nil, err, 'check attribute detached')
  441. mesh1:detachAttribute('VertexPosition')
  442. test:assertTrue(mesh1:isAttributeEnabled('VertexPosition'), 'check cant detach def attribute')
  443. end
  444. -- ParticleSystem (love.graphics.newParticleSystem)
  445. love.test.graphics.ParticleSystem = function(test)
  446. -- create new system
  447. local image = love.graphics.newImage('resources/pixel.png')
  448. local quad1 = love.graphics.newQuad(0, 0, 1, 1, image)
  449. local quad2 = love.graphics.newQuad(0, 0, 1, 1, image)
  450. local psystem = love.graphics.newParticleSystem(image, 1000)
  451. test:assertObject(psystem)
  452. -- check psystem state properties
  453. psystem:start()
  454. psystem:update(1)
  455. test:assertTrue(psystem:isActive(), 'check active')
  456. test:assertFalse(psystem:isPaused(), 'checked not paused by def')
  457. test:assertFalse(psystem:hasRelativeRotation(), 'check rel rot def')
  458. psystem:pause()
  459. test:assertTrue(psystem:isPaused(), 'check now paused')
  460. test:assertFalse(psystem:isStopped(), 'check not stopped by def')
  461. psystem:stop()
  462. test:assertTrue(psystem:isStopped(), 'check now stopped')
  463. psystem:start()
  464. psystem:reset()
  465. -- check emitting some particles
  466. -- need to set a lifespan at minimum or none will be counted
  467. local min, max = psystem:getParticleLifetime()
  468. test:assertEquals(0, min, 'check def lifetime min')
  469. test:assertEquals(0, max, 'check def lifetime max')
  470. psystem:setParticleLifetime(1, 2)
  471. psystem:emit(10)
  472. psystem:update(1)
  473. test:assertEquals(10, psystem:getCount(), 'check added particles')
  474. psystem:reset()
  475. test:assertEquals(0, psystem:getCount(), 'check reset')
  476. -- check setting colors
  477. local colors1 = {psystem:getColors()}
  478. test:assertEquals(1, #colors1, 'check 1 color by def')
  479. psystem:setColors(1, 1, 1, 1, 1, 0, 0, 1)
  480. local colors2 = {psystem:getColors()}
  481. test:assertEquals(2, #colors2, 'check set colors')
  482. test:assertEquals(1, colors2[2][1], 'check set color')
  483. -- check setting direction
  484. test:assertEquals(0, psystem:getDirection(), 'check def direction')
  485. psystem:setDirection(90 * (math.pi/180))
  486. test:assertEquals(math.floor(math.pi/2*100), math.floor(psystem:getDirection()*100), 'check set direction')
  487. -- check emission area options
  488. psystem:setEmissionArea('normal', 100, 50)
  489. psystem:setEmissionArea('ellipse', 100, 50)
  490. psystem:setEmissionArea('borderellipse', 100, 50)
  491. psystem:setEmissionArea('borderrectangle', 100, 50)
  492. psystem:setEmissionArea('none', 100, 50)
  493. psystem:setEmissionArea('uniform', 100, 50)
  494. local dist, dx, dy, angle, rel = psystem:getEmissionArea()
  495. test:assertEquals('uniform', dist, 'check emission area dist')
  496. test:assertEquals(100, dx, 'check emission area dx')
  497. test:assertEquals(50, dy, 'check emission area dy')
  498. test:assertEquals(0, angle, 'check emission area angle')
  499. test:assertFalse(rel, 'check emission area rel')
  500. -- check emission rate
  501. test:assertEquals(0, psystem:getEmissionRate(), 'check def emission rate')
  502. psystem:setEmissionRate(1)
  503. test:assertEquals(1, psystem:getEmissionRate(), 'check changed emission rate')
  504. -- check emission lifetime
  505. test:assertEquals(-1, psystem:getEmitterLifetime(), 'check def emitter life')
  506. psystem:setEmitterLifetime(10)
  507. test:assertEquals(10, psystem:getEmitterLifetime(), 'check changed emitter life')
  508. -- check insert mode
  509. test:assertEquals('top', psystem:getInsertMode(), 'check def insert mode')
  510. psystem:setInsertMode('bottom')
  511. psystem:setInsertMode('random')
  512. test:assertEquals('random', psystem:getInsertMode(), 'check change insert mode')
  513. -- check linear acceleration
  514. local xmin1, ymin1, xmax1, ymax1 = psystem:getLinearAcceleration()
  515. test:assertEquals(0, xmin1, 'check def lin acceleration xmin')
  516. test:assertEquals(0, ymin1, 'check def lin acceleration ymin')
  517. test:assertEquals(0, xmax1, 'check def lin acceleration xmax')
  518. test:assertEquals(0, ymax1, 'check def lin acceleration ymax')
  519. psystem:setLinearAcceleration(1, 2, 3, 4)
  520. local xmin2, ymin2, xmax2, ymax2 = psystem:getLinearAcceleration()
  521. test:assertEquals(1, xmin2, 'check change lin acceleration xmin')
  522. test:assertEquals(2, ymin2, 'check change lin acceleration ymin')
  523. test:assertEquals(3, xmax2, 'check change lin acceleration xmax')
  524. test:assertEquals(4, ymax2, 'check change lin acceleration ymax')
  525. -- check linear damping
  526. local min3, max3 = psystem:getLinearDamping()
  527. test:assertEquals(0, min3, 'check def lin damping min')
  528. test:assertEquals(0, max3, 'check def lin damping max')
  529. psystem:setLinearDamping(1, 2)
  530. local min4, max4 = psystem:getLinearDamping()
  531. test:assertEquals(1, min4, 'check change lin damping min')
  532. test:assertEquals(2, max4, 'check change lin damping max')
  533. -- check offset
  534. local ox1, oy1 = psystem:getOffset()
  535. test:assertEquals(0.5, ox1, 'check def offset x') -- 0.5 cos middle of pixel image which is 1x1
  536. test:assertEquals(0.5, oy1, 'check def offset y')
  537. psystem:setOffset(0, 10)
  538. local ox2, oy2 = psystem:getOffset()
  539. test:assertEquals(0, ox2, 'check change offset x')
  540. test:assertEquals(10, oy2, 'check change offset y')
  541. -- check lifetime (we set it earlier)
  542. local min5, max5 = psystem:getParticleLifetime()
  543. test:assertEquals(1, min5, 'check p lifetime min')
  544. test:assertEquals(2, max5, 'check p lifetime max')
  545. -- check position
  546. local x1, y1 = psystem:getPosition()
  547. test:assertEquals(0, x1, 'check emitter x')
  548. test:assertEquals(0, y1, 'check emitter y')
  549. psystem:setPosition(10, 12)
  550. local x2, y2 = psystem:getPosition()
  551. test:assertEquals(10, x2, 'check set emitter x')
  552. test:assertEquals(12, y2, 'check set emitter y')
  553. -- check quads
  554. test:assertEquals(0, #psystem:getQuads(), 'check def quads')
  555. psystem:setQuads({quad1})
  556. psystem:setQuads(quad1, quad2)
  557. test:assertEquals(2, #psystem:getQuads(), 'check set quads')
  558. -- check radial acceleration
  559. local min6, max6 = psystem:getRadialAcceleration()
  560. test:assertEquals(0, min6, 'check def rad accel min')
  561. test:assertEquals(0, max6, 'check def rad accel max')
  562. psystem:setRadialAcceleration(1, 2)
  563. local min7, max7 = psystem:getRadialAcceleration()
  564. test:assertEquals(1, min7, 'check change rad accel min')
  565. test:assertEquals(2, max7, 'check change rad accel max')
  566. -- check rotation
  567. local min8, max8 = psystem:getRotation()
  568. test:assertEquals(0, min8, 'check def rot min')
  569. test:assertEquals(0, max8, 'check def rot max')
  570. psystem:setRotation(90 * (math.pi/180), 180 * (math.pi/180))
  571. local min8, max8 = psystem:getRotation()
  572. test:assertEquals(math.floor(math.pi/2*100), math.floor(min8*100), 'check set rot min')
  573. test:assertEquals(math.floor(math.pi*100), math.floor(max8*100), 'check set rot max')
  574. -- check variation
  575. test:assertEquals(0, psystem:getSizeVariation(), 'check def variation')
  576. psystem:setSizeVariation(1)
  577. test:assertEquals(1, psystem:getSizeVariation(), 'check change variation')
  578. -- check sizes
  579. test:assertEquals(1, #{psystem:getSizes()}, 'check def size')
  580. psystem:setSizes(1, 2, 4, 1, 3, 2)
  581. local sizes = {psystem:getSizes()}
  582. test:assertEquals(6, #sizes, 'check set sizes')
  583. test:assertEquals(3, sizes[5], 'check set size')
  584. -- check speed
  585. local min9, max9 = psystem:getSpeed()
  586. test:assertEquals(0, min9, 'check def speed min')
  587. test:assertEquals(0, max9, 'check def speed max')
  588. psystem:setSpeed(1, 10)
  589. local min10, max10 = psystem:getSpeed()
  590. test:assertEquals(1, min10, 'check change speed min')
  591. test:assertEquals(10, max10, 'check change speed max')
  592. -- check variation + spin
  593. local variation = psystem:getSpinVariation()
  594. test:assertEquals(0, variation, 'check def spin variation')
  595. psystem:setSpinVariation(1)
  596. test:assertEquals(1, psystem:getSpinVariation(), 'check change spin variation')
  597. psystem:setSpin(1, 2)
  598. local min11, max11 = psystem:getSpin()
  599. test:assertEquals(1, min11, 'check change spin min')
  600. test:assertEquals(2, max11, 'check change spin max')
  601. -- check spread
  602. test:assertEquals(0, psystem:getSpread(), 'check def spread')
  603. psystem:setSpread(90 * (math.pi/180))
  604. test:assertEquals(math.floor(math.pi/2*100), math.floor(psystem:getSpread()*100), 'check change spread')
  605. -- tangential acceleration
  606. local min12, max12 = psystem:getTangentialAcceleration()
  607. test:assertEquals(0, min12, 'check def tan accel min')
  608. test:assertEquals(0, max12, 'check def tan accel max')
  609. psystem:setTangentialAcceleration(1, 2)
  610. local min13, max13 = psystem:getTangentialAcceleration()
  611. test:assertEquals(1, min13, 'check change tan accel min')
  612. test:assertEquals(2, max13, 'check change tan accel max')
  613. -- check texture
  614. test:assertNotEquals(nil, psystem:getTexture(), 'check texture obj')
  615. test:assertObject(psystem:getTexture())
  616. psystem:setTexture(love.graphics.newImage('resources/love.png'))
  617. test:assertObject(psystem:getTexture())
  618. -- try a graphics test!
  619. -- hard to get exactly because of the variation but we can use some pixel
  620. -- tolerance and volume to try and cover the randomness
  621. local psystem2 = love.graphics.newParticleSystem(image, 5000)
  622. psystem2:setEmissionArea('uniform', 2, 64)
  623. psystem2:setColors(1, 0, 0, 1)
  624. psystem2:setDirection(0 * math.pi/180)
  625. psystem2:setEmitterLifetime(100)
  626. psystem2:setEmissionRate(5000)
  627. local psystem3 = psystem2:clone()
  628. psystem3:setPosition(64, 0)
  629. psystem3:setColors(0, 1, 0, 1)
  630. psystem3:setDirection(180 * (math.pi/180))
  631. psystem2:start()
  632. psystem3:start()
  633. psystem2:update(1)
  634. psystem3:update(1)
  635. local canvas = love.graphics.newCanvas(64, 64)
  636. love.graphics.setCanvas(canvas)
  637. love.graphics.clear(0, 0, 0, 1)
  638. love.graphics.draw(psystem2, 0, 0)
  639. love.graphics.draw(psystem3, 0, 0)
  640. love.graphics.setCanvas()
  641. -- this should result in a bunch of red pixels on the left 2px of the canvas
  642. -- and a bunch of green pixels on the right 2px of the canvas
  643. local imgdata = love.graphics.readbackTexture(canvas)
  644. test.pixel_tolerance = 1
  645. test:compareImg(imgdata)
  646. end
  647. -- Quad (love.graphics.newQuad)
  648. love.test.graphics.Quad = function(test)
  649. -- create quad obj
  650. local texture = love.graphics.newImage('resources/love.png')
  651. local quad = love.graphics.newQuad(0, 0, 32, 32, texture)
  652. test:assertObject(quad)
  653. -- check properties
  654. test:assertEquals(1, quad:getLayer(), 'check default layer')
  655. quad:setLayer(2)
  656. test:assertEquals(2, quad:getLayer(), 'check changed layer')
  657. local sw, sh = quad:getTextureDimensions()
  658. test:assertEquals(64, sw, 'check texture w')
  659. test:assertEquals(64, sh, 'check texture h')
  660. -- check drawing and viewport changes
  661. local canvas = love.graphics.newCanvas(64, 64)
  662. love.graphics.setCanvas(canvas)
  663. love.graphics.draw(texture, quad, 0, 0)
  664. quad:setViewport(32, 32, 32, 32, 64, 64)
  665. love.graphics.draw(texture, quad, 32, 32)
  666. love.graphics.setCanvas()
  667. local imgdata = love.graphics.readbackTexture(canvas)
  668. test:assertPixels(imgdata, {
  669. white = {{17,31},{31,31},{31,24},{32,32},{46,32},{32,46}},
  670. lovepink = {{2,31},{31,2}},
  671. loveblue = {{32,61},{61,32}}
  672. }, 'check quad drawing')
  673. test:compareImg(imgdata)
  674. end
  675. -- Shader (love.graphics.newShader)
  676. love.test.graphics.Shader = function(test)
  677. -- check valid shader
  678. local pixelcode1 = [[
  679. uniform Image tex2;
  680. vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) {
  681. vec4 texturecolor = Texel(tex2, texture_coords);
  682. return texturecolor * color;
  683. }
  684. ]]
  685. local vertexcode1 = [[
  686. vec4 position(mat4 transform_projection, vec4 vertex_position) {
  687. return transform_projection * vertex_position;
  688. }
  689. ]]
  690. local shader1 = love.graphics.newShader(pixelcode1, vertexcode1, {debugname = 'testshader'})
  691. test:assertObject(shader1)
  692. test:assertEquals('', shader1:getWarnings(), 'check shader valid')
  693. test:assertFalse(shader1:hasUniform('tex1'), 'check invalid uniform')
  694. test:assertTrue(shader1:hasUniform('tex2'), 'check valid uniform')
  695. test:assertEquals('testshader', shader1:getDebugName())
  696. -- check invalid shader
  697. local pixelcode2 = [[
  698. uniform float ww;
  699. vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) {
  700. vec4 texturecolor = Texel(tex, texture_coords);
  701. float unused = ww * 3 * color;
  702. return texturecolor * color;
  703. }
  704. ]]
  705. local res, err = pcall(love.graphics.newShader, pixelcode2, vertexcode1)
  706. test:assertNotEquals(nil, err, 'check shader compile fails')
  707. -- check using a shader to draw + sending uniforms
  708. -- shader will return a given color if overwrite set to 1, otherwise def. draw
  709. local pixelcode3 = [[
  710. uniform vec4 col;
  711. uniform float overwrite;
  712. vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) {
  713. vec4 texcol = Texel(tex, texture_coords);
  714. if (overwrite == 1.0) {
  715. return col;
  716. } else {
  717. return texcol * color;
  718. }
  719. }
  720. ]]
  721. local shader3 = love.graphics.newShader(pixelcode3, vertexcode1)
  722. local canvas = love.graphics.newCanvas(16, 16)
  723. love.graphics.push("all")
  724. love.graphics.setCanvas(canvas)
  725. -- set color to yellow
  726. love.graphics.setColor(1, 1, 0, 1)
  727. -- turn shader 'on' and use red to draw
  728. shader3:send('overwrite', 1)
  729. shader3:sendColor('col', {1, 0, 0, 1})
  730. love.graphics.setShader(shader3)
  731. love.graphics.rectangle('fill', 0, 0, 8, 8)
  732. love.graphics.setShader()
  733. -- turn shader 'off' and draw again
  734. shader3:send('overwrite', 0)
  735. love.graphics.setShader(shader3)
  736. love.graphics.rectangle('fill', 8, 8, 8, 8)
  737. love.graphics.pop()
  738. local imgdata = love.graphics.readbackTexture(canvas)
  739. test:assertPixels(imgdata, {
  740. red = {{1,1},{1,7},{7,7},{7,1}},
  741. yellow = {{8,8},{8,15},{15,15},{15,8}}
  742. }, 'shader draw check')
  743. test:compareImg(imgdata)
  744. -- test some uncommon paths for shader uniforms
  745. local shader4 = love.graphics.newShader[[
  746. uniform bool booleans[5];
  747. vec4 effect(vec4 vcolor, Image tex, vec2 tc, vec2 pc) {
  748. return booleans[3] ? vec4(0, 1, 0, 0) : vec4(1, 0, 0, 0);
  749. }
  750. ]]
  751. shader4:send("booleans", false, true, true)
  752. local shader5 = love.graphics.newShader[[
  753. uniform sampler2D textures[5];
  754. vec4 effect(vec4 vcolor, Image tex, vec2 tc, vec2 pc) {
  755. return Texel(textures[2], tc) + Texel(textures[3], tc);
  756. }
  757. ]]
  758. local canvas2 = love.graphics.newCanvas(1, 1)
  759. love.graphics.setCanvas(canvas2)
  760. love.graphics.clear(0, 0.5, 0, 1)
  761. love.graphics.setCanvas()
  762. shader5:send("textures", canvas2, canvas2, canvas2, canvas2, canvas2)
  763. local shader6 = love.graphics.newShader[[
  764. struct Data {
  765. bool boolValue;
  766. float floatValue;
  767. sampler2D tex;
  768. };
  769. uniform Data data[3];
  770. vec4 effect(vec4 vcolor, Image tex, vec2 tc, vec2 pc) {
  771. return data[1].boolValue ? Texel(data[0].tex, tc) : vec4(0.0, 0.0, 0.0, 0.0);
  772. }
  773. ]]
  774. shader6:send("data[1].boolValue", true)
  775. shader6:send("data[0].tex", canvas2)
  776. end
  777. -- SpriteBatch (love.graphics.newSpriteBatch)
  778. love.test.graphics.SpriteBatch = function(test)
  779. -- create batch
  780. local texture1 = love.graphics.newImage('resources/cubemap.png')
  781. local texture2 = love.graphics.newImage('resources/love.png')
  782. local quad1 = love.graphics.newQuad(32, 12, 1, 1, texture2) -- lovepink
  783. local quad2 = love.graphics.newQuad(32, 32, 1, 1, texture2) -- white
  784. local sbatch = love.graphics.newSpriteBatch(texture1, 5000)
  785. test:assertObject(sbatch)
  786. -- check initial count
  787. test:assertEquals(0, sbatch:getCount(), 'check batch size')
  788. -- check buffer size
  789. test:assertEquals(5000, sbatch:getBufferSize(), 'check batch size')
  790. -- check height/width/texture
  791. test:assertEquals(texture1:getWidth(), sbatch:getTexture():getWidth(), 'check texture match w')
  792. test:assertEquals(texture1:getHeight(), sbatch:getTexture():getHeight(), 'check texture match h')
  793. sbatch:setTexture(texture2)
  794. test:assertEquals(texture2:getWidth(), sbatch:getTexture():getWidth(), 'check texture change w')
  795. test:assertEquals(texture2:getHeight(), sbatch:getTexture():getHeight(), 'check texture change h')
  796. -- check colors
  797. local r1, g1, b1, a1 = sbatch:getColor()
  798. test:assertEquals(1, r1, 'check initial color r')
  799. test:assertEquals(1, g1, 'check initial color g')
  800. test:assertEquals(1, b1, 'check initial color b')
  801. test:assertEquals(1, a1, 'check initial color a')
  802. sbatch:setColor(1, 0, 0, 1)
  803. local r2, g2, b2, a2 = sbatch:getColor()
  804. test:assertEquals(1, r2, 'check set color r')
  805. test:assertEquals(0, g2, 'check set color g')
  806. test:assertEquals(0, b2, 'check set color b')
  807. test:assertEquals(1, a2, 'check set color a')
  808. -- check adding sprites
  809. local offset_x = 0
  810. local offset_y = 0
  811. local color = 'white'
  812. sbatch:setColor(1, 1, 1, 1)
  813. local sprites = {}
  814. for s=1,4096 do
  815. local spr = sbatch:add(quad1, offset_x, offset_y, 0, 1, 1)
  816. table.insert(sprites, {spr, offset_x, offset_y})
  817. offset_x = offset_x + 1
  818. if s % 64 == 0 then
  819. -- alternate row colors
  820. if color == 'white' then
  821. color = 'red'
  822. sbatch:setColor(1, 0, 0, 1)
  823. else
  824. color = 'white'
  825. sbatch:setColor(1, 1, 1, 1)
  826. end
  827. offset_y = offset_y + 1
  828. offset_x = 0
  829. end
  830. end
  831. test:assertEquals(4096, sbatch:getCount())
  832. -- test drawing and setting
  833. local canvas = love.graphics.newCanvas(64, 64)
  834. love.graphics.setCanvas(canvas)
  835. love.graphics.clear(0, 0, 0, 1)
  836. love.graphics.draw(sbatch, 0, 0)
  837. love.graphics.setCanvas()
  838. local imgdata1 = love.graphics.readbackTexture(canvas)
  839. test:assertPixels(imgdata1, {
  840. lovepink = {{0,0},{63,2},{0,32},{63,32},{63,0},{63,2}}
  841. }, 'sbatch draw normal')
  842. test:compareImg(imgdata1)
  843. -- use set to change some sprites
  844. for s=1,2048 do
  845. sbatch:set(sprites[s][1], quad2, sprites[s][2], sprites[s][3]+1, 0, 1, 1)
  846. end
  847. love.graphics.setCanvas(canvas)
  848. love.graphics.clear(0, 0, 0, 1)
  849. love.graphics.draw(sbatch, 0, 0)
  850. love.graphics.setCanvas()
  851. local imgdata2 = love.graphics.readbackTexture(canvas)
  852. test:assertPixels(imgdata2, {
  853. lovepink = {{0,32},{63,32}},
  854. black = {{0,0},{63,0}},
  855. white = {{0,1},{63,1},{0,31},{63,31}}
  856. }, 'sbatch draw set')
  857. test:compareImg(imgdata2)
  858. -- set drawRange and redraw
  859. sbatch:setDrawRange(1025, 2048)
  860. love.graphics.setCanvas(canvas)
  861. love.graphics.clear(0, 0, 0, 1)
  862. love.graphics.draw(sbatch, 0, 0)
  863. love.graphics.setCanvas()
  864. local imgdata3 = love.graphics.readbackTexture(canvas)
  865. test:assertPixels(imgdata3, {
  866. lovepink = {{0,32},{63,32}},
  867. black = {{0,0},{63,0},{0,48},{63,48}},
  868. white = {{0,17},{63,17},{0,31},{63,31}}
  869. }, 'sbatch draw drawrange')
  870. test:compareImg(imgdata3)
  871. -- clear and redraw
  872. sbatch:clear()
  873. love.graphics.setCanvas(canvas)
  874. love.graphics.clear(0, 0, 0, 1)
  875. love.graphics.draw(sbatch, 0, 0)
  876. love.graphics.setCanvas()
  877. local imgdata4 = love.graphics.readbackTexture(canvas)
  878. test:assertPixels(imgdata4, {
  879. black = {{0,0},{63,0},{0,32},{63,32},{0,63},{63,63}},
  880. }, 'sbatch draw clear')
  881. test:compareImg(imgdata4)
  882. -- array texture sbatch
  883. local texture3 = love.graphics.newArrayImage({
  884. 'resources/love.png',
  885. 'resources/loveinv.png'
  886. })
  887. local asbatch = love.graphics.newSpriteBatch(texture3, 4096)
  888. local quad3 = love.graphics.newQuad(32, 52, 1, 1, texture3) -- loveblue
  889. sprites = {}
  890. for s=1,4096 do
  891. local spr = asbatch:addLayer(1, quad3, 0, s, math.floor(s/64), 1, 1)
  892. table.insert(sprites, {spr, s, math.floor(s/64)})
  893. end
  894. test:assertEquals(4096, asbatch:getCount(), 'check max batch size applies')
  895. for s=1,2048 do
  896. asbatch:setLayer(sprites[s][1], 2, sprites[s][2], sprites[s][3], 0, 1, 1)
  897. end
  898. love.graphics.setCanvas(canvas)
  899. love.graphics.clear(0, 0, 0, 1)
  900. love.graphics.draw(asbatch, 0, 0)
  901. love.graphics.setCanvas()
  902. local imgdata5 = love.graphics.readbackTexture(canvas)
  903. test:assertPixels(imgdata5, {
  904. loveblue = {{31,2},{63,2},{3,30},{3,33},{16,47},{63,47}},
  905. lovepink = {{17,48},{63,48},{31,61},{63,61}},
  906. black = {{0,0},{63,0},{63,63},{63,0},{30,2},{30,61}},
  907. }, 'sbatch draw layers')
  908. test:compareImg(imgdata5)
  909. end
  910. -- Text (love.graphics.newTextBatch)
  911. love.test.graphics.Text = function(test)
  912. -- setup text object
  913. local font = love.graphics.newFont('resources/font.ttf', 8)
  914. local plaintext = love.graphics.newTextBatch(font, 'test')
  915. test:assertObject(plaintext)
  916. -- check height/width/dimensions
  917. test:assertEquals(font:getHeight(), plaintext:getFont():getHeight(), 'check font matches')
  918. local tw, th = plaintext:getDimensions()
  919. test:assertEquals(24, tw, 'check initial dim w')
  920. test:assertEquals(8, th, 'check initial dim h')
  921. test:assertEquals(tw, plaintext:getWidth(), 'check initial dim w')
  922. test:assertEquals(th, plaintext:getHeight(), 'check initial dim h')
  923. -- check changing text effects dimensions
  924. plaintext:add('more text', 100, 0, 0)
  925. test:assertEquals(49, plaintext:getDimensions(), 'check adding text')
  926. plaintext:set('test')
  927. test:assertEquals(24, plaintext:getDimensions(), 'check resetting text')
  928. plaintext:clear()
  929. test:assertEquals(0, plaintext:getDimensions(), 'check clearing text')
  930. -- check drawing + setting more complex text
  931. local colortext = love.graphics.newTextBatch(font, {{1, 0, 0, 1}, 'test'})
  932. test:assertObject(colortext)
  933. colortext:setf('LÖVE is an *awesome* framework you can use to make 2D games in Lua', 60, 'right')
  934. colortext:addf({{1, 1, 0}, 'overlap'}, 1000, 'left')
  935. local font2 = love.graphics.newFont('resources/font.ttf', 8)
  936. colortext:setFont(font2)
  937. local canvas = love.graphics.newCanvas(64, 64)
  938. love.graphics.setCanvas(canvas)
  939. love.graphics.draw(colortext, 0, 10)
  940. love.graphics.setCanvas()
  941. local imgdata = love.graphics.readbackTexture(canvas)
  942. test:assertPixels(imgdata, {
  943. yellow = {{1,9},{8,13},{16,11},{22,10},{25,7},{29,9},{32,13},{34,15}},
  944. white = {{17,13},{30,12},{38,9},{44,13},{58,13},{8,29},{58,29},{57,37},{5,39},{57,45},{1,55}}
  945. }, 'text draw check')
  946. test:compareImg(imgdata)
  947. end
  948. -- Video (love.graphics.newVideo)
  949. love.test.graphics.Video = function(test)
  950. -- create video obj
  951. local video = love.graphics.newVideo('resources/sample.ogv')
  952. test:assertObject(video)
  953. -- check dimensions
  954. local w, h = video:getDimensions()
  955. test:assertEquals(496, w, 'check vid dim w')
  956. test:assertEquals(502, h, 'check vid dim h')
  957. test:assertEquals(w, video:getWidth(), 'check vid width match')
  958. test:assertEquals(h, video:getHeight(), 'check vid height match')
  959. -- check filters
  960. local min1, mag1, ani1 = video:getFilter()
  961. test:assertEquals('nearest', min1, 'check def filter min')
  962. test:assertEquals('nearest', mag1, 'check def filter mag')
  963. test:assertEquals(1, ani1, 'check def filter ani')
  964. video:setFilter('linear', 'linear', 2)
  965. local min2, mag2, ani2 = video:getFilter()
  966. test:assertEquals('linear', min2, 'check changed filter min')
  967. test:assertEquals('linear', mag2, 'check changed filter mag')
  968. test:assertEquals(2, ani2, 'check changed filter ani')
  969. -- check video playing
  970. test:assertFalse(video:isPlaying(), 'check paused by default')
  971. test:assertEquals(0, video:tell(), 'check 0:00 by default')
  972. -- covered by their own obj tests in video but check returns obj
  973. local source = video:getSource()
  974. test:assertObject(source)
  975. local stream = video:getStream()
  976. test:assertObject(stream)
  977. -- check playing / pausing / seeking states
  978. video:play()
  979. test:waitSeconds(0.25)
  980. video:pause()
  981. -- runners can be a bit funny and just not play anything sometimes
  982. if not GITHUB_RUNNER then
  983. test:assertRange(video:tell(), 0.2, 0.35, 'check video playing for 0.25s')
  984. end
  985. video:seek(0.2)
  986. test:assertEquals(0.2, video:tell(), 'check video seeking')
  987. video:rewind()
  988. test:assertEquals(0, video:tell(), 'check video rewind')
  989. video:setFilter('nearest', 'nearest', 1)
  990. -- check actuall drawing with the vid
  991. local canvas = love.graphics.newCanvas(500, 500)
  992. love.graphics.setCanvas(canvas)
  993. love.graphics.clear(1, 0, 0, 1)
  994. love.graphics.draw(video, 0, 0)
  995. love.graphics.setCanvas()
  996. local imgdata = love.graphics.readbackTexture(canvas)
  997. test:assertPixels(imgdata, {
  998. black = {{0,0},{495,0},{495,499},{0,499}},
  999. red = {{499,0},{499,499}}
  1000. }, 'video draw')
  1001. test:compareImg(imgdata)
  1002. end
  1003. --------------------------------------------------------------------------------
  1004. --------------------------------------------------------------------------------
  1005. ------------------------------------DRAWING-------------------------------------
  1006. --------------------------------------------------------------------------------
  1007. --------------------------------------------------------------------------------
  1008. -- love.graphics.arc
  1009. love.test.graphics.arc = function(test)
  1010. -- draw some arcs using pi format
  1011. local canvas = love.graphics.newCanvas(32, 32)
  1012. love.graphics.setCanvas(canvas)
  1013. love.graphics.clear(0, 0, 0, 1)
  1014. love.graphics.setColor(1, 1, 1, 1)
  1015. love.graphics.arc('line', "pie", 16, 16, 16, 0 * (math.pi/180), 360 * (math.pi/180), 10)
  1016. love.graphics.arc('fill', "pie", 16, 16, 16, 270 * (math.pi/180), 45 * (math.pi/180), 10)
  1017. love.graphics.setColor(1, 0, 0, 1)
  1018. love.graphics.arc('line', "pie", 16, 16, 16, 0 * (math.pi/180), 90 * (math.pi/180), 10)
  1019. love.graphics.setColor(1, 1, 0, 1)
  1020. love.graphics.arc('line', "pie", 16, 16, 16, 180 * (math.pi/180), 135 * (math.pi/180), 10)
  1021. love.graphics.setColor(1, 1, 1, 1)
  1022. love.graphics.setCanvas()
  1023. local imgdata1 = love.graphics.readbackTexture(canvas)
  1024. -- draw some arcs with open format
  1025. love.graphics.setCanvas(canvas)
  1026. love.graphics.clear(0, 0, 0, 1)
  1027. love.graphics.setColor(1, 1, 1, 1)
  1028. love.graphics.arc('line', "open", 16, 16, 16, 0 * (math.pi/180), 315 * (math.pi/180), 10)
  1029. love.graphics.setColor(1, 0, 0, 1)
  1030. love.graphics.arc('fill', "open", 16, 16, 16, 0 * (math.pi/180), 180 * (math.pi/180), 10)
  1031. love.graphics.setColor(1, 1, 0, 1)
  1032. love.graphics.arc('fill', "open", 16, 16, 16, 180 * (math.pi/180), 270 * (math.pi/180), 10)
  1033. love.graphics.setColor(1, 1, 1, 1)
  1034. love.graphics.setCanvas()
  1035. local imgdata2 = love.graphics.readbackTexture(canvas)
  1036. -- draw some arcs with closed format
  1037. love.graphics.setCanvas(canvas)
  1038. love.graphics.clear(0, 0, 0, 1)
  1039. love.graphics.setColor(1, 1, 1, 1)
  1040. love.graphics.arc('line', "closed", 16, 16, 16, 0 * (math.pi/180), 315 * (math.pi/180), 10)
  1041. love.graphics.setColor(1, 0, 0, 1)
  1042. love.graphics.arc('fill', "closed", 16, 16, 16, 0 * (math.pi/180), 180 * (math.pi/180), 10)
  1043. love.graphics.setColor(1, 1, 0, 1)
  1044. love.graphics.arc('line', "closed", 16, 16, 16, 180 * (math.pi/180), 90 * (math.pi/180), 10)
  1045. love.graphics.setColor(1, 1, 1, 1)
  1046. love.graphics.setCanvas()
  1047. local imgdata3 = love.graphics.readbackTexture(canvas)
  1048. if GITHUB_RUNNER and love.system.getOS() == 'OS X' then
  1049. -- on macosx runners, the arcs are not drawn as accurately at low res
  1050. -- there's a couple pixels different in the curve of the arc but as we
  1051. -- are at such a low resolution I think that can be expected
  1052. -- on real hardware the test passes fine though
  1053. test:assertTrue(true, 'skip test')
  1054. else
  1055. test:compareImg(imgdata1)
  1056. test:compareImg(imgdata2)
  1057. test:compareImg(imgdata3)
  1058. end
  1059. end
  1060. -- love.graphics.circle
  1061. love.test.graphics.circle = function(test)
  1062. -- draw some circles
  1063. local canvas = love.graphics.newCanvas(32, 32)
  1064. love.graphics.setCanvas(canvas)
  1065. love.graphics.clear(0, 0, 0, 1)
  1066. love.graphics.setColor(1, 1, 1, 1)
  1067. love.graphics.circle('fill', 16, 16, 16)
  1068. love.graphics.setColor(1, 0, 0, 1)
  1069. love.graphics.circle('line', 16, 16, 16)
  1070. love.graphics.setColor(1, 1, 0, 1)
  1071. love.graphics.circle('fill', 16, 16, 8)
  1072. love.graphics.setColor(0, 1, 0, 1)
  1073. love.graphics.circle('fill', 16, 16, 4)
  1074. love.graphics.setColor(1, 1, 1, 1)
  1075. love.graphics.setCanvas()
  1076. local imgdata = love.graphics.readbackTexture(canvas)
  1077. test:assertPixels(imgdata, {
  1078. white = {{13,8},{18,8},{23,13},{23,18}},
  1079. green = {
  1080. {15,12},{16,12},{13,13},{18,13},{12,15},{12,16},{13,18},{18,18},
  1081. {15,19},{16,19},{19,15},{19,16}
  1082. },
  1083. black = {{10,0},{21,0},{0,10},{0,21},{31,10},{31,21},{10,31},{21,31}},
  1084. yellow = {
  1085. {11,10},{10,11},{8,14},{8,17},{10,20},{11,21},{14,23},{17,23},{20,21},
  1086. {21,20},{23,17},{23,14},{20,10},{21,11},{17,8},{14,8}
  1087. },
  1088. red = {{11,0},{20,0},{11,31},{20,31},{0,11},{0,20},{31,20},{31,11}}
  1089. }, 'circle')
  1090. test:compareImg(imgdata)
  1091. end
  1092. -- love.graphics.clear
  1093. love.test.graphics.clear = function(test)
  1094. local canvas = love.graphics.newCanvas(16, 16)
  1095. love.graphics.setCanvas(canvas)
  1096. love.graphics.clear(0, 0, 0, 1)
  1097. love.graphics.clear(1, 1, 0, 1)
  1098. love.graphics.setCanvas()
  1099. local imgdata = love.graphics.readbackTexture(canvas)
  1100. test:assertPixels(imgdata, {
  1101. yellow = {{0,0},{15,0},{0,15},{15,15},{8,8}}
  1102. }, 'clear')
  1103. test:compareImg(imgdata)
  1104. end
  1105. -- love.graphics.discard
  1106. love.test.graphics.discard = function(test)
  1107. -- from the docs: "on some desktops this may do nothing"
  1108. test:skipTest('cant test this worked')
  1109. end
  1110. -- love.graphics.draw
  1111. love.test.graphics.draw = function(test)
  1112. local canvas1 = love.graphics.newCanvas(32, 32)
  1113. local canvas2 = love.graphics.newCanvas(32, 32)
  1114. local transform = love.math.newTransform( )
  1115. transform:translate(16, 0)
  1116. transform:scale(0.5, 0.5)
  1117. love.graphics.setCanvas(canvas1)
  1118. love.graphics.clear(0, 0, 0, 1)
  1119. -- img, offset
  1120. love.graphics.draw(Logo.texture, Logo.img, 0, 0, 0, 1, 1, 16, 16)
  1121. love.graphics.setCanvas()
  1122. love.graphics.setCanvas(canvas2)
  1123. love.graphics.clear(1, 0, 0, 1)
  1124. -- canvas, scale, shear, transform obj
  1125. love.graphics.draw(canvas1, 0, 0, 0, 1, 1, 0, 0, 2, 2)
  1126. love.graphics.draw(canvas1, 0, 16, 0, 0.5, 0.5)
  1127. love.graphics.draw(canvas1, 16, 16, 0, 0.5, 0.5)
  1128. love.graphics.draw(canvas1, transform)
  1129. love.graphics.setCanvas()
  1130. local imgdata = love.graphics.readbackTexture(canvas2)
  1131. test:assertPixels(imgdata, {
  1132. lovepink = {{23,3},{23,19},{7,19},{0,0},{16,0},{0,16},{16,16}},
  1133. loveblue = {{0,31},{15,17},{15,31},{16,31},{31,17},{31,31},{16,15},{31,15}},
  1134. white = {{6,19},{8,19},{22,19},{24,19},{22,3},{24,3}},
  1135. red = {{0,1},{1,0},{15,0},{15,7},{0,15},{7,15}}
  1136. }, 'drawing')
  1137. test:compareImg(imgdata)
  1138. end
  1139. -- love.graphics.drawInstanced
  1140. love.test.graphics.drawInstanced = function(test)
  1141. local image = love.graphics.newImage('resources/love.png')
  1142. local vertices = {
  1143. { 0, 0, 0, 0, 1, 0, 0 },
  1144. { image:getWidth(), 0, 1, 0, 0, 1, 0 },
  1145. { image:getWidth(), image:getHeight(), 1, 1, 0, 0, 1 },
  1146. { 0, image:getHeight(), 0, 1, 1, 1, 0 },
  1147. }
  1148. local mesh = love.graphics.newMesh(vertices, 'fan')
  1149. local canvas = love.graphics.newCanvas(64, 64)
  1150. love.graphics.setCanvas(canvas)
  1151. love.graphics.clear(0, 0, 0, 1)
  1152. love.graphics.drawInstanced(mesh, 1000, 0, 0, 0, 1, 1)
  1153. love.graphics.setCanvas()
  1154. local imgdata = love.graphics.readbackTexture(canvas)
  1155. test:assertPixels(imgdata, {
  1156. red = {{0,0}},
  1157. green = {{63,0}},
  1158. blue = {{63,63}},
  1159. yellow = {{0,63}}
  1160. }, 'draw instances')
  1161. -- need 1 tolerance here just cos of the amount of colors
  1162. test.rgba_tolerance = 1
  1163. test:compareImg(imgdata)
  1164. end
  1165. -- love.graphics.drawLayer
  1166. love.test.graphics.drawLayer = function(test)
  1167. local image = love.graphics.newArrayImage({
  1168. 'resources/love.png', 'resources/loveinv.png',
  1169. 'resources/love.png', 'resources/loveinv.png'
  1170. })
  1171. local canvas = love.graphics.newCanvas(64, 64)
  1172. love.graphics.setCanvas(canvas)
  1173. love.graphics.clear(0, 0, 0, 1)
  1174. love.graphics.drawLayer(image, 1, 0, 0, 0, 1, 1)
  1175. love.graphics.drawLayer(image, 2, 32, 0, 0, 0.5, 0.5)
  1176. love.graphics.drawLayer(image, 4, 0, 32, 0, 0.5, 0.5)
  1177. love.graphics.drawLayer(image, 3, 32, 32, 0, 2, 2, 16, 16)
  1178. love.graphics.setCanvas()
  1179. local imgdata = love.graphics.readbackTexture(canvas)
  1180. test:assertPixels(imgdata, {
  1181. lovepink = {{30,2},{33,2},{2,30},{2,33},{4,60},{4,63},{60,4},{63,4},{31,23},{32,23}},
  1182. loveblue = {{14,33},{17,33},{46,1},{49,1},{1,46},{1,49},{33,14},{33,17}},
  1183. black = {{0,0},{63,0},{0,63},{39,6},{40,6},{6,39},{6,40},{6,55},{55,6}},
  1184. white = {{46,11},{48,11},{14,43},{16,43},{30,23},{33,23},{34,54},{53,40},{63,63}}
  1185. }, 'draw layer')
  1186. test:compareImg(imgdata)
  1187. end
  1188. -- love.graphics.ellipse
  1189. love.test.graphics.ellipse = function(test)
  1190. local canvas = love.graphics.newCanvas(32, 32)
  1191. love.graphics.setCanvas(canvas)
  1192. love.graphics.clear(0, 0, 0, 1)
  1193. love.graphics.setColor(1, 0, 0, 1)
  1194. love.graphics.ellipse('fill', 16, 16, 16, 8)
  1195. love.graphics.setColor(1, 1, 0, 1)
  1196. love.graphics.ellipse('fill', 24, 24, 10, 24)
  1197. love.graphics.setColor(1, 0, 1, 1)
  1198. love.graphics.ellipse('fill', 16, 0, 8, 16)
  1199. love.graphics.setColor(1, 1, 1, 1)
  1200. love.graphics.setCanvas()
  1201. local imgdata = love.graphics.readbackTexture(canvas)
  1202. test:assertPixels(imgdata, {
  1203. red = {{0,14},{0,17},{7,9},{7,22},{14,15},{14,16}},
  1204. pink = {{15,15},{16,15},{8,0},{8,4},{23,0},{23,4},{13,14},{18,14}},
  1205. yellow = {{24,0},{25,0},{14,17},{14,30},{15,31},{31,8}}
  1206. }, 'ellipses')
  1207. test:compareImg(imgdata)
  1208. end
  1209. -- love.graphics.flushBatch
  1210. love.test.graphics.flushBatch = function(test)
  1211. love.graphics.flushBatch()
  1212. local initial = love.graphics.getStats()['drawcalls']
  1213. local canvas = love.graphics.newCanvas(32, 32)
  1214. love.graphics.setCanvas(canvas)
  1215. love.graphics.clear(0, 0, 0, 1)
  1216. love.graphics.rectangle('fill', 0, 0, 32, 32)
  1217. love.graphics.setColor(1, 1, 1, 1)
  1218. love.graphics.setCanvas()
  1219. love.graphics.flushBatch()
  1220. local after = love.graphics.getStats()['drawcalls']
  1221. test:assertEquals(initial+1, after, 'check drawcalls increased')
  1222. end
  1223. -- love.graphics.line
  1224. love.test.graphics.line = function(test)
  1225. local canvas = love.graphics.newCanvas(16, 16)
  1226. love.graphics.setCanvas(canvas)
  1227. love.graphics.clear(0, 0, 0, 1)
  1228. love.graphics.setColor(1, 0, 0, 1)
  1229. love.graphics.line(1,1,16,1,16,16,1,16,1,1)
  1230. love.graphics.setColor(1, 1, 0, 1)
  1231. love.graphics.line({0,0,8,8,16,0,8,8,16,16,8,8,0,16})
  1232. love.graphics.setColor(1, 1, 1, 1)
  1233. love.graphics.setCanvas()
  1234. local imgdata = love.graphics.readbackTexture(canvas)
  1235. test:assertPixels(imgdata, {
  1236. yellow = {{0,0},{15,0},{0,15},{15,15},{7,7},{8,7},{8,7},{8,8}},
  1237. red = {{1,0},{14,0},{0,1},{0,14},{15,1},{15,14},{1,15},{14,15}}
  1238. }, 'lines')
  1239. test:compareImg(imgdata)
  1240. end
  1241. -- love.graphics.points
  1242. love.test.graphics.points = function(test)
  1243. local canvas = love.graphics.newCanvas(16, 16)
  1244. love.graphics.push("all")
  1245. love.graphics.setCanvas(canvas)
  1246. love.graphics.clear(0, 0, 0, 1)
  1247. love.graphics.translate(0.5, 0.5) -- draw points at the center of pixels
  1248. love.graphics.setColor(1, 0, 0, 1)
  1249. love.graphics.points(0,0,15,0,15,15,0,15,0,0)
  1250. love.graphics.setColor(1, 1, 0, 1)
  1251. love.graphics.points({1,1,7,7,14,1,7,8,14,14,8,8,1,14,8,7})
  1252. love.graphics.pop()
  1253. local imgdata = love.graphics.readbackTexture(canvas)
  1254. test:compareImg(imgdata)
  1255. end
  1256. -- love.graphics.polygon
  1257. love.test.graphics.polygon = function(test)
  1258. local canvas = love.graphics.newCanvas(16, 16)
  1259. love.graphics.setCanvas(canvas)
  1260. love.graphics.clear(0, 0, 0, 1)
  1261. love.graphics.setColor(1, 0, 0, 1)
  1262. love.graphics.polygon("fill", 1, 1, 4, 5, 8, 10, 16, 2, 7, 3, 5, 16, 16, 16, 1, 8)
  1263. love.graphics.setColor(1, 1, 0, 1)
  1264. love.graphics.polygon("line", {2, 2, 4, 5, 3, 7, 8, 15, 12, 4, 5, 10})
  1265. love.graphics.setColor(1, 1, 1, 1)
  1266. love.graphics.setCanvas()
  1267. local imgdata = love.graphics.readbackTexture(canvas)
  1268. test:assertPixels(imgdata, {
  1269. yellow = {{1,0},{1,1},{5,9},{7,14},{8,14},{12,3}},
  1270. red = {{2,1},{1,2},{1,7},{5,15},{14,15},{8,8},{14,2},{7,1}}
  1271. }, 'polygon')
  1272. test:compareImg(imgdata)
  1273. end
  1274. -- love.graphics.print
  1275. love.test.graphics.print = function(test)
  1276. love.graphics.setFont(Font)
  1277. local canvas = love.graphics.newCanvas(16, 16)
  1278. love.graphics.setCanvas(canvas)
  1279. love.graphics.clear(0, 0, 0, 1)
  1280. love.graphics.setColor(1, 0, 0, 1)
  1281. love.graphics.print('love', 0, 3, 0, 1, 1, 0, 0)
  1282. love.graphics.setColor(0, 1, 0, 1)
  1283. love.graphics.print('ooo', 0, 3, 0, 2, 2, 0, 0)
  1284. love.graphics.setColor(0, 0, 1, 1)
  1285. love.graphics.print('hello', 0, 3, 90*(math.pi/180), 1, 1, 0, 8)
  1286. love.graphics.setColor(1, 1, 1, 1)
  1287. love.graphics.setCanvas()
  1288. local imgdata = love.graphics.readbackTexture(canvas)
  1289. test:assertPixels(imgdata, {
  1290. red = {{0,0},{1,0},{1,1},{2,6},{4,4},{7,6},{10,2},{11,5},{14,3},{14,4}},
  1291. green = {
  1292. {2,1},{2,2},{0,3},{1,3},{1,8},{2,9},{7,10},{8,8},{9,4},{13,3},{14,2},
  1293. {13,8},{14,9}
  1294. },
  1295. blue = {
  1296. {4,15},{10,15},{4,12},{6,12},{8,12},{5,9},{7,9},{4,3},{10,3},{8,6},{7,7},
  1297. {4,7},{7,13},{8,12}
  1298. }
  1299. }, 'print')
  1300. test:compareImg(imgdata)
  1301. end
  1302. -- love.graphics.printf
  1303. love.test.graphics.printf = function(test)
  1304. love.graphics.setFont(Font)
  1305. local canvas = love.graphics.newCanvas(32, 32)
  1306. love.graphics.setCanvas(canvas)
  1307. love.graphics.clear(0, 0, 0, 1)
  1308. love.graphics.setColor(1, 0, 0, 1)
  1309. love.graphics.printf('love', 0, 0, 8, "left")
  1310. love.graphics.setColor(0, 1, 0, 1)
  1311. love.graphics.printf('love', 0, 5, 16, "right")
  1312. love.graphics.setColor(0, 0, 1, 1)
  1313. love.graphics.printf('love', 0, 7, 32, "center")
  1314. love.graphics.setColor(1, 1, 1, 1)
  1315. love.graphics.setCanvas()
  1316. local imgdata = love.graphics.readbackTexture(canvas)
  1317. test:assertPixels(imgdata, {
  1318. red = {
  1319. {1,0},{1,1},{0,3},{2,3},{2,7},{0,9},{3,11},{4,10},{0,15},{4,15},{2,19},
  1320. {0,24},{1,23},{3,23},{4,24},{0,26},{1,27},{2,27},{3,27}
  1321. },
  1322. green = {
  1323. {1,2},{0,8},{1,8},{2,8},{4,7},{5,8},{7,8},{8,7},{10,4},{14,4},{11,7},
  1324. {12,8},{10,13},{11,12},{13,12},{14,13},{10,15},{11,16}
  1325. },
  1326. blue = {{6,4},{6,10},{9,7},{10,6},{16,9},{18,9},{21,8},{25,8}}
  1327. }, 'printf')
  1328. test:compareImg(imgdata)
  1329. end
  1330. -- love.graphics.rectangle
  1331. love.test.graphics.rectangle = function(test)
  1332. -- setup, draw a 16x16 red rectangle with a blue central square
  1333. local canvas = love.graphics.newCanvas(16, 16)
  1334. love.graphics.setCanvas(canvas)
  1335. love.graphics.clear(0, 0, 0, 1)
  1336. love.graphics.setColor(1, 0, 0, 1)
  1337. love.graphics.rectangle('fill', 0, 0, 16, 16)
  1338. love.graphics.setColor(0, 0, 1, 1)
  1339. love.graphics.rectangle('fill', 6, 6, 4, 4)
  1340. love.graphics.setColor(1, 1, 1, 1)
  1341. love.graphics.setCanvas()
  1342. local imgdata1 = love.graphics.readbackTexture(canvas)
  1343. -- test, check red bg and blue central square
  1344. test:assertPixels(imgdata1, {
  1345. red = {{0,0},{15,0},{15,15},{0,15}},
  1346. blue = {{6,6},{9,6},{9,9},{6,9}}
  1347. }, 'fill')
  1348. -- clear canvas to do some line testing
  1349. love.graphics.setCanvas(canvas)
  1350. love.graphics.clear(0, 0, 0, 1)
  1351. love.graphics.setColor(1, 0, 0, 1)
  1352. love.graphics.rectangle('line', 1, 1, 15, 15) -- red border
  1353. love.graphics.setColor(0, 0, 1, 1)
  1354. love.graphics.rectangle('line', 1, 1, 2, 15) -- 3x16 left aligned blue outline
  1355. love.graphics.setColor(0, 1, 0, 1)
  1356. love.graphics.rectangle('line', 11, 1, 5, 15) -- 6x16 right aligned green outline
  1357. love.graphics.setColor(1, 1, 1, 1)
  1358. love.graphics.setCanvas()
  1359. local imgdata2 = love.graphics.readbackTexture(canvas)
  1360. -- -- check corners and inner corners
  1361. test:assertPixels(imgdata2, {
  1362. red = {{3,0},{9,0},{3,15,9,15}},
  1363. blue = {{0,0},{2,0},{0,15},{2,15}},
  1364. green = {{10,0},{15,0},{10,15},{15,15}},
  1365. black = {
  1366. {1,1},{1,14},{3,1},{9,1},{3,14},
  1367. {9,14},{11,1},{14,1},{11,14},{14,14}
  1368. }
  1369. }, 'line')
  1370. test:compareImg(imgdata1)
  1371. test:compareImg(imgdata2)
  1372. end
  1373. --------------------------------------------------------------------------------
  1374. --------------------------------------------------------------------------------
  1375. --------------------------------OBJECT CREATION---------------------------------
  1376. --------------------------------------------------------------------------------
  1377. --------------------------------------------------------------------------------
  1378. -- love.graphics.captureScreenshot
  1379. love.test.graphics.captureScreenshot = function(test)
  1380. love.graphics.captureScreenshot('example-screenshot.png')
  1381. test:waitFrames(10)
  1382. -- need to wait until end of the frame for the screenshot
  1383. test:assertNotNil(love.filesystem.openFile('example-screenshot.png', 'r'))
  1384. love.filesystem.remove('example-screenshot.png')
  1385. -- test callback version
  1386. love.graphics.captureScreenshot(function (idata)
  1387. test:assertNotEquals(nil, idata, 'check we have image data')
  1388. end)
  1389. test:waitFrames(10)
  1390. end
  1391. -- love.graphics.newArrayImage
  1392. -- @NOTE this is just basic nil checking, objs have their own test method
  1393. love.test.graphics.newArrayImage = function(test)
  1394. test:assertObject(love.graphics.newArrayImage({
  1395. 'resources/love.png', 'resources/love2.png', 'resources/love3.png'
  1396. }))
  1397. end
  1398. -- love.graphics.newCanvas
  1399. -- @NOTE this is just basic nil checking, objs have their own test method
  1400. love.test.graphics.newCanvas = function(test)
  1401. test:assertObject(love.graphics.newCanvas(16, 16, {
  1402. type = '2d',
  1403. format = 'normal',
  1404. readable = true,
  1405. msaa = 0,
  1406. dpiscale = 1,
  1407. mipmaps = 'none'
  1408. }))
  1409. test:assertObject(love.graphics.newCanvas(1000, 1000))
  1410. end
  1411. -- love.graphics.newCubeImage
  1412. -- @NOTE this is just basic nil checking, objs have their own test method
  1413. love.test.graphics.newCubeImage = function(test)
  1414. test:assertObject(love.graphics.newCubeImage('resources/cubemap.png', {
  1415. mipmaps = false,
  1416. linear = false
  1417. }))
  1418. end
  1419. -- love.graphics.newFont
  1420. -- @NOTE this is just basic nil checking, objs have their own test method
  1421. love.test.graphics.newFont = function(test)
  1422. test:assertObject(love.graphics.newFont('resources/font.ttf'))
  1423. test:assertObject(love.graphics.newFont('resources/font.ttf', 8, "normal", 1))
  1424. end
  1425. -- love.graphics.newImage
  1426. -- @NOTE this is just basic nil checking, objs have their own test method
  1427. love.test.graphics.newImage = function(test)
  1428. test:assertObject(love.graphics.newImage('resources/love.png', {
  1429. mipmaps = false,
  1430. linear = false,
  1431. dpiscale = 1
  1432. }))
  1433. end
  1434. -- love.graphics.newImageFont
  1435. -- @NOTE this is just basic nil checking, objs have their own test method
  1436. love.test.graphics.newImageFont = function(test)
  1437. test:assertObject(love.graphics.newImageFont('resources/love.png', 'ABCD', 1))
  1438. end
  1439. -- love.graphics.newMesh
  1440. -- @NOTE this is just basic nil checking, objs have their own test method
  1441. love.test.graphics.newMesh = function(test)
  1442. test:assertObject(love.graphics.newMesh({{1, 1, 0, 0, 1, 1, 1, 1}}, 'fan', 'dynamic'))
  1443. end
  1444. -- love.graphics.newParticleSystem
  1445. -- @NOTE this is just basic nil checking, objs have their own test method
  1446. love.test.graphics.newParticleSystem = function(test)
  1447. local imgdata = love.graphics.newImage('resources/love.png')
  1448. test:assertObject(love.graphics.newParticleSystem(imgdata, 1000))
  1449. end
  1450. -- love.graphics.newQuad
  1451. -- @NOTE this is just basic nil checking, objs have their own test method
  1452. love.test.graphics.newQuad = function(test)
  1453. local imgdata = love.graphics.newImage('resources/love.png')
  1454. test:assertObject(love.graphics.newQuad(0, 0, 16, 16, imgdata))
  1455. end
  1456. -- love.graphics.newShader
  1457. -- @NOTE this is just basic nil checking, objs have their own test method
  1458. love.test.graphics.newShader = function(test)
  1459. local pixelcode = [[
  1460. vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) {
  1461. vec4 texturecolor = Texel(tex, texture_coords);
  1462. return texturecolor * color;
  1463. }
  1464. ]]
  1465. local vertexcode = [[
  1466. vec4 position(mat4 transform_projection, vec4 vertex_position) {
  1467. return transform_projection * vertex_position;
  1468. }
  1469. ]]
  1470. test:assertObject(love.graphics.newShader(pixelcode, vertexcode))
  1471. end
  1472. -- love.graphics.newSpriteBatch
  1473. -- @NOTE this is just basic nil checking, objs have their own test method
  1474. love.test.graphics.newSpriteBatch = function(test)
  1475. local imgdata = love.graphics.newImage('resources/love.png')
  1476. test:assertObject(love.graphics.newSpriteBatch(imgdata, 1000))
  1477. end
  1478. -- love.graphics.newText
  1479. -- @NOTE this is just basic nil checking, objs have their own test method
  1480. love.test.graphics.newTextBatch = function(test)
  1481. local font = love.graphics.newFont('resources/font.ttf')
  1482. test:assertObject(love.graphics.newTextBatch(font, 'helloworld'))
  1483. end
  1484. -- love.graphics.newVideo
  1485. -- @NOTE this is just basic nil checking, objs have their own test method
  1486. love.test.graphics.newVideo = function(test)
  1487. test:assertObject(love.graphics.newVideo('resources/sample.ogv', {
  1488. audio = false,
  1489. dpiscale = 1
  1490. }))
  1491. end
  1492. -- love.graphics.newVolumeImage
  1493. -- @NOTE this is just basic nil checking, objs have their own test method
  1494. love.test.graphics.newVolumeImage = function(test)
  1495. test:assertObject(love.graphics.newVolumeImage({
  1496. 'resources/love.png', 'resources/love2.png', 'resources/love3.png'
  1497. }, {
  1498. mipmaps = false,
  1499. linear = false
  1500. }))
  1501. end
  1502. -- love.graphics.validateShader
  1503. love.test.graphics.validateShader = function(test)
  1504. local pixelcode = [[
  1505. vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) {
  1506. vec4 texturecolor = Texel(tex, texture_coords);
  1507. return texturecolor * color;
  1508. }
  1509. ]]
  1510. local vertexcode = [[
  1511. vec4 position(mat4 transform_projection, vec4 vertex_position) {
  1512. return transform_projection * vertex_position;
  1513. }
  1514. ]]
  1515. -- check made up code first
  1516. local status, _ = love.graphics.validateShader(true, 'nothing here', 'or here')
  1517. test:assertFalse(status, 'check invalid shader code')
  1518. -- check real code
  1519. status, _ = love.graphics.validateShader(true, pixelcode, vertexcode)
  1520. test:assertTrue(status, 'check valid shader code')
  1521. end
  1522. --------------------------------------------------------------------------------
  1523. --------------------------------------------------------------------------------
  1524. ---------------------------------GRAPHICS STATE---------------------------------
  1525. --------------------------------------------------------------------------------
  1526. --------------------------------------------------------------------------------
  1527. -- love.graphics.getBackgroundColor
  1528. love.test.graphics.getBackgroundColor = function(test)
  1529. -- check default bg is black
  1530. local r, g, b, a = love.graphics.getBackgroundColor()
  1531. test:assertEquals(0, r, 'check default background r')
  1532. test:assertEquals(0, g, 'check default background g')
  1533. test:assertEquals(0, b, 'check default background b')
  1534. test:assertEquals(1, a, 'check default background a')
  1535. -- check set value returns correctly
  1536. love.graphics.setBackgroundColor(1, 1, 1, 0)
  1537. r, g, b, a = love.graphics.getBackgroundColor()
  1538. test:assertEquals(1, r, 'check updated background r')
  1539. test:assertEquals(1, g, 'check updated background g')
  1540. test:assertEquals(1, b, 'check updated background b')
  1541. test:assertEquals(0, a, 'check updated background a')
  1542. love.graphics.setBackgroundColor(0, 0, 0, 1) -- reset
  1543. end
  1544. -- love.graphics.getBlendMode
  1545. love.test.graphics.getBlendMode = function(test)
  1546. -- check default blend mode
  1547. local mode, alphamode = love.graphics.getBlendMode()
  1548. test:assertEquals('alpha', mode, 'check default blend mode')
  1549. test:assertEquals('alphamultiply', alphamode, 'check default alpha blend')
  1550. -- check set mode returns correctly
  1551. love.graphics.setBlendMode('add', 'premultiplied')
  1552. mode, alphamode = love.graphics.getBlendMode()
  1553. test:assertEquals('add', mode, 'check changed blend mode')
  1554. test:assertEquals('premultiplied', alphamode, 'check changed alpha blend')
  1555. love.graphics.setBlendMode('alpha', 'alphamultiply') -- reset
  1556. end
  1557. -- love.graphics.getCanvas
  1558. love.test.graphics.getCanvas = function(test)
  1559. -- by default should be nil if drawing to real screen
  1560. test:assertEquals(nil, love.graphics.getCanvas(), 'check no canvas set')
  1561. -- should return not nil when we target a canvas
  1562. local canvas = love.graphics.newCanvas(16, 16)
  1563. love.graphics.setCanvas(canvas)
  1564. test:assertObject(love.graphics.getCanvas())
  1565. love.graphics.setCanvas()
  1566. end
  1567. -- love.graphics.getColor
  1568. love.test.graphics.getColor = function(test)
  1569. -- by default should be white
  1570. local r, g, b, a = love.graphics.getColor()
  1571. test:assertEquals(1, r, 'check default color r')
  1572. test:assertEquals(1, g, 'check default color g')
  1573. test:assertEquals(1, b, 'check default color b')
  1574. test:assertEquals(1, a, 'check default color a')
  1575. -- check set color is returned correctly
  1576. love.graphics.setColor(0, 0, 0, 0)
  1577. r, g, b, a = love.graphics.getColor()
  1578. test:assertEquals(0, r, 'check changed color r')
  1579. test:assertEquals(0, g, 'check changed color g')
  1580. test:assertEquals(0, b, 'check changed color b')
  1581. test:assertEquals(0, a, 'check changed color a')
  1582. love.graphics.setColor(1, 1, 1, 1) -- reset
  1583. end
  1584. -- love.graphics.getColorMask
  1585. love.test.graphics.getColorMask = function(test)
  1586. -- by default should all be active
  1587. local r, g, b, a = love.graphics.getColorMask()
  1588. test:assertTrue(r, 'check default color mask r')
  1589. test:assertTrue(g, 'check default color mask g')
  1590. test:assertTrue(b, 'check default color mask b')
  1591. test:assertTrue(a, 'check default color mask a')
  1592. -- check set color mask is returned correctly
  1593. love.graphics.setColorMask(false, false, true, false)
  1594. r, g, b, a = love.graphics.getColorMask()
  1595. test:assertFalse(r, 'check changed color mask r')
  1596. test:assertFalse(g, 'check changed color mask g')
  1597. test:assertTrue( b, 'check changed color mask b')
  1598. test:assertFalse(a, 'check changed color mask a')
  1599. love.graphics.setColorMask(true, true, true, true) -- reset
  1600. end
  1601. -- love.graphics.getDefaultFilter
  1602. love.test.graphics.getDefaultFilter = function(test)
  1603. -- we set this already for testsuite so we know what it should be
  1604. local min, mag, anisotropy = love.graphics.getDefaultFilter()
  1605. test:assertEquals('nearest', min, 'check default filter min')
  1606. test:assertEquals('nearest', mag, 'check default filter mag')
  1607. test:assertEquals(1, anisotropy, 'check default filter mag')
  1608. end
  1609. -- love.graphics.getDepthMode
  1610. love.test.graphics.getDepthMode = function(test)
  1611. -- by default should be always/write
  1612. local comparemode, write = love.graphics.getDepthMode()
  1613. test:assertEquals('always', comparemode, 'check default compare depth')
  1614. test:assertFalse(write, 'check default depth buffer write')
  1615. end
  1616. -- love.graphics.getFont
  1617. love.test.graphics.getFont = function(test)
  1618. test:assertObject(love.graphics.getFont())
  1619. end
  1620. -- love.graphics.getFrontFaceWinding
  1621. love.test.graphics.getFrontFaceWinding = function(test)
  1622. -- check default winding
  1623. test:assertEquals('ccw', love.graphics.getFrontFaceWinding())
  1624. -- check setting value changes it correctly
  1625. love.graphics.setFrontFaceWinding('cw')
  1626. test:assertEquals('cw', love.graphics.getFrontFaceWinding())
  1627. love.graphics.setFrontFaceWinding('ccw') -- reset
  1628. end
  1629. -- love.graphics.getLineJoin
  1630. love.test.graphics.getLineJoin = function(test)
  1631. -- check default line join
  1632. test:assertEquals('miter', love.graphics.getLineJoin())
  1633. -- check set value returned correctly
  1634. love.graphics.setLineJoin('none')
  1635. test:assertEquals('none', love.graphics.getLineJoin())
  1636. love.graphics.setLineJoin('miter') -- reset
  1637. end
  1638. -- love.graphics.getLineStyle
  1639. love.test.graphics.getLineStyle = function(test)
  1640. -- we know this should be as testsuite sets it!
  1641. test:assertEquals('rough', love.graphics.getLineStyle())
  1642. -- check set value returned correctly
  1643. love.graphics.setLineStyle('smooth')
  1644. test:assertEquals('smooth', love.graphics.getLineStyle())
  1645. love.graphics.setLineStyle('rough') -- reset
  1646. end
  1647. -- love.graphics.getLineWidth
  1648. love.test.graphics.getLineWidth = function(test)
  1649. -- we know this should be as testsuite sets it!
  1650. test:assertEquals(1, love.graphics.getLineWidth())
  1651. -- check set value returned correctly
  1652. love.graphics.setLineWidth(10)
  1653. test:assertEquals(10, love.graphics.getLineWidth())
  1654. love.graphics.setLineWidth(1) -- reset
  1655. end
  1656. -- love.graphics.getMeshCullMode
  1657. love.test.graphics.getMeshCullMode = function(test)
  1658. -- get default mesh culling
  1659. test:assertEquals('none', love.graphics.getMeshCullMode())
  1660. -- check set value returned correctly
  1661. love.graphics.setMeshCullMode('front')
  1662. test:assertEquals('front', love.graphics.getMeshCullMode())
  1663. love.graphics.setMeshCullMode('back') -- reset
  1664. end
  1665. -- love.graphics.getPointSize
  1666. love.test.graphics.getPointSize = function(test)
  1667. -- get default point size
  1668. test:assertEquals(1, love.graphics.getPointSize())
  1669. -- check set value returned correctly
  1670. love.graphics.setPointSize(10)
  1671. test:assertEquals(10, love.graphics.getPointSize())
  1672. love.graphics.setPointSize(1) -- reset
  1673. end
  1674. -- love.graphics.getScissor
  1675. love.test.graphics.getScissor = function(test)
  1676. -- should be no scissor atm
  1677. local x, y, w, h = love.graphics.getScissor()
  1678. test:assertEquals(nil, x, 'check no scissor')
  1679. test:assertEquals(nil, y, 'check no scissor')
  1680. test:assertEquals(nil, w, 'check no scissor')
  1681. test:assertEquals(nil, h, 'check no scissor')
  1682. -- check set value returned correctly
  1683. love.graphics.setScissor(0, 0, 16, 16)
  1684. x, y, w, h = love.graphics.getScissor()
  1685. test:assertEquals(0, x, 'check scissor set')
  1686. test:assertEquals(0, y, 'check scissor set')
  1687. test:assertEquals(16, w, 'check scissor set')
  1688. test:assertEquals(16, h, 'check scissor set')
  1689. love.graphics.setScissor() -- reset
  1690. end
  1691. -- love.graphics.getShader
  1692. love.test.graphics.getShader = function(test)
  1693. -- should be no shader active
  1694. test:assertEquals(nil, love.graphics.getShader(), 'check no active shader')
  1695. end
  1696. -- love.graphics.getStackDepth
  1697. love.test.graphics.getStackDepth = function(test)
  1698. -- by default should be none
  1699. test:assertEquals(0, love.graphics.getStackDepth(), 'check no transforms in stack')
  1700. -- now add 3
  1701. love.graphics.push()
  1702. love.graphics.push()
  1703. love.graphics.push()
  1704. test:assertEquals(3, love.graphics.getStackDepth(), 'check 3 transforms in stack')
  1705. -- now remove 2
  1706. love.graphics.pop()
  1707. love.graphics.pop()
  1708. test:assertEquals(1, love.graphics.getStackDepth(), 'check 1 transforms in stack')
  1709. -- now back to 0
  1710. love.graphics.pop()
  1711. test:assertEquals(0, love.graphics.getStackDepth(), 'check no transforms in stack')
  1712. end
  1713. -- love.graphics.getStencilState
  1714. love.test.graphics.getStencilState = function(test)
  1715. -- check default vals
  1716. local action, comparemode, value = love.graphics.getStencilState( )
  1717. test:assertEquals('keep', action, 'check default stencil action')
  1718. test:assertEquals('always', comparemode, 'check default stencil compare')
  1719. test:assertEquals(0, value, 'check default stencil value')
  1720. -- check set stencil values is returned
  1721. love.graphics.setStencilState('replace', 'less', 255)
  1722. local action, comparemode, value = love.graphics.getStencilState()
  1723. test:assertEquals('replace', action, 'check changed stencil action')
  1724. test:assertEquals('less', comparemode, 'check changed stencil compare')
  1725. test:assertEquals(255, value, 'check changed stencil value')
  1726. love.graphics.setStencilState() -- reset
  1727. end
  1728. -- love.graphics.intersectScissor
  1729. love.test.graphics.intersectScissor = function(test)
  1730. -- make a scissor for the left half, then interset to make the top half
  1731. -- then we should be able to fill the canvas with red and only top 4x4 is filled
  1732. local canvas = love.graphics.newCanvas(16, 16)
  1733. love.graphics.setCanvas(canvas)
  1734. love.graphics.clear(0, 0, 0, 1)
  1735. love.graphics.origin()
  1736. love.graphics.setScissor(0, 0, 8, 16)
  1737. love.graphics.intersectScissor(0, 0, 4, 4)
  1738. love.graphics.setColor(1, 0, 0, 1)
  1739. love.graphics.rectangle('fill', 0, 0, 16, 16)
  1740. love.graphics.setColor(1, 1, 1, 1)
  1741. love.graphics.setScissor()
  1742. love.graphics.setCanvas()
  1743. local imgdata = love.graphics.readbackTexture(canvas)
  1744. test:assertPixels(imgdata, {
  1745. red = {{0,0},{3,3}},
  1746. black ={{4,0},{0,4},{4,4}}
  1747. }, 'intersect scissor')
  1748. test:compareImg(imgdata)
  1749. end
  1750. -- love.graphics.isActive
  1751. love.test.graphics.isActive = function(test)
  1752. local name, version, vendor, device = love.graphics.getRendererInfo()
  1753. if string.find(name, 'Vulkan') ~= nil then
  1754. test:skipTest('love.graphics.isActive() crashes on Vulkan')
  1755. else
  1756. test:assertTrue(love.graphics.isActive(), 'check graphics is active') -- i mean if you got this far
  1757. end
  1758. end
  1759. -- love.graphics.isGammaCorrect
  1760. love.test.graphics.isGammaCorrect = function(test)
  1761. -- we know the config so know this is false
  1762. test:assertNotNil(love.graphics.isGammaCorrect())
  1763. end
  1764. -- love.graphics.isWireframe
  1765. love.test.graphics.isWireframe = function(test)
  1766. local name, version, vendor, device = love.graphics.getRendererInfo()
  1767. if string.match(name, 'OpenGL ES') then
  1768. test:skipTest('Wireframe not supported on OpenGL ES')
  1769. else
  1770. -- check off by default
  1771. test:assertFalse(love.graphics.isWireframe(), 'check no wireframe by default')
  1772. -- check on when enabled
  1773. love.graphics.setWireframe(true)
  1774. test:assertTrue(love.graphics.isWireframe(), 'check wireframe is set')
  1775. love.graphics.setWireframe(false) -- reset
  1776. end
  1777. end
  1778. -- love.graphics.reset
  1779. love.test.graphics.reset = function(test)
  1780. -- reset should reset current canvas and any colors/scissor
  1781. local canvas = love.graphics.newCanvas(16, 16)
  1782. love.graphics.setBackgroundColor(0, 0, 1, 1)
  1783. love.graphics.setColor(0, 1, 0, 1)
  1784. love.graphics.setCanvas(canvas)
  1785. love.graphics.reset()
  1786. local r, g, b, a = love.graphics.getBackgroundColor()
  1787. test:assertEquals(1, r+g+b+a, 'check background reset')
  1788. r, g, b, a = love.graphics.getColor()
  1789. test:assertEquals(4, r+g+b+a, 'check color reset')
  1790. test:assertEquals(nil, love.graphics.getCanvas(), 'check canvas reset')
  1791. love.graphics.setDefaultFilter("nearest", "nearest")
  1792. love.graphics.setLineStyle('rough')
  1793. love.graphics.setPointSize(1)
  1794. love.graphics.setLineWidth(1)
  1795. end
  1796. -- love.graphics.setBackgroundColor
  1797. love.test.graphics.setBackgroundColor = function(test)
  1798. -- check background is set
  1799. love.graphics.setBackgroundColor(1, 0, 0, 1)
  1800. local r, g, b, a = love.graphics.getBackgroundColor()
  1801. test:assertEquals(1, r, 'check set bg r')
  1802. test:assertEquals(0, g, 'check set bg g')
  1803. test:assertEquals(0, b, 'check set bg b')
  1804. test:assertEquals(1, a, 'check set bg a')
  1805. love.graphics.setBackgroundColor(0, 0, 0, 1)
  1806. end
  1807. -- love.graphics.setBlendMode
  1808. love.test.graphics.setBlendMode = function(test)
  1809. -- create fully white canvas, then draw diff. pixels through blendmodes
  1810. local canvas = love.graphics.newCanvas(16, 16)
  1811. love.graphics.setCanvas(canvas)
  1812. love.graphics.clear(0.5, 0.5, 0.5, 1)
  1813. love.graphics.setBlendMode('add', 'alphamultiply')
  1814. love.graphics.setColor(1, 0, 0, 1)
  1815. love.graphics.rectangle('fill', 0, 0, 1, 1)
  1816. love.graphics.setBlendMode('subtract', 'alphamultiply')
  1817. love.graphics.setColor(1, 1, 1, 0.5)
  1818. love.graphics.rectangle('fill', 15, 0, 1, 1)
  1819. love.graphics.setBlendMode('multiply', 'premultiplied')
  1820. love.graphics.setColor(0, 1, 0, 1)
  1821. love.graphics.rectangle('fill', 15, 15, 1, 1)
  1822. love.graphics.setBlendMode('replace', 'premultiplied')
  1823. love.graphics.setColor(0, 0, 1, 0.5)
  1824. love.graphics.rectangle('fill', 0, 15, 1, 1)
  1825. love.graphics.setColor(1, 1, 1, 1)
  1826. love.graphics.setCanvas()
  1827. local imgdata = love.graphics.readbackTexture(canvas)
  1828. -- check the 4 corners
  1829. test:assertPixels(imgdata, {
  1830. redpale = {{0,0}},
  1831. black = {{15,0}},
  1832. greenhalf = {{15,15}},
  1833. bluefade = {{0,15}}
  1834. }, 'blend mode')
  1835. love.graphics.setBlendMode('alpha', 'alphamultiply') -- reset
  1836. -- need 1rgba tolerance here on some machines
  1837. test.rgba_tolerance = 1
  1838. test:compareImg(imgdata)
  1839. end
  1840. -- love.graphics.setCanvas
  1841. love.test.graphics.setCanvas = function(test)
  1842. -- make 2 canvas, set to each, draw one to the other, check output
  1843. local canvas1 = love.graphics.newCanvas(16, 16)
  1844. local canvas2 = love.graphics.newCanvas(16, 16)
  1845. love.graphics.setCanvas(canvas1)
  1846. test:assertEquals(canvas1, love.graphics.getCanvas(), 'check canvas 1 set')
  1847. love.graphics.clear(1, 0, 0, 1)
  1848. love.graphics.setCanvas(canvas2)
  1849. test:assertEquals(canvas2, love.graphics.getCanvas(), 'check canvas 2 set')
  1850. love.graphics.clear(0, 0, 0, 1)
  1851. love.graphics.draw(canvas1, 0, 0)
  1852. love.graphics.setCanvas()
  1853. test:assertEquals(nil, love.graphics.getCanvas(), 'check no canvas set')
  1854. local imgdata = love.graphics.readbackTexture(canvas2)
  1855. -- check 2nd canvas is red
  1856. test:assertPixels(imgdata, {
  1857. red = {{0,0},{15,0},{15,15},{0,15}}
  1858. }, 'set canvas')
  1859. test:compareImg(imgdata)
  1860. end
  1861. -- love.graphics.setColor
  1862. love.test.graphics.setColor = function(test)
  1863. -- set colors, draw rect, check color
  1864. local canvas = love.graphics.newCanvas(16, 16)
  1865. love.graphics.setCanvas(canvas)
  1866. love.graphics.clear(0, 0, 0, 1)
  1867. love.graphics.setColor(1, 0, 0, 1)
  1868. local r, g, b, a = love.graphics.getColor()
  1869. test:assertEquals(1, r, 'check r set')
  1870. test:assertEquals(0, g, 'check g set')
  1871. test:assertEquals(0, b, 'check b set')
  1872. test:assertEquals(1, a, 'check a set')
  1873. love.graphics.rectangle('fill', 0, 0, 16, 1)
  1874. love.graphics.setColor(1, 1, 0, 1)
  1875. love.graphics.rectangle('fill', 0, 1, 16, 1)
  1876. love.graphics.setColor(0, 1, 0, 0.5)
  1877. love.graphics.rectangle('fill', 0, 2, 16, 1)
  1878. love.graphics.setColor(0, 0, 1, 1)
  1879. love.graphics.rectangle('fill', 0, 3, 16, 1)
  1880. love.graphics.setColor(1, 1, 1, 1)
  1881. love.graphics.setCanvas()
  1882. local imgdata = love.graphics.readbackTexture(canvas)
  1883. test:assertPixels(imgdata, {
  1884. red = {{0,0},{5,0},{10,0},{15,0}},
  1885. yellow = {{0,1},{5,1},{10,1},{15,1}},
  1886. greenhalf = {{0,2},{5,2},{10,2},{15,2}},
  1887. blue = {{0,3},{5,3},{10,3},{15,3}}
  1888. }, 'set color')
  1889. test:compareImg(imgdata)
  1890. end
  1891. -- love.graphics.setColorMask
  1892. love.test.graphics.setColorMask = function(test)
  1893. -- set mask, draw stuff, check output pixels
  1894. local canvas = love.graphics.newCanvas(16, 16)
  1895. love.graphics.setCanvas(canvas)
  1896. love.graphics.clear(0, 0, 0, 1)
  1897. -- mask off blue
  1898. love.graphics.setColorMask(true, true, false, true)
  1899. local r, g, b, a = love.graphics.getColorMask()
  1900. test:assertEquals(r, true, 'check r mask')
  1901. test:assertEquals(g, true, 'check g mask')
  1902. test:assertEquals(b, false, 'check b mask')
  1903. test:assertEquals(a, true, 'check a mask')
  1904. -- draw "black" which should then turn to yellow
  1905. love.graphics.setColor(1, 1, 1, 1)
  1906. love.graphics.rectangle('fill', 0, 0, 16, 16)
  1907. love.graphics.setColorMask(true, true, true, true)
  1908. love.graphics.setCanvas()
  1909. local imgdata = love.graphics.readbackTexture(canvas)
  1910. test:assertPixels(imgdata, {
  1911. yellow = {{0,0},{0,15},{15,15},{15,0}}
  1912. }, 'set color mask')
  1913. test:compareImg(imgdata)
  1914. end
  1915. -- love.graphics.setDefaultFilter
  1916. love.test.graphics.setDefaultFilter = function(test)
  1917. -- check setting filter val works
  1918. love.graphics.setDefaultFilter('linear', 'linear', 1)
  1919. local min, mag, anisotropy = love.graphics.getDefaultFilter()
  1920. test:assertEquals('linear', min, 'check default filter min')
  1921. test:assertEquals('linear', mag, 'check default filter mag')
  1922. test:assertEquals(1, anisotropy, 'check default filter mag')
  1923. love.graphics.setDefaultFilter('nearest', 'nearest', 1) -- reset
  1924. end
  1925. -- love.graphics.setDepthMode
  1926. love.test.graphics.setDepthMode = function(test)
  1927. -- check documented modes are valid
  1928. local comparemode, write = love.graphics.getDepthMode()
  1929. local modes = {
  1930. 'equal', 'notequal', 'less', 'lequal', 'gequal',
  1931. 'greater', 'never', 'always'
  1932. }
  1933. for m=1,#modes do
  1934. love.graphics.setDepthMode(modes[m], true)
  1935. test:assertEquals(modes[m], love.graphics.getDepthMode(), 'check depth mode ' .. modes[m] .. ' set')
  1936. end
  1937. love.graphics.setDepthMode(comparemode, write)
  1938. -- @TODO better graphics drawing specific test
  1939. end
  1940. -- love.graphics.setFont
  1941. love.test.graphics.setFont = function(test)
  1942. -- set font doesnt return anything so draw with the test font
  1943. local canvas = love.graphics.newCanvas(16, 16)
  1944. love.graphics.setFont(Font)
  1945. love.graphics.setCanvas(canvas)
  1946. love.graphics.clear(0, 0, 0, 1)
  1947. love.graphics.setColor(1, 0, 0, 1)
  1948. love.graphics.print('love', 0, 3)
  1949. love.graphics.setColor(1, 1, 1, 1)
  1950. love.graphics.setCanvas()
  1951. local imgdata = love.graphics.readbackTexture(canvas)
  1952. test:assertPixels(imgdata, {
  1953. red = {
  1954. {0,0},{0,6},{2,6},{6,2},
  1955. {4,4},{8,4},{6,6},{10,2},
  1956. {14,2},{12,6}
  1957. }
  1958. }, 'set font for print')
  1959. test:compareImg(imgdata)
  1960. end
  1961. -- love.graphics.setFrontFaceWinding
  1962. love.test.graphics.setFrontFaceWinding = function(test)
  1963. -- check documented modes are valid
  1964. local original = love.graphics.getFrontFaceWinding()
  1965. love.graphics.setFrontFaceWinding('cw')
  1966. test:assertEquals('cw', love.graphics.getFrontFaceWinding(), 'check ffw cw set')
  1967. love.graphics.setFrontFaceWinding('ccw')
  1968. test:assertEquals('ccw', love.graphics.getFrontFaceWinding(), 'check ffw ccw set')
  1969. love.graphics.setFrontFaceWinding(original)
  1970. -- @TODO better graphics drawing specific test
  1971. end
  1972. -- love.graphics.setLineJoin
  1973. love.test.graphics.setLineJoin = function(test)
  1974. local canvas = love.graphics.newCanvas(16, 16)
  1975. love.graphics.setFont(Font)
  1976. love.graphics.setCanvas(canvas)
  1977. love.graphics.clear(0, 0, 0, 1)
  1978. local line = {0,1,8,1,8,8}
  1979. love.graphics.setLineStyle('rough')
  1980. love.graphics.setLineWidth(2)
  1981. love.graphics.setColor(1, 0, 0)
  1982. love.graphics.setLineJoin('bevel')
  1983. love.graphics.line(line)
  1984. love.graphics.translate(0, 4)
  1985. love.graphics.setColor(1, 1, 0)
  1986. love.graphics.setLineJoin('none')
  1987. love.graphics.line(line)
  1988. love.graphics.translate(0, 4)
  1989. love.graphics.setColor(0, 0, 1)
  1990. love.graphics.setLineJoin('miter')
  1991. love.graphics.line(line)
  1992. love.graphics.setColor(1, 1, 1)
  1993. love.graphics.setLineWidth(1)
  1994. love.graphics.origin()
  1995. love.graphics.setCanvas()
  1996. local imgdata = love.graphics.readbackTexture(canvas)
  1997. test:assertPixels(imgdata, {
  1998. black = {{8,0}},
  1999. red = {{8,4}},
  2000. yellow = {{8,7}},
  2001. blue = {{8,8}}
  2002. }, 'set line join')
  2003. test:compareImg(imgdata)
  2004. end
  2005. -- love.graphics.setLineStyle
  2006. love.test.graphics.setLineStyle = function(test)
  2007. local canvas = love.graphics.newCanvas(16, 16)
  2008. love.graphics.setFont(Font)
  2009. love.graphics.setCanvas(canvas)
  2010. love.graphics.clear(0, 0, 0, 1)
  2011. love.graphics.setColor(1, 0, 0)
  2012. local line = {0,1,16,1}
  2013. love.graphics.setLineStyle('rough')
  2014. love.graphics.line(line)
  2015. love.graphics.translate(0, 4)
  2016. love.graphics.setLineStyle('smooth')
  2017. love.graphics.line(line)
  2018. love.graphics.setLineStyle('rough')
  2019. love.graphics.setColor(1, 1, 1)
  2020. love.graphics.origin()
  2021. love.graphics.setCanvas()
  2022. local imgdata = love.graphics.readbackTexture(canvas)
  2023. test:assertPixels(imgdata, {
  2024. red = {{0,0},{7,0},{15,0}},
  2025. red07 = {{0,4},{7,4},{15,4}}
  2026. }, 'set line style')
  2027. -- linux runner needs a 1/255 tolerance for the blend between a rough line + bg
  2028. if GITHUB_RUNNER and love.system.getOS() == 'Linux' then
  2029. test.rgba_tolerance = 1
  2030. end
  2031. test:compareImg(imgdata)
  2032. end
  2033. -- love.graphics.setLineWidth
  2034. love.test.graphics.setLineWidth = function(test)
  2035. local canvas = love.graphics.newCanvas(16, 16)
  2036. love.graphics.setFont(Font)
  2037. love.graphics.setCanvas(canvas)
  2038. love.graphics.clear(0, 0, 0, 1)
  2039. local line = {0,1,8,1,8,8}
  2040. love.graphics.setColor(1, 0, 0)
  2041. love.graphics.setLineWidth(2)
  2042. love.graphics.line(line)
  2043. love.graphics.translate(0, 4)
  2044. love.graphics.setColor(1, 1, 0)
  2045. love.graphics.setLineWidth(3)
  2046. love.graphics.line(line)
  2047. love.graphics.translate(0, 4)
  2048. love.graphics.setColor(0, 0, 1)
  2049. love.graphics.setLineWidth(4)
  2050. love.graphics.line(line)
  2051. love.graphics.setColor(1, 1, 1)
  2052. love.graphics.setLineWidth(1)
  2053. love.graphics.origin()
  2054. love.graphics.setCanvas()
  2055. local imgdata = love.graphics.readbackTexture(canvas)
  2056. test:assertPixels(imgdata, {
  2057. black = {{0,2},{6,2},{0,6},{5,6},{0,11},{5,11}},
  2058. red = {{0,0},{0,1},{7,2},{8,2}},
  2059. yellow = {{0,3},{0,5},{6,6},{8,6}},
  2060. blue = {{0,7},{0,10},{6,15},{9,15}}
  2061. }, 'set line width')
  2062. test:compareImg(imgdata)
  2063. end
  2064. -- love.graphics.setMeshCullMode
  2065. love.test.graphics.setMeshCullMode = function(test)
  2066. -- check documented modes are valid
  2067. local original = love.graphics.getMeshCullMode()
  2068. local modes = {'back', 'front', 'none'}
  2069. for m=1,#modes do
  2070. love.graphics.setMeshCullMode(modes[m])
  2071. test:assertEquals(modes[m], love.graphics.getMeshCullMode(), 'check mesh cull mode ' .. modes[m] .. ' was set')
  2072. end
  2073. love.graphics.setMeshCullMode(original)
  2074. -- @TODO better graphics drawing specific test
  2075. end
  2076. -- love.graphics.setScissor
  2077. love.test.graphics.setScissor = function(test)
  2078. -- make a scissor for the left half
  2079. -- then we should be able to fill the canvas with red and only left is filled
  2080. local canvas = love.graphics.newCanvas(16, 16)
  2081. love.graphics.setCanvas(canvas)
  2082. love.graphics.clear(0, 0, 0, 1)
  2083. love.graphics.origin()
  2084. love.graphics.setScissor(0, 0, 8, 16)
  2085. love.graphics.setColor(1, 0, 0, 1)
  2086. love.graphics.rectangle('fill', 0, 0, 16, 16)
  2087. love.graphics.setColor(1, 1, 1, 1)
  2088. love.graphics.setScissor()
  2089. love.graphics.setCanvas()
  2090. local imgdata = love.graphics.readbackTexture(canvas)
  2091. test:assertPixels(imgdata, {
  2092. red = {{0,0},{7,0},{0,15},{7,15}},
  2093. black ={{8,0},{8,15},{15,0},{15,15}}
  2094. }, 'set scissor')
  2095. test:compareImg(imgdata)
  2096. end
  2097. -- love.graphics.setShader
  2098. love.test.graphics.setShader = function(test)
  2099. -- make a shader that will only ever draw yellow
  2100. local pixelcode = [[
  2101. vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) {
  2102. vec4 texturecolor = Texel(tex, texture_coords);
  2103. return vec4(1.0,1.0,0.0,1.0);
  2104. }
  2105. ]]
  2106. local vertexcode = [[
  2107. vec4 position(mat4 transform_projection, vec4 vertex_position) {
  2108. return transform_projection * vertex_position;
  2109. }
  2110. ]]
  2111. local shader = love.graphics.newShader(pixelcode, vertexcode)
  2112. local canvas = love.graphics.newCanvas(16, 16)
  2113. love.graphics.setCanvas(canvas)
  2114. love.graphics.clear(0, 0, 0, 1)
  2115. love.graphics.setShader(shader)
  2116. -- draw red rectangle
  2117. love.graphics.setColor(1, 0, 0, 1)
  2118. love.graphics.rectangle('fill', 0, 0, 16, 16)
  2119. love.graphics.setShader()
  2120. love.graphics.setColor(1, 1, 1, 1)
  2121. love.graphics.setCanvas()
  2122. local imgdata = love.graphics.readbackTexture(canvas)
  2123. test:assertPixels(imgdata, {
  2124. yellow = {{0,0},{15,0},{0,15},{15,15}},
  2125. }, 'check shader set to yellow')
  2126. test:compareImg(imgdata)
  2127. end
  2128. -- love.graphics.setStencilState
  2129. love.test.graphics.setStencilState = function(test)
  2130. local canvas = love.graphics.newCanvas(16, 16)
  2131. love.graphics.setCanvas({canvas, stencil=true})
  2132. love.graphics.clear(0, 0, 0, 1)
  2133. love.graphics.setStencilState('replace', 'always', 1)
  2134. love.graphics.circle('fill', 8, 8, 6)
  2135. love.graphics.setStencilState('keep', 'greater', 0)
  2136. love.graphics.setColor(1, 0, 0, 1)
  2137. love.graphics.rectangle('fill', 0, 0, 16, 16)
  2138. love.graphics.setColor(1, 1, 1, 1)
  2139. love.graphics.setStencilState()
  2140. love.graphics.setCanvas()
  2141. local imgdata = love.graphics.readbackTexture(canvas)
  2142. test:assertPixels(imgdata, {
  2143. red = {{6,2},{9,2},{2,6},{2,9},{13,6},{9,6},{6,13},{9,13}}
  2144. }, 'check stencil test')
  2145. test:compareImg(imgdata)
  2146. end
  2147. -- love.graphics.setWireframe
  2148. love.test.graphics.setWireframe = function(test)
  2149. local name, version, vendor, device = love.graphics.getRendererInfo()
  2150. if string.match(name, 'OpenGL ES') then
  2151. test:skipTest('Wireframe not supported on OpenGL ES')
  2152. else
  2153. -- check wireframe outlines
  2154. love.graphics.setWireframe(true)
  2155. local canvas = love.graphics.newCanvas(16, 16)
  2156. love.graphics.setCanvas(canvas)
  2157. love.graphics.clear(0, 0, 0, 1)
  2158. love.graphics.setColor(1, 1, 0, 1)
  2159. love.graphics.rectangle('fill', 2, 2, 13, 13)
  2160. love.graphics.setColor(1, 1, 1, 1)
  2161. love.graphics.setCanvas()
  2162. love.graphics.setWireframe(false)
  2163. local imgdata = love.graphics.readbackTexture(canvas)
  2164. -- on macOS runners wireframes are drawn 1px off from the target
  2165. if GITHUB_RUNNER and love.system.getOS() == 'OS X' then
  2166. test.pixel_tolerance = 1
  2167. end
  2168. test:compareImg(imgdata)
  2169. end
  2170. end
  2171. --------------------------------------------------------------------------------
  2172. --------------------------------------------------------------------------------
  2173. -------------------------------COORDINATE SYSTEM--------------------------------
  2174. --------------------------------------------------------------------------------
  2175. --------------------------------------------------------------------------------
  2176. -- love.graphics.applyTransform
  2177. love.test.graphics.applyTransform = function(test)
  2178. -- use transform object to translate the drawn rectangle
  2179. local transform = love.math.newTransform()
  2180. transform:translate(10, 0)
  2181. local canvas = love.graphics.newCanvas(16, 16)
  2182. love.graphics.setCanvas(canvas)
  2183. love.graphics.clear(0, 0, 0, 1)
  2184. love.graphics.setColor(1, 0, 0, 1)
  2185. love.graphics.applyTransform(transform)
  2186. love.graphics.rectangle('fill', 0, 0, 1, 1)
  2187. love.graphics.setColor(1, 1, 1, 1)
  2188. love.graphics.setCanvas()
  2189. local imgdata = love.graphics.readbackTexture(canvas)
  2190. test:assertPixels(imgdata, { red = {{10, 0}} }, 'apply transform 10')
  2191. test:compareImg(imgdata)
  2192. end
  2193. -- love.graphics.inverseTransformPoint
  2194. love.test.graphics.inverseTransformPoint = function(test)
  2195. -- start with 0, 0
  2196. local sx, sy = love.graphics.inverseTransformPoint(0, 0)
  2197. test:assertEquals(0, sx, 'check starting x is 0')
  2198. test:assertEquals(0, sy, 'check starting y is 0')
  2199. -- check translation effects the point
  2200. love.graphics.translate(1, 5)
  2201. sx, sy = love.graphics.inverseTransformPoint(1, 5)
  2202. test:assertEquals(0, sx, 'check transformed x is 0')
  2203. test:assertEquals(0, sy, 'check transformed y is 0')
  2204. love.graphics.origin()
  2205. end
  2206. -- love.graphics.origin
  2207. love.test.graphics.origin = function(test)
  2208. -- if we do some translations and scaling
  2209. -- using .origin() should reset it all and draw the pixel at 0,0
  2210. local canvas = love.graphics.newCanvas(16, 16)
  2211. love.graphics.setCanvas(canvas)
  2212. love.graphics.clear(0, 0, 0, 1)
  2213. love.graphics.origin()
  2214. love.graphics.translate(10, 10)
  2215. love.graphics.scale(1, 1)
  2216. love.graphics.shear(20, 20)
  2217. love.graphics.origin()
  2218. love.graphics.setColor(1, 0, 0, 1)
  2219. love.graphics.rectangle('fill', 0, 0, 1, 1)
  2220. love.graphics.setColor(1, 1, 1, 1)
  2221. love.graphics.setCanvas()
  2222. local imgdata = love.graphics.readbackTexture(canvas)
  2223. test:assertPixels(imgdata, { red = {{0, 0}} }, 'origin check')
  2224. test:compareImg(imgdata)
  2225. end
  2226. -- love.graphics.pop
  2227. love.test.graphics.pop = function(test)
  2228. -- if we push at the start, and then run a pop
  2229. -- it should reset it all and draw the pixel at 0,0
  2230. local canvas = love.graphics.newCanvas(16, 16)
  2231. love.graphics.setCanvas(canvas)
  2232. love.graphics.clear(0, 0, 0, 1)
  2233. love.graphics.push()
  2234. love.graphics.translate(10, 10)
  2235. love.graphics.scale(1, 1)
  2236. love.graphics.shear(20, 20)
  2237. love.graphics.pop()
  2238. love.graphics.setColor(1, 0, 0, 1)
  2239. love.graphics.rectangle('fill', 0, 0, 1, 1)
  2240. love.graphics.setColor(1, 1, 1, 1)
  2241. love.graphics.setCanvas()
  2242. local imgdata = love.graphics.readbackTexture(canvas)
  2243. test:assertPixels(imgdata, { red = {{0, 0}} }, 'pop 1')
  2244. test:compareImg(imgdata)
  2245. end
  2246. -- love.graphics.push
  2247. love.test.graphics.push = function(test)
  2248. -- if we push at the start, do some stuff, then another push
  2249. -- 1 pop should only go back 1 push and draw the pixel at 1, 1
  2250. local canvas = love.graphics.newCanvas(16, 16)
  2251. love.graphics.setCanvas(canvas)
  2252. love.graphics.clear(0, 0, 0, 1)
  2253. love.graphics.push()
  2254. love.graphics.scale(1, 1)
  2255. love.graphics.shear(20, 20)
  2256. love.graphics.push()
  2257. love.graphics.translate(1, 1)
  2258. love.graphics.pop()
  2259. love.graphics.setColor(1, 0, 0, 1)
  2260. love.graphics.rectangle('fill', 0, 0, 1, 1)
  2261. love.graphics.setColor(1, 1, 1, 1)
  2262. love.graphics.setCanvas()
  2263. local imgdata = love.graphics.readbackTexture(canvas)
  2264. test:assertPixels(imgdata, { red = {{1, 1}} }, 'push 1')
  2265. test:compareImg(imgdata)
  2266. end
  2267. -- love.graphics.replaceTransform
  2268. love.test.graphics.replaceTransform = function(test)
  2269. -- if use transform object to translate
  2270. -- set some normal transforms first which should get overwritten
  2271. local transform = love.math.newTransform()
  2272. transform:translate(10, 0)
  2273. local canvas = love.graphics.newCanvas(16, 16)
  2274. love.graphics.setCanvas(canvas)
  2275. love.graphics.clear(0, 0, 0, 1)
  2276. love.graphics.setColor(1, 0, 0, 1)
  2277. love.graphics.scale(2, 2)
  2278. love.graphics.translate(10, 10)
  2279. love.graphics.replaceTransform(transform)
  2280. love.graphics.rectangle('fill', 0, 0, 1, 1)
  2281. love.graphics.setColor(1, 1, 1, 1)
  2282. love.graphics.setCanvas()
  2283. local imgdata = love.graphics.readbackTexture(canvas)
  2284. test:assertPixels(imgdata, { red = {{10, 0}} }, 'replace transform 10')
  2285. test:compareImg(imgdata)
  2286. end
  2287. -- love.graphics.rotate
  2288. love.test.graphics.rotate = function(test)
  2289. -- starting at 0,0, we rotate by 90deg and then draw
  2290. -- we can then check the drawn rectangle is rotated
  2291. local canvas = love.graphics.newCanvas(16, 16)
  2292. love.graphics.setCanvas(canvas)
  2293. love.graphics.clear(0, 0, 0, 1)
  2294. love.graphics.setColor(1, 0, 0, 1)
  2295. love.graphics.translate(4, 0)
  2296. love.graphics.rotate(90 * (math.pi/180))
  2297. love.graphics.rectangle('fill', 0, 0, 4, 4)
  2298. love.graphics.setColor(1, 1, 1, 1)
  2299. love.graphics.setCanvas()
  2300. local imgdata = love.graphics.readbackTexture(canvas)
  2301. test:assertPixels(imgdata, { red = {{0,0},{3,0},{3,3},{0,3}} }, 'rotate 90')
  2302. test:compareImg(imgdata)
  2303. end
  2304. -- love.graphics.scale
  2305. love.test.graphics.scale = function(test)
  2306. -- starting at 0,0, we scale by 4x and then draw
  2307. -- we can then check the drawn rectangle covers the whole canvas
  2308. local canvas = love.graphics.newCanvas(16, 16)
  2309. love.graphics.setCanvas(canvas)
  2310. love.graphics.clear(0, 0, 0, 1)
  2311. love.graphics.setColor(1, 0, 0, 1)
  2312. love.graphics.scale(4, 4)
  2313. love.graphics.rectangle('fill', 0, 0, 4, 4)
  2314. love.graphics.setColor(1, 1, 1, 1)
  2315. love.graphics.setCanvas()
  2316. local imgdata = love.graphics.readbackTexture(canvas)
  2317. test:assertPixels(imgdata, { red = {{1,1},{1,15},{15,1},{15,15}} }, 'scale 4x')
  2318. end
  2319. -- love.graphics.shear
  2320. love.test.graphics.shear = function(test)
  2321. -- starting at 0,0, we shear by 2x and then draw
  2322. -- we can then check the drawn rectangle has moved over
  2323. local canvas = love.graphics.newCanvas(16, 16)
  2324. love.graphics.setCanvas(canvas)
  2325. love.graphics.clear(0, 0, 0, 1)
  2326. love.graphics.origin()
  2327. love.graphics.setColor(1, 0, 0, 1)
  2328. love.graphics.shear(2, 0)
  2329. love.graphics.rectangle('fill', 0, 0, 4, 4)
  2330. love.graphics.setColor(1, 1, 1, 1)
  2331. love.graphics.setCanvas()
  2332. local imgdata1 = love.graphics.readbackTexture(canvas)
  2333. test:assertPixels(imgdata1, { red = {{1,0},{4,0},{7,3},{10,3}} }, 'shear x')
  2334. -- same again at 0,0, we shear by 2y and then draw
  2335. -- we can then check the drawn rectangle has moved down
  2336. love.graphics.setCanvas(canvas)
  2337. love.graphics.clear(0, 0, 0, 1)
  2338. love.graphics.origin()
  2339. love.graphics.setColor(1, 0, 0, 1)
  2340. love.graphics.shear(0, 2)
  2341. love.graphics.rectangle('fill', 0, 0, 4, 4)
  2342. love.graphics.setColor(1, 1, 1, 1)
  2343. love.graphics.setCanvas()
  2344. local imgdata2 = love.graphics.readbackTexture(canvas)
  2345. test:assertPixels(imgdata2, { red = { {0,1},{0,4},{3,7},{3,10}} }, 'shear y')
  2346. test:compareImg(imgdata1)
  2347. test:compareImg(imgdata2)
  2348. end
  2349. -- love.graphics.transformPoint
  2350. love.test.graphics.transformPoint = function(test)
  2351. -- start with 0, 0
  2352. local sx, sy = love.graphics.transformPoint(0, 0)
  2353. test:assertEquals(0, sx, 'check starting x is 0')
  2354. test:assertEquals(0, sy, 'check starting y is 0')
  2355. -- check translation effects the point
  2356. love.graphics.translate(1, 5)
  2357. sx, sy = love.graphics.transformPoint(0, 0)
  2358. test:assertEquals(1, sx, 'check transformed x is 0')
  2359. test:assertEquals(5, sy, 'check transformed y is 10')
  2360. end
  2361. -- love.graphics.translate
  2362. love.test.graphics.translate = function(test)
  2363. -- starting at 0,0, we translate 4 times and draw a pixel at each point
  2364. -- we can then check the 4 points are now red
  2365. local canvas = love.graphics.newCanvas(16, 16)
  2366. love.graphics.setCanvas(canvas)
  2367. love.graphics.clear(0, 0, 0, 1)
  2368. love.graphics.setColor(1, 0, 0, 1)
  2369. love.graphics.translate(5, 0)
  2370. love.graphics.rectangle('fill', 0, 0, 1, 1)
  2371. love.graphics.translate(0, 5)
  2372. love.graphics.rectangle('fill', 0, 0, 1, 1)
  2373. love.graphics.translate(-5, 0)
  2374. love.graphics.rectangle('fill', 0, 0, 1, 1)
  2375. love.graphics.translate(0, -5)
  2376. love.graphics.rectangle('fill', 0, 0, 1, 1)
  2377. love.graphics.setColor(1, 1, 1, 1)
  2378. love.graphics.setCanvas()
  2379. local imgdata = love.graphics.readbackTexture(canvas)
  2380. test:assertPixels(imgdata, { red = {{5,0},{0,5},{5,5},{0,0}} }, 'translate 4x')
  2381. test:compareImg(imgdata)
  2382. end
  2383. --------------------------------------------------------------------------------
  2384. --------------------------------------------------------------------------------
  2385. -------------------------------------WINDOW-------------------------------------
  2386. --------------------------------------------------------------------------------
  2387. --------------------------------------------------------------------------------
  2388. -- love.graphics.getDPIScale
  2389. -- @NOTE hardware dependent so can't check result
  2390. love.test.graphics.getDPIScale = function(test)
  2391. test:assertNotNil(love.graphics.getDPIScale())
  2392. end
  2393. -- love.graphics.getDimensions
  2394. love.test.graphics.getDimensions = function(test)
  2395. -- check graphics dimensions match window dimensions
  2396. local gwidth, gheight = love.graphics.getDimensions()
  2397. local wwidth, wheight, _ = love.window.getMode()
  2398. test:assertEquals(wwidth, gwidth, 'check graphics dimension w matches window w')
  2399. test:assertEquals(wheight, gheight, 'check graphics dimension h matches window h')
  2400. end
  2401. -- love.graphics.getHeight
  2402. love.test.graphics.getHeight = function(test)
  2403. -- check graphics height match window height
  2404. local wwidth, wheight, _ = love.window.getMode()
  2405. test:assertEquals(wheight, love.graphics.getHeight(), 'check graphics h matches window h')
  2406. end
  2407. -- love.graphics.getPixelDimensions
  2408. love.test.graphics.getPixelDimensions = function(test)
  2409. -- check graphics dimensions match window dimensions relative to dpi
  2410. local dpi = love.graphics.getDPIScale()
  2411. local gwidth, gheight = love.graphics.getPixelDimensions()
  2412. local wwidth, wheight, _ = love.window.getMode()
  2413. test:assertEquals(wwidth, gwidth/dpi, 'check graphics pixel dpi w matches window w')
  2414. test:assertEquals(wheight, gheight/dpi, 'check graphics pixel dpi h matches window h')
  2415. end
  2416. -- love.graphics.getPixelHeight
  2417. love.test.graphics.getPixelHeight = function(test)
  2418. -- check graphics height match window height relative to dpi
  2419. local dpi = love.graphics.getDPIScale()
  2420. local wwidth, wheight, _ = love.window.getMode()
  2421. test:assertEquals(wheight,love.graphics.getPixelHeight()/dpi, 'check graphics pixel dpi h matches window h')
  2422. end
  2423. -- love.graphics.getPixelWidth
  2424. love.test.graphics.getPixelWidth = function(test)
  2425. -- check graphics width match window width relative to dpi
  2426. local dpi = love.graphics.getDPIScale()
  2427. local wwidth, wheight, _ = love.window.getMode()
  2428. test:assertEquals(wwidth, love.graphics.getWidth()/dpi, 'check graphics pixel dpi w matches window w')
  2429. end
  2430. -- love.graphics.getWidth
  2431. love.test.graphics.getWidth = function(test)
  2432. -- check graphics width match window width
  2433. local wwidth, wheight, _ = love.window.getMode()
  2434. test:assertEquals(wwidth, love.graphics.getWidth(), 'check graphics w matches window w')
  2435. end
  2436. --------------------------------------------------------------------------------
  2437. --------------------------------------------------------------------------------
  2438. -------------------------------SYSTEM INFORMATION-------------------------------
  2439. --------------------------------------------------------------------------------
  2440. --------------------------------------------------------------------------------
  2441. -- love.graphics.getTextureFormats
  2442. love.test.graphics.getTextureFormats = function(test)
  2443. local formats = {
  2444. 'hdr', 'r8i', 'r8ui', 'r16i', 'r16ui', 'r32i', 'r32ui', 'rg8i', 'rg8ui',
  2445. 'rg16i', 'rg16ui', 'rg32i', 'rg32ui', 'bgra8', 'r8', 'rgba8i', 'rgba8ui',
  2446. 'rgba16i', 'rg8', 'rgba32i', 'rgba32ui', 'rgba8', 'DXT1', 'r16', 'DXT5',
  2447. 'rg16', 'BC4s', 'rgba16', 'BC5s', 'r16f', 'BC6hs', 'BC7', 'PVR1rgb2',
  2448. 'rg16f', 'PVR1rgba2', 'rgba16f', 'ETC1', 'r32f', 'ETC2rgba', 'rg32f',
  2449. 'EACr', 'rgba32f', 'EACrg', 'rgba4', 'ASTC4x4', 'ASTC5x4', 'rgb5a1',
  2450. 'ASTC6x5', 'rgb565', 'ASTC8x5', 'ASTC8x6', 'rgb10a2', 'ASTC10x5',
  2451. 'rg11b10f', 'ASTC10x8', 'ASTC10x10', 'ASTC12x10', 'ASTC12x12', 'normal',
  2452. 'srgba8', 'la8', 'ASTC10x6', 'ASTC8x8', 'ASTC6x6', 'ASTC5x5', 'EACrgs',
  2453. 'EACrs', 'ETC2rgba1', 'ETC2rgb', 'PVR1rgba4', 'PVR1rgb4', 'BC6h',
  2454. 'BC5', 'BC4', 'DXT3', 'stencil8', 'rgba16ui', 'bgra8srgb'
  2455. }
  2456. local supported = love.graphics.getTextureFormats({ canvas = true })
  2457. test:assertNotNil(supported)
  2458. for f=1,#formats do
  2459. test:assertNotEquals(nil, supported[formats[f] ], 'expected a key for format: ' .. formats[f])
  2460. end
  2461. end
  2462. -- love.graphics.getRendererInfo
  2463. -- @NOTE hardware dependent so best can do is nil checking
  2464. love.test.graphics.getRendererInfo = function(test)
  2465. local name, version, vendor, device = love.graphics.getRendererInfo()
  2466. test:assertNotNil(name)
  2467. test:assertNotNil(version)
  2468. test:assertNotNil(vendor)
  2469. test:assertNotNil(device)
  2470. end
  2471. -- love.graphics.getStats
  2472. -- @NOTE cant really predict some of these so just nil check for most
  2473. love.test.graphics.getStats = function(test)
  2474. local stattypes = {
  2475. 'drawcalls', 'canvasswitches', 'texturememory', 'shaderswitches',
  2476. 'drawcallsbatched', 'textures', 'fonts'
  2477. }
  2478. local stats = love.graphics.getStats()
  2479. for s=1,#stattypes do
  2480. test:assertNotEquals(nil, stats[stattypes[s] ], 'expected a key for stat: ' .. stattypes[s])
  2481. end
  2482. end
  2483. -- love.graphics.getSupported
  2484. love.test.graphics.getSupported = function(test)
  2485. -- cant check values as hardware dependent but we can check the keys in the
  2486. -- table match what the documentation lists
  2487. local gfs = {
  2488. 'clampzero', 'lighten', 'glsl3', 'instancing', 'fullnpot',
  2489. 'pixelshaderhighp', 'shaderderivatives', 'indirectdraw', 'mipmaprange',
  2490. 'copyrendertargettobuffer', 'copytexturetobuffer', 'copybuffer',
  2491. 'indexbuffer32bit', 'multirendertargetformats', 'clampone', 'blendminmax',
  2492. 'glsl4'
  2493. }
  2494. local features = love.graphics.getSupported()
  2495. for g=1,#gfs do
  2496. test:assertNotEquals(nil, features[gfs[g] ], 'expected a key for graphic feature: ' .. gfs[g])
  2497. end
  2498. end
  2499. -- love.graphics.getSystemLimits
  2500. love.test.graphics.getSystemLimits = function(test)
  2501. -- cant check values as hardware dependent but we can check the keys in the
  2502. -- table match what the documentation lists
  2503. local glimits = {
  2504. 'texelbuffersize', 'shaderstoragebuffersize', 'threadgroupsx',
  2505. 'threadgroupsy', 'pointsize', 'texturesize', 'texturelayers', 'volumetexturesize',
  2506. 'cubetexturesize', 'anisotropy', 'texturemsaa', 'rendertargets', 'threadgroupsz'
  2507. }
  2508. local limits = love.graphics.getSystemLimits()
  2509. for g=1,#glimits do
  2510. test:assertNotEquals(nil, limits[glimits[g] ], 'expected a key for system limit: ' .. glimits[g])
  2511. end
  2512. end
  2513. -- love.graphics.getTextureTypes
  2514. love.test.graphics.getTextureTypes = function(test)
  2515. -- cant check values as hardware dependent but we can check the keys in the
  2516. -- table match what the documentation lists
  2517. local ttypes = {
  2518. '2d', 'array', 'cube', 'volume'
  2519. }
  2520. local types = love.graphics.getTextureTypes()
  2521. for t=1,#ttypes do
  2522. test:assertNotEquals(nil, types[ttypes[t] ], 'expected a key for texture type: ' .. ttypes[t])
  2523. end
  2524. end