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 visual selection code for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2009-01-02 00:28:26 +03:00
|
|
|
// Copyright 1998-2009 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
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 22:21:25 +04:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#if HAVE_GL
|
|
|
|
|
2003-07-23 18:38:00 +04:00
|
|
|
# include <FL/Fl.H>
|
|
|
|
# include <FL/x.H>
|
|
|
|
# include <stdlib.h>
|
|
|
|
# include "Fl_Gl_Choice.H"
|
2004-05-16 02:58:19 +04:00
|
|
|
# include <FL/gl_draw.H>
|
2003-07-23 18:38:00 +04:00
|
|
|
# include "flstring.h"
|
2008-09-19 21:40:20 +04:00
|
|
|
# include <FL/fl_utf8.h>
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2004-09-10 01:34:48 +04:00
|
|
|
# ifdef __APPLE__
|
2003-07-23 18:38:00 +04:00
|
|
|
# include <FL/Fl_Window.H>
|
|
|
|
# endif
|
2001-12-06 03:17:47 +03:00
|
|
|
|
2005-09-13 03:03:34 +04:00
|
|
|
# ifdef WIN32
|
|
|
|
void fl_save_dc(HWND, HDC);
|
|
|
|
# endif
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
static Fl_Gl_Choice *first;
|
|
|
|
|
2009-03-22 22:21:34 +03:00
|
|
|
// this assumes one of the two arguments is zero:
|
1998-10-06 22:21:25 +04:00
|
|
|
// We keep the list system in Win32 to stay compatible and interpret
|
|
|
|
// the list later...
|
2002-08-09 07:17:30 +04:00
|
|
|
Fl_Gl_Choice *Fl_Gl_Choice::find(int m, const int *alistp) {
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Gl_Choice *g;
|
|
|
|
|
|
|
|
for (g = first; g; g = g->next)
|
2002-08-09 07:17:30 +04:00
|
|
|
if (g->mode == m && g->alist == alistp)
|
1998-10-06 22:21:25 +04:00
|
|
|
return g;
|
|
|
|
|
2008-10-14 03:10:43 +04:00
|
|
|
#if defined(USE_X11)
|
2001-12-18 14:00:09 +03:00
|
|
|
const int *blist;
|
|
|
|
int list[32];
|
|
|
|
|
2002-08-09 07:17:30 +04:00
|
|
|
if (alistp)
|
|
|
|
blist = alistp;
|
2001-12-18 14:00:09 +03:00
|
|
|
else {
|
|
|
|
int n = 0;
|
2002-08-09 07:17:30 +04:00
|
|
|
if (m & FL_INDEX) {
|
2008-10-14 03:10:43 +04:00
|
|
|
list[n++] = GLX_BUFFER_SIZE;
|
2001-12-18 14:00:09 +03:00
|
|
|
list[n++] = 8; // glut tries many sizes, but this should work...
|
|
|
|
} else {
|
2008-10-14 03:10:43 +04:00
|
|
|
list[n++] = GLX_RGBA;
|
|
|
|
list[n++] = GLX_GREEN_SIZE;
|
2002-08-09 07:17:30 +04:00
|
|
|
list[n++] = (m & FL_RGB8) ? 8 : 1;
|
|
|
|
if (m & FL_ALPHA) {
|
2008-10-14 03:10:43 +04:00
|
|
|
list[n++] = GLX_ALPHA_SIZE;
|
2004-09-24 20:00:11 +04:00
|
|
|
list[n++] = (m & FL_RGB8) ? 8 : 1;
|
2001-12-18 14:00:09 +03:00
|
|
|
}
|
2002-08-09 07:17:30 +04:00
|
|
|
if (m & FL_ACCUM) {
|
2008-10-14 03:10:43 +04:00
|
|
|
list[n++] = GLX_ACCUM_GREEN_SIZE;
|
2001-12-18 14:00:09 +03:00
|
|
|
list[n++] = 1;
|
2002-08-09 07:17:30 +04:00
|
|
|
if (m & FL_ALPHA) {
|
2008-10-14 03:10:43 +04:00
|
|
|
list[n++] = GLX_ACCUM_ALPHA_SIZE;
|
2001-12-18 14:00:09 +03:00
|
|
|
list[n++] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-08-09 07:17:30 +04:00
|
|
|
if (m & FL_DOUBLE) {
|
2008-10-14 03:10:43 +04:00
|
|
|
list[n++] = GLX_DOUBLEBUFFER;
|
2001-12-18 14:00:09 +03:00
|
|
|
}
|
2002-08-09 07:17:30 +04:00
|
|
|
if (m & FL_DEPTH) {
|
2008-10-14 03:10:43 +04:00
|
|
|
list[n++] = GLX_DEPTH_SIZE; list[n++] = 1;
|
2001-12-18 14:00:09 +03:00
|
|
|
}
|
2002-08-09 07:17:30 +04:00
|
|
|
if (m & FL_STENCIL) {
|
2008-10-14 03:10:43 +04:00
|
|
|
list[n++] = GLX_STENCIL_SIZE; list[n++] = 1;
|
2001-12-18 14:00:09 +03:00
|
|
|
}
|
2002-08-09 07:17:30 +04:00
|
|
|
if (m & FL_STEREO) {
|
2008-10-14 03:10:43 +04:00
|
|
|
list[n++] = GLX_STEREO;
|
|
|
|
}
|
|
|
|
# if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample)
|
|
|
|
if (m & FL_MULTISAMPLE) {
|
|
|
|
list[n++] = GLX_SAMPLES_SGIS;
|
|
|
|
list[n++] = 4; // value Glut uses
|
2002-03-25 19:41:01 +03:00
|
|
|
}
|
2003-07-23 18:38:00 +04:00
|
|
|
# endif
|
2008-10-14 03:10:43 +04:00
|
|
|
list[n] = 0;
|
2001-12-18 14:00:09 +03:00
|
|
|
blist = list;
|
|
|
|
}
|
2008-10-14 03:10:43 +04:00
|
|
|
|
2001-12-18 14:00:09 +03:00
|
|
|
fl_open_display();
|
2008-10-14 03:10:43 +04:00
|
|
|
XVisualInfo *visp = glXChooseVisual(fl_display, fl_screen, (int *)blist);
|
|
|
|
if (!visp) {
|
|
|
|
# if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample)
|
|
|
|
if (m&FL_MULTISAMPLE) return find(m&~FL_MULTISAMPLE,0);
|
|
|
|
# endif
|
|
|
|
return 0;
|
|
|
|
}
|
2004-08-25 04:20:27 +04:00
|
|
|
|
|
|
|
#elif defined(__APPLE_QUARTZ__)
|
2004-09-10 01:34:48 +04:00
|
|
|
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
|
2004-08-25 04:20:27 +04:00
|
|
|
const int *blist;
|
|
|
|
int list[32];
|
|
|
|
|
|
|
|
if (alistp)
|
|
|
|
blist = alistp;
|
|
|
|
else {
|
|
|
|
int n = 0;
|
|
|
|
if (m & FL_INDEX) {
|
|
|
|
list[n++] = AGL_BUFFER_SIZE;
|
|
|
|
list[n++] = 8; // glut tries many sizes, but this should work...
|
|
|
|
} else {
|
|
|
|
list[n++] = AGL_RGBA;
|
|
|
|
list[n++] = AGL_GREEN_SIZE;
|
|
|
|
list[n++] = (m & FL_RGB8) ? 8 : 1;
|
|
|
|
if (m & FL_ALPHA) {
|
|
|
|
list[n++] = AGL_ALPHA_SIZE;
|
2004-09-24 20:00:11 +04:00
|
|
|
list[n++] = (m & FL_RGB8) ? 8 : 1;
|
2004-08-25 04:20:27 +04:00
|
|
|
}
|
|
|
|
if (m & FL_ACCUM) {
|
|
|
|
list[n++] = AGL_ACCUM_GREEN_SIZE;
|
|
|
|
list[n++] = 1;
|
|
|
|
if (m & FL_ALPHA) {
|
|
|
|
list[n++] = AGL_ACCUM_ALPHA_SIZE;
|
|
|
|
list[n++] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m & FL_DOUBLE) {
|
|
|
|
list[n++] = AGL_DOUBLEBUFFER;
|
|
|
|
}
|
|
|
|
if (m & FL_DEPTH) {
|
|
|
|
list[n++] = AGL_DEPTH_SIZE; list[n++] = 24;
|
|
|
|
}
|
|
|
|
if (m & FL_STENCIL) {
|
|
|
|
list[n++] = AGL_STENCIL_SIZE; list[n++] = 1;
|
|
|
|
}
|
|
|
|
# ifdef AGL_STEREO
|
|
|
|
if (m & FL_STEREO) {
|
|
|
|
list[n++] = AGL_STEREO;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
list[n] = AGL_NONE;
|
|
|
|
blist = list;
|
|
|
|
}
|
|
|
|
fl_open_display();
|
|
|
|
AGLPixelFormat fmt = aglChoosePixelFormat(NULL, 0, (GLint*)blist);
|
|
|
|
if (!fmt) return 0;
|
2001-12-18 14:00:09 +03:00
|
|
|
|
2008-10-14 03:10:43 +04:00
|
|
|
#elif defined(WIN32)
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2000-03-18 13:04:18 +03:00
|
|
|
// Replacement for ChoosePixelFormat() that finds one with an overlay
|
|
|
|
// if possible:
|
|
|
|
if (!fl_gc) fl_GetDC(0);
|
|
|
|
int pixelformat = 0;
|
|
|
|
PIXELFORMATDESCRIPTOR chosen_pfd;
|
|
|
|
for (int i = 1; ; i++) {
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
if (!DescribePixelFormat(fl_gc, i, sizeof(pfd), &pfd)) break;
|
|
|
|
// continue if it does not satisfy our requirements:
|
|
|
|
if (~pfd.dwFlags & (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL)) continue;
|
2002-08-09 07:17:30 +04:00
|
|
|
if (pfd.iPixelType != ((m&FL_INDEX)?PFD_TYPE_COLORINDEX:PFD_TYPE_RGBA)) continue;
|
|
|
|
if ((m & FL_ALPHA) && !pfd.cAlphaBits) continue;
|
|
|
|
if ((m & FL_ACCUM) && !pfd.cAccumBits) continue;
|
|
|
|
if ((!(m & FL_DOUBLE)) != (!(pfd.dwFlags & PFD_DOUBLEBUFFER))) continue;
|
|
|
|
if ((!(m & FL_STEREO)) != (!(pfd.dwFlags & PFD_STEREO))) continue;
|
|
|
|
if ((m & FL_DEPTH) && !pfd.cDepthBits) continue;
|
|
|
|
if ((m & FL_STENCIL) && !pfd.cStencilBits) continue;
|
2000-03-18 13:04:18 +03:00
|
|
|
// see if better than the one we have already:
|
|
|
|
if (pixelformat) {
|
2004-05-14 01:02:41 +04:00
|
|
|
// offering non-generic rendering is better (read: hardware accelleration)
|
|
|
|
if (!(chosen_pfd.dwFlags & PFD_GENERIC_FORMAT) &&
|
|
|
|
(pfd.dwFlags & PFD_GENERIC_FORMAT)) continue;
|
2000-03-18 13:04:18 +03:00
|
|
|
// offering overlay is better:
|
2004-05-14 01:02:41 +04:00
|
|
|
else if (!(chosen_pfd.bReserved & 15) && (pfd.bReserved & 15)) {}
|
2000-03-18 13:04:18 +03:00
|
|
|
// otherwise more bit planes is better:
|
2003-09-20 22:45:55 +04:00
|
|
|
else if (chosen_pfd.cColorBits > pfd.cColorBits) continue;
|
|
|
|
else if (chosen_pfd.cDepthBits > pfd.cDepthBits) continue;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2000-03-18 13:04:18 +03:00
|
|
|
pixelformat = i;
|
|
|
|
chosen_pfd = pfd;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2000-03-18 13:04:18 +03:00
|
|
|
//printf("Chosen pixel format is %d\n", pixelformat);
|
|
|
|
if (!pixelformat) return 0;
|
2008-10-14 03:10:43 +04:00
|
|
|
#else
|
|
|
|
# error platform unsupported
|
|
|
|
#endif
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
g = new Fl_Gl_Choice;
|
2002-08-09 07:17:30 +04:00
|
|
|
g->mode = m;
|
|
|
|
g->alist = alistp;
|
1998-10-06 22:21:25 +04:00
|
|
|
g->next = first;
|
|
|
|
first = g;
|
|
|
|
|
2008-10-14 03:10:43 +04:00
|
|
|
#if defined(USE_X11)
|
2002-08-09 07:17:30 +04:00
|
|
|
g->vis = visp;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
if (/*MaxCmapsOfScreen(ScreenOfDisplay(fl_display,fl_screen))==1 && */
|
2002-08-09 07:17:30 +04:00
|
|
|
visp->visualid == fl_visual->visualid &&
|
2008-09-11 03:56:49 +04:00
|
|
|
!fl_getenv("MESA_PRIVATE_CMAP"))
|
1998-10-06 22:21:25 +04:00
|
|
|
g->colormap = fl_colormap;
|
|
|
|
else
|
|
|
|
g->colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen),
|
2002-08-09 07:17:30 +04:00
|
|
|
visp->visual, AllocNone);
|
2008-10-14 03:10:43 +04:00
|
|
|
# elif defined(WIN32)
|
|
|
|
g->pixelformat = pixelformat;
|
|
|
|
g->pfd = chosen_pfd;
|
|
|
|
# elif defined(__APPLE_QUARTZ__)
|
|
|
|
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
|
|
|
|
g->pixelformat = fmt;
|
|
|
|
# else
|
|
|
|
# error unsupported platform
|
2003-07-23 18:38:00 +04:00
|
|
|
# endif
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
2003-07-17 09:52:47 +04:00
|
|
|
static GLContext *context_list = 0;
|
|
|
|
static int nContext = 0, NContext = 0;
|
|
|
|
|
|
|
|
static void add_context(GLContext ctx) {
|
|
|
|
if (!ctx) return;
|
|
|
|
if (nContext==NContext) {
|
|
|
|
if (!NContext) NContext = 8;
|
|
|
|
NContext *= 2;
|
|
|
|
context_list = (GLContext*)realloc(
|
|
|
|
context_list, NContext*sizeof(GLContext));
|
|
|
|
}
|
|
|
|
context_list[nContext++] = ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void del_context(GLContext ctx) {
|
|
|
|
int i;
|
|
|
|
for (i=0; i<nContext; i++) {
|
|
|
|
if (context_list[i]==ctx) {
|
|
|
|
memmove(context_list+i, context_list+i+1,
|
|
|
|
(nContext-i-1) * sizeof(GLContext));
|
|
|
|
context_list[--nContext] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-05-16 02:58:19 +04:00
|
|
|
if (!nContext) gl_remove_displaylist_fonts();
|
2003-07-17 09:52:47 +04:00
|
|
|
}
|
2001-03-14 20:20:02 +03:00
|
|
|
|
2008-10-14 03:10:43 +04:00
|
|
|
#if defined(USE_X11)
|
|
|
|
|
|
|
|
GLContext fl_create_gl_context(XVisualInfo* vis) {
|
2009-06-30 17:38:45 +04:00
|
|
|
GLContext shared_ctx = 0;
|
2009-06-30 22:48:22 +04:00
|
|
|
if (context_list && nContext) shared_ctx = context_list[0];
|
2008-10-14 03:10:43 +04:00
|
|
|
GLContext context = glXCreateContext(fl_display, vis, shared_ctx, 1);
|
|
|
|
if (context)
|
|
|
|
add_context(context);
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(WIN32)
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2001-03-14 20:20:02 +03:00
|
|
|
GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer) {
|
|
|
|
Fl_X* i = Fl_X::i(window);
|
|
|
|
HDC hdc = i->private_dc;
|
|
|
|
if (!hdc) {
|
|
|
|
hdc = i->private_dc = GetDCEx(i->xid, 0, DCX_CACHE);
|
2005-09-13 03:03:34 +04:00
|
|
|
fl_save_dc(i->xid, hdc);
|
2001-12-19 21:15:34 +03:00
|
|
|
SetPixelFormat(hdc, g->pixelformat, (PIXELFORMATDESCRIPTOR*)(&g->pfd));
|
2003-07-23 18:38:00 +04:00
|
|
|
# if USE_COLORMAP
|
2001-12-19 21:15:34 +03:00
|
|
|
if (fl_palette) SelectPalette(hdc, fl_palette, FALSE);
|
2003-07-23 18:38:00 +04:00
|
|
|
# endif
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2001-03-14 20:20:02 +03:00
|
|
|
GLContext context =
|
|
|
|
layer ? wglCreateLayerContext(hdc, layer) : wglCreateContext(hdc);
|
|
|
|
if (context) {
|
2009-06-30 17:38:45 +04:00
|
|
|
if (context_list && nContext)
|
2003-07-17 09:52:47 +04:00
|
|
|
wglShareLists(context_list[0], context);
|
|
|
|
add_context(context);
|
2001-03-14 20:20:02 +03:00
|
|
|
}
|
|
|
|
return context;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
1999-09-16 09:34:27 +04:00
|
|
|
|
2004-08-25 04:20:27 +04:00
|
|
|
# elif defined(__APPLE_QUARTZ__)
|
2009-12-07 01:21:55 +03:00
|
|
|
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
|
|
|
|
GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer) {
|
|
|
|
GLContext context, shared_ctx = 0;
|
|
|
|
if (context_list && nContext) shared_ctx = context_list[0];
|
|
|
|
context = aglCreateContext( g->pixelformat, shared_ctx);
|
|
|
|
if (!context) return 0;
|
|
|
|
add_context((GLContext)context);
|
|
|
|
if ( window->parent() ) {
|
|
|
|
#ifdef __APPLE_COCOA__
|
|
|
|
int H = window->window()->h();
|
|
|
|
GLint rect[] = { window->x(), H-window->h()-window->y(), window->w(), window->h() };
|
|
|
|
#else
|
|
|
|
Rect wrect;
|
|
|
|
GetWindowPortBounds( fl_xid(window), &wrect );
|
|
|
|
GLint rect[] = { window->x(), wrect.bottom-window->h()-window->y(), window->w(), window->h() };
|
|
|
|
#endif
|
|
|
|
aglSetInteger( (GLContext)context, AGL_BUFFER_RECT, rect );
|
|
|
|
aglEnable( (GLContext)context, AGL_BUFFER_RECT );
|
|
|
|
}
|
|
|
|
#if defined(__APPLE_COCOA__)
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
|
|
|
aglSetWindowRef(context, MACwindowRef(window) );
|
|
|
|
#else
|
|
|
|
aglSetDrawable( context, GetWindowPort( MACwindowRef(window) ) );
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
aglSetDrawable( context, GetWindowPort( fl_xid(window) ) );
|
|
|
|
#endif
|
|
|
|
return (context);
|
2004-08-25 04:20:27 +04:00
|
|
|
}
|
2003-07-23 18:38:00 +04:00
|
|
|
# else
|
2008-10-14 03:10:43 +04:00
|
|
|
# error unsupported platform
|
2003-07-23 18:38:00 +04:00
|
|
|
# endif
|
1999-09-16 09:34:27 +04:00
|
|
|
|
2001-03-14 20:20:02 +03:00
|
|
|
static GLContext cached_context;
|
1999-09-16 09:34:27 +04:00
|
|
|
static Fl_Window* cached_window;
|
|
|
|
|
2001-03-14 20:20:02 +03:00
|
|
|
void fl_set_gl_context(Fl_Window* w, GLContext context) {
|
|
|
|
if (context != cached_context || w != cached_window) {
|
|
|
|
cached_context = context;
|
1999-09-16 09:34:27 +04:00
|
|
|
cached_window = w;
|
2008-10-14 03:10:43 +04:00
|
|
|
# if defined(USE_X11)
|
|
|
|
glXMakeCurrent(fl_display, fl_xid(w), context);
|
|
|
|
# elif defined(WIN32)
|
2001-03-14 20:20:02 +03:00
|
|
|
wglMakeCurrent(Fl_X::i(w)->private_dc, context);
|
2004-08-25 04:20:27 +04:00
|
|
|
# elif defined(__APPLE_QUARTZ__)
|
2004-09-10 01:34:48 +04:00
|
|
|
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
|
2004-08-25 04:20:27 +04:00
|
|
|
if ( w->parent() ) { //: resize our GL buffer rectangle
|
2009-12-07 01:21:55 +03:00
|
|
|
#ifdef __APPLE_COCOA__
|
|
|
|
int H = w->window()->h();
|
|
|
|
GLint rect[] = { w->x(), H-w->h()-w->y(), w->w(), w->h() };
|
|
|
|
#else
|
|
|
|
Rect wrect;
|
|
|
|
GetWindowPortBounds( fl_xid(w), &wrect );
|
2004-08-25 04:20:27 +04:00
|
|
|
GLint rect[] = { w->x(), wrect.bottom-w->h()-w->y(), w->w(), w->h() };
|
2009-12-07 01:21:55 +03:00
|
|
|
#endif
|
2004-08-25 04:20:27 +04:00
|
|
|
aglSetInteger( context, AGL_BUFFER_RECT, rect );
|
|
|
|
aglEnable( context, AGL_BUFFER_RECT );
|
|
|
|
}
|
2009-12-07 01:21:55 +03:00
|
|
|
#if defined(__APPLE_COCOA__)
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
|
|
|
aglSetWindowRef(context, MACwindowRef(w) );
|
|
|
|
#else
|
|
|
|
aglSetDrawable( context, GetWindowPort( MACwindowRef(w) ) );
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
aglSetDrawable( context, GetWindowPort( fl_xid(w) ) );
|
|
|
|
#endif
|
2004-08-25 04:20:27 +04:00
|
|
|
aglSetCurrentContext(context);
|
2003-07-23 18:38:00 +04:00
|
|
|
# else
|
2008-10-14 03:10:43 +04:00
|
|
|
# error unsupported platform
|
2003-07-23 18:38:00 +04:00
|
|
|
# endif
|
1999-09-16 09:34:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void fl_no_gl_context() {
|
|
|
|
cached_context = 0;
|
|
|
|
cached_window = 0;
|
2008-10-14 03:10:43 +04:00
|
|
|
# if defined(USE_X11)
|
|
|
|
glXMakeCurrent(fl_display, 0, 0);
|
|
|
|
# elif defined(WIN32)
|
1999-09-16 09:34:27 +04:00
|
|
|
wglMakeCurrent(0, 0);
|
2004-08-25 04:20:27 +04:00
|
|
|
# elif defined(__APPLE_QUARTZ__)
|
2004-09-10 01:34:48 +04:00
|
|
|
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
|
2009-06-30 17:38:45 +04:00
|
|
|
AGLContext ctx = aglGetCurrentContext();
|
2010-03-11 01:36:23 +03:00
|
|
|
# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
|
|
|
if (ctx) aglSetWindowRef(ctx, NULL);
|
|
|
|
# else
|
2009-06-30 17:38:45 +04:00
|
|
|
if (ctx) aglSetDrawable(ctx, NULL);
|
2010-03-11 01:36:23 +03:00
|
|
|
# endif
|
2001-11-27 20:44:08 +03:00
|
|
|
aglSetCurrentContext(0);
|
2003-07-23 18:38:00 +04:00
|
|
|
# else
|
2008-10-14 03:10:43 +04:00
|
|
|
# error unsupported platform
|
2003-07-23 18:38:00 +04:00
|
|
|
# endif
|
1999-09-16 09:34:27 +04:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2001-03-14 20:20:02 +03:00
|
|
|
void fl_delete_gl_context(GLContext context) {
|
|
|
|
if (cached_context == context) fl_no_gl_context();
|
2008-10-14 03:10:43 +04:00
|
|
|
# if defined(USE_X11)
|
|
|
|
glXDestroyContext(fl_display, context);
|
|
|
|
# elif defined(WIN32)
|
2003-07-17 09:52:47 +04:00
|
|
|
wglDeleteContext(context);
|
2004-08-25 04:20:27 +04:00
|
|
|
# elif defined(__APPLE_QUARTZ__)
|
2004-09-10 01:34:48 +04:00
|
|
|
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
|
2004-08-25 04:20:27 +04:00
|
|
|
aglDestroyContext( context );
|
2003-07-23 18:38:00 +04:00
|
|
|
# else
|
2008-10-14 03:10:43 +04:00
|
|
|
# error unsupported platform
|
2003-07-23 18:38:00 +04:00
|
|
|
# endif
|
2003-07-17 09:52:47 +04:00
|
|
|
del_context(context);
|
2001-03-14 20:20:02 +03:00
|
|
|
}
|
|
|
|
|
2003-07-23 18:38:00 +04: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
|
|
|
//
|