gfxGLTextureObject.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "console/console.h"
  23. #include "gfx/gl/tGL/tGL.h"
  24. #include "math/mRect.h"
  25. #include "gfx/gl/gfxGLTextureObject.h"
  26. #include "gfx/gfxDevice.h"
  27. #include "gfx/gl/gfxGLEnumTranslate.h"
  28. #include "gfx/gl/gfxGLTextureManager.h"
  29. #include "gfx/gl/gfxGLUtils.h"
  30. #include "gfx/gfxCardProfile.h"
  31. GFXGLTextureObject::GFXGLTextureObject(GFXDevice * aDevice, GFXTextureProfile *profile) :
  32. GFXTextureObject(aDevice, profile),
  33. mIsNPoT2(false),
  34. mBinding(GL_TEXTURE_2D),
  35. mBytesPerTexel(4),
  36. mLockedRectRect(0, 0, 0, 0),
  37. mGLDevice(static_cast<GFXGLDevice*>(mDevice)),
  38. mIsZombie(false),
  39. mZombieCache(NULL),
  40. mNeedInitSamplerState(true),
  41. mFrameAllocatorMark(0),
  42. mFrameAllocatorPtr(NULL)
  43. {
  44. #ifdef TORQUE_DEBUG
  45. mFrameAllocatorMarkGuard = FrameAllocator::getWaterMark();
  46. #endif
  47. dMemset(&mLockedRect, 0, sizeof(mLockedRect));
  48. AssertFatal(dynamic_cast<GFXGLDevice*>(mDevice), "GFXGLTextureObject::GFXGLTextureObject - Invalid device type, expected GFXGLDevice!");
  49. glGenTextures(1, &mHandle);
  50. glGenBuffers(1, &mBuffer);
  51. }
  52. GFXGLTextureObject::~GFXGLTextureObject()
  53. {
  54. glDeleteTextures(1, &mHandle);
  55. glDeleteBuffers(1, &mBuffer);
  56. delete[] mZombieCache;
  57. kill();
  58. }
  59. GFXLockedRect* GFXGLTextureObject::lock(U32 mipLevel /*= 0*/, RectI* inRect /*= NULL*/, U32 faceIndex /*= 0*/)
  60. {
  61. //AssertFatal(mBinding != GL_TEXTURE_3D, "GFXGLTextureObject::lock - We don't support locking 3D textures yet");
  62. U32 width = mTextureSize.x >> mipLevel;
  63. U32 height = mTextureSize.y >> mipLevel;
  64. if(inRect)
  65. {
  66. if((inRect->point.x + inRect->extent.x > width) || (inRect->point.y + inRect->extent.y > height))
  67. AssertFatal(false, "GFXGLTextureObject::lock - Rectangle too big!");
  68. mLockedRectRect = *inRect;
  69. }
  70. else
  71. {
  72. mLockedRectRect = RectI(0, 0, width, height);
  73. }
  74. mLockedRect.pitch = mLockedRectRect.extent.x * mBytesPerTexel;
  75. // CodeReview [ags 12/19/07] This one texel boundary is necessary to keep the clipmap code from crashing. Figure out why.
  76. U32 size = (mLockedRectRect.extent.x + 1) * (mLockedRectRect.extent.y + 1) * getDepth() * mBytesPerTexel;
  77. AssertFatal(!mFrameAllocatorMark && !mFrameAllocatorPtr, "");
  78. mFrameAllocatorMark = FrameAllocator::getWaterMark();
  79. mFrameAllocatorPtr = (U8*)FrameAllocator::alloc( size );
  80. mLockedRect.bits = mFrameAllocatorPtr;
  81. #ifdef TORQUE_DEBUG
  82. mFrameAllocatorMarkGuard = FrameAllocator::getWaterMark();
  83. #endif
  84. if( !mLockedRect.bits )
  85. return NULL;
  86. return &mLockedRect;
  87. }
  88. void GFXGLTextureObject::unlock(U32 mipLevel /*= 0*/, U32 faceIndex /*= 0*/)
  89. {
  90. if(!mLockedRect.bits)
  91. return;
  92. // I know this is in unlock, but in GL we actually do our submission in unlock.
  93. PROFILE_SCOPE(GFXGLTextureObject_lockRT);
  94. PRESERVE_TEXTURE(mBinding);
  95. glBindTexture(mBinding, mHandle);
  96. glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mBuffer);
  97. glBufferData(GL_PIXEL_UNPACK_BUFFER, (mLockedRectRect.extent.x + 1) * (mLockedRectRect.extent.y + 1) * mBytesPerTexel, mFrameAllocatorPtr, GL_STREAM_DRAW);
  98. S32 z = getDepth();
  99. if (mBinding == GL_TEXTURE_3D)
  100. glTexSubImage3D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y, z,
  101. mLockedRectRect.extent.x, mLockedRectRect.extent.y, z, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
  102. else if(mBinding == GL_TEXTURE_2D)
  103. glTexSubImage2D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y,
  104. mLockedRectRect.extent.x, mLockedRectRect.extent.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
  105. else if(mBinding == GL_TEXTURE_1D)
  106. glTexSubImage1D(mBinding, mipLevel, (mLockedRectRect.point.x > 1 ? mLockedRectRect.point.x : mLockedRectRect.point.y),
  107. (mLockedRectRect.extent.x > 1 ? mLockedRectRect.extent.x : mLockedRectRect.extent.y), GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
  108. glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
  109. mLockedRect.bits = NULL;
  110. #if TORQUE_DEBUG
  111. AssertFatal(mFrameAllocatorMarkGuard == FrameAllocator::getWaterMark(), "");
  112. #endif
  113. FrameAllocator::setWaterMark(mFrameAllocatorMark);
  114. mFrameAllocatorMark = 0;
  115. mFrameAllocatorPtr = NULL;
  116. }
  117. void GFXGLTextureObject::release()
  118. {
  119. glDeleteTextures(1, &mHandle);
  120. glDeleteBuffers(1, &mBuffer);
  121. mHandle = 0;
  122. mBuffer = 0;
  123. }
  124. void GFXGLTextureObject::reInit()
  125. {
  126. AssertFatal(!mHandle && !mBuffer,"Must release before reInit");
  127. glGenTextures(1, &mHandle);
  128. glGenBuffers(1, &mBuffer);
  129. }
  130. bool GFXGLTextureObject::copyToBmp(GBitmap * bmp)
  131. {
  132. if (!bmp)
  133. return false;
  134. // check format limitations
  135. // at the moment we only support RGBA for the source (other 4 byte formats should
  136. // be easy to add though)
  137. AssertFatal(mFormat == GFXFormatR16G16B16A16F || mFormat == GFXFormatR8G8B8A8 || mFormat == GFXFormatR8G8B8A8_LINEAR_FORCE || mFormat == GFXFormatR8G8B8A8_SRGB, "copyToBmp: invalid format");
  138. if (mFormat != GFXFormatR16G16B16A16F && mFormat != GFXFormatR8G8B8A8 && mFormat != GFXFormatR8G8B8A8_LINEAR_FORCE && mFormat != GFXFormatR8G8B8A8_SRGB)
  139. return false;
  140. AssertFatal(bmp->getWidth() == getWidth(), avar("GFXGLTextureObject::copyToBmp - Width mismatch: %i vs %i", bmp->getWidth(), getWidth()));
  141. AssertFatal(bmp->getHeight() == getHeight(), avar("GFXGLTextureObject::copyToBmp - Height mismatch: %i vs %i", bmp->getHeight(), getHeight()));
  142. PROFILE_SCOPE(GFXGLTextureObject_copyToBmp);
  143. PRESERVE_TEXTURE(mBinding);
  144. glBindTexture(mBinding, mHandle);
  145. U8 dstBytesPerPixel = GFXFormat_getByteSize( bmp->getFormat() );
  146. U8 srcBytesPerPixel = GFXFormat_getByteSize( mFormat );
  147. FrameAllocatorMarker mem;
  148. const bool isCubemap = (mBinding == GL_TEXTURE_CUBE_MAP);
  149. const U32 numFaces = isCubemap ? 6 : 1;
  150. for (U32 mip = 0; mip < getMipLevels(); mip++)
  151. {
  152. U32 width = getWidth() >> mip;
  153. U32 height = getHeight() >> mip;
  154. if (width == 0) width = 1;
  155. if (height == 0) height = 1;
  156. // Check if multisampled
  157. GLint samples = 0;
  158. GLenum target = mBinding;
  159. if (mBinding == GL_TEXTURE_CUBE_MAP)
  160. target = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
  161. glGetTexLevelParameteriv(target, mip, GL_TEXTURE_SAMPLES, &samples);
  162. if (samples > 0)
  163. {
  164. Con::warnf("GFXGLTextureObject::copyToBmp - Texture is multisampled (%d samples) at mip %d; resolve first.", samples, mip);
  165. return false;
  166. }
  167. for (U32 face = 0; face < numFaces; face++)
  168. {
  169. GLenum faceTarget = isCubemap ? GFXGLFaceType[face] : mBinding;
  170. U32 pixelCount = width * height;
  171. U8* srcPixels = (U8*)mem.alloc(pixelCount * srcBytesPerPixel);
  172. U8* dest = bmp->getWritableBits(mip, face);
  173. if (!dest)
  174. {
  175. Con::errorf("GFXGLTextureObject::copyToBmp - No destination bits for mip=%u face=%u", mip, face);
  176. continue;
  177. }
  178. // Read texture data
  179. glGetTexImage(faceTarget, mip, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], srcPixels);
  180. if (mFormat == GFXFormatR16G16B16A16F)
  181. {
  182. dMemcpy(dest, srcPixels, pixelCount * srcBytesPerPixel);
  183. }
  184. else
  185. {
  186. // Simple 8-bit per channel copy (RGBA)
  187. U8* src = srcPixels;
  188. for (U32 i = 0; i < pixelCount; ++i)
  189. {
  190. dest[0] = src[0];
  191. dest[1] = src[1];
  192. dest[2] = src[2];
  193. if (dstBytesPerPixel == 4)
  194. dest[3] = src[3];
  195. src += srcBytesPerPixel;
  196. dest += dstBytesPerPixel;
  197. }
  198. }
  199. } // face
  200. } // mip
  201. glBindTexture(mBinding, 0);
  202. return true;
  203. }
  204. void GFXGLTextureObject::updateTextureSlot(const GFXTexHandle& texHandle, const U32 slot, const S32 face)
  205. {
  206. if (!texHandle.isValid())
  207. return;
  208. GFXGLTextureObject* srcTex = static_cast<GFXGLTextureObject*>(texHandle.getPointer());
  209. if (!srcTex || srcTex->getHandle() == 0)
  210. return;
  211. const GLenum dstTarget = mBinding; // destination binding (this)
  212. const GLenum srcTarget = srcTex->getBinding(); // source binding
  213. const bool srcIsCube = (srcTarget == GL_TEXTURE_CUBE_MAP || srcTarget == GL_TEXTURE_CUBE_MAP_ARRAY);
  214. // Determine list of faces to copy from source
  215. U32 firstFace = 0;
  216. U32 faceCount = 1;
  217. if (face >= 0)
  218. {
  219. firstFace = (U32)face;
  220. faceCount = 1;
  221. }
  222. else if (srcIsCube)
  223. {
  224. firstFace = 0;
  225. faceCount = 6;
  226. }
  227. else
  228. {
  229. firstFace = 0;
  230. faceCount = 1;
  231. }
  232. // Ensure textures are valid
  233. if (!glIsTexture(mHandle) || !glIsTexture(srcTex->getHandle()))
  234. {
  235. Con::errorf("updateTextureSlot: invalid GL texture handle src=%u dst=%u", srcTex->getHandle(), mHandle);
  236. return;
  237. }
  238. // If copyImage supported, prefer that. We'll copy face-by-face (one-layer depth = 1)
  239. if (GFXGL->mCapabilities.copyImage)
  240. {
  241. for (U32 mip = 0; mip < getMipLevels(); ++mip)
  242. {
  243. const GLsizei mipW = getMax(1u, srcTex->getWidth() >> mip);
  244. const GLsizei mipH = getMax(1u, srcTex->getHeight() >> mip);
  245. for (U32 f = firstFace; f < firstFace + faceCount; ++f)
  246. {
  247. // Compute source z offset (for cube arrays it's layer index; for cubemap it's face index)
  248. GLint srcZ = 0;
  249. if (srcTarget == GL_TEXTURE_CUBE_MAP_ARRAY)
  250. {
  251. srcZ = f;
  252. }
  253. else if (srcTarget == GL_TEXTURE_CUBE_MAP)
  254. {
  255. srcZ = f;
  256. }
  257. else
  258. {
  259. srcZ = 0; // 2D source
  260. }
  261. // Compute destination layer (z offset) depending on destination type
  262. GLint dstZ = 0;
  263. if (dstTarget == GL_TEXTURE_CUBE_MAP_ARRAY)
  264. {
  265. // each slot is a whole cubemap => slot * 6 + faceIndex
  266. dstZ = (GLint)(slot * 6 + f);
  267. }
  268. else if (dstTarget == GL_TEXTURE_2D_ARRAY)
  269. {
  270. dstZ = (GLint)slot; // each slot is a single layer
  271. }
  272. else if (dstTarget == GL_TEXTURE_CUBE_MAP)
  273. {
  274. dstZ = (GLint)f;
  275. }
  276. else
  277. {
  278. dstZ = 0; // 2D texture target
  279. }
  280. // Copy single layer/face at this mip
  281. glCopyImageSubData(
  282. srcTex->getHandle(), srcTarget, mip, 0, 0, srcZ,
  283. mHandle, dstTarget, mip, 0, 0, dstZ,
  284. mipW, mipH, 1
  285. );
  286. GLenum err = glGetError();
  287. if (err != GL_NO_ERROR)
  288. Con::errorf("glCopyImageSubData failed with 0x%X (mip=%u face=%u)", err, mip, f);
  289. }
  290. }
  291. return;
  292. }
  293. // Fallback: CPU-side copy using glGetTexImage + glTexSubImage
  294. for (U32 mip = 0; mip < getMipLevels() && mip < srcTex->getMipLevels(); ++mip)
  295. {
  296. const GLsizei mipW = getMax(1u, srcTex->getWidth() >> mip);
  297. const GLsizei mipH = getMax(1u, srcTex->getHeight() >> mip);
  298. const U32 pixelSize = GFXFormat_getByteSize(mFormat); // assuming same fmt for src/dst
  299. const U32 dataSize = mipW * mipH * pixelSize;
  300. FrameAllocatorMarker mem;
  301. U8* buffer = (U8*)mem.alloc(dataSize);
  302. glBindTexture(srcTarget, srcTex->getHandle());
  303. glBindTexture(dstTarget, mHandle);
  304. for (U32 f = firstFace; f < firstFace + faceCount; ++f)
  305. {
  306. GLenum srcFaceTarget = srcTarget;
  307. if (srcTarget == GL_TEXTURE_CUBE_MAP)
  308. srcFaceTarget = GFXGLFaceType[f];
  309. // read pixels from source
  310. glGetTexImage(srcFaceTarget, mip, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], buffer);
  311. GLint dstLayer = 0;
  312. if (dstTarget == GL_TEXTURE_CUBE_MAP_ARRAY)
  313. dstLayer = (GLint)(slot * 6 + f);
  314. else if (dstTarget == GL_TEXTURE_2D_ARRAY)
  315. dstLayer = (GLint)slot;
  316. else if (dstTarget == GL_TEXTURE_CUBE_MAP)
  317. dstLayer = (GLint)f;
  318. else
  319. dstLayer = 0;
  320. if (dstTarget == GL_TEXTURE_CUBE_MAP)
  321. {
  322. GLenum dstFaceTarget = GFXGLFaceType[f];
  323. glTexSubImage2D(dstFaceTarget, mip, 0, 0, mipW, mipH,
  324. GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], buffer);
  325. }
  326. else if (dstTarget == GL_TEXTURE_2D)
  327. {
  328. glTexSubImage2D(GL_TEXTURE_2D, mip, 0, 0, mipW, mipH,
  329. GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], buffer);
  330. }
  331. else if (dstTarget == GL_TEXTURE_2D_ARRAY || dstTarget == GL_TEXTURE_CUBE_MAP_ARRAY)
  332. {
  333. glTexSubImage3D(dstTarget, mip, 0, 0, dstLayer, mipW, mipH, 1,
  334. GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], buffer);
  335. }
  336. }
  337. glBindTexture(dstTarget, 0);
  338. glBindTexture(srcTarget, 0);
  339. }
  340. }
  341. void GFXGLTextureObject::copyTo(GFXTextureObject* dstTex)
  342. {
  343. }
  344. void GFXGLTextureObject::initSamplerState(const GFXSamplerStateDesc &ssd)
  345. {
  346. glTexParameteri(mBinding, GL_TEXTURE_MIN_FILTER, minificationFilter(ssd.minFilter, ssd.mipFilter, mMipLevels));
  347. glTexParameteri(mBinding, GL_TEXTURE_MAG_FILTER, GFXGLTextureFilter[ssd.magFilter]);
  348. glTexParameteri(mBinding, GL_TEXTURE_WRAP_S, !mIsNPoT2 ? GFXGLTextureAddress[ssd.addressModeU] : GL_CLAMP_TO_EDGE);
  349. glTexParameteri(mBinding, GL_TEXTURE_WRAP_T, !mIsNPoT2 ? GFXGLTextureAddress[ssd.addressModeV] : GL_CLAMP_TO_EDGE);
  350. if(mBinding == GL_TEXTURE_3D)
  351. glTexParameteri(mBinding, GL_TEXTURE_WRAP_R, GFXGLTextureAddress[ssd.addressModeW]);
  352. if(static_cast< GFXGLDevice* >( GFX )->supportsAnisotropic() )
  353. glTexParameterf(mBinding, GL_TEXTURE_MAX_ANISOTROPY_EXT, ssd.maxAnisotropy);
  354. mNeedInitSamplerState = false;
  355. mSampler = ssd;
  356. }
  357. void GFXGLTextureObject::bind(U32 textureUnit)
  358. {
  359. glActiveTexture(GL_TEXTURE0 + textureUnit);
  360. glBindTexture(mBinding, mHandle);
  361. GFXGL->getOpenglCache()->setCacheBindedTex(textureUnit, mBinding, mHandle);
  362. }
  363. U8* GFXGLTextureObject::getTextureData( U32 mip )
  364. {
  365. AssertFatal( mMipLevels, "");
  366. mip = (mip < mMipLevels) ? mip : 0;
  367. const U32 dataSize = ImageUtil::isCompressedFormat(mFormat)
  368. ? getCompressedSurfaceSize( mFormat, mTextureSize.x, mTextureSize.y, mip )
  369. : (mTextureSize.x >> mip) * (mTextureSize.y >> mip) * mBytesPerTexel;
  370. U8* data = new U8[dataSize];
  371. PRESERVE_TEXTURE(mBinding);
  372. glBindTexture(mBinding, mHandle);
  373. if( ImageUtil::isCompressedFormat(mFormat) )
  374. glGetCompressedTexImage( mBinding, mip, data );
  375. else
  376. glGetTexImage(mBinding, mip, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], data);
  377. return data;
  378. }
  379. void GFXGLTextureObject::copyIntoCache()
  380. {
  381. PRESERVE_TEXTURE(mBinding);
  382. glBindTexture(mBinding, mHandle);
  383. U32 cacheSize = mTextureSize.x * mTextureSize.y;
  384. if(mBinding == GL_TEXTURE_3D)
  385. cacheSize *= mTextureSize.z;
  386. cacheSize *= mBytesPerTexel;
  387. mZombieCache = new U8[cacheSize];
  388. glGetTexImage(mBinding, 0, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
  389. }
  390. void GFXGLTextureObject::reloadFromCache()
  391. {
  392. if(!mZombieCache)
  393. return;
  394. if(mBinding == GL_TEXTURE_3D)
  395. {
  396. static_cast<GFXGLTextureManager*>(TEXMGR)->_loadTexture(this, mZombieCache);
  397. delete[] mZombieCache;
  398. mZombieCache = NULL;
  399. return;
  400. }
  401. PRESERVE_TEXTURE(mBinding);
  402. glBindTexture(mBinding, mHandle);
  403. if(mBinding == GL_TEXTURE_2D)
  404. glTexSubImage2D(mBinding, 0, 0, 0, mTextureSize.x, mTextureSize.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
  405. else if(mBinding == GL_TEXTURE_1D)
  406. glTexSubImage1D(mBinding, 0, 0, (mTextureSize.x > 1 ? mTextureSize.x : mTextureSize.y), GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
  407. if(mMipLevels != 1)
  408. glGenerateMipmap(mBinding);
  409. delete[] mZombieCache;
  410. mZombieCache = NULL;
  411. mIsZombie = false;
  412. }
  413. void GFXGLTextureObject::zombify()
  414. {
  415. if(mIsZombie)
  416. return;
  417. mIsZombie = true;
  418. if(!mProfile->doStoreBitmap() && !mProfile->isRenderTarget() && !mProfile->isDynamic() && !mProfile->isZTarget())
  419. copyIntoCache();
  420. release();
  421. }
  422. void GFXGLTextureObject::resurrect()
  423. {
  424. if(!mIsZombie)
  425. return;
  426. glGenTextures(1, &mHandle);
  427. glGenBuffers(1, &mBuffer);
  428. }
  429. F32 GFXGLTextureObject::getMaxUCoord() const
  430. {
  431. return mBinding == GL_TEXTURE_2D ? 1.0f : (F32)getWidth();
  432. }
  433. F32 GFXGLTextureObject::getMaxVCoord() const
  434. {
  435. return mBinding == GL_TEXTURE_2D ? 1.0f : (F32)getHeight();
  436. }
  437. const String GFXGLTextureObject::describeSelf() const
  438. {
  439. String ret = Parent::describeSelf();
  440. ret += String::ToString(" GL Handle: %i", mHandle);
  441. return ret;
  442. }