From 3942dff532fc9a57d410fe565a3e97bc85f0584c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 2 May 2020 22:03:43 +0200 Subject: [PATCH] GL: add a test for global function pointers across libraries as well. Fails. The huge change just before should have made the fix possible, but apparently it's not so simple. Nothing is ever simple. Sigh. --- .../Test/GlobalStateAcrossLibrariesGLTest.cpp | 29 +++++++++++++++++-- .../GlobalStateAcrossLibrariesLibrary.cpp | 4 +++ .../Test/GlobalStateAcrossLibrariesLibrary.h | 1 + 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Magnum/GL/Test/GlobalStateAcrossLibrariesGLTest.cpp b/src/Magnum/GL/Test/GlobalStateAcrossLibrariesGLTest.cpp index faa32bd81..18899d583 100644 --- a/src/Magnum/GL/Test/GlobalStateAcrossLibrariesGLTest.cpp +++ b/src/Magnum/GL/Test/GlobalStateAcrossLibrariesGLTest.cpp @@ -33,14 +33,16 @@ namespace Magnum { namespace GL { namespace Test { namespace { struct GlobalStateAcrossLibrariesGLTest: OpenGLTester { explicit GlobalStateAcrossLibrariesGLTest(); - void test(); + void magnumContext(); + void functionPointers(); }; GlobalStateAcrossLibrariesGLTest::GlobalStateAcrossLibrariesGLTest() { - addTests({&GlobalStateAcrossLibrariesGLTest::test}); + addTests({&GlobalStateAcrossLibrariesGLTest::magnumContext, + &GlobalStateAcrossLibrariesGLTest::functionPointers}); } -void GlobalStateAcrossLibrariesGLTest::test() { +void GlobalStateAcrossLibrariesGLTest::magnumContext() { #if defined(MAGNUM_BUILD_STATIC_UNIQUE_GLOBALS) && !defined(MAGNUM_BUILD_STATIC) CORRADE_VERIFY(!"MAGNUM_BUILD_STATIC_UNIQUE_GLOBALS enabled but MAGNUM_BUILD_STATIC not"); #endif @@ -55,6 +57,27 @@ void GlobalStateAcrossLibrariesGLTest::test() { } } +void GlobalStateAcrossLibrariesGLTest::functionPointers() { + #if defined(MAGNUM_BUILD_STATIC_UNIQUE_GLOBALS) && !defined(MAGNUM_BUILD_STATIC) + CORRADE_VERIFY(!"MAGNUM_BUILD_STATIC_UNIQUE_GLOBALS enabled but MAGNUM_BUILD_STATIC not"); + #endif + + CORRADE_VERIFY(glCreateProgram); + + { + #ifndef MAGNUM_BUILD_STATIC_UNIQUE_GLOBALS + CORRADE_EXPECT_FAIL("MAGNUM_BUILD_STATIC_UNIQUE_GLOBALS not enabled."); + #endif + /* Annotating the flextGL global with __attribute__((weak)) makes + static builds crash on startup due to a null function pointer call. + This is because even the GL 1.0 / 1.1 function pointers are accessed + through this struct and somehow the weak symbol makes the struct all + nulls. Not sure how to proceed. */ + CORRADE_EXPECT_FAIL("Deduplication of global GL function pointers across shared libraries isn't implemented yet."); + CORRADE_COMPARE(createProgramInALibrary(), reinterpret_cast(glCreateProgram)); + } +} + }}}} CORRADE_TEST_MAIN(Magnum::GL::Test::GlobalStateAcrossLibrariesGLTest) diff --git a/src/Magnum/GL/Test/GlobalStateAcrossLibrariesLibrary.cpp b/src/Magnum/GL/Test/GlobalStateAcrossLibrariesLibrary.cpp index 9f102c33c..2afb6a0d9 100644 --- a/src/Magnum/GL/Test/GlobalStateAcrossLibrariesLibrary.cpp +++ b/src/Magnum/GL/Test/GlobalStateAcrossLibrariesLibrary.cpp @@ -34,4 +34,8 @@ GL::Context* currentContextInALibrary() { return &GL::Context::current(); } +void* createProgramInALibrary() { + return reinterpret_cast(glCreateProgram); +} + }}} diff --git a/src/Magnum/GL/Test/GlobalStateAcrossLibrariesLibrary.h b/src/Magnum/GL/Test/GlobalStateAcrossLibrariesLibrary.h index aa4afda1a..a6ee82369 100644 --- a/src/Magnum/GL/Test/GlobalStateAcrossLibrariesLibrary.h +++ b/src/Magnum/GL/Test/GlobalStateAcrossLibrariesLibrary.h @@ -38,6 +38,7 @@ namespace Magnum { namespace GL { namespace Test { MAGNUM_GLOBALSTATEACROSSLIBRARIESLIBRARY_EXPORT GL::Context* currentContextInALibrary(); +MAGNUM_GLOBALSTATEACROSSLIBRARIESLIBRARY_EXPORT void* createProgramInALibrary(); }}}