mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 22:28:32 +09:00
[Chore] (MG_Backend/DirectGLES): tidying up code
This commit is contained in:
@@ -461,10 +461,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
|
|
||||||
// Bind texture object
|
// Bind texture object
|
||||||
auto target = textureObject->GetTarget();
|
auto target = textureObject->GetTarget();
|
||||||
if (target == TextureTarget::Texture1D || target == TextureTarget::TextureRectangle ||
|
if (!TextureImpl::IsSupportedTextureTarget(target)) {
|
||||||
target == TextureTarget::Texture2DMultisampleArray || target == TextureTarget::Texture1DArray ||
|
|
||||||
target == TextureTarget::Texture2DMultisample ||
|
|
||||||
target == TextureTarget::Texture2DArray) {
|
|
||||||
MGLOG_D(" Texture target %s is not supported, skipping.",
|
MGLOG_D(" Texture target %s is not supported, skipping.",
|
||||||
MG_Util::ConvertTextureTargetToString(target).c_str());
|
MG_Util::ConvertTextureTargetToString(target).c_str());
|
||||||
continue;
|
continue;
|
||||||
@@ -733,9 +730,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
|
|
||||||
void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1,
|
void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1,
|
||||||
GLint dstY1, GLbitfield mask, GLenum filter) {
|
GLint dstY1, GLbitfield mask, GLenum filter) {
|
||||||
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_DEBUG
|
|
||||||
DebugImpl::OpenGLScopeMarker marker(__func__);
|
|
||||||
#endif
|
|
||||||
DebugImpl::ErrorLopper errorLopper;
|
DebugImpl::ErrorLopper errorLopper;
|
||||||
|
|
||||||
TextureImpl::SyncNeccessaryTextures();
|
TextureImpl::SyncNeccessaryTextures();
|
||||||
@@ -764,6 +758,42 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UpdateTextureBindingAtTarget(GLenum target) {
|
||||||
|
#ifdef TRACY_ENABLE
|
||||||
|
ZoneScopedNC(__func__, TRACY_ZONECOLOR_BACKEND);
|
||||||
|
#endif
|
||||||
|
auto unit = MG_State::pGLContext->GetActiveTextureUnit();
|
||||||
|
auto& textureUnit = MG_State::pGLContext->GetTextureUnitObject(unit);
|
||||||
|
|
||||||
|
MG_External::GLES::glActiveTexture(GL_TEXTURE0 + unit);
|
||||||
|
auto textureTarget = MG_Util::ConvertGLEnumToTextureTarget(target);
|
||||||
|
if (!TextureImpl::IsSupportedTextureTarget(textureTarget)) {
|
||||||
|
MOBILEGL_ASSERT(false, " Texture target %s is not supported, skipping.",
|
||||||
|
MG_Util::ConvertTextureTargetToString(textureTarget).c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& bindingSlot = textureUnit.GetBindingSlot(textureTarget);
|
||||||
|
{
|
||||||
|
const auto& textureObject = bindingSlot.GetBoundObject();
|
||||||
|
if (!textureObject) {
|
||||||
|
MGLOG_W("%s: Texture target %s does not have texture bound.", __func__,
|
||||||
|
MG_Util::ConvertTextureTargetToString(textureTarget).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& backendTextureIt = TextureImpl::g_backendTextureObjects.find(textureObject);
|
||||||
|
SharedPtr<TextureImpl::BackendTextureObject> backendTextureObject;
|
||||||
|
if (backendTextureIt == TextureImpl::g_backendTextureObjects.end()) {
|
||||||
|
backendTextureObject = MakeShared<TextureImpl::BackendTextureObject>();
|
||||||
|
TextureImpl::g_backendTextureObjects[textureObject] = backendTextureObject;
|
||||||
|
} else {
|
||||||
|
backendTextureObject = backendTextureIt->second;
|
||||||
|
}
|
||||||
|
backendTextureObject->Bind(target);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width,
|
void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width,
|
||||||
GLsizei height, GLint border) {
|
GLsizei height, GLint border) {
|
||||||
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_DEBUG
|
#if MOBILEGL_LOG_ACTIVE_LEVEL <= MOBILEGL_LOG_LEVEL_DEBUG
|
||||||
@@ -784,45 +814,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
if (!UpdateTextureBindingAtTarget(target))
|
||||||
#ifdef TRACY_ENABLE
|
|
||||||
ZoneScopedNC("BindCurrentTexturesAtTarget", TRACY_ZONECOLOR_BACKEND);
|
|
||||||
#endif
|
|
||||||
auto unit = MG_State::pGLContext->GetActiveTextureUnit();
|
|
||||||
auto& textureUnit = MG_State::pGLContext->GetTextureUnitObject(unit);
|
|
||||||
|
|
||||||
MG_External::GLES::glActiveTexture(GL_TEXTURE0 + unit);
|
|
||||||
auto textureTarget = MG_Util::ConvertGLEnumToTextureTarget(target);
|
|
||||||
if (textureTarget == TextureTarget::Texture1D ||
|
|
||||||
textureTarget == TextureTarget::TextureRectangle ||
|
|
||||||
textureTarget == TextureTarget::Texture2DMultisampleArray ||
|
|
||||||
textureTarget == TextureTarget::Texture1DArray ||
|
|
||||||
textureTarget == TextureTarget::Texture2DMultisample ||
|
|
||||||
textureTarget == TextureTarget::Texture2DArray) {
|
|
||||||
MOBILEGL_ASSERT(false, " Texture target %s is not supported, skipping.",
|
|
||||||
MG_Util::ConvertTextureTargetToString(textureTarget).c_str());
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
const auto& bindingSlot = textureUnit.GetBindingSlot(textureTarget);
|
|
||||||
{
|
|
||||||
const auto &textureObject = bindingSlot.GetBoundObject();
|
|
||||||
if (!textureObject) {
|
|
||||||
MGLOG_W("%s: Texture target %s does not have texture bound.", __func__,
|
|
||||||
MG_Util::ConvertTextureTargetToString(textureTarget).c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto &backendTextureIt = TextureImpl::g_backendTextureObjects.find(
|
|
||||||
textureObject);
|
|
||||||
if (backendTextureIt == TextureImpl::g_backendTextureObjects.end()) {
|
|
||||||
MGLOG_W("%s: No backend texture object found for frontend texture object %d.", __func__,
|
|
||||||
textureObject->GetExternalIndex());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
backendTextureIt->second->Bind(target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GLint realInternalFormat;
|
// GLint realInternalFormat;
|
||||||
// MG_External::GLES::glGetTexLevelParameteriv(target, level, GL_TEXTURE_INTERNAL_FORMAT, &realInternalFormat);
|
// MG_External::GLES::glGetTexLevelParameteriv(target, level, GL_TEXTURE_INTERNAL_FORMAT, &realInternalFormat);
|
||||||
@@ -914,21 +907,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
MGLOG_D("ES error (%s:%d): %s", file, line, MG_Util::ConvertGLEnumToString(err).c_str());
|
||||||
});
|
});
|
||||||
|
|
||||||
Int unit = MG_State::pGLContext->GetActiveTextureUnit();
|
if (!UpdateTextureBindingAtTarget(target))
|
||||||
auto& activeUnit = MG_State::pGLContext->GetTextureUnitObject(unit);
|
return;
|
||||||
TextureTarget textureTarget = MG_Util::ConvertGLEnumToTextureTarget(target);
|
|
||||||
auto& bindingSlot = activeUnit.GetBindingSlot(textureTarget);
|
|
||||||
const auto& textureObject = bindingSlot.GetBoundObject();
|
|
||||||
|
|
||||||
const auto& backendTextureIt = TextureImpl::g_backendTextureObjects.find(textureObject);
|
|
||||||
SharedPtr<TextureImpl::BackendTextureObject> backendTextureObject;
|
|
||||||
if (backendTextureIt == TextureImpl::g_backendTextureObjects.end()) {
|
|
||||||
backendTextureObject = MakeShared<TextureImpl::BackendTextureObject>();
|
|
||||||
TextureImpl::g_backendTextureObjects[textureObject] = backendTextureObject;
|
|
||||||
} else {
|
|
||||||
backendTextureObject = backendTextureIt->second;
|
|
||||||
}
|
|
||||||
backendTextureObject->Bind(target);
|
|
||||||
|
|
||||||
BindCurrentFBO(FramebufferTarget::Read);
|
BindCurrentFBO(FramebufferTarget::Read);
|
||||||
errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) {
|
errorLopper.Loop([file = __FILE__, line = __LINE__](auto err) {
|
||||||
|
|||||||
@@ -314,12 +314,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
auto targetInternal = stateTextureObject->GetTarget();
|
auto targetInternal = stateTextureObject->GetTarget();
|
||||||
MGLOG_D(" Texture target for syncing is %s",
|
MGLOG_D(" Texture target for syncing is %s",
|
||||||
MG_Util::ConvertTextureTargetToString(targetInternal).c_str());
|
MG_Util::ConvertTextureTargetToString(targetInternal).c_str());
|
||||||
if (targetInternal == TextureTarget::Texture1D ||
|
if (!IsSupportedTextureTarget(targetInternal)) {
|
||||||
targetInternal == TextureTarget::TextureRectangle ||
|
|
||||||
targetInternal == TextureTarget::Texture2DMultisampleArray ||
|
|
||||||
targetInternal == TextureTarget::Texture1DArray ||
|
|
||||||
targetInternal == TextureTarget::Texture2DMultisample ||
|
|
||||||
targetInternal == TextureTarget::Texture2DArray) {
|
|
||||||
MGLOG_E(" Texture target %s is not supported, skipping.",
|
MGLOG_E(" Texture target %s is not supported, skipping.",
|
||||||
MG_Util::ConvertTextureTargetToString(targetInternal).c_str());
|
MG_Util::ConvertTextureTargetToString(targetInternal).c_str());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -56,6 +56,17 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
} // namespace VertexArrayImpl
|
} // namespace VertexArrayImpl
|
||||||
|
|
||||||
namespace TextureImpl {
|
namespace TextureImpl {
|
||||||
|
inline Bool IsSupportedTextureTarget(TextureTarget target) {
|
||||||
|
if (target == TextureTarget::Texture1D ||
|
||||||
|
target == TextureTarget::TextureRectangle ||
|
||||||
|
target == TextureTarget::Texture2DMultisampleArray ||
|
||||||
|
target == TextureTarget::Texture1DArray ||
|
||||||
|
target == TextureTarget::Texture2DMultisample ||
|
||||||
|
target == TextureTarget::Texture2DArray)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
struct StateTextureBasicInfo { // Used for tracking texture state changes
|
struct StateTextureBasicInfo { // Used for tracking texture state changes
|
||||||
TextureInternalFormat internalFormat = TextureInternalFormat::Unknown;
|
TextureInternalFormat internalFormat = TextureInternalFormat::Unknown;
|
||||||
SizeT width = 0;
|
SizeT width = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user