casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GLPixelCanvas.h
Go to the documentation of this file.
00001 //# GLPixelCanvas.h: Class defining OpenGL version PixelCanvas.
00002 //# Copyright (C) 2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id $
00027 
00028 #ifndef TRIALDISPLAY_GLPIXELCANVAS_H
00029 #define TRIALDISPLAY_GLPIXELCANVAS_H
00030 
00031 #include <casa/aips.h>
00032 #include <graphics/X11/X_enter.h>
00033 #include <X11/Xlib.h>
00034 #include <X11/Intrinsic.h>
00035 #include <X11/Xutil.h>
00036 #include <GL/gl.h>
00037 #include <GL/glx.h>
00038 #include <graphics/X11/X_exit.h>
00039 
00040 #include <display/Display/PixelCanvas.h>
00041 #include <display/Display/GLPixelCanvasColorTable.h>
00042 #include <display/Display/GLSupport.h>
00043 
00044 namespace casa { //# NAMESPACE CASA - BEGIN
00045 
00046 class GLPCDisplayList;
00047 class GLPCDisplayListEntry;
00048 class GLPCDisplayListElement;
00049 class GLPCTextureParams;
00050 
00051 // <summary>
00052 //      OpenGL implementation of PixelCanvas.
00053 // </summary>
00054 
00055 // <use visibility=export>
00056 
00057 // <prerequisite>
00058 // <li> <linkto class="PixelCanvasColorTable">PixelCanvasColorTable</linkto>
00059 // <li> <linkto class="GLPixelCanvasColorTable">GLPixelCanvasColorTable</linkto>
00060 // <li> <linkto class="PixelCanvas">PixelCanvas</linkto>
00061 // <li> <linkto class="X11PixelCanvas"> Knowledge of X11PixelCanvas could help</linkto>
00062 // </prerequisite>
00063 //
00064 // <synopsis>
00065 // Implementation of PixelCanvas for OpenGL. Most, but not all of the
00066 // PixelCanvas functions are available. There is very little support for
00067 // 3D.
00068 // </synopsis>
00069 // <thrown>
00070 //    None
00071 // </thrown>
00072 // <todo asof="2001/09/25">
00073 //#   <li>
00074 // </todo>
00075 
00076 class GLPixelCanvas : public PixelCanvas
00077 {
00078 public:
00079 // <note role=caution>
00080 // Drawing can not take place until the window exists!
00081 // </note>
00082   GLPixelCanvas(Widget parent, GLPixelCanvasColorTable * glpcctbl,
00083                 uInt width, uInt height);
00084   virtual ~GLPixelCanvas();
00085 
00086   // enabling/disabling of event tracking (unimplemented)
00087   // <group>
00088   virtual void enableMotionEvents();
00089   virtual void disableMotionEvents();
00090   virtual void enablePositionEvents();
00091   virtual void disablePositionEvents();
00092   // </group>
00093 
00094   // Does this canvas support cached display lists?  The user of the
00095   // canvas should always check this, because undefined behaviour can
00096   // result when an attempt is made to use a list on a PixelCanvas
00097   // which does not support lists.
00098   virtual Bool supportsLists();
00099   
00100   // begin caching display commands - return list ID
00101   virtual uInt newList();
00102   // end caching display commands
00103   virtual void endList();
00104   // (Cacheable) recall cached display commands
00105   virtual void drawList(uInt list);
00106   // translate all lists
00107   virtual void translateAllLists(Int xt, Int yt);
00108   // translate the list
00109   virtual void translateList(uInt list, Int xt, Int yt);
00110   // remove list from cache
00111   virtual void deleteList(uInt list);
00112   // flush all lists from the cache
00113   virtual void deleteLists();
00114   // return True if the list exists
00115   virtual Bool validList(uInt list);
00116 
00117   // (Cacheable) Set the font to the recognizable font name. (unimplemented)
00118   virtual Bool setFont(const String &fontName);
00119   // (Cacheable) Draw text using that font aligned in some way to the
00120   // position. (unimplemented)
00121   virtual void drawText(Int x, Int y, const String &text, 
00122                         Display::TextAlign alignment = Display::AlignCenter);
00123 
00124   // (Cacheable) Draw an array of 2D color data as a raster image for zoom = <1,1>
00125   // <group>
00126   virtual void drawImage(const Matrix<uInt> &data, Int x, Int y);
00127   virtual void drawImage(const Matrix<Int> &data, Int x, Int y);
00128   virtual void drawImage(const Matrix<uLong> &data, Int x, Int y);
00129   virtual void drawImage(const Matrix<Float> &data, Int x, Int y);
00130   virtual void drawImage(const Matrix<Double> &data, Int x, Int y);
00131   // </group>
00132   // (Cacheable) Draw an image using color indexes. If in RGB mode,
00133   // the virtual colortable is used.
00134   void GLPixelCanvas::drawIndexedImage( const Matrix<uInt> &data,
00135                                         Float x=0.0, Float y=0.0, Float z=0.0,
00136                                         Float xscl=1.0, Float yscl=1.0);
00137   // (Cacheable) Draw an array of 2D color data as a raster image,
00138   // taking note of the <src>Bool</src> mask.
00139   // (opaqueMask ignored/unimplemented)
00140   // <group>
00141   virtual void drawImage(const Int &x, const Int &y, 
00142                          const Matrix<uInt> &data, 
00143                          const Matrix<Bool> &mask,
00144                          Bool opaqueMask=False);
00145   // </group>
00146 
00147   // (Cacheable) Draw an array of 2D color data as a raster image for any positive integer zoom
00148   // <group>
00149   virtual void drawImage(const Matrix<uInt> &data, Int x, Int y, 
00150                          uInt xzoom, uInt yzoom);
00151   virtual void drawImage(const Matrix<Int> &data, Int x, Int y, 
00152                          uInt xzoom, uInt yzoom);
00153   virtual void drawImage(const Matrix<uLong> &data, Int x, Int y, 
00154                          uInt xzoom, uInt yzoom);
00155   virtual void drawImage(const Matrix<Float> &data, Int x, Int y, 
00156                          uInt xzoom, uInt yzoom);
00157   virtual void drawImage(const Matrix<Double> &data, Int x, Int y, 
00158                          uInt xzoom, uInt yzoom);
00159   // </group>
00160 
00161   // (Cacheable) Draw a component of a multi-channel image, storing it
00162   // in buffers until flushComponentImages() is called.
00163   virtual void drawImage(const Matrix<uInt> &data, const Int &x, const Int &y,
00164                          const Display::ColorComponent &colorcomponent);
00165 
00166   // Fill one of the channel buffers.
00167   virtual void bufferComponent(const Matrix<uInt> &data,
00168                                const Int &x, const Int &y,
00169                                const Display::ColorComponent 
00170                                &colorcomponent);
00171 
00172   // (NOT CACHEABLE!) Flush the component buffers.
00173   virtual void flushComponentBuffers();
00174 
00175   // (Cacheable) Draw a single point using current color
00176   // <group>
00177   virtual void drawPoint(Int x1, Int y1);
00178   virtual void drawPoint(Float x1, Float y1);
00179   virtual void drawPoint3D(Float x1, Float y1, Float z1);
00180   virtual void drawPoint(Double x1, Double y1);
00181   // </group>
00182   
00183   // (Cacheable) Draw N points specified as a Nx2 matrix
00184   // <group>
00185   virtual void drawPoints(const Matrix<Int> &verts);
00186   virtual void drawPoints(const Matrix<Float> &verts);
00187   void drawPoints3D(const Matrix<Float> &verts);
00188   virtual void drawPoints(const Matrix<Double> &verts);
00189   // </group>
00190 
00191   // (Cacheable) Draw a bunch of points using current color
00192   // <group>
00193   virtual void drawPoints(const Vector<Int> &x1, const Vector<Int> &y1);
00194   virtual void drawPoints(const Vector<Float> &x1, 
00195                           const Vector<Float> &y1);
00196   virtual void drawPoints3D(const Vector<Float> &x1, 
00197                           const Vector<Float> &y1, const Vector<Float> &z1);
00198   virtual void drawPoints(const Vector<Double> &x1, 
00199                           const Vector<Double> &y1);
00200   // </group>
00201 // (cacheable) Change the size of the points (in pixels) drawn by drawPoints.
00202   void setPointSize(const uInt pointsize);
00203 
00204   // (Cacheable) Draw a single line using current color
00205   // <group>
00206   virtual void drawLine(Int x1, Int y1, Int x2, Int y2);
00207   virtual void drawLine(Float x1, Float y1, Float x2, Float y2);
00208   virtual void drawLine3D(Float x1, Float y1, Float z1,
00209                           Float x2, Float y2, Float z2);
00210   virtual void drawLine(Double x1, Double y1, Double x2, Double y2);
00211   // </group>
00212 
00213   // (Cacheable) Draw N/2 lines from an Nx2 matrix
00214   // <group>
00215   virtual void drawLines(const Matrix<Int> &verts);
00216   virtual void drawLines(const Matrix<Float> &verts);
00217   virtual void drawLines3D(const Matrix<Float> &verts);
00218   virtual void drawLines(const Matrix<Double> &verts);
00219   // </group>
00220 
00221   // (Cacheable) Draw a bunch of unrelated lines using current color
00222   // <group>
00223   virtual void drawLines(const Vector<Int> &x1, const Vector<Int> &y1, 
00224                          const Vector<Int> &x2, const Vector<Int> &y2);
00225   virtual void drawLines(const Vector<Float> &x1, const Vector<Float> &y1, 
00226                          const Vector<Float> &x2, 
00227                          const Vector<Float> &y2);
00228   virtual void drawLines(const Vector<Double> &x1, const Vector<Double> &y1, 
00229                          const Vector<Double> &x2, 
00230                          const Vector<Double> &y2);
00231   // </group>
00232   
00233   // (Cacheable) Draw a single connected line between the given points.
00234   // <group>
00235   virtual void drawPolyline(const Vector<Int> &x1, 
00236                             const Vector<Int> &y1);
00237   virtual void drawPolyline(const Vector<Float> &x1, 
00238                             const Vector<Float> &y1);
00239   virtual void drawPolyline3D(const Vector<Float> &x1, 
00240                             const Vector<Float> &y1,
00241                             const Vector<Float> &z1);
00242   virtual void drawPolyline(const Vector<Double> &x1, 
00243                             const Vector<Double> &y1);
00244   // </group>
00245  
00246   // (Cacheable) Draw N-1 connected lines from Nx2 matrix of vertices
00247   // <group>
00248   virtual void drawPolyline(const Matrix<Int> &verts);
00249   virtual void drawPolyline(const Matrix<Float> &verts);
00250   virtual void drawPolyline(const Matrix<Double> &verts);
00251   // </group>
00252 
00253   // (Cacheable) Draw a closed polygon
00254   // <group>
00255   virtual void drawPolygon(const Vector<Int> &x1, const Vector<Int> &y1);
00256   virtual void drawPolygon(const Vector<Float> &x1, 
00257                            const Vector<Float> &y1);
00258   virtual void drawPolygon3D(const Vector<Float> &x1, 
00259                            const Vector<Float> &y1,
00260                            const Vector<Float> &z1);
00261   virtual void drawPolygon(const Vector<Double> &x1, 
00262                            const Vector<Double> &y1);
00263   // </group>
00264 
00265   // (Cacheable) Draw and fill a closed polygon
00266   // <group>
00267   virtual void drawFilledPolygon(const Vector<Int> &x1, 
00268                                  const Vector<Int> &y1);
00269   virtual void drawFilledPolygon(const Vector<Float> &x1, 
00270                                  const Vector<Float> &y1);
00271   virtual void drawFilledPolygon3D(const Vector<Float> &x1,
00272                                    const Vector<Float> &y1,
00273                                    const Vector<Float> &z1);
00274   virtual void drawFilledPolygon(const Vector<Double> &x1, 
00275                                  const Vector<Double> &y1);
00276   // </group>
00277 
00278   // (Cacheable) Draw a closed N-sided polygon from Nx2 matrix of vertices
00279   // <group>
00280   virtual void drawPolygon(const Matrix<Int> &verts);
00281   virtual void drawPolygon(const Matrix<Float> &verts);
00282   virtual void drawPolygon3D(const Matrix<Float> &verts);
00283   virtual void drawPolygon(const Matrix<Double> &verts);
00284   // </group>
00285 
00286   // (Cacheable) Draw a rectangle
00287   // <group>
00288   virtual void drawRectangle(Int x1, Int y1, Int x2, Int y2);
00289   virtual void drawRectangle(Float x1, Float y1, Float x2, Float y2);
00290   virtual void drawRectangle(Double x1, Double y1, Double x2, Double y2);
00291   // </group>
00292 
00293   // (Cacheable) Draw a filled rectangle
00294   // <group>
00295   virtual void drawFilledRectangle(Int x1, Int y1, Int x2, Int y2);
00296   virtual void drawFilledRectangle(Float x1, Float y1, Float x2, Float y2);
00297   virtual void drawFilledRectangle(Double x1, Double y1, Double x2, 
00298                                    Double y2);
00299   // </group>  
00300 
00301   // (Cacheable) Draw a set of points, specifying a color per point to be drawn.
00302   // <group>
00303   virtual void drawColoredPoints(const Vector<Int> &x1, 
00304                                  const Vector<Int> &y1, 
00305                                  const Vector<uInt> &colors);
00306   virtual void drawColoredPoints(const Vector<Float> &x1, 
00307                                  const Vector<Float> &y1, 
00308                                  const Vector<uInt> &colors);
00309   virtual void drawColoredPoints(const Vector<Double> &x1, 
00310                                  const Vector<Double> &y1, 
00311                                  const Vector<uInt> &colors);
00312   virtual void drawColoredPoints(const Matrix<Int> &xy,
00313                                  const Vector<uInt> &colors);
00314   virtual void drawColoredPoints(const Matrix<Float> &xy,
00315                                  const Vector<uInt> &colors);
00316 
00317   virtual void drawColoredPoints(const Matrix<Double> &xy,
00318                                  const Vector<uInt> &colors);
00319 
00320   // </group>
00321 
00322   // (Cacheable) Draw a set of lines, specifying a color per line to be drawn.
00323   // <group>
00324   virtual void drawColoredLines(const Vector<Int> &x1, 
00325                                 const Vector<Int> &y1, 
00326                                 const Vector<Int> &x2, 
00327                                 const Vector<Int> &y2, 
00328                                 const Vector<uInt> &colors);
00329   virtual void drawColoredLines(const Vector<Float> &x1, 
00330                                 const Vector<Float> &y1, 
00331                                 const Vector<Float> &x2, 
00332                                 const Vector<Float> &y2, 
00333                                 const Vector<uInt> &colors);
00334   virtual void drawColoredLines(const Vector<Double> &x1, 
00335                                 const Vector<Double> &y1, 
00336                                 const Vector<Double> &x2, 
00337                                 const Vector<Double> &y2, 
00338                                 const Vector<uInt> &colors);
00339   // </group>
00340   
00341   // Set Graphics Attributes
00342   // Options for functions with enum argument
00343   // listed in <linkto class=Display>DisplayEnums</linkto>
00344   // <group>
00345   virtual void setForeground(uLong color);
00346   virtual void setLineWidth(Float width);
00347   virtual void setLineStyle(Display::LineStyle style);
00348   virtual void setFillStyle(Display::FillStyle style);
00349   virtual void setDrawFunction(Display::DrawFunction function);
00350   // </group>
00351 
00352   // Unimplemented set graphics functions.
00353   // <group>
00354   virtual void setBackground(uLong color);
00355   virtual void setCapStyle(Display::CapStyle style);
00356   virtual void setJoinStyle(Display::JoinStyle style);
00357   virtual void setFillRule(Display::FillRule rule);
00358   virtual void setArcMode(Display::ArcMode mode);
00359   // </group>
00360 
00361   // Implemented get Graphics Attributes functions.
00362   // <group>
00363   virtual uLong                 getForeground()   const;
00364   virtual Float                 getLineWidth()    const;
00365   virtual Display::LineStyle    getLineStyle()    const;
00366   virtual Display::FillStyle    getFillStyle()    const;
00367   virtual Display::DrawFunction getDrawFunction() const;
00368   // </group>
00369   // Unimplemented get Graphics Attributes.
00370   // <group>
00371   virtual uLong                 getBackground()   const;
00372   virtual Display::CapStyle     getCapStyle()     const;
00373   virtual Display::JoinStyle    getJoinStyle()    const;
00374   virtual Display::FillRule     getFillRule()     const;
00375   virtual Display::ArcMode      getArcMode()      const;
00376   // </group>
00377 
00378   // (Cacheable) Option Control
00379   // Options listed in <linkto class=Display>DisplayEnums</linkto>
00380   // Only Display::ClipWindow is implemented.
00381   // <group>
00382   virtual Bool enable(Display::Option option);
00383   virtual Bool disable(Display::Option option);
00384   // </group>
00385 
00386   // Control the image-caching strategy. (Ignored)
00387   virtual void setImageCacheStrategy(Display::ImageCacheStrategy strategy);
00388   virtual Display::ImageCacheStrategy imageCacheStrategy() const;
00389 
00390   // (Cacheable) Setup the clip window.  The clip window, when enabled, allows
00391   // a user to clip all graphics output to a rectangular region on
00392   // the screen.
00393   // <group>
00394   virtual void setClipWindow(Int x1, Int y1, Int x2, Int y2);
00395   virtual void getClipWindow(Int &x1, Int &y1, Int &x2, Int &y2);
00396   // </group>
00397 
00398   // (Not Cacheable) Redraw the window
00399   // <group>
00400   void redraw() { repaint(True); }
00401   virtual void refresh(const Display::RefreshReason &reason = 
00402                        Display::UserCommand,
00403                        const Bool &explicitrequest = True);
00404   // Just redraws window. (If redraw is T, the window will be redrawn. If
00405   // F, it will only be redrawn if autoRefresh is T.
00406   void repaint(const Bool redraw=False);
00407   // </group>
00408 
00409   // Cause display to flush any graphics commands not yet drawn
00410   virtual void flush();
00411 
00412   // (Cacheable) Clear the window using the background color
00413   // <note role=tip> If you want to clear the window use clear(),
00414   // not clear(IIII).
00415   // </note>
00416   // <group>
00417   virtual void clear();
00418   virtual void clear(Int x1, Int y1, Int x2, Int y2);
00419   // </group>
00420 
00421   // (Cacheable) Set the color to use for clearing the display
00422   // <group>
00423   virtual void setClearColor(uInt colorIndex);
00424   // <note role=caution> Setting named colors for Index mode isn't implemented.
00425   // </note>
00426   virtual void setClearColor(const String &colorname);
00427   virtual void setClearColor(float r, float g, float b);
00428   // </group>
00429 
00430   // (Not Cacheable) Get the current color to use for clearing the display.
00431   virtual uInt clearColor() const;
00432   virtual void getClearColor(float &r, float &g, float &b) const;
00433 
00434   // Get/set the current foreground/background colors.  These colors
00435   // should be used when the special Strings "foreground" and "background"
00436   // are given for a color.
00437   // <group>
00438   virtual void setDeviceForegroundColor(const String colorname);
00439   virtual String deviceForegroundColor() const;
00440   virtual void setDeviceBackgroundColor(const String colorname);
00441   virtual String deviceBackgroundColor() const;
00442   // </group>
00443 
00444   // Return the width of the GLPixelCanvas in pixels
00445   virtual uInt width() const;
00446   // Return the height of the GLPixelCanvas in pixels
00447   virtual uInt height() const;
00448   // Return the depth of the GLPixelCanvas in bits
00449   virtual uInt depth() const;
00450   // Get the pixel density (in dots per inch [dpi]) of the GLPixelCanvas
00451   // <note role=tip> The X server is queried. It may or may not have the
00452   // correct answer. </note>
00453   virtual void pixelDensity(Float &xdpi, Float &ydpi) const;
00454 
00455   // (Cacheable) Set current color (works in RGB or colormap mode)
00456   // <group>
00457   // <note role=tip> setColor(colorIndex) when called in RGB mode gets the
00458   // RGB values from the virtual color table. setForeground assumes the
00459   // value is a packed pixel. </note>
00460   virtual void setColor(uInt colorIndex);
00461   virtual void setColor(const String &colorname);
00462   // <note role=caution> Calling setRGBColor when in Index mode ignores
00463   // r, g & b and uses the current index value. </note>
00464   virtual void setRGBColor(float r, float g, float b);
00465   // </group>
00466 
00467   // Get color components in range 0 to 1 without actually 
00468   // allocating the color.  This is needed to set up other
00469   // devices, for example PgPlot.
00470   virtual Bool getColorComponents(const String &colorname, Float &r,
00471                                   Float &g, Float &b);
00472 
00473   // (Not Cacheable) Returns the current color as a color index
00474   // <note> In RGB mode, this is only valid if setColor(index) has
00475   // been called. </note>
00476   virtual uInt color() const;
00477 
00478   // (Not Cacheable) Retuns the current color as an RGB triple
00479   virtual void getColor(float &r, float &g, float &b) const;
00480 
00481   // (Not Cacheable) Get color index value (works in RGB or colormap mode)
00482   // <note role=tip> Don't bother. No existing canvas implements these.
00483   // </note>
00484   // <group>
00485   virtual Bool getColor(Int x, Int y, uInt &color);
00486   // This should be removed since no one implements it.
00487   virtual Bool getRGBColor(Int x, Int y, float &r, float &g, float &b);
00488   // </group>
00489 
00490   // (Not Cacheable) resize request.  returns true if window was resized. 
00491   // Will refresh if doCallbacks is True.
00492   virtual Bool resize(uInt reqXSize, uInt reqYSize, Bool doCallbacks = True);
00493   
00494   // (Not Cacheable) resize the colortable by requesting a new number of cells
00495   virtual Bool resizeColorTable(uInt newSize);
00496 
00497   // (Not Cacheable) resize the colortable by requesting a new RGB/HSV cube
00498   virtual Bool resizeColorTable(uInt nReds, uInt nGreens, uInt nBlues);
00499 
00500   // Need a mechanism to return the GLPixelCanvasColorTable so 
00501   // drawing functions within classes can operate.
00502   virtual GLPixelCanvasColorTable * glpcctbl() const {return glpcctbl_;}
00503   // Return the pixel canvas color table
00504   PixelCanvasColorTable * pcctbl() const { return glpcctbl_; }
00505 
00506   void setPcctbl(PixelCanvasColorTable * pcctbl)
00507   { glpcctbl_ = (GLPixelCanvasColorTable *) pcctbl; }
00508 
00509   // save/restore the current translation.  This is called pushMatrix because
00510   // eventually we may want scaling or rotation to play a modest
00511   // role here.
00512   // <note role=tip> GLPixelCanvas uses OpenGL's push/pop matrix. </note>
00513   // <group>
00514   virtual void pushMatrix();
00515   virtual void popMatrix();
00516   // </group>
00517   // zero the current translation
00518   virtual void loadIdentity();
00519 
00520   // translation functions
00521   // translate applies a relative translation to the current matrix and
00522   // can be used to position graphics.  Together with pushMatrix and
00523   // popMatrix it can be used to build heirarchical scenes.
00524   // <group>
00525   virtual void translate(Int xt, Int yt);
00526   // <note role=tip> get/x/yTranslation are not currently implemented. </note>
00527   virtual void getTranslation(Int &xt, Int &yt) const;
00528   virtual Int xTranslation() const;
00529   virtual Int yTranslation() const;
00530   // </group>
00531 
00532   // (Not cacheable) set the draw buffer
00533   // <note role=caution> The draw buffer is always set to BACK if double
00534   // buffered and FRONT if single buffered. </note>
00535   virtual void setDrawBuffer(Display::DrawBuffer buf);
00536   // buffer memory exchanges
00537   // (Not cacheable) 
00538   // <group>
00539   // <note role=caution> Of this group, only swapbuffers() works. </note>
00540   static void copyBuffer(GLenum from, GLenum to,
00541                          GLint x, GLint y,
00542                          GLsizei width, GLsizei height);
00543   void copyBuffer(GLenum from, GLenum to);
00544   virtual void copyBackBufferToFrontBuffer();
00545   virtual void copyFrontBufferToBackBuffer();
00546   virtual void swapBuffers();
00547   // </group>
00548 
00549   // partial buffer memory exchanges.  (x1,y1 are blc, x2,y2 are trc)
00550   // None of these are implemented.
00551   // <group>
00552   virtual void copyBackBufferToFrontBuffer(Int x1, Int y1, Int x2, Int y2);
00553   virtual void copyFrontBufferToBackBuffer(Int x1, Int y1, Int x2, Int y2);
00554   virtual void swapBuffers(Int x1, Int y1, Int x2, Int y2);
00555   // </group>
00556 
00557   // return True if refresh is allowed right now...
00558   virtual Bool refreshAllowed() const;
00559 
00560   // Make this canvas's context current.
00561   // <note role=caution> This must be called when switching between
00562   // GLPixelCanvases or else drawing will go to the wrong canvas. It is
00563   // not needed unless more than one GLPixelCanvas is active at a time.
00564   // </note>
00565   void makeCurrent();
00566   // Wait for X or GL commands to finish. Usually not needed.
00567   // <group>
00568   void waitX();
00569   void waitGL();
00570   // </group>
00571   // Print any GL error messages.
00572   // if msg is non NULL, it is printed first if there is an error.
00573   // nspaces is the number of spaces to indent the text.
00574   // Returns the number of errors. Usually only used internally.
00575   // <group>
00576   int glcheck(const char *msg=NULL, uInt nspaces=0);
00577   static int glCheck(const char *msg=NULL, uInt nspaces=0);
00578   // </group>
00579 
00580   // Various ways to draw images. Used internally.
00581   // <group>
00582   void drawTexturedImage(GLfloat x, GLfloat y, GLfloat z,
00583                          GLsizei width, GLsizei height,
00584                          GLfloat xscale, GLfloat yscale,
00585                          GLenum format, const GLushort *pixels,
00586                          GLPCTextureParams *params = NULL);
00587 
00588   void drawImagePixels( GLfloat x, GLfloat y, GLfloat z,
00589                         GLsizei width, GLsizei height,
00590                         GLfloat xscale, GLfloat yscale,
00591                         GLenum format, const GLushort *pixels);
00592 
00593   static void drawPixels(GLfloat x, GLfloat y, GLfloat z,
00594                          GLsizei width, GLsizei height,
00595                          GLfloat xscale, GLfloat yscale,
00596                          GLenum format, GLenum type,
00597                          const GLvoid *pixels);
00598 
00599   // Calls drawImagePixels if in indexed mode or drawTexturedImage if RGB.
00600   void drawGLImage(GLfloat x, GLfloat y, GLfloat z,
00601                    GLsizei width, GLsizei height,
00602                    GLfloat xscale, GLfloat yscale,
00603                    GLenum format, const GLushort *pixels);
00604  // </group>
00605 
00606   void bufferZValue(const Float z=0.0)
00607         { itsComponentZ_ = z;}
00608 
00609   // Tracing support. May be useful when debugging graphics code.
00610   // <group>
00611   // Turn tracing on/off.
00612   void trace(Boolean trace){ trace_ = trace;}
00613   Boolean tracing()const{return trace_;}
00614   // Set trace level. (actually a mask). default is GLTraceNormal.
00615   // NOT fully implemented.
00616   void traceLevel(const uLong traceLevel){traceLevel_ = traceLevel;}
00617   uLong traceLevel()const {return traceLevel_;}
00618   void postToStream(Bool p=False) { log_.postToStream(p);}
00619   void postToString(String *s=NULL) { log_.postToString(s);}
00620   void postString() { log_.postString();}
00621   // Add a note entry to traced output.
00622   void note(const char *note);
00623   // </group>
00624 
00625   // Normally GLPixelCanvas repaints the window when it is damaged. If
00626   // the user wishes to handle this, turn off auto refreshing.
00627   // <group>
00628   Boolean autoRefresh()const {return autoRefresh_;}
00629   void autoRefresh(Boolean refresh){ autoRefresh_ = refresh;}
00630   // </group>
00631 
00632   // OpenGL's push/popAttrib functions
00633   void pushAttrib(const GLbitfield attrib);
00634   void popAttrib();
00635   Boolean doubleBuffered()const{return doubleBuffered_;}
00636   Boolean isRGB()const{return isRGB_;}
00637 protected:
00638 
00639 private:
00640   // Handle the X expose event.  This is caught by the pixel canvas
00641   // and forwarded as a refresh event only if the pixel canvas changed
00642   // dimensions.  If there was no size change, the pixel canvas simply
00643   // copies its pixmap to the display without generating a refresh.
00644   void exposeHandler();
00645 
00646   // Called when window is resized.
00647   void resizeHandler();
00648   // Event Handling
00649   // <group>
00650   static void handleEventsCB(Widget w, GLPixelCanvas * xpc,
00651                              XEvent * ev, Boolean *);
00652   void handleEvents(Widget w, XEvent * ev);
00653   Boolean handleResizeEvent(uInt w, uInt h);
00654   // handle colorTable resize
00655   static void colorTableResizeCB(PixelCanvasColorTable * pcctbl, uInt, 
00656                                  GLPixelCanvas * xpc, 
00657                                  Display::RefreshReason reason);
00658 
00659   // </group>
00660 
00661 private:
00662   void initComponents();
00663 
00664   // Internal handling of display lists.
00665   // There is a list of GLPCDisplayLists. Item 0 always exists and is used
00666   // to redraw the window after expose events. Any other entries are
00667   // created in response to newList() calls.
00668   // <group>
00669   // Return a pointer to a new GLPC display list.
00670   GLPCDisplayList *createList(const char *name=NULL);
00671   // Create a new display list and add to the list of lists.
00672   uInt makeList(const char *name=NULL);
00673   // Grow the list.
00674   void resizeList();
00675   // Go through the list of display lists removing any unused lists.
00676   void cleanLists();
00677   // Called when the window is resized or cleared. Deletes the repaint
00678   // list.
00679   void purgeLists();
00680   // Remove a display list from list of lists. Returns True if list
00681   // was removed. False if listid is invalid or list has already been removed.
00682   Boolean removeList(uInt listid);
00683   // Called to begin caching.
00684   void beginListEntry(const char *name=NULL);
00685   void beginListEntry(GLPCDisplayListElement *e);
00686   // Called to end caching.
00687   void endListEntry();
00688   // </group>
00689   
00690   // Print <name> if tracing is turned on.
00691   // Most user callable drawing routines call this.
00692   // <group>
00693   void traceCheck(const char *name, uLong traceLevel, uInt nspaces);
00694   void traceCheck(const char *name, uLong traceLevel)
00695         {traceCheck(name, traceLevel, nspaces_);}
00696   // </group>
00697   // Holds both a color index and RGBA values.
00698   class GLPCColorValue {
00699     public:
00700         GLPCColorValue() { index=0; red=green=blue=0.0;alpha=1.0;}
00701         uLong index;    // Index for PseudoColor, packed for RGB.
00702         Float red, green, blue, alpha;
00703   };
00704   // Store the new value in the struct.
00705   //  If RGB mode, index is interpreted as a packed RGB value.
00706   void storeColorValue(GLPCColorValue &v, uLong value);
00707   //  If RGB mode, index is interpreted as an index into the virtual CT.
00708   void storeColorIndex(GLPCColorValue &v, uInt index);
00709   void storeColorValue(GLPCColorValue &v, Float r, Float g, Float b);
00710   void storeColorValue(GLPCColorValue &v,
00711                        Float r, Float g, Float b, Float a);
00712   // index is always treated as an index. (In RGB mode, the virtual
00713   // color table is used.
00714   void setCurrentColorIndex(uInt index, const char *name=NULL);
00715   void setCurrentColorValue(uLong value, const char *name=NULL);
00716   void setCurrentColorValue(Float r, Float g, Float b,
00717                             const char *name=NULL);
00718   void setCurrentColorValue(Float r, Float g, Float b, Float a,
00719                             const char *name=NULL);
00720   void setCurrentColorValue(const GLPCColorValue &v, const char *name=NULL);
00721 
00722   void setClearColorIndex(uInt index, const char *name=NULL);
00723   void setClearColorValue(uLong index, const char *name=NULL);
00724   void setClearColorValue(Float r, Float g, Float b,
00725                           const char *name=NULL);
00726   void setClearColorValue(Float r, Float g, Float b, Float a,
00727                           const char *name=NULL);
00728   // Tell OpenGL to use the given color index or RGB value depending
00729   // on whether we're in Index or RGB mode. If name is not NULL,
00730   // wrap the call in the usual begin/endListEntry, tracecheck.
00731   void setClearColorValue(const GLPCColorValue &v, const char *name=NULL);
00732 
00733   // Internal versions of public functions
00734   void drawColoredPoints_(const char *Name, const Vector<Int> &x1, 
00735                           const Vector<Int> &y1, 
00736                           const Vector<uInt> &colors);
00737   void drawColoredPoints_(const char *Name, const Vector<Float> &x1, 
00738                           const Vector<Float> &y1, 
00739                           const Vector<uInt> &colors);
00740   void drawColoredPoints_(const char *Name, const Vector<Double> &x1, 
00741                           const Vector<Double> &y1, 
00742                           const Vector<uInt> &colors);
00743   void pRWbuf(const char *str=NULL, int nspaces=0);
00744   // Routines to print warnings.
00745   void warn(const char *routine, const char *msg,
00746             const SourceLocation *where)const;
00747   void unimplemented(const char *routine, const SourceLocation *where)const;
00748 
00749 private:
00750   ::XDisplay    *display_;
00751   Widget        parent_;
00752   Widget        form_;
00753   Widget        drawArea_;
00754   XVisualInfo   *visualInfo_;
00755   Visual        *visual_;
00756   uInt          BlackPixel_;
00757   //  GL information.
00758   Bool          doubleBuffered_;
00759   Bool          isRGB_;                 // If not, it's indexed.
00760   //
00761   GLPixelCanvasColorTable *glpcctbl_;
00762   GLXContext    context_;
00763   GLbitfield    bufferMask_;
00764   uInt          width_;
00765   uInt          height_;
00766   uInt          depth_;
00767   Boolean       doClipping_;
00768   Int           clipX1_, clipY1_;
00769   Int           clipX2_, clipY2_;
00770   String        itsDeviceForegroundColor_, itsDeviceBackgroundColor_;
00772   GLPCColorValue currentColor_;
00773   // Clear color.
00774   GLPCColorValue clearColor_;
00775 
00776   Display::LineStyle    lineStyle_;  // Store style types
00777   Display::FillStyle    fillStyle_;  // for 'get's.
00779   Boolean       exposeHandlerFirstTime_;
00780   // Component / multi-channel buffers etc.
00781   uShort        *itsComponents_;                // Length = 3*width*height.
00782   Float         itsComponentX_, itsComponentY_, itsComponentZ_;
00783   Float         itsComponentScaleX_, itsComponentScaleY_;
00784   uLong         itsComponentWidth_, itsComponentHeight_;
00785   // Display lists.
00786   uInt          listSize_;
00787   uInt          numinuse_;
00788   uInt          nextfree_;
00789   uInt          sizeincr_;
00790   uInt          currentListID_;                 // Current display list id.
00791   GLPCDisplayList **dlists_;                    // List of display lists.
00792   GLPCDisplayListElement *currentElement_;      // Current caching element.
00793 
00794   Boolean       trace_;         // Print tracing info?
00795   uLong         traceLevel_;
00796   uInt          nspaces_;       // # of spaces to indent trace printout.
00797   mutable GLLogIO log_;
00798   Boolean       autoRefresh_;
00799 };
00800 
00801 
00802 } //# NAMESPACE CASA - END
00803 
00804 #endif