summaryrefslogtreecommitdiff
path: root/src/Fl_Gl_Choice.cxx
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2014-12-20 07:19:23 +0000
committerManolo Gouy <Manolo>2014-12-20 07:19:23 +0000
commitf3a84c0ee5f88fe664d759106724f786c706f817 (patch)
tree3541953164e2d24c31ae46ef11f2c2e86b3873a3 /src/Fl_Gl_Choice.cxx
parenta7dc3ea9e24399f318a9478fbcffe04ff2870de6 (diff)
Changed OpenGL support for the Mac OS X platform: use cocoa instead of deprecated AGL.
All changes are mac-specific, except a very minor change in file src/gl_draw.cxx where string drawing wrongly claimed to support @symbol, not possible because symbols are drawn using non-GL primitives. Unchanged application code can use the new FLTK code. In addition, the new code allows mac applications to draw OpenGL scenes at high resolution on so-called 'retina' displays, but this requires some support from app code. They must call, before opening GL windows, Fl::use_high_resolution(1); and change their glViewport() calls as follows glViewport(0, 0, pxel_w(), pixel_h()); This uses 2 new member functions of the Fl_Gl_Window class, pixel_w() and pixel_h() returning the window dimensions in pixel units, that is, twice the w() and h() when the window is mapped on a retina display. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10498 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Gl_Choice.cxx')
-rw-r--r--src/Fl_Gl_Choice.cxx114
1 files changed, 10 insertions, 104 deletions
diff --git a/src/Fl_Gl_Choice.cxx b/src/Fl_Gl_Choice.cxx
index 45fbc4bfc..3ed89cee7 100644
--- a/src/Fl_Gl_Choice.cxx
+++ b/src/Fl_Gl_Choice.cxx
@@ -28,8 +28,11 @@
# include <FL/fl_utf8.h>
# ifdef __APPLE__
-# include <ApplicationServices/ApplicationServices.h>
-# include <FL/Fl_Window.H>
+extern NSOpenGLContext* gl_create_context_for_window(NSOpenGLPixelFormat *pixelformat,
+ NSOpenGLContext *shared_ctx, Fl_Window *window);
+extern void gl_context_release(NSOpenGLContext*);
+extern void gl_context_makecurrent(NSOpenGLContext*);
+extern void gl_cleardrawable(void);
# endif
# ifdef WIN32
@@ -108,53 +111,7 @@ Fl_Gl_Choice *Fl_Gl_Choice::find(int m, const int *alistp) {
}
#elif defined(__APPLE_QUARTZ__)
- // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
- const int *blist;
- int list[32];
-
- if (alistp)
- blist = alistp;
- else {
- int n = 0;
- if (m & FL_INDEX) {
- list[n++] = AGL_BUFFER_SIZE;
- list[n++] = 8; // glut tries many sizes, but this should work...
- } else {
- list[n++] = AGL_RGBA;
- list[n++] = AGL_GREEN_SIZE;
- list[n++] = (m & FL_RGB8) ? 8 : 1;
- if (m & FL_ALPHA) {
- list[n++] = AGL_ALPHA_SIZE;
- list[n++] = (m & FL_RGB8) ? 8 : 1;
- }
- if (m & FL_ACCUM) {
- list[n++] = AGL_ACCUM_GREEN_SIZE;
- list[n++] = 1;
- if (m & FL_ALPHA) {
- list[n++] = AGL_ACCUM_ALPHA_SIZE;
- list[n++] = 1;
- }
- }
- }
- if (m & FL_DOUBLE) {
- list[n++] = AGL_DOUBLEBUFFER;
- }
- if (m & FL_DEPTH) {
- list[n++] = AGL_DEPTH_SIZE; list[n++] = 24;
- }
- if (m & FL_STENCIL) {
- list[n++] = AGL_STENCIL_SIZE; list[n++] = 1;
- }
-# ifdef AGL_STEREO
- if (m & FL_STEREO) {
- list[n++] = AGL_STEREO;
- }
-# endif
- list[n] = AGL_NONE;
- blist = list;
- }
- fl_open_display();
- AGLPixelFormat fmt = aglChoosePixelFormat(NULL, 0, (GLint*)blist);
+ NSOpenGLPixelFormat* fmt = Fl_X::mode_to_NSOpenGLPixelFormat(m, alistp);
if (!fmt) return 0;
#elif defined(WIN32)
@@ -216,7 +173,6 @@ Fl_Gl_Choice *Fl_Gl_Choice::find(int m, const int *alistp) {
g->pixelformat = pixelformat;
g->pfd = chosen_pfd;
# elif defined(__APPLE_QUARTZ__)
- // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
g->pixelformat = fmt;
# else
# error unsupported platform
@@ -287,38 +243,13 @@ GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int lay
}
# elif defined(__APPLE_QUARTZ__)
-#if !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 && __LP64__)
-static CGrafPtr fl_GetWindowPort(WindowRef window)
-{
- typedef CGrafPtr (*wf)(WindowRef);
- static wf f = NULL;
- if ( ! f) f = (wf)Fl_X::get_carbon_function("GetWindowPort");
- return (*f)(window);
-}
-#endif
-// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer) {
GLContext context, shared_ctx = 0;
if (context_list && nContext) shared_ctx = context_list[0];
- context = aglCreateContext( g->pixelformat, shared_ctx);
+ context = gl_create_context_for_window(g->pixelformat, shared_ctx, window);
if (!context) return 0;
add_context((GLContext)context);
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
-#if __LP64__
- // 64 bit version
- aglSetWindowRef(context, Fl_X::i(window)->window_ref() );
-#else
- // 32 bit version >= 10.5
- if (aglSetWindowRef != NULL)
- aglSetWindowRef(context, Fl_X::i(window)->window_ref() );
- else
- aglSetDrawable( context, fl_GetWindowPort( Fl_X::i(window)->window_ref() ) );
-#endif
-#else
- // 32 bit version < 10.5
- aglSetDrawable( context, fl_GetWindowPort( Fl_X::i(window)->window_ref() ) );
-#endif
return (context);
}
# else
@@ -337,23 +268,7 @@ void fl_set_gl_context(Fl_Window* w, GLContext context) {
# elif defined(WIN32)
wglMakeCurrent(Fl_X::i(w)->private_dc, context);
# elif defined(__APPLE_QUARTZ__)
- // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
-#if __LP64__
- // 64 bit version
- aglSetWindowRef(context, Fl_X::i(w)->window_ref() );
-#else
- // 32 bit version >= 10.5
- if (aglSetWindowRef != NULL)
- aglSetWindowRef(context, Fl_X::i(w)->window_ref() );
- else
- aglSetDrawable( context, fl_GetWindowPort( Fl_X::i(w)->window_ref() ) );
-#endif
-#else
- // 32 bit version < 10.5
- aglSetDrawable( context, fl_GetWindowPort( Fl_X::i(w)->window_ref() ) );
-#endif
- aglSetCurrentContext(context);
+ gl_context_makecurrent(context);
# else
# error unsupported platform
# endif
@@ -368,15 +283,7 @@ void fl_no_gl_context() {
# elif defined(WIN32)
wglMakeCurrent(0, 0);
# elif defined(__APPLE_QUARTZ__)
- // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
- AGLContext ctx = aglGetCurrentContext();
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
- if (aglSetWindowRef != NULL)
- { if(ctx) aglSetWindowRef(ctx, NULL ); }
- else
-#endif
- if(ctx) aglSetDrawable( ctx, NULL );
- aglSetCurrentContext(0);
+ gl_cleardrawable();
# else
# error unsupported platform
# endif
@@ -389,8 +296,7 @@ void fl_delete_gl_context(GLContext context) {
# elif defined(WIN32)
wglDeleteContext(context);
# elif defined(__APPLE_QUARTZ__)
- // warning: the Quartz version should probably use Core GL (CGL) instead of AGL
- aglDestroyContext( context );
+ gl_context_release(context);
# else
# error unsupported platform
# endif