diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-09-28 17:06:00 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-09-28 17:06:00 +0200 |
| commit | c2efb0d8494b101d9700afc79302fcf371995a6e (patch) | |
| tree | bd18b6ba6d706e2cd638a45fee43dce61a92af60 /src | |
| parent | 7d58e2385452b8373448e3f91013a8cda39c7aa3 (diff) | |
macOS: support of FLTK widgets in OpenGL 3 windows - cont'd.
This code is OK under macOS 10 9 and 13.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_cocoa.mm | 16 | ||||
| -rw-r--r-- | src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H | 3 | ||||
| -rw-r--r-- | src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx | 34 | ||||
| -rw-r--r-- | src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H | 5 |
4 files changed, 44 insertions, 14 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 9cb302dcb..ccb4ebe81 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -2941,25 +2941,29 @@ NSOpenGLContext* Fl_Cocoa_Window_Driver::create_GLcontext_for_window(NSOpenGLPix } -NSOpenGLContext *Fl_Cocoa_Window_Driver::gl1ctxt_create() { +NSOpenGLContext *Fl_Cocoa_Window_Driver::gl1ctxt_create(NSView **gl1view) { FLView *view = (FLView*)[fl_xid(pWindow) contentView]; - NSView *gl1view = [[NSView alloc] initWithFrame:[view frame]]; - [view addSubview:gl1view]; - [gl1view release]; + *gl1view = [[NSView alloc] initWithFrame:[view frame]]; NSOpenGLPixelFormat *gl1pixelformat = Fl_Cocoa_Window_Driver::mode_to_NSOpenGLPixelFormat( FL_RGB8 | FL_ALPHA | FL_SINGLE, NULL); NSOpenGLContext *gl1ctxt = [[NSOpenGLContext alloc] initWithFormat:gl1pixelformat shareContext:nil]; [gl1pixelformat release]; - remove_gl_context_opacity(gl1ctxt); + return gl1ctxt; +} + +void Fl_Cocoa_Window_Driver::gl1ctxt_add(NSOpenGLContext *gl1ctxt, NSView *gl1view) { + FLView *flview = (FLView*)[fl_xid(pWindow) contentView]; + [flview addSubview:gl1view]; + [gl1view release]; #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_7 if (fl_mac_os_version >= 100700 && Fl::use_high_res_GL()) { [gl1view setWantsBestResolutionOpenGLSurface:YES]; } #endif [gl1ctxt setView:gl1view]; - return gl1ctxt; + remove_gl_context_opacity(gl1ctxt); } diff --git a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H index e1a8dabb3..f0456eec9 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H +++ b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H @@ -28,9 +28,9 @@ class Fl_Gl_Choice; class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver { NSOpenGLContext *gl1ctxt; // GL1 context in addition to GL3 context + static void delayed_addgl1ctxt(void *data); friend Fl_Gl_Window_Driver* Fl_Gl_Window_Driver::newGlWindowDriver(Fl_Gl_Window *); Fl_Cocoa_Gl_Window_Driver(Fl_Gl_Window *win); - ~Fl_Cocoa_Gl_Window_Driver(); virtual float pixels_per_unit(); virtual void before_show(int& need_after); virtual void after_show(); @@ -53,6 +53,7 @@ class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver { void apply_scissor(); virtual void switch_to_GL1(); virtual void switch_back(); + virtual void gl_hide_before(void *&); }; diff --git a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx index 7a20a7536..bb4c53df1 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx +++ b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx @@ -53,10 +53,6 @@ Fl_Cocoa_Gl_Window_Driver::Fl_Cocoa_Gl_Window_Driver(Fl_Gl_Window *win) : gl1ctxt = NULL; } -Fl_Cocoa_Gl_Window_Driver::~Fl_Cocoa_Gl_Window_Driver() { - if (gl1ctxt) Fl_Cocoa_Window_Driver::GLcontext_release(gl1ctxt); -} - Fl_Gl_Choice *Fl_Cocoa_Gl_Window_Driver::find(int m, const int *alistp) { Fl::screen_driver()->open_display(); // useful when called through gl_start() @@ -331,12 +327,31 @@ FL_EXPORT NSOpenGLContext *fl_mac_glcontext(GLContext rc) { view/GL context. */ +static struct win_view { + Fl_Gl_Window *win; + NSView *gl1view; + NSOpenGLContext *gl1ctxt; +} win_view_struct; + +void Fl_Cocoa_Gl_Window_Driver::delayed_addgl1ctxt(void *d) { + struct win_view *data = (struct win_view *)d; + Fl_Cocoa_Window_Driver::driver(data->win)->gl1ctxt_add(data->gl1ctxt, data->gl1view); + data->win->redraw(); +} + void Fl_Cocoa_Gl_Window_Driver::switch_to_GL1() { if (!gl1ctxt) { - gl1ctxt = Fl_Cocoa_Window_Driver::driver(pWindow)->gl1ctxt_create(); - Fl::add_timeout(0.01, (Fl_Timeout_Handler)delayed_redraw, pWindow); + gl1ctxt = Fl_Cocoa_Window_Driver::driver(pWindow)->gl1ctxt_create( + &win_view_struct.gl1view); + win_view_struct.win = pWindow; + win_view_struct.gl1ctxt = gl1ctxt; + Fl::add_timeout(0.01, + Fl_Cocoa_Gl_Window_Driver::delayed_addgl1ctxt, + &win_view_struct); } Fl_Cocoa_Window_Driver::GLcontext_makecurrent(gl1ctxt); + glClearColor(0., 0., 0., 0.); + glClear(GL_COLOR_BUFFER_BIT); } void Fl_Cocoa_Gl_Window_Driver::switch_back() { @@ -344,6 +359,13 @@ void Fl_Cocoa_Gl_Window_Driver::switch_back() { Fl_Cocoa_Window_Driver::GLcontext_makecurrent((NSOpenGLContext*)pWindow->context()); } +void Fl_Cocoa_Gl_Window_Driver::gl_hide_before(void *&) { + if (gl1ctxt) { + Fl_Cocoa_Window_Driver::GLcontext_release(gl1ctxt); + gl1ctxt = 0; + } +} + class Fl_Gl_Cocoa_Plugin : public Fl_Cocoa_Plugin { public: diff --git a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H index d6f7534c2..16cea4e67 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H +++ b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H @@ -36,6 +36,7 @@ class Fl_Window; @class FLWindow; @class NSOpenGLContext; @class NSOpenGLPixelFormat; +@class NSView; #else class CALayer; class NSCursor; @@ -43,6 +44,7 @@ class NSImage; class FLWindow; class NSOpenGLContext; class NSOpenGLPixelFormat; +class NSView; #endif // __OBJC__ /** @@ -155,7 +157,8 @@ public: static void GL_cleardrawable(void); // uses Objective-c static void gl_start(NSOpenGLContext*); // uses Objective-c static void remove_gl_context_opacity(NSOpenGLContext*); // uses Objective-c - NSOpenGLContext *gl1ctxt_create(); // uses Objective-c + NSOpenGLContext *gl1ctxt_create(NSView **); // uses Objective-c + void gl1ctxt_add(NSOpenGLContext*, NSView*); // uses Objective-c static void gl1ctxt_resize(NSOpenGLContext*); // uses Objective-c //icons |
