[Feat] (...): Handle pixel store correctly.

This commit is contained in:
BZLZHH
2025-11-01 19:52:33 +08:00
parent bcb947235d
commit d652645346
11 changed files with 406 additions and 73 deletions
+4
View File
@@ -285,6 +285,10 @@ namespace MobileGL {
return m_renderState.GetPixelStoreParam(param);
}
PixelStoreParameters GLContext::GetPixelStoreParameters(Bool isUnpack) const {
return m_renderState.GetPixelStoreParameters(isUnpack);
}
void GLContext::SetCullFaceMode(CullFaceMode mode) {
m_renderState.SetCullFaceMode(mode);
}
+1
View File
@@ -90,6 +90,7 @@ namespace MobileGL {
Float GetClearDepth() const;
void SetPixelStoreParam(PixelStoreParam param, Int value);
Int GetPixelStoreParam(PixelStoreParam param) const;
PixelStoreParameters GetPixelStoreParameters(Bool isUnpack) const;
void SetCullFaceMode(CullFaceMode mode);
CullFaceMode GetCullFaceMode() const;
void SetScissorBox(IntVec4 box); // x, y, width, height
@@ -3,20 +3,7 @@
namespace MobileGL {
namespace MG_State {
namespace GLState {
RenderState::RenderState() {
for (int i = 0; i < static_cast<int>(PixelStoreParam::PixelStoreParamCount); ++i) {
switch (static_cast<PixelStoreParam>(i)) {
case PixelStoreParam::PackAlignment:
case PixelStoreParam::UnpackAlignment:
m_pixelStoreParams[i] = 4;
break;
default:
m_pixelStoreParams[i] = 0;
break;
}
}
}
RenderState::RenderState() {}
// -------------------- Rasterization --------------------
void RenderState::SetViewport(IntVec4 viewport) {
@@ -124,11 +111,107 @@ namespace MobileGL {
// -------------------- Pixel Store --------------------
void RenderState::SetPixelStoreParam(PixelStoreParam param, Int value) {
m_pixelStoreParams[static_cast<SizeT>(param)] = value;
switch (param) {
case PixelStoreParam::PackAlignment:
m_packParameters.Alignment = value;
break;
case PixelStoreParam::PackRowLength:
m_packParameters.RowLength = value;
break;
case PixelStoreParam::PackImageHeight:
m_packParameters.ImageHeight = value;
break;
case PixelStoreParam::PackSkipPixels:
m_packParameters.SkipPixels = value;
break;
case PixelStoreParam::PackSkipRows:
m_packParameters.SkipRows = value;
break;
case PixelStoreParam::PackSkipImages:
m_packParameters.SkipImages = value;
break;
case PixelStoreParam::PackSwapBytes:
m_packParameters.SwapBytes = value != 0;
break;
case PixelStoreParam::PackLsbFirst:
m_packParameters.LSBFirst = value != 0;
break;
case PixelStoreParam::UnpackAlignment:
m_unpackParameters.Alignment = value;
break;
case PixelStoreParam::UnpackRowLength:
m_unpackParameters.RowLength = value;
break;
case PixelStoreParam::UnpackImageHeight:
m_unpackParameters.ImageHeight = value;
break;
case PixelStoreParam::UnpackSkipPixels:
m_unpackParameters.SkipPixels = value;
break;
case PixelStoreParam::UnpackSkipRows:
m_unpackParameters.SkipRows = value;
break;
case PixelStoreParam::UnpackSkipImages:
m_unpackParameters.SkipImages = value;
break;
case PixelStoreParam::UnpackSwapBytes:
m_unpackParameters.SwapBytes = value != 0;
break;
case PixelStoreParam::UnpackLsbFirst:
m_unpackParameters.LSBFirst = value != 0;
break;
default:
MGLOG_F("RenderState::SetPixelStoreParam: Invalid PixelStoreParam enum: %d",
static_cast<int>(param));
assert(false && "Invalid PixelStoreParam enum");
return;
}
}
Int RenderState::GetPixelStoreParam(PixelStoreParam param) const {
return m_pixelStoreParams[static_cast<SizeT>(param)];
switch (param) {
case PixelStoreParam::PackAlignment:
return m_packParameters.Alignment;
case PixelStoreParam::PackRowLength:
return m_packParameters.RowLength;
case PixelStoreParam::PackImageHeight:
return m_packParameters.ImageHeight;
case PixelStoreParam::PackSkipPixels:
return m_packParameters.SkipPixels;
case PixelStoreParam::PackSkipRows:
return m_packParameters.SkipRows;
case PixelStoreParam::PackSkipImages:
return m_packParameters.SkipImages;
case PixelStoreParam::PackSwapBytes:
return m_packParameters.SwapBytes ? 1 : 0;
case PixelStoreParam::PackLsbFirst:
return m_packParameters.LSBFirst ? 1 : 0;
case PixelStoreParam::UnpackAlignment:
return m_unpackParameters.Alignment;
case PixelStoreParam::UnpackRowLength:
return m_unpackParameters.RowLength;
case PixelStoreParam::UnpackImageHeight:
return m_unpackParameters.ImageHeight;
case PixelStoreParam::UnpackSkipPixels:
return m_unpackParameters.SkipPixels;
case PixelStoreParam::UnpackSkipRows:
return m_unpackParameters.SkipRows;
case PixelStoreParam::UnpackSkipImages:
return m_unpackParameters.SkipImages;
case PixelStoreParam::UnpackSwapBytes:
return m_unpackParameters.SwapBytes ? 1 : 0;
case PixelStoreParam::UnpackLsbFirst:
return m_unpackParameters.LSBFirst ? 1 : 0;
default:
MGLOG_F("RenderState::GetPixelStoreParam: Invalid PixelStoreParam enum: %d",
static_cast<int>(param));
assert(false && "Invalid PixelStoreParam enum");
return 0;
}
}
PixelStoreParameters RenderState::GetPixelStoreParameters(Bool isUnpack) const {
return isUnpack ? m_unpackParameters : m_packParameters;
}
// -------------------- Cull Face --------------------
@@ -109,6 +109,17 @@ namespace MobileGL {
Unknown = -1
};
struct PixelStoreParameters {
Bool SwapBytes = false;
Bool LSBFirst = false;
Int RowLength = 0;
Int ImageHeight = 0;
Int SkipPixels = 0;
Int SkipRows = 0;
Int SkipImages = 0;
Int Alignment = 4;
};
namespace MG_State {
namespace GLState {
class RenderState {
@@ -147,6 +158,7 @@ namespace MobileGL {
// Pixel Store
void SetPixelStoreParam(PixelStoreParam param, Int value);
Int GetPixelStoreParam(PixelStoreParam param) const;
PixelStoreParameters GetPixelStoreParameters(Bool isUnpack) const;
// Cull Face
void SetCullFaceMode(CullFaceMode mode);
@@ -180,7 +192,8 @@ namespace MobileGL {
Float m_clearDepth = 1.0f;
// Pixel Store
Array<Int, static_cast<SizeT>(PixelStoreParam::PixelStoreParamCount)> m_pixelStoreParams;
PixelStoreParameters m_packParameters;
PixelStoreParameters m_unpackParameters;
// Cull Face
Bool m_cullFaceEnabled = false;
@@ -58,8 +58,10 @@ namespace MobileGL {
}
MipmapLevelInternal& TextureObjectBase::GetMipmap(Int index) {
if (index > m_mipmaps.size()) {
// fallback to the last mipmap
if (index >= m_mipmaps.size()) {
MGLOG_F("TextureObjectBase::GetMipmap: Requested mipmap level %d exceeds available levels %zu",
index, m_mipmaps.size());
assert(false && "Requested mipmap level exceeds available levels");
index = static_cast<Int>(m_mipmaps.size() - 1);
}
return m_mipmaps[index];
@@ -145,7 +147,7 @@ namespace MobileGL {
void TextureObject1D::SetMipmapImpl(const MipmapLevelInput& level) {
if (level.size.x() > 0) {
m_mipmaps.push_back(level);
m_mipmaps.push_back(MipmapLevelInternal(level));
}
}
@@ -155,7 +157,7 @@ namespace MobileGL {
void TextureObject2D::SetMipmapImpl(const MipmapLevelInput& level) {
if (level.size.x() > 0 && level.size.y() > 0) {
m_mipmaps.push_back(level);
m_mipmaps.push_back(MipmapLevelInternal(level));
}
}
@@ -165,7 +167,7 @@ namespace MobileGL {
void TextureObject3D::SetMipmapImpl(const MipmapLevelInput& level) {
if (level.size.x() > 0 && level.size.y() > 0 && level.size.z() > 0) {
m_mipmaps.push_back(level);
m_mipmaps.push_back(MipmapLevelInternal(level));
}
}