diff --git a/MobileGL/MG_Impl/EGLImpl/EGLPlatformExtensions.h b/MobileGL/MG_Impl/EGLImpl/EGLPlatformExtensions.h index 1e53f0b4..c081ac8f 100644 --- a/MobileGL/MG_Impl/EGLImpl/EGLPlatformExtensions.h +++ b/MobileGL/MG_Impl/EGLImpl/EGLPlatformExtensions.h @@ -25,9 +25,12 @@ namespace MobileGL::MG_Impl::EGLImpl { inline constexpr const char* kPlatformExtensionString = "EGL_EXT_client_extensions EGL_EXT_platform_base EGL_KHR_platform_base " "EGL_MESA_platform_surfaceless" MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS; +// eglGetProcAddress answers every core GL and EGL entry point. Loaders such as GLFW read +// EGL_KHR_get_all_proc_addresses to decide that, and without it they resolve core GL from +// whatever libGL.so.1 the system has instead of from this library. #define MOBILEGL_DISPLAY_EXTENSIONS \ - "EGL_KHR_create_context EGL_KHR_surfaceless_context EGL_KHR_no_config_context EGL_EXT_platform_base " \ - "EGL_KHR_platform_base EGL_MESA_platform_surfaceless" MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS + "EGL_KHR_create_context EGL_KHR_get_all_proc_addresses EGL_KHR_surfaceless_context EGL_KHR_no_config_context " \ + "EGL_EXT_platform_base EGL_KHR_platform_base EGL_MESA_platform_surfaceless" MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS inline constexpr const char* kDisplayExtensionString = MOBILEGL_DISPLAY_EXTENSIONS; // The split client reports a lost server session through glGetGraphicsResetStatus. inline constexpr const char* kDisplayExtensionStringWithResetNotification = @@ -47,6 +50,7 @@ namespace MobileGL::MG_Impl::EGLImpl { " EGL_KHR_fence_sync EGL_KHR_wait_sync EGL_ANDROID_native_fence_sync"; #undef MOBILEGL_DISPLAY_EXTENSIONS inline constexpr const char* kClientExtensionString = - "EGL_EXT_client_extensions EGL_KHR_create_context EGL_EXT_platform_base " - "EGL_KHR_platform_base EGL_MESA_platform_surfaceless" MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS; + "EGL_EXT_client_extensions EGL_KHR_client_get_all_proc_addresses EGL_KHR_create_context " + "EGL_EXT_platform_base EGL_KHR_platform_base " + "EGL_MESA_platform_surfaceless" MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS; } // namespace MobileGL::MG_Impl::EGLImpl diff --git a/MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp b/MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp index debb3423..3998c7d2 100644 --- a/MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp +++ b/MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp @@ -409,7 +409,7 @@ DECLARE_GL_FUNCTION_HEAD(void, VertexAttribFormat, GLuint attribindex, GLint siz DECLARE_GL_FUNCTION_HEAD(void, VertexAttribIFormat, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset) DECLARE_GL_FUNCTION_END_NO_RETURN(void, VertexAttribIFormat, attribindex, size, type, relativeoffset) DECLARE_GL_FUNCTION_HEAD(void, VertexAttribBinding, GLuint attribindex, GLuint bindingindex) DECLARE_GL_FUNCTION_END_NO_RETURN(void, VertexAttribBinding, attribindex, bindingindex) DECLARE_GL_FUNCTION_HEAD(void, VertexBindingDivisor, GLuint bindingindex, GLuint divisor) DECLARE_GL_FUNCTION_END_NO_RETURN(void, VertexBindingDivisor, bindingindex, divisor) -DECLARE_GL_FUNCTION_STUB_HEAD(void, BlendBarrier) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, BlendBarrier) +DECLARE_GL_FUNCTION_HEAD(void, BlendBarrier) DECLARE_GL_FUNCTION_END_NO_RETURN(void, BlendBarrier) DECLARE_GL_FUNCTION_HEAD(void, CopyImageSubData, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth) DECLARE_GL_FUNCTION_END_NO_RETURN(void, CopyImageSubData, srcName, srcTarget, srcLevel, srcX, srcY, srcZ, dstName, dstTarget, dstLevel, dstX, dstY, dstZ, srcWidth, srcHeight, srcDepth) DECLARE_GL_FUNCTION_STUB_HEAD(void, DebugMessageControl, GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint* ids, GLboolean enabled) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, DebugMessageControl, source, type, severity, count, ids, enabled) DECLARE_GL_FUNCTION_HEAD(void, DebugMessageInsert, GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* buf) DECLARE_GL_FUNCTION_END_NO_RETURN(void, DebugMessageInsert, source, type, id, severity, length, buf) @@ -438,7 +438,7 @@ DECLARE_GL_FUNCTION_HEAD(void, DrawElementsBaseVertex, GLenum mode, GLsizei coun DECLARE_GL_FUNCTION_HEAD(void, DrawRangeElementsBaseVertex, GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices, GLint basevertex) DECLARE_GL_FUNCTION_END_NO_RETURN(void, DrawRangeElementsBaseVertex, mode, start, end, count, type, indices, basevertex) DECLARE_GL_FUNCTION_HEAD(void, DrawElementsInstancedBaseVertex, GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instancecount, GLint basevertex) DECLARE_GL_FUNCTION_END_NO_RETURN(void, DrawElementsInstancedBaseVertex, mode, count, type, indices, instancecount, basevertex) DECLARE_GL_FUNCTION_HEAD(void, FramebufferTexture, GLenum target, GLenum attachment, GLuint texture, GLint level) DECLARE_GL_FUNCTION_END_NO_RETURN(void, FramebufferTexture, target, attachment, texture, level) -DECLARE_GL_FUNCTION_STUB_HEAD(void, PrimitiveBoundingBox, GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, GLfloat maxY, GLfloat maxZ, GLfloat maxW) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, PrimitiveBoundingBox, minX, minY, minZ, minW, maxX, maxY, maxZ, maxW) +DECLARE_GL_FUNCTION_HEAD(void, PrimitiveBoundingBox, GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, GLfloat maxY, GLfloat maxZ, GLfloat maxW) DECLARE_GL_FUNCTION_END_NO_RETURN(void, PrimitiveBoundingBox, minX, minY, minZ, minW, maxX, maxY, maxZ, maxW) DECLARE_GL_FUNCTION_HEAD(GLenum, GetGraphicsResetStatus) DECLARE_GL_FUNCTION_END(GLenum, GetGraphicsResetStatus) DECLARE_GL_FUNCTION_HEAD(void, ReadnPixels, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void* data) DECLARE_GL_FUNCTION_END_NO_RETURN(void, ReadnPixels, x, y, width, height, format, type, bufSize, data) DECLARE_GL_FUNCTION_HEAD(void, GetnUniformfv, GLuint program, GLint location, GLsizei bufSize, GLfloat* params) DECLARE_GL_FUNCTION_END_NO_RETURN(void, GetnUniformfv, program, location, bufSize, params) diff --git a/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp b/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp index 5d47e41c..3e36d80e 100644 --- a/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp +++ b/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp @@ -860,6 +860,12 @@ namespace MobileGL::MG_Impl::GLImpl { case GL_BLEND: *params = MG_State::pGLContext->IsCapabilityEnabled(CapabilityInput::Blend) ? GL_TRUE : GL_FALSE; return; + case GL_PRIMITIVE_BOUNDING_BOX: { + const auto& box = MG_State::pGLContext->GetPrimitiveBoundingBox(); + for (SizeT i = 0; i < box.size(); ++i) + params[i] = box[i] != 0.0f ? GL_TRUE : GL_FALSE; + return; + } case GL_BLEND_COLOR: { const FloatVec4& blendColor = MG_State::pGLContext->GetBlendColor(); params[0] = blendColor.x() != 0.0f ? GL_TRUE : GL_FALSE; @@ -998,6 +1004,11 @@ namespace MobileGL::MG_Impl::GLImpl { } switch (pname) { + case GL_PRIMITIVE_BOUNDING_BOX: { + const auto& box = MG_State::pGLContext->GetPrimitiveBoundingBox(); + std::copy(box.begin(), box.end(), params); + return; + } case GL_BLEND_COLOR: { const FloatVec4& blendColor = MG_State::pGLContext->GetBlendColor(); params[0] = blendColor.x(); @@ -1552,6 +1563,13 @@ namespace MobileGL::MG_Impl::GLImpl { params[0] = static_cast(timestamp); return; } + case GL_PRIMITIVE_BOUNDING_BOX: { + // Eight components, more than the scratch array below holds. + const auto& box = MG_State::pGLContext->GetPrimitiveBoundingBox(); + for (SizeT i = 0; i < box.size(); ++i) + params[i] = static_cast(std::llround(box[i])); + return; + } default: break; } @@ -1600,6 +1618,13 @@ namespace MobileGL::MG_Impl::GLImpl { MakeUnique("MG_Impl/GLImpl", __func__, "params pointer cannot be null")); return; } + if (pname == GL_PRIMITIVE_BOUNDING_BOX) { + // Eight components, more than the scratch array below holds. + const auto& box = MG_State::pGLContext->GetPrimitiveBoundingBox(); + for (SizeT i = 0; i < box.size(); ++i) + params[i] = static_cast(box[i]); + return; + } GLfloat floats[4] = {}; GetFloatv(pname, floats); GLsizei count = 1; @@ -1796,6 +1821,12 @@ namespace MobileGL::MG_Impl::GLImpl { case GL_BLEND: *params = MG_State::pGLContext->IsCapabilityEnabled(CapabilityInput::Blend) ? GL_TRUE : GL_FALSE; return; + case GL_PRIMITIVE_BOUNDING_BOX: { + const auto& box = MG_State::pGLContext->GetPrimitiveBoundingBox(); + for (SizeT i = 0; i < box.size(); ++i) + params[i] = static_cast(std::lround(box[i])); + return; + } case GL_BLEND_COLOR: { const FloatVec4& blendColor = MG_State::pGLContext->GetBlendColor(); params[0] = static_cast(blendColor.x()); diff --git a/MobileGL/MG_Impl/GLImpl/RenderState/GL_RenderState.cpp b/MobileGL/MG_Impl/GLImpl/RenderState/GL_RenderState.cpp index aef060d1..a981982e 100644 --- a/MobileGL/MG_Impl/GLImpl/RenderState/GL_RenderState.cpp +++ b/MobileGL/MG_Impl/GLImpl/RenderState/GL_RenderState.cpp @@ -1109,6 +1109,13 @@ namespace MobileGL::MG_Impl::GLImpl { MinSampleShading_State(value); } + void BlendBarrier() {} + + void PrimitiveBoundingBox(GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, GLfloat maxY, + GLfloat maxZ, GLfloat maxW) { + MG_State::pGLContext->SetPrimitiveBoundingBox({minX, minY, minZ, minW, maxX, maxY, maxZ, maxW}); + } + void PolygonOffset(GLfloat factor, GLfloat units) { PolygonOffset_State(factor, units); } diff --git a/MobileGL/MG_Impl/GLImpl/RenderState/GL_RenderState.h b/MobileGL/MG_Impl/GLImpl/RenderState/GL_RenderState.h index 47a40be5..7b91db6b 100644 --- a/MobileGL/MG_Impl/GLImpl/RenderState/GL_RenderState.h +++ b/MobileGL/MG_Impl/GLImpl/RenderState/GL_RenderState.h @@ -39,6 +39,10 @@ namespace MobileGL::MG_Impl::GLImpl { void Scissor(GLint x, GLint y, GLsizei width, GLsizei height); void SampleCoverage(GLfloat value, GLboolean invert); void MinSampleShading(GLfloat value); + // ES 3.2 core. No advanced blend equation is accepted, so there is never a blend to order. + void BlendBarrier(); + void PrimitiveBoundingBox(GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, GLfloat maxY, + GLfloat maxZ, GLfloat maxW); void PolygonOffset(GLfloat factor, GLfloat units); void PolygonOffsetClamp(GLfloat factor, GLfloat units, GLfloat clamp); void ClipControl(GLenum origin, GLenum depth); diff --git a/MobileGL/MG_Impl/GetProcAddress.cpp b/MobileGL/MG_Impl/GetProcAddress.cpp index a001abd2..178059d0 100644 --- a/MobileGL/MG_Impl/GetProcAddress.cpp +++ b/MobileGL/MG_Impl/GetProcAddress.cpp @@ -47,6 +47,10 @@ extern "C" void glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSi extern "C" void glGetnUniformivKHR(GLuint program, GLint location, GLsizei bufSize, GLint* params); extern "C" void glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params); extern "C" void glGetnUniformuivKHR(GLuint program, GLint location, GLsizei bufSize, GLuint* params); +// ES 3.2 core names (Definitions.cpp) that no desktop header declares. +extern "C" void glBlendBarrier(void); +extern "C" void glPrimitiveBoundingBox(GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, + GLfloat maxY, GLfloat maxZ, GLfloat maxW); #define GETPROC(name, var) \ if (strcmp(#name, var) == 0) { \ @@ -511,6 +515,8 @@ namespace MobileGL::MG_Impl { GETPROC(glVertexAttribP4ui, name); GETPROC(glVertexAttribP4uiv, name); GETPROC(glMinSampleShading, name); + GETPROC(glBlendBarrier, name); + GETPROC(glPrimitiveBoundingBox, name); GETPROC(glBlendEquationi, name); GETPROC(glBlendEquationSeparatei, name); GETPROC(glBlendFunci, name); diff --git a/MobileGL/MG_State/GLState/Core.h b/MobileGL/MG_State/GLState/Core.h index 0068d9c9..b44bb85a 100644 --- a/MobileGL/MG_State/GLState/Core.h +++ b/MobileGL/MG_State/GLState/Core.h @@ -434,6 +434,10 @@ namespace MobileGL { void SetShadingRateCombinerOps(Uint8 op0, Uint8 op1); Uint8 GetShadingRateCombinerOp0() const; Uint8 GetShadingRateCombinerOp1() const; + // glPrimitiveBoundingBox (ES 3.2 core): min (x, y, z, w) then max (x, y, z, w). + // A hint, so it is kept and queried but never forwarded. + void SetPrimitiveBoundingBox(const std::array& box) { m_primitiveBoundingBox = box; } + const std::array& GetPrimitiveBoundingBox() const { return m_primitiveBoundingBox; } void SetPixelStoreParam(PixelStoreParam param, Int value); Int GetPixelStoreParam(PixelStoreParam param) const; PixelStoreParameters GetPixelStoreParameters(Bool isUnpack) const; @@ -703,6 +707,8 @@ namespace MobileGL { Uint64 m_transformFeedbackAccountedCaptureDraws = 0; Uint64 m_transformFeedbackGeometryCaptureDraws = 0; + std::array m_primitiveBoundingBox = {-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}; + // Conditional rendering. Context state, not object state: GL 4.6 core 10.9 allows // exactly one block open at a time and no object owns it. Bool m_conditionalRenderActive = false; diff --git a/MobileGL/MG_Test/EGLState/EGLStateTest.cpp b/MobileGL/MG_Test/EGLState/EGLStateTest.cpp index 3aed20cc..69cf7185 100644 --- a/MobileGL/MG_Test/EGLState/EGLStateTest.cpp +++ b/MobileGL/MG_Test/EGLState/EGLStateTest.cpp @@ -7,12 +7,14 @@ // End of Source File Header #include +#include #include #include #include #include #include #include +#include #include #include @@ -634,6 +636,21 @@ TEST(EGLStateRobustness, HidesGlResetExtensionsWhenUnavailable) { EXPECT_STREQ(extensions.front(), "GL_OES_EGL_image"); } +// eglGetProcAddress answers core GL and EGL, and loaders such as GLFW only use it for core GL +// when the extension says so; otherwise they take core GL from the system libGL.so.1. +TEST(EGLStateExtensions, EveryListPromisesProcAddressesForCoreEntryPoints) { + namespace EGLImpl = MobileGL::MG_Impl::EGLImpl; + const auto hasToken = [](const char* list, const char* token) { + const std::string padded = std::string(" ") + list + " "; + return padded.find(std::string(" ") + token + " ") != std::string::npos; + }; + EXPECT_TRUE(hasToken(EGLImpl::kClientExtensionString, "EGL_KHR_client_get_all_proc_addresses")); + for (const char* display : {EGLImpl::kDisplayExtensionString, EGLImpl::kDisplayExtensionStringWithResetNotification, + EGLImpl::kDisplayExtensionStringWithSharedImages}) { + EXPECT_TRUE(hasToken(display, "EGL_KHR_get_all_proc_addresses")) << display; + } +} + TEST(EGLStateRobustness, RejectsResetNotificationWhenUnavailable) { auto fixture = CreateFixture(); auto& state = fixture->State; diff --git a/MobileGL/MG_Test/State/RenderStateTest.cpp b/MobileGL/MG_Test/State/RenderStateTest.cpp index e8f81c12..a3b85428 100644 --- a/MobileGL/MG_Test/State/RenderStateTest.cpp +++ b/MobileGL/MG_Test/State/RenderStateTest.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -901,6 +902,48 @@ TEST_F(RenderStateTest, MinSampleShadingRoundTripsAndClamps) { MG_Impl::GLImpl::MinSampleShading(0.0f); } +// ES 3.2 core entry points that EGL_KHR_get_all_proc_addresses promises by name. The bounding box +// is a hint, but its state is queryable: initial (-1, -1, -1, 1) to (1, 1, 1, 1). +TEST_F(RenderStateTest, PrimitiveBoundingBoxAndBlendBarrierResolveAndKeepState) { + EXPECT_NE(MG_Impl::GetProcAddress("glBlendBarrier"), nullptr); + EXPECT_NE(MG_Impl::GetProcAddress("glPrimitiveBoundingBox"), nullptr); + DrainPendingGlErrors(); + + GLfloat box[8] = {}; + MG_Impl::GLImpl::GetFloatv(GL_PRIMITIVE_BOUNDING_BOX, box); + const GLfloat initial[8] = {-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}; + for (int i = 0; i < 8; ++i) + EXPECT_FLOAT_EQ(box[i], initial[i]) << i; + + MG_Impl::GLImpl::PrimitiveBoundingBox(-2.5f, 0.0f, 3.0f, 1.0f, 4.0f, 5.0f, 6.0f, 1.0f); + MG_Impl::GLImpl::BlendBarrier(); + EXPECT_EQ(MG_Impl::GLImpl::GetError(), static_cast(GL_NO_ERROR)); + MG_Impl::GLImpl::GetFloatv(GL_PRIMITIVE_BOUNDING_BOX, box); + const GLfloat expected[8] = {-2.5f, 0.0f, 3.0f, 1.0f, 4.0f, 5.0f, 6.0f, 1.0f}; + for (int i = 0; i < 8; ++i) + EXPECT_FLOAT_EQ(box[i], expected[i]) << i; + + // All eight components through every typed getter, including the ones that widen. + GLdouble asDouble[8] = {}; + MG_Impl::GLImpl::GetDoublev(GL_PRIMITIVE_BOUNDING_BOX, asDouble); + GLint64 asInt64[8] = {}; + MG_Impl::GLImpl::GetInteger64v(GL_PRIMITIVE_BOUNDING_BOX, asInt64); + GLint asInt[8] = {}; + MG_Impl::GLImpl::GetIntegerv(GL_PRIMITIVE_BOUNDING_BOX, asInt); + GLboolean asBoolean[8] = {}; + MG_Impl::GLImpl::GetBooleanv(GL_PRIMITIVE_BOUNDING_BOX, asBoolean); + const GLint rounded[8] = {-3, 0, 3, 1, 4, 5, 6, 1}; + for (int i = 0; i < 8; ++i) { + EXPECT_DOUBLE_EQ(asDouble[i], static_cast(expected[i])) << i; + EXPECT_EQ(asInt64[i], rounded[i]) << i; + EXPECT_EQ(asInt[i], rounded[i]) << i; + EXPECT_EQ(asBoolean[i], expected[i] != 0.0f ? GL_TRUE : GL_FALSE) << i; + } + EXPECT_EQ(MG_Impl::GLImpl::GetError(), static_cast(GL_NO_ERROR)); + + MG_Impl::GLImpl::PrimitiveBoundingBox(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); +} + TEST_F(RenderStateTest, SampleShadingEnableIsStoredAndQueryable) { DrainPendingGlErrors();