Fl_Gl_Window_Driver.H 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // "$Id: Fl_Gl_Window_Driver.H 12617 2017-12-30 10:43:36Z manolo $"
  3. //
  4. // Definition of class Fl_Gl_Window_Driver, and of its platform-specific derived classes
  5. // for the Fast Light Tool Kit (FLTK).
  6. //
  7. // Copyright 2016-2017 by Bill Spitzak and others.
  8. //
  9. // This library is free software. Distribution and use rights are outlined in
  10. // the file "COPYING" which should have been included with this file. If this
  11. // file is missing or damaged, see the license at:
  12. //
  13. // http://www.fltk.org/COPYING.php
  14. //
  15. // Please report all bugs and problems on the following page:
  16. //
  17. // http://www.fltk.org/str.php
  18. //
  19. #ifndef Fl_Gl_Window_Driver_H
  20. #define Fl_Gl_Window_Driver_H
  21. #if defined(FL_PORTING)
  22. # pragma message "FL_PORTING: please, derive and implement the Fl_Gl_Window_Driver class for your platform"
  23. #endif
  24. #include <FL/Fl_Gl_Window.H>
  25. class Fl_Gl_Choice;
  26. class Fl_Font_Descriptor;
  27. /* The constructor of each Fl_Gl_Window object creates also an object from a
  28. platform-specific derived class from this class.
  29. */
  30. class Fl_Gl_Window_Driver {
  31. protected:
  32. Fl_Gl_Window *pWindow;
  33. public:
  34. Fl_Gl_Choice* g() {return pWindow->g;}
  35. void g(Fl_Gl_Choice *c) {pWindow->g = c;}
  36. int mode() {return pWindow->mode_;}
  37. void mode(int m) { pWindow->mode_ = m;}
  38. const int *alist() {return pWindow->alist;}
  39. void alist(const int *l) { pWindow->alist = l;}
  40. void* overlay() {return pWindow->overlay;}
  41. void draw_overlay() {pWindow->draw_overlay();}
  42. Fl_Gl_Window_Driver(Fl_Gl_Window *win) : pWindow(win) {}
  43. virtual ~Fl_Gl_Window_Driver() {}
  44. static Fl_Gl_Window_Driver *newGlWindowDriver(Fl_Gl_Window *w);
  45. static Fl_Gl_Window_Driver *global();
  46. virtual float pixels_per_unit() {return 1;}
  47. virtual void before_show(int& need_redraw) {}
  48. virtual void after_show(int need_redraw) {}
  49. virtual void invalidate();
  50. virtual int mode_(int m, const int *a) {return 0;}
  51. virtual void make_current_before() {}
  52. virtual void make_current_after() {}
  53. virtual void swap_buffers() {}
  54. virtual void resize(int is_a_resize, int w, int h) {}
  55. virtual char swap_type();
  56. virtual void flush_context() {}
  57. virtual int flush_begin(char& valid_f) {return 0;}
  58. virtual void hide_overlay(void *& overlay) {}
  59. static Fl_Gl_Choice *find_begin(int m, const int *alistp);
  60. // Return one of these structures for a given gl mode.
  61. // The second argument is a glX attribute list, and is used if mode is zero.
  62. // This is not supported on Win32:
  63. virtual Fl_Gl_Choice *find(int mode, const int *alistp) {return NULL;}
  64. virtual GLContext create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer = 0) {return 0;}
  65. virtual void set_gl_context(Fl_Window* w, GLContext context) {}
  66. virtual void delete_gl_context(GLContext) {}
  67. virtual void make_overlay(void* &o);
  68. virtual void hide_overlay() {}
  69. virtual void make_overlay_current() {}
  70. virtual void redraw_overlay() {}
  71. virtual int can_do_overlay() {return 0;}
  72. virtual void waitGL() {} // support for gl_finish() function
  73. virtual void gl_visual(Fl_Gl_Choice*); // support for Fl::gl_visual() function
  74. virtual void gl_start() {} // support for gl_start() function
  75. virtual void* GetProcAddress(const char *procName); // support for glutGetProcAddress()
  76. virtual void draw_string(const char* str, int n); // support for gl_draw()
  77. virtual void get_list(Fl_Font_Descriptor* fd, int r) {} // support for gl_draw() without textures
  78. virtual void gl_bitmap_font(Fl_Font_Descriptor *fl_fontsize) {} // support for gl_font() without textures
  79. virtual int overlay_color(Fl_Color i) {return 0;} // support for gl_color() with HAVE_GL_OVERLAY
  80. };
  81. #ifdef FL_CFG_GFX_QUARTZ
  82. #ifdef __OBJC__
  83. @class NSOpenGLPixelFormat;
  84. #else
  85. class NSOpenGLPixelFormat;
  86. #endif // __OBJC__
  87. class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver {
  88. friend class Fl_Gl_Window_Driver;
  89. Fl_Cocoa_Gl_Window_Driver(Fl_Gl_Window *win) : Fl_Gl_Window_Driver(win) {}
  90. virtual float pixels_per_unit();
  91. virtual void before_show(int& need_redraw);
  92. virtual void after_show(int need_redraw);
  93. virtual int mode_(int m, const int *a);
  94. virtual void make_current_before();
  95. virtual void swap_buffers();
  96. virtual void resize(int is_a_resize, int w, int h);
  97. virtual char swap_type();
  98. virtual void flush_context();
  99. virtual Fl_Gl_Choice *find(int m, const int *alistp);
  100. virtual GLContext create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer = 0);
  101. virtual void set_gl_context(Fl_Window* w, GLContext context);
  102. virtual void delete_gl_context(GLContext);
  103. virtual void make_overlay_current();
  104. virtual void redraw_overlay();
  105. virtual void gl_start();
  106. virtual void draw_string(const char* str, int n);
  107. static NSOpenGLContext* create_GLcontext_for_window(NSOpenGLPixelFormat *pixelformat, NSOpenGLContext *shared_ctx, Fl_Window *window);
  108. static NSOpenGLPixelFormat *mode_to_NSOpenGLPixelFormat(int mode, const int*); // uses Objective-c
  109. static void GLcontext_update(NSOpenGLContext*); // uses Objective-c
  110. static void GLcontext_release(NSOpenGLContext*); // uses Objective-c
  111. static void GLcontext_makecurrent(NSOpenGLContext*); // uses Objective-c
  112. static void GL_cleardrawable(void); // uses Objective-c
  113. };
  114. #endif // FL_CFG_GFX_QUARTZ
  115. #ifdef FL_CFG_GFX_GDI
  116. class Fl_WinAPI_Gl_Window_Driver : public Fl_Gl_Window_Driver {
  117. friend class Fl_Gl_Window_Driver;
  118. Fl_WinAPI_Gl_Window_Driver(Fl_Gl_Window *win) : Fl_Gl_Window_Driver(win) {}
  119. virtual float pixels_per_unit();
  120. virtual int mode_(int m, const int *a);
  121. virtual void make_current_after();
  122. virtual void swap_buffers();
  123. virtual void invalidate() {}
  124. virtual int flush_begin(char& valid_f);
  125. virtual void hide_overlay(void *& overlay);
  126. virtual Fl_Gl_Choice *find(int m, const int *alistp);
  127. virtual GLContext create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer = 0);
  128. virtual void set_gl_context(Fl_Window* w, GLContext context);
  129. virtual void delete_gl_context(GLContext);
  130. virtual void make_overlay_current();
  131. virtual void redraw_overlay();
  132. virtual void* GetProcAddress(const char *procName);
  133. virtual void gl_bitmap_font(Fl_Font_Descriptor *fl_fontsize);
  134. virtual void get_list(Fl_Font_Descriptor *fd, int r);
  135. #if HAVE_GL_OVERLAY
  136. virtual int can_do_overlay();
  137. virtual int overlay_color(Fl_Color i);
  138. #endif
  139. };
  140. #endif // FL_CFG_GFX_GDI
  141. #ifdef FL_CFG_GFX_XLIB
  142. #include <X11/Xutil.h>
  143. class Fl_X11_Gl_Window_Driver : public Fl_Gl_Window_Driver {
  144. friend class Fl_Gl_Window_Driver;
  145. Fl_X11_Gl_Window_Driver(Fl_Gl_Window *win) : Fl_Gl_Window_Driver(win) {}
  146. virtual float pixels_per_unit();
  147. virtual void before_show(int& need_redraw);
  148. virtual int mode_(int m, const int *a);
  149. virtual void swap_buffers();
  150. virtual void resize(int is_a_resize, int w, int h);
  151. virtual char swap_type();
  152. virtual Fl_Gl_Choice *find(int m, const int *alistp);
  153. virtual GLContext create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer = 0);
  154. virtual void set_gl_context(Fl_Window* w, GLContext context);
  155. virtual void delete_gl_context(GLContext);
  156. #if HAVE_GL_OVERLAY
  157. virtual void make_overlay(void *&o);
  158. virtual int can_do_overlay();
  159. virtual void hide_overlay();
  160. virtual int overlay_color(Fl_Color i);
  161. #endif
  162. virtual void make_overlay_current();
  163. virtual void redraw_overlay();
  164. virtual void waitGL();
  165. virtual void gl_visual(Fl_Gl_Choice*); // support for Fl::gl_visual()
  166. virtual void gl_start();
  167. virtual void gl_bitmap_font(Fl_Font_Descriptor *fl_fontsize);
  168. virtual void get_list(Fl_Font_Descriptor *fd, int r);
  169. public:
  170. static GLContext create_gl_context(XVisualInfo* vis);
  171. };
  172. #endif // FL_CFG_GFX_XLIB
  173. #endif /* Fl_Gl_Window_Driver_H */
  174. //
  175. // End of "$Id: Fl_Gl_Window_Driver.H 12617 2017-12-30 10:43:36Z manolo $".
  176. //