1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// OpenGL context routines for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2018-02-01 00:17:17 +03:00
|
|
|
// Copyright 1998-2018 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// 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
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 23:14:55 +04:00
|
|
|
|
|
|
|
// You MUST use gl_visual() to select the default visual before doing
|
|
|
|
// show() of any windows. Mesa will crash if you try to use a visual
|
|
|
|
// not returned by glxChooseVisual.
|
|
|
|
|
|
|
|
// This does not work with Fl_Double_Window's! It will try to draw
|
|
|
|
// into the front buffer. Depending on the system this will either
|
|
|
|
// crash or do nothing (when pixmaps are being used as back buffer
|
|
|
|
// and GL is being done by hardware), work correctly (when GL is done
|
|
|
|
// with software, such as Mesa), or draw into the front buffer and
|
|
|
|
// be erased when the buffers are swapped (when double buffer hardware
|
|
|
|
// is being used)
|
|
|
|
|
2016-05-08 09:42:57 +03:00
|
|
|
#include "config_lib.h"
|
1998-10-06 23:14:55 +04:00
|
|
|
#if HAVE_GL
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/fl_draw.H>
|
2014-10-30 12:18:45 +03:00
|
|
|
#include <FL/gl.h>
|
2016-05-13 09:45:40 +03:00
|
|
|
class Fl_Gl_Choice;
|
2016-05-08 09:42:57 +03:00
|
|
|
#include <FL/Fl_Gl_Window.H>
|
|
|
|
#include <FL/Fl_Gl_Window_Driver.H>
|
1998-10-06 23:14:55 +04:00
|
|
|
|
2001-03-14 20:20:02 +03:00
|
|
|
static GLContext context;
|
1998-10-06 23:14:55 +04:00
|
|
|
static int clip_state_number=-1;
|
|
|
|
static int pw, ph;
|
2018-02-07 18:34:44 +03:00
|
|
|
float gl_start_scale = 1;
|
1998-10-06 23:14:55 +04:00
|
|
|
|
2001-12-18 14:00:09 +03:00
|
|
|
static Fl_Gl_Choice* gl_choice;
|
|
|
|
|
2009-04-10 00:44:31 +04:00
|
|
|
/** Creates an OpenGL context */
|
1998-10-06 23:14:55 +04:00
|
|
|
void gl_start() {
|
2018-02-07 18:34:44 +03:00
|
|
|
gl_start_scale = Fl_Display_Device::display_device()->driver()->scale();
|
1998-10-06 23:14:55 +04:00
|
|
|
if (!context) {
|
2001-03-14 20:20:02 +03:00
|
|
|
if (!gl_choice) Fl::gl_visual(0);
|
2016-05-08 09:42:57 +03:00
|
|
|
context = Fl_Gl_Window_Driver::global()->create_gl_context(Fl_Window::current(), gl_choice);
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
2016-05-08 09:42:57 +03:00
|
|
|
Fl_Gl_Window_Driver::global()->set_gl_context(Fl_Window::current(), context);
|
|
|
|
Fl_Gl_Window_Driver::global()->gl_start();
|
2018-02-07 18:34:44 +03:00
|
|
|
if (pw != int(Fl_Window::current()->w() * gl_start_scale) || ph != int(Fl_Window::current()->h() * gl_start_scale)) {
|
|
|
|
pw = int(Fl_Window::current()->w() * gl_start_scale);
|
|
|
|
ph = int(Fl_Window::current()->h() * gl_start_scale);
|
1998-10-06 23:14:55 +04:00
|
|
|
glLoadIdentity();
|
|
|
|
glViewport(0, 0, pw, ph);
|
2018-02-07 18:34:44 +03:00
|
|
|
glOrtho(0, Fl_Window::current()->w(), 0, Fl_Window::current()->h(), -1, 1);
|
1998-10-06 23:14:55 +04:00
|
|
|
glDrawBuffer(GL_FRONT);
|
|
|
|
}
|
2011-02-05 02:32:53 +03:00
|
|
|
if (clip_state_number != fl_graphics_driver->fl_clip_state_number) {
|
|
|
|
clip_state_number = fl_graphics_driver->fl_clip_state_number;
|
1998-10-06 23:14:55 +04:00
|
|
|
int x, y, w, h;
|
|
|
|
if (fl_clip_box(0, 0, Fl_Window::current()->w(), Fl_Window::current()->h(),
|
|
|
|
x, y, w, h)) {
|
2016-04-17 18:36:23 +03:00
|
|
|
fl_clip_region(Fl_Graphics_Driver::default_driver().XRectangleRegion(x,y,w,h));
|
2018-02-07 18:34:44 +03:00
|
|
|
glScissor(x*gl_start_scale, (Fl_Window::current()->h()-(y+h))*gl_start_scale, w*gl_start_scale, h*gl_start_scale);
|
1998-10-06 23:14:55 +04:00
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
} else {
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
}
|
|
|
|
}
|
2018-02-07 18:34:44 +03:00
|
|
|
Fl_Display_Device::display_device()->driver()->scale(1);
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
|
|
|
|
2009-04-10 00:44:31 +04:00
|
|
|
/** Releases an OpenGL context */
|
1998-10-06 23:14:55 +04:00
|
|
|
void gl_finish() {
|
|
|
|
glFlush();
|
2016-05-08 09:42:57 +03:00
|
|
|
Fl_Gl_Window_Driver::global()->waitGL();
|
2018-02-07 18:34:44 +03:00
|
|
|
Fl_Display_Device::display_device()->driver()->scale(gl_start_scale);
|
|
|
|
gl_start_scale = 1;
|
2016-05-08 09:42:57 +03:00
|
|
|
}
|
|
|
|
|
2018-06-23 19:47:40 +03:00
|
|
|
/**
|
2018-06-23 23:50:22 +03:00
|
|
|
\cond DriverDev
|
|
|
|
\addtogroup DriverDeveloper
|
|
|
|
\{
|
2018-06-23 19:47:40 +03:00
|
|
|
*/
|
|
|
|
|
2016-05-08 09:42:57 +03:00
|
|
|
void Fl_Gl_Window_Driver::gl_visual(Fl_Gl_Choice *c) {
|
|
|
|
gl_choice = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FL_CFG_GFX_QUARTZ
|
|
|
|
|
|
|
|
void Fl_Cocoa_Gl_Window_Driver::gl_start() {
|
2016-05-09 19:10:54 +03:00
|
|
|
GLcontext_update(context); // supports window resizing
|
2016-05-08 09:42:57 +03:00
|
|
|
}
|
|
|
|
|
1998-10-06 23:14:55 +04:00
|
|
|
#endif
|
2016-05-08 09:42:57 +03:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef FL_CFG_GFX_XLIB
|
2018-02-01 00:17:17 +03:00
|
|
|
#include <FL/platform.H>
|
2016-05-13 09:45:40 +03:00
|
|
|
#include "Fl_Gl_Choice.H"
|
2016-05-08 09:42:57 +03:00
|
|
|
|
|
|
|
void Fl_X11_Gl_Window_Driver::gl_visual(Fl_Gl_Choice *c) {
|
|
|
|
Fl_Gl_Window_Driver::gl_visual(c);
|
|
|
|
fl_visual = c->vis;
|
|
|
|
fl_colormap = c->colormap;
|
1998-10-06 23:14:55 +04:00
|
|
|
}
|
2008-10-14 03:10:43 +04:00
|
|
|
|
2016-05-08 09:42:57 +03:00
|
|
|
void Fl_X11_Gl_Window_Driver::gl_start() {
|
|
|
|
glXWaitX();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // FL_CFG_GFX_XLIB
|
|
|
|
|
1998-10-06 23:14:55 +04:00
|
|
|
int Fl::gl_visual(int mode, int *alist) {
|
2016-05-08 09:42:57 +03:00
|
|
|
Fl_Gl_Choice *c = Fl_Gl_Window_Driver::global()->find(mode,alist);
|
1998-10-06 23:14:55 +04:00
|
|
|
if (!c) return 0;
|
2016-05-08 09:42:57 +03:00
|
|
|
Fl_Gl_Window_Driver::global()->gl_visual(c);
|
1998-10-06 23:14:55 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2016-05-08 09:42:57 +03:00
|
|
|
|
2018-06-23 19:47:40 +03:00
|
|
|
/**
|
2018-06-23 23:50:22 +03:00
|
|
|
\}
|
|
|
|
\endcond
|
2018-06-23 19:47:40 +03:00
|
|
|
*/
|
|
|
|
|
2016-05-08 09:42:57 +03:00
|
|
|
#endif // HAVE_GL
|
1998-10-20 00:46:58 +04:00
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|