| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "BsGLPrerequisites.h" |
| 6 | #include "Image/BsTexture.h" |
| 7 | #include "BsGLSupport.h" |
| 8 | |
| 9 | namespace bs { namespace ct |
| 10 | { |
| 11 | /** @addtogroup GL |
| 12 | * @{ |
| 13 | */ |
| 14 | |
| 15 | /** OpenGL implementation of a texture. */ |
| 16 | class GLTexture : public Texture |
| 17 | { |
| 18 | public: |
| 19 | virtual ~GLTexture(); |
| 20 | |
| 21 | /** Returns OpenGL texture target type. */ |
| 22 | GLenum getGLTextureTarget() const; |
| 23 | |
| 24 | /** Returns internal OpenGL texture handle. */ |
| 25 | GLuint getGLID() const; |
| 26 | |
| 27 | /** Returns the internal OpenGL format used by the texture. */ |
| 28 | GLenum getGLFormat() const { return mGLFormat; } |
| 29 | |
| 30 | /** |
| 31 | * Returns a hardware pixel buffer for a certain face and level of the texture. |
| 32 | * |
| 33 | * @param[in] face Index of the texture face, if texture has more than one. Array index for texture arrays and |
| 34 | * a cube face for cube textures. |
| 35 | * @param[in] mipmap Index of the mip level. 0 being the largest mip level. |
| 36 | * |
| 37 | * @note Cube face indices: +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5) |
| 38 | */ |
| 39 | SPtr<GLPixelBuffer> getBuffer(UINT32 face, UINT32 mipmap); |
| 40 | |
| 41 | /** |
| 42 | * Picks an OpenGL texture target based on the texture type, number of samples per pixel, and number of faces. |
| 43 | */ |
| 44 | static GLenum getGLTextureTarget(TextureType type, UINT32 numSamples, UINT32 numFaces); |
| 45 | |
| 46 | /** Picks an OpenGL texture target based on a GPU program parameter type. */ |
| 47 | static GLenum getGLTextureTarget(GpuParamObjectType type); |
| 48 | |
| 49 | protected: |
| 50 | friend class GLTextureManager; |
| 51 | |
| 52 | GLTexture(GLSupport& support, const TEXTURE_DESC& desc, const SPtr<PixelData>& initialData, |
| 53 | GpuDeviceFlags deviceMask); |
| 54 | |
| 55 | /** @copydoc Texture::initialize */ |
| 56 | void initialize() override; |
| 57 | |
| 58 | /** @copydoc Texture::lock */ |
| 59 | PixelData lockImpl(GpuLockOptions options, UINT32 mipLevel = 0, UINT32 face = 0, UINT32 deviceIdx = 0, |
| 60 | UINT32 queueIdx = 0) override; |
| 61 | |
| 62 | /** @copydoc Texture::unlock */ |
| 63 | void unlockImpl() override; |
| 64 | |
| 65 | /** @copydoc Texture::copyImpl */ |
| 66 | void copyImpl(const SPtr<Texture>& target, const TEXTURE_COPY_DESC& desc, |
| 67 | const SPtr<CommandBuffer>& commandBuffer) override; |
| 68 | |
| 69 | /** @copydoc Texture::readData */ |
| 70 | void readDataImpl(PixelData& dest, UINT32 mipLevel = 0, UINT32 face = 0, UINT32 deviceIdx = 0, |
| 71 | UINT32 queueIdx = 0) override; |
| 72 | |
| 73 | /** @copydoc Texture::writeData */ |
| 74 | void writeDataImpl(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false, |
| 75 | UINT32 queueIdx = 0) override; |
| 76 | |
| 77 | /** Creates pixel buffers for each face and mip level. Texture must have been created previously. */ |
| 78 | void createSurfaceList(); |
| 79 | |
| 80 | /** Creates an empty and uninitialized texture view object. */ |
| 81 | SPtr<TextureView> createView(const TEXTURE_VIEW_DESC& desc) override; |
| 82 | |
| 83 | private: |
| 84 | GLuint mTextureID = 0; |
| 85 | GLenum mGLFormat = 0; |
| 86 | PixelFormat mInternalFormat = PF_UNKNOWN; |
| 87 | GLSupport& mGLSupport; |
| 88 | SPtr<GLPixelBuffer> mLockedBuffer; |
| 89 | |
| 90 | Vector<SPtr<GLPixelBuffer>>mSurfaceList; |
| 91 | }; |
| 92 | |
| 93 | /** @} */ |
| 94 | }} |