gfxGLTextureObject.h 3.6 KB

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