Graphics.cpp 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. /**
  2. * Copyright (c) 2006-2017 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. // LOVE
  21. #include "Graphics.h"
  22. #include "Buffer.h"
  23. #include "math/MathModule.h"
  24. #include "Polyline.h"
  25. #include "font/Font.h"
  26. #include "window/Window.h"
  27. #include "Font.h"
  28. #include "Video.h"
  29. // C++
  30. #include <algorithm>
  31. #include <stdlib.h>
  32. namespace love
  33. {
  34. namespace graphics
  35. {
  36. static bool gammaCorrect = false;
  37. static bool debugMode = false;
  38. static bool debugModeQueried = false;
  39. void setGammaCorrect(bool gammacorrect)
  40. {
  41. gammaCorrect = gammacorrect;
  42. }
  43. bool isGammaCorrect()
  44. {
  45. return gammaCorrect;
  46. }
  47. void gammaCorrectColor(Colorf &c)
  48. {
  49. if (isGammaCorrect())
  50. {
  51. c.r = math::gammaToLinear(c.r);
  52. c.g = math::gammaToLinear(c.g);
  53. c.b = math::gammaToLinear(c.b);
  54. }
  55. }
  56. Colorf gammaCorrectColor(const Colorf &c)
  57. {
  58. Colorf r = c;
  59. gammaCorrectColor(r);
  60. return r;
  61. }
  62. void unGammaCorrectColor(Colorf &c)
  63. {
  64. if (isGammaCorrect())
  65. {
  66. c.r = math::linearToGamma(c.r);
  67. c.g = math::linearToGamma(c.g);
  68. c.b = math::linearToGamma(c.b);
  69. }
  70. }
  71. Colorf unGammaCorrectColor(const Colorf &c)
  72. {
  73. Colorf r = c;
  74. unGammaCorrectColor(r);
  75. return r;
  76. }
  77. bool isDebugEnabled()
  78. {
  79. if (!debugModeQueried)
  80. {
  81. const char *debugenv = getenv("LOVE_GRAPHICS_DEBUG");
  82. debugMode = debugenv != nullptr && debugenv[0] != '0';
  83. debugModeQueried = true;
  84. }
  85. return debugMode;
  86. }
  87. love::Type Graphics::type("graphics", &Module::type);
  88. Shader::ShaderSource Graphics::defaultShaderCode[Shader::STANDARD_MAX_ENUM][Shader::LANGUAGE_MAX_ENUM][2];
  89. Graphics::Graphics()
  90. : width(0)
  91. , height(0)
  92. , pixelWidth(0)
  93. , pixelHeight(0)
  94. , created(false)
  95. , active(true)
  96. , writingToStencil(false)
  97. , streamBufferState()
  98. , projectionMatrix()
  99. , canvasSwitchCount(0)
  100. {
  101. transformStack.reserve(16);
  102. transformStack.push_back(Matrix4());
  103. pixelScaleStack.reserve(16);
  104. pixelScaleStack.push_back(1);
  105. if (!Shader::initialize())
  106. throw love::Exception("Shader support failed to initialize!");
  107. }
  108. Graphics::~Graphics()
  109. {
  110. states.clear();
  111. defaultFont.set(nullptr);
  112. for (int i = 0; i < Shader::STANDARD_MAX_ENUM; i++)
  113. {
  114. if (Shader::standardShaders[i])
  115. {
  116. Shader::standardShaders[i]->release();
  117. Shader::standardShaders[i] = nullptr;
  118. }
  119. }
  120. delete streamBufferState.vb[0];
  121. delete streamBufferState.vb[1];
  122. delete streamBufferState.indexBuffer;
  123. Shader::deinitialize();
  124. }
  125. Quad *Graphics::newQuad(Quad::Viewport v, double sw, double sh)
  126. {
  127. return new Quad(v, sw, sh);
  128. }
  129. Font *Graphics::newFont(love::font::Rasterizer *data, const Texture::Filter &filter)
  130. {
  131. return new Font(data, filter);
  132. }
  133. Video *Graphics::newVideo(love::video::VideoStream *stream, float pixeldensity)
  134. {
  135. return new Video(this, stream, pixeldensity);
  136. }
  137. bool Graphics::validateShader(bool gles, const Shader::ShaderSource &source, std::string &err)
  138. {
  139. return Shader::validate(this, gles, source, true, err);
  140. }
  141. int Graphics::getWidth() const
  142. {
  143. return width;
  144. }
  145. int Graphics::getHeight() const
  146. {
  147. return height;
  148. }
  149. int Graphics::getPixelWidth() const
  150. {
  151. return pixelWidth;
  152. }
  153. int Graphics::getPixelHeight() const
  154. {
  155. return pixelHeight;
  156. }
  157. double Graphics::getCurrentPixelDensity() const
  158. {
  159. if (states.back().renderTargets.colors.size() > 0)
  160. {
  161. Canvas *c = states.back().renderTargets.colors[0].canvas;
  162. return (double) c->getPixelHeight() / (double) c->getHeight();
  163. }
  164. return getScreenPixelDensity();
  165. }
  166. double Graphics::getScreenPixelDensity() const
  167. {
  168. return (double) getPixelHeight() / (double) getHeight();
  169. }
  170. bool Graphics::isCreated() const
  171. {
  172. return created;
  173. }
  174. bool Graphics::isActive() const
  175. {
  176. // The graphics module is only completely 'active' if there's a window, a
  177. // context, and the active variable is set.
  178. auto window = getInstance<love::window::Window>(M_WINDOW);
  179. return active && isCreated() && window != nullptr && window->isOpen();
  180. }
  181. void Graphics::reset()
  182. {
  183. DisplayState s;
  184. stopDrawToStencilBuffer();
  185. restoreState(s);
  186. origin();
  187. }
  188. /**
  189. * State functions.
  190. **/
  191. void Graphics::restoreState(const DisplayState &s)
  192. {
  193. setColor(s.color);
  194. setBackgroundColor(s.backgroundColor);
  195. setBlendMode(s.blendMode, s.blendAlphaMode);
  196. setLineWidth(s.lineWidth);
  197. setLineStyle(s.lineStyle);
  198. setLineJoin(s.lineJoin);
  199. setPointSize(s.pointSize);
  200. if (s.scissor)
  201. setScissor(s.scissorRect);
  202. else
  203. setScissor();
  204. setStencilTest(s.stencilCompare, s.stencilTestValue);
  205. setFont(s.font.get());
  206. setShader(s.shader.get());
  207. setCanvas(s.renderTargets);
  208. setColorMask(s.colorMask);
  209. setWireframe(s.wireframe);
  210. setDefaultFilter(s.defaultFilter);
  211. setDefaultMipmapFilter(s.defaultMipmapFilter, s.defaultMipmapSharpness);
  212. }
  213. void Graphics::restoreStateChecked(const DisplayState &s)
  214. {
  215. const DisplayState &cur = states.back();
  216. if (s.color != cur.color)
  217. setColor(s.color);
  218. setBackgroundColor(s.backgroundColor);
  219. if (s.blendMode != cur.blendMode || s.blendAlphaMode != cur.blendAlphaMode)
  220. setBlendMode(s.blendMode, s.blendAlphaMode);
  221. // These are just simple assignments.
  222. setLineWidth(s.lineWidth);
  223. setLineStyle(s.lineStyle);
  224. setLineJoin(s.lineJoin);
  225. if (s.pointSize != cur.pointSize)
  226. setPointSize(s.pointSize);
  227. if (s.scissor != cur.scissor || (s.scissor && !(s.scissorRect == cur.scissorRect)))
  228. {
  229. if (s.scissor)
  230. setScissor(s.scissorRect);
  231. else
  232. setScissor();
  233. }
  234. if (s.stencilCompare != cur.stencilCompare || s.stencilTestValue != cur.stencilTestValue)
  235. setStencilTest(s.stencilCompare, s.stencilTestValue);
  236. setFont(s.font.get());
  237. setShader(s.shader.get());
  238. const auto &sRTs = s.renderTargets;
  239. const auto &curRTs = cur.renderTargets;
  240. bool canvaseschanged = sRTs.colors.size() != curRTs.colors.size();
  241. if (!canvaseschanged)
  242. {
  243. for (size_t i = 0; i < sRTs.colors.size() && i < curRTs.colors.size(); i++)
  244. {
  245. const auto &rt1 = sRTs.colors[i];
  246. const auto &rt2 = curRTs.colors[i];
  247. if (rt1.canvas.get() != rt2.canvas.get() || rt1.slice != rt2.slice || rt1.mipmap != rt2.mipmap)
  248. {
  249. canvaseschanged = true;
  250. break;
  251. }
  252. }
  253. if (!canvaseschanged && (sRTs.depthStencil.canvas.get() != curRTs.depthStencil.canvas.get()
  254. || sRTs.depthStencil.slice != curRTs.depthStencil.slice
  255. || sRTs.depthStencil.mipmap != curRTs.depthStencil.mipmap))
  256. {
  257. canvaseschanged = true;
  258. }
  259. }
  260. if (canvaseschanged)
  261. setCanvas(s.renderTargets);
  262. if (s.colorMask != cur.colorMask)
  263. setColorMask(s.colorMask);
  264. if (s.wireframe != cur.wireframe)
  265. setWireframe(s.wireframe);
  266. setDefaultFilter(s.defaultFilter);
  267. setDefaultMipmapFilter(s.defaultMipmapFilter, s.defaultMipmapSharpness);
  268. }
  269. Colorf Graphics::getColor() const
  270. {
  271. return states.back().color;
  272. }
  273. void Graphics::setBackgroundColor(Colorf c)
  274. {
  275. states.back().backgroundColor = c;
  276. }
  277. Colorf Graphics::getBackgroundColor() const
  278. {
  279. return states.back().backgroundColor;
  280. }
  281. void Graphics::checkSetDefaultFont()
  282. {
  283. // We don't create or set the default Font if an existing font is in use.
  284. if (states.back().font.get() != nullptr)
  285. return;
  286. // Create a new default font if we don't have one yet.
  287. if (!defaultFont.get())
  288. {
  289. auto fontmodule = Module::getInstance<font::Font>(M_FONT);
  290. if (!fontmodule)
  291. throw love::Exception("Font module has not been loaded.");
  292. auto hinting = font::TrueTypeRasterizer::HINTING_NORMAL;
  293. StrongRef<font::Rasterizer> r(fontmodule->newTrueTypeRasterizer(12, hinting), Acquire::NORETAIN);
  294. defaultFont.set(newFont(r.get()), Acquire::NORETAIN);
  295. }
  296. states.back().font.set(defaultFont.get());
  297. }
  298. void Graphics::setFont(love::graphics::Font *font)
  299. {
  300. // We don't need to set a default font here if null is passed in, since we
  301. // only care about the default font in getFont and print.
  302. DisplayState &state = states.back();
  303. state.font.set(font);
  304. }
  305. love::graphics::Font *Graphics::getFont()
  306. {
  307. checkSetDefaultFont();
  308. return states.back().font.get();
  309. }
  310. void Graphics::setShader(love::graphics::Shader *shader)
  311. {
  312. if (shader == nullptr)
  313. return setShader();
  314. flushStreamDraws();
  315. shader->attach();
  316. states.back().shader.set(shader);
  317. }
  318. void Graphics::setShader()
  319. {
  320. flushStreamDraws();
  321. Shader::attachDefault(Shader::STANDARD_DEFAULT);
  322. states.back().shader.set(nullptr);
  323. }
  324. love::graphics::Shader *Graphics::getShader() const
  325. {
  326. return states.back().shader.get();
  327. }
  328. void Graphics::setCanvas(RenderTarget rt)
  329. {
  330. if (rt.canvas == nullptr)
  331. return setCanvas();
  332. RenderTargets rts;
  333. rts.colors.push_back(rt);
  334. setCanvas(rts);
  335. }
  336. void Graphics::setCanvas(const RenderTargetsStrongRef &rts)
  337. {
  338. RenderTargets targets;
  339. targets.colors.reserve(rts.colors.size());
  340. for (const auto &rt : rts.colors)
  341. targets.colors.emplace_back(rt.canvas.get(), rt.slice, rt.mipmap);
  342. targets.depthStencil = RenderTarget(rts.depthStencil.canvas, rts.depthStencil.slice, rts.depthStencil.mipmap);
  343. return setCanvas(targets);
  344. }
  345. Graphics::RenderTargets Graphics::getCanvas() const
  346. {
  347. const auto &curRTs = states.back().renderTargets;
  348. RenderTargets rts;
  349. rts.colors.reserve(curRTs.colors.size());
  350. for (const auto &rt : curRTs.colors)
  351. rts.colors.emplace_back(rt.canvas.get(), rt.slice, rt.mipmap);
  352. rts.depthStencil = RenderTarget(curRTs.depthStencil.canvas, curRTs.depthStencil.slice, curRTs.depthStencil.mipmap);
  353. return rts;
  354. }
  355. bool Graphics::isCanvasActive() const
  356. {
  357. return !states.back().renderTargets.colors.empty();
  358. }
  359. bool Graphics::isCanvasActive(love::graphics::Canvas *canvas) const
  360. {
  361. const auto &curRTs = states.back().renderTargets;
  362. for (const auto &rt : curRTs.colors)
  363. {
  364. if (rt.canvas.get() == canvas)
  365. return true;
  366. }
  367. if (curRTs.depthStencil.canvas.get() == canvas)
  368. return true;
  369. return false;
  370. }
  371. void Graphics::intersectScissor(const Rect &rect)
  372. {
  373. Rect currect = states.back().scissorRect;
  374. if (!states.back().scissor)
  375. {
  376. currect.x = 0;
  377. currect.y = 0;
  378. currect.w = std::numeric_limits<int>::max();
  379. currect.h = std::numeric_limits<int>::max();
  380. }
  381. int x1 = std::max(currect.x, rect.x);
  382. int y1 = std::max(currect.y, rect.y);
  383. int x2 = std::min(currect.x + currect.w, rect.x + rect.w);
  384. int y2 = std::min(currect.y + currect.h, rect.y + rect.h);
  385. Rect newrect = {x1, y1, std::max(0, x2 - x1), std::max(0, y2 - y1)};
  386. setScissor(newrect);
  387. }
  388. bool Graphics::getScissor(Rect &rect) const
  389. {
  390. const DisplayState &state = states.back();
  391. rect = state.scissorRect;
  392. return state.scissor;
  393. }
  394. void Graphics::getStencilTest(CompareMode &compare, int &value)
  395. {
  396. const DisplayState &state = states.back();
  397. compare = state.stencilCompare;
  398. value = state.stencilTestValue;
  399. }
  400. Graphics::ColorMask Graphics::getColorMask() const
  401. {
  402. return states.back().colorMask;
  403. }
  404. Graphics::BlendMode Graphics::getBlendMode(BlendAlpha &alphamode) const
  405. {
  406. alphamode = states.back().blendAlphaMode;
  407. return states.back().blendMode;
  408. }
  409. void Graphics::setDefaultFilter(const Texture::Filter &f)
  410. {
  411. Texture::defaultFilter = f;
  412. states.back().defaultFilter = f;
  413. }
  414. const Texture::Filter &Graphics::getDefaultFilter() const
  415. {
  416. return Texture::defaultFilter;
  417. }
  418. void Graphics::setDefaultMipmapFilter(Texture::FilterMode filter, float sharpness)
  419. {
  420. Texture::defaultMipmapFilter = filter;
  421. Texture::defaultMipmapSharpness = sharpness;
  422. states.back().defaultMipmapFilter = filter;
  423. states.back().defaultMipmapSharpness = sharpness;
  424. }
  425. void Graphics::getDefaultMipmapFilter(Texture::FilterMode *filter, float *sharpness) const
  426. {
  427. *filter = Texture::defaultMipmapFilter;
  428. *sharpness = Texture::defaultMipmapSharpness;
  429. }
  430. void Graphics::setLineWidth(float width)
  431. {
  432. states.back().lineWidth = width;
  433. }
  434. void Graphics::setLineStyle(Graphics::LineStyle style)
  435. {
  436. states.back().lineStyle = style;
  437. }
  438. void Graphics::setLineJoin(Graphics::LineJoin join)
  439. {
  440. states.back().lineJoin = join;
  441. }
  442. float Graphics::getLineWidth() const
  443. {
  444. return states.back().lineWidth;
  445. }
  446. Graphics::LineStyle Graphics::getLineStyle() const
  447. {
  448. return states.back().lineStyle;
  449. }
  450. Graphics::LineJoin Graphics::getLineJoin() const
  451. {
  452. return states.back().lineJoin;
  453. }
  454. float Graphics::getPointSize() const
  455. {
  456. return states.back().pointSize;
  457. }
  458. bool Graphics::isWireframe() const
  459. {
  460. return states.back().wireframe;
  461. }
  462. void Graphics::captureScreenshot(const ScreenshotInfo &info)
  463. {
  464. pendingScreenshotCallbacks.push_back(info);
  465. }
  466. Graphics::StreamVertexData Graphics::requestStreamDraw(const StreamDrawRequest &req)
  467. {
  468. using namespace vertex;
  469. StreamBufferState &state = streamBufferState;
  470. if (state.vertexCount == 0 && Shader::current != nullptr && req.texture != nullptr)
  471. Shader::current->checkMainTexture(req.texture);
  472. bool shouldflush = false;
  473. bool shouldresize = false;
  474. if (req.primitiveMode != state.primitiveMode
  475. || req.formats[0] != state.formats[0] || req.formats[1] != state.formats[1]
  476. || ((req.indexMode != TriangleIndexMode::NONE) != (state.indexCount > 0))
  477. || req.texture != state.texture)
  478. {
  479. shouldflush = true;
  480. }
  481. int totalvertices = state.vertexCount + req.vertexCount;
  482. // We only support uint16 index buffers for now.
  483. if (totalvertices > LOVE_UINT16_MAX && req.indexMode != TriangleIndexMode::NONE)
  484. shouldflush = true;
  485. int reqIndexCount = getIndexCount(req.indexMode, req.vertexCount);
  486. size_t reqIndexSize = reqIndexCount * sizeof(uint16);
  487. size_t newdatasizes[2] = {0, 0};
  488. size_t buffersizes[3] = {0, 0, 0};
  489. for (int i = 0; i < 2; i++)
  490. {
  491. if (req.formats[i] == CommonFormat::NONE)
  492. continue;
  493. size_t stride = getFormatStride(req.formats[i]);
  494. size_t datasize = stride * totalvertices;
  495. if (state.vbMap[i].data != nullptr && datasize > state.vbMap[i].size)
  496. shouldflush = true;
  497. if (datasize > state.vb[i]->getSize())
  498. {
  499. buffersizes[i] = std::max(datasize, state.vb[i]->getSize() * 2);
  500. shouldresize = true;
  501. }
  502. newdatasizes[i] = stride * req.vertexCount;
  503. }
  504. if (req.indexMode != TriangleIndexMode::NONE)
  505. {
  506. size_t datasize = (state.indexCount + reqIndexCount) * sizeof(uint16);
  507. if (state.indexBufferMap.data != nullptr && datasize > state.indexBufferMap.size)
  508. shouldflush = true;
  509. if (datasize > state.indexBuffer->getSize())
  510. {
  511. buffersizes[2] = std::max(datasize, state.indexBuffer->getSize() * 2);
  512. shouldresize = true;
  513. }
  514. }
  515. if (shouldflush || shouldresize)
  516. {
  517. flushStreamDraws();
  518. state.primitiveMode = req.primitiveMode;
  519. state.formats[0] = req.formats[0];
  520. state.formats[1] = req.formats[1];
  521. state.texture = req.texture;
  522. }
  523. if (shouldresize)
  524. {
  525. for (int i = 0; i < 2; i++)
  526. {
  527. if (state.vb[i]->getSize() < buffersizes[i])
  528. {
  529. delete state.vb[i];
  530. state.vb[i] = newStreamBuffer(BUFFER_VERTEX, buffersizes[i]);
  531. }
  532. }
  533. if (state.indexBuffer->getSize() < buffersizes[2])
  534. {
  535. delete state.indexBuffer;
  536. state.indexBuffer = newStreamBuffer(BUFFER_INDEX, buffersizes[2]);
  537. }
  538. }
  539. if (req.indexMode != TriangleIndexMode::NONE)
  540. {
  541. if (state.indexBufferMap.data == nullptr)
  542. state.indexBufferMap = state.indexBuffer->map(reqIndexSize);
  543. uint16 *indices = (uint16 *) state.indexBufferMap.data;
  544. fillIndices(req.indexMode, state.vertexCount, req.vertexCount, indices);
  545. state.indexBufferMap.data += reqIndexSize;
  546. }
  547. StreamVertexData d;
  548. for (int i = 0; i < 2; i++)
  549. {
  550. if (newdatasizes[i] > 0)
  551. {
  552. if (state.vbMap[i].data == nullptr)
  553. state.vbMap[i] = state.vb[i]->map(newdatasizes[i]);
  554. d.stream[i] = state.vbMap[i].data;
  555. state.vbMap[i].data += newdatasizes[i];
  556. }
  557. }
  558. state.vertexCount += req.vertexCount;
  559. state.indexCount += reqIndexCount;
  560. return d;
  561. }
  562. void Graphics::flushStreamDrawsGlobal()
  563. {
  564. Graphics *instance = getInstance<Graphics>(M_GRAPHICS);
  565. if (instance != nullptr)
  566. instance->flushStreamDraws();
  567. }
  568. /**
  569. * Drawing
  570. **/
  571. void Graphics::draw(Drawable *drawable, const Matrix4 &m)
  572. {
  573. drawable->draw(this, m);
  574. }
  575. void Graphics::draw(Texture *texture, Quad *quad, const Matrix4 &m)
  576. {
  577. texture->draw(this, quad, m);
  578. }
  579. void Graphics::drawLayer(Texture *texture, int layer, const Matrix4 &m)
  580. {
  581. texture->drawLayer(this, layer, m);
  582. }
  583. void Graphics::drawLayer(Texture *texture, int layer, Quad *quad, const Matrix4 &m)
  584. {
  585. texture->drawLayer(this, layer, quad, m);
  586. }
  587. void Graphics::drawInstanced(Mesh *mesh, const Matrix4 &m, int instancecount)
  588. {
  589. mesh->drawInstanced(this, m, instancecount);
  590. }
  591. void Graphics::print(const std::vector<Font::ColoredString> &str, const Matrix4 &m)
  592. {
  593. checkSetDefaultFont();
  594. if (states.back().font.get() != nullptr)
  595. print(str, states.back().font.get(), m);
  596. }
  597. void Graphics::print(const std::vector<Font::ColoredString> &str, Font *font, const Matrix4 &m)
  598. {
  599. font->print(this, str, m, states.back().color);
  600. }
  601. void Graphics::printf(const std::vector<Font::ColoredString> &str, float wrap, Font::AlignMode align, const Matrix4 &m)
  602. {
  603. checkSetDefaultFont();
  604. if (states.back().font.get() != nullptr)
  605. printf(str, states.back().font.get(), wrap, align, m);
  606. }
  607. void Graphics::printf(const std::vector<Font::ColoredString> &str, Font *font, float wrap, Font::AlignMode align, const Matrix4 &m)
  608. {
  609. font->printf(this, str, wrap, align, m, states.back().color);
  610. }
  611. /**
  612. * Primitives (points, shapes, lines).
  613. **/
  614. void Graphics::points(const float *coords, const Colorf *colors, size_t numpoints)
  615. {
  616. StreamDrawRequest req;
  617. req.primitiveMode = vertex::PrimitiveMode::POINTS;
  618. req.formats[0] = vertex::CommonFormat::XYf;
  619. req.formats[1] = vertex::CommonFormat::RGBAub;
  620. req.vertexCount = (int) numpoints;
  621. StreamVertexData data = requestStreamDraw(req);
  622. const Matrix4 &t = getTransform();
  623. t.transform((Vector *) data.stream[0], (const Vector *) coords, req.vertexCount);
  624. Color *colordata = (Color *) data.stream[1];
  625. if (colors)
  626. {
  627. Colorf nc = getColor();
  628. gammaCorrectColor(nc);
  629. if (isGammaCorrect())
  630. {
  631. for (int i = 0; i < req.vertexCount; i++)
  632. {
  633. Colorf ci = colors[i];
  634. gammaCorrectColor(ci);
  635. ci *= nc;
  636. unGammaCorrectColor(ci);
  637. colordata[i] = toColor(ci);
  638. }
  639. }
  640. else
  641. {
  642. for (int i = 0; i < req.vertexCount; i++)
  643. colordata[i] = toColor(nc * colors[i]);
  644. }
  645. }
  646. else
  647. {
  648. Color c = toColor(getColor());
  649. for (int i = 0; i < req.vertexCount; i++)
  650. colordata[i] = c;
  651. }
  652. }
  653. int Graphics::calculateEllipsePoints(float rx, float ry) const
  654. {
  655. int points = (int) sqrtf(((rx + ry) / 2.0f) * 20.0f * (float) pixelScaleStack.back());
  656. return std::max(points, 8);
  657. }
  658. void Graphics::polyline(const float *coords, size_t count)
  659. {
  660. float halfwidth = getLineWidth() * 0.5f;
  661. LineJoin linejoin = getLineJoin();
  662. LineStyle linestyle = getLineStyle();
  663. float pixelsize = 1.0f / std::max((float) pixelScaleStack.back(), 0.000001f);
  664. if (linejoin == LINE_JOIN_NONE)
  665. {
  666. NoneJoinPolyline line;
  667. line.render(coords, count, halfwidth, pixelsize, linestyle == LINE_SMOOTH);
  668. line.draw(this);
  669. }
  670. else if (linejoin == LINE_JOIN_BEVEL)
  671. {
  672. BevelJoinPolyline line;
  673. line.render(coords, count, halfwidth, pixelsize, linestyle == LINE_SMOOTH);
  674. line.draw(this);
  675. }
  676. else if (linejoin == LINE_JOIN_MITER)
  677. {
  678. MiterJoinPolyline line;
  679. line.render(coords, count, halfwidth, pixelsize, linestyle == LINE_SMOOTH);
  680. line.draw(this);
  681. }
  682. }
  683. void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h)
  684. {
  685. float coords[] = {x,y, x,y+h, x+w,y+h, x+w,y, x,y};
  686. polygon(mode, coords, 5 * 2);
  687. }
  688. void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h, float rx, float ry, int points)
  689. {
  690. if (rx == 0 || ry == 0)
  691. {
  692. rectangle(mode, x, y, w, h);
  693. return;
  694. }
  695. // Radius values that are more than half the rectangle's size aren't handled
  696. // correctly (for now)...
  697. if (w >= 0.02f)
  698. rx = std::min(rx, w / 2.0f - 0.01f);
  699. if (h >= 0.02f)
  700. ry = std::min(ry, h / 2.0f - 0.01f);
  701. points = std::max(points / 4, 1);
  702. const float half_pi = static_cast<float>(LOVE_M_PI / 2);
  703. float angle_shift = half_pi / ((float) points + 1.0f);
  704. int num_coords = (points + 2) * 8;
  705. float *coords = getScratchBuffer<float>(num_coords + 2);
  706. float phi = .0f;
  707. for (int i = 0; i <= points + 2; ++i, phi += angle_shift)
  708. {
  709. coords[2 * i + 0] = x + rx * (1 - cosf(phi));
  710. coords[2 * i + 1] = y + ry * (1 - sinf(phi));
  711. }
  712. phi = half_pi;
  713. for (int i = points + 2; i <= 2 * (points + 2); ++i, phi += angle_shift)
  714. {
  715. coords[2 * i + 0] = x + w - rx * (1 + cosf(phi));
  716. coords[2 * i + 1] = y + ry * (1 - sinf(phi));
  717. }
  718. phi = 2 * half_pi;
  719. for (int i = 2 * (points + 2); i <= 3 * (points + 2); ++i, phi += angle_shift)
  720. {
  721. coords[2 * i + 0] = x + w - rx * (1 + cosf(phi));
  722. coords[2 * i + 1] = y + h - ry * (1 + sinf(phi));
  723. }
  724. phi = 3 * half_pi;
  725. for (int i = 3 * (points + 2); i <= 4 * (points + 2); ++i, phi += angle_shift)
  726. {
  727. coords[2 * i + 0] = x + rx * (1 - cosf(phi));
  728. coords[2 * i + 1] = y + h - ry * (1 + sinf(phi));
  729. }
  730. coords[num_coords + 0] = coords[0];
  731. coords[num_coords + 1] = coords[1];
  732. polygon(mode, coords, num_coords + 2);
  733. }
  734. void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h, float rx, float ry)
  735. {
  736. rectangle(mode, x, y, w, h, rx, ry, calculateEllipsePoints(rx, ry));
  737. }
  738. void Graphics::circle(DrawMode mode, float x, float y, float radius, int points)
  739. {
  740. ellipse(mode, x, y, radius, radius, points);
  741. }
  742. void Graphics::circle(DrawMode mode, float x, float y, float radius)
  743. {
  744. ellipse(mode, x, y, radius, radius);
  745. }
  746. void Graphics::ellipse(DrawMode mode, float x, float y, float a, float b, int points)
  747. {
  748. float two_pi = (float) (LOVE_M_PI * 2);
  749. if (points <= 0) points = 1;
  750. float angle_shift = (two_pi / points);
  751. float phi = .0f;
  752. float *coords = getScratchBuffer<float>(2 * (points + 1));
  753. for (int i = 0; i < points; ++i, phi += angle_shift)
  754. {
  755. coords[2*i+0] = x + a * cosf(phi);
  756. coords[2*i+1] = y + b * sinf(phi);
  757. }
  758. coords[2*points+0] = coords[0];
  759. coords[2*points+1] = coords[1];
  760. polygon(mode, coords, (points + 1) * 2);
  761. }
  762. void Graphics::ellipse(DrawMode mode, float x, float y, float a, float b)
  763. {
  764. ellipse(mode, x, y, a, b, calculateEllipsePoints(a, b));
  765. }
  766. void Graphics::arc(DrawMode drawmode, ArcMode arcmode, float x, float y, float radius, float angle1, float angle2, int points)
  767. {
  768. // Nothing to display with no points or equal angles. (Or is there with line mode?)
  769. if (points <= 0 || angle1 == angle2)
  770. return;
  771. // Oh, you want to draw a circle?
  772. if (fabs(angle1 - angle2) >= 2.0f * (float) LOVE_M_PI)
  773. {
  774. circle(drawmode, x, y, radius, points);
  775. return;
  776. }
  777. float angle_shift = (angle2 - angle1) / points;
  778. // Bail on precision issues.
  779. if (angle_shift == 0.0)
  780. return;
  781. // Prevent the connecting line from being drawn if a closed line arc has a
  782. // small angle. Avoids some visual issues when connected lines are at sharp
  783. // angles, due to the miter line join drawing code.
  784. if (drawmode == DRAW_LINE && arcmode == ARC_CLOSED && fabsf(angle1 - angle2) < LOVE_TORAD(4))
  785. arcmode = ARC_OPEN;
  786. // Quick fix for the last part of a filled open arc not being drawn (because
  787. // polygon(DRAW_FILL, ...) doesn't work without a closed loop of vertices.)
  788. if (drawmode == DRAW_FILL && arcmode == ARC_OPEN)
  789. arcmode = ARC_CLOSED;
  790. float phi = angle1;
  791. float *coords = nullptr;
  792. int num_coords = 0;
  793. const auto createPoints = [&](float *coordinates)
  794. {
  795. for (int i = 0; i <= points; ++i, phi += angle_shift)
  796. {
  797. coordinates[2 * i + 0] = x + radius * cosf(phi);
  798. coordinates[2 * i + 1] = y + radius * sinf(phi);
  799. }
  800. };
  801. if (arcmode == ARC_PIE)
  802. {
  803. num_coords = (points + 3) * 2;
  804. coords = getScratchBuffer<float>(num_coords);
  805. coords[0] = coords[num_coords - 2] = x;
  806. coords[1] = coords[num_coords - 1] = y;
  807. createPoints(coords + 2);
  808. }
  809. else if (arcmode == ARC_OPEN)
  810. {
  811. num_coords = (points + 1) * 2;
  812. coords = getScratchBuffer<float>(num_coords);
  813. createPoints(coords);
  814. }
  815. else // ARC_CLOSED
  816. {
  817. num_coords = (points + 2) * 2;
  818. coords = getScratchBuffer<float>(num_coords);
  819. createPoints(coords);
  820. // Connect the ends of the arc.
  821. coords[num_coords - 2] = coords[0];
  822. coords[num_coords - 1] = coords[1];
  823. }
  824. polygon(drawmode, coords, num_coords);
  825. }
  826. void Graphics::arc(DrawMode drawmode, ArcMode arcmode, float x, float y, float radius, float angle1, float angle2)
  827. {
  828. float points = (float) calculateEllipsePoints(radius, radius);
  829. // The amount of points is based on the fraction of the circle created by the arc.
  830. float angle = fabsf(angle1 - angle2);
  831. if (angle < 2.0f * (float) LOVE_M_PI)
  832. points *= angle / (2.0f * (float) LOVE_M_PI);
  833. arc(drawmode, arcmode, x, y, radius, angle1, angle2, (int) (points + 0.5f));
  834. }
  835. /// @param mode the draw mode
  836. /// @param coords the coordinate array
  837. /// @param count the number of coordinates/size of the array
  838. void Graphics::polygon(DrawMode mode, const float *coords, size_t count)
  839. {
  840. // coords is an array of a closed loop of vertices, i.e.
  841. // coords[count-2] = coords[0], coords[count-1] = coords[1]
  842. if (mode == DRAW_LINE)
  843. {
  844. polyline(coords, count);
  845. }
  846. else
  847. {
  848. StreamDrawRequest req;
  849. req.formats[0] = vertex::CommonFormat::XYf;
  850. req.formats[1] = vertex::CommonFormat::RGBAub;
  851. req.indexMode = vertex::TriangleIndexMode::FAN;
  852. req.vertexCount = (int)count/2 - 1;
  853. StreamVertexData data = requestStreamDraw(req);
  854. const Matrix4 &t = getTransform();
  855. t.transform((Vector *) data.stream[0], (const Vector *) coords, req.vertexCount);
  856. Color c = toColor(getColor());
  857. Color *colordata = (Color *) data.stream[1];
  858. for (int i = 0; i < req.vertexCount; i++)
  859. colordata[i] = c;
  860. }
  861. }
  862. void Graphics::push(StackType type)
  863. {
  864. if (stackTypeStack.size() == MAX_USER_STACK_DEPTH)
  865. throw Exception("Maximum stack depth reached (more pushes than pops?)");
  866. pushTransform();
  867. pixelScaleStack.push_back(pixelScaleStack.back());
  868. if (type == STACK_ALL)
  869. states.push_back(states.back());
  870. stackTypeStack.push_back(type);
  871. }
  872. void Graphics::pop()
  873. {
  874. if (stackTypeStack.size() < 1)
  875. throw Exception("Minimum stack depth reached (more pops than pushes?)");
  876. popTransform();
  877. pixelScaleStack.pop_back();
  878. if (stackTypeStack.back() == STACK_ALL)
  879. {
  880. DisplayState &newstate = states[states.size() - 2];
  881. restoreStateChecked(newstate);
  882. // The last two states in the stack should be equal now.
  883. states.pop_back();
  884. }
  885. stackTypeStack.pop_back();
  886. }
  887. /**
  888. * Transform and stack functions.
  889. **/
  890. const Matrix4 &Graphics::getTransform() const
  891. {
  892. return transformStack.back();
  893. }
  894. const Matrix4 &Graphics::getProjection() const
  895. {
  896. return projectionMatrix;
  897. }
  898. void Graphics::pushTransform()
  899. {
  900. transformStack.push_back(transformStack.back());
  901. }
  902. void Graphics::pushIdentityTransform()
  903. {
  904. transformStack.push_back(Matrix4());
  905. }
  906. void Graphics::popTransform()
  907. {
  908. transformStack.pop_back();
  909. }
  910. void Graphics::rotate(float r)
  911. {
  912. transformStack.back().rotate(r);
  913. }
  914. void Graphics::scale(float x, float y)
  915. {
  916. transformStack.back().scale(x, y);
  917. pixelScaleStack.back() *= (fabs(x) + fabs(y)) / 2.0;
  918. }
  919. void Graphics::translate(float x, float y)
  920. {
  921. transformStack.back().translate(x, y);
  922. }
  923. void Graphics::shear(float kx, float ky)
  924. {
  925. transformStack.back().shear(kx, ky);
  926. }
  927. void Graphics::origin()
  928. {
  929. transformStack.back().setIdentity();
  930. pixelScaleStack.back() = 1;
  931. }
  932. void Graphics::applyTransform(love::math::Transform *transform)
  933. {
  934. Matrix4 &m = transformStack.back();
  935. m *= transform->getMatrix();
  936. float sx, sy;
  937. m.getApproximateScale(sx, sy);
  938. pixelScaleStack.back() = (sx + sy) / 2.0;
  939. }
  940. void Graphics::replaceTransform(love::math::Transform *transform)
  941. {
  942. const Matrix4 &m = transform->getMatrix();
  943. transformStack.back() = m;
  944. float sx, sy;
  945. m.getApproximateScale(sx, sy);
  946. pixelScaleStack.back() = (sx + sy) / 2.0;
  947. }
  948. Vector Graphics::transformPoint(Vector point)
  949. {
  950. Vector p;
  951. transformStack.back().transform(&p, &point, 1);
  952. return p;
  953. }
  954. Vector Graphics::inverseTransformPoint(Vector point)
  955. {
  956. Vector p;
  957. // TODO: We should probably cache the inverse transform so we don't have to
  958. // re-calculate it every time this is called.
  959. transformStack.back().inverse().transform(&p, &point, 1);
  960. return p;
  961. }
  962. const Shader::ShaderSource &Graphics::getCurrentDefaultShaderCode() const
  963. {
  964. return defaultShaderCode[Shader::STANDARD_DEFAULT][getShaderLanguageTarget()][isGammaCorrect() ? 1 : 0];
  965. }
  966. /**
  967. * Constants.
  968. **/
  969. bool Graphics::getConstant(const char *in, DrawMode &out)
  970. {
  971. return drawModes.find(in, out);
  972. }
  973. bool Graphics::getConstant(DrawMode in, const char *&out)
  974. {
  975. return drawModes.find(in, out);
  976. }
  977. bool Graphics::getConstant(const char *in, ArcMode &out)
  978. {
  979. return arcModes.find(in, out);
  980. }
  981. bool Graphics::getConstant(ArcMode in, const char *&out)
  982. {
  983. return arcModes.find(in, out);
  984. }
  985. bool Graphics::getConstant(const char *in, BlendMode &out)
  986. {
  987. return blendModes.find(in, out);
  988. }
  989. bool Graphics::getConstant(BlendMode in, const char *&out)
  990. {
  991. return blendModes.find(in, out);
  992. }
  993. bool Graphics::getConstant(const char *in, BlendAlpha &out)
  994. {
  995. return blendAlphaModes.find(in, out);
  996. }
  997. bool Graphics::getConstant(BlendAlpha in, const char *&out)
  998. {
  999. return blendAlphaModes.find(in, out);
  1000. }
  1001. bool Graphics::getConstant(const char *in, LineStyle &out)
  1002. {
  1003. return lineStyles.find(in, out);
  1004. }
  1005. bool Graphics::getConstant(LineStyle in, const char *&out)
  1006. {
  1007. return lineStyles.find(in, out);
  1008. }
  1009. bool Graphics::getConstant(const char *in, LineJoin &out)
  1010. {
  1011. return lineJoins.find(in, out);
  1012. }
  1013. bool Graphics::getConstant(LineJoin in, const char *&out)
  1014. {
  1015. return lineJoins.find(in, out);
  1016. }
  1017. bool Graphics::getConstant(const char *in, Feature &out)
  1018. {
  1019. return features.find(in, out);
  1020. }
  1021. bool Graphics::getConstant(Feature in, const char *&out)
  1022. {
  1023. return features.find(in, out);
  1024. }
  1025. bool Graphics::getConstant(const char *in, SystemLimit &out)
  1026. {
  1027. return systemLimits.find(in, out);
  1028. }
  1029. bool Graphics::getConstant(SystemLimit in, const char *&out)
  1030. {
  1031. return systemLimits.find(in, out);
  1032. }
  1033. bool Graphics::getConstant(const char *in, StackType &out)
  1034. {
  1035. return stackTypes.find(in, out);
  1036. }
  1037. bool Graphics::getConstant(StackType in, const char *&out)
  1038. {
  1039. return stackTypes.find(in, out);
  1040. }
  1041. StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
  1042. {
  1043. { "line", DRAW_LINE },
  1044. { "fill", DRAW_FILL },
  1045. };
  1046. StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM> Graphics::drawModes(Graphics::drawModeEntries, sizeof(Graphics::drawModeEntries));
  1047. StringMap<Graphics::ArcMode, Graphics::ARC_MAX_ENUM>::Entry Graphics::arcModeEntries[] =
  1048. {
  1049. { "open", ARC_OPEN },
  1050. { "closed", ARC_CLOSED },
  1051. { "pie", ARC_PIE },
  1052. };
  1053. StringMap<Graphics::ArcMode, Graphics::ARC_MAX_ENUM> Graphics::arcModes(Graphics::arcModeEntries, sizeof(Graphics::arcModeEntries));
  1054. StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM>::Entry Graphics::blendModeEntries[] =
  1055. {
  1056. { "alpha", BLEND_ALPHA },
  1057. { "add", BLEND_ADD },
  1058. { "subtract", BLEND_SUBTRACT },
  1059. { "multiply", BLEND_MULTIPLY },
  1060. { "lighten", BLEND_LIGHTEN },
  1061. { "darken", BLEND_DARKEN },
  1062. { "screen", BLEND_SCREEN },
  1063. { "replace", BLEND_REPLACE },
  1064. { "none", BLEND_NONE },
  1065. };
  1066. StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM> Graphics::blendModes(Graphics::blendModeEntries, sizeof(Graphics::blendModeEntries));
  1067. StringMap<Graphics::BlendAlpha, Graphics::BLENDALPHA_MAX_ENUM>::Entry Graphics::blendAlphaEntries[] =
  1068. {
  1069. { "alphamultiply", BLENDALPHA_MULTIPLY },
  1070. { "premultiplied", BLENDALPHA_PREMULTIPLIED },
  1071. };
  1072. StringMap<Graphics::BlendAlpha, Graphics::BLENDALPHA_MAX_ENUM> Graphics::blendAlphaModes(Graphics::blendAlphaEntries, sizeof(Graphics::blendAlphaEntries));
  1073. StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM>::Entry Graphics::lineStyleEntries[] =
  1074. {
  1075. { "smooth", LINE_SMOOTH },
  1076. { "rough", LINE_ROUGH }
  1077. };
  1078. StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM> Graphics::lineStyles(Graphics::lineStyleEntries, sizeof(Graphics::lineStyleEntries));
  1079. StringMap<Graphics::LineJoin, Graphics::LINE_JOIN_MAX_ENUM>::Entry Graphics::lineJoinEntries[] =
  1080. {
  1081. { "none", LINE_JOIN_NONE },
  1082. { "miter", LINE_JOIN_MITER },
  1083. { "bevel", LINE_JOIN_BEVEL }
  1084. };
  1085. StringMap<Graphics::LineJoin, Graphics::LINE_JOIN_MAX_ENUM> Graphics::lineJoins(Graphics::lineJoinEntries, sizeof(Graphics::lineJoinEntries));
  1086. StringMap<Graphics::Feature, Graphics::FEATURE_MAX_ENUM>::Entry Graphics::featureEntries[] =
  1087. {
  1088. { "multicanvasformats", FEATURE_MULTI_CANVAS_FORMATS },
  1089. { "clampzero", FEATURE_CLAMP_ZERO },
  1090. { "lighten", FEATURE_LIGHTEN },
  1091. { "fullnpot", FEATURE_FULL_NPOT },
  1092. { "pixelshaderhighp", FEATURE_PIXEL_SHADER_HIGHP },
  1093. { "arraytexture", FEATURE_ARRAY_TEXTURE },
  1094. { "volumetexture", FEATURE_VOLUME_TEXTURE },
  1095. { "glsl3", FEATURE_GLSL3 },
  1096. { "instancing", FEATURE_INSTANCING },
  1097. };
  1098. StringMap<Graphics::Feature, Graphics::FEATURE_MAX_ENUM> Graphics::features(Graphics::featureEntries, sizeof(Graphics::featureEntries));
  1099. StringMap<Graphics::SystemLimit, Graphics::LIMIT_MAX_ENUM>::Entry Graphics::systemLimitEntries[] =
  1100. {
  1101. { "pointsize", LIMIT_POINT_SIZE },
  1102. { "texturesize", LIMIT_TEXTURE_SIZE },
  1103. { "texturelayers", LIMIT_TEXTURE_LAYERS },
  1104. { "volumetexturesize", LIMIT_VOLUME_TEXTURE_SIZE },
  1105. { "cubetexturesize", LIMIT_CUBE_TEXTURE_SIZE },
  1106. { "multicanvas", LIMIT_MULTI_CANVAS },
  1107. { "canvasmsaa", LIMIT_CANVAS_MSAA },
  1108. { "anisotropy", LIMIT_ANISOTROPY },
  1109. };
  1110. StringMap<Graphics::SystemLimit, Graphics::LIMIT_MAX_ENUM> Graphics::systemLimits(Graphics::systemLimitEntries, sizeof(Graphics::systemLimitEntries));
  1111. StringMap<Graphics::StackType, Graphics::STACK_MAX_ENUM>::Entry Graphics::stackTypeEntries[] =
  1112. {
  1113. { "all", STACK_ALL },
  1114. { "transform", STACK_TRANSFORM },
  1115. };
  1116. StringMap<Graphics::StackType, Graphics::STACK_MAX_ENUM> Graphics::stackTypes(Graphics::stackTypeEntries, sizeof(Graphics::stackTypeEntries));
  1117. } // graphics
  1118. } // love