summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2018-11-29 17:50:55 +0000
committerManolo Gouy <Manolo>2018-11-29 17:50:55 +0000
commitb511f6a7a4f02cad8731c7e514f2778444a066fa (patch)
tree83421b62e3922cf915774d4a4657cf0939c03f8e /src
parentd600ccc034b93c0ad6dc034550dc87d3fcf32530 (diff)
Use the Fl_Gl_Device_Plugin mechanism to simplify the construction of a layer-backed GL window.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@13140 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Gl_Device_Plugin.cxx4
-rw-r--r--src/Fl_Gl_Window.cxx9
-rw-r--r--src/Fl_Gl_Window_Driver.H1
-rw-r--r--src/Fl_cocoa.mm15
4 files changed, 17 insertions, 12 deletions
diff --git a/src/Fl_Gl_Device_Plugin.cxx b/src/Fl_Gl_Device_Plugin.cxx
index f5e24585a..ee827aef5 100644
--- a/src/Fl_Gl_Device_Plugin.cxx
+++ b/src/Fl_Gl_Device_Plugin.cxx
@@ -44,6 +44,10 @@ public:
if (!glw) return NULL;
return Fl_OpenGL_Display_Device::capture_gl_rectangle(glw, x, y, w, h);
}
+ virtual GLContext context(Fl_Window *window) {
+ Fl_Gl_Window *glw = window->as_gl_window();
+ return glw ? glw->context() : 0;
+ }
};
static Fl_Gl_Device_Plugin Gl_Device_Plugin;
diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx
index af1bcc667..3968fa7ca 100644
--- a/src/Fl_Gl_Window.cxx
+++ b/src/Fl_Gl_Window.cxx
@@ -524,15 +524,6 @@ void Fl_Cocoa_Gl_Window_Driver::after_show(int need_redraw) {
if(need_redraw) pWindow->redraw();//necessary only after creation of a top-level GL window
}
-int Fl_Cocoa_Gl_Window_Driver::flush_begin(char& valid_f_) {
- Fl_Cocoa_Window_Driver *d = Fl_Cocoa_Window_Driver::driver(pWindow);
- if (d->wait_for_expose_value) { // 1st drawing of layer-backed GL window
- Fl_Cocoa_Window_Driver::GLcontext_update(pWindow->context()); // layer-backed GL windows may be empty without this
- d->wait_for_expose_value = 0;
- }
- return 0;
-}
-
float Fl_Cocoa_Gl_Window_Driver::pixels_per_unit()
{
int retina = (fl_mac_os_version >= 100700 && Fl::use_high_res_GL() && Fl_X::i(pWindow) &&
diff --git a/src/Fl_Gl_Window_Driver.H b/src/Fl_Gl_Window_Driver.H
index 955b9a29f..c0e4e2c6c 100644
--- a/src/Fl_Gl_Window_Driver.H
+++ b/src/Fl_Gl_Window_Driver.H
@@ -109,7 +109,6 @@ class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver {
virtual void after_show(int need_redraw);
virtual int mode_(int m, const int *a);
virtual void make_current_before();
- virtual int flush_begin(char& valid_f);
virtual void swap_buffers();
virtual void resize(int is_a_resize, int w, int h);
virtual char swap_type();
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 5835a2288..02fe0791c 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -147,6 +147,11 @@ static TISCreateASCIICapableInputSourceList_type TISCreateASCIICapableInputSourc
typedef void (*KeyScript_type)(short);
static KeyScript_type KeyScript;
+static Fl_Device_Plugin *opengl_plugin_device() {
+ static Fl_Plugin_Manager pm("fltk:device");
+ static Fl_Device_Plugin *pi = (Fl_Device_Plugin*)pm.plugin("opengl.device.fltk.org");
+ return pi;
+}
/* fltk-utf8 placekeepers */
void fl_set_status(int x, int y, int w, int h)
@@ -2203,6 +2208,13 @@ static CGContextRef prepare_bitmap_for_layer(int w, int h ) {
Fl_Window *window = [(FLWindow*)[self window] getFl_Window];
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 *pi = opengl_plugin_device();
+ if (pi) {
+ [pi->context(window) update]; // layer-backed GL windows may be empty without this
+ }
+ d->wait_for_expose_value = 0;
+ }
window->clear_damage(FL_DAMAGE_ALL);
d->Fl_Window_Driver::flush();
window->clear_damage();
@@ -4238,8 +4250,7 @@ static NSBitmapImageRep* GL_rect_to_nsbitmap(Fl_Window *win, int x, int y, int w
// captures a rectangle from a GL window and returns it as an allocated NSBitmapImageRep
// the capture has high res on retina
{
- Fl_Plugin_Manager pm("fltk:device");
- Fl_Device_Plugin *pi = (Fl_Device_Plugin*)pm.plugin("opengl.device.fltk.org");
+ Fl_Device_Plugin *pi = opengl_plugin_device();
if (!pi) return nil;
Fl_RGB_Image *img = pi->rectangle_capture(win, x, y, w, h);
NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:img->w() pixelsHigh:img->h() bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:4*img->w() bitsPerPixel:32];