FLTK logo

Re: [fltk.coredev] GL root Fl_Gl_Window::draw

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.coredev  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: GL root Fl_Gl_Window::draw Manolo Sep 28, 2022  
 
Ian: would you, please, try with this patch (after a git pull) ?
patch -p1 < switch2GL1attempt.patch.txt

--
You received this message because you are subscribed to the Google Groups "fltk.coredev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkcoredev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkcoredev/76638c37-a076-4b68-bd48-40dfe21ec48fn%40googlegroups.com.
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 9cb302dcb..be8b24681 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -2944,8 +2944,6 @@ - (void)draggingSession:(NSDraggingSession *)session
 NSOpenGLContext *Fl_Cocoa_Window_Driver::gl1ctxt_create() {
   FLView *view = (FLView*)[fl_xid(pWindow) contentView];
   NSView *gl1view = [[NSView alloc] initWithFrame:[view frame]];
-  [view addSubview:gl1view];
-  [gl1view release];
   NSOpenGLPixelFormat *gl1pixelformat =
       Fl_Cocoa_Window_Driver::mode_to_NSOpenGLPixelFormat(
                               FL_RGB8 | FL_ALPHA | FL_SINGLE, NULL);
@@ -2962,6 +2960,12 @@ - (void)draggingSession:(NSDraggingSession *)session
   return gl1ctxt;
 }
 
+void Fl_Cocoa_Window_Driver::gl1ctxt_add(NSOpenGLContext *gl1ctxt) {
+  FLView *flview = (FLView*)[fl_xid(pWindow) contentView];
+  NSView *gl1view = [gl1ctxt view];
+  [flview addSubview:gl1view];
+  [gl1view release];
+}
 
 void Fl_Cocoa_Window_Driver::gl1ctxt_resize(NSOpenGLContext *ctxt) {
   [[ctxt view] setFrame:[[[ctxt view] superview] frame]];
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H
index e1a8dabb3..b3f6de017 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H
+++ b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.H
@@ -28,6 +28,7 @@ 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(Fl_Gl_Window *win);
   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();
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx
index 7a20a7536..1034d517c 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx
+++ b/src/drivers/Cocoa/Fl_Cocoa_Gl_Window_Driver.cxx
@@ -331,10 +331,18 @@ FL_EXPORT NSOpenGLContext *fl_mac_glcontext(GLContext rc) {
  view/GL context.
  */
 
+void Fl_Cocoa_Gl_Window_Driver::delayed_addgl1ctxt(Fl_Gl_Window *win) {
+  Fl_Cocoa_Gl_Window_Driver *gldr = (Fl_Cocoa_Gl_Window_Driver*)Fl_Gl_Window_Driver::driver(win);
+  Fl_Cocoa_Window_Driver::driver(win)->gl1ctxt_add(gldr->gl1ctxt);
+  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);
+    Fl::add_timeout(0.01,
+            (Fl_Timeout_Handler)Fl_Cocoa_Gl_Window_Driver::delayed_addgl1ctxt,
+            pWindow);
   }
   Fl_Cocoa_Window_Driver::GLcontext_makecurrent(gl1ctxt);
 }
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
index d6f7534c2..a430f2c18 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
+++ b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H
@@ -156,6 +156,7 @@ public:
   static void gl_start(NSOpenGLContext*); // uses Objective-c
   static void remove_gl_context_opacity(NSOpenGLContext*); // uses Objective-c
   NSOpenGLContext *gl1ctxt_create(); // uses Objective-c
+  void gl1ctxt_add(NSOpenGLContext*); // uses Objective-c
   static void gl1ctxt_resize(NSOpenGLContext*); // uses Objective-c
 
   //icons
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.