mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Feat] (MG_Backend/DirectGLES): implement multisample texture backend
This commit is contained in:
@@ -541,7 +541,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
static_cast<SizeT>(baseSize.y()),
|
static_cast<SizeT>(baseSize.y()),
|
||||||
static_cast<SizeT>(baseSize.z()),
|
static_cast<SizeT>(baseSize.z()),
|
||||||
0,
|
0,
|
||||||
0};
|
0,
|
||||||
|
stateTextureObject->GetSamples(),
|
||||||
|
stateTextureObject->HasFixedSampleLocations()};
|
||||||
switch (stateTextureObject->GetStorageType()) {
|
switch (stateTextureObject->GetStorageType()) {
|
||||||
case TextureStorageType::Mipmap: {
|
case TextureStorageType::Mipmap: {
|
||||||
auto* textureMipmapObject =
|
auto* textureMipmapObject =
|
||||||
@@ -565,6 +567,33 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
&glFormat, &glType);
|
&glFormat, &glType);
|
||||||
|
|
||||||
const auto& uploadTargets = textureMipmapObject->GetUploadTargets();
|
const auto& uploadTargets = textureMipmapObject->GetUploadTargets();
|
||||||
|
if (TextureImpl::IsMultisampleTextureTarget(targetInternal)) {
|
||||||
|
DebugImpl::ErrorLopper::Clear();
|
||||||
|
g_GLESFuncs.glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
|
switch (targetInternal) {
|
||||||
|
case TextureTarget::Texture2DMultisample:
|
||||||
|
g_GLESFuncs.glTexStorage2DMultisample(
|
||||||
|
target, static_cast<GLsizei>(stateTextureObject->GetSamples()), glInternalFormat,
|
||||||
|
static_cast<GLsizei>(baseSize.x()), static_cast<GLsizei>(baseSize.y()),
|
||||||
|
stateTextureObject->HasFixedSampleLocations() ? GL_TRUE : GL_FALSE);
|
||||||
|
break;
|
||||||
|
case TextureTarget::Texture2DMultisampleArray:
|
||||||
|
g_GLESFuncs.glTexStorage3DMultisample(
|
||||||
|
target, static_cast<GLsizei>(stateTextureObject->GetSamples()), glInternalFormat,
|
||||||
|
static_cast<GLsizei>(baseSize.x()), static_cast<GLsizei>(baseSize.y()),
|
||||||
|
static_cast<GLsizei>(baseSize.z()),
|
||||||
|
stateTextureObject->HasFixedSampleLocations() ? GL_TRUE : GL_FALSE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
MOBILEGL_ASSERT(false, "Unexpected multisample target: %d", static_cast<Int>(targetInternal));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (const auto& uploadTarget : uploadTargets) {
|
||||||
|
for (SizeT level = 0; level < mipmapCount; ++level) {
|
||||||
|
textureMipmapObject->MarkStorageDirty(uploadTarget, level, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for (auto& uploadTarget : uploadTargets) {
|
for (auto& uploadTarget : uploadTargets) {
|
||||||
for (SizeT level = 0; level < mipmapCount; ++level) {
|
for (SizeT level = 0; level < mipmapCount; ++level) {
|
||||||
auto levelTexelSize = textureMipmapObject->GetMipmapTexelSize(uploadTarget, level);
|
auto levelTexelSize = textureMipmapObject->GetMipmapTexelSize(uploadTarget, level);
|
||||||
@@ -620,11 +649,24 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
textureMipmapObject->MarkStorageDirty(uploadTarget, level, false);
|
textureMipmapObject->MarkStorageDirty(uploadTarget, level, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_isInitialized = true;
|
m_isInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Update all dirty mipmap levels
|
{ // Update all dirty mipmap levels
|
||||||
|
if (TextureImpl::IsMultisampleTextureTarget(targetInternal)) {
|
||||||
|
const auto& uploadTargets = textureMipmapObject->GetUploadTargets();
|
||||||
|
for (const auto& uploadTarget : uploadTargets) {
|
||||||
|
for (SizeT level = 0; level < mipmapCount; ++level) {
|
||||||
|
if (textureMipmapObject->IsStorageDirty(uploadTarget, level)) {
|
||||||
|
textureMipmapObject->MarkStorageDirty(uploadTarget, level, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
const auto mipmapCount = textureMipmapObject->GetMipmapLevelCount();
|
const auto mipmapCount = textureMipmapObject->GetMipmapLevelCount();
|
||||||
GLenum glInternalFormat, glType, glFormat;
|
GLenum glInternalFormat, glType, glFormat;
|
||||||
TextureImpl::GenerateTextureFormatInfo(textureMipmapObject->GetFormat(), &glInternalFormat,
|
TextureImpl::GenerateTextureFormatInfo(textureMipmapObject->GetFormat(), &glInternalFormat,
|
||||||
@@ -780,6 +822,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto& samplerParams = samplerObject->GetAllSamplerParameters();
|
||||||
|
if (TextureImpl::IsMultisampleTextureTarget(targetInternal)) {
|
||||||
|
m_cacheSamplerParameters = samplerParams;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Bind(target);
|
Bind(target);
|
||||||
DebugImpl::ErrorLopper::Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
DebugImpl::ErrorLopper::Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
||||||
MGLOG_D("%s(%s:%d) ES error: %s", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
MGLOG_D("%s(%s:%d) ES error: %s", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||||
@@ -787,7 +835,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
|
|
||||||
// Update built-in sampler parameters
|
// Update built-in sampler parameters
|
||||||
MGLOG_D("Updating sampler parameters for texture with ID: %u", m_backendTextureId);
|
MGLOG_D("Updating sampler parameters for texture with ID: %u", m_backendTextureId);
|
||||||
const auto& samplerParams = samplerObject->GetAllSamplerParameters();
|
|
||||||
|
|
||||||
#define SYNC_TEX_SAMPLER_PARAM_IF_CHANGED(internalName, glName, type) \
|
#define SYNC_TEX_SAMPLER_PARAM_IF_CHANGED(internalName, glName, type) \
|
||||||
if (m_cacheSamplerParameters.internalName != samplerParams.internalName) { \
|
if (m_cacheSamplerParameters.internalName != samplerParams.internalName) { \
|
||||||
@@ -874,6 +921,13 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TextureImpl::IsMultisampleTextureTarget(targetInternal)) {
|
||||||
|
m_cacheLodRange = stateTextureObject->GetLevelRange();
|
||||||
|
m_cacheSwizzleParams = stateTextureObject->GetAllSwizzleParams();
|
||||||
|
m_cacheBorderColor = stateTextureObject->GetBorderColor();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Bind(target);
|
Bind(target);
|
||||||
DebugImpl::ErrorLopper::Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
DebugImpl::ErrorLopper::Loop([file = __FILE__, line = __LINE__, func = __func__](GLenum err) {
|
||||||
MGLOG_D("%s(%s:%d) ES error: %s", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
MGLOG_D("%s(%s:%d) ES error: %s", func, file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||||
|
|||||||
@@ -162,12 +162,16 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
namespace TextureImpl {
|
namespace TextureImpl {
|
||||||
inline Bool IsSupportedTextureTarget(TextureTarget target) {
|
inline Bool IsSupportedTextureTarget(TextureTarget target) {
|
||||||
if (target == TextureTarget::Texture1D || target == TextureTarget::TextureRectangle ||
|
if (target == TextureTarget::Texture1D || target == TextureTarget::TextureRectangle ||
|
||||||
target == TextureTarget::Texture2DMultisampleArray || target == TextureTarget::Texture1DArray ||
|
target == TextureTarget::Texture1DArray || target == TextureTarget::Texture2DArray)
|
||||||
target == TextureTarget::Texture2DMultisample || target == TextureTarget::Texture2DArray)
|
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Bool IsMultisampleTextureTarget(TextureTarget target) {
|
||||||
|
return target == TextureTarget::Texture2DMultisample ||
|
||||||
|
target == TextureTarget::Texture2DMultisampleArray;
|
||||||
|
}
|
||||||
|
|
||||||
inline Bool SupportsWrapR(TextureTarget target) {
|
inline Bool SupportsWrapR(TextureTarget target) {
|
||||||
return target == TextureTarget::Texture3D || target == TextureTarget::TextureCubeMap;
|
return target == TextureTarget::Texture3D || target == TextureTarget::TextureCubeMap;
|
||||||
}
|
}
|
||||||
@@ -179,11 +183,14 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
SizeT depth = 0;
|
SizeT depth = 0;
|
||||||
SizeT mipmapLevels = 0;
|
SizeT mipmapLevels = 0;
|
||||||
Uint bufferExternalIndex = 0;
|
Uint bufferExternalIndex = 0;
|
||||||
|
Int samples = 0;
|
||||||
|
Bool fixedSampleLocations = true;
|
||||||
|
|
||||||
bool operator==(const StateTextureBasicInfo& other) const {
|
bool operator==(const StateTextureBasicInfo& other) const {
|
||||||
return internalFormat == other.internalFormat && width == other.width && height == other.height &&
|
return internalFormat == other.internalFormat && width == other.width && height == other.height &&
|
||||||
depth == other.depth && mipmapLevels == other.mipmapLevels &&
|
depth == other.depth && mipmapLevels == other.mipmapLevels &&
|
||||||
bufferExternalIndex == other.bufferExternalIndex;
|
bufferExternalIndex == other.bufferExternalIndex && samples == other.samples &&
|
||||||
|
fixedSampleLocations == other.fixedSampleLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const StateTextureBasicInfo& other) const { return !(*this == other); }
|
bool operator!=(const StateTextureBasicInfo& other) const { return !(*this == other); }
|
||||||
|
|||||||
Reference in New Issue
Block a user