From 7ba32581504e66f89fd23b60c55fb58fb0a12bc9 Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Tue, 12 Aug 2025 18:12:34 +0800 Subject: [PATCH] [Feat] (MG_Impl/Texture): Implement basic validators for texture. --- .../MG_Impl/GLImpl/Texture/Validators.cpp | 40 +++++++++++++++++++ MobileGL/MG_Impl/GLImpl/Texture/Validators.h | 11 +++++ 2 files changed, 51 insertions(+) create mode 100644 MobileGL/MG_Impl/GLImpl/Texture/Validators.cpp create mode 100644 MobileGL/MG_Impl/GLImpl/Texture/Validators.h diff --git a/MobileGL/MG_Impl/GLImpl/Texture/Validators.cpp b/MobileGL/MG_Impl/GLImpl/Texture/Validators.cpp new file mode 100644 index 00000000..160d5dd9 --- /dev/null +++ b/MobileGL/MG_Impl/GLImpl/Texture/Validators.cpp @@ -0,0 +1,40 @@ +#include "Validators.h" +#include +#include +#include +#include +#include +#include + +namespace MobileGL::MG_Impl::GLImpl { + namespace TextureImpl { + Bool ValidateTextureTarget(TextureTarget target) { + if (target == TextureTarget::Unknown) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidEnum, + MakeShared("MG_Impl/GLImpl", "ValidateTextureTarget", "Invalid texture target")); + return false; + } + return true; + } + + Bool ValidateTextureName(GLuint texture, Bool allowZero) { + if (texture == 0) { + if (allowZero) return true; + + MG_State::pGLContext->RecordError(ErrorCode::InvalidValue, + MakeShared("MG_Impl/GLImpl", "ValidateTextureName", + "Texture name cannot be zero")); + return false; + } + + if (!MG_State::pGLContext->ValidateTextureName(texture)) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidValue, + MakeShared("MG_Impl/GLImpl", "ValidateTextureName", "Invalid texture name")); + return false; + } + return true; + } + } // namespace TextureImpl +} // namespace MobileGL::MG_Impl::GLImpl diff --git a/MobileGL/MG_Impl/GLImpl/Texture/Validators.h b/MobileGL/MG_Impl/GLImpl/Texture/Validators.h new file mode 100644 index 00000000..573e6a1c --- /dev/null +++ b/MobileGL/MG_Impl/GLImpl/Texture/Validators.h @@ -0,0 +1,11 @@ +#pragma once +#include "MG_Util/Types.h" +#include +#include + +namespace MobileGL::MG_Impl::GLImpl { + namespace TextureImpl { + Bool ValidateTextureTarget(TextureTarget target); + Bool ValidateTextureName(GLuint texture, Bool allowZero = false); + } // namespace TextureImpl +} // namespace MobileGL::MG_Impl::GLImpl \ No newline at end of file