[Optimization] (MG_Constant): use vector instead of unordered_set to improve performance

This commit is contained in:
2025-07-08 12:39:39 +08:00
parent 532ca5ced5
commit e3765f1f50
5 changed files with 52 additions and 46 deletions
+4 -3
View File
@@ -263,8 +263,9 @@ GLenum BufferState::DeleteN(GLsizei n, const GLuint* buffers) {
}
bool BufferState::IsValidTarget_(GLenum target) {
MG_Util::Debug::LogD("MG_State: Buffer: IsValidTarget_ called with target=0x%x,result=%d", target, !(MG_Constants::Buffer::VALID_TARGETS.find(target) == MG_Constants::Buffer::VALID_TARGETS.end()));
return !(MG_Constants::Buffer::VALID_TARGETS.find(target) == MG_Constants::Buffer::VALID_TARGETS.end());
bool ret = MG_Constants::Common::Contains(target, MG_Constants::Buffer::VALID_TARGETS);
MG_Util::Debug::LogD("MG_State: Buffer: IsValidTarget_ called with target=0x%x,result=%d", target, ret);
return ret;
}
GLenum BufferState::QueryPropertyIntVector(GLenum target, GLenum pname, GLint* params) const {
@@ -277,7 +278,7 @@ GLenum BufferState::QueryPropertyIntVector(GLenum target, GLenum pname, GLint* p
return GL_INVALID_ENUM;
}
if (MG_Constants::Buffer::VALID_PARAM_NAMES.find(pname) == MG_Constants::Buffer::VALID_PARAM_NAMES.end()) {
if (!MG_Constants::Common::Contains(pname, MG_Constants::Buffer::VALID_PARAM_NAMES)) {
return GL_INVALID_ENUM;
}
+10 -10
View File
@@ -10,7 +10,7 @@ CommonState::CommonState() {
}
GLenum CommonState::SetPixelStoreInt(GLenum pname, GLint param) {
if (MG_Constants::PixelStore::VALID_PARAM_NAMES.find(pname) == MG_Constants::PixelStore::VALID_PARAM_NAMES.end()) {
if (!MG_Constants::Common::Contains(pname, MG_Constants::PixelStore::VALID_PARAM_NAMES)) {
return GL_INVALID_ENUM;
}
@@ -61,7 +61,7 @@ GLint CommonState::QueryPixelStoreInt(GLenum pname) {
}
GLenum CommonState::Enable(GLenum cap) {
if (MG_Constants::CommonState::VALID_CAPS.find(cap) == MG_Constants::CommonState::VALID_CAPS.end()) {
if (!MG_Constants::Common::Contains(cap, MG_Constants::CommonState::VALID_CAPS)) {
return GL_INVALID_ENUM;
}
capabilities[cap] = true;
@@ -69,7 +69,7 @@ GLenum CommonState::Enable(GLenum cap) {
}
GLenum CommonState::Disable(GLenum cap) {
if (MG_Constants::CommonState::VALID_CAPS.find(cap) == MG_Constants::CommonState::VALID_CAPS.end()) {
if (!MG_Constants::Common::Contains(cap, MG_Constants::CommonState::VALID_CAPS)) {
return GL_INVALID_ENUM;
}
capabilities[cap] = false;
@@ -77,8 +77,8 @@ GLenum CommonState::Disable(GLenum cap) {
}
GLenum CommonState::BlendFunc(GLenum sfactor, GLenum dfactor) {
if (MG_Constants::Blend::VALID_FACTORS.find(sfactor) == MG_Constants::Blend::VALID_FACTORS.end() ||
MG_Constants::Blend::VALID_FACTORS.find(dfactor) == MG_Constants::Blend::VALID_FACTORS.end()) {
if (!MG_Constants::Common::Contains(sfactor, MG_Constants::Blend::VALID_FACTORS) ||
!MG_Constants::Common::Contains(dfactor, MG_Constants::Blend::VALID_FACTORS)) {
return GL_INVALID_ENUM;
}
@@ -89,10 +89,10 @@ GLenum CommonState::BlendFunc(GLenum sfactor, GLenum dfactor) {
GLenum CommonState::BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB,
GLenum srcAlpha, GLenum dstAlpha) {
if (MG_Constants::Blend::VALID_FACTORS.find(srcRGB) == MG_Constants::Blend::VALID_FACTORS.end() ||
MG_Constants::Blend::VALID_FACTORS.find(dstRGB) == MG_Constants::Blend::VALID_FACTORS.end() ||
MG_Constants::Blend::VALID_FACTORS.find(srcAlpha) == MG_Constants::Blend::VALID_FACTORS.end() ||
MG_Constants::Blend::VALID_FACTORS.find(dstAlpha) == MG_Constants::Blend::VALID_FACTORS.end()) {
if (!MG_Constants::Common::Contains(srcRGB, MG_Constants::Blend::VALID_FACTORS) ||
!MG_Constants::Common::Contains(dstRGB, MG_Constants::Blend::VALID_FACTORS) ||
!MG_Constants::Common::Contains(srcAlpha, MG_Constants::Blend::VALID_FACTORS) ||
!MG_Constants::Common::Contains(dstAlpha, MG_Constants::Blend::VALID_FACTORS)) {
return GL_INVALID_ENUM;
}
blendSrcRGB = srcRGB;
@@ -133,7 +133,7 @@ GLenum CommonState::ColorMask(GLboolean red, GLboolean green, GLboolean blue, GL
}
GLenum CommonState::DepthFunc(GLenum func) {
if (MG_Constants::Depth::VALID_FUNCS.find(func) == MG_Constants::Depth::VALID_FUNCS.end()) {
if (!MG_Constants::Common::Contains(func, MG_Constants::Depth::VALID_FUNCS)) {
return GL_INVALID_ENUM;
}
depthFunc = func;
@@ -42,7 +42,7 @@ GLenum FramebufferState::Delete(GLuint framebuffer) {
}
GLenum FramebufferState::Bind(GLenum target, GLuint framebuffer) {
if (MG_Constants::Framebuffer::VALID_TARGETS.find(target) == MG_Constants::Framebuffer::VALID_TARGETS.end())
if (!MG_Constants::Common::Contains(target, MG_Constants::Framebuffer::VALID_TARGETS))
return GL_INVALID_ENUM;
if (framebuffer != 0 && !ValidateHandle(framebuffer))
return GL_INVALID_OPERATION;
@@ -57,8 +57,8 @@ GLenum FramebufferState::Bind(GLenum target, GLuint framebuffer) {
GLenum FramebufferState::AttachTexture2D(GLenum target, GLenum attachment,
GLenum textarget, GLuint texture, GLint level) {
if (MG_Constants::Framebuffer::VALID_ATTACHMENTS.find(attachment) == MG_Constants::Framebuffer::VALID_ATTACHMENTS.end() ||
MG_Constants::Texture::VALID_TARGETS.find(textarget) == MG_Constants::Texture::VALID_TARGETS.end())
if (!MG_Constants::Common::Contains(attachment, MG_Constants::Framebuffer::VALID_ATTACHMENTS) ||
!MG_Constants::Common::Contains(textarget, MG_Constants::Texture::VALID_TARGETS))
return GL_INVALID_ENUM;
if (target == GL_FRAMEBUFFER) {
target = GL_DRAW_FRAMEBUFFER;
+14 -14
View File
@@ -121,7 +121,7 @@ GLenum TextureState::CreateN(GLsizei n, GLuint* textures) {
GLenum TextureState::Bind(GLenum target, GLuint texture) {
MG_Util::Debug::LogD("MG_State: Texture: Bind called with target=0x%x, texture=%u", target, texture);
if (MG_Constants::Texture::VALID_TARGETS.find(target) == MG_Constants::Texture::VALID_TARGETS.end()) {
if (!MG_Constants::Common::Contains(target, MG_Constants::Texture::VALID_TARGETS)) {
MG_Util::Debug::LogE("MG_State: Texture: Bind invalid target=0x%x", target);
return GL_INVALID_ENUM;
}
@@ -497,12 +497,12 @@ GLenum TextureState::UpdateRegion2D(GLenum target, GLint level, GLint xoffset,
GLenum TextureState::SetTexturePropertyFloat(GLenum target, GLenum pname, GLfloat param) {
MG_Util::Debug::LogD("MG_State: Texture: SetTexturePropertyFloat called target=0x%x, pname=0x%x, param=%f", target, pname, param);
if (MG_Constants::Texture::VALID_TARGETS.find(target) == MG_Constants::Texture::VALID_TARGETS.end()) {
if (!MG_Constants::Common::Contains(target, MG_Constants::Texture::VALID_TARGETS)) {
MG_Util::Debug::LogE("MG_State: Texture: SetTexturePropertyFloat invalid target=0x%x", target);
return GL_INVALID_ENUM;
}
if (MG_Constants::Texture::VALID_TEXTURE_PARAM_NAMES.find(pname) == MG_Constants::Texture::VALID_TEXTURE_PARAM_NAMES.end()) {
if (!MG_Constants::Common::Contains(pname, MG_Constants::Texture::VALID_TEXTURE_PARAM_NAMES)) {
MG_Util::Debug::LogE("MG_State: Texture: SetTexturePropertyFloat invalid pname=0x%x", pname);
return GL_INVALID_ENUM;
}
@@ -549,12 +549,12 @@ GLenum TextureState::SetTexturePropertyFloat(GLenum target, GLenum pname, GLfloa
GLenum TextureState::SetTexturePropertyInt(GLenum target, GLenum pname, GLint param) {
MG_Util::Debug::LogD("MG_State: Texture: SetTexturePropertyInt called target=0x%x, pname=0x%x, param=%d", target, pname, param);
if (MG_Constants::Texture::VALID_TARGETS.find(target) == MG_Constants::Texture::VALID_TARGETS.end()) {
if (!MG_Constants::Common::Contains(target, MG_Constants::Texture::VALID_TARGETS)) {
MG_Util::Debug::LogE("MG_State: Texture: SetTexturePropertyInt invalid target=0x%x", target);
return GL_INVALID_ENUM;
}
if (MG_Constants::Texture::VALID_TEXTURE_PARAM_NAMES.find(pname) == MG_Constants::Texture::VALID_TEXTURE_PARAM_NAMES.end()) {
if (!MG_Constants::Common::Contains(pname, MG_Constants::Texture::VALID_TEXTURE_PARAM_NAMES)) {
MG_Util::Debug::LogE("MG_State: Texture: SetTexturePropertyInt invalid pname=0x%x", pname);
return GL_INVALID_ENUM;
}
@@ -645,7 +645,7 @@ GLenum TextureState::DeleteN(GLsizei n, const GLuint* textures) {
GLenum TextureState::QueryLevelPropertyIntVector(GLenum target, GLint level, GLenum pname, GLint* params) {
MG_Util::Debug::LogD("MG_State: Texture: QueryLevelPropertyIntVector called target=0x%x, level=%d, pname=0x%x", target, level, pname);
if (MG_Constants::Texture::VALID_TARGETS.find(target) == MG_Constants::Texture::VALID_TARGETS.end()) {
if (!MG_Constants::Common::Contains(target, MG_Constants::Texture::VALID_TARGETS)) {
MG_Util::Debug::LogE("MG_State: Texture: QueryLevelPropertyIntVector invalid target=0x%x", target);
return GL_INVALID_ENUM;
}
@@ -655,7 +655,7 @@ GLenum TextureState::QueryLevelPropertyIntVector(GLenum target, GLint level, GLe
return GL_INVALID_VALUE;
}
if (MG_Constants::Texture::VALID_QUERY_LEVEL_PROPERTY_PARAM_NAMES.find(pname) == MG_Constants::Texture::VALID_QUERY_LEVEL_PROPERTY_PARAM_NAMES.end()) {
if (!MG_Constants::Common::Contains(pname, MG_Constants::Texture::VALID_TEXTURE_PARAM_NAMES)) {
MG_Util::Debug::LogE("MG_State: Texture: QueryLevelPropertyIntVector invalid pname=0x%x", pname);
return GL_INVALID_ENUM;
}
@@ -805,7 +805,7 @@ GLenum TextureState::CheckUploadingTexture2DValidity_(GLenum target, GLint level
GLsizei width, GLsizei height, GLint border, GLenum format,
GLenum type, const void* data) {
MG_Util::Debug::LogD("MG_State: Texture: CheckUploadingTexture2DValidity_ called target=0x%x, level=%d", target, level);
if (MG_Constants::Texture::VALID_TARGETS.find(target) == MG_Constants::Texture::VALID_TARGETS.end()) {
if (!MG_Constants::Common::Contains(target, MG_Constants::Texture::VALID_TARGETS)) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ invalid target=0x%x", target);
return GL_INVALID_ENUM;
}
@@ -845,17 +845,17 @@ GLenum TextureState::CheckUploadingTexture2DValidity_(GLenum target, GLint level
return GL_INVALID_VALUE;
}
if (MG_Constants::Texture::VALID_INTERNAL_FORMATS.find(internalFormat) == MG_Constants::Texture::VALID_INTERNAL_FORMATS.end()) {
if (!MG_Constants::Common::Contains((GLenum)internalFormat, MG_Constants::Texture::VALID_INTERNAL_FORMATS)) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ invalid internalFormat=0x%x", internalFormat);
return GL_INVALID_VALUE;
}
if (MG_Constants::Texture::VALID_FORMATS.find(format) == MG_Constants::Texture::VALID_FORMATS.end()) {
if (!MG_Constants::Common::Contains((GLenum)format, MG_Constants::Texture::VALID_FORMATS)) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ invalid format=0x%x", format);
return GL_INVALID_ENUM;
}
if (MG_Constants::Texture::VALID_TYPES.find(type) == MG_Constants::Texture::VALID_TYPES.end()) {
if (!MG_Constants::Common::Contains((GLenum)type, MG_Constants::Texture::VALID_TYPES)) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ invalid type=0x%x", type);
return GL_INVALID_ENUM;
}
@@ -927,7 +927,7 @@ GLenum TextureState::CheckUpdatingTextureRegion2DValidity_(GLenum target, GLint
MG_Util::Debug::LogD("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ called target=0x%x, level=%d, x=%d, y=%d, w=%d, h=%d",
target, level, xoffset, yoffset, width, height);
if (MG_Constants::Texture::VALID_TARGETS.find(target) == MG_Constants::Texture::VALID_TARGETS.end()) {
if (!MG_Constants::Common::Contains(target, MG_Constants::Texture::VALID_TARGETS)) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ invalid target=0x%x", target);
return GL_INVALID_ENUM;
}
@@ -977,12 +977,12 @@ GLenum TextureState::CheckUpdatingTextureRegion2DValidity_(GLenum target, GLint
return GL_INVALID_OPERATION;
}
if (MG_Constants::Texture::VALID_FORMATS.find(format) == MG_Constants::Texture::VALID_FORMATS.end()) {
if (!MG_Constants::Common::Contains(format, MG_Constants::Texture::VALID_FORMATS)) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ invalid format=0x%x", format);
return GL_INVALID_ENUM;
}
if (MG_Constants::Texture::VALID_TYPES.find(type) == MG_Constants::Texture::VALID_TYPES.end()) {
if (!MG_Constants::Common::Contains(type, MG_Constants::Texture::VALID_TYPES)) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ invalid type=0x%x", type);
return GL_INVALID_ENUM;
}