Canvas.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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. #include "Canvas.h"
  21. #include "graphics/Graphics.h"
  22. #include <algorithm> // For min/max
  23. namespace love
  24. {
  25. namespace graphics
  26. {
  27. namespace opengl
  28. {
  29. static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat format, GLuint texture, int layers, int mips)
  30. {
  31. // get currently bound fbo to reset to it later
  32. GLuint current_fbo = gl.getFramebuffer(OpenGL::FRAMEBUFFER_ALL);
  33. glGenFramebuffers(1, &framebuffer);
  34. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, framebuffer);
  35. if (texture != 0)
  36. {
  37. bool unusedSRGB = false;
  38. OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(format, false, unusedSRGB);
  39. int faces = texType == TEXTURE_CUBE ? 6 : 1;
  40. // Make sure all faces and layers of the texture are initialized to
  41. // transparent black. This is unfortunately probably pretty slow for
  42. // 2D-array and 3D textures with a lot of layers...
  43. for (int mip = mips - 1; mip >= 0; mip--)
  44. {
  45. int nlayers = layers;
  46. if (texType == TEXTURE_VOLUME)
  47. nlayers = std::max(layers >> mip, 1);
  48. for (int layer = nlayers - 1; layer >= 0; layer--)
  49. {
  50. for (int face = faces - 1; face >= 0; face--)
  51. {
  52. for (GLenum attachment : fmt.framebufferAttachments)
  53. {
  54. if (attachment == GL_NONE)
  55. continue;
  56. gl.framebufferTexture(attachment, texType, texture, mip, layer, face);
  57. }
  58. if (isPixelFormatDepthStencil(format))
  59. {
  60. gl.clearDepth(1.0);
  61. glClearStencil(0);
  62. glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  63. }
  64. else
  65. {
  66. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  67. glClear(GL_COLOR_BUFFER_BIT);
  68. }
  69. }
  70. }
  71. }
  72. }
  73. GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
  74. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo);
  75. return status;
  76. }
  77. static bool createRenderbuffer(int width, int height, int &samples, PixelFormat pixelformat, GLuint &buffer)
  78. {
  79. int reqsamples = samples;
  80. bool unusedSRGB = false;
  81. OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(pixelformat, true, unusedSRGB);
  82. GLuint current_fbo = gl.getFramebuffer(OpenGL::FRAMEBUFFER_ALL);
  83. // Temporary FBO used to clear the renderbuffer.
  84. GLuint fbo = 0;
  85. glGenFramebuffers(1, &fbo);
  86. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, fbo);
  87. glGenRenderbuffers(1, &buffer);
  88. glBindRenderbuffer(GL_RENDERBUFFER, buffer);
  89. if (samples > 1)
  90. glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, fmt.internalformat, width, height);
  91. else
  92. glRenderbufferStorage(GL_RENDERBUFFER, fmt.internalformat, width, height);
  93. for (GLenum attachment : fmt.framebufferAttachments)
  94. {
  95. if (attachment != GL_NONE)
  96. glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, buffer);
  97. }
  98. if (samples > 1)
  99. glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, &samples);
  100. else
  101. samples = 0;
  102. glBindRenderbuffer(GL_RENDERBUFFER, 0);
  103. GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
  104. if (status == GL_FRAMEBUFFER_COMPLETE && (reqsamples <= 1 || samples > 1))
  105. {
  106. if (isPixelFormatDepthStencil(pixelformat))
  107. {
  108. gl.clearDepth(1.0);
  109. glClearStencil(0);
  110. glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  111. }
  112. else
  113. {
  114. // Initialize the buffer to transparent black.
  115. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  116. glClear(GL_COLOR_BUFFER_BIT);
  117. }
  118. }
  119. else
  120. {
  121. glDeleteRenderbuffers(1, &buffer);
  122. buffer = 0;
  123. samples = 0;
  124. }
  125. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo);
  126. gl.deleteFramebuffer(fbo);
  127. return status == GL_FRAMEBUFFER_COMPLETE;
  128. }
  129. Canvas::Canvas(const Settings &settings)
  130. : love::graphics::Canvas(settings)
  131. , fbo(0)
  132. , texture(0)
  133. , renderbuffer(0)
  134. , actualSamples(0)
  135. {
  136. format = getSizedFormat(format);
  137. initQuad();
  138. loadVolatile();
  139. if (status != GL_FRAMEBUFFER_COMPLETE)
  140. throw love::Exception("Cannot create Canvas: %s", OpenGL::framebufferStatusString(status));
  141. }
  142. Canvas::~Canvas()
  143. {
  144. unloadVolatile();
  145. }
  146. bool Canvas::loadVolatile()
  147. {
  148. if (texture != 0)
  149. return true;
  150. if (!Canvas::isSupported())
  151. throw love::Exception("Canvases are not supported by your OpenGL drivers!");
  152. if (!Canvas::isFormatSupported(format, readable))
  153. {
  154. const char *fstr = "rgba8";
  155. const char *readablestr = "";
  156. if (readable != !isPixelFormatDepthStencil(format))
  157. readablestr = readable ? " readable" : " non-readable";
  158. love::getConstant(Canvas::getSizedFormat(format), fstr);
  159. throw love::Exception("The %s%s canvas format is not supported by your OpenGL drivers.", fstr, readablestr);
  160. }
  161. if (getRequestedMSAA() > 1 && texType != TEXTURE_2D)
  162. throw love::Exception("MSAA is only supported for 2D texture types.");
  163. if (!readable && texType != TEXTURE_2D)
  164. throw love::Exception("Non-readable pixel formats are only supported for 2D texture types.");
  165. if (!gl.isTextureTypeSupported(texType))
  166. {
  167. const char *textypestr = "unknown";
  168. Texture::getConstant(texType, textypestr);
  169. throw love::Exception("%s textures are not supported on this system!", textypestr);
  170. }
  171. switch (texType)
  172. {
  173. case TEXTURE_2D:
  174. if (pixelWidth > gl.getMax2DTextureSize())
  175. throw TextureTooLargeException("width", pixelWidth);
  176. else if (pixelHeight > gl.getMax2DTextureSize())
  177. throw TextureTooLargeException("height", pixelHeight);
  178. break;
  179. case TEXTURE_VOLUME:
  180. if (pixelWidth > gl.getMax3DTextureSize())
  181. throw TextureTooLargeException("width", pixelWidth);
  182. else if (pixelHeight > gl.getMax3DTextureSize())
  183. throw TextureTooLargeException("height", pixelHeight);
  184. else if (depth > gl.getMax3DTextureSize())
  185. throw TextureTooLargeException("depth", depth);
  186. break;
  187. case TEXTURE_2D_ARRAY:
  188. if (pixelWidth > gl.getMax2DTextureSize())
  189. throw TextureTooLargeException("width", pixelWidth);
  190. else if (pixelHeight > gl.getMax2DTextureSize())
  191. throw TextureTooLargeException("height", pixelHeight);
  192. else if (layers > gl.getMaxTextureLayers())
  193. throw TextureTooLargeException("array layer count", layers);
  194. break;
  195. case TEXTURE_CUBE:
  196. if (pixelWidth != pixelHeight)
  197. throw love::Exception("Cubemap textures must have equal width and height.");
  198. else if (pixelWidth > gl.getMaxCubeTextureSize())
  199. throw TextureTooLargeException("width", pixelWidth);
  200. break;
  201. default:
  202. break;
  203. }
  204. OpenGL::TempDebugGroup debuggroup("Canvas load");
  205. fbo = texture = 0;
  206. renderbuffer = 0;
  207. status = GL_FRAMEBUFFER_COMPLETE;
  208. // getMaxRenderbufferSamples will be 0 on systems that don't support
  209. // multisampled renderbuffers / don't export FBO multisample extensions.
  210. actualSamples = getRequestedMSAA();
  211. actualSamples = std::min(actualSamples, gl.getMaxRenderbufferSamples());
  212. actualSamples = std::max(actualSamples, 0);
  213. actualSamples = actualSamples == 1 ? 0 : actualSamples;
  214. if (isReadable())
  215. {
  216. glGenTextures(1, &texture);
  217. gl.bindTextureToUnit(this, 0, false);
  218. GLenum gltype = OpenGL::getGLTextureType(texType);
  219. if (GLAD_ANGLE_texture_usage)
  220. glTexParameteri(gltype, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
  221. setFilter(filter);
  222. setWrap(wrap);
  223. setMipmapSharpness(mipmapSharpness);
  224. setDepthSampleMode(depthCompareMode);
  225. while (glGetError() != GL_NO_ERROR)
  226. /* Clear the error buffer. */;
  227. bool isSRGB = format == PIXELFORMAT_sRGBA8;
  228. if (!gl.rawTexStorage(texType, mipmapCount, format, isSRGB, pixelWidth, pixelHeight, texType == TEXTURE_VOLUME ? depth : layers))
  229. {
  230. status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
  231. return false;
  232. }
  233. if (glGetError() != GL_NO_ERROR)
  234. {
  235. gl.deleteTexture(texture);
  236. texture = 0;
  237. status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
  238. return false;
  239. }
  240. // Create a canvas-local FBO used for glReadPixels as well as MSAA blitting.
  241. status = createFBO(fbo, texType, format, texture, texType == TEXTURE_VOLUME ? depth : layers, mipmapCount);
  242. if (status != GL_FRAMEBUFFER_COMPLETE)
  243. {
  244. if (fbo != 0)
  245. {
  246. gl.deleteFramebuffer(fbo);
  247. fbo = 0;
  248. }
  249. return false;
  250. }
  251. }
  252. if (!isReadable() || actualSamples > 0)
  253. createRenderbuffer(pixelWidth, pixelHeight, actualSamples, format, renderbuffer);
  254. int64 memsize = getPixelFormatSize(format) * pixelWidth * pixelHeight;
  255. if (getMipmapCount() > 1)
  256. memsize *= 1.33334;
  257. if (actualSamples > 1 && isReadable())
  258. memsize += getPixelFormatSize(format) * pixelWidth * pixelHeight * actualSamples;
  259. else if (actualSamples > 1)
  260. memsize *= actualSamples;
  261. setGraphicsMemorySize(memsize);
  262. return true;
  263. }
  264. void Canvas::unloadVolatile()
  265. {
  266. if (fbo != 0)
  267. gl.deleteFramebuffer(fbo);
  268. if (renderbuffer != 0)
  269. glDeleteRenderbuffers(1, &renderbuffer);
  270. if (texture != 0)
  271. gl.deleteTexture(texture);
  272. fbo = 0;
  273. renderbuffer = 0;
  274. texture = 0;
  275. setGraphicsMemorySize(0);
  276. }
  277. void Canvas::setFilter(const Texture::Filter &f)
  278. {
  279. Texture::setFilter(f);
  280. if (!OpenGL::hasTextureFilteringSupport(getPixelFormat()))
  281. {
  282. filter.mag = filter.min = FILTER_NEAREST;
  283. if (filter.mipmap == FILTER_LINEAR)
  284. filter.mipmap = FILTER_NEAREST;
  285. }
  286. gl.bindTextureToUnit(this, 0, false);
  287. gl.setTextureFilter(texType, filter);
  288. }
  289. bool Canvas::setWrap(const Texture::Wrap &w)
  290. {
  291. Graphics::flushStreamDrawsGlobal();
  292. bool success = true;
  293. bool forceclamp = texType == TEXTURE_CUBE;
  294. wrap = w;
  295. // If we only have limited NPOT support then the wrap mode must be CLAMP.
  296. if ((GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot))
  297. && (pixelWidth != nextP2(pixelWidth) || pixelHeight != nextP2(pixelHeight) || depth != nextP2(depth)))
  298. {
  299. forceclamp = true;
  300. }
  301. if (forceclamp)
  302. {
  303. if (wrap.s != WRAP_CLAMP || wrap.t != WRAP_CLAMP || wrap.r != WRAP_CLAMP)
  304. success = false;
  305. wrap.s = wrap.t = wrap.r = WRAP_CLAMP;
  306. }
  307. if (!gl.isClampZeroTextureWrapSupported())
  308. {
  309. if (wrap.s == WRAP_CLAMP_ZERO) wrap.s = WRAP_CLAMP;
  310. if (wrap.t == WRAP_CLAMP_ZERO) wrap.t = WRAP_CLAMP;
  311. if (wrap.r == WRAP_CLAMP_ZERO) wrap.r = WRAP_CLAMP;
  312. }
  313. gl.bindTextureToUnit(this, 0, false);
  314. gl.setTextureWrap(texType, wrap);
  315. return success;
  316. }
  317. bool Canvas::setMipmapSharpness(float sharpness)
  318. {
  319. if (!gl.isSamplerLODBiasSupported())
  320. return false;
  321. Graphics::flushStreamDrawsGlobal();
  322. float maxbias = gl.getMaxLODBias();
  323. if (maxbias > 0.01f)
  324. maxbias -= 0.0f;
  325. mipmapSharpness = std::min(std::max(sharpness, -maxbias), maxbias);
  326. gl.bindTextureToUnit(this, 0, false);
  327. // negative bias is sharper
  328. glTexParameterf(gl.getGLTextureType(texType), GL_TEXTURE_LOD_BIAS, -mipmapSharpness);
  329. return true;
  330. }
  331. void Canvas::setDepthSampleMode(Optional<CompareMode> mode)
  332. {
  333. Texture::setDepthSampleMode(mode);
  334. bool supported = gl.isDepthCompareSampleSupported();
  335. if (mode.hasValue)
  336. {
  337. if (!supported)
  338. throw love::Exception("Depth comparison sampling in shaders is not supported on this system.");
  339. Graphics::flushStreamDrawsGlobal();
  340. gl.bindTextureToUnit(texType, texture, 0, false);
  341. GLenum gltextype = OpenGL::getGLTextureType(texType);
  342. // See the comment in depthstencil.h
  343. GLenum glmode = OpenGL::getGLCompareMode(getReversedCompareMode(mode.value));
  344. glTexParameteri(gltextype, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
  345. glTexParameteri(gltextype, GL_TEXTURE_COMPARE_FUNC, glmode);
  346. }
  347. else if (isPixelFormatDepth(format) && supported)
  348. {
  349. Graphics::flushStreamDrawsGlobal();
  350. gl.bindTextureToUnit(texType, texture, 0, false);
  351. GLenum gltextype = OpenGL::getGLTextureType(texType);
  352. glTexParameteri(gltextype, GL_TEXTURE_COMPARE_MODE, GL_NONE);
  353. }
  354. depthCompareMode = mode;
  355. }
  356. ptrdiff_t Canvas::getHandle() const
  357. {
  358. return texture;
  359. }
  360. love::image::ImageData *Canvas::newImageData(love::image::Image *module, int slice, int mipmap, const Rect &r)
  361. {
  362. love::image::ImageData *data = love::graphics::Canvas::newImageData(module, slice, mipmap, r);
  363. bool isSRGB = false;
  364. OpenGL::TextureFormat fmt = gl.convertPixelFormat(data->getFormat(), false, isSRGB);
  365. GLuint current_fbo = gl.getFramebuffer(OpenGL::FRAMEBUFFER_ALL);
  366. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, getFBO());
  367. if (slice > 0 || mipmap > 0)
  368. {
  369. int layer = texType == TEXTURE_CUBE ? 0 : slice;
  370. int face = texType == TEXTURE_CUBE ? slice : 0;
  371. gl.framebufferTexture(GL_COLOR_ATTACHMENT0, texType, texture, mipmap, layer, face);
  372. }
  373. glReadPixels(r.x, r.y, r.w, r.h, fmt.externalformat, fmt.type, data->getData());
  374. if (slice > 0 || mipmap > 0)
  375. gl.framebufferTexture(GL_COLOR_ATTACHMENT0, texType, texture, 0, 0, 0);
  376. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo);
  377. return data;
  378. }
  379. void Canvas::generateMipmaps()
  380. {
  381. if (getMipmapCount() == 1 || getMipmapMode() == MIPMAPS_NONE)
  382. throw love::Exception("generateMipmaps can only be called on a Canvas which was created with mipmaps enabled.");
  383. gl.bindTextureToUnit(this, 0, false);
  384. GLenum gltextype = OpenGL::getGLTextureType(texType);
  385. if (gl.bugs.generateMipmapsRequiresTexture2DEnable)
  386. glEnable(gltextype);
  387. glGenerateMipmap(gltextype);
  388. }
  389. PixelFormat Canvas::getSizedFormat(PixelFormat format)
  390. {
  391. switch (format)
  392. {
  393. case PIXELFORMAT_NORMAL:
  394. if (isGammaCorrect())
  395. return PIXELFORMAT_sRGBA8;
  396. else if (!OpenGL::isPixelFormatSupported(PIXELFORMAT_RGBA8, true, true, false))
  397. // 32-bit render targets don't have guaranteed support on GLES2.
  398. return PIXELFORMAT_RGBA4;
  399. else
  400. return PIXELFORMAT_RGBA8;
  401. case PIXELFORMAT_HDR:
  402. return PIXELFORMAT_RGBA16F;
  403. default:
  404. return format;
  405. }
  406. }
  407. bool Canvas::isSupported()
  408. {
  409. return GLAD_ES_VERSION_2_0 || GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_object || GLAD_EXT_framebuffer_object;
  410. }
  411. bool Canvas::isMultiFormatMultiCanvasSupported()
  412. {
  413. return gl.getMaxRenderTargets() > 1 && (GLAD_ES_VERSION_3_0 || GLAD_VERSION_3_0 || GLAD_ARB_framebuffer_object);
  414. }
  415. Canvas::SupportedFormat Canvas::supportedFormats[] = {};
  416. Canvas::SupportedFormat Canvas::checkedFormats[] = {};
  417. bool Canvas::isFormatSupported(PixelFormat format)
  418. {
  419. return isFormatSupported(format, !isPixelFormatDepthStencil(format));
  420. }
  421. bool Canvas::isFormatSupported(PixelFormat format, bool readable)
  422. {
  423. if (!isSupported())
  424. return false;
  425. const char *fstr = "?";
  426. love::getConstant(format, fstr);
  427. bool supported = true;
  428. format = getSizedFormat(format);
  429. if (!OpenGL::isPixelFormatSupported(format, true, readable, false))
  430. return false;
  431. if (checkedFormats[format].get(readable))
  432. return supportedFormats[format].get(readable);
  433. // Even though we might have the necessary OpenGL version or extension,
  434. // drivers are still allowed to throw FRAMEBUFFER_UNSUPPORTED when attaching
  435. // a texture to a FBO whose format the driver doesn't like. So we should
  436. // test with an actual FBO.
  437. GLuint texture = 0;
  438. GLuint renderbuffer = 0;
  439. bool unusedSRGB = false;
  440. OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(format, readable, unusedSRGB);
  441. GLuint current_fbo = gl.getFramebuffer(OpenGL::FRAMEBUFFER_ALL);
  442. GLuint fbo = 0;
  443. glGenFramebuffers(1, &fbo);
  444. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, fbo);
  445. // Make sure at least something is bound to a color attachment. I believe
  446. // this is required on ES2 but I'm not positive.
  447. if (isPixelFormatDepthStencil(format))
  448. gl.framebufferTexture(GL_COLOR_ATTACHMENT0, TEXTURE_2D, gl.getDefaultTexture(TEXTURE_2D), 0, 0, 0);
  449. if (readable)
  450. {
  451. glGenTextures(1, &texture);
  452. gl.bindTextureToUnit(TEXTURE_2D, texture, 0, false);
  453. Texture::Filter f;
  454. f.min = f.mag = Texture::FILTER_NEAREST;
  455. gl.setTextureFilter(TEXTURE_2D, f);
  456. Texture::Wrap w;
  457. gl.setTextureWrap(TEXTURE_2D, w);
  458. unusedSRGB = false;
  459. gl.rawTexStorage(TEXTURE_2D, 1, format, unusedSRGB, 1, 1);
  460. }
  461. else
  462. {
  463. glGenRenderbuffers(1, &renderbuffer);
  464. glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
  465. glRenderbufferStorage(GL_RENDERBUFFER, fmt.internalformat, 1, 1);
  466. }
  467. for (GLenum attachment : fmt.framebufferAttachments)
  468. {
  469. if (attachment == GL_NONE)
  470. continue;
  471. if (readable)
  472. gl.framebufferTexture(attachment, TEXTURE_2D, texture, 0, 0, 0);
  473. else
  474. glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, renderbuffer);
  475. }
  476. supported = glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
  477. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo);
  478. gl.deleteFramebuffer(fbo);
  479. if (texture != 0)
  480. gl.deleteTexture(texture);
  481. if (renderbuffer != 0)
  482. glDeleteRenderbuffers(1, &renderbuffer);
  483. // Cache the result so we don't do this for every isFormatSupported call.
  484. checkedFormats[format].set(readable, true);
  485. supportedFormats[format].set(readable, supported);
  486. return supported;
  487. }
  488. } // opengl
  489. } // graphics
  490. } // love