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 #include "GLResource.h" 00023 #include "FontTexture.h" 00024 #include "NuxGraphicsResources.h" 00025 #include "GLResourceManager.h" 00026 00027 namespace nux 00028 { 00029 00030 NUX_IMPLEMENT_GLOBAL_OBJECT (NuxGraphicsResources); 00031 00032 void NuxGraphicsResources::Constructor() 00033 { 00034 00035 } 00036 00037 void NuxGraphicsResources::Destructor() 00038 { 00039 00040 } 00041 00042 void NuxGraphicsResources::InitializeResources() 00043 { 00044 // FilePath m_FilePath; 00045 // m_FilePath.AddSearchPath(TEXT("")); // for case where fully qualified path is given 00046 // m_FilePath.AddSearchPath(TEXT("./ini")); 00047 // m_FilePath.AddSearchPath(TEXT("../ini")); 00048 // m_FilePath.AddSearchPath(TEXT("../../ini")); 00049 // m_FilePath.AddSearchPath(TEXT("../../../ini")); 00050 // 00051 // 00052 // NString file_search = TEXT("inalogic.ini"); 00053 // NString FileName = m_FilePath.GetFile(file_search.GetTCharPtr()); 00054 // if (FileName == TEXT("")) 00055 // { 00056 // nuxCriticalMsg(TEXT("[GraphicsDisplay::GraphicsDisplay] Can't find inalogic.ini file.")); 00057 // // exit(-1); 00058 // } 00059 // 00060 // if(FileName != TEXT("")) 00061 // { 00062 // NString key_name = TEXT("UseBackupFBO"); 00063 // NString section_name = TEXT("OpenGLSystem"); 00064 // 00065 // if(CIniFile::RecordExists(key_name.GetTCharPtr(), section_name.GetTCharPtr(), FileName.GetTCharPtr()) == false) 00066 // { 00067 // nuxDebugMsg(TEXT("[GraphicsDisplay::GraphicsDisplay] Key [%s] does not exit in .ini file.")); 00068 // } 00069 // else 00070 // { 00071 // bool m_BackupFrameBuffer; 00072 // NString value = CIniFile::GetValue(key_name.GetTCharPtr(), section_name.GetTCharPtr(), FileName.GetTCharPtr()); 00073 // if((value == TEXT("1")) || (value == TEXT("true"))) 00074 // { 00075 // m_BackupFrameBuffer = true; 00076 // } 00077 // else 00078 // { 00079 // m_BackupFrameBuffer = false; 00080 // } 00081 // } 00082 // 00083 // section_name = TEXT("SearchPath"); 00084 // key_name = TEXT("FontPath"); 00085 // if(CIniFile::RecordExists(key_name.GetTCharPtr(), section_name.GetTCharPtr(), FileName.GetTCharPtr())) 00086 // { 00087 // NString FontPath = CIniFile::GetValue(key_name.GetTCharPtr(), section_name.GetTCharPtr(), FileName.GetTCharPtr()); 00088 // FontPath.ParseToArray(m_FontSearchPath, TEXT(";")); 00089 // } 00090 // else 00091 // { 00092 // nuxCriticalMsg(TEXT("[GraphicsDisplay::GraphicsDisplay] Failed to read font search path from .ini file.")); 00093 // // return; 00094 // 00095 // } 00096 // 00097 // key_name = TEXT("UITexturePath"); 00098 // if(CIniFile::RecordExists(key_name.GetTCharPtr(), section_name.GetTCharPtr(), FileName.GetTCharPtr())) 00099 // { 00100 // NString UITexturePath = CIniFile::GetValue(key_name.GetTCharPtr(), section_name.GetTCharPtr(), FileName.GetTCharPtr()); 00101 // UITexturePath.ParseToArray(m_UITextureSearchPath, TEXT(";")); 00102 // } 00103 // else 00104 // { 00105 // nuxCriticalMsg(TEXT("[GraphicsDisplay::GraphicsDisplay] Failed to read texture search path from .ini file.")); 00106 // // return; 00107 // } 00108 // 00109 // key_name = TEXT("ShaderPath"); 00110 // if(CIniFile::RecordExists(key_name.GetTCharPtr(), section_name.GetTCharPtr(), FileName.GetTCharPtr())) 00111 // { 00112 // NString ShaderPath = CIniFile::GetValue(key_name.GetTCharPtr(), section_name.GetTCharPtr(), FileName.GetTCharPtr()); 00113 // ShaderPath.ParseToArray(m_ShaderSearchPath, TEXT(";")); 00114 // } 00115 // else 00116 // { 00117 // nuxCriticalMsg(TEXT("[GraphicsDisplay::GraphicsDisplay] Failed to read shader search path from .ini file.")); 00118 // // return; 00119 // } 00120 // } 00121 00122 #ifdef NUX_OS_LINUX 00123 m_ResourcePathLocation.AddSearchPath (TEXT (PKGDATADIR) ); 00124 m_ResourcePathLocation.AddSearchPath (TEXT (PKGDATADIR"/Fonts") ); 00125 m_ResourcePathLocation.AddSearchPath (TEXT (PKGDATADIR"/Meshes") ); 00126 m_ResourcePathLocation.AddSearchPath (TEXT (PKGDATADIR"/UITextures") ); 00127 00128 #ifdef NUX_DEBUG 00129 /* For examples */ 00130 m_ResourcePathLocation.AddSearchPath (TEXT ("../data") ); 00131 m_ResourcePathLocation.AddSearchPath (TEXT ("../data/Fonts") ); 00132 m_ResourcePathLocation.AddSearchPath (TEXT ("../data/Meshes") ); 00133 m_ResourcePathLocation.AddSearchPath (TEXT ("../data/UITextures") ); 00134 #endif 00135 00136 #else 00137 m_ResourcePathLocation.AddSearchPath (TEXT ("") ); 00138 m_ResourcePathLocation.AddSearchPath (TEXT ("./") ); 00139 m_ResourcePathLocation.AddSearchPath (TEXT ("../") ); 00140 m_ResourcePathLocation.AddSearchPath (TEXT ("../../") ); 00141 m_ResourcePathLocation.AddSearchPath (TEXT ("./Data") ); 00142 m_ResourcePathLocation.AddSearchPath (TEXT ("../Data") ); 00143 m_ResourcePathLocation.AddSearchPath (TEXT ("../../Data") ); 00144 m_ResourcePathLocation.AddSearchPath (TEXT ("../../../Data") ); 00145 m_ResourcePathLocation.AddSearchPath (TEXT ("./Data/Fonts") ); 00146 m_ResourcePathLocation.AddSearchPath (TEXT ("../Data/Fonts") ); 00147 m_ResourcePathLocation.AddSearchPath (TEXT ("../../Data/Fonts") ); 00148 m_ResourcePathLocation.AddSearchPath (TEXT ("../../../Data/Fonts") ); 00149 m_ResourcePathLocation.AddSearchPath (TEXT ("./Data/UITextures") ); 00150 m_ResourcePathLocation.AddSearchPath (TEXT ("../Data/UITextures") ); 00151 m_ResourcePathLocation.AddSearchPath (TEXT ("../../Data/UITextures") ); 00152 m_ResourcePathLocation.AddSearchPath (TEXT ("../../../Data/UITextures") ); 00153 #endif 00154 00155 m_ResourcePathLocation.AddSearchPath (m_FontSearchPath); 00156 m_ResourcePathLocation.AddSearchPath (m_ShaderSearchPath); 00157 m_ResourcePathLocation.AddSearchPath (m_UITextureSearchPath); 00158 } 00159 00160 #ifdef NUX_OS_WINDOWS 00161 NString NuxGraphicsResources::FindResourceLocation (const TCHAR *ResourceFileName, bool ErrorOnFail) 00162 { 00163 NString path = m_ResourcePathLocation.GetFile (ResourceFileName); 00164 00165 if (path == TEXT ("") && ErrorOnFail) 00166 { 00167 nuxCriticalMsg (TEXT ("[NuxGraphicsResources::FindResourceLocation] Failed to locate resource file: %s."), ResourceFileName); 00168 return NString (TEXT("")); 00169 } 00170 00171 return path; 00172 } 00173 00174 NString NuxGraphicsResources::FindUITextureLocation (const TCHAR *ResourceFileName, bool ErrorOnFail) 00175 { 00176 FilePath searchpath; 00177 searchpath.AddSearchPath (m_UITextureSearchPath); 00178 NString path = searchpath.GetFile (ResourceFileName); 00179 00180 if ( (path == TEXT ("") ) && ErrorOnFail) 00181 { 00182 nuxCriticalMsg (TEXT ("[NuxGraphicsResources::FindResourceLocation] Failed to locate ui texture file: %s."), ResourceFileName); 00183 return NString (TEXT("")); 00184 } 00185 00186 return path; 00187 } 00188 00189 NString NuxGraphicsResources::FindShaderLocation (const TCHAR *ResourceFileName, bool ErrorOnFail) 00190 { 00191 FilePath searchpath; 00192 searchpath.AddSearchPath (m_ShaderSearchPath); 00193 NString path = searchpath.GetFile (ResourceFileName); 00194 00195 if ( (path == TEXT ("") ) && ErrorOnFail) 00196 { 00197 nuxCriticalMsg (TEXT ("[NuxGraphicsResources::FindResourceLocation] Failed to locate shader file: %s."), ResourceFileName); 00198 return NString (TEXT("")); 00199 } 00200 00201 return path; 00202 } 00203 00204 NString NuxGraphicsResources::FindFontLocation (const TCHAR *ResourceFileName, bool ErrorOnFail) 00205 { 00206 FilePath searchpath; 00207 searchpath.AddSearchPath (m_FontSearchPath); 00208 NString path = searchpath.GetFile (ResourceFileName); 00209 00210 if ( (path == TEXT ("") ) && ErrorOnFail) 00211 { 00212 nuxCriticalMsg (TEXT ("[NuxGraphicsResources::FindResourceLocation] Failed to locate font file file: %s."), ResourceFileName); 00213 return NString (TEXT("")); 00214 } 00215 00216 return path; 00217 } 00218 #elif defined(NUX_OS_LINUX) 00219 NString NuxGraphicsResources::FindResourceLocation (const TCHAR *ResourceFileName, bool ErrorOnFail) 00220 { 00221 NString path = m_ResourcePathLocation.GetFile (ResourceFileName); 00222 00223 if (path == TEXT ("") && ErrorOnFail) 00224 { 00225 nuxCriticalMsg (TEXT ("[NuxGraphicsResources::FindResourceLocation] Failed to locate resource file: %s."), ResourceFileName); 00226 return NString (TEXT("")); 00227 } 00228 00229 return path; 00230 } 00231 00232 NString NuxGraphicsResources::FindUITextureLocation (const TCHAR *ResourceFileName, bool ErrorOnFail) 00233 { 00234 FilePath searchpath; 00235 searchpath.AddSearchPath (m_UITextureSearchPath); 00236 NString path = searchpath.GetFile (ResourceFileName); 00237 00238 if ( (path == TEXT ("") ) && ErrorOnFail) 00239 { 00240 nuxCriticalMsg (TEXT ("[NuxGraphicsResources::FindResourceLocation] Failed to locate ui texture file: %s."), ResourceFileName); 00241 return NString (TEXT("")); 00242 } 00243 00244 return path; 00245 } 00246 00247 NString NuxGraphicsResources::FindShaderLocation (const TCHAR *ResourceFileName, bool ErrorOnFail) 00248 { 00249 FilePath searchpath; 00250 searchpath.AddSearchPath (m_ShaderSearchPath); 00251 NString path = searchpath.GetFile (ResourceFileName); 00252 00253 if ( (path == TEXT ("") ) && ErrorOnFail) 00254 { 00255 nuxCriticalMsg (TEXT ("[NuxGraphicsResources::FindResourceLocation] Failed to locate shader file: %s."), ResourceFileName); 00256 return NString (TEXT("")); 00257 } 00258 00259 return path; 00260 } 00261 00262 NString NuxGraphicsResources::FindFontLocation (const TCHAR *ResourceFileName, bool ErrorOnFail) 00263 { 00264 FilePath searchpath; 00265 searchpath.AddSearchPath (m_FontSearchPath); 00266 NString path = searchpath.GetFile (ResourceFileName); 00267 00268 if ( (path == TEXT ("") ) && ErrorOnFail) 00269 { 00270 nuxCriticalMsg (TEXT ("[NuxGraphicsResources::FindResourceLocation] Failed to locate font file file: %s."), ResourceFileName); 00271 return NString (TEXT("")); 00272 } 00273 00274 return path; 00275 } 00276 #endif 00277 00278 }