From 222243bc865df5f6531e6ec7d20c3b1b072d1ee6 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Fri, 29 Jan 2016 15:24:33 +0000 Subject: [PATCH] Made OpenGL driver compile by itself instead of including files from another .cxx file. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11083 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- ide/Xcode4/FLTK.xcodeproj/project.pbxproj | 54 +++++ src/CMakeLists.txt | 10 + src/Fl_Gl_Device_Plugin.cxx | 7 + .../OpenGL/Fl_OpenGL_Display_Device.cxx | 42 ++++ src/drivers/OpenGL/Fl_OpenGL_Display_Device.h | 196 ++++++++++++++++++ .../OpenGL/Fl_OpenGL_Graphics_Driver.cxx | 34 +++ .../OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx | 7 + .../Fl_OpenGL_Graphics_Driver_color.cxx | 7 + .../OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx | 8 + .../Fl_OpenGL_Graphics_Driver_line_style.cxx | 6 + .../OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx | 9 +- .../Quartz/Fl_Quartz_Display_Device.cxx | 129 ++++++++++++ src/drivers/Quartz/Fl_Quartz_Display_Device.h | 69 ++++++ 13 files changed, 575 insertions(+), 3 deletions(-) create mode 100644 src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx create mode 100644 src/drivers/OpenGL/Fl_OpenGL_Display_Device.h create mode 100644 src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.cxx create mode 100644 src/drivers/Quartz/Fl_Quartz_Display_Device.cxx create mode 100644 src/drivers/Quartz/Fl_Quartz_Display_Device.h diff --git a/ide/Xcode4/FLTK.xcodeproj/project.pbxproj b/ide/Xcode4/FLTK.xcodeproj/project.pbxproj index fbc7ab9e1..2e9a5d867 100644 --- a/ide/Xcode4/FLTK.xcodeproj/project.pbxproj +++ b/ide/Xcode4/FLTK.xcodeproj/project.pbxproj @@ -706,6 +706,16 @@ C984AFA812D02A1800D66DAD /* demo.menu in Resources */ = {isa = PBXBuildFile; fileRef = C984AFA712D02A1800D66DAD /* demo.menu */; }; C99FD8E212D2A2AD002FC776 /* browser.cxx in CopyFiles */ = {isa = PBXBuildFile; fileRef = 6D999C03407EAEE9C4D3477A /* browser.cxx */; }; C9A374AB3AD29E141C659819 /* fltk.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = FEB0F8FE6383384180570D94 /* fltk.framework */; }; + C9B6BB351C5BACA100E80696 /* Fl_Quartz_Display_Device.cxx in Sources */ = {isa = PBXBuildFile; fileRef = C9B6BB331C5BACA100E80696 /* Fl_Quartz_Display_Device.cxx */; }; + C9B6BB4D1C5BB7C500E80696 /* Fl_OpenGL_Display_Device.cxx in Sources */ = {isa = PBXBuildFile; fileRef = C9B6BB4A1C5BB72500E80696 /* Fl_OpenGL_Display_Device.cxx */; }; + C9B6BB4E1C5BB7C500E80696 /* Fl_OpenGL_Graphics_Driver.cxx in Sources */ = {isa = PBXBuildFile; fileRef = C9B6BB481C5BB0C600E80696 /* Fl_OpenGL_Graphics_Driver.cxx */; }; + C9B6BB4F1C5BB7C500E80696 /* Fl_OpenGL_Graphics_Driver_color.cxx in Sources */ = {isa = PBXBuildFile; fileRef = C9B6BB381C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_color.cxx */; }; + C9B6BB501C5BB7C500E80696 /* Fl_OpenGL_Graphics_Driver_image.cxx in Sources */ = {isa = PBXBuildFile; fileRef = C9B6BB3A1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_image.cxx */; }; + C9B6BB511C5BB7C500E80696 /* Fl_OpenGL_Graphics_Driver_line_style.cxx in Sources */ = {isa = PBXBuildFile; fileRef = C9B6BB3C1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_line_style.cxx */; }; + C9B6BB521C5BB7C500E80696 /* Fl_OpenGL_Graphics_Driver_vertex.cxx in Sources */ = {isa = PBXBuildFile; fileRef = C9B6BB3E1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_vertex.cxx */; }; + C9B6BB581C5BB7EB00E80696 /* Fl_OpenGL_Graphics_Driver_arci.cxx in Sources */ = {isa = PBXBuildFile; fileRef = C9B6BB371C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_arci.cxx */; }; + C9B6BB591C5BB7EB00E80696 /* Fl_OpenGL_Graphics_Driver_font.cxx in Sources */ = {isa = PBXBuildFile; fileRef = C9B6BB391C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_font.cxx */; }; + C9B6BB5A1C5BB7EB00E80696 /* Fl_OpenGL_Graphics_Driver_rect.cxx in Sources */ = {isa = PBXBuildFile; fileRef = C9B6BB3D1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_rect.cxx */; }; C9C4C91FDA73557BB6B69F3D /* jchuff.c in Sources */ = {isa = PBXBuildFile; fileRef = D9DB580DCA05DE487FACA272 /* jchuff.c */; }; C9D72F10B7A22DD0349ABC68 /* fltk_forms.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 097D0B476E396B9AAC6FA1E0 /* fltk_forms.framework */; }; C9EDD4441274B93000ADB21C /* Enumerations.H in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84CE79448708855561FEE498 /* Enumerations.H */; }; @@ -4758,6 +4768,19 @@ C97E30B11C59704300E22076 /* Fl_Quartz_Graphics_Driver.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Fl_Quartz_Graphics_Driver.cxx; path = ../../src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx; sourceTree = ""; }; C97E30B21C59704300E22076 /* Fl_Quartz_Printer_Graphics_Driver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Fl_Quartz_Printer_Graphics_Driver.h; path = ../../src/drivers/Quartz/Fl_Quartz_Printer_Graphics_Driver.h; sourceTree = ""; }; C984AFA712D02A1800D66DAD /* demo.menu */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = demo.menu; path = ../../test/demo.menu; sourceTree = SOURCE_ROOT; }; + C9B6BB331C5BACA100E80696 /* Fl_Quartz_Display_Device.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Fl_Quartz_Display_Device.cxx; path = ../../src/drivers/Quartz/Fl_Quartz_Display_Device.cxx; sourceTree = ""; }; + C9B6BB341C5BACA100E80696 /* Fl_Quartz_Display_Device.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Fl_Quartz_Display_Device.h; path = ../../src/drivers/Quartz/Fl_Quartz_Display_Device.h; sourceTree = ""; }; + C9B6BB371C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_arci.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Fl_OpenGL_Graphics_Driver_arci.cxx; path = ../../src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx; sourceTree = ""; }; + C9B6BB381C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_color.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Fl_OpenGL_Graphics_Driver_color.cxx; path = ../../src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_color.cxx; sourceTree = ""; }; + C9B6BB391C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_font.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Fl_OpenGL_Graphics_Driver_font.cxx; path = ../../src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx; sourceTree = ""; }; + C9B6BB3A1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_image.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Fl_OpenGL_Graphics_Driver_image.cxx; path = ../../src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_image.cxx; sourceTree = ""; }; + C9B6BB3C1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_line_style.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Fl_OpenGL_Graphics_Driver_line_style.cxx; path = ../../src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx; sourceTree = ""; }; + C9B6BB3D1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_rect.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Fl_OpenGL_Graphics_Driver_rect.cxx; path = ../../src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx; sourceTree = ""; }; + C9B6BB3E1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_vertex.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Fl_OpenGL_Graphics_Driver_vertex.cxx; path = ../../src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx; sourceTree = ""; }; + C9B6BB3F1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Fl_OpenGL_Graphics_Driver.h; path = ../../src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.h; sourceTree = ""; }; + C9B6BB481C5BB0C600E80696 /* Fl_OpenGL_Graphics_Driver.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Fl_OpenGL_Graphics_Driver.cxx; path = ../../src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.cxx; sourceTree = ""; }; + C9B6BB4A1C5BB72500E80696 /* Fl_OpenGL_Display_Device.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Fl_OpenGL_Display_Device.cxx; path = ../../src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx; sourceTree = ""; }; + C9B6BB4B1C5BB72500E80696 /* Fl_OpenGL_Display_Device.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Fl_OpenGL_Display_Device.h; path = ../../src/drivers/OpenGL/Fl_OpenGL_Display_Device.h; sourceTree = ""; }; C9EDD143127338F600ADB21C /* README.OSX.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = README.OSX.txt; path = ../../README.OSX.txt; sourceTree = SOURCE_ROOT; }; C9EDD4DE1274BB6600ADB21C /* png.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = png.h; path = ../../png/png.h; sourceTree = SOURCE_ROOT; }; C9EDD4DF1274BB6600ADB21C /* pngconf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pngconf.h; path = ../../png/pngconf.h; sourceTree = SOURCE_ROOT; }; @@ -6213,6 +6236,7 @@ 7D01507BB2E71FC0C390ABEA /* fltk_gl */ = { isa = PBXGroup; children = ( + C9B6BB361C5BAF2400E80696 /* Drivers */, 7E097C61B5952D56DFB93ECF /* Headers */, 27C65F509527076EB26E9C0F /* Fl_Gl_Choice.cxx */, A7A692EB67C5CBE35D4A4B5C /* Fl_Gl_Device_Plugin.cxx */, @@ -6722,6 +6746,8 @@ C97E30A01C596C8500E22076 /* Quartz */ = { isa = PBXGroup; children = ( + C9B6BB341C5BACA100E80696 /* Fl_Quartz_Display_Device.h */, + C9B6BB331C5BACA100E80696 /* Fl_Quartz_Display_Device.cxx */, C97E30A21C596CC900E22076 /* Fl_Quartz_Graphics_Driver.h */, C97E30B11C59704300E22076 /* Fl_Quartz_Graphics_Driver.cxx */, C97E30A11C596CC900E22076 /* Fl_Quartz_Graphics_Driver_rect.cxx */, @@ -6737,6 +6763,24 @@ name = Quartz; sourceTree = ""; }; + C9B6BB361C5BAF2400E80696 /* Drivers */ = { + isa = PBXGroup; + children = ( + C9B6BB4B1C5BB72500E80696 /* Fl_OpenGL_Display_Device.h */, + C9B6BB4A1C5BB72500E80696 /* Fl_OpenGL_Display_Device.cxx */, + C9B6BB3F1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver.h */, + C9B6BB481C5BB0C600E80696 /* Fl_OpenGL_Graphics_Driver.cxx */, + C9B6BB371C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_arci.cxx */, + C9B6BB381C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_color.cxx */, + C9B6BB391C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_font.cxx */, + C9B6BB3A1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_image.cxx */, + C9B6BB3C1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_line_style.cxx */, + C9B6BB3D1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_rect.cxx */, + C9B6BB3E1C5BB07E00E80696 /* Fl_OpenGL_Graphics_Driver_vertex.cxx */, + ); + name = Drivers; + sourceTree = ""; + }; C9EDD4DC1274BB4100ADB21C /* Headers */ = { isa = PBXGroup; children = ( @@ -10486,6 +10530,7 @@ E1B04810E72BD9557356CAAE /* fluid.cxx in Sources */, 98A96758FF9D01852DFBECFE /* function_panel.cxx in Sources */, 438CCCA43724B2E59680EF6B /* template_panel.cxx in Sources */, + C9B6BB351C5BACA100E80696 /* Fl_Quartz_Display_Device.cxx in Sources */, 27B4C89E8CBF260313ACA42E /* undo.cxx in Sources */, B7D0770AC83AA04E8E12B76E /* widget_panel.cxx in Sources */, ); @@ -10512,15 +10557,24 @@ buildActionMask = 2147483647; files = ( C635DF0A06D278F09C3A6359 /* Fl_Gl_Choice.cxx in Sources */, + C9B6BB511C5BB7C500E80696 /* Fl_OpenGL_Graphics_Driver_line_style.cxx in Sources */, + C9B6BB591C5BB7EB00E80696 /* Fl_OpenGL_Graphics_Driver_font.cxx in Sources */, + C9B6BB521C5BB7C500E80696 /* Fl_OpenGL_Graphics_Driver_vertex.cxx in Sources */, FBAEA5F4CE75FCFCE1B7521A /* Fl_Gl_Device_Plugin.cxx in Sources */, + C9B6BB5A1C5BB7EB00E80696 /* Fl_OpenGL_Graphics_Driver_rect.cxx in Sources */, + C9B6BB581C5BB7EB00E80696 /* Fl_OpenGL_Graphics_Driver_arci.cxx in Sources */, 0C1C8E024CC1739ECC147412 /* Fl_Gl_Overlay.cxx in Sources */, + C9B6BB4D1C5BB7C500E80696 /* Fl_OpenGL_Display_Device.cxx in Sources */, 93473D40BFD87C1C855E3E2B /* Fl_Gl_Window.cxx in Sources */, 0E33CB7A389B20931404C97C /* freeglut_geometry.cxx in Sources */, 671D5E8AC4CDE34D468FDFE9 /* freeglut_stroke_mono_roman.cxx in Sources */, 58D9DA0C0F0A11E97EAAB61B /* freeglut_stroke_roman.cxx in Sources */, 00BD4FD0209BFB1A6446B9A5 /* freeglut_teapot.cxx in Sources */, + C9B6BB4F1C5BB7C500E80696 /* Fl_OpenGL_Graphics_Driver_color.cxx in Sources */, 0EEF4C6DD5294217DB42BB88 /* gl_draw.cxx in Sources */, D7C1EDE212D9E84D085257BF /* glut_compatability.cxx in Sources */, + C9B6BB501C5BB7C500E80696 /* Fl_OpenGL_Graphics_Driver_image.cxx in Sources */, + C9B6BB4E1C5BB7C500E80696 /* Fl_OpenGL_Graphics_Driver.cxx in Sources */, F0EF820CDDEDCCBA9DF9AD84 /* glut_font.cxx in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 94ca5db90..cc8c7e59b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -178,6 +178,7 @@ elseif (APPLE) # FILE(GLOB DRIVER_FILES drivers/Quartz/Fl_Quartz_Graphics_Driver_*.cxx) set(DRIVER_FILES + drivers/Quartz/Fl_Quartz_Display_Device.cxx drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx drivers/Quartz/Fl_Quartz_Graphics_Driver_color.cxx drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx @@ -223,6 +224,15 @@ set(GLCPPFILES gl_start.cxx glut_compatability.cxx glut_font.cxx + drivers/OpenGL/Fl_OpenGL_Display_Device.cxx + drivers/OpenGL/Fl_OpenGL_Graphics_Driver.cxx + drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx + drivers/OpenGL/Fl_OpenGL_Graphics_Driver_color.cxx + drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx + drivers/OpenGL/Fl_OpenGL_Graphics_Driver_image.cxx + drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx + drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx + drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx ) set(IMGCPPFILES diff --git a/src/Fl_Gl_Device_Plugin.cxx b/src/Fl_Gl_Device_Plugin.cxx index 16af6fbdb..50ee159b8 100644 --- a/src/Fl_Gl_Device_Plugin.cxx +++ b/src/Fl_Gl_Device_Plugin.cxx @@ -31,6 +31,9 @@ #endif + +// FIXME: remove the code below +#if 0 // ------ this should be in a separate file! ----------------------------------- #ifdef FL_CFG_GFX_OPENGL @@ -62,6 +65,10 @@ const char *Fl_OpenGL_Display_Device::class_id = "Fl_OpenGL_Display_Device"; #include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx" #include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx" +#endif + + + #if defined(__APPLE__) uchar *convert_BGRA_to_RGB(uchar *baseAddress, int w, int h, int mByteWidth) diff --git a/src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx b/src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx new file mode 100644 index 000000000..94ea3a136 --- /dev/null +++ b/src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx @@ -0,0 +1,42 @@ +// +// "$Id$" +// +// implementation of class Fl_Gl_Device_Plugin for the Fast Light Tool Kit (FLTK). +// +// Copyright 2010-2014 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// http://www.fltk.org/COPYING.php +// +// Please report all bugs and problems to: +// +// http://www.fltk.org/str.php +// + +#include +#include "../../config_lib.h" +#include +#include +#include + +#include "Fl_OpenGL_Graphics_Driver.h" + +Fl_OpenGL_Display_Device *Fl_OpenGL_Display_Device::display_device() { + static Fl_OpenGL_Display_Device *display = new Fl_OpenGL_Display_Device(new Fl_OpenGL_Graphics_Driver()); + return display; +}; + +Fl_OpenGL_Display_Device::Fl_OpenGL_Display_Device(Fl_OpenGL_Graphics_Driver *graphics_driver) +: Fl_Surface_Device(graphics_driver) +{ +} + +const char *Fl_OpenGL_Display_Device::class_id = "Fl_OpenGL_Display_Device"; + + +// +// End of "$Id$". +// diff --git a/src/drivers/OpenGL/Fl_OpenGL_Display_Device.h b/src/drivers/OpenGL/Fl_OpenGL_Display_Device.h new file mode 100644 index 000000000..dab9608d4 --- /dev/null +++ b/src/drivers/OpenGL/Fl_OpenGL_Display_Device.h @@ -0,0 +1,196 @@ +// +// "$Id$" +// +// implementation of class Fl_Gl_Device_Plugin for the Fast Light Tool Kit (FLTK). +// +// Copyright 2010-2014 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// http://www.fltk.org/COPYING.php +// +// Please report all bugs and problems to: +// +// http://www.fltk.org/str.php +// + + +// FIXME: fill with code! +#if 0 + +#include +#include "config_lib.h" +#include +#include +#include "Fl_Gl_Choice.H" +#include +#include "FL/Fl.H" + +#if defined(WIN32) || defined(__APPLE__) +#elif defined(FL_PORTING) +# pragma message "FL_PORTING: implement code to read OpenGL renderings into RGB maps" +#else +#endif + + +// ------ this should be in a separate file! ----------------------------------- +#ifdef FL_CFG_GFX_OPENGL + +#include +#include + +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver.h" + +Fl_OpenGL_Display_Device *Fl_OpenGL_Display_Device::display_device() { + static Fl_OpenGL_Display_Device *display = new Fl_OpenGL_Display_Device(new Fl_OpenGL_Graphics_Driver()); + return display; +}; + +Fl_OpenGL_Display_Device::Fl_OpenGL_Display_Device(Fl_OpenGL_Graphics_Driver *graphics_driver) +: Fl_Surface_Device(graphics_driver) +{ +} + +const char *Fl_OpenGL_Display_Device::class_id = "Fl_OpenGL_Display_Device"; + +#endif +// ------ end of separate file! ------------------------------------------------ + +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx" +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_color.cxx" +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx" +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_image.cxx" +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx" +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx" +#include "drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx" + + +#if defined(__APPLE__) +uchar *convert_BGRA_to_RGB(uchar *baseAddress, int w, int h, int mByteWidth) +{ + uchar *newimg = new uchar[3*w*h]; + uchar *to = newimg; + for (int i = 0; i < h; i++) { + uchar *from = baseAddress + i * mByteWidth; + for (int j = 0; j < w; j++, from += 4) { +#if __ppc__ + memcpy(to, from + 1, 3); + to += 3; +#else + *(to++) = *(from+2); + *(to++) = *(from+1); + *(to++) = *from; +#endif + } + } + delete[] baseAddress; + return newimg; +} +#endif + +static Fl_RGB_Image* capture_gl_rectangle(Fl_Gl_Window *glw, int x, int y, int w, int h) +/* captures a rectangle of a Fl_Gl_Window window, and returns it as a RGB image + stored from bottom to top. + */ +{ +#if defined(__APPLE__) + const int bytesperpixel = 4; + int factor = glw->pixels_per_unit(); + if (factor > 1) { + w *= factor; h *= factor; x *= factor; y *= factor; + } +#else + const int bytesperpixel = 3; +#endif + glw->flush(); // forces a GL redraw, necessary for the glpuzzle demo + // Read OpenGL context pixels directly. + // For extra safety, save & restore OpenGL states that are changed + glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); + glPixelStorei(GL_PACK_ALIGNMENT, 4); /* Force 4-byte alignment */ + glPixelStorei(GL_PACK_ROW_LENGTH, 0); + glPixelStorei(GL_PACK_SKIP_ROWS, 0); + glPixelStorei(GL_PACK_SKIP_PIXELS, 0); + // Read a block of pixels from the frame buffer + int mByteWidth = w * bytesperpixel; + mByteWidth = (mByteWidth + 3) & ~3; // Align to 4 bytes + uchar *baseAddress = new uchar[mByteWidth * h]; + glReadPixels(x, glw->pixel_h() - (y+h), w, h, +#if defined(__APPLE__) + GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, +#else + GL_RGB, GL_UNSIGNED_BYTE, +#endif + baseAddress); + glPopClientAttrib(); +#if defined(__APPLE__) + baseAddress = convert_BGRA_to_RGB(baseAddress, w, h, mByteWidth); + mByteWidth = 3 * w; +#endif + Fl_RGB_Image *img = new Fl_RGB_Image(baseAddress, w, h, 3, mByteWidth); + img->alloc_array = 1; + return img; +} + +#ifdef __APPLE__ +static void imgProviderReleaseData (void *info, const void *data, size_t size) +{ + delete (Fl_RGB_Image *)info; +} +#endif + +/** + This class will make sure that OpenGL printing/screen capture is available if fltk_gl + was linked to the program + */ +class Fl_Gl_Device_Plugin : public Fl_Device_Plugin { +public: + Fl_Gl_Device_Plugin() : Fl_Device_Plugin(name()) { } + virtual const char *name() { return "opengl.device.fltk.org"; } + virtual int print(Fl_Widget *w, int x, int y, int height /*useless*/) { + Fl_Gl_Window *glw = w->as_gl_window(); + if (!glw) return 0; + Fl_RGB_Image *img = capture_gl_rectangle(glw, 0, 0, glw->w(), glw->h()); +#ifdef __APPLE__ + if (Fl_Surface_Device::surface()->driver()->has_feature(Fl_Graphics_Driver::NATIVE)) { + // convert the image to CGImage, and draw it at full res (useful on retina display) + CGColorSpaceRef cSpace = CGColorSpaceCreateDeviceRGB(); + CGDataProviderRef provider = CGDataProviderCreateWithData(img, img->array, img->ld() * img->h(), imgProviderReleaseData); + CGImageRef cgimg = CGImageCreate(img->w(), img->h(), 8, 24, img->ld(), cSpace, + (CGBitmapInfo)(kCGImageAlphaNone), + provider, NULL, false, kCGRenderingIntentDefault); + CGColorSpaceRelease(cSpace); + CGDataProviderRelease(provider); + CGContextDrawImage(fl_gc, CGRectMake(0, 0, glw->w(), glw->h()), cgimg); + CFRelease(cgimg); + return 1; + } else if (img->w() > glw->w()) { + Fl_RGB_Image *img2 = (Fl_RGB_Image*)img->copy(glw->w(), glw->h()); + delete img; + img = img2; + } +#endif + int ld = img->ld() ? img->ld() : img->w() * img->d(); + fl_draw_image(img->array + (img->h() - 1) * ld, x, y , img->w(), img->h(), 3, - ld); + delete img; + return 1; + } + virtual Fl_RGB_Image* rectangle_capture(Fl_Widget *widget, int x, int y, int w, int h) { + Fl_Gl_Window *glw = widget->as_gl_window(); + if (!glw) return NULL; + return capture_gl_rectangle(glw, x, y, w, h); + } +}; + +static Fl_Gl_Device_Plugin Gl_Device_Plugin; + +// The purpose of this variable, used in Fl_Gl_Window.cxx, is only to force this file to be loaded +// whenever Fl_Gl_Window.cxx is loaded, that is, whenever fltk_gl is. +FL_EXPORT int fl_gl_load_plugin = 0; + +#endif + +// +// End of "$Id$". +// diff --git a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.cxx new file mode 100644 index 000000000..ff59992d8 --- /dev/null +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.cxx @@ -0,0 +1,34 @@ +// +// "$Id$" +// +// Rectangle drawing routines for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2016 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// http://www.fltk.org/COPYING.php +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +#ifndef FL_CFG_GFX_OPENGL_CXX +#define FL_CFG_GFX_OPENGL_CXX + + +#include +#include "Fl_OpenGL_Graphics_Driver.h" + + +const char *Fl_OpenGL_Graphics_Driver::class_id = "Fl_OpenGL_Graphics_Driver"; + + +#endif // FL_CFG_GFX_OPENGL_RECT_CXX + +// +// End of "$Id$". +// diff --git a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx index 15ec4cf36..28e0f6c67 100644 --- a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx @@ -24,7 +24,14 @@ \brief Utility functions for drawing circles using integers */ +#include +#include "../../config_lib.h" +#include "Fl_OpenGL_Graphics_Driver.h" #include +#include +#include +#include +#include #define _USE_MATH_DEFINES #include diff --git a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_color.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_color.cxx index 0923b02fb..f103154b7 100644 --- a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_color.cxx +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_color.cxx @@ -21,8 +21,15 @@ \brief Color handling */ +#include +#include "../../config_lib.h" #include "Fl_OpenGL_Graphics_Driver.h" #include +#include +#include +#include +#include + // Implementation of fl_color(i), fl_color(r,g,b). diff --git a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx index 0fe187d91..65ab5d7bb 100644 --- a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx @@ -27,7 +27,15 @@ */ +#include +#include "../../config_lib.h" +#include "Fl_OpenGL_Graphics_Driver.h" #include +#include +#include +#include +#include + // FIXME: check out FreeGlut: // FIXME: implement font-to-RGBA in the main graphics driver diff --git a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx index c9606f95d..7062ff53c 100644 --- a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx @@ -24,8 +24,14 @@ \brief Line style drawing utility hiding different platforms. */ +#include +#include "../../config_lib.h" #include "Fl_OpenGL_Graphics_Driver.h" #include +#include +#include +#include +#include extern int fl_line_width_; diff --git a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx index 1ea30a4d7..8536d4901 100644 --- a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx @@ -25,8 +25,13 @@ \brief OpenGL specific line and polygon drawing with integer coordinates. */ -#include +#include +#include "../../config_lib.h" #include "Fl_OpenGL_Graphics_Driver.h" +#include +#include +#include +#include // --- line and polygon drawing with integer coordinates @@ -199,8 +204,6 @@ void Fl_OpenGL_Graphics_Driver::restore_clip() { fl_clip_state_number++; } -const char *Fl_OpenGL_Graphics_Driver::class_id = "Fl_OpenGL_Graphics_Driver"; - #endif // FL_CFG_GFX_OPENGL_RECT_CXX diff --git a/src/drivers/Quartz/Fl_Quartz_Display_Device.cxx b/src/drivers/Quartz/Fl_Quartz_Display_Device.cxx new file mode 100644 index 000000000..df0eaba5d --- /dev/null +++ b/src/drivers/Quartz/Fl_Quartz_Display_Device.cxx @@ -0,0 +1,129 @@ +// +// "$Id$" +// +// implementation of Fl_Device class for the Fast Light Tool Kit (FLTK). +// +// Copyright 2010-2016 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// http://www.fltk.org/COPYING.php +// +// Please report all bugs and problems to: +// +// http://www.fltk.org/str.php +// + +// FIXME: implement this +#if 0 + +#include +#include +#include + +#include "config_lib.h" +#ifdef FL_CFG_GFX_QUARTZ +#include "drivers/Quartz/Fl_Quartz_Graphics_Driver.h" +#endif + +#if defined(WIN32) || defined(__APPLE__) +#elif defined(FL_PORTING) +# pragma message "FL_PORTING: instantiate and implement various device drivers here" +#else +#endif + +const char *Fl_Device::class_id = "Fl_Device"; +const char *Fl_Surface_Device::class_id = "Fl_Surface_Device"; +const char *Fl_Display_Device::class_id = "Fl_Display_Device"; +const char *Fl_Graphics_Driver::class_id = "Fl_Graphics_Driver"; +#if defined(__APPLE__) || defined(FL_DOXYGEN) +# ifndef FL_DOXYGEN + bool Fl_Display_Device::high_res_window_ = false; +# endif +#endif +#if defined(WIN32) || defined(FL_DOXYGEN) +const char *Fl_GDI_Graphics_Driver::class_id = "Fl_GDI_Graphics_Driver"; +const char *Fl_GDI_Printer_Graphics_Driver::class_id = "Fl_GDI_Printer_Graphics_Driver"; +#endif +#if !(defined(__APPLE__) || defined(WIN32)) +#if defined(FL_PORTING) +# pragma message "FL_PORTING: instantiate the main graphics driver here" +#else +const char *Fl_Xlib_Graphics_Driver::class_id = "Fl_Xlib_Graphics_Driver"; +#endif +#endif + + +/** \brief Make this surface the current drawing surface. + This surface will receive all future graphics requests. */ +void Fl_Surface_Device::set_current(void) +{ + fl_graphics_driver = _driver; + _surface = this; +} + +FL_EXPORT Fl_Graphics_Driver *fl_graphics_driver; // the current target device of graphics operations +Fl_Surface_Device* Fl_Surface_Device::_surface; // the current target surface of graphics operations + +const Fl_Graphics_Driver::matrix Fl_Graphics_Driver::m0 = {1, 0, 0, 1, 0, 0}; + +Fl_Graphics_Driver::Fl_Graphics_Driver() { + font_ = 0; + size_ = 0; + sptr=0; rstackptr=0; + rstack[0] = NULL; + fl_clip_state_number=0; + m = m0; + fl_matrix = &m; + p = (XPOINT *)0; + font_descriptor_ = NULL; + p_size = 0; +}; + +void Fl_Graphics_Driver::text_extents(const char*t, int n, int& dx, int& dy, int& w, int& h) +{ + w = (int)width(t, n); + h = - height(); + dx = 0; + dy = descent(); +} + +/** A constructor that sets the graphics driver used by the display */ +Fl_Display_Device::Fl_Display_Device(Fl_Graphics_Driver *graphics_driver) : Fl_Surface_Device(graphics_driver) { + this->set_current(); +}; + + +/** Returns the platform display device. */ +Fl_Display_Device *Fl_Display_Device::display_device() { + static Fl_Display_Device *display = new Fl_Display_Device(new +#if defined(__APPLE__) + Fl_Quartz_Graphics_Driver +#elif defined(WIN32) + Fl_GDI_Graphics_Driver +#elif defined(FL_PORTING) +# pragma message "FL_PORTING: instantiate your display driver here" + Fl_XXX_Graphics_Driver +#else + Fl_Xlib_Graphics_Driver +#endif + ); + return display; +}; + + +Fl_Surface_Device *Fl_Surface_Device::default_surface() +{ + return Fl_Display_Device::display_device(); +} + + +Fl_Display_Device *Fl_Display_Device::_display = Fl_Display_Device::display_device(); + +#endif + +// +// End of "$Id$". +// diff --git a/src/drivers/Quartz/Fl_Quartz_Display_Device.h b/src/drivers/Quartz/Fl_Quartz_Display_Device.h new file mode 100644 index 000000000..221b80478 --- /dev/null +++ b/src/drivers/Quartz/Fl_Quartz_Display_Device.h @@ -0,0 +1,69 @@ +// +// "$Id$" +// +// Definition of class Fl_Quartz_Display_Device +// for the Fast Light Tool Kit (FLTK). +// +// Copyright 2010-2016 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// http://www.fltk.org/COPYING.php +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +/** \file Fl_Quartz_Disply_Device.h + \brief Implement a connection between the Cocoa window management and the + Quartz graphics driver on OS X. +*/ + +#ifndef FL_QUARTZ_DISPLAY_DEVICE_H +#define FL_QUARTZ_DISPLAY_DEVICE_H + +// FIXME: implement this +#if 0 +#include +#include +#include +#include +#include +#include +#include + +/** + A display to which the computer can draw. + When the program begins running, an Fl_Display_Device instance has been created and made the current drawing surface. + There is no need to create any other object of this class. + */ +class FL_EXPORT Fl_Display_Device : public Fl_Surface_Device { + friend class Fl_Quartz_Graphics_Driver; + static Fl_Display_Device *_display; // the platform display device +#ifdef __APPLE__ + friend class Fl_X; + friend class Fl_Graphics_Driver; + static bool high_res_window_; //< true when drawing to a window of a retina display (Mac OS X only) + static bool high_resolution() {return high_res_window_;} +#elif defined(WIN32) +#elif defined(FL_PORTING) +# pragma message "FL_PORTING: implement functions for extra high res drawing if your platform supports it" +#else +#endif +public: + static const char *class_id; + const char *class_name() {return class_id;}; + Fl_Display_Device(Fl_Graphics_Driver *graphics_driver); + static Fl_Display_Device *display_device(); +}; + +#endif + +#endif // FL_QUARTZ_DISPLAY_DEVICE_H + +// +// End of "$Id$". +//