1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
//
// "$Id$"
//
// OpenGL overlay code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 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
//
#include <config.h>
#if HAVE_GL
#include <FL/Fl.H>
#include <FL/x.H>
#include "Fl_Gl_Choice.H"
#include <FL/Fl_Gl_Window.H>
#include <stdlib.h>
#if !HAVE_GL_OVERLAY
int Fl_Gl_Window::can_do_overlay() {return 0;}
void Fl_Gl_Window::make_overlay() {overlay = this;}
#else
// Methods on Fl_Gl_Window that create an overlay window. Because
// many programs don't need the overlay, this is separated into this
// source file so it is not linked in if not used.
// Under X this is done by creating another window, of class _Fl_Gl_Overlay
// which is a subclass of Fl_Gl_Window except it uses the overlay planes.
// A pointer to this is stored in the "overlay" pointer of the Fl_Gl_Window.
// Under win32 another GLX context is created to draw into the overlay
// and it is stored in the "overlay" pointer.
// In both cases if overlay hardware is unavailable, the overlay is
// "faked" by drawing into the main layers. This is indicated by
// setting overlay == this.
#ifndef WIN32
////////////////////////////////////////////////////////////////
// X version
extern XVisualInfo *fl_find_overlay_visual();
extern XVisualInfo *fl_overlay_visual;
extern Colormap fl_overlay_colormap;
extern unsigned long fl_transparent_pixel;
extern uchar fl_overlay;
class _Fl_Gl_Overlay : public Fl_Gl_Window {
void flush();
void draw();
public:
void show();
_Fl_Gl_Overlay(int x, int y, int w, int h) :
Fl_Gl_Window(x,y,w,h) {
set_flag(INACTIVE);
}
};
void _Fl_Gl_Overlay::flush() {
make_current();
#ifdef BOXX_BUGS
// The BoXX overlay is broken and you must not call swap-buffers. This
// code will make it work, but we lose because machines that do support
// double-buffered overlays will blink when they don't have to
glDrawBuffer(GL_FRONT);
draw();
#else
draw();
swap_buffers();
#endif
glFlush();
valid(1);
}
void _Fl_Gl_Overlay::draw() {
if (!valid()) glClearIndex((GLfloat)fl_transparent_pixel);
if (damage() != FL_DAMAGE_EXPOSE) glClear(GL_COLOR_BUFFER_BIT);
Fl_Gl_Window *w = (Fl_Gl_Window *)parent();
uchar save_valid = w->valid();
w->valid(valid());
fl_overlay = 1;
w->draw_overlay();
fl_overlay = 0;
valid(w->valid());
w->valid(save_valid);
}
void _Fl_Gl_Overlay::show() {
if (!shown()) {
fl_background_pixel = int(fl_transparent_pixel);
Fl_X::make_xid(this, fl_overlay_visual, fl_overlay_colormap);
fl_background_pixel = -1;
// find the outermost window to tell wm about the colormap:
Fl_Window *w = window();
for (;;) {Fl_Window *w1 = w->window(); if (!w1) break; w = w1;}
XSetWMColormapWindows(fl_display, fl_xid(w), &(Fl_X::i(this)->xid), 1);
context(fl_create_gl_context(fl_overlay_visual), 1);
valid(0);
}
Fl_Gl_Window::show();
}
int Fl_Gl_Window::can_do_overlay() {
return fl_find_overlay_visual() != 0;
}
void Fl_Gl_Window::make_overlay() {
if (overlay) return;
if (can_do_overlay()) {
_Fl_Gl_Overlay* o = new _Fl_Gl_Overlay(0,0,w(),h());
overlay = o;
add(*o);
o->show();
} else {
overlay = this; // fake the overlay
}
}
#else
////////////////////////////////////////////////////////////////
// WIN32 version:
//static COLORREF *palette;
extern int fl_overlay_depth;
void Fl_Gl_Window::make_overlay() {
if (overlay) return;
GLContext context = fl_create_gl_context(this, g, 1);
if (!context) {overlay = this; return;} // fake the overlay
HDC hdc = Fl_X::i(this)->private_dc;
overlay = context;
LAYERPLANEDESCRIPTOR pfd;
wglDescribeLayerPlane(hdc, g->pixelformat, 1, sizeof(pfd), &pfd);
if (!pfd.iPixelType) {
; // full-color overlay
} else {
fl_overlay_depth = pfd.cColorBits; // used by gl_color()
if (fl_overlay_depth > 8) fl_overlay_depth = 8;
COLORREF palette[256];
int n = (1<<fl_overlay_depth)-1;
// copy all colors except #0 into the overlay palette:
for (int i = 0; i <= n; i++) {
uchar r,g,b; Fl::get_color((Fl_Color)i,r,g,b);
palette[i] = RGB(r,g,b);
}
// always provide black & white in the last 2 pixels:
if (fl_overlay_depth < 8) {
palette[n-1] = RGB(0,0,0);
palette[n] = RGB(255,255,255);
}
// and use it:
wglSetLayerPaletteEntries(hdc, 1, 1, n, palette+1);
wglRealizeLayerPalette(hdc, 1, TRUE);
}
valid(0);
return;
}
int Fl_Gl_Window::can_do_overlay() {
if (!g) {
g = Fl_Gl_Choice::find(mode_,alist);
if (!g) return 0;
}
return (g->pfd.bReserved & 15) != 0;
}
////////////////////////////////////////////////////////////////
#endif
#endif
void Fl_Gl_Window::redraw_overlay() {
if (!shown()) return;
make_overlay();
#ifdef __APPLE__
redraw();
#else
#ifndef WIN32
if (overlay != this)
((Fl_Gl_Window*)overlay)->redraw();
else
#endif
damage(FL_DAMAGE_OVERLAY);
#endif
}
void Fl_Gl_Window::make_overlay_current() {
make_overlay();
#ifdef __APPLE__
// this is not very useful, but unfortunately, Apple decided
// that front buffer drawing can no longer (OS X 10.4) be
// supported on their platforms.
make_current();
#else
#if HAVE_GL_OVERLAY
if (overlay != this) {
#ifdef WIN32
fl_set_gl_context(this, (GLContext)overlay);
// if (fl_overlay_depth)
// wglRealizeLayerPalette(Fl_X::i(this)->private_dc, 1, TRUE);
#else
((Fl_Gl_Window*)overlay)->make_current();
#endif
} else
#endif
glDrawBuffer(GL_FRONT);
#endif
}
/** Hides the window if it is not this window, does nothing in WIN32. */
void Fl_Gl_Window::hide_overlay() {
#if HAVE_GL_OVERLAY
#ifdef WIN32
// nothing needs to be done? Or should it be erased?
#else
if (overlay && overlay!=this) ((Fl_Gl_Window*)overlay)->hide();
#endif
#endif
}
#endif
//
// End of "$Id$".
//
|