Changeset 41
- Timestamp:
- 01/12/10 22:31:22 (2 years ago)
- Location:
- cafu/trunk
- Files:
-
- 5 modified
-
CaWE/AppCaWE.cpp (modified) (8 diffs)
-
CaWE/AppCaWE.hpp (modified) (2 diffs)
-
CaWE/ParentFrame.cpp (modified) (9 diffs)
-
CaWE/ParentFrame.hpp (modified) (2 diffs)
-
CompilerSetup.py.tmpl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cafu/trunk/CaWE/AppCaWE.cpp
r36 r41 31 31 #include "wx/splash.h" 32 32 #include "wx/stdpaths.h" 33 34 #if defined(_WIN32)35 #define WIN32_LEAN_AND_MEAN36 #include <windows.h>37 #include <direct.h>38 #endif39 33 40 34 #include "AppCaWE.hpp" … … 51 45 #include "Tool.hpp" 52 46 #include "ToolManager.hpp" 47 48 #include "ClipSys/CollisionModelMan_impl.hpp" 53 49 #include "ConsoleCommands/Console.hpp" 54 50 #include "ConsoleCommands/ConsoleStdout.hpp" … … 58 54 #include "ConsoleCommands/ConFunc.hpp" 59 55 #include "FileSys/FileManImpl.hpp" 60 #include "MaterialSystem/MapComposition.hpp" 56 #include "GuiSys/GuiMan.hpp" 57 #include "GuiSys/Window.hpp" 61 58 #include "MaterialSystem/MaterialManagerImpl.hpp" 62 #include "MaterialSystem/Renderer.hpp"63 #include "MaterialSystem/TextureMap.hpp"64 #include "PlatformAux.hpp"65 #include "GuiSys/GuiMan.hpp"66 #include "GuiSys/GuiManImpl.hpp"67 #include "GuiSys/Window.hpp"68 59 #include "TypeSys.hpp" 69 #include "ClipSys/CollisionModelMan_impl.hpp"70 71 #ifdef _WIN3272 #elif __linux__73 #include <dirent.h>74 #include <dlfcn.h>75 #define __stdcall76 #define GetProcAddress dlsym77 #define FreeLibrary dlclose78 #endif79 60 80 61 … … 103 84 : wxApp(), 104 85 m_FileConfig(NULL), 105 m_ParentFrame(NULL), 106 m_RendererDLL(NULL) 86 m_ParentFrame(NULL) 107 87 { 108 88 static ConsoleInterpreterImplT ConInterpreterImpl; … … 166 146 m_FileConfig=new wxFileConfig("CaWE", "Carsten Fuchs Software", UserDataDir+"/CaWE.config"); 167 147 wxConfigBase::Set(m_FileConfig); 148 149 150 // Setup the global Material Manager pointer. 151 static MaterialManagerImplT MatManImpl; 152 153 MaterialManager=&MatManImpl; 154 155 // Register the material script with the CaWE materials definitions. 156 if (MaterialManager->RegisterMaterialScript(AppDir+"/res/CaWE.cmat", AppDir+"/res/").Size()==0) 157 wxMessageBox("CaWE.cmat not found in \""+AppDir+"\".", "WARNING"); 168 158 169 159 … … 228 218 /**********************************************/ 229 219 230 // Setup the global Material Manager pointer.231 static MaterialManagerImplT MatManImpl;232 233 MaterialManager=&MatManImpl;234 235 236 // Prepare the name strings.237 #ifdef SCONS_BUILD_DIR238 #define QUOTE(str) QUOTE_HELPER(str)239 #define QUOTE_HELPER(str) #str240 241 #ifdef _WIN32242 const wxString MatSysRendererDLLName=wxString("Libs/")+QUOTE(SCONS_BUILD_DIR)+"/MaterialSystem/RendererOpenGL12.dll";243 #else244 const wxString MatSysRendererDLLName=wxString("Libs/")+QUOTE(SCONS_BUILD_DIR)+"/MaterialSystem/libRendererOpenGL12.so";245 #endif246 247 #undef QUOTE248 #undef QUOTE_HELPER249 #else250 const wxString MatSysRendererDLLName=wxString("Renderers/RendererOpenGL12")+PlatformAux::GetEnvFileSuffix().c_str()+".dll";251 #endif252 253 254 // Load the DLL.255 #ifdef _WIN32256 m_RendererDLL=LoadLibrary(L"./RendererOpenGL12.dll");257 258 if (m_RendererDLL==NULL)259 m_RendererDLL=LoadLibrary(MatSysRendererDLLName);260 #else261 // Note that RTLD_GLOBAL must *not* be passed-in here, or else we get in trouble with subsequently loaded libraries.262 // (E.g. dlsym(RendererDLL, "GetRenderer") return identical results for different RendererDLLs.)263 // Please refer to the man page of dlopen for more details.264 m_RendererDLL=dlopen("./libRendererOpenGL12.so", RTLD_NOW);265 if (!m_RendererDLL) m_RendererDLL=dlopen(MatSysRendererDLLName.c_str(), RTLD_NOW);266 267 if (!m_RendererDLL) printf("%s\n", dlerror());268 #endif269 270 if (m_RendererDLL==NULL) { wxMessageBox("FAILED - could not load the library at "+MatSysRendererDLLName, "ERROR"); return false; }271 272 273 // Get the renderer.274 typedef MatSys::RendererI* (__stdcall *GetRendererT)(cf::ConsoleI* Console_, cf::FileSys::FileManI* FileMan_);275 276 #ifdef _WIN32277 GetRendererT GetRenderer=(GetRendererT)GetProcAddress(m_RendererDLL, "_GetRenderer@8");278 #else279 GetRendererT GetRenderer=(GetRendererT)GetProcAddress(m_RendererDLL, "GetRenderer");280 #endif281 282 if (!GetRenderer) { wxMessageBox("FAILED - could not get the address of the GetRenderer() function.", "ERROR"); FreeLibrary(m_RendererDLL); return false; }283 284 // When we get here, the console and the file man must already have been initialized.285 assert(Console!=NULL);286 assert(cf::FileSys::FileMan!=NULL);287 MatSys::Renderer=GetRenderer(Console, cf::FileSys::FileMan);288 289 if (MatSys::Renderer==NULL) { wxMessageBox("FAILED - could not get the renderer.", "ERROR"); FreeLibrary(m_RendererDLL); return false; }290 291 292 // Check if we already have OpenGL errors here.293 // Shouldn't be the case though, because any errors here must have been caused by the ParentFrames wxCanvas ctor.294 GLenum Error=glGetError();295 if (Error!=GL_NO_ERROR) wxMessageBox(wxString::Format("glGetError() reported error %i!", Error));296 297 if (!MatSys::Renderer->IsSupported())298 {299 wxMessageBox("Renderer "+MatSysRendererDLLName+" says that it's not supported.\n\n"300 "(This may be caused by your desktop being set to 16 BPP (or less).\n"301 "Please set your desktop bit-depth to 32 BPP (True Color), and try again.)");302 FreeLibrary(m_RendererDLL);303 return false;304 }305 306 MatSys::Renderer->Initialize();307 308 309 // Get the texture manager.310 typedef MatSys::TextureMapManagerI* (__stdcall *GetTMMT)();311 312 #ifdef _WIN32313 GetTMMT GetTMM=(GetTMMT)GetProcAddress(m_RendererDLL, "_GetTextureMapManager@0");314 #else315 GetTMMT GetTMM=(GetTMMT)GetProcAddress(m_RendererDLL, "GetTextureMapManager");316 #endif317 318 if (!GetTMM) { wxMessageBox("FAILED - could not get the address of the GetTextureMapManager() function.", "ERROR"); FreeLibrary(m_RendererDLL); return false; }319 MatSys::TextureMapManager=GetTMM();320 if (MatSys::TextureMapManager==NULL) { wxMessageBox("No TextureMapManager obtained.", "ERROR"); FreeLibrary(m_RendererDLL); return false; }321 322 // Register the material script with the CaWE materials definitions.323 if (MaterialManager->RegisterMaterialScript(AppDir+"/res/CaWE.cmat", AppDir+"/res/").Size()==0)324 wxMessageBox("CaWE.cmat not found in \""+AppDir+"\".", "WARNING");325 326 // Create a very simple lightmap for the materials that need one, and register it with the renderer.327 char Data[]={ 255, 255, 255, 255, 255, 255, 0, 0,328 255, 255, 255, 255, 255, 255, 0, 0 };329 330 MatSys::Renderer->SetCurrentLightMap(MatSys::TextureMapManager->GetTextureMap2D(Data, 2, 2, 3, true, MapCompositionT(MapCompositionT::Linear, MapCompositionT::Linear)));331 MatSys::Renderer->SetCurrentLightDirMap(NULL); // The MatSys provides a default for LightDirMaps when NULL is set.332 333 334 220 // Initialize the global options from the CaWE config files. 335 221 Options.Init(); … … 339 225 CursorMan=new CursorManT; 340 226 341 // Initialize the GUI managager.342 // This has to be done after all materials are loaded (during Options initialization) so the GuiManager finds its default material.343 cf::GuiSys::GuiMan=new cf::GuiSys::GuiManImplT();344 345 227 return wxApp::OnInit(); 346 228 } … … 356 238 m_FileConfig=NULL; 357 239 358 // Release the GuiManager BEFORE the renderer.359 delete cf::GuiSys::GuiMan;360 cf::GuiSys::GuiMan=NULL;361 362 // Unload the Cafu Material System.363 // Checks for NULL are required to gracefully handle (DLL loading, and other) failures in InitInstance().364 if (MatSys::Renderer!=NULL && m_RendererDLL)365 {366 MatSys::Renderer->Release();367 FreeLibrary(m_RendererDLL);368 }369 370 240 // TODO: delete cf::FileSys::FileMan; // Shoud have cf::FileSys::FileMan=new cf::FileSys::FileManImplT; in OnInit(). 371 241 cf::FileSys::FileMan=NULL; -
cafu/trunk/CaWE/AppCaWE.hpp
r36 r41 27 27 #include "wx/wx.h" 28 28 29 #if __linux__30 #define HMODULE void*31 #endif32 33 34 29 class ParentFrameT; 35 30 class wxFileConfig; … … 54 49 wxFileConfig* m_FileConfig; 55 50 ParentFrameT* m_ParentFrame; 56 HMODULE m_RendererDLL;57 51 }; 58 52 -
cafu/trunk/CaWE/ParentFrame.cpp
r36 r41 35 35 #include "ModelEditor/Document.hpp" 36 36 37 #include "ConsoleCommands/Console.hpp" 38 #include "FileSys/FileManImpl.hpp" 37 39 #include "GuiSys/GuiImpl.hpp" // Needed to catch InitErrorT if GUI document creation fails. 40 #include "GuiSys/GuiManImpl.hpp" 41 #include "MaterialSystem/MapComposition.hpp" 42 #include "MaterialSystem/Renderer.hpp" 43 #include "MaterialSystem/TextureMap.hpp" 38 44 #include "TextParser/TextParser.hpp" 45 #include "PlatformAux.hpp" 39 46 40 47 #include "wx/wx.h" … … 50 57 #include <fstream> 51 58 59 #ifdef _WIN32 60 #define WIN32_LEAN_AND_MEAN 61 #include <windows.h> 62 #include <direct.h> 63 #elif __linux__ 64 #include <dirent.h> 65 #include <dlfcn.h> 66 #define __stdcall 67 #define GetProcAddress dlsym 68 #define FreeLibrary dlclose 69 #endif 70 52 71 53 72 BEGIN_EVENT_TABLE(ParentFrameT, wxMDIParentFrame) … … 55 74 EVT_SIZE(ParentFrameT::OnSize) 56 75 #endif 76 EVT_SHOW(ParentFrameT::OnShow) 57 77 EVT_CLOSE(ParentFrameT::OnClose) 58 78 EVT_MENU_RANGE(ID_MENU_FILE_NEW_MAP, ID_MENU_FILE_EXIT, ParentFrameT::OnMenuFile) … … 85 105 #endif 86 106 m_GLCanvas(NULL), 87 m_GLContext(NULL) 107 m_GLContext(NULL), 108 m_RendererDLL(NULL) 88 109 { 89 110 wxMenuBar *item0 = new wxMenuBar; … … 142 163 143 164 144 // Create the parent GL canvas. 145 m_GLCanvas=new wxGLCanvas(this, -1, OpenGLAttributeList, wxPoint(600, 5), wxSize(10, 10), 0, "ParentGLCanvas"); 146 147 148 Centre(wxBOTH); 149 Maximize(true); // The wxMAXIMIZE frame style does not seem to have any effect for this frame...(?) 150 Show(true); 165 // Create the parent GL canvas and a GL context. 166 m_GLCanvas =new wxGLCanvas(this, -1, OpenGLAttributeList, wxPoint(600, 5), wxSize(10, 10), 0, "ParentGLCanvas"); 151 167 m_GLContext=new wxGLContext(m_GLCanvas); 152 wxASSERT(m_GLContext); 153 m_GLCanvas->SetCurrent(*m_GLContext); // Aha - under X11 this must be *after* Show(true), not before the window is opened!154 155 // The above attribute list can certainly NOT be met on 16 BPP desktops. 156 // However, we do not check if the RC of the m_GLCanvas is valid here (it should), 157 // as the IsSupported() method of each MatSys Renderer does the same check, too,158 // a nd I have adjusted the error message appropriately there (see AppCaWE.cpp,159 // the user is told to check whether his desktop is set to 32 BPP if IsSupported() fails).160 // const char* Version=(char const*)glGetString(GL_VERSION); // Another way to see if the RC is valid: Version!=NULL <==> RC valid.161 // printf("%s (%u): GL_VERSION string is \"%s\".\n", __FILE__, __LINE__, Version==NULL ? "NULL" : Version); 168 169 Maximize(); // Under wxGTK, the wxMAXIMIZE frame style does not seem to suffice... 170 Show(); // Without this, the parent frame is not shown... 171 172 #ifdef __WXMSW__ 173 // ARGH! See my message "wx 2.9.0, Showing parent frame during app init" to wx-users 174 // at http://article.gmane.org/gmane.comp.lib.wxwindows.general/68490 for details. 175 wxShowEvent SE(0, true); 176 OnShow(SE); 177 #endif 162 178 } 163 179 … … 166 182 { 167 183 m_FileHistory.Save(*wxConfigBase::Get()); 184 185 // Release the GuiManager (BEFORE the renderer). 186 if (cf::GuiSys::GuiMan!=NULL) 187 { 188 delete cf::GuiSys::GuiMan; 189 cf::GuiSys::GuiMan=NULL; 190 } 191 192 // Release the Cafu Material System. 193 MatSys::TextureMapManager=NULL; 194 195 if (MatSys::Renderer!=NULL) 196 { 197 MatSys::Renderer->Release(); 198 MatSys::Renderer=NULL; 199 } 200 201 if (m_RendererDLL!=NULL) 202 { 203 FreeLibrary(m_RendererDLL); 204 m_RendererDLL=NULL; 205 } 168 206 } 169 207 … … 204 242 } 205 243 #endif 244 245 246 void ParentFrameT::OnShow(wxShowEvent& SE) 247 { 248 if (SE.IsShown() && m_RendererDLL==NULL) 249 { 250 // Initialize the Material System. 251 // This code is in this place due to a few peculiarities of OpenGL under GTK that do not exist under MSW: 252 // - First, an OpenGL context can only be made current with a canvas that is shown on the screen. 253 // - Second, calling Show() in the ctor above doesn't show the frame immediately - that requires 254 // getting back to the main event loop first. 255 // Consequently, the first and best opportunity for initializing the MatSys is here. 256 wxASSERT(m_GLCanvas->IsShownOnScreen()); 257 258 // If this was in the ctor, it would trigger an assertion in debug build and yield an invalid (unusable) 259 // OpenGL context in release builds (the GL code in the MatSys::Renderer->IsSupported() methods would fail). 260 m_GLCanvas->SetCurrent(*m_GLContext); 261 262 // Prepare the name strings. 263 #ifdef SCONS_BUILD_DIR 264 #define QUOTE(str) QUOTE_HELPER(str) 265 #define QUOTE_HELPER(str) #str 266 267 #ifdef _WIN32 268 const wxString MatSysRendererDLLName=wxString("Libs/")+QUOTE(SCONS_BUILD_DIR)+"/MaterialSystem/RendererOpenGL12.dll"; 269 #else 270 const wxString MatSysRendererDLLName=wxString("Libs/")+QUOTE(SCONS_BUILD_DIR)+"/MaterialSystem/libRendererOpenGL12.so"; 271 #endif 272 273 #undef QUOTE 274 #undef QUOTE_HELPER 275 #else 276 const wxString MatSysRendererDLLName=wxString("Renderers/RendererOpenGL12")+PlatformAux::GetEnvFileSuffix().c_str()+".dll"; 277 #endif 278 279 280 // Load the DLL. 281 #ifdef _WIN32 282 m_RendererDLL=LoadLibrary(L"./RendererOpenGL12.dll"); 283 284 if (m_RendererDLL==NULL) 285 m_RendererDLL=LoadLibrary(MatSysRendererDLLName); 286 #else 287 // Note that RTLD_GLOBAL must *not* be passed-in here, or else we get in trouble with subsequently loaded libraries. 288 // (E.g. dlsym(RendererDLL, "GetRenderer") return identical results for different RendererDLLs.) 289 // Please refer to the man page of dlopen for more details. 290 m_RendererDLL=dlopen("./libRendererOpenGL12.so", RTLD_NOW); 291 if (!m_RendererDLL) m_RendererDLL=dlopen(MatSysRendererDLLName.c_str(), RTLD_NOW); 292 293 if (!m_RendererDLL) printf("%s\n", dlerror()); 294 #endif 295 296 if (m_RendererDLL==NULL) { wxMessageBox("FAILED - could not load the library at "+MatSysRendererDLLName, "ERROR"); Destroy(); return; } 297 298 299 // Get the renderer. 300 typedef MatSys::RendererI* (__stdcall *GetRendererT)(cf::ConsoleI* Console_, cf::FileSys::FileManI* FileMan_); 301 302 #ifdef _WIN32 303 GetRendererT GetRenderer=(GetRendererT)GetProcAddress(m_RendererDLL, "_GetRenderer@8"); 304 #else 305 GetRendererT GetRenderer=(GetRendererT)GetProcAddress(m_RendererDLL, "GetRenderer"); 306 #endif 307 308 if (!GetRenderer) { wxMessageBox("FAILED - could not get the address of the GetRenderer() function.", "ERROR"); Destroy(); return; } 309 310 // When we get here, the console and the file man must already have been initialized. 311 wxASSERT(Console!=NULL); 312 wxASSERT(cf::FileSys::FileMan!=NULL); 313 MatSys::Renderer=GetRenderer(Console, cf::FileSys::FileMan); 314 315 if (MatSys::Renderer==NULL) { wxMessageBox("FAILED - could not get the renderer.", "ERROR"); Destroy(); return; } 316 317 318 // Check if we already have OpenGL errors here. 319 // Shouldn't be the case though, because any errors here must have been caused by the ParentFrames wxCanvas ctor. 320 GLenum Error=glGetError(); 321 if (Error!=GL_NO_ERROR) wxMessageBox(wxString::Format("glGetError() reported error %i!", Error)); 322 323 if (!MatSys::Renderer->IsSupported()) 324 { 325 wxMessageBox("Renderer "+MatSysRendererDLLName+" says that it's not supported.\n\n" 326 "This may be caused by your desktop being set to 16 BPP (or less).\n" 327 "Please set your desktop bit-depth to 24 or 32 BPP (True Color), and try again."); 328 Destroy(); 329 return; 330 } 331 332 MatSys::Renderer->Initialize(); 333 334 335 // Get the texture manager. 336 typedef MatSys::TextureMapManagerI* (__stdcall *GetTMMT)(); 337 338 #ifdef _WIN32 339 GetTMMT GetTMM=(GetTMMT)GetProcAddress(m_RendererDLL, "_GetTextureMapManager@0"); 340 #else 341 GetTMMT GetTMM=(GetTMMT)GetProcAddress(m_RendererDLL, "GetTextureMapManager"); 342 #endif 343 344 if (!GetTMM) { wxMessageBox("FAILED - could not get the address of the GetTextureMapManager() function.", "ERROR"); Destroy(); return; } 345 MatSys::TextureMapManager=GetTMM(); 346 if (MatSys::TextureMapManager==NULL) { wxMessageBox("No TextureMapManager obtained.", "ERROR"); Destroy(); return; } 347 348 // Create a very simple lightmap for the materials that need one, and register it with the renderer. 349 char Data[]={ 255, 255, 255, 255, 255, 255, 0, 0, 350 255, 255, 255, 255, 255, 255, 0, 0 }; 351 352 MatSys::Renderer->SetCurrentLightMap(MatSys::TextureMapManager->GetTextureMap2D(Data, 2, 2, 3, true, MapCompositionT(MapCompositionT::Linear, MapCompositionT::Linear))); 353 MatSys::Renderer->SetCurrentLightDirMap(NULL); // The MatSys provides a default for LightDirMaps when NULL is set. 354 355 356 // Initialize the GUI managager. 357 // This has to be done after all materials are loaded (AppCaWE::OnInit()) and after the MatSys::Renderer has been initialized, 358 // so that the GuiManager finds its default material and can register it for rendering. 359 cf::GuiSys::GuiMan=new cf::GuiSys::GuiManImplT(); 360 } 361 } 206 362 207 363 … … 312 468 void ParentFrameT::OnMenuFile(wxCommandEvent& CE) 313 469 { 470 wxASSERT(m_RendererDLL!=NULL && MatSys::Renderer!=NULL); 471 314 472 switch (CE.GetId()) 315 473 { … … 670 828 void ParentFrameT::OnMenuHelp(wxCommandEvent& CE) 671 829 { 830 wxASSERT(m_RendererDLL!=NULL && MatSys::Renderer!=NULL); 831 672 832 switch (CE.GetId()) 673 833 { -
cafu/trunk/CaWE/ParentFrame.hpp
r36 r41 28 28 #include "wx/mdi.h" 29 29 #include "Templates/Array.hpp" 30 31 #if __linux__ 32 #define HMODULE void* 33 #endif 30 34 31 35 … … 110 114 void OnSize (wxSizeEvent& SE); 111 115 #endif 116 void OnShow (wxShowEvent& SE); ///< Event handler for "has been shown" events. 112 117 void OnClose (wxCloseEvent& CE); ///< Event handler for close events, e.g. after a system close button or command or a call to Close(). See wx Window Deletion Overview for more details. 113 118 void OnMenuFile(wxCommandEvent& CE); ///< Event handler for File menu events. 114 119 void OnMenuHelp(wxCommandEvent& CE); ///< Event handler for Help menu events. 120 121 HMODULE m_RendererDLL; 115 122 116 123 DECLARE_EVENT_TABLE() -
cafu/trunk/CompilerSetup.py.tmpl
r36 r41 1 1 # Edit the settings and paths in this file as required for your system. 2 #3 # The correct paths are easily determined by browsing your programs folder with4 # the Windows Explorer, by opening the Visual Studio Command Prompt and viewing5 # the environment variables (enter the SET command in order to output them all),6 # or by looking them up in the Visual Studio IDE.7 8 2 9 3 # The default compiler to be used for each platform. 10 4 # Note that this can easily be overridden at the command-line 11 # by the "cmp" parameter. Example: scons -Q cmp=vc 912 defaultCompilerWin32="vc 8"; # Valid values are "vc8" and "vc9".5 # by the "cmp" parameter. Example: scons -Q cmp=vc8 6 defaultCompilerWin32="vc9"; # Valid values are "vc8" and "vc9". 13 7 defaultCompilerLinux="g++"; # Currently, only "g++" is a valid value. 14 8
