mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Fix, Test] (GLImpl, GLState): refuse a compressed texture in glClearTexImage/glClearTexSubImage
This commit is contained in:
@@ -48,6 +48,7 @@ namespace MobileGL {
|
||||
m_dirtyRects.resize(requiredLevelCount);
|
||||
m_compressedData.resize(requiredLevelCount);
|
||||
m_compressedFormats.resize(requiredLevelCount, GL_NONE);
|
||||
m_requestedCompressedFormats.resize(requiredLevelCount, GL_NONE);
|
||||
}
|
||||
|
||||
m_texelSizes[level] = input.texelSize;
|
||||
@@ -79,6 +80,9 @@ namespace MobileGL {
|
||||
m_compressedFormats[level] = GL_NONE;
|
||||
m_compressedData[level].clear();
|
||||
m_compressedData[level].shrink_to_fit();
|
||||
// Same story for the requested-format tag: a respecified level is whatever this
|
||||
// call asked for, and the compressed entry points re-arm it right afterwards.
|
||||
m_requestedCompressedFormats[level] = GL_NONE;
|
||||
}
|
||||
|
||||
void MipmapStorage::SetCompressedImage(Uint level, GLenum internalFormat, const void* data, SizeT size) {
|
||||
@@ -110,6 +114,16 @@ namespace MobileGL {
|
||||
return m_compressedData[level].data();
|
||||
}
|
||||
|
||||
void MipmapStorage::SetRequestedCompressedFormat(Uint level, GLenum internalFormat) {
|
||||
if (level >= m_requestedCompressedFormats.size()) return;
|
||||
m_requestedCompressedFormats[level] = internalFormat;
|
||||
}
|
||||
|
||||
GLenum MipmapStorage::GetRequestedCompressedFormat(Uint level) const {
|
||||
if (level >= m_requestedCompressedFormats.size()) return GL_NONE;
|
||||
return m_requestedCompressedFormats[level];
|
||||
}
|
||||
|
||||
void MipmapStorage::TruncateToLevelCount(SizeT levelCount) {
|
||||
if (levelCount >= m_data.size()) return;
|
||||
|
||||
@@ -120,6 +134,7 @@ namespace MobileGL {
|
||||
m_dirtyRects.resize(levelCount);
|
||||
m_compressedData.resize(levelCount);
|
||||
m_compressedFormats.resize(levelCount);
|
||||
m_requestedCompressedFormats.resize(levelCount);
|
||||
}
|
||||
|
||||
void MipmapStorage::UpdateSubData(Uint level, DataPtr input) {
|
||||
|
||||
@@ -96,6 +96,18 @@ namespace MobileGL {
|
||||
SizeT GetCompressedByteSize(Uint level) const;
|
||||
const void* MapCompressedData(Uint level) const;
|
||||
|
||||
// The compressed internalformat the application ASKED for, which is not the same
|
||||
// question as the one above: the six generic GL_COMPRESSED_* enums let the
|
||||
// implementation choose, MobileGL chooses uncompressed storage, and the level is
|
||||
// deliberately left untagged so GL_TEXTURE_COMPRESSED keeps answering false and
|
||||
// glGetCompressedTexImage is not handed a blob nothing ever compressed. The entry
|
||||
// points that must refuse a compressed image outright (glClearTexImage /
|
||||
// glClearTexSubImage, GL 4.6 core 8.19) still need to know, so the request is
|
||||
// recorded separately. Set right after AllocateLevel, which clears it.
|
||||
void SetRequestedCompressedFormat(Uint level, GLenum internalFormat);
|
||||
// GL_NONE when the level was not requested with a compressed internalformat.
|
||||
GLenum GetRequestedCompressedFormat(Uint level) const;
|
||||
|
||||
protected:
|
||||
// Insert one clamped, non-empty write box, keeping the list disjoint
|
||||
// and bounded (see kMaxDirtyRects).
|
||||
@@ -115,6 +127,7 @@ namespace MobileGL {
|
||||
Vector<Vector<MipmapDirtyRegion>> m_dirtyRects;
|
||||
Vector<Vector<Uint8>> m_compressedData;
|
||||
Vector<GLenum> m_compressedFormats;
|
||||
Vector<GLenum> m_requestedCompressedFormats;
|
||||
};
|
||||
} // namespace GLState
|
||||
} // namespace MG_State
|
||||
|
||||
@@ -111,6 +111,16 @@ namespace MobileGL {
|
||||
return m_storage[targetIndex].MapCompressedData(level);
|
||||
}
|
||||
|
||||
void SetRequestedCompressedFormat(Uint targetIndex, Uint level, GLenum internalFormat) {
|
||||
MOBILEGL_ASSERT(targetIndex < TargetCount, "SetRequestedCompressedFormat: target invalid");
|
||||
m_storage[targetIndex].SetRequestedCompressedFormat(level, internalFormat);
|
||||
}
|
||||
|
||||
GLenum GetRequestedCompressedFormat(Uint targetIndex, Uint level) const {
|
||||
MOBILEGL_ASSERT(targetIndex < TargetCount, "GetRequestedCompressedFormat: target invalid");
|
||||
return m_storage[targetIndex].GetRequestedCompressedFormat(level);
|
||||
}
|
||||
|
||||
protected:
|
||||
Array<MipmapStorage, TargetCount> m_storage;
|
||||
};
|
||||
|
||||
@@ -373,6 +373,18 @@ namespace MobileGL {
|
||||
return m_textureStorage.MapCompressedData(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel);
|
||||
}
|
||||
|
||||
void TextureObjectWithOneMipmap::SetMipmapRequestedCompressedFormat(TextureUploadTarget uploadTarget,
|
||||
Uint mipmapLevel, GLenum internalFormat) {
|
||||
m_textureStorage.SetRequestedCompressedFormat(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel,
|
||||
internalFormat);
|
||||
}
|
||||
|
||||
GLenum TextureObjectWithOneMipmap::GetMipmapRequestedCompressedFormat(TextureUploadTarget uploadTarget,
|
||||
Uint mipmapLevel) const {
|
||||
return m_textureStorage.GetRequestedCompressedFormat(GetIndexOfTextureUploadTarget(uploadTarget),
|
||||
mipmapLevel);
|
||||
}
|
||||
|
||||
IntVec3 TextureObjectWithOneMipmap::GetBaseSize() const {
|
||||
if (m_textureStorage.GetLevelCount() == 0) {
|
||||
return {0, 0, 0};
|
||||
|
||||
@@ -220,6 +220,15 @@ namespace MobileGL::MG_State::GLState {
|
||||
virtual GLenum GetMipmapCompressedFormat(TextureUploadTarget uploadTarget, Uint mipmapLevel) const = 0;
|
||||
virtual SizeT GetMipmapCompressedByteSize(TextureUploadTarget uploadTarget, Uint mipmapLevel) const = 0;
|
||||
virtual const void* MapMipmapCompressedImage(TextureUploadTarget uploadTarget, Uint mipmapLevel) const = 0;
|
||||
|
||||
// The compressed internalformat the level was REQUESTED with, recorded even when MobileGL
|
||||
// answered it with uncompressed storage (the six generic GL_COMPRESSED_* enums) - see
|
||||
// MipmapStorage. Only the entry points GL forbids on a compressed image read it.
|
||||
virtual void SetMipmapRequestedCompressedFormat(TextureUploadTarget uploadTarget, Uint mipmapLevel,
|
||||
GLenum internalFormat) = 0;
|
||||
// GL_NONE when the level was not requested with a compressed internalformat.
|
||||
virtual GLenum GetMipmapRequestedCompressedFormat(TextureUploadTarget uploadTarget,
|
||||
Uint mipmapLevel) const = 0;
|
||||
};
|
||||
|
||||
// Cheap replacement for dynamic_cast on the hot path: TextureObjectMipmap is the
|
||||
@@ -286,6 +295,9 @@ namespace MobileGL::MG_State::GLState {
|
||||
GLenum GetMipmapCompressedFormat(TextureUploadTarget uploadTarget, Uint mipmapLevel) const override;
|
||||
SizeT GetMipmapCompressedByteSize(TextureUploadTarget uploadTarget, Uint mipmapLevel) const override;
|
||||
const void* MapMipmapCompressedImage(TextureUploadTarget uploadTarget, Uint mipmapLevel) const override;
|
||||
void SetMipmapRequestedCompressedFormat(TextureUploadTarget uploadTarget, Uint mipmapLevel,
|
||||
GLenum internalFormat) override;
|
||||
GLenum GetMipmapRequestedCompressedFormat(TextureUploadTarget uploadTarget, Uint mipmapLevel) const override;
|
||||
|
||||
IntVec3 GetBaseSize() const override;
|
||||
Bool IsComplete() const override;
|
||||
|
||||
@@ -96,6 +96,18 @@ namespace MobileGL {
|
||||
return m_textureStorage.MapCompressedData(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel);
|
||||
}
|
||||
|
||||
void TextureObject2DCube::SetMipmapRequestedCompressedFormat(TextureUploadTarget uploadTarget,
|
||||
Uint mipmapLevel, GLenum internalFormat) {
|
||||
m_textureStorage.SetRequestedCompressedFormat(GetIndexOfTextureUploadTarget(uploadTarget), mipmapLevel,
|
||||
internalFormat);
|
||||
}
|
||||
|
||||
GLenum TextureObject2DCube::GetMipmapRequestedCompressedFormat(TextureUploadTarget uploadTarget,
|
||||
Uint mipmapLevel) const {
|
||||
return m_textureStorage.GetRequestedCompressedFormat(GetIndexOfTextureUploadTarget(uploadTarget),
|
||||
mipmapLevel);
|
||||
}
|
||||
|
||||
Uint TextureObject2DCube::GetIndexOfTextureUploadTarget(TextureUploadTarget target) const {
|
||||
MOBILEGL_ASSERT(TextureUploadTarget::CubeMapPositiveX <= target &&
|
||||
target <= TextureUploadTarget::CubeMapNegativeZ,
|
||||
|
||||
@@ -39,6 +39,10 @@ namespace MobileGL {
|
||||
SizeT GetMipmapCompressedByteSize(TextureUploadTarget uploadTarget, Uint mipmapLevel) const override;
|
||||
const void* MapMipmapCompressedImage(TextureUploadTarget uploadTarget,
|
||||
Uint mipmapLevel) const override;
|
||||
void SetMipmapRequestedCompressedFormat(TextureUploadTarget uploadTarget, Uint mipmapLevel,
|
||||
GLenum internalFormat) override;
|
||||
GLenum GetMipmapRequestedCompressedFormat(TextureUploadTarget uploadTarget,
|
||||
Uint mipmapLevel) const override;
|
||||
|
||||
IntVec3 GetBaseSize() const override;
|
||||
Bool IsComplete() const override;
|
||||
|
||||
Reference in New Issue
Block a user