From 78f9dfa8ef51cc3f0c12b41c87e9396daa82d197 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 15 Feb 2020 02:58:41 +0800 Subject: [PATCH] Remove unnecessary constructors. --- cocos/renderer/backend/Texture.cpp | 21 --------------------- cocos/renderer/backend/Texture.h | 14 +------------- cocos/renderer/backend/metal/TextureMTL.mm | 9 +++++---- cocos/renderer/backend/opengl/TextureGL.cpp | 11 ++++++----- 4 files changed, 12 insertions(+), 43 deletions(-) diff --git a/cocos/renderer/backend/Texture.cpp b/cocos/renderer/backend/Texture.cpp index aedeeb69d9..7b55c44366 100644 --- a/cocos/renderer/backend/Texture.cpp +++ b/cocos/renderer/backend/Texture.cpp @@ -98,16 +98,6 @@ namespace } } -TextureBackend::TextureBackend(const TextureDescriptor& descriptor) - : _bitsPerElement(computeBitsPerElement(descriptor.textureFormat)) - , _width(descriptor.width) - , _height(descriptor.height) - , _textureType(descriptor.textureType) - , _textureFormat(descriptor.textureFormat) - , _textureUsage(descriptor.textureUsage) -{ -} - TextureBackend::~TextureBackend() {} @@ -121,15 +111,4 @@ void TextureBackend::updateTextureDescriptor(const cocos2d::backend::TextureDesc _height = descriptor.height; } -Texture2DBackend::Texture2DBackend(const TextureDescriptor& descriptor) - : TextureBackend(descriptor) -{ -} - -TextureCubemapBackend::TextureCubemapBackend(const TextureDescriptor &descriptor) - : TextureBackend(descriptor) -{ - -} - CC_BACKEND_END diff --git a/cocos/renderer/backend/Texture.h b/cocos/renderer/backend/Texture.h index 1069be9d48..5c0b1cd7ce 100644 --- a/cocos/renderer/backend/Texture.h +++ b/cocos/renderer/backend/Texture.h @@ -110,7 +110,7 @@ protected: /** * @param descriptor Specifies the texture descirptor. */ - TextureBackend(const TextureDescriptor& descriptor); + TextureBackend() {} virtual ~TextureBackend(); /// The bytes of all components. @@ -184,12 +184,6 @@ public: * @return Texture height. */ inline std::size_t getHeight() const { return _height; } - -protected: - /** - * @param descriptor Specifies the texture descriptor. - */ - Texture2DBackend(const TextureDescriptor& descriptor); }; /** @@ -204,12 +198,6 @@ public: * @param data Specifies a pointer to the image data in memory. */ virtual void updateFaceData(TextureCubeFace side, void *data, int index = 0) = 0; - -protected: - /** - * @param descriptor Specifies the texture descriptor. - */ - TextureCubemapBackend(const TextureDescriptor& descriptor); }; //end of _backend group diff --git a/cocos/renderer/backend/metal/TextureMTL.mm b/cocos/renderer/backend/metal/TextureMTL.mm index d4f4b663ef..da5c8b41fb 100644 --- a/cocos/renderer/backend/metal/TextureMTL.mm +++ b/cocos/renderer/backend/metal/TextureMTL.mm @@ -275,7 +275,7 @@ void TextureInfoMTL::recreateSampler(const SamplerDescriptor &descriptor) /// CLASS TextureMTL TextureMTL::TextureMTL(id mtlDevice, const TextureDescriptor& descriptor) -: backend::Texture2DBackend(descriptor), _textureInfo(mtlDevice) +: _textureInfo(mtlDevice) { updateTextureDescriptor(descriptor); } @@ -291,8 +291,9 @@ void TextureMTL::updateSamplerDescriptor(const SamplerDescriptor &sampler) void TextureMTL::updateTextureDescriptor(const cocos2d::backend::TextureDescriptor &descriptor, int index) { - _textureInfo._descriptor = descriptor; TextureBackend::updateTextureDescriptor(descriptor, index); + + _textureInfo._descriptor = descriptor; _textureInfo.ensure(index, MTL_TEXTURE_2D); updateSamplerDescriptor(descriptor.samplerDescriptor); if (PixelFormat::RGB888 == _textureFormat) @@ -391,7 +392,7 @@ void TextureMTL::generateMipmaps() /// CLASS TextureCubeMTL TextureCubeMTL::TextureCubeMTL(id mtlDevice, const TextureDescriptor& descriptor) -: backend::TextureCubemapBackend(descriptor), _textureInfo(mtlDevice) +: _textureInfo(mtlDevice) { updateTextureDescriptor(descriptor); } @@ -402,7 +403,7 @@ TextureCubeMTL::~TextureCubeMTL() void TextureCubeMTL::updateTextureDescriptor(const cocos2d::backend::TextureDescriptor &descriptor, int index) { - TextureBackend::updateTextureDescriptor(descriptor); + TextureBackend::updateTextureDescriptor(descriptor, index); _textureInfo._descriptor = descriptor; _textureInfo.ensure(index, MTL_TEXTURE_CUBE); diff --git a/cocos/renderer/backend/opengl/TextureGL.cpp b/cocos/renderer/backend/opengl/TextureGL.cpp index 69260418c2..df188c60b3 100644 --- a/cocos/renderer/backend/opengl/TextureGL.cpp +++ b/cocos/renderer/backend/opengl/TextureGL.cpp @@ -114,7 +114,7 @@ GLuint TextureInfoGL::ensure(int index, GLenum target) return texID; } -Texture2DGL::Texture2DGL(const TextureDescriptor& descriptor) : Texture2DBackend(descriptor) +Texture2DGL::Texture2DGL(const TextureDescriptor& descriptor) { updateTextureDescriptor(descriptor); @@ -141,6 +141,7 @@ void Texture2DGL::initWithZeros() void Texture2DGL::updateTextureDescriptor(const cocos2d::backend::TextureDescriptor &descriptor, int index) { TextureBackend::updateTextureDescriptor(descriptor, index); + UtilsGL::toGLTypes(descriptor.textureFormat, _textureInfo.internalFormat, _textureInfo.format, _textureInfo.type, _isCompressed); bool isPow2 = ISPOW2(_width) && ISPOW2(_height); @@ -331,12 +332,10 @@ void Texture2DGL::getBytes(std::size_t x, std::size_t y, std::size_t width, std: } TextureCubeGL::TextureCubeGL(const TextureDescriptor& descriptor) - :TextureCubemapBackend(descriptor) { assert(_width == _height); _textureType = TextureType::TEXTURE_CUBE; - UtilsGL::toGLTypes(_textureFormat, _textureInfo.internalFormat, _textureInfo.format, _textureInfo.type, _isCompressed); - updateSamplerDescriptor(descriptor.samplerDescriptor); + updateTextureDescriptor(descriptor); #if CC_ENABLE_CACHE_TEXTURE_DATA // Listen this event to restored texture id after coming to foreground on Android. @@ -351,8 +350,10 @@ TextureCubeGL::TextureCubeGL(const TextureDescriptor& descriptor) void TextureCubeGL::updateTextureDescriptor(const cocos2d::backend::TextureDescriptor &descriptor, int index) { + backend::TextureCubemapBackend::updateTextureDescriptor(descriptor, index); + UtilsGL::toGLTypes(descriptor.textureFormat, _textureInfo.internalFormat, _textureInfo.format, _textureInfo.type, _isCompressed); - _textureFormat = descriptor.textureFormat; + updateSamplerDescriptor(descriptor.samplerDescriptor); }