summaryrefslogtreecommitdiff
path: root/src/Fl_Gl_Window.cxx
diff options
context:
space:
mode:
authorBill Spitzak <spitzak@gmail.com>2000-07-07 08:38:58 +0000
committerBill Spitzak <spitzak@gmail.com>2000-07-07 08:38:58 +0000
commit7badf7c2168e2ad534bd5a934e21d6a5946cf595 (patch)
treef002846384f87cead43f55e09d0eaac959e7c898 /src/Fl_Gl_Window.cxx
parenta5ae7d54a6aa1101d1695621136cb06402bd76ef (diff)
Buttons with box(FL_NO_BOX) did not draw. Apparently they did in
older versions of fltk, I restored this. (bug 108771) Removed 8-bit colormap drawing code that was not doing anything in fl_draw_image due to Mike's changes. I also made fl_color(r,g,b) actually allocate the requested color rather than the nearest fltk color-cube color (this is only done for the first color that maps to a given entry in the fltk color cube), the result is that pixmaps with a small number of colors are drawn much more accurately. The resulting code seems to produce better images and is a good deal smaller! Fixed makeinclude.in so CFLAGS are used for c source code instead of CXXFLAGS. (bug 108694) Better fix for gif files suggested by pauly (bug 108770) Performance of Fl_Gl_Window may be improved on some types of OpenGL implementations, in particular MESA or other software emulators, by setting the GL_SWAP_TYPE environment variable. This variable declares what is in the back buffer after you do a swapbuffers. setenv GL_SWAP_TYPE COPY This indicates that the back buffer is copied to the front buffer, and still contains it's old data. This is true of many hardware implementations. Setting this will speed up emulation of overlays, and widgets that can do partial update can take advantage of this as damage() will not be cleared to -1. setenv GL_SWAP_TYPE NODAMAGE This indicates that nothing changes the back buffer except drawing into it. This is true of MESA and Win32 software emulation and perhaps some hardware emulation on systems with lots of memory. All other values for GL_SWAP_TYPE, and not setting the variable, cause fltk to assumme that the back buffer must be completely redrawn after a swap. This is easily tested by running the gl_overlay demo program and seeing if the display is correct when you drag another window over it or if you drag the window off the screen and back on. You have to exit and run the program again for it to see any changes to the environment variable. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1246 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Gl_Window.cxx')
-rw-r--r--src/Fl_Gl_Window.cxx134
1 files changed, 68 insertions, 66 deletions
diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx
index d2a32bbfe..895fa0985 100644
--- a/src/Fl_Gl_Window.cxx
+++ b/src/Fl_Gl_Window.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Gl_Window.cxx,v 1.12.2.15 2000/06/10 19:30:01 carl Exp $"
+// "$Id: Fl_Gl_Window.cxx,v 1.12.2.16 2000/07/07 08:38:58 spitzak Exp $"
//
// OpenGL window code for the Fast Light Tool Kit (FLTK).
//
@@ -30,6 +30,8 @@
#include <FL/x.H>
#include <FL/Fl_Gl_Window.H>
#include "Fl_Gl_Choice.H"
+#include <stdlib.h>
+#include <string.h>
////////////////////////////////////////////////////////////////
@@ -42,22 +44,17 @@
// this reason you can define some symbols to describe what is left in
// the back buffer.
-// The default of SWAP_SWAP works on an SGI, and will also work (but
-// is sub-optimal) on machines that should be SWAP_COPY or SWAP_NODAMAGE.
-// The win32 emulation of OpenGL can use COPY, but some (all?) OpenGL
-// cards use SWAP.
+// Having not found any way to determine this from glx (or wgl) I have
+// resorted to letting the user specify it with an environment variable,
+// GL_SWAP_TYPE, it should be equal to one of these symbols:
// contents of back buffer after glXSwapBuffers():
-#define UNDEFINED 0 // unknown
-#define SWAP 1 // former front buffer
-#define COPY 2 // unchanged
-#define NODAMAGE 3 // unchanged even by X expose() events
-
-//#ifdef MESA
-//#define SWAP_TYPE NODAMAGE
-//#else
-#define SWAP_TYPE SWAP
-//#endif
+#define UNDEFINED 1 // anything
+#define SWAP 2 // former front buffer (same as unknown)
+#define COPY 3 // unchanged
+#define NODAMAGE 4 // unchanged even by X expose() events
+
+static char SWAP_TYPE; // 0 = determine it from environment variable
////////////////////////////////////////////////////////////////
@@ -196,66 +193,71 @@ void Fl_Gl_Window::flush() {
if (g->d) {
-#if SWAP_TYPE == NODAMAGE
-
- // don't draw if only overlay damage or expose events:
- if ((damage()&~(FL_DAMAGE_OVERLAY|FL_DAMAGE_EXPOSE)) || !save_valid) draw();
- swap_buffers();
-
-#elif SWAP_TYPE == COPY
+ if (!SWAP_TYPE) {
+ SWAP_TYPE = UNDEFINED;
+ const char* c = getenv("GL_SWAP_TYPE");
+ if (c) {
+ if (!strcmp(c,"COPY")) SWAP_TYPE = COPY;
+ else if (!strcmp(c, "NODAMAGE")) SWAP_TYPE = NODAMAGE;
+ }
+ }
- // don't draw if only the overlay is damaged:
- if (damage() != FL_DAMAGE_OVERLAY || !save_valid) draw();
- swap_buffers();
+ if (SWAP_TYPE == NODAMAGE) {
-#else // SWAP_TYPE == SWAP || SWAP_TYPE == UNDEFINED
+ // don't draw if only overlay damage or expose events:
+ if ((damage()&~(FL_DAMAGE_OVERLAY|FL_DAMAGE_EXPOSE)) || !save_valid)
+ draw();
+ swap_buffers();
- if (overlay == this) { // Use CopyPixels to act like SWAP_TYPE == COPY
+ } else if (SWAP_TYPE == COPY) {
// don't draw if only the overlay is damaged:
- if (damage1_ || damage() != FL_DAMAGE_OVERLAY || !save_valid) draw();
- // we use a seperate context for the copy because rasterpos must be 0
- // and depth test needs to be off:
- static GLXContext ortho_context = 0;
- static Fl_Gl_Window* ortho_window = 0;
- int init = !ortho_context;
- if (init) {
+ if (damage() != FL_DAMAGE_OVERLAY || !save_valid) draw();
+ swap_buffers();
+
+ } else { // SWAP_TYPE == UNDEFINED
+
+ // If we are faking the overlay, use CopyPixels to act like
+ // SWAP_TYPE == COPY. Otherwise overlay redraw is way too slow.
+ if (overlay == this) {
+ // don't draw if only the overlay is damaged:
+ if (damage1_ || damage() != FL_DAMAGE_OVERLAY || !save_valid) draw();
+ // we use a seperate context for the copy because rasterpos must be 0
+ // and depth test needs to be off:
+ static GLXContext ortho_context = 0;
+ static Fl_Gl_Window* ortho_window = 0;
+ int init = !ortho_context;
+ if (init) {
#ifdef _WIN32
- ortho_context = wglCreateContext(Fl_X::i(this)->private_dc);
+ ortho_context = wglCreateContext(Fl_X::i(this)->private_dc);
#else
- ortho_context = glXCreateContext(fl_display,g->vis,fl_first_context,1);
+ ortho_context =glXCreateContext(fl_display,g->vis,fl_first_context,1);
#endif
- }
- fl_set_gl_context(this, ortho_context);
- if (init || !save_valid || ortho_window != this) {
- glDisable(GL_DEPTH_TEST);
- glReadBuffer(GL_BACK);
- glDrawBuffer(GL_FRONT);
- glLoadIdentity();
- glViewport(0, 0, w(), h());
- glOrtho(0, w(), 0, h(), -1, 1);
- glRasterPos2i(0,0);
- ortho_window = this;
- }
- glCopyPixels(0,0,w(),h(),GL_COLOR);
- make_current(); // set current context back to draw overlay
- damage1_ = 0;
-
- } else {
+ }
+ fl_set_gl_context(this, ortho_context);
+ if (init || !save_valid || ortho_window != this) {
+ glDisable(GL_DEPTH_TEST);
+ glReadBuffer(GL_BACK);
+ glDrawBuffer(GL_FRONT);
+ glLoadIdentity();
+ glViewport(0, 0, w(), h());
+ glOrtho(0, w(), 0, h(), -1, 1);
+ glRasterPos2i(0,0);
+ ortho_window = this;
+ }
+ glCopyPixels(0,0,w(),h(),GL_COLOR);
+ make_current(); // set current context back to draw overlay
+ damage1_ = 0;
+
+ } else {
+
+ damage1_ = damage();
+ clear_damage(~0); draw();
+ swap_buffers();
-#if SWAP_TYPE == SWAP
- uchar old_damage = damage();
- clear_damage(damage1_|old_damage); draw();
- swap_buffers();
- damage1_ = old_damage;
-#else // SWAP_TYPE == UNDEFINED
- clear_damage(~0); draw();
- swap_buffers();
- damage1_ = ~0;
-#endif
+ }
}
-#endif
if (overlay==this) { // fake overlay in front buffer
glDrawBuffer(GL_FRONT);
@@ -269,6 +271,7 @@ void Fl_Gl_Window::flush() {
draw();
if (overlay == this) draw_overlay();
glFlush();
+
}
#ifdef _WIN32
@@ -321,7 +324,6 @@ void Fl_Gl_Window::init() {
context = 0;
g = 0;
overlay = 0;
- damage1_ = 0;
}
void Fl_Gl_Window::draw_overlay() {}
@@ -329,5 +331,5 @@ void Fl_Gl_Window::draw_overlay() {}
#endif
//
-// End of "$Id: Fl_Gl_Window.cxx,v 1.12.2.15 2000/06/10 19:30:01 carl Exp $".
+// End of "$Id: Fl_Gl_Window.cxx,v 1.12.2.16 2000/07/07 08:38:58 spitzak Exp $".
//