OpenGL overlays now work on NT. Tested on several different cards.

They work best on 8-bit overlays like the SGI 320 has.  On cards with
fewer bits you get only a few colors, really only FL_BLACK, FL_RED, and
FL_WHITE are guaranteed to work.  This could be improved but would mean
copying the ugly X colormap allocation code.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1048 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Bill Spitzak 2000-03-24 08:42:03 +00:00
parent 7851ae3252
commit eeaa7f7ae0
3 changed files with 91 additions and 61 deletions

View File

@ -1,5 +1,5 @@
// //
// "$Id: Fl_Gl_Overlay.cxx,v 1.5.2.3 2000/03/18 10:04:17 bill Exp $" // "$Id: Fl_Gl_Overlay.cxx,v 1.5.2.4 2000/03/24 08:42:02 bill Exp $"
// //
// OpenGL overlay code for the Fast Light Tool Kit (FLTK). // OpenGL overlay code for the Fast Light Tool Kit (FLTK).
// //
@ -103,11 +103,15 @@ int Fl_Gl_Window::can_do_overlay() {
#else // WIN32: #else // WIN32:
static int no_overlay_hardware = 0;
int Fl_Gl_Window::can_do_overlay() { int Fl_Gl_Window::can_do_overlay() {
if (no_overlay_hardware) return 0;
Fl_Gl_Choice* choice = Fl_Gl_Choice::find(0,0); Fl_Gl_Choice* choice = Fl_Gl_Choice::find(0,0);
return (choice && (choice->pfd.bReserved & 15)); return (choice && (choice->pfd.bReserved & 15));
} }
int fl_overlay_depth = 0;
#endif #endif
#else #else
@ -116,28 +120,50 @@ int Fl_Gl_Window::can_do_overlay() {return 0;}
#endif #endif
#include <stdio.h>
void Fl_Gl_Window::make_overlay() { void Fl_Gl_Window::make_overlay() {
if (!overlay) { if (!overlay) {
#if HAVE_GL_OVERLAY #if HAVE_GL_OVERLAY
#ifdef WIN32 #ifdef WIN32
HDC hdc = fl_private_dc(this, mode_,&g); if (!no_overlay_hardware) {
GLXContext context = wglCreateLayerContext(hdc, 1); HDC hdc = fl_private_dc(this, mode_,&g);
if (context) { GLXContext context = wglCreateLayerContext(hdc, 1);
if (fl_first_context) wglShareLists(fl_first_context, context); if (!context) { // no overlay hardware
else fl_first_context = context; no_overlay_hardware = 1;
overlay = context; printf("No overlay detected\n");
// copy all colors except #0 into the overlay palette: } else {
COLORREF pcr[256]; if (fl_first_context) wglShareLists(fl_first_context, context);
for (int i = 0; i < 256; i++) { else fl_first_context = context;
uchar r,g,b; Fl::get_color((Fl_Color)i,r,g,b); overlay = context;
pcr[i] = RGB(r,g,b); LAYERPLANEDESCRIPTOR pfd;
wglDescribeLayerPlane(hdc, g->pixelformat, 1, sizeof(pfd), &pfd);
if (!pfd.iPixelType) {
printf("Color Overlay found\n");
} else {
printf("Overlay of depth %d found\n", pfd.cColorBits);
fl_overlay_depth = pfd.cColorBits; // used by gl_color()
if (fl_overlay_depth > 8) fl_overlay_depth = 8;
COLORREF palette[256];
// copy all colors except #0 into the overlay palette:
for (int i = 0; i < 256; 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[(1<<fl_overlay_depth)-2] = RGB(0,0,0);
palette[(1<<fl_overlay_depth)-1] = RGB(255,255,255);
}
// and use it:
wglSetLayerPaletteEntries(hdc, 1, 1, 255, palette+1);
wglRealizeLayerPalette(hdc, 1, TRUE);
}
valid(0);
return;
} }
wglSetLayerPaletteEntries(hdc, 1, 1, 255, pcr+1);
wglRealizeLayerPalette(hdc, 1, TRUE);
valid(0);
return;
} }
#else // glX version: #else
if (can_do_overlay()) { if (can_do_overlay()) {
_Fl_Gl_Overlay* o = new _Fl_Gl_Overlay(0,0,w(),h()); _Fl_Gl_Overlay* o = new _Fl_Gl_Overlay(0,0,w(),h());
overlay = o; overlay = o;
@ -168,6 +194,8 @@ void Fl_Gl_Window::make_overlay_current() {
if (overlay != this) { if (overlay != this) {
#ifdef WIN32 #ifdef WIN32
fl_set_gl_context(this, (GLXContext)overlay); fl_set_gl_context(this, (GLXContext)overlay);
if (fl_overlay_depth)
wglRealizeLayerPalette(fl_private_dc(this, mode_,&g), 1, TRUE);
#else #else
((Fl_Gl_Window*)overlay)->make_current(); ((Fl_Gl_Window*)overlay)->make_current();
#endif #endif
@ -189,5 +217,5 @@ void Fl_Gl_Window::hide_overlay() {
#endif #endif
// //
// End of "$Id: Fl_Gl_Overlay.cxx,v 1.5.2.3 2000/03/18 10:04:17 bill Exp $". // End of "$Id: Fl_Gl_Overlay.cxx,v 1.5.2.4 2000/03/24 08:42:02 bill Exp $".
// //

View File

@ -1,5 +1,5 @@
// //
// "$Id: Fl_Gl_Window.cxx,v 1.12.2.8 2000/03/18 10:04:18 bill Exp $" // "$Id: Fl_Gl_Window.cxx,v 1.12.2.9 2000/03/24 08:42:02 bill Exp $"
// //
// OpenGL window code for the Fast Light Tool Kit (FLTK). // OpenGL window code for the Fast Light Tool Kit (FLTK).
// //
@ -59,14 +59,6 @@
#define SWAP_TYPE SWAP #define SWAP_TYPE SWAP
#endif #endif
//
// Windows may need a different color palette...
//
#if defined(WIN32) && HAVE_GL
extern HPALETTE fl_gl_palette;
#endif
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
int Fl_Gl_Window::can_do(int a, const int *b) { int Fl_Gl_Window::can_do(int a, const int *b) {
@ -159,41 +151,57 @@ void Fl_Gl_Window::swap_buffers() {
#endif #endif
} }
#if HAVE_GL_OVERLAY #if defined(_WIN32) && HAVE_GL_OVERLAY
#ifdef WIN32
uchar fl_overlay; // changes how fl_color() works uchar fl_overlay; // changes how fl_color() works
#endif #endif
#endif
void Fl_Gl_Window::flush() { void Fl_Gl_Window::flush() {
make_current(); uchar save_valid = valid_;
#if defined(_WIN32) && HAVE_GL_OVERLAY #if defined(_WIN32) && HAVE_GL_OVERLAY
uchar save_valid = valid_; if (overlay && overlay != this &&
if (overlay && overlay!= this && damage() == FL_DAMAGE_OVERLAY) goto DRAW_OVERLAY_ONLY; ((damage()&(FL_DAMAGE_OVERLAY|FL_DAMAGE_ALL|FL_DAMAGE_EXPOSE))
|| !save_valid)) {
// Draw into hardware overlay planes
if (!g->d) SetCursor(0); // SGI 320 messes up overlay over singlebuffer
fl_set_gl_context(this, (GLXContext)overlay);
glDisable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT);
fl_overlay = 1;
draw_overlay();
fl_overlay = 0;
valid(save_valid);
if (damage() == FL_DAMAGE_OVERLAY) {
wglSwapLayerBuffers(Fl_X::i(this)->private_dc,WGL_SWAP_OVERLAY1);
if (!g->d) SetCursor(Fl_X::i(this)->cursor);
return;
}
if (!g->d) SetCursor(Fl_X::i(this)->cursor);
}
#endif #endif
make_current();
if (g->d) { if (g->d) {
#if SWAP_TYPE == NODAMAGE #if SWAP_TYPE == NODAMAGE
// don't draw if only overlay damage or expose events: // don't draw if only overlay damage or expose events:
if ((damage()&~(FL_DAMAGE_OVERLAY|FL_DAMAGE_EXPOSE)) || !valid()) draw(); if ((damage()&~(FL_DAMAGE_OVERLAY|FL_DAMAGE_EXPOSE)) || !save_valid) draw();
swap_buffers(); swap_buffers();
#elif SWAP_TYPE == COPY #elif SWAP_TYPE == COPY
// don't draw if only the overlay is damaged: // don't draw if only the overlay is damaged:
if (damage() != FL_DAMAGE_OVERLAY || !valid()) draw(); if (damage() != FL_DAMAGE_OVERLAY || !save_valid) draw();
swap_buffers(); swap_buffers();
#else // SWAP_TYPE == SWAP || SWAP_TYPE == UNDEFINED #else // SWAP_TYPE == SWAP || SWAP_TYPE == UNDEFINED
if (overlay == this) { // Use CopyPixels to act like SWAP_TYPE == COPY if (overlay == this) { // Use CopyPixels to act like SWAP_TYPE == COPY
uchar save_valid = valid_;
// don't draw if only the overlay is damaged: // don't draw if only the overlay is damaged:
if (damage1_ || damage() != FL_DAMAGE_OVERLAY || !valid()) draw(); if (damage1_ || damage() != FL_DAMAGE_OVERLAY || !save_valid) draw();
// we use a seperate context for the copy because rasterpos must be 0 // we use a seperate context for the copy because rasterpos must be 0
// and depth test needs to be off: // and depth test needs to be off:
static GLXContext ortho_context = 0; static GLXContext ortho_context = 0;
@ -207,7 +215,6 @@ void Fl_Gl_Window::flush() {
#endif #endif
fl_set_gl_context(this, ortho_context); fl_set_gl_context(this, ortho_context);
if (init || !save_valid || ortho_window != this) { if (init || !save_valid || ortho_window != this) {
ortho_window = this;
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glReadBuffer(GL_BACK); glReadBuffer(GL_BACK);
glDrawBuffer(GL_FRONT); glDrawBuffer(GL_FRONT);
@ -215,6 +222,7 @@ void Fl_Gl_Window::flush() {
glViewport(0, 0, w(), h()); glViewport(0, 0, w(), h());
glOrtho(0, w(), 0, h(), -1, 1); glOrtho(0, w(), 0, h(), -1, 1);
glRasterPos2i(0,0); glRasterPos2i(0,0);
ortho_window = this;
} }
glCopyPixels(0,0,w(),h(),GL_COLOR); glCopyPixels(0,0,w(),h(),GL_COLOR);
make_current(); // set current context back to draw overlay make_current(); // set current context back to draw overlay
@ -251,25 +259,6 @@ void Fl_Gl_Window::flush() {
} }
#if HAVE_GL_OVERLAY
#ifdef WIN32
if (overlay && overlay != this) {
DRAW_OVERLAY_ONLY:
// Draw into hardware overlay planes
if (!g->d) SetCursor(0); // SGI system messes up overlay over singlebuffer
valid_ = save_valid;
fl_set_gl_context(this, (GLXContext)overlay);
glDisable(GL_SCISSOR_TEST);
fl_overlay = 1;
glClear(GL_COLOR_BUFFER_BIT);
draw_overlay();
wglSwapLayerBuffers(Fl_X::i(this)->private_dc,WGL_SWAP_OVERLAY1);
fl_overlay = 0;
if (!g->d) SetCursor(Fl_X::i(this)->cursor);
}
#endif
#endif
valid(1); valid(1);
} }
@ -318,5 +307,5 @@ void Fl_Gl_Window::draw_overlay() {}
#endif #endif
// //
// End of "$Id: Fl_Gl_Window.cxx,v 1.12.2.8 2000/03/18 10:04:18 bill Exp $". // End of "$Id: Fl_Gl_Window.cxx,v 1.12.2.9 2000/03/24 08:42:02 bill Exp $".
// //

View File

@ -1,5 +1,5 @@
// //
// "$Id: gl_draw.cxx,v 1.7 1999/01/07 19:17:46 mike Exp $" // "$Id: gl_draw.cxx,v 1.7.2.1 2000/03/24 08:42:03 bill Exp $"
// //
// OpenGL drawing support routines for the Fast Light Tool Kit (FLTK). // OpenGL drawing support routines for the Fast Light Tool Kit (FLTK).
// //
@ -117,12 +117,25 @@ void gl_rect(int x, int y, int w, int h) {
#if HAVE_GL_OVERLAY #if HAVE_GL_OVERLAY
extern uchar fl_overlay; extern uchar fl_overlay;
extern int fl_overlay_depth;
#endif #endif
void gl_color(Fl_Color i) { void gl_color(Fl_Color i) {
#if HAVE_GL_OVERLAY #if HAVE_GL_OVERLAY
#ifdef WIN32 #ifdef WIN32
if (fl_overlay) {glIndexi(i ? i : FL_GRAY_RAMP); return;} if (fl_overlay && fl_overlay_depth) {
if (fl_overlay_depth < 8) {
// only black & white produce the expected colors. This could
// be improved by fixing the colormap set in Fl_Gl_Overlay.cxx
int size = 1<<fl_overlay_depth;
if (!i) glIndexi(size-2);
else if (i >= size-2) glIndexi(size-1);
else glIndexi(i);
} else {
glIndexi(i ? i : FL_GRAY_RAMP);
}
return;
}
#else #else
if (fl_overlay) {glIndexi(int(fl_xpixel(i))); return;} if (fl_overlay) {glIndexi(int(fl_xpixel(i))); return;}
#endif #endif
@ -142,5 +155,5 @@ void gl_draw_image(const uchar* b, int x, int y, int w, int h, int d, int ld) {
#endif #endif
// //
// End of "$Id: gl_draw.cxx,v 1.7 1999/01/07 19:17:46 mike Exp $". // End of "$Id: gl_draw.cxx,v 1.7.2.1 2000/03/24 08:42:03 bill Exp $".
// //