From: Mikko Rasa Date: Wed, 10 Nov 2021 18:08:34 +0000 (+0200) Subject: Move the Resource function override of Texture classes into backend X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f73e671dcb36c097647cddbf5b1eaaad2ffc9299;p=libs%2Fgl.git Move the Resource function override of Texture classes into backend There's enough differences between APIs that these can't be sensibly kept in the common classes. --- diff --git a/source/backends/opengl/texture1d_backend.cpp b/source/backends/opengl/texture1d_backend.cpp index a94a5c44..a270468b 100644 --- a/source/backends/opengl/texture1d_backend.cpp +++ b/source/backends/opengl/texture1d_backend.cpp @@ -62,5 +62,11 @@ void OpenGLTexture1D::sub_image(unsigned level, int x, unsigned wd, const void * } } +size_t OpenGLTexture1D::get_data_size() const +{ + unsigned width = static_cast(this)->width; + return id ? width*get_pixel_size(storage_fmt) : 0; +} + } // namespace GL } // namespace Msp diff --git a/source/backends/opengl/texture1d_backend.h b/source/backends/opengl/texture1d_backend.h index 449118d9..8c0fa8c6 100644 --- a/source/backends/opengl/texture1d_backend.h +++ b/source/backends/opengl/texture1d_backend.h @@ -13,6 +13,11 @@ protected: void allocate(); void sub_image(unsigned, int, unsigned, const void *); + +public: + virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } + virtual std::size_t get_data_size() const; + virtual void unload() { } }; using Texture1DBackend = OpenGLTexture1D; diff --git a/source/backends/opengl/texture2d_backend.cpp b/source/backends/opengl/texture2d_backend.cpp index 578cefe3..72962117 100644 --- a/source/backends/opengl/texture2d_backend.cpp +++ b/source/backends/opengl/texture2d_backend.cpp @@ -95,11 +95,18 @@ void OpenGLTexture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsig glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); } -Resource::AsyncLoader *OpenGLTexture2D::create_async_loader(IO::Seekable &io) +Resource::AsyncLoader *OpenGLTexture2D::load(IO::Seekable &io, const Resources *) { return new AsyncLoader(static_cast(*this), io); } +uint64_t OpenGLTexture2D::get_data_size() const +{ + unsigned width = static_cast(this)->width; + unsigned height = static_cast(this)->height; + return id ? width*height*get_pixel_size(format) : 0; +} + void OpenGLTexture2D::unload() { glDeleteTextures(1, &id); diff --git a/source/backends/opengl/texture2d_backend.h b/source/backends/opengl/texture2d_backend.h index 595c51f5..af9f482c 100644 --- a/source/backends/opengl/texture2d_backend.h +++ b/source/backends/opengl/texture2d_backend.h @@ -19,8 +19,10 @@ protected: void sub_image(unsigned, int, int, unsigned, unsigned, const void *); void sub_image(unsigned, int, int, unsigned, unsigned, const Buffer &, unsigned); - Resource::AsyncLoader *create_async_loader(IO::Seekable &); - void unload(); +public: + virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0); + virtual std::size_t get_data_size() const; + virtual void unload(); }; using Texture2DBackend = OpenGLTexture2D; diff --git a/source/backends/opengl/texture2dmultisample_backend.cpp b/source/backends/opengl/texture2dmultisample_backend.cpp index c9faa85e..e6ee7614 100644 --- a/source/backends/opengl/texture2dmultisample_backend.cpp +++ b/source/backends/opengl/texture2dmultisample_backend.cpp @@ -41,5 +41,13 @@ void OpenGLTexture2DMultisample::allocate() apply_swizzle(); } +size_t OpenGLTexture2DMultisample::get_data_size() const +{ + unsigned width = static_cast(this)->width; + unsigned height = static_cast(this)->height; + unsigned samples = static_cast(this)->samples; + return width*height*get_pixel_size(format)*samples; +} + } // namespace GL } // namespace Msp diff --git a/source/backends/opengl/texture2dmultisample_backend.h b/source/backends/opengl/texture2dmultisample_backend.h index e8a37e4c..7adb0bf0 100644 --- a/source/backends/opengl/texture2dmultisample_backend.h +++ b/source/backends/opengl/texture2dmultisample_backend.h @@ -12,6 +12,11 @@ protected: OpenGLTexture2DMultisample(); void allocate(); + +public: + virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } + virtual std::size_t get_data_size() const; + virtual void unload() { } }; using Texture2DMultisampleBackend = OpenGLTexture2DMultisample; diff --git a/source/backends/opengl/texture3d_backend.cpp b/source/backends/opengl/texture3d_backend.cpp index d2c1088e..0796472a 100644 --- a/source/backends/opengl/texture3d_backend.cpp +++ b/source/backends/opengl/texture3d_backend.cpp @@ -74,5 +74,13 @@ bool OpenGLTexture3D::is_array() const return target==GL_TEXTURE_2D_ARRAY; } +size_t OpenGLTexture3D::get_data_size() const +{ + unsigned width = static_cast(this)->width; + unsigned height = static_cast(this)->height; + unsigned depth = static_cast(this)->depth; + return id ? width*height*depth*get_pixel_size(storage_fmt) : 0; +} + } // namespace GL } // namespace Msp diff --git a/source/backends/opengl/texture3d_backend.h b/source/backends/opengl/texture3d_backend.h index 33dcee08..9e79f249 100644 --- a/source/backends/opengl/texture3d_backend.h +++ b/source/backends/opengl/texture3d_backend.h @@ -16,6 +16,11 @@ protected: void sub_image(unsigned, int, int, int, unsigned, unsigned, unsigned, const void *); bool is_array() const; + +public: + virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } + virtual std::size_t get_data_size() const; + virtual void unload() { } }; using Texture3DBackend = OpenGLTexture3D; diff --git a/source/backends/opengl/texturecube_backend.cpp b/source/backends/opengl/texturecube_backend.cpp index 39169612..2b9e09a9 100644 --- a/source/backends/opengl/texturecube_backend.cpp +++ b/source/backends/opengl/texturecube_backend.cpp @@ -75,6 +75,13 @@ void OpenGLTextureCube::sub_image(unsigned face, unsigned level, int x, int y, u } } +size_t OpenGLTextureCube::get_data_size() const +{ + unsigned size = static_cast(this)->size; + return id ? size*size*6*get_pixel_size(storage_fmt) : 0; +} + + unsigned get_gl_cube_face(unsigned face) { switch(static_cast(face)) diff --git a/source/backends/opengl/texturecube_backend.h b/source/backends/opengl/texturecube_backend.h index 2b789d2f..ed5f29cb 100644 --- a/source/backends/opengl/texturecube_backend.h +++ b/source/backends/opengl/texturecube_backend.h @@ -13,6 +13,11 @@ protected: void allocate(); void sub_image(unsigned, unsigned, int, int, unsigned, unsigned, const void *); + +public: + virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } + virtual std::size_t get_data_size() const; + virtual void unload() { } }; using TextureCubeBackend = OpenGLTextureCube; diff --git a/source/core/texture1d.cpp b/source/core/texture1d.cpp index 7d357ff2..d6aa1a34 100644 --- a/source/core/texture1d.cpp +++ b/source/core/texture1d.cpp @@ -62,11 +62,6 @@ unsigned Texture1D::get_level_size(unsigned level) const return width>>level; } -uint64_t Texture1D::get_data_size() const -{ - return id ? width*get_pixel_size(storage_fmt) : 0; -} - Texture1D::Loader::Loader(Texture1D &t): DataFile::DerivedObjectLoader(t) diff --git a/source/core/texture1d.h b/source/core/texture1d.h index efd0517d..16c88a18 100644 --- a/source/core/texture1d.h +++ b/source/core/texture1d.h @@ -51,11 +51,6 @@ public: private: unsigned get_n_levels() const; unsigned get_level_size(unsigned) const; - -public: - virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } - virtual std::size_t get_data_size() const; - virtual void unload() { } }; } // namespace GL diff --git a/source/core/texture2d.cpp b/source/core/texture2d.cpp index 9b1c16ea..c9aab79a 100644 --- a/source/core/texture2d.cpp +++ b/source/core/texture2d.cpp @@ -74,16 +74,6 @@ LinAl::Vector Texture2D::get_level_size(unsigned level) const return LinAl::Vector(w, h); } -Resource::AsyncLoader *Texture2D::load(IO::Seekable &io, const Resources *) -{ - return create_async_loader(io); -} - -uint64_t Texture2D::get_data_size() const -{ - return id ? width*height*get_pixel_size(format) : 0; -} - Texture2D::Loader::Loader(Texture2D &t): DataFile::DerivedObjectLoader(t) diff --git a/source/core/texture2d.h b/source/core/texture2d.h index 61a3f29f..3a9edae1 100644 --- a/source/core/texture2d.h +++ b/source/core/texture2d.h @@ -56,11 +56,6 @@ public: private: unsigned get_n_levels() const; LinAl::Vector get_level_size(unsigned) const; - -public: - virtual Resource::AsyncLoader *load(IO::Seekable &, const Resources * = 0); - virtual std::size_t get_data_size() const; - using Texture2DBackend::unload; }; } // namespace GL diff --git a/source/core/texture2dmultisample.cpp b/source/core/texture2dmultisample.cpp index 8ba52522..72c5f129 100644 --- a/source/core/texture2dmultisample.cpp +++ b/source/core/texture2dmultisample.cpp @@ -38,10 +38,5 @@ void Texture2DMultisample::image(const Graphics::Image &, unsigned) throw invalid_operation("Texture2DMultisample::image"); } -uint64_t Texture2DMultisample::get_data_size() const -{ - return id ? width*height*get_pixel_size(format)*samples : 0; -} - } // namespace GL } // namespace Msp diff --git a/source/core/texture2dmultisample.h b/source/core/texture2dmultisample.h index 20c0f864..8e234835 100644 --- a/source/core/texture2dmultisample.h +++ b/source/core/texture2dmultisample.h @@ -35,10 +35,6 @@ public: unsigned get_width() const { return width; } unsigned get_height() const { return height; } unsigned get_samples() const { return samples; } - - virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } - virtual std::size_t get_data_size() const; - virtual void unload() { } }; } // namespace GL diff --git a/source/core/texture3d.cpp b/source/core/texture3d.cpp index c901556a..496b5f1f 100644 --- a/source/core/texture3d.cpp +++ b/source/core/texture3d.cpp @@ -91,11 +91,6 @@ LinAl::Vector Texture3D::get_level_size(unsigned level) const return LinAl::Vector(w, h, d); } -uint64_t Texture3D::get_data_size() const -{ - return id ? width*height*depth*get_pixel_size(storage_fmt) : 0; -} - Texture3D::Loader::Loader(Texture3D &t): DataFile::DerivedObjectLoader(t) diff --git a/source/core/texture3d.h b/source/core/texture3d.h index c1bf8ed8..3009e148 100644 --- a/source/core/texture3d.h +++ b/source/core/texture3d.h @@ -65,11 +65,6 @@ public: protected: unsigned get_n_levels() const; LinAl::Vector get_level_size(unsigned) const; - -public: - virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } - virtual std::size_t get_data_size() const; - virtual void unload() { } }; } // namespace GL diff --git a/source/core/texturecube.cpp b/source/core/texturecube.cpp index 0e0a1fc9..2f36f336 100644 --- a/source/core/texturecube.cpp +++ b/source/core/texturecube.cpp @@ -138,11 +138,6 @@ Vector3 TextureCube::get_texel_direction(TextureCubeFace face, unsigned u, unsig return fv+s*sv+t*tv; } -uint64_t TextureCube::get_data_size() const -{ - return id ? size*size*6*get_pixel_size(storage_fmt) : 0; -} - TextureCube::Loader::Loader(TextureCube &t): DataFile::DerivedObjectLoader(t) diff --git a/source/core/texturecube.h b/source/core/texturecube.h index eef377e3..d444fee5 100644 --- a/source/core/texturecube.h +++ b/source/core/texturecube.h @@ -97,10 +97,6 @@ public: /** Returns a vector pointing to the center of a texel. */ Vector3 get_texel_direction(TextureCubeFace, unsigned, unsigned); - - virtual AsyncLoader *load(IO::Seekable &, const Resources * = 0) { return 0; } - virtual std::size_t get_data_size() const; - virtual void unload() { } }; void operator>>(const LexicalConverter &, TextureCubeFace &);