00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "std3d.h"
00027
00028
00029
00030
00031
00032
00033 #include "3d/driver_user.h"
00034 #include "nel/3d/u_driver.h"
00035 #include "3d/dru.h"
00036 #include "3d/scene.h"
00037 #include "3d/text_context_user.h"
00038 #include "3d/texture_user.h"
00039 #include "3d/material_user.h"
00040 #include "3d/scene_user.h"
00041 #include "3d/init_3d.h"
00042 #include "nel/3d/u_camera.h"
00043 #include "nel/misc/hierarchical_timer.h"
00044
00045
00046 using namespace NLMISC;
00047
00048 namespace NL3D
00049 {
00050
00051 H_AUTO_DECL( NL3D_UI_Driver )
00052 H_AUTO_DECL( NL3D_Render_DriverClearBuffer )
00053 H_AUTO_DECL( NL3D_Render_DriverSwapBuffer )
00054 H_AUTO_DECL( NL3D_Render_DriverDrawELT )
00055
00056 #define NL3D_HAUTO_UI_DRIVER H_AUTO_USE( NL3D_UI_Driver )
00057 #define NL3D_HAUTO_CLEAR_DRIVER H_AUTO_USE( NL3D_Render_DriverClearBuffer )
00058 #define NL3D_HAUTO_SWAP_DRIVER H_AUTO_USE( NL3D_Render_DriverSwapBuffer )
00059 #define NL3D_HAUTO_DRAW_DRIVER H_AUTO_USE( NL3D_Render_DriverDrawELT )
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 UDriver::UDriver()
00070 {
00071 NL3D_MEM_DRIVER
00072 }
00073
00074 UDriver::~UDriver()
00075 {
00076 NL3D_MEM_DRIVER
00077 }
00078
00079
00080
00081 void UDriver::setMatrixMode2D11()
00082 {
00083 NL3D_MEM_DRIVER
00084 setMatrixMode2D(CFrustum(0.0f,1.0f,0.0f,1.0f,-1.0f,1.0f,false));
00085 }
00086
00087 void UDriver::setMatrixMode2D43()
00088 {
00089 NL3D_MEM_DRIVER
00090 setMatrixMode2D(CFrustum(0.0f,4.0f/3.0f,0.0f,1.0f,-1.0f,1.0f,false));
00091 }
00092
00093
00094
00095 UDriver *UDriver::createDriver()
00096 {
00097 NL3D_MEM_DRIVER
00098 return new CDriverUser;
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 bool CDriverUser::_StaticInit= false;
00111
00112
00113
00114 CDriverUser::CDriverUser()
00115 {
00116 NL3D_MEM_DRIVER
00117
00118
00119 nlassert((uint)IDriver::idCount == (uint)UDriver::idCount);
00120 nlassert((uint)IDriver::typeCount == (uint)UDriver::typeCount);
00121 nlassert((uint)IDriver::iconCount == (uint)UDriver::iconCount);
00122
00123
00124
00125 if(!_StaticInit)
00126 {
00127 _StaticInit= true;
00128
00129 NL3D::registerSerial3d();
00130
00131
00132 CScene::registerBasics();
00133 }
00134
00135
00136 _Driver= CDRU::createGlDriver();
00137 nlassert(_Driver);
00138 _Driver->init();
00139
00140 _WindowInit= false;
00141
00142
00143 _VBFlat.setVertexFormat(CVertexBuffer::PositionFlag);
00144 _VBColor.setVertexFormat(CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag);
00145 _VBUv.setVertexFormat(CVertexBuffer::PositionFlag | CVertexBuffer::TexCoord0Flag);
00146 _VBColorUv.setVertexFormat(CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag | CVertexBuffer::TexCoord0Flag);
00147 _VBQuadsColUv.setVertexFormat(CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag | CVertexBuffer::TexCoord0Flag);
00148
00149 _VBFlat.setNumVertices(4);
00150 _VBColor.setNumVertices(4);
00151 _VBUv.setNumVertices(4);
00152 _VBColorUv.setNumVertices(4);
00153
00154 _PBLine.setNumLine(1);
00155 _PBLine.setLine(0, 0, 1);
00156 _PBTri.setNumTri(1);
00157 _PBTri.setTri(0, 0, 1, 2);
00158 _PBQuad.setNumQuad(1);
00159 _PBQuad.setQuad(0, 0, 1, 2, 3);
00160
00161 }
00162
00163 CDriverUser::~CDriverUser()
00164 {
00165 NL3D_MEM_DRIVER
00166 release();
00167
00168 delete _Driver;
00169 _Driver= NULL;
00170 }
00171
00172
00173 UDriver::TModeList CDriverUser::enumModes()
00174 {
00175 NL3D_HAUTO_UI_DRIVER;
00176 NL3D_MEM_DRIVER
00177
00178 ModeList dlist;
00179 TModeList retlist;
00180
00181 dlist= _Driver->enumModes();
00182 for(sint i=0;i<(sint)dlist.size();i++)
00183 {
00184 retlist.push_back(CMode(dlist[i].Width, dlist[i].Height, dlist[i].Depth, dlist[i].Windowed));
00185 }
00186
00187 return retlist;
00188 }
00189
00190
00191 void CDriverUser::disableHardwareVertexProgram()
00192 {
00193 NL3D_MEM_DRIVER
00194 NL3D_HAUTO_UI_DRIVER;
00195
00196 _Driver->disableHardwareVertexProgram();
00197 }
00198 void CDriverUser::disableHardwareVertexArrayAGP()
00199 {
00200 NL3D_MEM_DRIVER
00201 NL3D_HAUTO_UI_DRIVER;
00202
00203 _Driver->disableHardwareVertexArrayAGP();
00204 }
00205 void CDriverUser::disableHardwareTextureShader()
00206 {
00207 NL3D_MEM_DRIVER
00208 NL3D_HAUTO_UI_DRIVER;
00209
00210 _Driver->disableHardwareTextureShader();
00211 }
00212
00213
00214 void CDriverUser::setDisplay(const CMode &mode)
00215 {
00216 NL3D_MEM_DRIVER
00217 NL3D_HAUTO_UI_DRIVER;
00218
00219
00220 nlverify(_Driver->setDisplay(NULL, GfxMode(mode.Width, mode.Height, mode.Depth, mode.Windowed)));
00221 nlverify(activate());
00222 _WindowInit= true;
00223
00224
00225 AsyncListener.reset ();
00226 EventServer.addEmitter(_Driver->getEventEmitter());
00227 AsyncListener.addToServer(EventServer);
00228
00229
00230 _CurrentMatrixContext.Viewport.initFullScreen();
00231 _CurrentMatrixContext.Scissor.initFullScreen();
00232 setMatrixMode2D11();
00233
00234
00235 _MatFlat.initUnlit();
00236 _MatFlat.setZFunc(UMaterial::always);
00237 _MatFlat.setZWrite(false);
00238 _MatText.initUnlit();
00239 _MatText.setZFunc(UMaterial::always);
00240 _MatText.setZWrite(false);
00241
00242 }
00243
00244 void CDriverUser::release()
00245 {
00246 NL3D_MEM_DRIVER
00247 NL3D_HAUTO_UI_DRIVER;
00248
00249 if(!_WindowInit)
00250 return;
00251
00252
00253 _MatFlat.initUnlit();
00254 _MatText.initUnlit();
00255
00256
00257 _Textures.clear();
00258 _Materials.clear();
00259 _TextContexts.clear();
00260 _Scenes.clear();
00261
00262
00263 AsyncListener.removeFromServer(EventServer);
00264 EventServer.removeEmitter(_Driver->getEventEmitter());
00265
00266
00267 _Driver->release();
00268 _WindowInit= false;
00269 }
00270
00271
00272
00273 bool CDriverUser::activate(void)
00274 {
00275 NL3D_MEM_DRIVER
00276 NL3D_HAUTO_UI_DRIVER;
00277
00278 return _Driver->activate();
00279 }
00280
00281
00282 bool CDriverUser::isActive()
00283 {
00284 NL3D_MEM_DRIVER
00285 NL3D_HAUTO_UI_DRIVER;
00286
00287 return _Driver->isActive();
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 void CDriverUser::setupMatrixContext()
00301 {
00302 NL3D_MEM_DRIVER
00303
00304 _Driver->setupScissor(_CurrentMatrixContext.Scissor);
00305 _Driver->setupViewport(_CurrentMatrixContext.Viewport);
00306 CFrustum &f= _CurrentMatrixContext.Frustum;
00307 _Driver->setFrustum(f.Left, f.Right, f.Bottom, f.Top, f.Near, f.Far, f.Perspective);
00308 _Driver->setupViewMatrix(_CurrentMatrixContext.ViewMatrix);
00309 _Driver->setupModelMatrix(_CurrentMatrixContext.ModelMatrix);
00310 }
00311
00312 void CDriverUser::setScissor(const CScissor &sc)
00313 {
00314 NL3D_MEM_DRIVER
00315 NL3D_HAUTO_UI_DRIVER;
00316
00317 _CurrentMatrixContext.Scissor= sc;
00318 setupMatrixContext();
00319 }
00320
00321 CScissor CDriverUser::getScissor()
00322 {
00323 NL3D_MEM_DRIVER
00324 NL3D_HAUTO_UI_DRIVER;
00325
00326 return _CurrentMatrixContext.Scissor;
00327 }
00328
00329 void CDriverUser::setViewport(const CViewport &vp)
00330 {
00331 NL3D_MEM_DRIVER
00332 NL3D_HAUTO_UI_DRIVER;
00333
00334 _CurrentMatrixContext.Viewport= vp;
00335 setupMatrixContext();
00336 }
00337
00338 CViewport CDriverUser::getViewport()
00339 {
00340 NL3D_MEM_DRIVER
00341 NL3D_HAUTO_UI_DRIVER;
00342
00343 return _CurrentMatrixContext.Viewport;
00344 }
00345
00346 void CDriverUser::setFrustum(const CFrustum &frust)
00347 {
00348 NL3D_MEM_DRIVER
00349 NL3D_HAUTO_UI_DRIVER;
00350
00351 _CurrentMatrixContext.Frustum= frust;
00352 setupMatrixContext();
00353 }
00354
00355 CFrustum CDriverUser::getFrustum()
00356 {
00357 NL3D_MEM_DRIVER
00358 NL3D_HAUTO_UI_DRIVER;
00359
00360 return _CurrentMatrixContext.Frustum;
00361 }
00362
00363 void CDriverUser::setViewMatrix(const CMatrix &mat)
00364 {
00365 NL3D_MEM_DRIVER
00366 NL3D_HAUTO_UI_DRIVER;
00367
00368 _CurrentMatrixContext.ViewMatrix= mat;
00369 setupMatrixContext();
00370 }
00371
00372 CMatrix CDriverUser::getViewMatrix()
00373 {
00374 NL3D_MEM_DRIVER
00375 NL3D_HAUTO_UI_DRIVER;
00376
00377 return _CurrentMatrixContext.ViewMatrix;
00378 }
00379
00380 void CDriverUser::setModelMatrix(const CMatrix &mat)
00381 {
00382 NL3D_MEM_DRIVER
00383 NL3D_HAUTO_UI_DRIVER;
00384
00385 _CurrentMatrixContext.ModelMatrix= mat;
00386 setupMatrixContext();
00387 }
00388
00389 CMatrix CDriverUser::getModelMatrix()
00390 {
00391 NL3D_MEM_DRIVER
00392 NL3D_HAUTO_UI_DRIVER;
00393
00394 return _CurrentMatrixContext.ModelMatrix;
00395 }
00396
00397
00398
00399
00400 void CDriverUser::setMatrixMode2D(const CFrustum &frust)
00401 {
00402 NL3D_MEM_DRIVER
00403 NL3D_HAUTO_UI_DRIVER;
00404
00405 _CurrentMatrixContext.Frustum= frust;
00406
00407 CVector I(1,0,0);
00408 CVector J(0,0,1);
00409 CVector K(0,-1,0);
00410
00411 _CurrentMatrixContext.ViewMatrix.identity();
00412 _CurrentMatrixContext.ViewMatrix.setRot(I,J,K, true);
00413 _CurrentMatrixContext.ModelMatrix.identity();
00414
00415 setupMatrixContext();
00416 }
00417
00418 void CDriverUser::setMatrixMode3D(UCamera &camera)
00419 {
00420 NL3D_MEM_DRIVER
00421 NL3D_HAUTO_UI_DRIVER;
00422
00423
00424 CMatrix viewMat;
00425 viewMat= camera.getMatrix();
00426 viewMat.invert();
00427 setViewMatrix(viewMat);
00428 setModelMatrix(CMatrix::Identity);
00429 setFrustum(camera.getFrustum());
00430 }
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 void CDriverUser::drawLine(const NLMISC::CLine &shp, UMaterial &mat)
00441 {
00442 NL3D_MEM_DRIVER
00443 NL3D_HAUTO_DRAW_DRIVER;
00444
00445 CVertexBuffer &vb= _VBFlat;
00446 CPrimitiveBlock &pb= _PBLine;
00447
00448 vb.setVertexCoord (0, shp.V0);
00449 vb.setVertexCoord (1, shp.V1);
00450
00451 _Driver->activeVertexBuffer(vb);
00452 _Driver->render(pb, convMat(mat));
00453 }
00454
00455 void CDriverUser::drawLine(const NLMISC::CLineColor &shp, UMaterial &mat)
00456 {
00457 NL3D_MEM_DRIVER
00458 NL3D_HAUTO_DRAW_DRIVER;
00459
00460 CVertexBuffer &vb= _VBColor;
00461 CPrimitiveBlock &pb= _PBLine;
00462
00463 vb.setVertexCoord (0, shp.V0);
00464 vb.setVertexCoord (1, shp.V1);
00465 vb.setColor(0, shp.Color0);
00466 vb.setColor(1, shp.Color1);
00467
00468 _Driver->activeVertexBuffer(vb);
00469 _Driver->render(pb, convMat(mat));
00470 }
00471
00472 void CDriverUser::drawLine(const NLMISC::CLineUV &shp, UMaterial &mat)
00473 {
00474 NL3D_MEM_DRIVER
00475 NL3D_HAUTO_DRAW_DRIVER;
00476
00477 CVertexBuffer &vb= _VBUv;
00478 CPrimitiveBlock &pb= _PBLine;
00479
00480 vb.setVertexCoord (0, shp.V0);
00481 vb.setVertexCoord (1, shp.V1);
00482 vb.setTexCoord (0, 0, shp.Uv0);
00483 vb.setTexCoord (1, 0, shp.Uv1);
00484
00485 _Driver->activeVertexBuffer(vb);
00486 _Driver->render(pb, convMat(mat));
00487 }
00488
00489 void CDriverUser::drawLine(const NLMISC::CLineColorUV &shp, UMaterial &mat)
00490 {
00491 NL3D_MEM_DRIVER
00492 NL3D_HAUTO_DRAW_DRIVER;
00493
00494 CVertexBuffer &vb= _VBColorUv;
00495 CPrimitiveBlock &pb= _PBLine;
00496
00497 vb.setVertexCoord (0, shp.V0);
00498 vb.setVertexCoord (1, shp.V1);
00499 vb.setColor(0, shp.Color0);
00500 vb.setColor(1, shp.Color1);
00501 vb.setTexCoord (0, 0, shp.Uv0);
00502 vb.setTexCoord (1, 0, shp.Uv1);
00503
00504 _Driver->activeVertexBuffer(vb);
00505 _Driver->render(pb, convMat(mat));
00506 }
00507
00508
00509
00510
00511 void CDriverUser::drawTriangle(const NLMISC::CTriangle &shp, UMaterial &mat)
00512 {
00513 NL3D_MEM_DRIVER
00514 NL3D_HAUTO_DRAW_DRIVER;
00515
00516 CVertexBuffer &vb= _VBFlat;
00517 CPrimitiveBlock &pb= _PBTri;
00518
00519 vb.setVertexCoord (0, shp.V0);
00520 vb.setVertexCoord (1, shp.V1);
00521 vb.setVertexCoord (2, shp.V2);
00522
00523 _Driver->activeVertexBuffer(vb);
00524 _Driver->render(pb, convMat(mat));
00525 }
00526
00527 void CDriverUser::drawTriangle(const NLMISC::CTriangleColor &shp, UMaterial &mat)
00528 {
00529 NL3D_MEM_DRIVER
00530 NL3D_HAUTO_DRAW_DRIVER;
00531
00532 CVertexBuffer &vb= _VBColor;
00533 CPrimitiveBlock &pb= _PBTri;
00534
00535 vb.setVertexCoord (0, shp.V0);
00536 vb.setVertexCoord (1, shp.V1);
00537 vb.setVertexCoord (2, shp.V2);
00538 vb.setColor(0, shp.Color0);
00539 vb.setColor(1, shp.Color1);
00540 vb.setColor(2, shp.Color2);
00541
00542 _Driver->activeVertexBuffer(vb);
00543 _Driver->render(pb, convMat(mat));
00544 }
00545
00546 void CDriverUser::drawTriangle(const NLMISC::CTriangleUV &shp, UMaterial &mat)
00547 {
00548 NL3D_MEM_DRIVER
00549 NL3D_HAUTO_DRAW_DRIVER;
00550
00551 CVertexBuffer &vb= _VBUv;
00552 CPrimitiveBlock &pb= _PBTri;
00553
00554 vb.setVertexCoord (0, shp.V0);
00555 vb.setVertexCoord (1, shp.V1);
00556 vb.setVertexCoord (2, shp.V2);
00557 vb.setTexCoord (0, 0, shp.Uv0);
00558 vb.setTexCoord (1, 0, shp.Uv1);
00559 vb.setTexCoord (2, 0, shp.Uv2);
00560
00561 _Driver->activeVertexBuffer(vb);
00562 _Driver->render(pb, convMat(mat));
00563 }
00564
00565 void CDriverUser::drawTriangle(const NLMISC::CTriangleColorUV &shp, UMaterial &mat)
00566 {
00567 NL3D_MEM_DRIVER
00568 NL3D_HAUTO_DRAW_DRIVER;
00569
00570 CVertexBuffer &vb= _VBColorUv;
00571 CPrimitiveBlock &pb= _PBTri;
00572
00573 vb.setVertexCoord (0, shp.V0);
00574 vb.setVertexCoord (1, shp.V1);
00575 vb.setVertexCoord (2, shp.V2);
00576 vb.setColor(0, shp.Color0);
00577 vb.setColor(1, shp.Color1);
00578 vb.setColor(2, shp.Color2);
00579 vb.setTexCoord (0, 0, shp.Uv0);
00580 vb.setTexCoord (1, 0, shp.Uv1);
00581 vb.setTexCoord (2, 0, shp.Uv2);
00582
00583 _Driver->activeVertexBuffer(vb);
00584 _Driver->render(pb, convMat(mat));
00585 }
00586
00587
00588
00589
00590 void CDriverUser::drawQuad(const NLMISC::CQuad &shp, UMaterial &mat)
00591 {
00592 NL3D_MEM_DRIVER
00593 NL3D_HAUTO_DRAW_DRIVER;
00594
00595 CVertexBuffer &vb= _VBFlat;
00596 CPrimitiveBlock &pb= _PBQuad;
00597
00598 vb.setVertexCoord (0, shp.V0);
00599 vb.setVertexCoord (1, shp.V1);
00600 vb.setVertexCoord (2, shp.V2);
00601 vb.setVertexCoord (3, shp.V3);
00602
00603 _Driver->activeVertexBuffer(vb);
00604 _Driver->render(pb, convMat(mat));
00605 }
00606
00607 void CDriverUser::drawQuad(const NLMISC::CQuadColor &shp, UMaterial &mat)
00608 {
00609 NL3D_MEM_DRIVER
00610 NL3D_HAUTO_DRAW_DRIVER;
00611
00612 CVertexBuffer &vb= _VBColor;
00613 CPrimitiveBlock &pb= _PBQuad;
00614
00615 vb.setVertexCoord (0, shp.V0);
00616 vb.setVertexCoord (1, shp.V1);
00617 vb.setVertexCoord (2, shp.V2);
00618 vb.setVertexCoord (3, shp.V3);
00619 vb.setColor(0, shp.Color0);
00620 vb.setColor(1, shp.Color1);
00621 vb.setColor(2, shp.Color2);
00622 vb.setColor(3, shp.Color3);
00623
00624 _Driver->activeVertexBuffer(vb);
00625 _Driver->render(pb, convMat(mat));
00626 }
00627
00628 void CDriverUser::drawQuad(const NLMISC::CQuadUV &shp, UMaterial &mat)
00629 {
00630 NL3D_MEM_DRIVER
00631 NL3D_HAUTO_DRAW_DRIVER;
00632
00633 CVertexBuffer &vb= _VBUv;
00634 CPrimitiveBlock &pb= _PBQuad;
00635
00636 vb.setVertexCoord (0, shp.V0);
00637 vb.setVertexCoord (1, shp.V1);
00638 vb.setVertexCoord (2, shp.V2);
00639 vb.setVertexCoord (3, shp.V3);
00640 vb.setTexCoord (0, 0, shp.Uv0);
00641 vb.setTexCoord (1, 0, shp.Uv1);
00642 vb.setTexCoord (2, 0, shp.Uv2);
00643 vb.setTexCoord (3, 0, shp.Uv3);
00644
00645 _Driver->activeVertexBuffer(vb);
00646 _Driver->render(pb, convMat(mat));
00647 }
00648
00649 void CDriverUser::drawQuad(const NLMISC::CQuadColorUV &shp, UMaterial &mat)
00650 {
00651 NL3D_MEM_DRIVER
00652 NL3D_HAUTO_DRAW_DRIVER;
00653
00654 CVertexBuffer &vb= _VBColorUv;
00655 CPrimitiveBlock &pb= _PBQuad;
00656
00657 vb.setVertexCoord (0, shp.V0);
00658 vb.setVertexCoord (1, shp.V1);
00659 vb.setVertexCoord (2, shp.V2);
00660 vb.setVertexCoord (3, shp.V3);
00661 vb.setColor(0, shp.Color0);
00662 vb.setColor(1, shp.Color1);
00663 vb.setColor(2, shp.Color2);
00664 vb.setColor(3, shp.Color3);
00665 vb.setTexCoord (0, 0, shp.Uv0);
00666 vb.setTexCoord (1, 0, shp.Uv1);
00667 vb.setTexCoord (2, 0, shp.Uv2);
00668 vb.setTexCoord (3, 0, shp.Uv3);
00669
00670 _Driver->activeVertexBuffer(vb);
00671 _Driver->render(pb, convMat(mat));
00672 }
00673
00674 void CDriverUser::drawQuads(const std::vector<NLMISC::CQuadColorUV> &q, UMaterial &mat)
00675 {
00676 NL3D_MEM_DRIVER
00677
00678 const CQuadColorUV *qptr = &(q[0]);
00679 drawQuads(qptr , q.size(), mat);
00680 }
00681
00682
00683 void CDriverUser::drawQuads(const NLMISC::CQuadColorUV *quads, uint32 nbQuads, UMaterial &mat)
00684 {
00685 NL3D_MEM_DRIVER
00686 NL3D_HAUTO_DRAW_DRIVER;
00687
00688 CVertexBuffer &vb = _VBQuadsColUv;
00689
00690 vb.setNumVertices (4*nbQuads);
00691
00692 for (uint32 i = 0; i < nbQuads; ++i)
00693 {
00694 const NLMISC::CQuadColorUV &qcuv = quads[i];
00695 vb.setVertexCoord (i*4+0, qcuv.V0);
00696 vb.setVertexCoord (i*4+1, qcuv.V1);
00697 vb.setVertexCoord (i*4+2, qcuv.V2);
00698 vb.setVertexCoord (i*4+3, qcuv.V3);
00699 vb.setColor(i*4+0, qcuv.Color0);
00700 vb.setColor(i*4+1, qcuv.Color1);
00701 vb.setColor(i*4+2, qcuv.Color2);
00702 vb.setColor(i*4+3, qcuv.Color3);
00703 vb.setTexCoord (i*4+0, 0, qcuv.Uv0);
00704 vb.setTexCoord (i*4+1, 0, qcuv.Uv1);
00705 vb.setTexCoord (i*4+2, 0, qcuv.Uv2);
00706 vb.setTexCoord (i*4+3, 0, qcuv.Uv3);
00707 }
00708
00709 _Driver->activeVertexBuffer(vb);
00710 _Driver->renderQuads(convMat(mat), 0, nbQuads);
00711 }
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722 void CDriverUser::drawBitmap (float x, float y, float width, float height, class UTexture& texture, bool blend, CRGBA col)
00723 {
00724 NL3D_MEM_DRIVER
00725 NL3D_HAUTO_DRAW_DRIVER;
00726
00727 _MatText.setTexture(&texture);
00728 _MatText.setColor(col);
00729 _MatText.setBlend(blend);
00730
00731 CQuadUV quad;
00732 quad.V0.set(x,y,0);
00733 quad.V1.set(x+width,y,0);
00734 quad.V2.set(x+width,y+height,0);
00735 quad.V3.set(x,y+height,0);
00736 quad.Uv0.U= 0.f;
00737 quad.Uv0.V= 1.f;
00738 quad.Uv1.U= 1.f;
00739 quad.Uv1.V= 1.f;
00740 quad.Uv2.U= 1.f;
00741 quad.Uv2.V= 0.f;
00742 quad.Uv3.U= 0.f;
00743 quad.Uv3.V= 0.f;
00744
00745 drawQuad(quad, _MatText);
00746 }
00747
00748 void CDriverUser::drawLine (float x0, float y0, float x1, float y1, CRGBA col)
00749 {
00750 NL3D_MEM_DRIVER
00751 NL3D_HAUTO_DRAW_DRIVER;
00752
00753 _MatFlat.setColor(col);
00754 _MatFlat.setBlend(true);
00755
00756 CLine line;
00757 line.V0.set(x0,y0,0);
00758 line.V1.set(x1,y1,0);
00759
00760 drawLine(line, _MatFlat);
00761 }
00762
00763 void CDriverUser::drawTriangle (float x0, float y0, float x1, float y1, float x2, float y2, CRGBA col)
00764 {
00765 NL3D_MEM_DRIVER
00766 NL3D_HAUTO_DRAW_DRIVER;
00767
00768 _MatFlat.setColor(col);
00769 _MatFlat.setBlend(true);
00770
00771 CTriangle tri;
00772 tri.V0.set(x0,y0,0);
00773 tri.V1.set(x1,y1,0);
00774 tri.V2.set(x2,y2,0);
00775
00776 drawTriangle(tri, _MatFlat);
00777 }
00778
00779 void CDriverUser::drawQuad (float x0, float y0, float x1, float y1, CRGBA col)
00780 {
00781 NL3D_MEM_DRIVER
00782 NL3D_HAUTO_DRAW_DRIVER;
00783
00784 _MatFlat.setColor(col);
00785 _MatFlat.setBlend(true);
00786
00787 CQuad quad;
00788 quad.V0.set(x0,y0,0);
00789 quad.V1.set(x1,y0,0);
00790 quad.V2.set(x1,y1,0);
00791 quad.V3.set(x0,y1,0);
00792
00793 drawQuad(quad, _MatFlat);
00794 }
00795
00796 void CDriverUser::drawQuad (float xcenter, float ycenter, float radius, CRGBA col)
00797 {
00798 NL3D_MEM_DRIVER
00799
00800 drawQuad(xcenter-radius, ycenter-radius, xcenter+radius, ycenter+radius, col);
00801 }
00802
00803 void CDriverUser::drawWiredQuad (float x0, float y0, float x1, float y1, CRGBA col)
00804 {
00805 NL3D_MEM_DRIVER
00806
00807
00808 drawLine(x0,y0,x0,y1,col);
00809
00810 drawLine(x1,y0,x1,y1,col);
00811
00812 drawLine(x0,y1,x1,y1,col);
00813
00814 drawLine(x0,y0,x1,y0,col);
00815 }
00816
00817 void CDriverUser::drawWiredQuad (float xcenter, float ycenter, float radius, CRGBA col)
00818 {
00819 NL3D_MEM_DRIVER
00820
00821 drawWiredQuad(xcenter-radius, ycenter-radius, xcenter+radius, ycenter+radius, col);
00822 }
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833 UDriver::TMessageBoxId CDriverUser::systemMessageBox (const char* message, const char* title, TMessageBoxType type, TMessageBoxIcon icon)
00834 {
00835 NL3D_MEM_DRIVER
00836
00837 IDriver::TMessageBoxId dret;
00838 IDriver::TMessageBoxType dtype= (IDriver::TMessageBoxType)(uint32)type;
00839 IDriver::TMessageBoxIcon dicon= (IDriver::TMessageBoxIcon)(uint32)icon;
00840 dret= _Driver->systemMessageBox (message, title, dtype, dicon);
00841
00842 return (UDriver::TMessageBoxId)(uint32)dret;
00843 }
00844
00845
00846
00847 CMaterial &CDriverUser::convMat(UMaterial &mat)
00848 {
00849 NL3D_MEM_DRIVER
00850
00851 CMaterialUser *pmat= (CMaterialUser*)&mat;
00852 return pmat->_Material;
00853 }
00854
00855
00856
00857 void CDriverUser::clearRGBABuffer(CRGBA col)
00858 {
00859 NL3D_MEM_DRIVER
00860 NL3D_HAUTO_CLEAR_DRIVER;
00861
00862 _Driver->clear2D(col);
00863 }
00864
00865 void CDriverUser::clearZBuffer()
00866 {
00867 NL3D_MEM_DRIVER
00868 NL3D_HAUTO_CLEAR_DRIVER;
00869
00870 _Driver->clearZBuffer();
00871 }
00872
00873 void CDriverUser::clearBuffers(CRGBA col)
00874 {
00875 NL3D_MEM_DRIVER
00876 NL3D_HAUTO_CLEAR_DRIVER;
00877
00878 _Driver->clear2D(col);
00879 _Driver->clearZBuffer();
00880 }
00881
00882 void CDriverUser::swapBuffers()
00883 {
00884 NL3D_MEM_DRIVER
00885 NL3D_HAUTO_SWAP_DRIVER;
00886
00887 _Driver->swapBuffers();
00888 }
00889
00890
00891
00892 bool CDriverUser::fogEnabled()
00893 {
00894 NL3D_MEM_DRIVER
00895 NL3D_HAUTO_UI_DRIVER;
00896
00897 return _Driver->fogEnabled();
00898 }
00899
00900 void CDriverUser::enableFog(bool enable)
00901 {
00902 NL3D_MEM_DRIVER
00903 NL3D_HAUTO_UI_DRIVER;
00904
00905 _Driver->enableFog(enable);
00906 }
00907
00908 void CDriverUser::setupFog(float start, float end, CRGBA color)
00909 {
00910 NL3D_MEM_DRIVER
00911 NL3D_HAUTO_UI_DRIVER;
00912
00913 _Driver->setupFog(start, end, color);
00914 }
00915
00916
00917
00918 void CDriverUser::setLight (uint8 num, const ULight& light)
00919 {
00920 NL3D_MEM_DRIVER
00921 NL3D_HAUTO_UI_DRIVER;
00922
00923 CLightUser *plight= (CLightUser*)&light;
00924 _Driver->setLight (num, plight->_Light);
00925 }
00926
00927 void CDriverUser::enableLight (uint8 num, bool enable)
00928 {
00929 NL3D_MEM_DRIVER
00930 NL3D_HAUTO_UI_DRIVER;
00931
00932 _Driver->enableLight (num, enable);
00933 }
00934
00935 void CDriverUser::setAmbientColor (CRGBA color)
00936 {
00937 NL3D_MEM_DRIVER
00938 NL3D_HAUTO_UI_DRIVER;
00939
00940 _Driver->setAmbientColor (color);
00941 }
00942
00943
00944
00945 void CDriverUser::setPolygonMode (TPolygonMode mode)
00946 {
00947 NL3D_MEM_DRIVER
00948 NL3D_HAUTO_UI_DRIVER;
00949
00950 IDriver::TPolygonMode dmode=IDriver::Filled;
00951 switch(mode)
00952 {
00953 case Filled: dmode= IDriver::Filled; break;
00954 case Line: dmode= IDriver::Line; break;
00955 case Point: dmode= IDriver::Point; break;
00956 default: nlstop;
00957 };
00958 _Driver->setPolygonMode (dmode);
00959 }
00960 U3dMouseListener* CDriverUser::create3dMouseListener ()
00961 {
00962 NL3D_MEM_DRIVER
00963 NL3D_HAUTO_UI_DRIVER;
00964
00965
00966 CEvent3dMouseListener *listener=new CEvent3dMouseListener();
00967
00968
00969 listener->addToServer (EventServer);
00970
00971 return listener;
00972 }
00973 void CDriverUser::delete3dMouseListener (U3dMouseListener *listener)
00974 {
00975 NL3D_MEM_DRIVER
00976 NL3D_HAUTO_UI_DRIVER;
00977
00978
00979 ((CEvent3dMouseListener*)listener)->removeFromServer (EventServer);
00980
00981 delete (CEvent3dMouseListener*)listener;
00982 }
00983 UDriver::TPolygonMode CDriverUser::getPolygonMode ()
00984 {
00985 NL3D_MEM_DRIVER
00986 NL3D_HAUTO_UI_DRIVER;
00987
00988 IDriver::TPolygonMode dmode;
00989 UDriver::TPolygonMode umode=UDriver::Filled;
00990 dmode= _Driver->getPolygonMode();
00991 switch(dmode)
00992 {
00993 case IDriver::Filled: umode= UDriver::Filled; break;
00994 case IDriver::Line: umode= UDriver::Line; break;
00995 case IDriver::Point: umode= UDriver::Point; break;
00996 default: nlstop;
00997 };
00998
00999 return umode;
01000 }
01001 void CDriverUser::forceDXTCCompression(bool dxtcComp)
01002 {
01003 NL3D_MEM_DRIVER
01004 NL3D_HAUTO_UI_DRIVER;
01005
01006 _Driver->forceDXTCCompression(dxtcComp);
01007 }
01008 void CDriverUser::forceTextureResize(uint divisor)
01009 {
01010 NL3D_MEM_DRIVER
01011 NL3D_HAUTO_UI_DRIVER;
01012
01013 _Driver->forceTextureResize(divisor);
01014 }
01015 bool CDriverUser::setMonitorColorProperties (const CMonitorColorProperties &properties)
01016 {
01017 NL3D_MEM_DRIVER
01018 NL3D_HAUTO_UI_DRIVER;
01019
01020 return _Driver->setMonitorColorProperties (properties);
01021 }
01022
01023
01024
01025
01026
01028
01029
01030
01031 uint32 CDriverUser::getImplementationVersion () const
01032 {
01033 NL3D_MEM_DRIVER
01034 NL3D_HAUTO_UI_DRIVER;
01035
01036 return _Driver->getImplementationVersion ();
01037 }
01038 const char* CDriverUser::getDriverInformation ()
01039 {
01040 NL3D_MEM_DRIVER
01041 NL3D_HAUTO_UI_DRIVER;
01042
01043 return _Driver->getDriverInformation();
01044 }
01045 const char* CDriverUser::getVideocardInformation ()
01046 {
01047 NL3D_MEM_DRIVER
01048 NL3D_HAUTO_UI_DRIVER;
01049
01050 return _Driver->getVideocardInformation ();
01051 }
01052 sint CDriverUser::getNbTextureStages()
01053 {
01054 NL3D_MEM_DRIVER
01055 NL3D_HAUTO_UI_DRIVER;
01056
01057 return _Driver->getNbTextureStages();
01058 }
01059 void CDriverUser::getWindowSize (uint32 &width, uint32 &height)
01060 {
01061 NL3D_MEM_DRIVER
01062 NL3D_HAUTO_UI_DRIVER;
01063
01064 _Driver->getWindowSize (width, height);
01065 }
01066 uint CDriverUser::getWindowWidth ()
01067 {
01068 NL3D_MEM_DRIVER
01069 NL3D_HAUTO_UI_DRIVER;
01070
01071 uint32 width, height;
01072 _Driver->getWindowSize (width, height);
01073 return width;
01074 }
01075 uint CDriverUser::getWindowHeight ()
01076 {
01077 NL3D_MEM_DRIVER
01078 NL3D_HAUTO_UI_DRIVER;
01079
01080 uint32 width, height;
01081 _Driver->getWindowSize (width, height);
01082 return height;
01083 }
01084 void CDriverUser::getBuffer (CBitmap &bitmap)
01085 {
01086 NL3D_MEM_DRIVER
01087 NL3D_HAUTO_UI_DRIVER;
01088
01089 _Driver->getBuffer (bitmap) ;
01090 }
01091 void CDriverUser::getZBuffer (std::vector<float> &zbuffer)
01092 {
01093 NL3D_MEM_DRIVER
01094 NL3D_HAUTO_UI_DRIVER;
01095
01096 _Driver->getZBuffer (zbuffer) ;
01097 }
01098 void CDriverUser::getBufferPart (CBitmap &bitmap, NLMISC::CRect &rect)
01099 {
01100 NL3D_MEM_DRIVER
01101 NL3D_HAUTO_UI_DRIVER;
01102
01103 _Driver->getBufferPart (bitmap, rect) ;
01104 }
01105 void CDriverUser::getZBufferPart (std::vector<float> &zbuffer, NLMISC::CRect &rect)
01106 {
01107 NL3D_MEM_DRIVER
01108 NL3D_HAUTO_UI_DRIVER;
01109
01110 _Driver->getZBufferPart (zbuffer, rect) ;
01111 }
01112 bool CDriverUser::fillBuffer (CBitmap &bitmap)
01113 {
01114 NL3D_MEM_DRIVER
01115 NL3D_HAUTO_UI_DRIVER;
01116
01117 return _Driver->fillBuffer(bitmap);
01118 }
01119
01120
01121
01122
01123
01124
01125
01126
01127 NLMISC::IMouseDevice *CDriverUser::enableLowLevelMouse(bool enable)
01128 {
01129 NL3D_MEM_DRIVER
01130 NL3D_HAUTO_UI_DRIVER;
01131
01132 return _Driver->enableLowLevelMouse(enable);
01133 }
01134 NLMISC::IKeyboardDevice *CDriverUser::enableLowLevelKeyboard(bool enable)
01135 {
01136 NL3D_MEM_DRIVER
01137 NL3D_HAUTO_UI_DRIVER;
01138
01139 return _Driver->enableLowLevelKeyboard(enable);
01140 }
01141 NLMISC::IInputDeviceManager *CDriverUser::getLowLevelInputDeviceManager()
01142 {
01143 NL3D_MEM_DRIVER
01144 NL3D_HAUTO_UI_DRIVER;
01145
01146 return _Driver->getLowLevelInputDeviceManager();
01147 }
01148 void CDriverUser::showCursor (bool b)
01149 {
01150 NL3D_MEM_DRIVER
01151 NL3D_HAUTO_UI_DRIVER;
01152
01153 _Driver->showCursor(b);
01154 }
01155 void CDriverUser::setMousePos (float x, float y)
01156 {
01157 NL3D_MEM_DRIVER
01158 NL3D_HAUTO_UI_DRIVER;
01159
01160 _Driver->setMousePos (x, y);
01161 }
01162 void CDriverUser::setCapture (bool b)
01163 {
01164 NL3D_MEM_DRIVER
01165 NL3D_HAUTO_UI_DRIVER;
01166
01167 _Driver->setCapture (b);
01168 }
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179 void CDriverUser::setupAsyncTextureLod(uint baseLevel, uint maxLevel)
01180 {
01181 _AsyncTextureManager.setupLod(baseLevel, maxLevel);
01182 }
01183
01184 void CDriverUser::setupAsyncTextureMaxUploadPerFrame(uint maxup)
01185 {
01186 _AsyncTextureManager.setupMaxUploadPerFrame(maxup);
01187 }
01188
01189 void CDriverUser::updateAsyncTexture()
01190 {
01191 _AsyncTextureManager.update(getDriver());
01192 }
01193
01194
01195
01196 void CDriverUser::setupMaxTotalAsyncTextureSize(uint maxText)
01197 {
01198 _AsyncTextureManager.setupMaxTotalTextureSize(maxText);
01199 }
01200
01201 uint CDriverUser::getTotalAsyncTextureSizeAsked() const
01202 {
01203 return _AsyncTextureManager.getTotalTextureSizeAsked();
01204 }
01205
01206 uint CDriverUser::getLastAsyncTextureSizeGot() const
01207 {
01208 return _AsyncTextureManager.getLastTextureSizeGot();
01209 }
01210
01211
01212 void CDriverUser::setupMaxHLSColoringPerFrame(uint maxCol)
01213 {
01214 _AsyncTextureManager.setupMaxHLSColoringPerFrame(maxCol);
01215 }
01216
01217
01218 void CDriverUser::loadHLSBank(const std::string &fileName)
01219 {
01220
01221 CHLSTextureBank *hlsBank= new CHLSTextureBank;
01222 try
01223 {
01224 std::string path= CPath::lookup(fileName);
01225 CIFile fIn;
01226 if(!fIn.open(path))
01227 throw EPathNotFound(path);
01228 fIn.serial(*hlsBank);
01229 }
01230 catch(Exception &)
01231 {
01232 delete hlsBank;
01233 throw;
01234 }
01235
01236
01237 _AsyncTextureManager.HLSManager.addBank(hlsBank);
01238 }
01239
01240
01241 }