summaryrefslogtreecommitdiff
path: root/src/drivers/OpenGL
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2016-01-29 15:24:33 +0000
committerMatthias Melcher <fltk@matthiasm.com>2016-01-29 15:24:33 +0000
commit222243bc865df5f6531e6ec7d20c3b1b072d1ee6 (patch)
tree77d171db9767483f808c3c06aa75a1de3ae4d64e /src/drivers/OpenGL
parent72dda7f35a11ca0fedac1ba5047db6988fb16299 (diff)
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
Diffstat (limited to 'src/drivers/OpenGL')
-rw-r--r--src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx42
-rw-r--r--src/drivers/OpenGL/Fl_OpenGL_Display_Device.h196
-rw-r--r--src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver.cxx34
-rw-r--r--src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_arci.cxx7
-rw-r--r--src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_color.cxx7
-rw-r--r--src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_font.cxx8
-rw-r--r--src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_line_style.cxx6
-rw-r--r--src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_rect.cxx9
8 files changed, 306 insertions, 3 deletions
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 <config.h>
+#include "../../config_lib.h"
+#include <FL/Fl_Gl_Window.H>
+#include <FL/Fl_Device.H>
+#include <FL/gl.h>
+
+#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 <config.h>
+#include "config_lib.h"
+#include <FL/Fl_Printer.H>
+#include <FL/Fl_Gl_Window.H>
+#include "Fl_Gl_Choice.H"
+#include <FL/Fl_RGB_Image.H>
+#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 <FL/Fl_Device.H>
+#include <FL/gl.h>
+
+#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 <FL/gl.h>
+#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 <config.h>
+#include "../../config_lib.h"
+#include "Fl_OpenGL_Graphics_Driver.h"
#include <FL/gl.h>
+#include <FL/Fl_Gl_Window.H>
+#include <FL/Fl_RGB_Image.H>
+#include <FL/Fl.H>
+#include <FL/fl_draw.h>
#define _USE_MATH_DEFINES
#include <math.h>
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 <config.h>
+#include "../../config_lib.h"
#include "Fl_OpenGL_Graphics_Driver.h"
#include <FL/gl.h>
+#include <FL/Fl_Gl_Window.H>
+#include <FL/Fl_RGB_Image.H>
+#include <FL/Fl.H>
+#include <FL/fl_draw.h>
+
// 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 <config.h>
+#include "../../config_lib.h"
+#include "Fl_OpenGL_Graphics_Driver.h"
#include <FL/gl.h>
+#include <FL/Fl_Gl_Window.H>
+#include <FL/Fl_RGB_Image.H>
+#include <FL/Fl.H>
+#include <FL/fl_draw.h>
+
// 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 <config.h>
+#include "../../config_lib.h"
#include "Fl_OpenGL_Graphics_Driver.h"
#include <FL/gl.h>
+#include <FL/Fl_Gl_Window.H>
+#include <FL/Fl_RGB_Image.H>
+#include <FL/Fl.H>
+#include <FL/fl_draw.h>
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 <FL/gl.h>
+#include <config.h>
+#include "../../config_lib.h"
#include "Fl_OpenGL_Graphics_Driver.h"
+#include <FL/gl.h>
+#include <FL/Fl_Gl_Window.H>
+#include <FL/Fl_RGB_Image.H>
+#include <FL/Fl.H>
// --- 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