summaryrefslogtreecommitdiff
path: root/src/drivers/Cocoa
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-09-28 17:06:00 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2022-09-28 17:06:00 +0200
commitc2efb0d8494b101d9700afc79302fcf371995a6e (patch)
treebd18b6ba6d706e2cd638a45fee43dce61a92af60 /src/drivers/Cocoa
parent7d58e2385452b8373448e3f91013a8cda39c7aa3 (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/drivers/Cocoa')
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H3
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx34
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H5
3 files changed, 34 insertions, 8 deletions
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