Texture.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. /**
  2. * Copyright (c) 2006-2020 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 "Texture.h"
  21. #include "graphics/Graphics.h"
  22. #include "Graphics.h"
  23. #include "common/int.h"
  24. // STD
  25. #include <algorithm> // for min/max
  26. namespace love
  27. {
  28. namespace graphics
  29. {
  30. namespace opengl
  31. {
  32. static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat format, GLuint texture, int mips, int layers, bool clear)
  33. {
  34. // get currently bound fbo to reset to it later
  35. GLuint current_fbo = gl.getFramebuffer(OpenGL::FRAMEBUFFER_ALL);
  36. glGenFramebuffers(1, &framebuffer);
  37. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, framebuffer);
  38. if (texture != 0)
  39. {
  40. if (isPixelFormatDepthStencil(format) && (GLAD_ES_VERSION_3_0 || !GLAD_ES_VERSION_2_0))
  41. {
  42. // glDrawBuffers is an ext in GL2. glDrawBuffer doesn't exist in ES3.
  43. GLenum none = GL_NONE;
  44. if (GLAD_ES_VERSION_3_0)
  45. glDrawBuffers(1, &none);
  46. else
  47. glDrawBuffer(GL_NONE);
  48. glReadBuffer(GL_NONE);
  49. }
  50. bool unusedSRGB = false;
  51. OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(format, false, unusedSRGB);
  52. int faces = texType == TEXTURE_CUBE ? 6 : 1;
  53. // Make sure all faces and layers of the texture are initialized to
  54. // transparent black. This is unfortunately probably pretty slow for
  55. // 2D-array and 3D textures with a lot of layers...
  56. for (int mip = mips - 1; mip >= 0; mip--)
  57. {
  58. for (int layer = layers - 1; layer >= 0; layer--)
  59. {
  60. for (int face = faces - 1; face >= 0; face--)
  61. {
  62. for (GLenum attachment : fmt.framebufferAttachments)
  63. {
  64. if (attachment == GL_NONE)
  65. continue;
  66. gl.framebufferTexture(attachment, texType, texture, mip, layer, face);
  67. }
  68. if (clear)
  69. {
  70. if (isPixelFormatDepthStencil(format))
  71. {
  72. bool hadDepthWrites = gl.hasDepthWrites();
  73. if (!hadDepthWrites) // glDepthMask also affects glClear.
  74. gl.setDepthWrites(true);
  75. gl.clearDepth(1.0);
  76. glClearStencil(0);
  77. glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  78. if (!hadDepthWrites)
  79. gl.setDepthWrites(hadDepthWrites);
  80. }
  81. else
  82. {
  83. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  84. glClear(GL_COLOR_BUFFER_BIT);
  85. }
  86. }
  87. }
  88. }
  89. }
  90. }
  91. GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
  92. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo);
  93. return status;
  94. }
  95. static GLenum newRenderbuffer(int width, int height, int &samples, PixelFormat pixelformat, GLuint &buffer)
  96. {
  97. bool unusedSRGB = false;
  98. OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(pixelformat, true, unusedSRGB);
  99. GLuint current_fbo = gl.getFramebuffer(OpenGL::FRAMEBUFFER_ALL);
  100. // Temporary FBO used to clear the renderbuffer.
  101. GLuint fbo = 0;
  102. glGenFramebuffers(1, &fbo);
  103. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, fbo);
  104. if (isPixelFormatDepthStencil(pixelformat) && (GLAD_ES_VERSION_3_0 || !GLAD_ES_VERSION_2_0))
  105. {
  106. // glDrawBuffers is an ext in GL2. glDrawBuffer doesn't exist in ES3.
  107. GLenum none = GL_NONE;
  108. if (GLAD_ES_VERSION_3_0)
  109. glDrawBuffers(1, &none);
  110. else
  111. glDrawBuffer(GL_NONE);
  112. glReadBuffer(GL_NONE);
  113. }
  114. glGenRenderbuffers(1, &buffer);
  115. glBindRenderbuffer(GL_RENDERBUFFER, buffer);
  116. if (samples > 1)
  117. glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, fmt.internalformat, width, height);
  118. else
  119. glRenderbufferStorage(GL_RENDERBUFFER, fmt.internalformat, width, height);
  120. for (GLenum attachment : fmt.framebufferAttachments)
  121. {
  122. if (attachment != GL_NONE)
  123. glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, buffer);
  124. }
  125. if (samples > 1)
  126. {
  127. glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, &samples);
  128. samples = std::max(1, samples);
  129. }
  130. glBindRenderbuffer(GL_RENDERBUFFER, 0);
  131. GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
  132. if (status == GL_FRAMEBUFFER_COMPLETE)
  133. {
  134. if (isPixelFormatDepthStencil(pixelformat))
  135. {
  136. bool hadDepthWrites = gl.hasDepthWrites();
  137. if (!hadDepthWrites) // glDepthMask also affects glClear.
  138. gl.setDepthWrites(true);
  139. gl.clearDepth(1.0);
  140. glClearStencil(0);
  141. glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  142. if (!hadDepthWrites)
  143. gl.setDepthWrites(hadDepthWrites);
  144. }
  145. else
  146. {
  147. // Initialize the buffer to transparent black.
  148. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  149. glClear(GL_COLOR_BUFFER_BIT);
  150. }
  151. }
  152. else
  153. {
  154. glDeleteRenderbuffers(1, &buffer);
  155. buffer = 0;
  156. samples = 1;
  157. }
  158. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo);
  159. gl.deleteFramebuffer(fbo);
  160. return status;
  161. }
  162. Texture::Texture(const Settings &settings, const Slices *data)
  163. : love::graphics::Texture(settings, data)
  164. , slices(settings.type)
  165. , fbo(0)
  166. , texture(0)
  167. , renderbuffer(0)
  168. , framebufferStatus(GL_FRAMEBUFFER_COMPLETE)
  169. , textureGLError(GL_NO_ERROR)
  170. , actualSamples(1)
  171. {
  172. if (data != nullptr)
  173. slices = *data;
  174. if (!loadVolatile())
  175. {
  176. if (framebufferStatus != GL_FRAMEBUFFER_COMPLETE)
  177. throw love::Exception("Cannot create Texture (OpenGL framebuffer error: %s)", OpenGL::framebufferStatusString(framebufferStatus));
  178. if (textureGLError != GL_NO_ERROR)
  179. throw love::Exception("Cannot create Texture (OpenGL error: %s)", OpenGL::errorString(textureGLError));
  180. }
  181. // ImageData is referenced by the first loadVolatile call, but we don't
  182. // hang on to it after that so we can save memory.
  183. slices.clear();
  184. }
  185. Texture::~Texture()
  186. {
  187. unloadVolatile();
  188. }
  189. void Texture::createTexture()
  190. {
  191. // The base class handles some validation. For example, if ImageData is
  192. // given then it must exist for all mip levels, a render target can't use
  193. // a compressed format, etc.
  194. glGenTextures(1, &texture);
  195. gl.bindTextureToUnit(this, 0, false);
  196. // Use a default texture if the size is too big for the system.
  197. // validateDimensions is also called in the base class for RTs and
  198. // non-readable textures.
  199. if (!renderTarget && !validateDimensions(false))
  200. {
  201. usingDefaultTexture = true;
  202. setSamplerState(samplerState);
  203. bool isSRGB = false;
  204. gl.rawTexStorage(texType, 1, PIXELFORMAT_RGBA8_UNORM, isSRGB, 2, 2, 1);
  205. // A nice friendly checkerboard to signify invalid textures...
  206. GLubyte px[] = {0xFF,0xFF,0xFF,0xFF, 0xFF,0xA0,0xA0,0xFF,
  207. 0xFF,0xA0,0xA0,0xFF, 0xFF,0xFF,0xFF,0xFF};
  208. int slices = texType == TEXTURE_CUBE ? 6 : 1;
  209. Rect rect = {0, 0, 2, 2};
  210. for (int slice = 0; slice < slices; slice++)
  211. uploadByteData(PIXELFORMAT_RGBA8_UNORM, px, sizeof(px), 0, slice, rect, nullptr);
  212. return;
  213. }
  214. GLenum gltype = OpenGL::getGLTextureType(texType);
  215. if (renderTarget && GLAD_ANGLE_texture_usage)
  216. glTexParameteri(gltype, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
  217. setSamplerState(samplerState);
  218. int mipcount = getMipmapCount();
  219. int slicecount = 1;
  220. if (texType == TEXTURE_VOLUME)
  221. slicecount = getDepth();
  222. else if (texType == TEXTURE_2D_ARRAY)
  223. slicecount = getLayerCount();
  224. else if (texType == TEXTURE_CUBE)
  225. slicecount = 6;
  226. // For a couple flimsy reasons, we don't initialize the texture here if it's
  227. // compressed. I need to verify that getPixelFormatSliceSize will return the
  228. // correct value for all compressed texture formats, and I also vaguely
  229. // remember some driver issues on some old Android systems, maybe...
  230. // For now, the base class enforces data on init for compressed textures.
  231. if (!isCompressed())
  232. gl.rawTexStorage(texType, mipcount, format, sRGB, pixelWidth, pixelHeight, texType == TEXTURE_VOLUME ? depth : layers);
  233. int w = pixelWidth;
  234. int h = pixelHeight;
  235. int d = depth;
  236. OpenGL::TextureFormat fmt = gl.convertPixelFormat(format, false, sRGB);
  237. for (int mip = 0; mip < mipcount; mip++)
  238. {
  239. if (isCompressed() && (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME))
  240. {
  241. size_t mipsize = 0;
  242. if (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME)
  243. {
  244. for (int slice = 0; slice < slices.getSliceCount(mip); slice++)
  245. {
  246. auto id = slices.get(slice, mip);
  247. if (id != nullptr)
  248. mipsize += id->getSize();
  249. }
  250. }
  251. if (mipsize > 0)
  252. glCompressedTexImage3D(gltype, mip, fmt.internalformat, w, h, d, 0, mipsize, nullptr);
  253. }
  254. for (int slice = 0; slice < slicecount; slice++)
  255. {
  256. love::image::ImageDataBase *id = slices.get(slice, mip);
  257. if (id != nullptr)
  258. uploadImageData(id, mip, slice, 0, 0);
  259. }
  260. w = std::max(w / 2, 1);
  261. h = std::max(h / 2, 1);
  262. if (texType == TEXTURE_VOLUME)
  263. d = std::max(d / 2, 1);
  264. }
  265. bool hasdata = slices.get(0, 0) != nullptr;
  266. // All mipmap levels need to be initialized - for color formats we can clear
  267. // the base mip and use glGenerateMipmap after that's done. Depth and
  268. // stencil formats don't always support glGenerateMipmap so we need to
  269. // individually clear each mip level in that case. We avoid doing that for
  270. // color formats because of an Intel driver bug:
  271. // https://github.com/love2d/love/issues/1585
  272. int clearmips = 1;
  273. if (isPixelFormatDepthStencil(format))
  274. clearmips = mipmapCount;
  275. // Create a local FBO used for glReadPixels as well as MSAA blitting.
  276. if (isRenderTarget())
  277. {
  278. bool clear = !hasdata;
  279. int slices = texType == TEXTURE_VOLUME ? depth : layers;
  280. framebufferStatus = createFBO(fbo, texType, format, texture, clearmips, slices, clear);
  281. }
  282. else if (!hasdata)
  283. {
  284. // Initialize all slices to transparent black.
  285. for (int mip = 0; mip < clearmips; mip++)
  286. {
  287. int mipw = getPixelWidth(mip);
  288. int miph = getPixelHeight(mip);
  289. std::vector<uint8> emptydata(getPixelFormatSliceSize(format, mipw, miph));
  290. Rect r = {0, 0, mipw, miph};
  291. int slices = texType == TEXTURE_VOLUME ? getDepth(mip) : layers;
  292. slices = texType == TEXTURE_CUBE ? 6 : slices;
  293. for (int i = 0; i < slices; i++)
  294. uploadByteData(format, emptydata.data(), emptydata.size(), mip, i, r);
  295. }
  296. }
  297. // Non-readable textures can't have mipmaps (enforced in the base class),
  298. // so generateMipmaps here is fine - when they aren't already initialized.
  299. if (clearmips < mipmapCount && slices.getMipmapCount() <= 1 && getMipmapsMode() != MIPMAPS_NONE)
  300. generateMipmaps();
  301. }
  302. bool Texture::loadVolatile()
  303. {
  304. if (texture != 0 || renderbuffer != 0)
  305. return true;
  306. OpenGL::TempDebugGroup debuggroup("Texture load");
  307. // NPOT textures don't support mipmapping without full NPOT support.
  308. if ((GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot))
  309. && (pixelWidth != nextP2(pixelWidth) || pixelHeight != nextP2(pixelHeight)))
  310. {
  311. mipmapCount = 1;
  312. samplerState.mipmapFilter = SamplerState::MIPMAP_FILTER_NONE;
  313. }
  314. actualSamples = std::max(1, std::min(getRequestedMSAA(), gl.getMaxSamples()));
  315. while (glGetError() != GL_NO_ERROR); // Clear errors.
  316. framebufferStatus = GL_FRAMEBUFFER_COMPLETE;
  317. textureGLError = GL_NO_ERROR;
  318. if (isReadable())
  319. createTexture();
  320. if (!usingDefaultTexture && framebufferStatus == GL_FRAMEBUFFER_COMPLETE
  321. && (!isReadable() || actualSamples > 1))
  322. {
  323. framebufferStatus = newRenderbuffer(pixelWidth, pixelHeight, actualSamples, format, renderbuffer);
  324. }
  325. textureGLError = glGetError();
  326. if (framebufferStatus != GL_FRAMEBUFFER_COMPLETE || textureGLError != GL_NO_ERROR)
  327. {
  328. unloadVolatile();
  329. return false;
  330. }
  331. int64 memsize = 0;
  332. for (int mip = 0; mip < getMipmapCount(); mip++)
  333. {
  334. int w = getPixelWidth(mip);
  335. int h = getPixelHeight(mip);
  336. int slices = getDepth(mip) * layers * (texType == TEXTURE_CUBE ? 6 : 1);
  337. memsize += getPixelFormatSliceSize(format, w, h) * slices;
  338. }
  339. if (actualSamples > 1 && isReadable())
  340. {
  341. int slices = depth * layers * (texType == TEXTURE_CUBE ? 6 : 1);
  342. memsize += getPixelFormatSliceSize(format, pixelWidth, pixelHeight) * slices * actualSamples;
  343. }
  344. else if (actualSamples > 1)
  345. memsize *= actualSamples;
  346. setGraphicsMemorySize(memsize);
  347. usingDefaultTexture = false;
  348. return true;
  349. }
  350. void Texture::unloadVolatile()
  351. {
  352. if (isRenderTarget() && (fbo != 0 || renderbuffer != 0 || texture != 0))
  353. {
  354. // This is a bit ugly, but we need some way to destroy the cached FBO
  355. // when this texture's GL object is destroyed.
  356. auto gfx = Module::getInstance<Graphics>(Module::M_GRAPHICS);
  357. if (gfx != nullptr)
  358. gfx->cleanupRenderTexture(this);
  359. }
  360. if (fbo != 0)
  361. gl.deleteFramebuffer(fbo);
  362. if (renderbuffer != 0)
  363. glDeleteRenderbuffers(1, &renderbuffer);
  364. if (texture != 0)
  365. gl.deleteTexture(texture);
  366. fbo = 0;
  367. renderbuffer = 0;
  368. texture = 0;
  369. setGraphicsMemorySize(0);
  370. }
  371. void Texture::uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r, love::image::ImageDataBase *imgd)
  372. {
  373. love::image::ImageDataBase *oldd = slices.get(slice, level);
  374. // We can only replace the internal Data (used when reloading due to setMode)
  375. // if the dimensions match.
  376. if (imgd != nullptr && oldd != nullptr && oldd->getWidth() == imgd->getWidth()
  377. && oldd->getHeight() == imgd->getHeight())
  378. {
  379. slices.set(slice, level, imgd);
  380. }
  381. OpenGL::TempDebugGroup debuggroup("Texture data upload");
  382. gl.bindTextureToUnit(this, 0, false);
  383. OpenGL::TextureFormat fmt = OpenGL::convertPixelFormat(pixelformat, false, sRGB);
  384. GLenum gltarget = OpenGL::getGLTextureType(texType);
  385. if (texType == TEXTURE_CUBE)
  386. gltarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
  387. if (isPixelFormatCompressed(pixelformat))
  388. {
  389. if (r.x != 0 || r.y != 0)
  390. throw love::Exception("x and y parameters must be 0 for compressed textures.");
  391. if (texType == TEXTURE_2D || texType == TEXTURE_CUBE)
  392. glCompressedTexImage2D(gltarget, level, fmt.internalformat, r.w, r.h, 0, size, data);
  393. else if (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME)
  394. glCompressedTexSubImage3D(gltarget, level, 0, 0, slice, r.w, r.h, 1, fmt.internalformat, size, data);
  395. }
  396. else
  397. {
  398. if (texType == TEXTURE_2D || texType == TEXTURE_CUBE)
  399. glTexSubImage2D(gltarget, level, r.x, r.y, r.w, r.h, fmt.externalformat, fmt.type, data);
  400. else if (texType == TEXTURE_2D_ARRAY || texType == TEXTURE_VOLUME)
  401. glTexSubImage3D(gltarget, level, r.x, r.y, slice, r.w, r.h, 1, fmt.externalformat, fmt.type, data);
  402. }
  403. }
  404. void Texture::generateMipmapsInternal()
  405. {
  406. gl.bindTextureToUnit(this, 0, false);
  407. GLenum gltextype = OpenGL::getGLTextureType(texType);
  408. if (gl.bugs.generateMipmapsRequiresTexture2DEnable)
  409. glEnable(gltextype);
  410. glGenerateMipmap(gltextype);
  411. }
  412. void Texture::readbackImageData(love::image::ImageData *data, int slice, int mipmap, const Rect &r)
  413. {
  414. if (fbo == 0) // Should never be reached.
  415. return;
  416. bool isSRGB = false;
  417. OpenGL::TextureFormat fmt = gl.convertPixelFormat(data->getFormat(), false, isSRGB);
  418. GLuint current_fbo = gl.getFramebuffer(OpenGL::FRAMEBUFFER_ALL);
  419. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, getFBO());
  420. if (slice > 0 || mipmap > 0)
  421. {
  422. int layer = texType == TEXTURE_CUBE ? 0 : slice;
  423. int face = texType == TEXTURE_CUBE ? slice : 0;
  424. gl.framebufferTexture(GL_COLOR_ATTACHMENT0, texType, texture, mipmap, layer, face);
  425. }
  426. glReadPixels(r.x, r.y, r.w, r.h, fmt.externalformat, fmt.type, data->getData());
  427. if (slice > 0 || mipmap > 0)
  428. gl.framebufferTexture(GL_COLOR_ATTACHMENT0, texType, texture, 0, 0, 0);
  429. gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo);
  430. }
  431. void Texture::setSamplerState(const SamplerState &s)
  432. {
  433. if (s.depthSampleMode.hasValue && !gl.isDepthCompareSampleSupported())
  434. throw love::Exception("Depth comparison sampling in shaders is not supported on this system.");
  435. // Base class does common validation and assigns samplerState.
  436. love::graphics::Texture::setSamplerState(s);
  437. auto supportedflags = OpenGL::getPixelFormatUsageFlags(getPixelFormat());
  438. if ((supportedflags & PIXELFORMATUSAGEFLAGS_LINEAR) == 0)
  439. {
  440. samplerState.magFilter = samplerState.minFilter = SamplerState::FILTER_NEAREST;
  441. if (samplerState.mipmapFilter == SamplerState::MIPMAP_FILTER_LINEAR)
  442. samplerState.mipmapFilter = SamplerState::MIPMAP_FILTER_NEAREST;
  443. }
  444. // We don't want filtering or (attempted) mipmaps on the default texture.
  445. if (usingDefaultTexture)
  446. {
  447. samplerState.mipmapFilter = SamplerState::MIPMAP_FILTER_NONE;
  448. samplerState.minFilter = samplerState.magFilter = SamplerState::FILTER_NEAREST;
  449. }
  450. // If we only have limited NPOT support then the wrap mode must be CLAMP.
  451. if ((GLAD_ES_VERSION_2_0 && !(GLAD_ES_VERSION_3_0 || GLAD_OES_texture_npot))
  452. && (pixelWidth != nextP2(pixelWidth) || pixelHeight != nextP2(pixelHeight) || depth != nextP2(depth)))
  453. {
  454. samplerState.wrapU = samplerState.wrapV = samplerState.wrapW = SamplerState::WRAP_CLAMP;
  455. }
  456. gl.bindTextureToUnit(this, 0, false);
  457. gl.setSamplerState(texType, samplerState);
  458. }
  459. ptrdiff_t Texture::getHandle() const
  460. {
  461. return texture;
  462. }
  463. ptrdiff_t Texture::getRenderTargetHandle() const
  464. {
  465. return renderTarget ? (renderbuffer != 0 ? renderbuffer : texture) : 0;
  466. }
  467. } // opengl
  468. } // graphics
  469. } // love