diff options
| author | Manolo Gouy <Manolo> | 2016-05-08 06:42:57 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2016-05-08 06:42:57 +0000 |
| commit | 300747225ca2de6db483287fa44ed24d18765b99 (patch) | |
| tree | 6fb63553203032bc98f4dd84b3162c8e306ffc32 /FL | |
| parent | 048bb2b0f6ea49d0a88eee879017949bbd1ac83d (diff) | |
Rewrite OpenGL-related code under the driver model.
Class Fl_Gl_Window_Driver, with its platform-specific derived classes, is created
to hold platform-specific, OpenGL code.
File gl_draw.cxx still needs to be converted to the driver model.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11716 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'FL')
| -rw-r--r-- | FL/Fl_Gl_Window.H | 59 | ||||
| -rw-r--r-- | FL/Fl_Gl_Window_Driver.H | 167 |
2 files changed, 177 insertions, 49 deletions
diff --git a/FL/Fl_Gl_Window.H b/FL/Fl_Gl_Window.H index 8c5b9b723..11e0cef98 100644 --- a/FL/Fl_Gl_Window.H +++ b/FL/Fl_Gl_Window.H @@ -3,7 +3,7 @@ // // OpenGL header file for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2015 by Bill Spitzak and others. +// 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 @@ -33,7 +33,7 @@ typedef void* GLContext; // actually a GLXContext or HGLDC #endif class Fl_Gl_Choice; // structure to hold result of glXChooseVisual - +class Fl_Gl_Window_Driver; /** The Fl_Gl_Window widget sets things up so OpenGL works. @@ -55,6 +55,8 @@ class Fl_Gl_Choice; // structure to hold result of glXChooseVisual unless those widgets are modified to draw using OpenGL calls. */ class FL_EXPORT Fl_Gl_Window : public Fl_Window { + friend class Fl_Gl_Window_Driver; + Fl_Gl_Window_Driver *pGlWindowDriver; int mode_; const int *alist; @@ -66,21 +68,23 @@ class FL_EXPORT Fl_Gl_Window : public Fl_Window { void init(); void *overlay; - void make_overlay(); - friend class _Fl_Gl_Overlay; static int can_do(int, const int *); int mode(int, const int *); static int gl_plugin_linkage(); +protected: + virtual void draw(); public: - void show(); + /** Same as Fl_Window::show(int a, char **b) */ void show(int a, char **b) {Fl_Window::show(a,b);} void flush(); void hide(); void resize(int,int,int,int); int handle(int); + /** Returns a pointer to the window's Fl_Gl_Window_Driver object */ + Fl_Gl_Window_Driver *gl_driver() {return pGlWindowDriver;} /** Is turned off when FLTK creates a new context for this window or @@ -204,50 +208,15 @@ public: void swap_buffers(); void ortho(); - /** - Returns true if the hardware overlay is possible. If this is false, - FLTK will try to simulate the overlay, with significant loss of update - speed. Calling this will cause FLTK to open the display. - */ int can_do_overlay(); - /** - This method causes draw_overlay() to be called at a later time. - Initially the overlay is clear. If you want the window to display - something in the overlay when it first appears, you must call this - immediately after you show() your window. - */ void redraw_overlay(); void hide_overlay(); - /** - The make_overlay_current() method selects the OpenGL context - for the widget's overlay. It is called automatically prior to the - draw_overlay() method being called and can also be used to - implement feedback and/or selection within the handle() - method. - */ void make_overlay_current(); // Note: Doxygen docs in Fl_Widget.H to avoid redundancy. virtual Fl_Gl_Window* as_gl_window() {return this;} - /** The number of pixels per FLTK unit of length for the window. - Returns 1, except for a window mapped to - an Apple 'retina' display, and if Fl::use_high_res_GL(bool) is set to true, - when it returns 2. This method dynamically adjusts its value when the window - is moved to/from a retina display. This method is useful, e.g., to convert, - in a window's handle() method, the FLTK units returned by Fl::event_x() and - Fl::event_y() to the pixel units used by the OpenGL source code. - \version 1.3.4 - */ -#ifdef __APPLE__ // PORTME: Fl_Surface_Driver - additional functionality int pixels_per_unit(); -#elif defined(WIN32) - int pixels_per_unit() { return 1; } -#elif defined(FL_PORTING) -# pragma message "FL_PORTING: define multiple resolution OpenGL rendering if your platform supports it" -#else - int pixels_per_unit() { return 1; } -#endif /** Gives the window width in OpenGL pixels. Generally identical with the result of the w() function, but for a window mapped to an Apple 'retina' display, and if Fl::use_high_res_GL(bool) is set to true, @@ -279,17 +248,9 @@ public: Fl_Gl_Window(int X, int Y, int W, int H, const char *l=0) : Fl_Window(X,Y,W,H,l) {init();} - -protected: - /** - Draws the Fl_Gl_Window. - - You \e \b must override the draw() method. - */ - virtual void draw(); }; -#endif +#endif // Fl_Gl_Window_H // // End of "$Id$". diff --git a/FL/Fl_Gl_Window_Driver.H b/FL/Fl_Gl_Window_Driver.H new file mode 100644 index 000000000..b9b5c0a9b --- /dev/null +++ b/FL/Fl_Gl_Window_Driver.H @@ -0,0 +1,167 @@ +// +// "$Id: Fl_Gl_Window_Driver.H 11696 2016-04-25 06:29:36Z manolo $" +// +// Definition of classes Fl_Graphics_Driver, Fl_Surface_Device, Fl_Display_Device +// for the Fast Light Tool Kit (FLTK). +// +// Copyright 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_Gl_Window_Driver_H +#define Fl_Gl_Window_Driver_H + +#if defined(FL_PORTING) +# pragma message "FL_PORTING: please, derive and implement the Fl_Gl_Window_Driver class for your platform" +#endif + +#include <FL/Fl_Gl_Window.H> + +class Fl_Gl_Choice; + +/* The constructor of each Fl_Gl_Window object creates also an object from a + platform-specific derived class from this class. + */ +class Fl_Gl_Window_Driver { +protected: + Fl_Gl_Window *pWindow; +public: + Fl_Gl_Choice* g() {return pWindow->g;} + void g(Fl_Gl_Choice *c) {pWindow->g = c;} + int mode() {return pWindow->mode_;} + void mode(int m) { pWindow->mode_ = m;} + const int *alist() {return pWindow->alist;} + void alist(const int *l) { pWindow->alist = l;} + void* overlay() {return pWindow->overlay;} + void draw_overlay() {pWindow->draw_overlay();} + + Fl_Gl_Window_Driver(Fl_Gl_Window *win) : pWindow(win) {} + virtual ~Fl_Gl_Window_Driver() {} + static Fl_Gl_Window_Driver *newGlWindowDriver(Fl_Gl_Window *w); + static Fl_Gl_Window_Driver *global(); + virtual int pixels_per_unit() {return 1;} + virtual void before_show(int& need_redraw) {} + virtual void after_show(int need_redraw) {} + virtual void invalidate(); + virtual int mode_(int m, const int *a) {return 0;} + virtual void make_current_before() {} + virtual void make_current_after() {} + virtual void swap_buffers() {} + virtual void resize(int is_a_resize, int w, int h) {} + virtual char swap_type(); + virtual void flush_context() {} + virtual int flush_begin(char& valid_f) {return 0;} + virtual void hide_overlay(void *& overlay) {} + static Fl_Gl_Choice *find_begin(int m, const int *alistp); + // Return one of these structures for a given gl mode. + // The second argument is a glX attribute list, and is used if mode is zero. + // This is not supported on Win32: + virtual Fl_Gl_Choice *find(int mode, const int *alistp) {return NULL;} + virtual GLContext create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer = 0) {return 0;} + virtual void set_gl_context(Fl_Window* w, GLContext context) {} + virtual void delete_gl_context(GLContext) {} + virtual void make_overlay(void* &o); + virtual void hide_overlay() {} + virtual void make_overlay_current() {} + virtual void redraw_overlay() {} + virtual int can_do_overlay() {return 0;} + virtual void waitGL() {} // support for gl_finish() function + virtual void gl_visual(Fl_Gl_Choice*); // support for Fl::gl_visual() function + virtual void gl_start() {} // support for gl_start() function + virtual void* GetProcAddress(const char *procName); // support for glutGetProcAddress() +}; + +#ifdef FL_CFG_GFX_QUARTZ +class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver { + friend class Fl_Gl_Window_Driver; + Fl_Cocoa_Gl_Window_Driver(Fl_Gl_Window *win) : Fl_Gl_Window_Driver(win) {} + virtual int pixels_per_unit(); + virtual void before_show(int& need_redraw); + virtual void after_show(int need_redraw); + virtual int mode_(int m, const int *a); + virtual void make_current_before(); + virtual void swap_buffers(); + virtual void resize(int is_a_resize, int w, int h); + virtual char swap_type(); + virtual void flush_context(); + virtual Fl_Gl_Choice *find(int m, const int *alistp); + virtual GLContext create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer = 0); + virtual void set_gl_context(Fl_Window* w, GLContext context); + virtual void delete_gl_context(GLContext); + virtual void make_overlay_current(); + virtual void redraw_overlay(); + virtual void gl_start(); +}; +#endif // FL_CFG_GFX_QUARTZ + + +#ifdef FL_CFG_GFX_GDI + +class Fl_WinAPI_Gl_Window_Driver : public Fl_Gl_Window_Driver { + friend class Fl_Gl_Window_Driver; + Fl_WinAPI_Gl_Window_Driver(Fl_Gl_Window *win) : Fl_Gl_Window_Driver(win) {} + virtual int mode_(int m, const int *a); + virtual void make_current_after(); + virtual void swap_buffers(); + virtual void invalidate() {} + virtual int flush_begin(char& valid_f); + virtual void hide_overlay(void *& overlay); + virtual Fl_Gl_Choice *find(int m, const int *alistp); + virtual GLContext create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer = 0); + virtual void set_gl_context(Fl_Window* w, GLContext context); + virtual void delete_gl_context(GLContext); + virtual void make_overlay_current(); + virtual void redraw_overlay(); + virtual void* GetProcAddress(const char *procName); +#if HAVE_GL_OVERLAY + virtual int can_do_overlay(); +#endif +}; + +#endif // FL_CFG_GFX_GDI + + +#ifdef FL_CFG_GFX_XLIB +#include <X11/Xutil.h> +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 void before_show(int& need_redraw); + virtual int mode_(int m, const int *a); + virtual void swap_buffers(); + virtual void resize(int is_a_resize, int w, int h); + virtual char swap_type(); + virtual Fl_Gl_Choice *find(int m, const int *alistp); + virtual GLContext create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer = 0); + virtual void set_gl_context(Fl_Window* w, GLContext context); + virtual void delete_gl_context(GLContext); +#if HAVE_GL_OVERLAY + virtual void make_overlay(void *&o); + virtual int can_do_overlay(); + virtual void hide_overlay(); +#endif + virtual void make_overlay_current(); + virtual void redraw_overlay(); + virtual void waitGL(); + virtual void gl_visual(Fl_Gl_Choice*); // support for Fl::gl_visual() + virtual void gl_start(); +public: + static GLContext create_gl_context(XVisualInfo* vis); +}; + +#endif // FL_CFG_GFX_XLIB + +#endif /* Fl_Gl_Window_Driver_H */ + +// +// End of "$Id: Fl_Gl_Window_Driver.H 11662 2016-04-19 16:58:17Z manolo $". +// |
