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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1