From c49a6953b0f5cbfa2d20de4246a87efdc3b0aa52 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 5 Jan 2015 20:22:44 +0000 Subject: glretrace: Ensure we get a matching context. --- helpers/glprofile.hpp | 7 +++++++ retrace/glretrace_main.cpp | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/helpers/glprofile.hpp b/helpers/glprofile.hpp index dc35400b..1ff922cb 100644 --- a/helpers/glprofile.hpp +++ b/helpers/glprofile.hpp @@ -65,6 +65,13 @@ struct Profile { (major == refMajor && minor >= refMinor); } + inline bool + matches(const Profile expected) const { + return api == expected.api && + versionGreaterOrEqual(expected.major, expected.minor) && + core == expected.core; + } + // Comparison operator, mainly for use in std::map inline bool operator == (const Profile & other) const { diff --git a/retrace/glretrace_main.cpp b/retrace/glretrace_main.cpp index 714295f5..d60c4051 100755 --- a/retrace/glretrace_main.cpp +++ b/retrace/glretrace_main.cpp @@ -336,12 +336,26 @@ clientWaitSync(trace::Call &call, GLsync sync, GLbitfield flags, GLuint64 timeou } +/* + * Called the first time a context is made current. + */ void initContext() { glretrace::Context *currentContext = glretrace::getCurrentContext(); + assert(currentContext); + + /* Ensure we got a matching profile. + * + * In particular on MacOSX, there is no other way. + */ + glprofile::Profile expectedProfile = currentContext->wsContext->profile; + glprofile::Profile currentProfile = glprofile::getCurrentContextProfile(); + if (!currentProfile.matches(expectedProfile)) { + std::cerr << "error: bad context version: expected " << expectedProfile << ", got " << currentProfile << "\n"; + exit(1); + } /* Ensure we have adequate extension support */ - assert(currentContext); supportsTimestamp = currentContext->hasExtension("GL_ARB_timer_query"); supportsElapsed = currentContext->hasExtension("GL_EXT_timer_query") || supportsTimestamp; supportsOcclusion = currentContext->hasExtension("GL_ARB_occlusion_query"); -- cgit v1.2.3