GLPCDisplayList.h

Go to the documentation of this file.
00001 //# GLPCDisplayList.h: this defines GLPCDisplayList, which acts as a wrapper
00002 //# around OpenGL display lists for the GLPixelCanvas.
00003 //# Copyright (C) 2001
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //# $Id$
00028 
00029 // <summary>
00030 //      Display list support for GLPixelCanvas.
00031 // </summary>
00032 // <use visibility=local>
00033 //
00034 // <synopsis>
00035 // These classes are used to implement display list support for GLPixelCanvas.
00036 // Execution tracing is supported. The variable 'nspaces' gives the number
00037 // of spaces to indent the printout. All of these classes are used internally
00038 // by GLPixelCanvas and wouldn't be useful elsewhere.
00039 // </synopsis>
00040 //
00041 // <prerequisite>
00042 //   <li> None
00043 // </prerequisite>
00044 //
00045 // <thrown>
00046 //  None
00047 // </thrown>
00048 //
00049 // <todo asof="2001/10/9">
00050 //
00051 // </todo>
00052 
00053 #ifndef TRIALDISPLAY_GLPCDISPLAYLIST_H
00054 #define TRIALDISPLAY_GLPCDISPLAYLIST_H
00055 
00056 #include <string.h>
00057 #include <GL/gl.h>
00058 #include <casa/aips.h>
00059 #include <casa/BasicSL/String.h>
00060 
00061 namespace casa { //# NAMESPACE CASA - BEGIN
00062 
00063 // <summary>
00064 // Base class for the various display list subclasses.
00065 // </summary>
00066         class GLPCDisplayListElement {
00067         public:
00068                 // Draw element unless disabled or force is True.
00069                 virtual void call(Bool force=False, const uInt nspaces=0);
00070 
00071                 // enable/disable
00072                 // <group>
00073                 Bool enabled()const {
00074                         return enabled_;
00075                 }
00076                 Bool disabled()const {
00077                         return !enabled_;
00078                 }
00079                 virtual void disable();
00080                 virtual void enable();
00081                 // </group>
00082 
00083                 // Each element has a name which is printed out when tracing.
00084                 // <group>
00085                 const char *name()const {
00086                         return name_.chars();
00087                 }
00088                 void name(const char *);
00089                 // </group>
00090                 // Enable/disable tracing.
00091                 // <group>
00092                 Bool trace()const {
00093                         return trace_;
00094                 }
00095                 void trace(const Bool t) {
00096                         trace_ = t;
00097                 }
00098                 // </group>
00099                 // Begin recording commands.
00100                 // Recording is a one shot deal. After stop is called, recording
00101                 // can not be reenabled.
00102                 virtual void start();   //# Start recording.
00103                 // Stop display list recording. Ignored if not already recording.
00104                 virtual void stop();
00105                 // Each element is reference counted.
00106                 uLong useCount()const {
00107                         return usage_;
00108                 }
00109                 void ref();
00110                 void unref();
00111         protected:
00112                 GLPCDisplayListElement(const char *name=NULL);
00113                 // Elements self delete when the reference count goes to 0.
00114                 virtual ~GLPCDisplayListElement();
00115                 void traceCheck(uInt spaces=0, const char *str=NULL,
00116                                 const char *name=NULL);
00117         private:
00118                 uLong   usage_;
00119                 Bool    enabled_;
00120                 Bool    trace_;
00121                 String  name_;
00122         };
00123 
00124 // <summary>
00125 // Returns a Display List Element for recording GL commands.
00126 // </summary>
00127 // <synopsis>
00128 // Returns a Display List Element for recording GL commands.
00129 // Commands are recorded until stop is called by creating an OpenGL
00130 // display list and letting OpenGL do the actual recording. Calling
00131 // stop ends the list. Typically, these OpenGL lists are very short,
00132 // containing just one or two commands. eg. draw a rectangle.
00133 // </synopsis>
00134         class GLPCDisplayListEntry : public GLPCDisplayListElement {
00135         public:
00136                 enum RECORDSTATE { INITED, RECORDING, STOPPED};
00137 
00138                 GLPCDisplayListEntry::GLPCDisplayListEntry(
00139                     const char *name=NULL,
00140                     GLenum mode=GL_COMPILE_AND_EXECUTE);
00141                 virtual ~GLPCDisplayListEntry();
00142                 //# Draw list.
00143                 virtual void call(Bool force, const uInt spaces);
00144                 //# Recording is a one shot deal. After stop is called, recording
00145                 //# can not be reenabled.
00146                 virtual void start();   //# Start recording.
00147                 //# Stop display list recording. Ignored if not already recording.
00148                 virtual void stop();
00149         protected:
00150         private:
00151                 GLenum          mode_;
00152                 GLuint          id_;
00153                 RECORDSTATE     recording_;
00154         };
00155 
00156 //#////////////////////////////////////////////////////////////////
00157 
00158 // <summary>
00159 // DisplayListElement that can contain lists of other DisplayListElements.
00160 // </summary>
00161 // <synopsis>
00162 // When GLPixelCanvas::newList() is called, a GLPCDisplayList is created
00163 // to hold all the GLPCDisplayListEntrys that are created. A GLPCDisplayList
00164 // can also hold other GLPCDisplayLists (drawList called inside a list).
00165 // </synopsis>
00166         class GLPCDisplayList : public GLPCDisplayListElement {
00167         public:
00168                 // Amount by which to increment the list of display lists when
00169                 // it fills up.
00170                 enum {DefaultSizeIncrement=16};
00171 
00172                 GLPCDisplayList(const char *name=NULL,
00173                                 uInt sizeincr=GLPCDisplayList::DefaultSizeIncrement);
00174 
00175                 // Copy a display list's list.
00176                 GLPCDisplayList(const GLPCDisplayList &list);
00177                 ~GLPCDisplayList();
00178 
00179                 // Append another element to list.
00180                 void add(GLPCDisplayListElement *);
00181 
00182                 // Run the current list.
00183                 virtual void call(Bool force=False, uInt spaces=0);
00184 
00185                 // Translate the list.
00186                 // Set translation values. New values are added to current.
00187                 void translate(Float xt, Float yt, Float zt=0.0);
00188 
00189                 //# Miscellaneous
00190 
00191                 // Return current translation
00192                 void  translation(Float &xo, Float &yo)const;
00193                 void  translation(Float &xo, Float &yo, Float &zo)const;
00194                 // Return/Set amount to increase id list by.
00195                 uInt sizeincrement()const {
00196                         return sizeincr_;
00197                 }
00198                 void sizeincrement(const uInt sizeincr) {
00199                         sizeincr_ = sizeincr;
00200                 }
00201         protected:
00202         private:
00203                 void resize();
00204                 void unrefall();
00205 
00206                 GLfloat xt_, yt_, zt_;  //# Amount to translate display list.
00207                 uInt    sizeincr_;      //# Amount to increase listids_ when it's full.
00208                 uInt    numentries_;    //# # of entries & index to next free.
00209                 uInt    listSize_;      //# # of slots in list.
00210                 GLPCDisplayListElement **list_;
00211         };
00212 
00213 
00214 } //# NAMESPACE CASA - END
00215 
00216 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1