summaryrefslogtreecommitdiff
path: root/src/Fl_cocoa.mm
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/Fl_cocoa.mm
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/Fl_cocoa.mm')
-rw-r--r--src/Fl_cocoa.mm15
1 files changed, 13 insertions, 2 deletions
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];