00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "std3d.h"
00028
00029 #include <string>
00030
00031 #include "nel/misc/types_nl.h"
00032 #include "3d/driver.h"
00033 #include "3d/shader.h"
00034 #include "3d/vertex_buffer.h"
00035
00036
00037
00038 using namespace NLMISC;
00039 using namespace std;
00040
00041
00042 namespace NL3D
00043 {
00044
00045
00046 const uint32 IDriver::InterfaceVersion = 0x46;
00047
00048
00049 IDriver::IDriver() : _SyncTexDrvInfos( "IDriver::_SyncTexDrvInfos" )
00050 {
00051 _PolygonMode= Filled;
00052 }
00053
00054
00055 IDriver::~IDriver()
00056 {
00057
00058
00059 {
00060 CSynchronized<TTexDrvInfoPtrMap>::CAccessor access(&_SyncTexDrvInfos);
00061 TTexDrvInfoPtrMap &rTexDrvInfos = access.value();
00062 nlassert( rTexDrvInfos.size() == 0 );
00063 }
00064
00065 nlassert(_TexDrvShares.size()==0);
00066 nlassert(_Shaders.size()==0);
00067 nlassert(_VBDrvInfos.size()==0);
00068 nlassert(_VtxPrgDrvInfos.size()==0);
00069 }
00070
00071
00072
00073 bool IDriver::release(void)
00074 {
00075
00076
00077
00078
00079
00080 ItTexDrvSharePtrList ittex;
00081 while( (ittex = _TexDrvShares.begin()) !=_TexDrvShares.end() )
00082 {
00083
00084 delete *ittex;
00085 }
00086
00087
00088
00089 {
00090 CSynchronized<TTexDrvInfoPtrMap>::CAccessor access(&_SyncTexDrvInfos);
00091 TTexDrvInfoPtrMap &rTexDrvInfos = access.value();
00092
00093
00094 nlassert(rTexDrvInfos.empty());
00095 }
00096
00097
00098 ItShaderPtrList itshd;
00099 while( (itshd = _Shaders.begin()) != _Shaders.end() )
00100 {
00101
00102 delete *itshd;
00103 }
00104
00105
00106 ItVBDrvInfoPtrList itvb;
00107 while( (itvb = _VBDrvInfos.begin()) != _VBDrvInfos.end() )
00108 {
00109
00110 delete *itvb;
00111 }
00112
00113
00114 ItVtxPrgDrvInfoPtrList itVtxPrg;
00115 while( (itVtxPrg = _VtxPrgDrvInfos.begin()) != _VtxPrgDrvInfos.end() )
00116 {
00117
00118 delete *itVtxPrg;
00119 }
00120
00121 return true;
00122 }
00123
00124
00125
00126 GfxMode::GfxMode(uint16 w, uint16 h, uint8 d, bool windowed, bool offscreen)
00127 {
00128 Windowed= windowed;
00129 Width= w;
00130 Height= h;
00131 Depth= d;
00132 OffScreen= offscreen;
00133 }
00134
00135
00136 IDriver::TMessageBoxId IDriver::systemMessageBox (const char* message, const char* title, IDriver::TMessageBoxType type, IDriver::TMessageBoxIcon icon)
00137 {
00138 static const char* icons[iconCount]=
00139 {
00140 "",
00141 "WAIT:\n",
00142 "QUESTION:\n",
00143 "HEY!\n",
00144 "",
00145 "WARNING!\n",
00146 "ERROR!\n",
00147 "INFORMATION:\n",
00148 "STOP:\n"
00149 };
00150 static const char* messages[typeCount]=
00151 {
00152 "Press any key...",
00153 "(O)k or (C)ancel ?",
00154 "(Y)es or (N)o ?",
00155 "(A)bort (R)etry (I)gnore ?",
00156 "(Y)es (N)o (C)ancel ?",
00157 "(R)etry (C)ancel ?"
00158 };
00159 printf ("%s%s\n%s", icons[icon], title, message);
00160 while (1)
00161 {
00162 printf ("\n%s", messages[type]);
00163 int c=getchar();
00164 if (type==okType)
00165 return okId;
00166 switch (c)
00167 {
00168 case 'O':
00169 case 'o':
00170 if ((type==okType)||(type==okCancelType))
00171 return okId;
00172 break;
00173 case 'C':
00174 case 'c':
00175 if ((type==yesNoCancelType)||(type==okCancelType)||(type==retryCancelType))
00176 return cancelId;
00177 break;
00178 case 'Y':
00179 case 'y':
00180 if ((type==yesNoCancelType)||(type==yesNoType))
00181 return yesId;
00182 break;
00183 case 'N':
00184 case 'n':
00185 if ((type==yesNoCancelType)||(type==yesNoType))
00186 return noId;
00187 break;
00188 case 'A':
00189 case 'a':
00190 if (type==abortRetryIgnoreType)
00191 return abortId;
00192 break;
00193 case 'R':
00194 case 'r':
00195 if (type==abortRetryIgnoreType)
00196 return retryId;
00197 break;
00198 case 'I':
00199 case 'i':
00200 if (type==abortRetryIgnoreType)
00201 return ignoreId;
00202 break;
00203 }
00204 }
00205 nlassert (0);
00206 return okId;
00207 }
00208
00209
00210
00211
00212
00213 void IDriver::removeVBDrvInfoPtr(ItVBDrvInfoPtrList vbDrvInfoIt)
00214 {
00215 _VBDrvInfos.erase(vbDrvInfoIt);
00216 }
00217
00218 void IDriver::removeTextureDrvInfoPtr(ItTexDrvInfoPtrMap texDrvInfoIt)
00219 {
00220 CSynchronized<TTexDrvInfoPtrMap>::CAccessor access(&_SyncTexDrvInfos);
00221 TTexDrvInfoPtrMap &rTexDrvInfos = access.value();
00222
00223 rTexDrvInfos.erase(texDrvInfoIt);
00224 }
00225
00226 void IDriver::removeTextureDrvSharePtr(ItTexDrvSharePtrList texDrvShareIt)
00227 {
00228 _TexDrvShares.erase(texDrvShareIt);
00229 }
00230
00231 void IDriver::removeShaderPtr(ItShaderPtrList shaderIt)
00232 {
00233 _Shaders.erase(shaderIt);
00234 }
00235
00236 void IDriver::removeVtxPrgDrvInfoPtr(ItVtxPrgDrvInfoPtrList vtxPrgDrvInfoIt)
00237 {
00238 _VtxPrgDrvInfos.erase(vtxPrgDrvInfoIt);
00239 }
00240
00241
00242 bool IDriver::invalidateShareTexture (ITexture &texture)
00243 {
00244
00245 std::string name;
00246 getTextureShareName (texture, name);
00247
00248
00249 CSynchronized<TTexDrvInfoPtrMap>::CAccessor access(&_SyncTexDrvInfos);
00250 TTexDrvInfoPtrMap &rTexDrvInfos = access.value();
00251 TTexDrvInfoPtrMap::iterator iteDrvInfo = rTexDrvInfos.find (name);
00252 if (iteDrvInfo != rTexDrvInfos.end())
00253 {
00254
00255 TTexDrvSharePtrList::iterator shareIte = _TexDrvShares.begin ();
00256 while (shareIte != _TexDrvShares.end ())
00257 {
00258
00259 if ((*shareIte)->DrvTexture == iteDrvInfo->second)
00260 {
00261
00262 TTexDrvSharePtrList::iterator toRemove = shareIte;
00263 shareIte++;
00264 delete (*toRemove);
00265 }
00266 else
00267 shareIte++;
00268 }
00269
00270
00271 return true;
00272 }
00273 return false;
00274 }
00275
00276 void IDriver::getTextureShareName (const ITexture& tex, string &output)
00277 {
00278
00279 output= tex.getShareName();
00280
00281
00282 static char fmt[256];
00283 smprintf(fmt, 256, "@Fmt:%d", (uint32)tex.getUploadFormat());
00284 output+= fmt;
00285
00286
00287 if(tex.mipMapOn())
00288 output+= "@MMp:On";
00289 else
00290 output+= "@MMp:Off";
00291 }
00292 }