Graphics.cpp 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  1. /**
  2. * Copyright (c) 2006-2015 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 "common/config.h"
  22. #include "common/math.h"
  23. #include "common/Vector.h"
  24. #include "Graphics.h"
  25. #include "window/sdl/Window.h"
  26. #include "font/Font.h"
  27. #include "Polyline.h"
  28. // C++
  29. #include <vector>
  30. #include <sstream>
  31. #include <algorithm>
  32. #include <iterator>
  33. // C
  34. #include <cmath>
  35. #include <cstdio>
  36. namespace love
  37. {
  38. namespace graphics
  39. {
  40. namespace opengl
  41. {
  42. Graphics::Graphics()
  43. : width(0)
  44. , height(0)
  45. , created(false)
  46. , writingToStencil(false)
  47. {
  48. gl = OpenGL();
  49. states.reserve(10);
  50. states.push_back(DisplayState());
  51. currentWindow = love::window::sdl::Window::createSingleton();
  52. int w, h;
  53. love::window::WindowSettings wsettings;
  54. currentWindow->getWindow(w, h, wsettings);
  55. if (currentWindow->isCreated())
  56. setMode(w, h, wsettings.sRGB);
  57. }
  58. Graphics::~Graphics()
  59. {
  60. // We do this manually so the love objects get released before the window.
  61. states.clear();
  62. defaultFont.set(nullptr);
  63. if (Shader::defaultShader)
  64. {
  65. Shader::defaultShader->release();
  66. Shader::defaultShader = nullptr;
  67. }
  68. currentWindow->release();
  69. }
  70. const char *Graphics::getName() const
  71. {
  72. return "love.graphics.opengl";
  73. }
  74. void Graphics::restoreState(const DisplayState &s)
  75. {
  76. setColor(s.color);
  77. setBackgroundColor(s.backgroundColor);
  78. setBlendMode(s.blendMode);
  79. setLineWidth(s.lineWidth);
  80. setLineStyle(s.lineStyle);
  81. setLineJoin(s.lineJoin);
  82. setPointSize(s.pointSize);
  83. if (s.scissor)
  84. setScissor(s.scissorBox.x, s.scissorBox.y, s.scissorBox.w, s.scissorBox.h);
  85. else
  86. setScissor();
  87. setStencilTest(s.stencilTest, s.stencilInvert);
  88. setFont(s.font.get());
  89. setShader(s.shader.get());
  90. setCanvas(s.canvases);
  91. setColorMask(s.colorMask);
  92. setWireframe(s.wireframe);
  93. setDefaultFilter(s.defaultFilter);
  94. setDefaultMipmapFilter(s.defaultMipmapFilter, s.defaultMipmapSharpness);
  95. }
  96. void Graphics::restoreStateChecked(const DisplayState &s)
  97. {
  98. const DisplayState &cur = states.back();
  99. if (*(uint32 *) &s.color.r != *(uint32 *) &cur.color.r)
  100. setColor(s.color);
  101. if (*(uint32 *) &s.backgroundColor.r != *(uint32 *) &cur.backgroundColor.r)
  102. setBackgroundColor(s.backgroundColor);
  103. if (s.blendMode != cur.blendMode)
  104. setBlendMode(s.blendMode);
  105. // These are just simple assignments.
  106. setLineWidth(s.lineWidth);
  107. setLineStyle(s.lineStyle);
  108. setLineJoin(s.lineJoin);
  109. if (s.pointSize != cur.pointSize)
  110. setPointSize(s.pointSize);
  111. if (s.scissor != cur.scissor || (s.scissor && !(s.scissorBox == cur.scissorBox)))
  112. {
  113. if (s.scissor)
  114. setScissor(s.scissorBox.x, s.scissorBox.y, s.scissorBox.w, s.scissorBox.h);
  115. else
  116. setScissor();
  117. }
  118. if (s.stencilTest != cur.stencilTest || s.stencilInvert != cur.stencilInvert)
  119. setStencilTest(s.stencilTest, s.stencilInvert);
  120. setFont(s.font.get());
  121. setShader(s.shader.get());
  122. for (size_t i = 0; i < s.canvases.size() && i < cur.canvases.size(); i++)
  123. {
  124. if (s.canvases[i].get() != cur.canvases[i].get())
  125. {
  126. setCanvas(s.canvases);
  127. break;
  128. }
  129. }
  130. if (s.colorMask != cur.colorMask)
  131. setColorMask(s.colorMask);
  132. if (s.wireframe != cur.wireframe)
  133. setWireframe(s.wireframe);
  134. setDefaultFilter(s.defaultFilter);
  135. setDefaultMipmapFilter(s.defaultMipmapFilter, s.defaultMipmapSharpness);
  136. }
  137. void Graphics::checkSetDefaultFont()
  138. {
  139. // We don't create or set the default Font if an existing font is in use.
  140. if (states.back().font.get() != nullptr)
  141. return;
  142. // Create a new default font if we don't have one yet.
  143. if (!defaultFont.get())
  144. {
  145. font::Font *fontmodule = Module::getInstance<font::Font>(M_FONT);
  146. if (!fontmodule)
  147. throw love::Exception("Font module has not been loaded.");
  148. StrongRef<font::Rasterizer> r(fontmodule->newTrueTypeRasterizer(12));
  149. r->release();
  150. defaultFont.set(newFont(r.get()));
  151. defaultFont->release();
  152. }
  153. states.back().font.set(defaultFont.get());
  154. }
  155. void Graphics::setViewportSize(int width, int height)
  156. {
  157. this->width = width;
  158. this->height = height;
  159. if (!isCreated())
  160. return;
  161. // We want to affect the main screen, not any Canvas that's currently active
  162. // (not that any *should* be active when this is called.)
  163. std::vector<StrongRef<Canvas>> canvases = states.back().canvases;
  164. setCanvas();
  165. // Set the viewport to top-left corner.
  166. gl.setViewport(OpenGL::Viewport(0, 0, width, height));
  167. // If a canvas was bound before this function was called, it needs to be
  168. // made aware of the new system viewport size.
  169. Canvas::systemViewport = gl.getViewport();
  170. // Set up the projection matrix
  171. gl.matrices.projection.back() = Matrix::ortho(0.0, width, height, 0.0);
  172. // Restore the previously active Canvas.
  173. setCanvas(canvases);
  174. }
  175. bool Graphics::setMode(int width, int height, bool &sRGB)
  176. {
  177. this->width = width;
  178. this->height = height;
  179. // Okay, setup OpenGL.
  180. gl.initContext();
  181. gl.setupContext();
  182. created = true;
  183. setViewportSize(width, height);
  184. // Make sure antialiasing works when set elsewhere
  185. glEnable(GL_MULTISAMPLE);
  186. // Enable blending
  187. glEnable(GL_BLEND);
  188. // Auto-generated mipmaps should be the best quality possible
  189. glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
  190. // Enable textures
  191. if (!GLAD_ES_VERSION_2_0)
  192. glEnable(GL_TEXTURE_2D);
  193. gl.setTextureUnit(0);
  194. // Set pixel row alignment
  195. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  196. // Set whether drawing converts input from linear -> sRGB colorspace.
  197. if (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_sRGB || GLAD_EXT_framebuffer_sRGB
  198. || GLAD_ES_VERSION_3_0 || GLAD_EXT_sRGB)
  199. {
  200. if (GLAD_VERSION_1_0 || GLAD_EXT_sRGB_write_control)
  201. {
  202. if (sRGB)
  203. glEnable(GL_FRAMEBUFFER_SRGB);
  204. else
  205. glDisable(GL_FRAMEBUFFER_SRGB);
  206. }
  207. }
  208. else
  209. sRGB = false;
  210. Canvas::screenHasSRGB = sRGB;
  211. bool enabledebug = false;
  212. if (GLAD_VERSION_3_0)
  213. {
  214. // Enable OpenGL's debug output if a debug context has been created.
  215. GLint flags = 0;
  216. glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
  217. enabledebug = (flags & GL_CONTEXT_FLAG_DEBUG_BIT) != 0;
  218. }
  219. setDebug(enabledebug);
  220. // Reload all volatile objects.
  221. if (!Volatile::loadAll())
  222. ::printf("Could not reload all volatile objects.\n");
  223. // Restore the graphics state.
  224. restoreState(states.back());
  225. pixel_size_stack.clear();
  226. pixel_size_stack.reserve(5);
  227. pixel_size_stack.push_back(1);
  228. // We always need a default shader.
  229. if (!Shader::defaultShader)
  230. {
  231. Renderer renderer = GLAD_ES_VERSION_2_0 ? RENDERER_OPENGLES : RENDERER_OPENGL;
  232. Shader::defaultShader = newShader(Shader::defaultCode[renderer]);
  233. }
  234. // A shader should always be active, but the default shader shouldn't be
  235. // returned by getShader(), so we don't do setShader(defaultShader).
  236. if (!Shader::current)
  237. Shader::defaultShader->attach();
  238. return true;
  239. }
  240. void Graphics::unSetMode()
  241. {
  242. if (!isCreated())
  243. return;
  244. // Unload all volatile objects. These must be reloaded after the display
  245. // mode change.
  246. Volatile::unloadAll();
  247. gl.deInitContext();
  248. created = false;
  249. }
  250. static void APIENTRY debugCB(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /*len*/, const GLchar *msg, const GLvoid* /*usr*/)
  251. {
  252. // Human-readable strings for the debug info.
  253. const char *sourceStr = OpenGL::debugSourceString(source);
  254. const char *typeStr = OpenGL::debugTypeString(type);
  255. const char *severityStr = OpenGL::debugSeverityString(severity);
  256. const char *fmt = "OpenGL: %s [source=%s, type=%s, severity=%s, id=%d]\n";
  257. printf(fmt, msg, sourceStr, typeStr, severityStr, id);
  258. }
  259. void Graphics::setDebug(bool enable)
  260. {
  261. // Make sure debug output is supported. The AMD ext. is a bit different
  262. // so we don't make use of it, since AMD drivers now support KHR_debug.
  263. if (!(GLAD_VERSION_4_3 || GLAD_KHR_debug || GLAD_ARB_debug_output))
  264. return;
  265. // TODO: We don't support GL_KHR_debug in GLES yet.
  266. if (GLAD_ES_VERSION_2_0)
  267. return;
  268. // Ugly hack to reduce code duplication.
  269. if (GLAD_ARB_debug_output && !(GLAD_VERSION_4_3 || GLAD_KHR_debug))
  270. {
  271. fp_glDebugMessageCallback = (pfn_glDebugMessageCallback) fp_glDebugMessageCallbackARB;
  272. fp_glDebugMessageControl = (pfn_glDebugMessageControl) fp_glDebugMessageControlARB;
  273. }
  274. if (!enable)
  275. {
  276. // Disable the debug callback function.
  277. glDebugMessageCallback(nullptr, nullptr);
  278. // We can disable debug output entirely with KHR_debug.
  279. if (GLAD_VERSION_4_3 || GLAD_KHR_debug)
  280. glDisable(GL_DEBUG_OUTPUT);
  281. return;
  282. }
  283. // We don't want asynchronous debug output.
  284. glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
  285. glDebugMessageCallback(debugCB, nullptr);
  286. // Initially, enable everything.
  287. glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, GL_TRUE);
  288. // Disable messages about deprecated OpenGL functionality.
  289. glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR, GL_DONT_CARE, 0, 0, GL_FALSE);
  290. glDebugMessageControl(GL_DEBUG_SOURCE_SHADER_COMPILER, GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR, GL_DONT_CARE, 0, 0, GL_FALSE);
  291. if (GLAD_VERSION_4_3 || GLAD_KHR_debug)
  292. glEnable(GL_DEBUG_OUTPUT);
  293. ::printf("OpenGL debug output enabled (LOVE_GRAPHICS_DEBUG=1)\n");
  294. }
  295. void Graphics::reset()
  296. {
  297. DisplayState s;
  298. drawToStencilBuffer(false);
  299. restoreState(s);
  300. origin();
  301. }
  302. void Graphics::clear(ClearType type)
  303. {
  304. GLbitfield mask = 0;
  305. switch (type)
  306. {
  307. case CLEAR_ALL:
  308. default:
  309. mask = GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
  310. break;
  311. case CLEAR_STENCIL:
  312. mask = GL_STENCIL_BUFFER_BIT;
  313. break;
  314. }
  315. glClear(mask);
  316. }
  317. void Graphics::present()
  318. {
  319. // Make sure we don't have a canvas active.
  320. std::vector<StrongRef<Canvas>> canvases = states.back().canvases;
  321. setCanvas();
  322. if (GLAD_ES_VERSION_3_0 || GLAD_EXT_discard_framebuffer)
  323. {
  324. GLenum attachments[] = {GL_STENCIL, GL_DEPTH};
  325. if (gl.getDefaultFBO() != 0)
  326. {
  327. // A non-zero FBO needs different attachment enums.
  328. attachments[0] = GL_STENCIL_ATTACHMENT;
  329. attachments[1] = GL_DEPTH_ATTACHMENT;
  330. }
  331. // Hint for the driver that it doesn't need to save these buffers.
  332. if (GLAD_ES_VERSION_3_0)
  333. glInvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments);
  334. else if (GLAD_EXT_discard_framebuffer)
  335. glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments);
  336. }
  337. currentWindow->swapBuffers();
  338. // Restore the currently active canvas, if there is one.
  339. setCanvas(canvases);
  340. // Reset the per-frame stat counts.
  341. gl.stats.drawCalls = 0;
  342. Canvas::switchCount = 0;
  343. }
  344. int Graphics::getWidth() const
  345. {
  346. return width;
  347. }
  348. int Graphics::getHeight() const
  349. {
  350. return height;
  351. }
  352. bool Graphics::isCreated() const
  353. {
  354. return created;
  355. }
  356. void Graphics::setScissor(int x, int y, int width, int height)
  357. {
  358. OpenGL::Viewport box(x, y, width, height);
  359. states.back().scissor = true;
  360. glEnable(GL_SCISSOR_TEST);
  361. // OpenGL's reversed y-coordinate is compensated for in OpenGL::setScissor.
  362. gl.setScissor(box);
  363. states.back().scissorBox = box;
  364. }
  365. void Graphics::setScissor()
  366. {
  367. states.back().scissor = false;
  368. glDisable(GL_SCISSOR_TEST);
  369. }
  370. bool Graphics::getScissor(int &x, int &y, int &width, int &height) const
  371. {
  372. OpenGL::Viewport scissor = gl.getScissor();
  373. x = scissor.x;
  374. y = scissor.y;
  375. width = scissor.w;
  376. height = scissor.h;
  377. return states.back().scissor;
  378. }
  379. void Graphics::drawToStencilBuffer(bool enable)
  380. {
  381. if (writingToStencil == enable)
  382. return;
  383. writingToStencil = enable;
  384. if (!enable)
  385. {
  386. const DisplayState &state = states.back();
  387. // Revert the color write mask.
  388. setColorMask(state.colorMask);
  389. // Use the user-set stencil test state when writes are disabled.
  390. setStencilTest(state.stencilTest, state.stencilInvert);
  391. return;
  392. }
  393. // Make sure the active canvas has a stencil buffer.
  394. if (Canvas::current)
  395. Canvas::current->checkCreateStencil();
  396. // Disable color writes but don't save the state for it.
  397. glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
  398. // The stencil test must be enabled in order to write to the stencil buffer.
  399. glEnable(GL_STENCIL_TEST);
  400. glStencilFunc(GL_ALWAYS, 1, 1);
  401. glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
  402. }
  403. void Graphics::setStencilTest(bool enable, bool invert)
  404. {
  405. DisplayState &state = states.back();
  406. state.stencilTest = enable;
  407. state.stencilInvert = invert;
  408. if (writingToStencil)
  409. return;
  410. if (!enable)
  411. {
  412. glDisable(GL_STENCIL_TEST);
  413. return;
  414. }
  415. // Make sure the active canvas has a stencil buffer.
  416. if (Canvas::current)
  417. Canvas::current->checkCreateStencil();
  418. glEnable(GL_STENCIL_TEST);
  419. glStencilFunc(GL_EQUAL, invert ? 0 : 1, 1);
  420. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  421. }
  422. void Graphics::getStencilTest(bool &enable, bool &invert)
  423. {
  424. const DisplayState &state = states.back();
  425. enable = state.stencilTest;
  426. invert = state.stencilInvert;
  427. }
  428. Image *Graphics::newImage(love::image::ImageData *data, const Image::Flags &flags)
  429. {
  430. // Create the image.
  431. Image *image = new Image(data, flags);
  432. if (!isCreated())
  433. return image;
  434. bool success = false;
  435. try
  436. {
  437. success = image->load();
  438. }
  439. catch(love::Exception &)
  440. {
  441. image->release();
  442. throw;
  443. }
  444. if (!success)
  445. {
  446. image->release();
  447. return nullptr;
  448. }
  449. return image;
  450. }
  451. Image *Graphics::newImage(love::image::CompressedData *cdata, const Image::Flags &flags)
  452. {
  453. // Create the image.
  454. Image *image = new Image(cdata, flags);
  455. if (!isCreated())
  456. return image;
  457. bool success = false;
  458. try
  459. {
  460. success = image->load();
  461. }
  462. catch(love::Exception &)
  463. {
  464. image->release();
  465. throw;
  466. }
  467. if (!success)
  468. {
  469. image->release();
  470. return nullptr;
  471. }
  472. return image;
  473. }
  474. Quad *Graphics::newQuad(Quad::Viewport v, float sw, float sh)
  475. {
  476. return new Quad(v, sw, sh);
  477. }
  478. Font *Graphics::newFont(love::font::Rasterizer *r, const Texture::Filter &filter)
  479. {
  480. return new Font(r, filter);
  481. }
  482. SpriteBatch *Graphics::newSpriteBatch(Texture *texture, int size, int usage)
  483. {
  484. return new SpriteBatch(texture, size, usage);
  485. }
  486. ParticleSystem *Graphics::newParticleSystem(Texture *texture, int size)
  487. {
  488. return new ParticleSystem(texture, size);
  489. }
  490. Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int msaa)
  491. {
  492. if (!Canvas::isFormatSupported(format))
  493. {
  494. const char *fstr = "rgba8";
  495. Canvas::getConstant(format, fstr);
  496. throw love::Exception("The %s canvas format is not supported by your OpenGL implementation.", fstr);
  497. }
  498. if (width > gl.getMaxTextureSize())
  499. throw Exception("Cannot create canvas: width of %d pixels is too large for this system.", width);
  500. else if (height > gl.getMaxTextureSize())
  501. throw Exception("Cannot create canvas: height of %d pixels is too large for this system.", height);
  502. while (GL_NO_ERROR != glGetError())
  503. /* clear opengl error flag */;
  504. Canvas *canvas = new Canvas(width, height, format, msaa);
  505. GLenum err = canvas->getStatus();
  506. // everything ok, return canvas (early out)
  507. if (err == GL_FRAMEBUFFER_COMPLETE)
  508. return canvas;
  509. // create error message
  510. std::stringstream error_string;
  511. error_string << "Cannot create canvas: ";
  512. switch (err)
  513. {
  514. case GL_FRAMEBUFFER_UNSUPPORTED:
  515. error_string << "Not supported by your OpenGL implementation.";
  516. break;
  517. // remaining error codes are highly unlikely:
  518. case GL_FRAMEBUFFER_UNDEFINED:
  519. case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
  520. case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
  521. case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
  522. case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
  523. case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
  524. error_string << "Error in implementation. Possible fix: Make canvas width and height powers of two.";
  525. break;
  526. default:
  527. // my intel hda card wrongly returns 0 to glCheckFramebufferStatus() but sets
  528. // no error flag. I think it meant to return GL_FRAMEBUFFER_UNSUPPORTED, but who
  529. // knows.
  530. if (glGetError() == GL_NO_ERROR)
  531. error_string << "May not be supported by your OpenGL implementation.";
  532. // the remaining error is an indication of a serious fuckup since it should
  533. // only be returned if glCheckFramebufferStatus() was called with the wrong
  534. // arguments.
  535. else
  536. error_string << "Cannot create canvas: Aliens did it (OpenGL error code: " << glGetError() << ")";
  537. }
  538. canvas->release();
  539. throw Exception("%s", error_string.str().c_str());
  540. return nullptr; // never reached
  541. }
  542. Shader *Graphics::newShader(const Shader::ShaderSource &source)
  543. {
  544. return new Shader(source);
  545. }
  546. Mesh *Graphics::newMesh(const std::vector<Vertex> &vertices, Mesh::DrawMode mode)
  547. {
  548. return new Mesh(vertices, mode);
  549. }
  550. Mesh *Graphics::newMesh(int vertexcount, Mesh::DrawMode mode)
  551. {
  552. return new Mesh(vertexcount, mode);
  553. }
  554. Text *Graphics::newText(Font *font, const std::string &text)
  555. {
  556. return new Text(font, text);
  557. }
  558. void Graphics::setColor(const Color &c)
  559. {
  560. gl.setColor(c);
  561. states.back().color = c;
  562. }
  563. Color Graphics::getColor() const
  564. {
  565. return states.back().color;
  566. }
  567. void Graphics::setBackgroundColor(const Color &c)
  568. {
  569. gl.setClearColor(c);
  570. states.back().backgroundColor = c;
  571. }
  572. Color Graphics::getBackgroundColor() const
  573. {
  574. return states.back().backgroundColor;
  575. }
  576. void Graphics::setFont(Font *font)
  577. {
  578. // We don't need to set a default font here if null is passed in, since we
  579. // only care about the default font in getFont and print.
  580. DisplayState &state = states.back();
  581. state.font.set(font);
  582. }
  583. Font *Graphics::getFont()
  584. {
  585. checkSetDefaultFont();
  586. return states.back().font.get();
  587. }
  588. void Graphics::setShader(Shader *shader)
  589. {
  590. if (shader == nullptr)
  591. return setShader();
  592. DisplayState &state = states.back();
  593. shader->attach();
  594. state.shader.set(shader);
  595. }
  596. void Graphics::setShader()
  597. {
  598. DisplayState &state = states.back();
  599. // This will activate the default shader.
  600. Shader::detach();
  601. state.shader.set(nullptr);
  602. }
  603. Shader *Graphics::getShader() const
  604. {
  605. return states.back().shader.get();
  606. }
  607. void Graphics::setCanvas(Canvas *canvas)
  608. {
  609. if (canvas == nullptr)
  610. return setCanvas();
  611. DisplayState &state = states.back();
  612. canvas->startGrab();
  613. std::vector<StrongRef<Canvas>> canvasref;
  614. canvasref.push_back(canvas);
  615. std::swap(state.canvases, canvasref);
  616. }
  617. void Graphics::setCanvas(const std::vector<Canvas *> &canvases)
  618. {
  619. if (canvases.size() == 0)
  620. return setCanvas();
  621. else if (canvases.size() == 1)
  622. return setCanvas(canvases[0]);
  623. DisplayState &state = states.back();
  624. auto attachments = std::vector<Canvas *>(canvases.begin() + 1, canvases.end());
  625. canvases[0]->startGrab(attachments);
  626. std::vector<StrongRef<Canvas>> canvasrefs;
  627. canvasrefs.reserve(canvases.size());
  628. for (Canvas *c : canvases)
  629. canvasrefs.push_back(c);
  630. std::swap(state.canvases, canvasrefs);
  631. }
  632. void Graphics::setCanvas(const std::vector<StrongRef<Canvas>> &canvases)
  633. {
  634. std::vector<Canvas *> canvaslist;
  635. canvaslist.reserve(canvases.size());
  636. for (const StrongRef<Canvas> &c : canvases)
  637. canvaslist.push_back(c.get());
  638. return setCanvas(canvaslist);
  639. }
  640. void Graphics::setCanvas()
  641. {
  642. DisplayState &state = states.back();
  643. if (Canvas::current != nullptr)
  644. Canvas::current->stopGrab();
  645. state.canvases.clear();
  646. }
  647. std::vector<Canvas *> Graphics::getCanvas() const
  648. {
  649. std::vector<Canvas *> canvases;
  650. canvases.reserve(states.back().canvases.size());
  651. for (const StrongRef<Canvas> &c : states.back().canvases)
  652. canvases.push_back(c.get());
  653. return canvases;
  654. }
  655. void Graphics::setColorMask(ColorMask mask)
  656. {
  657. glColorMask(mask.r, mask.g, mask.b, mask.a);
  658. }
  659. Graphics::ColorMask Graphics::getColorMask() const
  660. {
  661. return states.back().colorMask;
  662. }
  663. void Graphics::setBlendMode(Graphics::BlendMode mode)
  664. {
  665. OpenGL::BlendState blend = {GL_ONE, GL_ONE, GL_ZERO, GL_ZERO, GL_FUNC_ADD};
  666. switch (mode)
  667. {
  668. case BLEND_ALPHA:
  669. blend.srcRGB = GL_SRC_ALPHA;
  670. blend.srcA = GL_ONE;
  671. blend.dstRGB = blend.dstA = GL_ONE_MINUS_SRC_ALPHA;
  672. break;
  673. case BLEND_MULTIPLY:
  674. blend.srcRGB = blend.srcA = GL_DST_COLOR;
  675. blend.dstRGB = blend.dstA = GL_ZERO;
  676. break;
  677. case BLEND_PREMULTIPLIED:
  678. blend.srcRGB = blend.srcA = GL_ONE;
  679. blend.dstRGB = blend.dstA = GL_ONE_MINUS_SRC_ALPHA;
  680. break;
  681. case BLEND_SUBTRACT:
  682. blend.func = GL_FUNC_REVERSE_SUBTRACT;
  683. case BLEND_ADD:
  684. blend.srcRGB = blend.srcA = GL_SRC_ALPHA;
  685. blend.dstRGB = blend.dstA = GL_ONE;
  686. break;
  687. case BLEND_SCREEN:
  688. blend.srcRGB = blend.srcA = GL_ONE;
  689. blend.dstRGB = blend.dstA = GL_ONE_MINUS_SRC_COLOR;
  690. break;
  691. case BLEND_REPLACE:
  692. default:
  693. blend.srcRGB = blend.srcA = GL_ONE;
  694. blend.dstRGB = blend.dstA = GL_ZERO;
  695. break;
  696. }
  697. gl.setBlendState(blend);
  698. states.back().blendMode = mode;
  699. }
  700. Graphics::BlendMode Graphics::getBlendMode() const
  701. {
  702. return states.back().blendMode;
  703. }
  704. void Graphics::setDefaultFilter(const Texture::Filter &f)
  705. {
  706. Texture::setDefaultFilter(f);
  707. states.back().defaultFilter = f;
  708. }
  709. const Texture::Filter &Graphics::getDefaultFilter() const
  710. {
  711. return Texture::getDefaultFilter();
  712. }
  713. void Graphics::setDefaultMipmapFilter(Texture::FilterMode filter, float sharpness)
  714. {
  715. Image::setDefaultMipmapFilter(filter);
  716. Image::setDefaultMipmapSharpness(sharpness);
  717. states.back().defaultMipmapFilter = filter;
  718. states.back().defaultMipmapSharpness = sharpness;
  719. }
  720. void Graphics::getDefaultMipmapFilter(Texture::FilterMode *filter, float *sharpness) const
  721. {
  722. *filter = Image::getDefaultMipmapFilter();
  723. *sharpness = Image::getDefaultMipmapSharpness();
  724. }
  725. void Graphics::setLineWidth(float width)
  726. {
  727. states.back().lineWidth = width;
  728. }
  729. void Graphics::setLineStyle(Graphics::LineStyle style)
  730. {
  731. states.back().lineStyle = style;
  732. }
  733. void Graphics::setLineJoin(Graphics::LineJoin join)
  734. {
  735. states.back().lineJoin = join;
  736. }
  737. float Graphics::getLineWidth() const
  738. {
  739. return states.back().lineWidth;
  740. }
  741. Graphics::LineStyle Graphics::getLineStyle() const
  742. {
  743. return states.back().lineStyle;
  744. }
  745. Graphics::LineJoin Graphics::getLineJoin() const
  746. {
  747. return states.back().lineJoin;
  748. }
  749. void Graphics::setPointSize(float size)
  750. {
  751. gl.setPointSize(size);
  752. states.back().pointSize = size;
  753. }
  754. float Graphics::getPointSize() const
  755. {
  756. return states.back().pointSize;
  757. }
  758. void Graphics::setWireframe(bool enable)
  759. {
  760. // Not supported in OpenGL ES.
  761. if (GLAD_ES_VERSION_2_0)
  762. return;
  763. glPolygonMode(GL_FRONT_AND_BACK, enable ? GL_LINE : GL_FILL);
  764. states.back().wireframe = enable;
  765. }
  766. bool Graphics::isWireframe() const
  767. {
  768. return states.back().wireframe;
  769. }
  770. void Graphics::print(const std::string &str, float x, float y , float angle, float sx, float sy, float ox, float oy, float kx, float ky)
  771. {
  772. checkSetDefaultFont();
  773. DisplayState &state = states.back();
  774. if (state.font.get() != nullptr)
  775. state.font->print(str, x, y, angle, sx, sy, ox, oy, kx, ky);
  776. }
  777. void Graphics::printf(const std::string &str, float x, float y, float wrap, Font::AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
  778. {
  779. checkSetDefaultFont();
  780. DisplayState &state = states.back();
  781. if (state.font.get() != nullptr)
  782. state.font->printf(str, x, y, wrap, align, angle, sx, sy, ox, oy, kx, ky);
  783. }
  784. /**
  785. * Primitives
  786. **/
  787. void Graphics::point(float x, float y)
  788. {
  789. GLfloat coord[] = {x, y};
  790. gl.prepareDraw();
  791. gl.bindTexture(gl.getDefaultTexture());
  792. glEnableVertexAttribArray(ATTRIB_POS);
  793. glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, coord);
  794. gl.drawArrays(GL_POINTS, 0, 1);
  795. glDisableVertexAttribArray(ATTRIB_POS);
  796. }
  797. void Graphics::polyline(const float *coords, size_t count)
  798. {
  799. DisplayState &state = states.back();
  800. if (state.lineJoin == LINE_JOIN_NONE)
  801. {
  802. NoneJoinPolyline line;
  803. line.render(coords, count, state.lineWidth * .5f, float(pixel_size_stack.back()), state.lineStyle == LINE_SMOOTH);
  804. line.draw();
  805. }
  806. else if (state.lineJoin == LINE_JOIN_BEVEL)
  807. {
  808. BevelJoinPolyline line;
  809. line.render(coords, count, state.lineWidth * .5f, float(pixel_size_stack.back()), state.lineStyle == LINE_SMOOTH);
  810. line.draw();
  811. }
  812. else // LINE_JOIN_MITER
  813. {
  814. MiterJoinPolyline line;
  815. line.render(coords, count, state.lineWidth * .5f, float(pixel_size_stack.back()), state.lineStyle == LINE_SMOOTH);
  816. line.draw();
  817. }
  818. }
  819. void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h)
  820. {
  821. float coords[] = {x,y, x,y+h, x+w,y+h, x+w,y, x,y};
  822. polygon(mode, coords, 5 * 2);
  823. }
  824. void Graphics::circle(DrawMode mode, float x, float y, float radius, int points)
  825. {
  826. float two_pi = static_cast<float>(LOVE_M_PI * 2);
  827. if (points <= 0) points = 1;
  828. float angle_shift = (two_pi / points);
  829. float phi = .0f;
  830. float *coords = new float[2 * (points + 1)];
  831. for (int i = 0; i < points; ++i, phi += angle_shift)
  832. {
  833. coords[2*i] = x + radius * cosf(phi);
  834. coords[2*i+1] = y + radius * sinf(phi);
  835. }
  836. coords[2*points] = coords[0];
  837. coords[2*points+1] = coords[1];
  838. polygon(mode, coords, (points + 1) * 2);
  839. delete[] coords;
  840. }
  841. void Graphics::arc(DrawMode mode, float x, float y, float radius, float angle1, float angle2, int points)
  842. {
  843. // Nothing to display with no points or equal angles. (Or is there with line mode?)
  844. if (points <= 0 || angle1 == angle2)
  845. return;
  846. // Oh, you want to draw a circle?
  847. if (fabs(angle1 - angle2) >= 2.0f * (float) LOVE_M_PI)
  848. {
  849. circle(mode, x, y, radius, points);
  850. return;
  851. }
  852. float angle_shift = (angle2 - angle1) / points;
  853. // Bail on precision issues.
  854. if (angle_shift == 0.0)
  855. return;
  856. float phi = angle1;
  857. int num_coords = (points + 3) * 2;
  858. float *coords = new float[num_coords];
  859. coords[0] = coords[num_coords - 2] = x;
  860. coords[1] = coords[num_coords - 1] = y;
  861. for (int i = 0; i <= points; ++i, phi += angle_shift)
  862. {
  863. coords[2 * (i+1)] = x + radius * cosf(phi);
  864. coords[2 * (i+1) + 1] = y + radius * sinf(phi);
  865. }
  866. // GL_POLYGON can only fill-draw convex polygons, so we need to do stuff manually here
  867. if (mode == DRAW_LINE)
  868. {
  869. polyline(coords, num_coords); // Artifacts at sharp angles if set to looping.
  870. }
  871. else
  872. {
  873. gl.prepareDraw();
  874. gl.bindTexture(gl.getDefaultTexture());
  875. glEnableVertexAttribArray(ATTRIB_POS);
  876. glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, coords);
  877. gl.drawArrays(GL_TRIANGLE_FAN, 0, points + 2);
  878. glDisableVertexAttribArray(ATTRIB_POS);
  879. }
  880. delete[] coords;
  881. }
  882. /// @param mode the draw mode
  883. /// @param coords the coordinate array
  884. /// @param count the number of coordinates/size of the array
  885. void Graphics::polygon(DrawMode mode, const float *coords, size_t count)
  886. {
  887. // coords is an array of a closed loop of vertices, i.e.
  888. // coords[count-2] = coords[0], coords[count-1] = coords[1]
  889. if (mode == DRAW_LINE)
  890. {
  891. polyline(coords, count);
  892. }
  893. else
  894. {
  895. gl.prepareDraw();
  896. gl.bindTexture(gl.getDefaultTexture());
  897. glEnableVertexAttribArray(ATTRIB_POS);
  898. glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, coords);
  899. gl.drawArrays(GL_TRIANGLE_FAN, 0, count/2-1); // opengl will close the polygon for us
  900. glDisableVertexAttribArray(ATTRIB_POS);
  901. }
  902. }
  903. love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool copyAlpha)
  904. {
  905. // Temporarily unbind the currently active canvas (glReadPixels reads the
  906. // active framebuffer, not the main one.)
  907. std::vector<StrongRef<Canvas>> canvases = states.back().canvases;
  908. setCanvas();
  909. int w = getWidth();
  910. int h = getHeight();
  911. int row = 4 * w;
  912. int size = row * h;
  913. GLubyte *pixels = nullptr;
  914. GLubyte *screenshot = nullptr;
  915. try
  916. {
  917. pixels = new GLubyte[size];
  918. screenshot = new GLubyte[size];
  919. }
  920. catch (std::exception &)
  921. {
  922. delete[] pixels;
  923. delete[] screenshot;
  924. setCanvas(canvases);
  925. throw love::Exception("Out of memory.");
  926. }
  927. glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
  928. if (!copyAlpha)
  929. {
  930. // Replace alpha values with full opacity.
  931. for (int i = 3; i < size; i += 4)
  932. pixels[i] = 255;
  933. }
  934. // OpenGL sucks and reads pixels from the lower-left. Let's fix that.
  935. GLubyte *src = pixels - row;
  936. GLubyte *dst = screenshot + size;
  937. for (int i = 0; i < h; ++i)
  938. memcpy(dst-=row, src+=row, row);
  939. delete[] pixels;
  940. love::image::ImageData *img = nullptr;
  941. try
  942. {
  943. // Tell the new ImageData that it owns the screenshot data, so we don't
  944. // need to delete it here.
  945. img = image->newImageData(w, h, (void *) screenshot, true);
  946. }
  947. catch (love::Exception &)
  948. {
  949. delete[] screenshot;
  950. setCanvas(canvases);
  951. throw;
  952. }
  953. // Re-bind the active canvas, if necessary.
  954. setCanvas(canvases);
  955. return img;
  956. }
  957. Graphics::RendererInfo Graphics::getRendererInfo() const
  958. {
  959. RendererInfo info;
  960. if (GLAD_ES_VERSION_2_0)
  961. info.name = "OpenGL ES";
  962. else
  963. info.name = "OpenGL";
  964. const char *str = (const char *) glGetString(GL_VERSION);
  965. if (str)
  966. info.version = str;
  967. else
  968. throw love::Exception("Cannot retrieve renderer version information.");
  969. str = (const char *) glGetString(GL_VENDOR);
  970. if (str)
  971. info.vendor = str;
  972. else
  973. throw love::Exception("Cannot retrieve renderer vendor information.");
  974. str = (const char *) glGetString(GL_RENDERER);
  975. if (str)
  976. info.device = str;
  977. else
  978. throw love::Exception("Cannot retrieve renderer device information.");
  979. return info;
  980. }
  981. Graphics::Stats Graphics::getStats() const
  982. {
  983. Stats stats;
  984. stats.drawCalls = gl.stats.drawCalls;
  985. stats.canvasSwitches = Canvas::switchCount;
  986. stats.canvases = Canvas::canvasCount;
  987. stats.images = Image::imageCount;
  988. stats.fonts = Font::fontCount;
  989. stats.textureMemory = gl.stats.textureMemory;
  990. return stats;
  991. }
  992. double Graphics::getSystemLimit(SystemLimit limittype) const
  993. {
  994. double limit = 0.0;
  995. switch (limittype)
  996. {
  997. case Graphics::LIMIT_POINT_SIZE:
  998. {
  999. GLfloat limits[2];
  1000. glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, limits);
  1001. limit = limits[1];
  1002. }
  1003. break;
  1004. case Graphics::LIMIT_TEXTURE_SIZE:
  1005. limit = (double) gl.getMaxTextureSize();
  1006. break;
  1007. case Graphics::LIMIT_MULTI_CANVAS:
  1008. limit = (double) gl.getMaxRenderTargets();
  1009. break;
  1010. case Graphics::LIMIT_CANVAS_MSAA:
  1011. if (GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_object
  1012. || GLAD_EXT_framebuffer_multisample)
  1013. {
  1014. GLint intlimit = 0;
  1015. glGetIntegerv(GL_MAX_SAMPLES, &intlimit);
  1016. limit = (double) intlimit;
  1017. }
  1018. break;
  1019. default:
  1020. break;
  1021. }
  1022. return limit;
  1023. }
  1024. bool Graphics::isSupported(Support feature) const
  1025. {
  1026. switch (feature)
  1027. {
  1028. case SUPPORT_MULTI_CANVAS:
  1029. return Canvas::isMultiCanvasSupported();
  1030. case SUPPORT_SRGB:
  1031. // sRGB support for the screen is guaranteed if it's supported as a
  1032. // Canvas format.
  1033. return Canvas::isFormatSupported(Canvas::FORMAT_SRGB);
  1034. default:
  1035. return false;
  1036. }
  1037. }
  1038. void Graphics::push(StackType type)
  1039. {
  1040. if (stackTypes.size() == MAX_USER_STACK_DEPTH)
  1041. throw Exception("Maximum stack depth reached (more pushes than pops?)");
  1042. gl.pushTransform();
  1043. pixel_size_stack.push_back(pixel_size_stack.back());
  1044. if (type == STACK_ALL)
  1045. states.push_back(states.back());
  1046. stackTypes.push_back(type);
  1047. }
  1048. void Graphics::pop()
  1049. {
  1050. if (stackTypes.size() < 1)
  1051. throw Exception("Minimum stack depth reached (more pops than pushes?)");
  1052. gl.popTransform();
  1053. pixel_size_stack.pop_back();
  1054. if (stackTypes.back() == STACK_ALL)
  1055. {
  1056. DisplayState &newstate = states[states.size() - 2];
  1057. restoreStateChecked(newstate);
  1058. // The last two states in the stack should be equal now.
  1059. states.pop_back();
  1060. }
  1061. stackTypes.pop_back();
  1062. }
  1063. void Graphics::rotate(float r)
  1064. {
  1065. gl.getTransform().rotate(r);
  1066. }
  1067. void Graphics::scale(float x, float y)
  1068. {
  1069. gl.getTransform().scale(x, y);
  1070. pixel_size_stack.back() *= 2. / (fabs(x) + fabs(y));
  1071. }
  1072. void Graphics::translate(float x, float y)
  1073. {
  1074. gl.getTransform().translate(x, y);
  1075. }
  1076. void Graphics::shear(float kx, float ky)
  1077. {
  1078. gl.getTransform().setShear(kx, ky);
  1079. }
  1080. void Graphics::origin()
  1081. {
  1082. gl.getTransform().setIdentity();
  1083. pixel_size_stack.back() = 1;
  1084. }
  1085. Graphics::DisplayState::DisplayState()
  1086. : color(255, 255, 255, 255)
  1087. , backgroundColor(0, 0, 0, 255)
  1088. , blendMode(BLEND_ALPHA)
  1089. , lineWidth(1.0f)
  1090. , lineStyle(LINE_SMOOTH)
  1091. , lineJoin(LINE_JOIN_MITER)
  1092. , pointSize(1.0f)
  1093. , scissor(false)
  1094. , scissorBox()
  1095. , stencilTest(false)
  1096. , stencilInvert(false)
  1097. , font(nullptr)
  1098. , shader(nullptr)
  1099. , colorMask({true, true, true, true})
  1100. , wireframe(false)
  1101. , defaultFilter()
  1102. , defaultMipmapFilter(Texture::FILTER_NEAREST)
  1103. , defaultMipmapSharpness(0.0f)
  1104. {
  1105. }
  1106. Graphics::DisplayState::DisplayState(const DisplayState &other)
  1107. : color(other.color)
  1108. , backgroundColor(other.backgroundColor)
  1109. , blendMode(other.blendMode)
  1110. , lineWidth(other.lineWidth)
  1111. , lineStyle(other.lineStyle)
  1112. , lineJoin(other.lineJoin)
  1113. , pointSize(other.pointSize)
  1114. , scissor(other.scissor)
  1115. , scissorBox(other.scissorBox)
  1116. , stencilTest(other.stencilTest)
  1117. , stencilInvert(other.stencilInvert)
  1118. , font(other.font)
  1119. , shader(other.shader)
  1120. , canvases(other.canvases)
  1121. , colorMask(other.colorMask)
  1122. , wireframe(other.wireframe)
  1123. , defaultFilter(other.defaultFilter)
  1124. , defaultMipmapFilter(other.defaultMipmapFilter)
  1125. , defaultMipmapSharpness(other.defaultMipmapSharpness)
  1126. {
  1127. }
  1128. Graphics::DisplayState::~DisplayState()
  1129. {
  1130. }
  1131. Graphics::DisplayState &Graphics::DisplayState::operator = (const DisplayState &other)
  1132. {
  1133. color = other.color;
  1134. backgroundColor = other.backgroundColor;
  1135. blendMode = other.blendMode;
  1136. lineWidth = other.lineWidth;
  1137. lineStyle = other.lineStyle;
  1138. lineJoin = other.lineJoin;
  1139. pointSize = other.pointSize;
  1140. scissor = other.scissor;
  1141. scissorBox = other.scissorBox;
  1142. stencilTest = other.stencilTest;
  1143. stencilInvert = other.stencilInvert;
  1144. font = other.font;
  1145. shader = other.shader;
  1146. canvases = other.canvases;
  1147. colorMask = other.colorMask;
  1148. wireframe = other.wireframe;
  1149. defaultFilter = other.defaultFilter;
  1150. defaultMipmapFilter = other.defaultMipmapFilter;
  1151. defaultMipmapSharpness = other.defaultMipmapSharpness;
  1152. return *this;
  1153. }
  1154. } // opengl
  1155. } // graphics
  1156. } // love