| 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 | #include "BsGLTextureManager.h" |
| 4 | #include "RenderAPI/BsRenderAPI.h" |
| 5 | #include "BsGLRenderTexture.h" |
| 6 | #include "BsGLPixelFormat.h" |
| 7 | |
| 8 | namespace bs |
| 9 | { |
| 10 | GLTextureManager::GLTextureManager(ct::GLSupport& support) |
| 11 | :TextureManager(), mGLSupport(support) |
| 12 | { |
| 13 | |
| 14 | } |
| 15 | |
| 16 | SPtr<RenderTexture> GLTextureManager::createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc) |
| 17 | { |
| 18 | GLRenderTexture* tex = new (bs_alloc<GLRenderTexture>()) GLRenderTexture(desc); |
| 19 | |
| 20 | return bs_core_ptr<GLRenderTexture>(tex); |
| 21 | } |
| 22 | |
| 23 | PixelFormat GLTextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) |
| 24 | { |
| 25 | // Check if this is a valid rendertarget format |
| 26 | if(usage & TU_RENDERTARGET) |
| 27 | return ct::GLRTTManager::instance().getSupportedAlternative(format); |
| 28 | |
| 29 | return ct::GLPixelUtil::getClosestSupportedPF(format, ttype, usage); |
| 30 | } |
| 31 | |
| 32 | namespace ct |
| 33 | { |
| 34 | GLTextureManager::GLTextureManager(GLSupport& support) |
| 35 | :mGLSupport(support) |
| 36 | { } |
| 37 | |
| 38 | SPtr<Texture> GLTextureManager::createTextureInternal(const TEXTURE_DESC& desc, |
| 39 | const SPtr<PixelData>& initialData, GpuDeviceFlags deviceMask) |
| 40 | { |
| 41 | GLTexture* tex = new (bs_alloc<GLTexture>()) GLTexture(mGLSupport, desc, initialData, deviceMask); |
| 42 | |
| 43 | SPtr<GLTexture> texPtr = bs_shared_ptr<GLTexture>(tex); |
| 44 | texPtr->_setThisPtr(texPtr); |
| 45 | |
| 46 | return texPtr; |
| 47 | } |
| 48 | |
| 49 | SPtr<RenderTexture> GLTextureManager::createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc, |
| 50 | UINT32 deviceIdx) |
| 51 | { |
| 52 | SPtr<GLRenderTexture> texPtr = bs_shared_ptr_new<GLRenderTexture>(desc, deviceIdx); |
| 53 | texPtr->_setThisPtr(texPtr); |
| 54 | |
| 55 | return texPtr; |
| 56 | } |
| 57 | } |
| 58 | } |