[Refactor] (TextureState.*): Optimize code.

This commit is contained in:
BZLZHH
2025-05-01 10:19:50 +08:00
parent 04976daa9f
commit b4f7aefb99
2 changed files with 136 additions and 136 deletions
+117 -117
View File
@@ -33,13 +33,13 @@ GLuint TextureUnitState::GetBoundTexture(GLenum target) {
// TextureState
TextureState::TextureState() {
textureUnits.resize(MG_Constants::Texture::MAX_TEXTURE_UNITS);
MG_Util::Debug::LogD("MG_State: Texture: TextureState constructor, textureUnits=%zu", textureUnits.size());
textureUnits_.resize(MG_Constants::Texture::MAX_TEXTURE_UNITS);
MG_Util::Debug::LogD("MG_State: Texture: TextureState constructor, textureUnits_=%zu", textureUnits_.size());
}
GLint TextureState::GetUnpackParam(GLenum pname) {
GLint TextureState::GetUnpackParam_(GLenum pname) {
GLint result = MG_State::GetPixelStoreInt(pname);
MG_Util::Debug::LogD("MG_State: Texture: GetUnpackParam pname=0x%x, returns %d", pname, result);
MG_Util::Debug::LogD("MG_State: Texture: GetUnpackParam_ pname=0x%x, returns %d", pname, result);
return result;
}
@@ -73,9 +73,9 @@ bool TextureState::IsTexture(GLuint texture) {
GLenum TextureState::BindUnit(GLenum textureUnit) {
MG_Util::Debug::LogD("MG_State: Texture: BindUnit textureUnit=0x%x", textureUnit);
GLuint unitIndex = textureUnit - GL_TEXTURE0;
if (unitIndex < textureUnits.size()) {
activeTextureUnit = unitIndex;
MG_Util::Debug::LogD("MG_State: Texture: BindUnit set activeTextureUnit=%u", activeTextureUnit);
if (unitIndex < textureUnits_.size()) {
activeTextureUnit_ = unitIndex;
MG_Util::Debug::LogD("MG_State: Texture: BindUnit set activeTextureUnit_=%u", activeTextureUnit_);
} else {
MG_Util::Debug::LogE("MG_State: Texture: BindUnit invalid texture unit 0x%x", textureUnit);
return GL_INVALID_ENUM;
@@ -101,12 +101,12 @@ GLenum TextureState::CreateN(GLsizei n, GLuint* textures) {
for (GLsizei i = 0; i < n; ++i) {
GLuint id = 0;
if (!freeIDs.empty()) {
id = *freeIDs.begin();
freeIDs.erase(freeIDs.begin());
if (!freeIDs_.empty()) {
id = *freeIDs_.begin();
freeIDs_.erase(freeIDs_.begin());
MG_Util::Debug::LogD("MG_State: Texture: CreateN reusing free id=%u", id);
} else {
id = ++lastUsedID;
id = ++lastUsedID_;
MG_Util::Debug::LogD("MG_State: Texture: CreateN new id=%u", id);
}
TextureObject obj;
@@ -127,7 +127,7 @@ GLenum TextureState::Bind(GLenum target, GLuint texture) {
}
if (texture == 0) {
TextureUnitState& unit = textureUnits[activeTextureUnit];
TextureUnitState& unit = textureUnits_[activeTextureUnit_];
unit.Bind(target, 0);
MG_Util::Debug::LogD("MG_State: Texture: Bind unbind succeeded for target=0x%x", target);
return GL_NO_ERROR;
@@ -147,7 +147,7 @@ GLenum TextureState::Bind(GLenum target, GLuint texture) {
}
TextureUnitState& unit = textureUnits[activeTextureUnit];
TextureUnitState& unit = textureUnits_[activeTextureUnit_];
TextureObject* texObj = nullptr;
auto it = this->textures.find(texture);
if (it == this->textures.end()) {
@@ -174,12 +174,12 @@ GLenum TextureState::Bind(GLenum target, GLuint texture) {
return GL_NO_ERROR;
}
size_t TextureState::CalculatePixelDataSize(GLenum format, GLenum type, GLsizei width, GLsizei height) {
MG_Util::Debug::LogD("MG_State: Texture: CalculatePixelDataSize called format=0x%x, type=0x%x, width=%d, height=%d", format, type, width, height);
size_t TextureState::CalculatePixelDataSize_(GLenum format, GLenum type, GLsizei width, GLsizei height) {
MG_Util::Debug::LogD("MG_State: Texture: CalculatePixelDataSize_ called format=0x%x, type=0x%x, width=%d, height=%d", format, type, width, height);
// Unpack Param
GLint rowLength = TextureState::GetUnpackParam(GL_UNPACK_ROW_LENGTH);
GLint alignment = TextureState::GetUnpackParam(GL_UNPACK_ALIGNMENT);
GLint rowLength = TextureState::GetUnpackParam_(GL_UNPACK_ROW_LENGTH);
GLint alignment = TextureState::GetUnpackParam_(GL_UNPACK_ALIGNMENT);
GLsizei actualRowLength = (rowLength > 0) ? rowLength : width;
size_t bytesPerPixel = 0;
@@ -234,7 +234,7 @@ size_t TextureState::CalculatePixelDataSize(GLenum format, GLenum type, GLsizei
size_t alignedRowSize = (rowSize + (alignment - 1)) & ~(alignment - 1);
size_t totalSize = alignedRowSize * height;
MG_Util::Debug::LogD("MG_State: Texture: CalculatePixelDataSize returns %zu", totalSize);
MG_Util::Debug::LogD("MG_State: Texture: CalculatePixelDataSize_ returns %zu", totalSize);
return totalSize;
}
@@ -243,7 +243,7 @@ GLenum TextureState::Upload2D(GLenum target, GLint level, GLint internalFormat,
GLenum type, const void* data) {
MG_Util::Debug::LogD("MG_State: Texture: Upload2D called target=0x%x, level=%d, width=%d, height=%d",
target, level, width, height);
GLenum validity = CheckUploadingTexture2DValidity(target, level, internalFormat,
GLenum validity = CheckUploadingTexture2DValidity_(target, level, internalFormat,
width, height, border, format, type, data);
if (validity != GL_NO_ERROR) {
MG_Util::Debug::LogE("MG_State: Texture: Upload2D validation failed with error 0x%x", validity);
@@ -257,7 +257,7 @@ GLenum TextureState::Upload2D(GLenum target, GLint level, GLint internalFormat,
target == GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY);
if (isProxyTexture) {
MG_Util::Debug::LogD("MG_State: Texture: Upload2D proxy texture detected");
TextureObject& proxyTex = proxyTextures[target];
TextureObject& proxyTex = proxyTextures_[target];
TextureParams::MipmapLevel mip{};
mip.width = width;
mip.height = height;
@@ -270,7 +270,7 @@ GLenum TextureState::Upload2D(GLenum target, GLint level, GLint internalFormat,
return GL_NO_ERROR;
}
GLuint boundTex = textureUnits[activeTextureUnit].GetBoundTexture(target);
GLuint boundTex = textureUnits_[activeTextureUnit_].GetBoundTexture(target);
TextureObject& tex = textures[boundTex];
TextureParams::MipmapLevel mip{};
mip.width = width;
@@ -279,18 +279,18 @@ GLenum TextureState::Upload2D(GLenum target, GLint level, GLint internalFormat,
mip.format = format;
mip.type = type;
if (data != nullptr) {
GLint unpackSwapBytes = GetUnpackParam(GL_UNPACK_SWAP_BYTES);
GLint unpackLSBFirst = GetUnpackParam(GL_UNPACK_LSB_FIRST);
GLint unpackSkipPixels = GetUnpackParam(GL_UNPACK_SKIP_PIXELS);
GLint unpackSkipRows = GetUnpackParam(GL_UNPACK_SKIP_ROWS);
GLint unpackRowLength = GetUnpackParam(GL_UNPACK_ROW_LENGTH);
GLint unpackAlignment = GetUnpackParam(GL_UNPACK_ALIGNMENT);
GLint unpackImageHeight = GetUnpackParam(GL_UNPACK_IMAGE_HEIGHT);
GLint unpackSkipImages = GetUnpackParam(GL_UNPACK_SKIP_IMAGES);
GLint unpackSwapBytes = GetUnpackParam_(GL_UNPACK_SWAP_BYTES);
GLint unpackLSBFirst = GetUnpackParam_(GL_UNPACK_LSB_FIRST);
GLint unpackSkipPixels = GetUnpackParam_(GL_UNPACK_SKIP_PIXELS);
GLint unpackSkipRows = GetUnpackParam_(GL_UNPACK_SKIP_ROWS);
GLint unpackRowLength = GetUnpackParam_(GL_UNPACK_ROW_LENGTH);
GLint unpackAlignment = GetUnpackParam_(GL_UNPACK_ALIGNMENT);
GLint unpackImageHeight = GetUnpackParam_(GL_UNPACK_IMAGE_HEIGHT);
GLint unpackSkipImages = GetUnpackParam_(GL_UNPACK_SKIP_IMAGES);
GLsizei rowLength = (unpackRowLength > 0) ? unpackRowLength : width;
size_t bytesPerPixel = CalculateBytesPerPixel(format, type);
size_t componentSize = GetComponentSize(type);
size_t bytesPerPixel = CalculateBytesPerPixel_(format, type);
size_t componentSize = GetComponentSize_(type);
size_t srcRowSize = rowLength * bytesPerPixel;
size_t srcRowStride = (srcRowSize + unpackAlignment - 1) & ~(unpackAlignment - 1);
@@ -313,10 +313,10 @@ GLenum TextureState::Upload2D(GLenum target, GLint level, GLint internalFormat,
GLubyte* dstRow = dstData + y * dstRowStride;
if (unpackSwapBytes) {
SwapBytesForTexture(format, type, srcRow, dstRow, width);
SwapBytesForTexture_(format, type, srcRow, dstRow, width);
}
else if (unpackLSBFirst && componentSize == 1) {
ReverseBitOrder(srcRow, dstRow, width * bytesPerPixel);
ReverseBitOrder_(srcRow, dstRow, width * bytesPerPixel);
}
else {
memcpy(dstRow, srcRow, width * bytesPerPixel);
@@ -338,13 +338,13 @@ GLenum TextureState::UpdateRegion2D(GLenum target, GLint level, GLint xoffset,
MG_Util::Debug::LogD("MG_State: Texture: UpdateRegion2D called target=0x%x, level=%d, x=%d, y=%d, w=%d, h=%d",
target, level, xoffset, yoffset, width, height);
GLenum validity = CheckUpdatingTextureRegion2DValidity(target, level, xoffset, yoffset, width, height, format, type, data);
GLenum validity = CheckUpdatingTextureRegion2DValidity_(target, level, xoffset, yoffset, width, height, format, type, data);
if (validity != GL_NO_ERROR) {
MG_Util::Debug::LogE("MG_State: Texture: UpdateRegion2D validation failed with error 0x%x", validity);
return validity;
}
GLuint boundTex = textureUnits[activeTextureUnit].GetBoundTexture(target);
GLuint boundTex = textureUnits_[activeTextureUnit_].GetBoundTexture(target);
auto& tex = textures[boundTex];
auto mipIt = tex.params.mipmapData.find(level);
if (mipIt == tex.params.mipmapData.end()) {
@@ -353,17 +353,17 @@ GLenum TextureState::UpdateRegion2D(GLenum target, GLint level, GLint xoffset,
}
TextureParams::MipmapLevel& mip = mipIt->second;
GLint unpackSwapBytes = GetUnpackParam(GL_UNPACK_SWAP_BYTES);
GLint unpackLSBFirst = GetUnpackParam(GL_UNPACK_LSB_FIRST);
GLint unpackRowLength = GetUnpackParam(GL_UNPACK_ROW_LENGTH);
GLint unpackAlignment = GetUnpackParam(GL_UNPACK_ALIGNMENT);
GLint unpackSkipPixels = GetUnpackParam(GL_UNPACK_SKIP_PIXELS);
GLint unpackSkipRows = GetUnpackParam(GL_UNPACK_SKIP_ROWS);
GLint unpackImageHeight = GetUnpackParam(GL_UNPACK_IMAGE_HEIGHT);
GLint unpackSkipImages = GetUnpackParam(GL_UNPACK_SKIP_IMAGES);
GLint unpackSwapBytes = GetUnpackParam_(GL_UNPACK_SWAP_BYTES);
GLint unpackLSBFirst = GetUnpackParam_(GL_UNPACK_LSB_FIRST);
GLint unpackRowLength = GetUnpackParam_(GL_UNPACK_ROW_LENGTH);
GLint unpackAlignment = GetUnpackParam_(GL_UNPACK_ALIGNMENT);
GLint unpackSkipPixels = GetUnpackParam_(GL_UNPACK_SKIP_PIXELS);
GLint unpackSkipRows = GetUnpackParam_(GL_UNPACK_SKIP_ROWS);
GLint unpackImageHeight = GetUnpackParam_(GL_UNPACK_IMAGE_HEIGHT);
GLint unpackSkipImages = GetUnpackParam_(GL_UNPACK_SKIP_IMAGES);
const size_t bytesPerPixel = CalculateBytesPerPixel(format, type);
const size_t srcSize = CalculatePixelDataSize(format, type, width, height);
const size_t bytesPerPixel = CalculateBytesPerPixel_(format, type);
const size_t srcSize = CalculatePixelDataSize_(format, type, width, height);
if (bytesPerPixel == 0) {
MG_Util::Debug::LogE("MG_State: Texture: Invalid format/type combination");
@@ -410,11 +410,11 @@ GLenum TextureState::UpdateRegion2D(GLenum target, GLint level, GLint xoffset,
for (GLsizei x = 0; x < width; ++x) {
const GLubyte* srcPixel = srcRow + x * bytesPerPixel;
GLubyte* dstPixel = dstRow + x * bytesPerPixel;
SwapPixelBytes(format, type, srcPixel, dstPixel);
SwapPixelBytes_(format, type, srcPixel, dstPixel);
}
} else if (unpackLSBFirst && GetComponentSize(type) == 1) {
} else if (unpackLSBFirst && GetComponentSize_(type) == 1) {
for (size_t i = 0; i < width * bytesPerPixel; ++i) {
dstRow[i] = ReverseBits(srcRow[i]);
dstRow[i] = ReverseBits_(srcRow[i]);
}
} else {
MG_Util::Debug::LogD("MG_State: Texture: UpdateRegion2D memcpy(dst=%p, src=%p, size=%zu) called.", dstRow, srcRow, width * bytesPerPixel);
@@ -472,7 +472,7 @@ GLenum TextureState::SetTexturePropertyFloat(GLenum target, GLenum pname, GLfloa
default:
break;
}
GLuint boundTex = textureUnits[activeTextureUnit].GetBoundTexture(target);
GLuint boundTex = textureUnits_[activeTextureUnit_].GetBoundTexture(target);
TextureObject& tex = textures[boundTex];
tex.params.texPropertiesFloat[pname] = param;
MG_Util::Debug::LogD("MG_State: Texture: SetTexturePropertyFloat succeeded for texture %u", boundTex);
@@ -523,7 +523,7 @@ GLenum TextureState::SetTexturePropertyInt(GLenum target, GLenum pname, GLint pa
break;
}
GLuint boundTex = textureUnits[activeTextureUnit].GetBoundTexture(target);
GLuint boundTex = textureUnits_[activeTextureUnit_].GetBoundTexture(target);
TextureObject& tex = textures[boundTex];
tex.params.texPropertiesInt[pname] = param;
MG_Util::Debug::LogD("MG_State: Texture: SetTexturePropertyInt succeeded for texture %u", boundTex);
@@ -539,9 +539,9 @@ GLenum TextureState::Delete(GLuint texture) {
auto it = this->textures.find(texture);
if (it != this->textures.end()) {
InvalidateTextureInAllUnits(texture);
InvalidateTextureInAllUnits_(texture);
this->textures.erase(it);
freeIDs.insert(texture);
freeIDs_.insert(texture);
MG_Util::Debug::LogD("MG_State: Texture: Delete succeeded for texture=%u", texture);
} else {
MG_Util::Debug::LogW("MG_State: Texture: Delete texture %u not found", texture);
@@ -561,9 +561,9 @@ GLenum TextureState::DeleteN(GLsizei n, const GLuint* textures) {
if (id == 0) continue;
auto it = this->textures.find(id);
if (it != this->textures.end()) {
InvalidateTextureInAllUnits(id);
InvalidateTextureInAllUnits_(id);
this->textures.erase(it);
freeIDs.insert(id);
freeIDs_.insert(id);
MG_Util::Debug::LogD("MG_State: Texture: DeleteN deleted texture=%u", id);
} else {
MG_Util::Debug::LogW("MG_State: Texture: DeleteN texture %u not found", id);
@@ -596,8 +596,8 @@ GLenum TextureState::GetLevelPropertyIntVector(GLenum target, GLint level, GLenu
return GL_INVALID_VALUE;
}
GLuint activeUnit = activeTextureUnit;
if (activeUnit >= textureUnits.size()) {
GLuint activeUnit = activeTextureUnit_;
if (activeUnit >= textureUnits_.size()) {
MG_Util::Debug::LogE("MG_State: Texture: GetLevelPropertyIntVector active texture unit out of range");
return GL_INVALID_OPERATION;
}
@@ -608,7 +608,7 @@ GLenum TextureState::GetLevelPropertyIntVector(GLenum target, GLint level, GLenu
target == GL_PROXY_TEXTURE_RECTANGLE || target == GL_PROXY_TEXTURE_2D_MULTISAMPLE ||
target == GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY);
TextureUnitState& unit = textureUnits[activeUnit];
TextureUnitState& unit = textureUnits_[activeUnit];
GLuint boundTexture = unit.GetBoundTexture(target);
if (!isProxyTexture && boundTexture == 0) {
@@ -643,7 +643,7 @@ GLenum TextureState::GetLevelPropertyIntVector(GLenum target, GLint level, GLenu
}
}
TextureObject& tex = isProxyTexture ? proxyTextures[target] : texIt->second;
TextureObject& tex = isProxyTexture ? proxyTextures_[target] : texIt->second;
if (!isProxyTexture && tex.target != target && tex.target != GL_NONE) {
MG_Util::Debug::LogE("MG_State: Texture: GetLevelPropertyIntVector texture target mismatch: texture target=0x%x, expected=0x%x", tex.target, target);
@@ -671,7 +671,7 @@ GLenum TextureState::GetLevelPropertyIntVector(GLenum target, GLint level, GLenu
}
const TextureParams::MipmapLevel& mip = mipIt->second;
ComponentSizes sizes = GetComponentSizes(mip.internalFormat);
ComponentSizes sizes = GetComponentSize_s_(mip.internalFormat);
switch (pname) {
case GL_TEXTURE_WIDTH:
@@ -720,86 +720,86 @@ GLenum TextureState::GetLevelPropertyIntVector(GLenum target, GLint level, GLenu
return GL_NO_ERROR;
}
void TextureState::InvalidateTextureInAllUnits(GLuint texture) {
MG_Util::Debug::LogD("MG_State: Texture: InvalidateTextureInAllUnits called for texture=%u", texture);
for (auto& unit : textureUnits) {
void TextureState::InvalidateTextureInAllUnits_(GLuint texture) {
MG_Util::Debug::LogD("MG_State: Texture: InvalidateTextureInAllUnits_ called for texture=%u", texture);
for (auto& unit : textureUnits_) {
for (auto& [target, tex] : unit.boundTextures) {
if (tex == texture) {
tex = 0;
MG_Util::Debug::LogD("MG_State: Texture: InvalidateTextureInAllUnits unset texture for target=0x%x", target);
MG_Util::Debug::LogD("MG_State: Texture: InvalidateTextureInAllUnits_ unset texture for target=0x%x", target);
}
}
}
}
GLenum TextureState::CheckUploadingTexture2DValidity(GLenum target, GLint level, GLint internalFormat,
GLenum TextureState::CheckUploadingTexture2DValidity_(GLenum target, GLint level, GLint internalFormat,
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);
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()) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity invalid target=0x%x", target);
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ invalid target=0x%x", target);
return GL_INVALID_ENUM;
}
if (level < 0) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity invalid level=%d", level);
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ invalid level=%d", level);
return GL_INVALID_VALUE;
}
if ((target == GL_TEXTURE_RECTANGLE || target == GL_PROXY_TEXTURE_RECTANGLE) && level != 0) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity invalid level for rectangle texture");
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ invalid level for rectangle texture");
return GL_INVALID_VALUE;
}
if (width < 0 || height < 0) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity invalid dimensions width=%d, height=%d", width, height);
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ invalid dimensions width=%d, height=%d", width, height);
return GL_INVALID_VALUE;
}
if ((target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) && width != height) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity cube map requires equal width and height");
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ cube map requires equal width and height");
return GL_INVALID_ENUM;
}
if (width > MG_Constants::Texture::MAX_TEXTURE_SIZE) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity width exceeds maximum: %d", width);
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ width exceeds maximum: %d", width);
return GL_INVALID_VALUE;
}
if (target == GL_TEXTURE_1D_ARRAY || target == GL_PROXY_TEXTURE_1D_ARRAY) {
if (height > MG_Constants::Texture::MAX_ARRAY_LAYERS) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity height exceeds MAX_ARRAY_LAYERS: %d", height);
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ height exceeds MAX_ARRAY_LAYERS: %d", height);
return GL_INVALID_VALUE;
}
} else if (height > MG_Constants::Texture::MAX_TEXTURE_SIZE) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity height exceeds maximum: %d", height);
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ height exceeds maximum: %d", height);
return GL_INVALID_VALUE;
}
if (MG_Constants::Texture::VALID_INTERNAL_FORMATS.find(internalFormat) == MG_Constants::Texture::VALID_INTERNAL_FORMATS.end()) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity invalid internalFormat=0x%x", internalFormat);
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()) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity invalid format=0x%x", format);
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()) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity invalid type=0x%x", type);
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ invalid type=0x%x", type);
return GL_INVALID_ENUM;
}
bool typeNeedsRGB = (type == GL_UNSIGNED_BYTE_3_3_2 || type == GL_UNSIGNED_SHORT_5_6_5);
if (typeNeedsRGB && format != GL_RGB) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity type requires RGB but format=0x%x", format);
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ type requires RGB but format=0x%x", format);
return GL_INVALID_OPERATION;
}
bool typeNeedsRGBA = (type == GL_UNSIGNED_SHORT_4_4_4_4 || type == GL_UNSIGNED_INT_8_8_8_8);
if (typeNeedsRGBA && format != GL_RGBA && format != GL_BGRA) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity type requires RGBA but format=0x%x", format);
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ type requires RGBA but format=0x%x", format);
return GL_INVALID_OPERATION;
}
@@ -809,13 +809,13 @@ GLenum TextureState::CheckUploadingTexture2DValidity(GLenum target, GLint level,
|| internalFormat == GL_DEPTH_STENCIL);
bool isDepthFormat = (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL);
if (isDepthInternal != isDepthFormat) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity depth internal/format mismatch");
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ depth internal/format mismatch");
return GL_INVALID_OPERATION;
}
if (isDepthInternal && (target != GL_TEXTURE_2D && target != GL_PROXY_TEXTURE_2D &&
target != GL_TEXTURE_RECTANGLE && target != GL_PROXY_TEXTURE_RECTANGLE)) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity invalid target for depth texture");
MG_Util::Debug::LogE("MG_State: Texture: CheckUploadingTexture2DValidity_ invalid target for depth texture");
return GL_INVALID_OPERATION;
}
@@ -825,10 +825,10 @@ GLenum TextureState::CheckUploadingTexture2DValidity(GLenum target, GLint level,
target == GL_PROXY_TEXTURE_RECTANGLE || target == GL_PROXY_TEXTURE_2D_MULTISAMPLE ||
target == GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY);
if (!isProxyTexture) {
GLuint boundTex = textureUnits[activeTextureUnit].GetBoundTexture(target);
GLuint boundTex = textureUnits_[activeTextureUnit_].GetBoundTexture(target);
if (boundTex == 0) {
MG_Util::Debug::LogE(
"MG_State: Texture: CheckUploadingTexture2DValidity no texture bound for target=0x%x",
"MG_State: Texture: CheckUploadingTexture2DValidity_ no texture bound for target=0x%x",
target);
return GL_INVALID_OPERATION;
}
@@ -836,92 +836,92 @@ GLenum TextureState::CheckUploadingTexture2DValidity(GLenum target, GLint level,
TextureObject &tex = textures[boundTex];
if (tex.target != target) {
MG_Util::Debug::LogE(
"MG_State: Texture: CheckUploadingTexture2DValidity texture target mismatch: texture target=0x%x, expected=0x%x",
"MG_State: Texture: CheckUploadingTexture2DValidity_ texture target mismatch: texture target=0x%x, expected=0x%x",
tex.target, target);
return GL_INVALID_OPERATION;
}
if (tex.IsImmutable()) {
MG_Util::Debug::LogE(
"MG_State: Texture: CheckUploadingTexture2DValidity texture is immutable");
"MG_State: Texture: CheckUploadingTexture2DValidity_ texture is immutable");
return GL_INVALID_OPERATION;
}
}
MG_Util::Debug::LogD("MG_State: Texture: CheckUploadingTexture2DValidity succeeded");
MG_Util::Debug::LogD("MG_State: Texture: CheckUploadingTexture2DValidity_ succeeded");
return GL_NO_ERROR;
}
GLenum TextureState::CheckUpdatingTextureRegion2DValidity(GLenum target, GLint level, GLint xoffset,
GLenum TextureState::CheckUpdatingTextureRegion2DValidity_(GLenum target, GLint level, GLint xoffset,
GLint yoffset, GLsizei width, GLsizei height, GLenum format,
GLenum type, const GLvoid* data) {
MG_Util::Debug::LogD("MG_State: Texture: CheckUpdatingTextureRegion2DValidity called target=0x%x, level=%d, x=%d, y=%d, w=%d, h=%d",
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()) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity invalid target=0x%x", target);
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ invalid target=0x%x", target);
return GL_INVALID_ENUM;
}
if (level < 0) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity invalid level=%d", level);
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ invalid level=%d", level);
return GL_INVALID_VALUE;
}
if (xoffset < 0 || yoffset < 0) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity negative offset x=%d, y=%d", xoffset, yoffset);
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ negative offset x=%d, y=%d", xoffset, yoffset);
return GL_INVALID_VALUE;
}
if (width < 0 || height < 0) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity negative dimensions w=%d, h=%d", width, height);
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ negative dimensions w=%d, h=%d", width, height);
return GL_INVALID_VALUE;
}
if (!data) {
// TODO: need to impl PBO and then impl here
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity data pointer is null");
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ data pointer is null");
return GL_INVALID_OPERATION ;
}
GLuint boundTex = textureUnits[activeTextureUnit].GetBoundTexture(target);
GLuint boundTex = textureUnits_[activeTextureUnit_].GetBoundTexture(target);
if (boundTex == 0) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity no texture bound for target=0x%x", target);
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ no texture bound for target=0x%x", target);
return GL_INVALID_OPERATION;
}
if (!IsTextureGenerated(boundTex)) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity texture %u not generated", boundTex);
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ texture %u not generated", boundTex);
return GL_INVALID_OPERATION;
}
auto tex = textures[boundTex];
if (tex.IsImmutable()) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity texture is immutable");
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ texture is immutable");
return GL_INVALID_OPERATION;
}
auto mipIt = tex.params.mipmapData.find(level);
if (mipIt == tex.params.mipmapData.end()) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity no mipmap level %d", level);
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ no mipmap level %d", level);
return GL_INVALID_OPERATION;
}
if (MG_Constants::Texture::VALID_FORMATS.find(format) == MG_Constants::Texture::VALID_FORMATS.end()) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity invalid format=0x%x", format);
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()) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity invalid type=0x%x", type);
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ invalid type=0x%x", type);
return GL_INVALID_ENUM;
}
bool typeNeedsRGB = (type == GL_UNSIGNED_BYTE_3_3_2 || type == GL_UNSIGNED_BYTE_2_3_3_REV ||
type == GL_UNSIGNED_SHORT_5_6_5 || type == GL_UNSIGNED_SHORT_5_6_5_REV);
if (typeNeedsRGB && format != GL_RGB) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity type requires RGB format");
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ type requires RGB format");
return GL_INVALID_OPERATION;
}
@@ -930,13 +930,13 @@ GLenum TextureState::CheckUpdatingTextureRegion2DValidity(GLenum target, GLint l
type == GL_UNSIGNED_INT_8_8_8_8 || type == GL_UNSIGNED_INT_8_8_8_8_REV ||
type == GL_UNSIGNED_INT_10_10_10_2 || type == GL_UNSIGNED_INT_2_10_10_10_REV);
if (typeNeedsRGBA && format != GL_RGBA && format != GL_BGRA) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity type requires RGBA/BGRA format");
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ type requires RGBA/BGRA format");
return GL_INVALID_OPERATION;
}
TextureParams::MipmapLevel& mip = mipIt->second;
if (xoffset + width > mip.width || yoffset + height > mip.height) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity region out of bounds: "
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ region out of bounds: "
"x=%d+%d > %d or y=%d+%d > %d",
xoffset, width, mip.width, yoffset, height, mip.height);
return GL_INVALID_VALUE;
@@ -952,15 +952,15 @@ GLenum TextureState::CheckUpdatingTextureRegion2DValidity(GLenum target, GLint l
bool isDepthFormat = (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL);
if (isDepthInternal != isDepthFormat) {
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity format mismatch with internal format");
MG_Util::Debug::LogE("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ format mismatch with internal format");
return GL_INVALID_OPERATION;
}
MG_Util::Debug::LogD("MG_State: Texture: CheckUpdatingTextureRegion2DValidity validated subimage update");
MG_Util::Debug::LogD("MG_State: Texture: CheckUpdatingTextureRegion2DValidity_ validated subimage update");
return GL_NO_ERROR;
}
ComponentSizes TextureState::GetComponentSizes(GLenum internalFormat) {
MG_Util::Debug::LogD("MG_State: Texture: GetComponentSizes called for internalFormat=0x%x", internalFormat);
ComponentSizes TextureState::GetComponentSize_s_(GLenum internalFormat) {
MG_Util::Debug::LogD("MG_State: Texture: GetComponentSize_s_ called for internalFormat=0x%x", internalFormat);
ComponentSizes sizes = {0};
switch (internalFormat) {
// Base formats
@@ -1072,12 +1072,12 @@ ComponentSizes TextureState::GetComponentSizes(GLenum internalFormat) {
}
break;
}
MG_Util::Debug::LogD("MG_State: Texture: GetComponentSizes returns (red=%d, green=%d, blue=%d, alpha=%d, depth=%d, stencil=%d, isCompressed=%d)",
MG_Util::Debug::LogD("MG_State: Texture: GetComponentSize_s_ returns (red=%d, green=%d, blue=%d, alpha=%d, depth=%d, stencil=%d, isCompressed=%d)",
sizes.red, sizes.green, sizes.blue, sizes.alpha, sizes.depth, sizes.stencil, sizes.isCompressed);
return sizes;
}
size_t TextureState::CalculateBytesPerPixel(GLenum format, GLenum type) {
size_t TextureState::CalculateBytesPerPixel_(GLenum format, GLenum type) {
switch (type) {
case GL_UNSIGNED_BYTE_3_3_2:
case GL_UNSIGNED_BYTE_2_3_3_REV:
@@ -1121,11 +1121,11 @@ size_t TextureState::CalculateBytesPerPixel(GLenum format, GLenum type) {
break;
}
size_t componentSize = GetComponentSize(type);
size_t componentSize = GetComponentSize_(type);
return components * componentSize;
}
size_t TextureState::GetComponentSize(GLenum type) {
size_t TextureState::GetComponentSize_(GLenum type) {
switch (type) {
case GL_BYTE:
case GL_UNSIGNED_BYTE:
@@ -1158,8 +1158,8 @@ size_t TextureState::GetComponentSize(GLenum type) {
}
}
void TextureState::SwapBytesForTexture(GLenum format, GLenum type, const GLubyte* src, GLubyte* dst, GLsizei width) {
size_t componentSize = GetComponentSize(type);
void TextureState::SwapBytesForTexture_(GLenum format, GLenum type, const GLubyte* src, GLubyte* dst, GLsizei width) {
size_t componentSize = GetComponentSize_(type);
if (componentSize <= 1) {
memcpy(dst, src, width * componentSize);
return;
@@ -1172,21 +1172,21 @@ void TextureState::SwapBytesForTexture(GLenum format, GLenum type, const GLubyte
}
}
GLubyte TextureState::ReverseBits(GLubyte b) {
GLubyte TextureState::ReverseBits_(GLubyte b) {
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
return b;
}
void TextureState::ReverseBitOrder(const GLubyte* src, GLubyte* dst, size_t byteCount) {
void TextureState::ReverseBitOrder_(const GLubyte* src, GLubyte* dst, size_t byteCount) {
for (size_t i = 0; i < byteCount; ++i) {
dst[i] = ReverseBits(src[i]);
dst[i] = ReverseBits_(src[i]);
}
}
void TextureState::SwapPixelBytes(GLenum format, GLenum type, const GLubyte* src, GLubyte* dst) {
const size_t size = GetComponentSize(type);
void TextureState::SwapPixelBytes_(GLenum format, GLenum type, const GLubyte* src, GLubyte* dst) {
const size_t size = GetComponentSize_(type);
for (size_t i = 0; i < size; ++i) {
dst[i] = src[size - 1 - i];
}
+19 -19
View File
@@ -55,15 +55,15 @@ public:
class TextureState {
private:
std::vector<TextureUnitState> textureUnits;
GLuint activeTextureUnit = 0;
std::vector<TextureUnitState> textureUnits_;
GLuint activeTextureUnit_ = 0;
GLuint lastUsedID = 0;
std::set<GLuint> freeIDs;
GLuint lastUsedID_ = 0;
std::set<GLuint> freeIDs_;
std::unordered_map<GLenum, TextureObject> proxyTextures;
std::unordered_map<GLenum, TextureObject> proxyTextures_;
static GLint GetUnpackParam(GLenum pname);
static GLint GetUnpackParam_(GLenum pname);
public:
TextureState();
@@ -89,22 +89,22 @@ public:
GLenum GetLevelPropertyIntVector(GLenum target, GLint level, GLenum pname, GLint* params);
private:
size_t CalculatePixelDataSize(GLenum format, GLenum type, GLsizei width, GLsizei height);
void InvalidateTextureInAllUnits(GLuint texture);
static ComponentSizes GetComponentSizes(GLenum internalFormat);
size_t CalculateBytesPerPixel(GLenum format, GLenum type);
static size_t GetComponentSize(GLenum type);
void SwapBytesForTexture(GLenum format, GLenum type, const GLubyte* src, GLubyte* dst, GLsizei width);
static void ReverseBitOrder(const GLubyte* src, GLubyte* dst, size_t size);
static GLubyte ReverseBits(GLubyte b);
void SwapPixelBytes(GLenum format, GLenum type, const GLubyte* src, GLubyte* dst);
size_t CalculatePixelDataSize_(GLenum format, GLenum type, GLsizei width, GLsizei height);
void InvalidateTextureInAllUnits_(GLuint texture);
static ComponentSizes GetComponentSize_s_(GLenum internalFormat);
size_t CalculateBytesPerPixel_(GLenum format, GLenum type);
static size_t GetComponentSize_(GLenum type);
void SwapBytesForTexture_(GLenum format, GLenum type, const GLubyte* src, GLubyte* dst, GLsizei width);
static void ReverseBitOrder_(const GLubyte* src, GLubyte* dst, size_t size);
static GLubyte ReverseBits_(GLubyte b);
void SwapPixelBytes_(GLenum format, GLenum type, const GLubyte* src, GLubyte* dst);
GLenum CheckUploadingTexture2DValidity(GLenum target, GLint level, GLint internalFormat,
GLenum CheckUploadingTexture2DValidity_(GLenum target, GLint level, GLint internalFormat,
GLsizei width, GLsizei height, GLint border, GLenum format,
GLenum type, const void* data);
GLenum CheckUpdatingTextureRegion2DValidity(GLenum target, GLint level, GLint xoffset,
GLint yoffset, GLsizei width, GLsizei height, GLenum format,
GLenum type, const GLvoid* data);
GLenum CheckUpdatingTextureRegion2DValidity_(GLenum target, GLint level, GLint xoffset,
GLint yoffset, GLsizei width, GLsizei height, GLenum format,
GLenum type, const GLvoid* data);
};
#endif //MOBILEGL_TEXTURESTATE_H