macOS: simpler handling of GL windows when first displayed.

tested on macOS versions 10.3, 10.6, 10.9, 10.14
This commit is contained in:
ManoloFLTK 2019-04-19 13:03:49 +02:00
parent 698fe39ff1
commit ebbee5301b
4 changed files with 23 additions and 27 deletions

View File

@ -72,7 +72,7 @@ int Fl_Gl_Window::can_do(int a, const int *b) {
}
void Fl_Gl_Window::show() {
int need_redraw = 0;
int need_after = 0;
if (!shown()) {
if (!g) {
g = pGlWindowDriver->find(mode_,alist);
@ -86,10 +86,10 @@ void Fl_Gl_Window::show() {
return;
}
}
pGlWindowDriver->before_show(need_redraw);
pGlWindowDriver->before_show(need_after);
}
Fl_Window::show();
pGlWindowDriver->after_show(need_redraw);
if (need_after) pGlWindowDriver->after_show();
}
@ -513,13 +513,13 @@ Fl_Gl_Window_Driver *Fl_Gl_Window_Driver::newGlWindowDriver(Fl_Gl_Window *w)
return new Fl_Cocoa_Gl_Window_Driver(w);
}
void Fl_Cocoa_Gl_Window_Driver::before_show(int& need_redraw) {
if( ! pWindow->parent() ) need_redraw=1;
void Fl_Cocoa_Gl_Window_Driver::before_show(int& need_after) {
need_after = 1;
}
void Fl_Cocoa_Gl_Window_Driver::after_show(int need_redraw) {
pWindow->set_visible();
if(need_redraw) pWindow->redraw();//necessary only after creation of a top-level GL window
void Fl_Cocoa_Gl_Window_Driver::after_show() {
// Makes sure the GL context is created to avoid drawing twice the window when first shown
pWindow->make_current();
}
float Fl_Cocoa_Gl_Window_Driver::pixels_per_unit()
@ -703,7 +703,7 @@ Fl_Gl_Window_Driver *Fl_Gl_Window_Driver::newGlWindowDriver(Fl_Gl_Window *w)
return new Fl_X11_Gl_Window_Driver(w);
}
void Fl_X11_Gl_Window_Driver::before_show(int& need_redraw) {
void Fl_X11_Gl_Window_Driver::before_show(int&) {
Fl_X::make_xid(pWindow, g()->vis, g()->colormap);
if (overlay() && overlay() != pWindow) ((Fl_Gl_Window*)overlay())->show();
}

View File

@ -52,8 +52,8 @@ public:
static Fl_Gl_Window_Driver *newGlWindowDriver(Fl_Gl_Window *w);
static Fl_Gl_Window_Driver *global();
virtual float pixels_per_unit() {return 1;}
virtual void before_show(int& need_redraw) {}
virtual void after_show(int need_redraw) {}
virtual void before_show(int& need_after) {}
virtual void after_show() {}
virtual void invalidate();
virtual int mode_(int m, const int *a) {return 0;}
virtual void make_current_before() {}
@ -105,8 +105,8 @@ class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver {
friend class Fl_OpenGL_Display_Device;
Fl_Cocoa_Gl_Window_Driver(Fl_Gl_Window *win) : Fl_Gl_Window_Driver(win) {}
virtual float pixels_per_unit();
virtual void before_show(int& need_redraw);
virtual void after_show(int need_redraw);
virtual void before_show(int& need_after);
virtual void after_show();
virtual int mode_(int m, const int *a);
virtual void make_current_before();
virtual void swap_buffers();
@ -161,7 +161,7 @@ class Fl_X11_Gl_Window_Driver : public Fl_Gl_Window_Driver {
friend class Fl_Gl_Window_Driver;
Fl_X11_Gl_Window_Driver(Fl_Gl_Window *win) : Fl_Gl_Window_Driver(win) {}
virtual float pixels_per_unit();
virtual void before_show(int& need_redraw);
virtual void before_show(int& need_after);
virtual int mode_(int m, const int *a);
virtual void swap_buffers();
virtual void resize(int is_a_resize, int w, int h);

View File

@ -2186,10 +2186,6 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
Fl_Cocoa_Window_Driver *d = Fl_Cocoa_Window_Driver::driver(window);
[self did_view_resolution_change];
if (d->wait_for_expose_value) { // 1st drawing of layer-backed GL window
Fl_Device_Plugin *plugin = Fl_Device_Plugin::opengl_plugin();
if (plugin) {
[plugin->context(window) update]; // layer-backed GL windows may be empty without this
}
d->wait_for_expose_value = 0;
}
window->clear_damage(FL_DAMAGE_ALL);
@ -2336,13 +2332,6 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
through_drawRect = YES;
Fl_Cocoa_Window_Driver *d = Fl_Cocoa_Window_Driver::driver(window);
[self did_view_resolution_change];
if (window->as_gl_window() && d->wait_for_expose_value) { // 1st drawing of GL window
Fl_Device_Plugin *plugin = Fl_Device_Plugin::opengl_plugin();
if (plugin) {
[plugin->context(window) update]; // GL windows may be empty without this
}
}
d->wait_for_expose_value = 0;
Fl_X *i = Fl_X::i(window);
if ( i->region ) {
@ -3661,6 +3650,7 @@ int Fl_Darwin_System_Driver::clipboard_contains(const char *type) {
}
void Fl_Cocoa_Window_Driver::destroy(FLWindow *xid) {
[[xid parentWindow] removeChildWindow:xid]; // necessary until 10.6 at least
if (fl_sys_menu_bar && Fl_Sys_Menu_Bar_Driver::window_menu_style())
Fl_MacOS_Sys_Menu_Bar_Driver::driver()->remove_window([xid getFl_Window]);
[xid close];

View File

@ -243,14 +243,20 @@ int glutCreateWindow(const char *title) {
W->valid(0);
W->context_valid(0);
W->make_current();
// some platforms (e.g., macOS 10.9) draw the window while show() runs
// but the window's draw function is not yet set when this function runs
W->redraw();
return W->number;
}
int glutCreateSubWindow(int win, int x, int y, int w, int h) {
Fl_Glut_Window *W = new Fl_Glut_Window(x,y,w,h,0);
windows[win]->add(W);
if (windows[win]->shown()) W->show();
W->make_current();
if (windows[win]->shown()) {
W->show();
W->make_current();
W->redraw();
}
return W->number;
}
/** Destroys the glut window, first unregister it from the glut windows list */