Skip to content

Commit

Permalink
tests: cleanup OpenGL in the rest runner
Browse files Browse the repository at this point in the history
  • Loading branch information
aras-p committed Apr 13, 2013
1 parent f426775 commit ab96570
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions tests/hlsl2glsltest/hlsl2glsltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

0 comments on commit ab96570

Please sign in to comment.