[Feat] (MG_Impl/GLImpl, MG_State): implement glClampColor and glPolygonMode

Fill the two empty // TODO state handlers with GL 3.3 Core-conformant
behavior, backed by new RenderState fields and glGet* read-back.

glClampColor:
- Accept only GL_CLAMP_READ_COLOR (compat GL_CLAMP_VERTEX/FRAGMENT_COLOR
  rejected); clamp is one of GL_TRUE / GL_FALSE / GL_FIXED_ONLY. Note the
  Khronos man page wrongly omits GL_FIXED_ONLY from the accepted set, but
  it is legal AND the default, so it is accepted here.
- Default GL_FIXED_ONLY; both error paths are GL_INVALID_ENUM with no
  state change. glGetIntegerv returns the raw tri-state enum; GetFloatv/
  GetDoublev widen it and GetBooleanv converts nonzero to GL_TRUE via the
  existing fall-through, so one GetIntegerv case serves every getter.

glPolygonMode:
- Core accepts only face == GL_FRONT_AND_BACK (GL_FRONT/GL_BACK were
  removed in 3.1 core); mode is GL_POINT / GL_LINE / GL_FILL. Both errors
  are GL_INVALID_ENUM with no state change.
- Keep separate front/back slots so GL_POLYGON_MODE round-trips its two
  values (identical under a core context). The raster effect (VkPolygonMode
  + fillModeNonSolid) remains a backend follow-up; this is the state layer.

Tests: two RenderStateSanity round-trips; the glClampColor GL_FIXED_ONLY
acceptance assertion is mutation-verified (rejecting it fails the test).
Full SanityTest sweep green (29/29).
This commit is contained in:
2026-07-10 21:21:40 -04:00
parent e460536119
commit 95876d9d8c
7 changed files with 209 additions and 4 deletions
+20
View File
@@ -352,6 +352,26 @@ namespace MobileGL::MG_State {
return m_renderState.GetPointSpriteCoordOrigin();
}
void GLContext::SetClampReadColor(GLenum clamp) {
m_renderState.SetClampReadColor(clamp);
}
GLenum GLContext::GetClampReadColor() const {
return m_renderState.GetClampReadColor();
}
void GLContext::SetPolygonMode(GLenum front, GLenum back) {
m_renderState.SetPolygonMode(front, back);
}
GLenum GLContext::GetPolygonModeFront() const {
return m_renderState.GetPolygonModeFront();
}
GLenum GLContext::GetPolygonModeBack() const {
return m_renderState.GetPolygonModeBack();
}
void GLContext::SetPointSize(Float size) {
m_renderState.SetPointSize(size);
}
+5
View File
@@ -131,6 +131,11 @@ namespace MobileGL {
Float GetPointFadeThresholdSize() const;
void SetPointSpriteCoordOrigin(GLenum origin);
GLenum GetPointSpriteCoordOrigin() const;
void SetClampReadColor(GLenum clamp);
GLenum GetClampReadColor() const;
void SetPolygonMode(GLenum front, GLenum back);
GLenum GetPolygonModeFront() const;
GLenum GetPolygonModeBack() const;
void SetCapability(CapabilityInput cap, Bool enabled);
Bool IsCapabilityEnabled(CapabilityInput cap) const;
void SetCapabilityIndexed(CapabilityInput cap, Uint index, Bool enabled);
@@ -103,6 +103,31 @@ namespace MobileGL {
return m_parameters.PointSpriteCoordOrigin;
}
void RenderState::SetClampReadColor(GLenum clamp) {
if (m_parameters.ClampReadColor == clamp) return;
m_parameters.ClampReadColor = clamp;
++m_version;
}
GLenum RenderState::GetClampReadColor() const {
return m_parameters.ClampReadColor;
}
void RenderState::SetPolygonMode(GLenum front, GLenum back) {
if (m_parameters.PolygonModeFront == front && m_parameters.PolygonModeBack == back) return;
m_parameters.PolygonModeFront = front;
m_parameters.PolygonModeBack = back;
++m_version;
}
GLenum RenderState::GetPolygonModeFront() const {
return m_parameters.PolygonModeFront;
}
GLenum RenderState::GetPolygonModeBack() const {
return m_parameters.PolygonModeBack;
}
void RenderState::SetPointSize(Float size) {
if (m_parameters.PointSize == size) return;
@@ -260,6 +260,14 @@ namespace MobileGL {
Float PointFadeThresholdSize = 1.0f;
GLenum PointSpriteCoordOrigin = GL_UPPER_LEFT;
// Color clamping (glClampColor). Core profile exposes only GL_CLAMP_READ_COLOR.
GLenum ClampReadColor = GL_FIXED_ONLY;
// Polygon rasterization mode (glPolygonMode). Core profile sets front and back together,
// but GL_POLYGON_MODE still reports both slots, so keep them separate for a faithful query.
GLenum PolygonModeFront = GL_FILL;
GLenum PolygonModeBack = GL_FILL;
// Scissor
Bool ColorLogicOpEnabled = false;
Bool DebugOutputEnabled = false;
@@ -310,6 +318,13 @@ namespace MobileGL {
Float GetPointFadeThresholdSize() const;
void SetPointSpriteCoordOrigin(GLenum origin);
GLenum GetPointSpriteCoordOrigin() const;
// Color clamping (glClampColor). Core profile has only GL_CLAMP_READ_COLOR.
void SetClampReadColor(GLenum clamp);
GLenum GetClampReadColor() const;
// Polygon mode (glPolygonMode). Core sets both faces together; the query reports both.
void SetPolygonMode(GLenum front, GLenum back);
GLenum GetPolygonModeFront() const;
GLenum GetPolygonModeBack() const;
// Capabilities
void SetCapability(CapabilityInput cap, Bool enabled);