Skip to content

Commit

Permalink
glretrace: Support MacOSX 4.1 contexts.
Browse files Browse the repository at this point in the history
Not really tested but it should hopefully work.
  • Loading branch information
jrfonseca committed Oct 29, 2013
1 parent 1369beb commit 797901b
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 52 deletions.
6 changes: 6 additions & 0 deletions retrace/d3dretrace_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
#include "d3dretrace.hpp"


void
retrace::setFeatureLevel(const char *featureLevel) {
/* TODO: Allow to override D3D feature level. */
}


void
retrace::setUp(void) {
}
Expand Down
2 changes: 2 additions & 0 deletions retrace/glretrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ struct Context {
}
};

extern glws::Profile defaultProfile;

extern bool insideList;
extern bool insideGlBeginEnd;
extern bool supportsARBShaderObjects;
Expand Down
29 changes: 25 additions & 4 deletions retrace/glretrace_cgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@


#define kCGLPFAAllRenderers 1
#define kCGLPFATripleBuffer 3
#define kCGLPFADoubleBuffer 5
#define kCGLPFAStereo 6
#define kCGLPFAAuxBuffers 7
Expand All @@ -58,6 +59,7 @@
#define kCGLPFAClosestPolicy 74
#define kCGLPFARobust 75
#define kCGLPFABackingStore 76
#define kCGLPFABackingVolatile 77
#define kCGLPFAMPSafe 78
#define kCGLPFAWindow 80
#define kCGLPFAMultiScreen 81
Expand All @@ -68,10 +70,13 @@
#define kCGLPFAAllowOfflineRenderers 96
#define kCGLPFAAcceleratedCompute 97
#define kCGLPFAOpenGLProfile 99
#define kCGLPFASupportsAutomaticGraphicsSwitching 101
#define kCGLPFAVirtualScreenCount 128

#define kCGLOGLPVersion_Legacy 0x1000
#define kCGLOGLPVersion_3_2_Core 0x3200
#define kCGLOGLPVersion_GL3_Core 0x3200
#define kCGLOGLPVersion_GL4_Core 0x4100


