casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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 {return enabled_;}
00074         Bool disabled()const {return !enabled_;}
00075         virtual void disable();
00076         virtual void enable();
00077         // </group>
00078 
00079         // Each element has a name which is printed out when tracing.
00080         // <group>
00081         const char *name()const{return name_.chars();}
00082         void name(const char *);
00083         // </group>
00084         // Enable/disable tracing.
00085         // <group>
00086         Bool trace()const{return trace_;}
00087         void trace(const Bool t){ trace_ = t;}
00088         // </group>
00089         // Begin recording commands.
00090         // Recording is a one shot deal. After stop is called, recording
00091         // can not be reenabled.
00092         virtual void start();   //# Start recording.
00093         // Stop display list recording. Ignored if not already recording.
00094         virtual void stop();
00095         // Each element is reference counted.
00096         uLong useCount()const {return usage_;}
00097         void ref();
00098         void unref();
00099   protected:
00100         GLPCDisplayListElement(const char *name=NULL);
00101         // Elements self delete when the reference count goes to 0.
00102         virtual ~GLPCDisplayListElement();
00103         void traceCheck(uInt spaces=0, const char *str=NULL,
00104                         const char *name=NULL);
00105   private:
00106         uLong   usage_;
00107         Bool    enabled_;
00108         Bool    trace_;
00109         String  name_;
00110 };
00111 
00112 // <summary>
00113 // Returns a Display List Element for recording GL commands.
00114 // </summary>
00115 // <synopsis>
00116 // Returns a Display List Element for recording GL commands.
00117 // Commands are recorded until stop is called by creating an OpenGL
00118 // display list and letting OpenGL do the actual recording. Calling
00119 // stop ends the list. Typically, these OpenGL lists are very short,
00120 // containing just one or two commands. eg. draw a rectangle.
00121 // </synopsis>
00122 class GLPCDisplayListEntry : public GLPCDisplayListElement {
00123   public:
00124         enum RECORDSTATE { INITED, RECORDING, STOPPED};
00125 
00126         GLPCDisplayListEntry::GLPCDisplayListEntry(
00127                                         const char *name=NULL,
00128                                         GLenum mode=GL_COMPILE_AND_EXECUTE);
00129         virtual ~GLPCDisplayListEntry();
00130         //# Draw list.
00131         virtual void call(Bool force, const uInt spaces);
00132         //# Recording is a one shot deal. After stop is called, recording
00133         //# can not be reenabled.
00134         virtual void start();   //# Start recording.
00135         //# Stop display list recording. Ignored if not already recording.
00136         virtual void stop();
00137   protected:
00138   private:
00139         GLenum          mode_;
00140         GLuint          id_;    
00141         RECORDSTATE     recording_;
00142 };
00143 
00144 //#////////////////////////////////////////////////////////////////
00145 
00146 // <summary>
00147 // DisplayListElement that can contain lists of other DisplayListElements.
00148 // </summary>
00149 // <synopsis>
00150 // When GLPixelCanvas::newList() is called, a GLPCDisplayList is created
00151 // to hold all the GLPCDisplayListEntrys that are created. A GLPCDisplayList
00152 // can also hold other GLPCDisplayLists (drawList called inside a list).
00153 // </synopsis>
00154 class GLPCDisplayList : public GLPCDisplayListElement {
00155   public:
00156         // Amount by which to increment the list of display lists when
00157         // it fills up.
00158         enum {DefaultSizeIncrement=16};
00159 
00160         GLPCDisplayList(const char *name=NULL,
00161                         uInt sizeincr=GLPCDisplayList::DefaultSizeIncrement);
00162 
00163         // Copy a display list's list.
00164         GLPCDisplayList(const GLPCDisplayList &list);
00165         ~GLPCDisplayList();
00166 
00167         // Append another element to list.
00168         void add(GLPCDisplayListElement *);
00169 
00170         // Run the current list.
00171         virtual void call(Bool force=False, uInt spaces=0);
00172 
00173         // Translate the list.
00174         // Set translation values. New values are added to current.
00175         void translate(Float xt, Float yt, Float zt=0.0);
00176 
00177         //# Miscellaneous
00178 
00179         // Return current translation
00180         void  translation(Float &xo, Float &yo)const;
00181         void  translation(Float &xo, Float &yo, Float &zo)const;
00182         // Return/Set amount to increase id list by.
00183         uInt sizeincrement()const{return sizeincr_;}
00184         void sizeincrement(const uInt sizeincr) { sizeincr_ = sizeincr;}
00185   protected:
00186   private:
00187         void resize();
00188         void unrefall();
00189 
00190         GLfloat xt_, yt_, zt_;  //# Amount to translate display list.
00191         uInt    sizeincr_;      //# Amount to increase listids_ when it's full.
00192         uInt    numentries_;    //# # of entries & index to next free.
00193         uInt    listSize_;      //# # of slots in list.
00194         GLPCDisplayListElement **list_;
00195 };
00196 
00197 
00198 } //# NAMESPACE CASA - END
00199 
00200 #endif