nux-1.14.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef NUXGRAPHICSGLOBALINITIALIZER_H 00024 #define NUXGRAPHICSGLOBALINITIALIZER_H 00025 00026 #define NUX_GLOBAL_GRAPHICS_OBJECT_INIT_SEQUENCE() \ 00027 NUX_GLOBAL_OBJECT_VARIABLE(RenderingStats); \ 00028 NUX_GLOBAL_OBJECT_VARIABLE(NuxGraphicsResources); 00029 00030 namespace nux 00031 { 00032 00033 class NuxGraphicsGlobalSingletonInitializer 00034 { 00035 NUX_DISABLE_OBJECT_COPY (NuxGraphicsGlobalSingletonInitializer); 00036 NuxGraphicsGlobalSingletonInitializer *operator & (); 00037 const NuxGraphicsGlobalSingletonInitializer *operator & () const; 00038 00039 public: 00040 NuxGraphicsGlobalSingletonInitializer(); 00041 ~NuxGraphicsGlobalSingletonInitializer(); 00042 00043 static bool Ready(); 00044 private: 00045 static bool m_NuxGraphicsGlobalObjectsReady; 00046 00047 NUX_GLOBAL_GRAPHICS_OBJECT_INIT_SEQUENCE(); 00048 }; 00049 00050 00051 // Nifty Counter idiom. See http://www-d0.fnal.gov/KAI/doc/tutorials/static_initialization.html 00052 class NuxGraphicsGlobalInitializer 00053 { 00054 public: 00055 NuxGraphicsGlobalInitializer(); 00056 ~NuxGraphicsGlobalInitializer(); 00057 private: 00058 static int m_Count; 00059 }; 00060 00061 // Every compilation unit that includes this file will have its own instance of sGlobalInitializer. sGlobalInitializer is initialized 00062 // before the main function of the program is called. The first time sGlobalInitializer is initialized, it calls SystemStart() to create 00063 // our global object singleton. In SystemStart() we have a change to create our singletons in any order we like. 00064 // When the program exits, every instance of sGlobalInitializer will be destroyed. The last instance destroyed will call SystemShutdown(). 00065 // In SystemShutdown() we can destroy our global objects in any order we like. 00066 00067 static NuxGraphicsGlobalInitializer sNuxGraphicsGlobalInitializer; 00068 00069 00070 } 00071 00072 #endif // NUXGRAPHICSGLOBALINITIALIZER_H