mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 06:08:30 +09:00
[Feat] (MG_State/TextureState): Add resource version for texture params.
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
// End of Source File Header
|
// End of Source File Header
|
||||||
|
|
||||||
#include "TextureObject.h"
|
#include "TextureObject.h"
|
||||||
|
#include "MG_Util/Types.h"
|
||||||
#include <MG_Util/Metrics/TextureMetrics.h>
|
#include <MG_Util/Metrics/TextureMetrics.h>
|
||||||
|
|
||||||
namespace MobileGL {
|
namespace MobileGL {
|
||||||
@@ -44,6 +45,7 @@ namespace MobileGL {
|
|||||||
|
|
||||||
void TextureObjectBase::SetInternalFormat(TextureInternalFormat format) {
|
void TextureObjectBase::SetInternalFormat(TextureInternalFormat format) {
|
||||||
m_internalFormat = format;
|
m_internalFormat = format;
|
||||||
|
++m_textureParamsVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint TextureObjectBase::GetExternalIndex() const {
|
Uint TextureObjectBase::GetExternalIndex() const {
|
||||||
@@ -56,6 +58,7 @@ namespace MobileGL {
|
|||||||
|
|
||||||
void TextureObjectBase::SetBorderColor(const FloatVec4& color) {
|
void TextureObjectBase::SetBorderColor(const FloatVec4& color) {
|
||||||
m_borderColor = color;
|
m_borderColor = color;
|
||||||
|
++m_textureParamsVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureSwizzleParam TextureObjectBase::GetSwizzleParam(TextureSwizzleParam param) const {
|
TextureSwizzleParam TextureObjectBase::GetSwizzleParam(TextureSwizzleParam param) const {
|
||||||
@@ -98,9 +101,12 @@ namespace MobileGL {
|
|||||||
static_cast<Int>(param));
|
static_cast<Int>(param));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
++m_textureParamsVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureObjectBase::SetSwizzleParamRGBA(const Vec4<TextureSwizzleParam>& values) {
|
void TextureObjectBase::SetSwizzleParamRGBA(const Vec4<TextureSwizzleParam>& values) {
|
||||||
m_swizzleParams = values;
|
m_swizzleParams = values;
|
||||||
|
++m_textureParamsVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UintVec2& TextureObjectBase::GetLevelRange() const {
|
const UintVec2& TextureObjectBase::GetLevelRange() const {
|
||||||
@@ -109,19 +115,26 @@ namespace MobileGL {
|
|||||||
|
|
||||||
void TextureObjectBase::SetBaseLevel(Uint baseLevel) {
|
void TextureObjectBase::SetBaseLevel(Uint baseLevel) {
|
||||||
m_levelRange.x() = baseLevel;
|
m_levelRange.x() = baseLevel;
|
||||||
|
++m_textureParamsVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureObjectBase::SetMaxLevel(Uint maxLevel) {
|
void TextureObjectBase::SetMaxLevel(Uint maxLevel) {
|
||||||
m_levelRange.y() = maxLevel;
|
m_levelRange.y() = maxLevel;
|
||||||
|
++m_textureParamsVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextureObjectBase::IsDirty() const {
|
Bool TextureObjectBase::IsDirty() const {
|
||||||
return m_dirtyBit;
|
return m_dirtyBit;
|
||||||
}
|
}
|
||||||
bool TextureObjectBase::CheckDirtyBit(TextureDirtyBit bit) const {
|
|
||||||
|
Bool TextureObjectBase::CheckDirtyBit(TextureDirtyBit bit) const {
|
||||||
return m_dirtyBit & bit;
|
return m_dirtyBit & bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Uint16 TextureObjectBase::GetTextureParamsVersion() const {
|
||||||
|
return m_textureParamsVersion;
|
||||||
|
}
|
||||||
|
|
||||||
Uint TextureObjectWithOneMipmap::GetMipmapLevelCount() const {
|
Uint TextureObjectWithOneMipmap::GetMipmapLevelCount() const {
|
||||||
return m_textureStorage.GetLevelCount();
|
return m_textureStorage.GetLevelCount();
|
||||||
}
|
}
|
||||||
@@ -151,14 +164,14 @@ namespace MobileGL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextureObjectWithOneMipmap::MarkStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel,
|
void TextureObjectWithOneMipmap::MarkStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel,
|
||||||
bool dirty) {
|
Bool dirty) {
|
||||||
m_textureStorage.MarkDirty(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel, dirty);
|
m_textureStorage.MarkDirty(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel, dirty);
|
||||||
if (dirty) {
|
if (dirty) {
|
||||||
m_dirtyBit.Set(TextureDirtyBit::StorageDirtyBit);
|
m_dirtyBit.Set(TextureDirtyBit::StorageDirtyBit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextureObjectWithOneMipmap::IsStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel) const {
|
Bool TextureObjectWithOneMipmap::IsStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel) const {
|
||||||
return m_textureStorage.IsDirty(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel);
|
return m_textureStorage.IsDirty(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +193,7 @@ namespace MobileGL {
|
|||||||
|
|
||||||
// For some reason mojang decided to have 0x0 in last level mipmap
|
// For some reason mojang decided to have 0x0 in last level mipmap
|
||||||
// Relaxing checks for that
|
// Relaxing checks for that
|
||||||
bool hadZero = false;
|
Bool hadZero = false;
|
||||||
for (SizeT i = 0; i < levelCount; ++i) {
|
for (SizeT i = 0; i < levelCount; ++i) {
|
||||||
const auto& levelSize = m_textureStorage.GetTexelSize(0, i);
|
const auto& levelSize = m_textureStorage.GetTexelSize(0, i);
|
||||||
if (levelSize.x() <= 0 || levelSize.y() <= 0 || levelSize.z() <= 0) {
|
if (levelSize.x() <= 0 || levelSize.y() <= 0 || levelSize.z() <= 0) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
namespace MobileGL {
|
namespace MobileGL {
|
||||||
namespace MG_State {
|
namespace MG_State {
|
||||||
namespace GLState {
|
namespace GLState {
|
||||||
enum class TextureDirtyBit: Uint8 {
|
enum class TextureDirtyBit : Uint8 {
|
||||||
None = 0,
|
None = 0,
|
||||||
StorageDirtyBit = 1 << 0, // refers to mipmap or TexBuffer according to tex type
|
StorageDirtyBit = 1 << 0, // refers to mipmap or TexBuffer according to tex type
|
||||||
ParamDirtyBit = 1 << 1
|
ParamDirtyBit = 1 << 1
|
||||||
@@ -47,8 +47,9 @@ namespace MobileGL {
|
|||||||
virtual const UintVec2& GetLevelRange() const = 0;
|
virtual const UintVec2& GetLevelRange() const = 0;
|
||||||
virtual void SetBaseLevel(Uint baseLevel) = 0;
|
virtual void SetBaseLevel(Uint baseLevel) = 0;
|
||||||
virtual void SetMaxLevel(Uint maxLevel) = 0;
|
virtual void SetMaxLevel(Uint maxLevel) = 0;
|
||||||
virtual bool IsDirty() const = 0;
|
virtual Bool IsDirty() const = 0;
|
||||||
virtual bool CheckDirtyBit(TextureDirtyBit bit) const = 0;
|
virtual Bool CheckDirtyBit(TextureDirtyBit bit) const = 0;
|
||||||
|
virtual Uint16 GetTextureParamsVersion() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual Uint GetIndexOfTextureUploadTarget(TextureUploadTarget target) const = 0;
|
virtual Uint GetIndexOfTextureUploadTarget(TextureUploadTarget target) const = 0;
|
||||||
@@ -75,8 +76,9 @@ namespace MobileGL {
|
|||||||
const UintVec2& GetLevelRange() const override;
|
const UintVec2& GetLevelRange() const override;
|
||||||
void SetBaseLevel(Uint baseLevel) override;
|
void SetBaseLevel(Uint baseLevel) override;
|
||||||
void SetMaxLevel(Uint maxLevel) override;
|
void SetMaxLevel(Uint maxLevel) override;
|
||||||
bool IsDirty() const override;
|
Bool IsDirty() const override;
|
||||||
bool CheckDirtyBit(TextureDirtyBit bit) const override;
|
Bool CheckDirtyBit(TextureDirtyBit bit) const override;
|
||||||
|
Uint16 GetTextureParamsVersion() const override;
|
||||||
virtual void ClearAllStorageDirtyBit() = 0;
|
virtual void ClearAllStorageDirtyBit() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -88,6 +90,7 @@ namespace MobileGL {
|
|||||||
Vec4<TextureSwizzleParam> m_swizzleParams = {TextureSwizzleParam::Red, TextureSwizzleParam::Green,
|
Vec4<TextureSwizzleParam> m_swizzleParams = {TextureSwizzleParam::Red, TextureSwizzleParam::Green,
|
||||||
TextureSwizzleParam::Blue, TextureSwizzleParam::Alpha};
|
TextureSwizzleParam::Blue, TextureSwizzleParam::Alpha};
|
||||||
UintVec2 m_levelRange = {0, 1000};
|
UintVec2 m_levelRange = {0, 1000};
|
||||||
|
Uint16 m_textureParamsVersion = 0;
|
||||||
|
|
||||||
Flags<TextureDirtyBit> m_dirtyBit = TextureDirtyBit::None;
|
Flags<TextureDirtyBit> m_dirtyBit = TextureDirtyBit::None;
|
||||||
};
|
};
|
||||||
@@ -105,8 +108,9 @@ namespace MobileGL {
|
|||||||
virtual void AllocateStorage(TextureUploadTarget uploadTarget, Uint mipmapLevel, MipmapInput input) = 0;
|
virtual void AllocateStorage(TextureUploadTarget uploadTarget, Uint mipmapLevel, MipmapInput input) = 0;
|
||||||
virtual void UpdateMipmapSubData(TextureUploadTarget uploadTarget, Uint mipmapLevel, DataPtr input) = 0;
|
virtual void UpdateMipmapSubData(TextureUploadTarget uploadTarget, Uint mipmapLevel, DataPtr input) = 0;
|
||||||
virtual void* MapMipmapData(TextureUploadTarget uploadTarget, Uint mipmapLevel) = 0;
|
virtual void* MapMipmapData(TextureUploadTarget uploadTarget, Uint mipmapLevel) = 0;
|
||||||
virtual void MarkStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel, bool dirty = true) = 0;
|
virtual void MarkStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel,
|
||||||
virtual bool IsStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel) const = 0;
|
Bool dirty = true) = 0;
|
||||||
|
virtual Bool IsStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TextureObjectWithOneMipmap : public TextureObjectMipmap {
|
class TextureObjectWithOneMipmap : public TextureObjectMipmap {
|
||||||
@@ -121,8 +125,8 @@ namespace MobileGL {
|
|||||||
void AllocateStorage(TextureUploadTarget uploadTarget, Uint mipmapLevel, MipmapInput input) override;
|
void AllocateStorage(TextureUploadTarget uploadTarget, Uint mipmapLevel, MipmapInput input) override;
|
||||||
void UpdateMipmapSubData(TextureUploadTarget uploadTarget, Uint mipmapLevel, DataPtr input) override;
|
void UpdateMipmapSubData(TextureUploadTarget uploadTarget, Uint mipmapLevel, DataPtr input) override;
|
||||||
void* MapMipmapData(TextureUploadTarget uploadTarget, Uint mipmapLevel) override;
|
void* MapMipmapData(TextureUploadTarget uploadTarget, Uint mipmapLevel) override;
|
||||||
void MarkStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel, bool dirty) override;
|
void MarkStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel, Bool dirty) override;
|
||||||
bool IsStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel) const override;
|
Bool IsStorageDirty(TextureUploadTarget uploadTarget, Uint mipmapLevel) const override;
|
||||||
void ClearAllStorageDirtyBit() override;
|
void ClearAllStorageDirtyBit() override;
|
||||||
|
|
||||||
IntVec3 GetBaseSize() const override;
|
IntVec3 GetBaseSize() const override;
|
||||||
|
|||||||
Reference in New Issue
Block a user