From ab9657070b1a688e67c8aa2e05321b4fbf77fffe Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Sat, 13 Apr 2013 18:33:46 +0300 Subject: [PATCH] tests: cleanup OpenGL in the rest runner --- tests/hlsl2glsltest/hlsl2glsltest.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/hlsl2glsltest/hlsl2glsltest.cpp b/tests/hlsl2glsltest/hlsl2glsltest.cpp index 5bdb1a9..85102f2 100644 --- a/tests/hlsl2glsltest/hlsl2glsltest.cpp +++ b/tests/hlsl2glsltest/hlsl2glsltest.cpp @@ -164,6 +164,13 @@ static bool ReadStringFromFile (const char* pathName, std::string& output) return true; } + +#if defined(__APPLE__) +static AGLPixelFormat s_GLPixelFormat; +static AGLContext s_GLContext; +#endif + + static bool InitializeOpenGL () { bool hasGLSL = false; @@ -204,9 +211,9 @@ static bool InitializeOpenGL () attributes[i++]=AGL_NO_RECOVERY; attributes[i++]=AGL_NONE; - AGLPixelFormat pixelFormat = aglChoosePixelFormat(NULL,0,attributes); - AGLContext agl = aglCreateContext(pixelFormat, NULL); - aglSetCurrentContext (agl); + s_GLPixelFormat = aglChoosePixelFormat(NULL,0,attributes); + s_GLContext = aglCreateContext(s_GLPixelFormat, NULL); + aglSetCurrentContext (s_GLContext); #else int argc = 0; char** argv = NULL; @@ -235,6 +242,18 @@ static bool InitializeOpenGL () return hasGLSL; } +static void CleanupOpenGL() +{ + #if defined(__APPLE__) + if (s_GLContext) + { + aglSetCurrentContext (NULL); + aglDestroyContext (s_GLContext); + aglDestroyPixelFormat(s_GLPixelFormat); + } + #endif +} + static void replace_string (std::string& target, const std::string& search, const std::string& replace, size_t startPos) { @@ -635,6 +654,7 @@ int main (int argc, const char** argv) printf ("%i tests succeeded, %.2fs\n", (int)tests, t); Hlsl2Glsl_Shutdown(); + CleanupOpenGL(); return errors ? 1 : 0; }