using namespace glretrace;
Expand Down Expand Up @@ -125,7 +130,7 @@ getContext(unsigned long long ctx) {


static void retrace_CGLChoosePixelFormat(trace::Call &call) {
int profile = kCGLOGLPVersion_Legacy;
int profile = 0;

const trace::Array * attribs = call.arg(0).toArray();
if (attribs) {
Expand All @@ -138,6 +143,7 @@ static void retrace_CGLChoosePixelFormat(trace::Call &call) {

switch (param) {
case kCGLPFAAllRenderers:
case kCGLPFATripleBuffer:
case kCGLPFADoubleBuffer:
case kCGLPFAStereo:
case kCGLPFAAuxBuffers:
Expand All @@ -156,6 +162,7 @@ static void retrace_CGLChoosePixelFormat(trace::Call &call) {
case kCGLPFAClosestPolicy:
case kCGLPFARobust:
case kCGLPFABackingStore:
case kCGLPFABackingVolatile:
case kCGLPFAMPSafe:
case kCGLPFAWindow:
case kCGLPFAMultiScreen:
Expand All @@ -164,6 +171,7 @@ static void retrace_CGLChoosePixelFormat(trace::Call &call) {
case kCGLPFARemotePBuffer:
case kCGLPFAAllowOfflineRenderers:
case kCGLPFAAcceleratedCompute:
case kCGLPFASupportsAutomaticGraphicsSwitching:
break;

case kCGLPFAColorSize:
Expand All @@ -190,9 +198,22 @@ static void retrace_CGLChoosePixelFormat(trace::Call &call) {
}
}

if (profile == kCGLOGLPVersion_3_2_Core) {
// TODO: Do this on a per visual basis
retrace::coreProfile = true;
// TODO: Do this on a per visual basis
switch (profile) {
case 0:
break;
case kCGLOGLPVersion_Legacy:
glretrace::defaultProfile = glws::PROFILE_COMPAT;
break;
case kCGLOGLPVersion_GL3_Core:
glretrace::defaultProfile = glws::PROFILE_3_2_CORE;
break;
case kCGLOGLPVersion_GL4_Core:
glretrace::defaultProfile = glws::PROFILE_4_1_CORE;
break;
default:
retrace::warning(call) << "unexpected opengl profile " << std::hex << profile << std::dec << "\n";
break;
}
}

Expand Down
9 changes: 9 additions & 0 deletions retrace/glretrace_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

namespace glretrace {

glws::Profile defaultProfile = glws::PROFILE_COMPAT;

bool insideList = false;
bool insideGlBeginEnd = false;
bool supportsARBShaderObjects = false;
Expand Down Expand Up @@ -450,6 +452,13 @@ class GLDumper : public retrace::Dumper {
static GLDumper glDumper;


void
retrace::setFeatureLevel(const char *featureLevel)
{
glretrace::defaultProfile = glws::PROFILE_3_2_CORE;
}


void
retrace::setUp(void) {
glws::init();
Expand Down
17 changes: 3 additions & 14 deletions retrace/glretrace_ws.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ getVisual(glws::Profile profile) {
}


inline glws::Profile
getDefaultProfile(void)
{
if (retrace::coreProfile) {
return glws::PROFILE_CORE;
} else {
return glws::PROFILE_COMPAT;
}
}


static glws::Drawable *
createDrawableHelper(glws::Profile profile, int width = 32, int height = 32, bool pbuffer = false) {
glws::Visual *visual = getVisual(profile);
Expand All @@ -91,13 +80,13 @@ createDrawable(glws::Profile profile) {

glws::Drawable *
createDrawable(void) {
return createDrawable(getDefaultProfile());
return createDrawable(defaultProfile);
}


glws::Drawable *
createPbuffer(int width, int height) {
return createDrawableHelper(getDefaultProfile(), width, height, true);
return createDrawableHelper(defaultProfile, width, height, true);
}


Expand All @@ -118,7 +107,7 @@ createContext(Context *shareContext, glws::Profile profile) {

Context *
createContext(Context *shareContext) {
return createContext(shareContext, getDefaultProfile());
return createContext(shareContext, defaultProfile);
}


Expand Down
2 changes: 1 addition & 1 deletion retrace/glws.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Drawable::copySubBuffer(int x, int y, int width, int height) {
bool
Context::hasExtension(const char *string) {
if (extensions.empty()) {
if (profile == PROFILE_CORE) {
if (isCoreProfile(profile)) {
// Use glGetStringi
GLint num_extensions = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
Expand Down
9 changes: 8 additions & 1 deletion retrace/glws.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ namespace glws {

enum Profile {
PROFILE_COMPAT = 0,
PROFILE_CORE,
PROFILE_3_2_CORE,
PROFILE_4_1_CORE,
PROFILE_ES1,
PROFILE_ES2,
PROFILE_MAX
};


static inline bool
isCoreProfile(Profile profile) {
return profile == PROFILE_3_2_CORE ||
profile == PROFILE_4_1_CORE;
}

bool
checkExtension(const char *extName, const char *extString);

Expand Down
29 changes: 14 additions & 15 deletions retrace/glws_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void swapBuffers(void) {
bool isMultiThreaded = [NSThread isMultiThreaded];
if (!isMultiThreaded) {
std::cerr << "error: failed to enable Cocoa multi-threading\n";
exit(1);
exit(1);
}

[NSApplication sharedApplication];
Expand All @@ -223,11 +223,6 @@ void swapBuffers(void) {

initThread();

if (profile != PROFILE_COMPAT &&
profile != PROFILE_CORE) {
return nil;
}

Attributes<NSOpenGLPixelFormatAttribute> attribs;

attribs.add(NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)1);
Expand All @@ -237,12 +232,21 @@ void swapBuffers(void) {
}
attribs.add(NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)1);
attribs.add(NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)1);
if (profile == PROFILE_CORE) {
#if CGL_VERSION_1_3
switch (profile) {
case PROFILE_COMPAT:
break;
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
case PROFILE_3_2_CORE:
attribs.add(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
#else
return NULL;
break;
#endif
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
case PROFILE_4_1_CORE:
attribs.add(NSOpenGLPFAOpenGLProfile, kCGLOGLPVersion_GL4_Core);
break;
#endif
default:
return NULL;
}

// Use Apple software rendering for debugging purposes.
Expand Down Expand Up @@ -275,11 +279,6 @@ void swapBuffers(void) {
NSOpenGLContext *share_context = nil;
NSOpenGLContext *context;

if (profile != PROFILE_COMPAT &&
profile != PROFILE_CORE) {
return nil;
}

if (shareContext) {
share_context = static_cast<CocoaContext*>(shareContext)->context;
}
Expand Down
3 changes: 2 additions & 1 deletion retrace/glws_egl_xlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@ createContext(const Visual *_visual, Context *shareContext, Profile profile, boo
load("libGL.so.1");
eglBindAPI(EGL_OPENGL_API);
break;
case PROFILE_CORE:
case PROFILE_3_2_CORE:
case PROFILE_4_1_CORE:
assert(0);
return NULL;
case PROFILE_ES1:
Expand Down
12 changes: 8 additions & 4 deletions retrace/glws_glx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ cleanup(void) {
Visual *
createVisual(bool doubleBuffer, Profile profile) {
if (profile != PROFILE_COMPAT &&
profile != PROFILE_CORE &&
profile != PROFILE_3_2_CORE &&
profile != PROFILE_4_1_CORE &&
profile != PROFILE_ES2) {
return NULL;
}
Expand Down Expand Up @@ -352,13 +353,16 @@ createContext(const Visual *_visual, Context *shareContext, Profile profile, boo
case PROFILE_ES2:
attribs.add(GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT);
break;
case PROFILE_CORE:
// XXX: This will invariable return a 3.2 context, when supported.
// We probably should have a PROFILE_CORE_XX per version.
case PROFILE_3_2_CORE:
attribs.add(GLX_CONTEXT_MAJOR_VERSION_ARB, 3);
attribs.add(GLX_CONTEXT_MINOR_VERSION_ARB, 2);
attribs.add(GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB);
break;
case PROFILE_4_1_CORE:
attribs.add(GLX_CONTEXT_MAJOR_VERSION_ARB, 4);
attribs.add(GLX_CONTEXT_MINOR_VERSION_ARB, 1);
attribs.add(GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB);
break;
default:
return NULL;
}
Expand Down
16 changes: 7 additions & 9 deletions retrace/glws_wgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ cleanup(void) {
Visual *
createVisual(bool doubleBuffer, Profile profile) {
if (profile != PROFILE_COMPAT &&
profile != PROFILE_CORE &&
profile != PROFILE_3_2_CORE &&
profile != PROFILE_4_1_CORE &&
profile != PROFILE_ES2) {
return NULL;
}
Expand All @@ -325,21 +326,18 @@ createDrawable(const Visual *visual, int width, int height, bool pbuffer)
Context *
createContext(const Visual *visual, Context *shareContext, Profile profile, bool debug)
{
if (profile != PROFILE_COMPAT &&
profile != PROFILE_CORE &&
profile != PROFILE_ES2) {
return NULL;
}

switch (profile) {
case PROFILE_CORE:
case PROFILE_COMPAT:
break;
case PROFILE_3_2_CORE:
case PROFILE_4_1_CORE:
std::cerr << "warning: ignoring OpenGL core profile request\n";
break;
case PROFILE_ES2:
std::cerr << "warning: ignoring OpenGL ES 2.0 profile request\n";
break;
default:
break;
return NULL;
}

return new WglContext(visual, profile, static_cast<WglContext *>(shareContext));
Expand Down
4 changes: 3 additions & 1 deletion retrace/retrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ extern Driver driver;
extern const char *driverModule;

extern bool doubleBuffer;
extern bool coreProfile;

extern unsigned frameNo;
extern unsigned callNo;
Expand Down Expand Up @@ -187,6 +186,9 @@ class Dumper
extern Dumper *dumper;


void
setFeatureLevel(const char *featureLevel);

void
setUp(void);

Expand Down
3 changes: 1 addition & 2 deletions retrace/retrace_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ Driver driver = DRIVER_DEFAULT;
const char *driverModule = NULL;

bool doubleBuffer = true;
bool coreProfile = false;

bool profiling = false;
bool profilingGpuTimes = false;
Expand Down Expand Up @@ -646,7 +645,7 @@ int main(int argc, char **argv)
retrace::verbosity = -2;
break;
case CORE_OPT:
retrace::coreProfile = true;
retrace::setFeatureLevel("3_2_core");
break;
case DB_OPT:
retrace::doubleBuffer = true;
Expand Down

0 comments on commit 797901b

Please sign in to comment.