00001 /* 00002 00003 ************************************************************************* 00004 00005 ArmageTron -- Just another Tron Lightcycle Game in 3D. 00006 Copyright (C) 2008 Manuel Moos (manuel@moosnet.de) and the AA Development Team 00007 00008 ************************************************************************** 00009 00010 This program is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU General Public License 00012 as published by the Free Software Foundation; either version 2 00013 of the License, or (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00023 00024 *************************************************************************** 00025 00026 */ 00027 00028 #ifndef ArmageTron_DISPLAYLIST_H 00029 #define ArmageTron_DISPLAYLIST_H 00030 00031 #include "aa_config.h" 00032 00033 #include "rGL.h" 00034 #include "tLinkedList.h" 00035 00036 00037 // Usage example for caching display elements: 00038 00039 #if 0 00040 void example() 00041 { 00042 static rDisplayList list; 00043 00044 // + some logic calling list.Clear() when it needs updating 00045 00046 if ( !list.Call() ) 00047 { 00048 rDisplayListFiller filler( list ); 00049 00050 // + rendering code 00051 } 00052 } 00053 00054 // Things we have found to be problematic in certain OpenGL 00055 // implementations: 00056 // - Redundant color settings (glColor3f(1,1,1);glColor3f(1,1,1);) 00057 // - Infinite points (glVertex4f(1,1,0,0);) 00058 #endif 00059 00061 class rDisplayList: public tListItem< rDisplayList > 00062 { 00063 friend class rDisplayListFiller; 00064 public: 00065 rDisplayList(); 00066 ~rDisplayList(); 00067 00068 bool IsSet() const 00069 { 00070 #ifndef DEDICATED 00071 return list_ && !inhibit_; 00072 #else 00073 return false; 00074 #endif 00075 } 00076 00077 bool IsInhibited() const 00078 { 00079 #ifndef DEDICATED 00080 return inhibit_; 00081 #else 00082 return false; 00083 #endif 00084 } 00085 00087 static bool IsRecording(); 00088 00090 bool Call() 00091 { 00092 return OnCall(); 00093 } 00094 00096 void Clear( int inhibitGeneration = 1 ); 00097 00099 static void ClearAll(); 00100 00102 static void Cancel(); 00103 protected: 00105 virtual bool OnCall(); 00106 private: 00107 rDisplayList( rDisplayList const & ); 00108 rDisplayList & operator = ( rDisplayList const & ); 00109 00110 #ifndef DEDICATED 00111 GLuint list_; 00112 int inhibit_; 00113 bool filling_; 00114 #endif 00115 }; 00116 00118 class rDisplayListAlphaSensitive: public rDisplayList 00119 { 00120 public: 00121 rDisplayListAlphaSensitive(); 00122 00123 protected: 00125 virtual bool OnCall(); 00126 private: 00127 bool lastAlpha_; 00128 }; 00129 00131 class rDisplayListFiller 00132 { 00133 friend class rDisplayList; 00134 public: 00136 explicit rDisplayListFiller( rDisplayList & list ); 00137 ~rDisplayListFiller(); 00138 00140 void Start(); 00141 00143 void Stop(); 00144 00145 private: 00146 rDisplayListFiller( rDisplayListFiller const & ); 00147 rDisplayListFiller & operator = ( rDisplayListFiller const & ); 00148 00149 #ifndef DEDICATED 00151 rDisplayList & list_; 00152 #endif 00153 }; 00154 00155 #endif 00156 00157