mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-07 19:58:32 +09:00
[Chore] (MG_State/TextureObject): separate TextureObjectWithOneMipmap
This commit is contained in:
@@ -23,7 +23,9 @@ namespace MobileGL {
|
||||
Texture1D,
|
||||
Texture2D,
|
||||
Texture3D,
|
||||
ProxyTexture1D,
|
||||
ProxyTexture2D,
|
||||
ProxyTexture3D,
|
||||
Texture1DArray,
|
||||
ProxyTexture1DArray,
|
||||
TextureRectangle,
|
||||
|
||||
@@ -10,45 +10,6 @@ namespace MobileGL {
|
||||
m_sampler = MakeShared<SamplerObject>(0);
|
||||
}
|
||||
|
||||
Uint TextureObjectBase::GetMipmapLevelCount() const {
|
||||
return m_textureStorage.GetLevelCount();
|
||||
}
|
||||
|
||||
const IntVec3 TextureObjectBase::GetMipmapTexelSize(TextureUploadTarget target, Uint mipmapLevel) const {
|
||||
return m_textureStorage.GetTexelSize(GetIndexOfTextureUploadTarget(target), mipmapLevel);
|
||||
}
|
||||
|
||||
const SizeT TextureObjectBase::GetMipmapByteSize(TextureUploadTarget target, Uint mipmapLevel) const {
|
||||
return m_textureStorage.GetByteSize(GetIndexOfTextureUploadTarget(target), mipmapLevel);
|
||||
}
|
||||
|
||||
void TextureObjectBase::AllocateStorage(TextureUploadTarget uploadTarget, Uint mipmapLevel,
|
||||
MipmapInput input) {
|
||||
// don't care target, index always 0
|
||||
m_textureStorage.AllocateLevel(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel, input);
|
||||
}
|
||||
void TextureObjectBase::UpdateMipmapSubData(TextureUploadTarget uploadTarget, Uint mipmapLevel,
|
||||
DataPtr input) {
|
||||
// ditto
|
||||
m_textureStorage.UpdateSubData(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel, input);
|
||||
}
|
||||
void* TextureObjectBase::MapMipmapData(TextureUploadTarget uploadTarget, Uint mipmapLevel) {
|
||||
return m_textureStorage.MapData(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel);
|
||||
}
|
||||
|
||||
void TextureObjectBase::MarkStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel, bool dirty) {
|
||||
// ditto
|
||||
m_textureStorage.MarkDirty(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel, dirty);
|
||||
}
|
||||
|
||||
bool TextureObjectBase::IsStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel) const {
|
||||
return m_textureStorage.IsDirty(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel);
|
||||
}
|
||||
|
||||
// void TextureObjectBase::SetMipmapLevel(const MipmapLevelInput& level) {
|
||||
// SetMipmapImpl(level);
|
||||
// }
|
||||
|
||||
TextureInternalFormat TextureObjectBase::GetFormat() const {
|
||||
return m_internalFormat;
|
||||
}
|
||||
@@ -58,59 +19,25 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
IntVec3 TextureObjectBase::GetBaseSize() const {
|
||||
if (m_textureStorage.GetLevelCount() == 0) {
|
||||
return {0, 0, 0};
|
||||
}
|
||||
return m_textureStorage.GetTexelSize(0, 0);
|
||||
return {0, 0, 0};
|
||||
}
|
||||
|
||||
SharedPtr<SamplerObject> TextureObjectBase::GetSamplerObject() const {
|
||||
return m_sampler;
|
||||
}
|
||||
|
||||
// const Vector<MipmapLevelInternal>& TextureObjectBase::GetMipmaps() const {
|
||||
// return m_mipmaps;
|
||||
// }
|
||||
|
||||
Bool TextureObjectBase::IsComplete() const {
|
||||
if (m_internalFormat == TextureInternalFormat::Unknown) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SizeT levelCount = m_textureStorage.GetLevelCount();
|
||||
if (levelCount == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < levelCount; ++i) {
|
||||
const auto& levelSize = m_textureStorage.GetTexelSize(0, i);
|
||||
if (levelSize.x() <= 0 || levelSize.y() <= 0 || levelSize.z() <= 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add more completeness checks based on texture type and mipmap levels
|
||||
return true;
|
||||
}
|
||||
|
||||
// MipmapLevelInternal& TextureObjectBase::GetMipmap(TextureUploadTarget target, Int index) {
|
||||
// if (index >= m_mipmaps.size()) {
|
||||
// MOBILEGL_ASSERT(false, "GetMipmap: index %d out of bounds, returning last mipmap level", index);
|
||||
// index = static_cast<Int>(m_mipmaps.size() - 1);
|
||||
// }
|
||||
// return m_mipmaps[index];
|
||||
// }
|
||||
|
||||
void TextureObjectBase::SetInternalFormat(TextureInternalFormat format) {
|
||||
m_internalFormat = format;
|
||||
}
|
||||
|
||||
// void TextureObjectBase::UnmarkMipmapDirty(Int index) {
|
||||
// if (index >= 0 && index < static_cast<Int>(m_mipmaps.size())) {
|
||||
// m_mipmaps[index].dirty = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
Uint TextureObjectBase::GetExternalIndex() const {
|
||||
return m_externalIndex;
|
||||
}
|
||||
@@ -173,6 +100,68 @@ namespace MobileGL {
|
||||
m_levelRange.y() = maxLevel;
|
||||
}
|
||||
|
||||
Uint TextureObjectWithOneMipmap::GetMipmapLevelCount() const {
|
||||
return m_textureStorage.GetLevelCount();
|
||||
}
|
||||
|
||||
const IntVec3 TextureObjectWithOneMipmap::GetMipmapTexelSize(TextureUploadTarget target, Uint mipmapLevel) const {
|
||||
return m_textureStorage.GetTexelSize(GetIndexOfTextureUploadTarget(target), mipmapLevel);
|
||||
}
|
||||
|
||||
const SizeT TextureObjectWithOneMipmap::GetMipmapByteSize(TextureUploadTarget target, Uint mipmapLevel) const {
|
||||
return m_textureStorage.GetByteSize(GetIndexOfTextureUploadTarget(target), mipmapLevel);
|
||||
}
|
||||
|
||||
void TextureObjectWithOneMipmap::AllocateStorage(TextureUploadTarget uploadTarget, Uint mipmapLevel,
|
||||
MipmapInput input) {
|
||||
// don't care target, index always 0
|
||||
m_textureStorage.AllocateLevel(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel, input);
|
||||
}
|
||||
void TextureObjectWithOneMipmap::UpdateMipmapSubData(TextureUploadTarget uploadTarget, Uint mipmapLevel,
|
||||
DataPtr input) {
|
||||
// ditto
|
||||
m_textureStorage.UpdateSubData(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel, input);
|
||||
}
|
||||
void* TextureObjectWithOneMipmap::MapMipmapData(TextureUploadTarget uploadTarget, Uint mipmapLevel) {
|
||||
return m_textureStorage.MapData(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel);
|
||||
}
|
||||
|
||||
void TextureObjectWithOneMipmap::MarkStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel, bool dirty) {
|
||||
// ditto
|
||||
m_textureStorage.MarkDirty(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel, dirty);
|
||||
}
|
||||
|
||||
bool TextureObjectWithOneMipmap::IsStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel) const {
|
||||
return m_textureStorage.IsDirty(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel);
|
||||
}
|
||||
|
||||
IntVec3 TextureObjectWithOneMipmap::GetBaseSize() const {
|
||||
if (m_textureStorage.GetLevelCount() == 0) {
|
||||
return {0, 0, 0};
|
||||
}
|
||||
return m_textureStorage.GetTexelSize(0, 0);
|
||||
}
|
||||
|
||||
Bool TextureObjectWithOneMipmap::IsComplete() const {
|
||||
if (!TextureObjectBase::IsComplete())
|
||||
return false;
|
||||
|
||||
SizeT levelCount = m_textureStorage.GetLevelCount();
|
||||
if (levelCount == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < levelCount; ++i) {
|
||||
const auto& levelSize = m_textureStorage.GetTexelSize(0, i);
|
||||
if (levelSize.x() <= 0 || levelSize.y() <= 0 || levelSize.z() <= 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add more completeness checks based on texture type and mipmap levels
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: add other texture types as needed
|
||||
|
||||
} // namespace GLState
|
||||
|
||||
@@ -46,14 +46,15 @@ namespace MobileGL {
|
||||
TextureObjectBase(TextureTarget target, Uint externalIndex);
|
||||
virtual ~TextureObjectBase() = default;
|
||||
|
||||
Uint GetMipmapLevelCount() const override;
|
||||
const IntVec3 GetMipmapTexelSize(TextureUploadTarget target, Uint mipmapLevel) const override;
|
||||
const SizeT GetMipmapByteSize(TextureUploadTarget target, Uint mipmapLevel) const override;
|
||||
void AllocateStorage(TextureUploadTarget uploadTarget, Uint mipmapLevel, MipmapInput input) override;
|
||||
void UpdateMipmapSubData(TextureUploadTarget uploadTarget, Uint mipmapLevel, DataPtr input) override;
|
||||
void* MapMipmapData(TextureUploadTarget uploadTarget, Uint mipmapLevel) override;
|
||||
void MarkStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel, bool dirty) override;
|
||||
bool IsStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel) const override;
|
||||
// Mipmap ops
|
||||
Uint GetMipmapLevelCount() const = 0;
|
||||
const IntVec3 GetMipmapTexelSize(TextureUploadTarget target, Uint mipmapLevel) const = 0;
|
||||
const SizeT GetMipmapByteSize(TextureUploadTarget target, Uint mipmapLevel) const = 0;
|
||||
void AllocateStorage(TextureUploadTarget uploadTarget, Uint mipmapLevel, MipmapInput input) = 0;
|
||||
void UpdateMipmapSubData(TextureUploadTarget uploadTarget, Uint mipmapLevel, DataPtr input) = 0;
|
||||
void* MapMipmapData(TextureUploadTarget uploadTarget, Uint mipmapLevel) = 0;
|
||||
void MarkStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel, bool dirty) = 0;
|
||||
bool IsStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel) const = 0;
|
||||
|
||||
TextureInternalFormat GetFormat() const override;
|
||||
TextureTarget GetTarget() const override;
|
||||
@@ -74,14 +75,32 @@ namespace MobileGL {
|
||||
const Uint m_externalIndex;
|
||||
const TextureTarget m_target = TextureTarget::Unknown;
|
||||
TextureInternalFormat m_internalFormat = TextureInternalFormat::Unknown;
|
||||
// Vector<MipmapLevelInternal> m_mipmaps = {};
|
||||
TextureStorage<1> m_textureStorage;
|
||||
SharedPtr<SamplerObject> m_sampler = nullptr;
|
||||
FloatVec4 m_borderColor = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
TextureSwizzleParam m_swizzleParams[4] = {TextureSwizzleParam::Red, TextureSwizzleParam::Green,
|
||||
TextureSwizzleParam::Blue, TextureSwizzleParam::Alpha};
|
||||
UintVec2 m_levelRange = {0, 1000};
|
||||
};
|
||||
|
||||
class TextureObjectWithOneMipmap: public TextureObjectBase {
|
||||
public:
|
||||
TextureObjectWithOneMipmap(TextureTarget target, Uint externalIndex): TextureObjectBase(target, externalIndex) {}
|
||||
virtual ~TextureObjectWithOneMipmap() = default;
|
||||
|
||||
Uint GetMipmapLevelCount() const override;
|
||||
const IntVec3 GetMipmapTexelSize(TextureUploadTarget target, Uint mipmapLevel) const override;
|
||||
const SizeT GetMipmapByteSize(TextureUploadTarget target, Uint mipmapLevel) const override;
|
||||
void AllocateStorage(TextureUploadTarget uploadTarget, Uint mipmapLevel, MipmapInput input) override;
|
||||
void UpdateMipmapSubData(TextureUploadTarget uploadTarget, Uint mipmapLevel, DataPtr input) override;
|
||||
void* MapMipmapData(TextureUploadTarget uploadTarget, Uint mipmapLevel) override;
|
||||
void MarkStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel, bool dirty) override;
|
||||
bool IsStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel) const override;
|
||||
|
||||
IntVec3 GetBaseSize() const override;
|
||||
Bool IsComplete() const override;
|
||||
protected:
|
||||
TextureStorage<1> m_textureStorage;
|
||||
};
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -4,13 +4,13 @@ namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
TextureObject1D::TextureObject1D(Uint externalIndex)
|
||||
: TextureObjectBase(TextureTarget::Texture1D, externalIndex) {}
|
||||
: TextureObjectWithOneMipmap(TextureTarget::Texture1D, externalIndex) {}
|
||||
|
||||
Uint TextureObject1D::GetIndexOfTextureUploadTarget(TextureUploadTarget target) const {
|
||||
MOBILEGL_ASSERT(target == TextureUploadTarget::Texture1D, "Invalid TextureUploadTarget!");
|
||||
MOBILEGL_ASSERT(target == TextureUploadTarget::Texture1D || target == TextureUploadTarget::ProxyTexture1D,
|
||||
"Invalid TextureUploadTarget!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
class TextureObject1D : public TextureObjectBase {
|
||||
class TextureObject1D : public TextureObjectWithOneMipmap {
|
||||
public:
|
||||
explicit TextureObject1D(Uint externalIndex);
|
||||
|
||||
|
||||
@@ -4,10 +4,11 @@ namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
TextureObject2D::TextureObject2D(Uint externalIndex)
|
||||
: TextureObjectBase(TextureTarget::Texture2D, externalIndex) {}
|
||||
: TextureObjectWithOneMipmap(TextureTarget::Texture2D, externalIndex) {}
|
||||
|
||||
Uint TextureObject2D::GetIndexOfTextureUploadTarget(TextureUploadTarget target) const {
|
||||
MOBILEGL_ASSERT(target == TextureUploadTarget::Texture1D, "Invalid TextureUploadTarget!");
|
||||
MOBILEGL_ASSERT(target == TextureUploadTarget::Texture2D || target == TextureUploadTarget::ProxyTexture2D,
|
||||
"Invalid TextureUploadTarget!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
class TextureObject2D : public TextureObjectBase {
|
||||
class TextureObject2D : public TextureObjectWithOneMipmap {
|
||||
public:
|
||||
explicit TextureObject2D(Uint externalIndex);
|
||||
|
||||
|
||||
@@ -4,10 +4,11 @@ namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
TextureObject3D::TextureObject3D(Uint externalIndex)
|
||||
: TextureObjectBase(TextureTarget::Texture3D, externalIndex) {}
|
||||
: TextureObjectWithOneMipmap(TextureTarget::Texture3D, externalIndex) {}
|
||||
|
||||
Uint TextureObject3D::GetIndexOfTextureUploadTarget(TextureUploadTarget target) const {
|
||||
MOBILEGL_ASSERT(target == TextureUploadTarget::Texture3D, "Invalid TextureUploadTarget!");
|
||||
MOBILEGL_ASSERT(target == TextureUploadTarget::Texture3D || target == TextureUploadTarget::ProxyTexture3D,
|
||||
"Invalid TextureUploadTarget!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
namespace GLState {
|
||||
class TextureObject3D : public TextureObjectBase {
|
||||
class TextureObject3D : public TextureObjectWithOneMipmap {
|
||||
public:
|
||||
explicit TextureObject3D(Uint externalIndex);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user