gfxGLTextureObject.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifndef _GFXGLTEXTUREOBJECT_H
  23. #define _GFXGLTEXTUREOBJECT_H
  24. #include "gfx/gfxTextureObject.h"
  25. #include "gfx/gl/ggl/ggl.h"
  26. class GFXGLDevice;
  27. class GFXGLTextureObject : public GFXTextureObject
  28. {
  29. public:
  30. GFXGLTextureObject(GFXDevice * aDevice, GFXTextureProfile *profile);
  31. virtual ~GFXGLTextureObject();
  32. void release();
  33. inline GLuint getHandle() const { return mHandle; }
  34. inline GLenum getBinding() const { return mBinding; }
  35. inline GLuint getBuffer() const { return mBuffer; }
  36. inline bool isZombie() const { return mIsZombie; }
  37. /// Binds the texture to the given texture unit
  38. /// and applies the current sampler state because GL tracks
  39. /// filtering and wrapper per object, while GFX tracks per sampler.
  40. void bind(U32 textureUnit) const;
  41. /// @return An array containing the texture data
  42. /// @note You are responsible for deleting the returned data! (Use delete[])
  43. U8* getTextureData();
  44. virtual F32 getMaxUCoord() const;
  45. virtual F32 getMaxVCoord() const;
  46. void reloadFromCache(); ///< Reloads texture from zombie cache, used by GFXGLTextureManager to resurrect the texture.
  47. #ifdef TORQUE_DEBUG
  48. virtual void pureVirtualCrash() {}
  49. #endif
  50. /// Get/set data from texture (for dynamic textures and render targets)
  51. /// @attention DO NOT READ FROM THE RETURNED RECT! It is not guaranteed to work and may incur significant performance penalties.
  52. virtual GFXLockedRect* lock(U32 mipLevel = 0, RectI *inRect = NULL);
  53. virtual void unlock(U32 mipLevel = 0 );
  54. virtual bool copyToBmp(GBitmap *); ///< Not implemented
  55. bool mIsNPoT2;
  56. // GFXResource interface
  57. virtual void zombify();
  58. virtual void resurrect();
  59. virtual const String describeSelf() const;
  60. private:
  61. friend class GFXGLTextureManager;
  62. typedef GFXTextureObject Parent;
  63. /// Internal GL object
  64. GLuint mHandle;
  65. GLuint mBuffer;
  66. GLenum mBinding;
  67. U32 mBytesPerTexel;
  68. GFXLockedRect mLockedRect;
  69. RectI mLockedRectRect;
  70. /// Pointer to owner device
  71. GFXGLDevice* mGLDevice;
  72. bool mIsZombie;
  73. U8* mZombieCache;
  74. void copyIntoCache();
  75. };
  76. #endif