Change Encyclo button name and macros icon
[ryzomcore.git] / nel / src / 3d / driver_user.cpp
blob757d2183fe1d92a4413d1dcec4fc0141408d5a88
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
6 // Copyright (C) 2010 Robert TIMM (rti) <mail@rtti.de>
7 // Copyright (C) 2013-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // Copyright (C) 2015 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
9 //
10 // This program is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Affero General Public License as
12 // published by the Free Software Foundation, either version 3 of the
13 // License, or (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Affero General Public License for more details.
20 // You should have received a copy of the GNU Affero General Public License
21 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "std3d.h"
25 // ***************************************************************************
26 // THIS FILE IS DIVIDED IN TWO PARTS BECAUSE IT MAKES VISUAL CRASH.
27 // fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
28 // ***************************************************************************
30 #include "nel/3d/driver_user.h"
31 #include "nel/3d/u_driver.h"
32 #include "nel/3d/dru.h"
33 #include "nel/3d/scene.h"
34 #include "nel/3d/text_context_user.h"
35 #include "nel/3d/texture_user.h"
36 #include "nel/3d/texture_file.h"
37 #include "nel/3d/scene_user.h"
38 #include "nel/3d/init_3d.h"
39 #include "nel/3d/water_env_map_user.h"
40 #include "nel/3d/water_pool_manager.h"
41 #include "nel/3d/u_camera.h"
42 #include "nel/3d/debug_vb.h"
44 #include "nel/misc/hierarchical_timer.h"
45 #include "nel/misc/event_emitter.h"
47 using namespace NLMISC;
49 #ifdef DEBUG_NEW
50 #define new DEBUG_NEW
51 #endif
53 namespace NL3D
57 H_AUTO_DECL( NL3D_UI_Driver )
58 H_AUTO_DECL( NL3D_Render_DriverClearBuffer )
59 H_AUTO_DECL( NL3D_Render_DriverSwapBuffer )
60 H_AUTO_DECL( NL3D_Texture_Driver )
62 #define NL3D_HAUTO_UI_DRIVER H_AUTO_USE( NL3D_UI_Driver )
63 #define NL3D_HAUTO_CLEAR_DRIVER H_AUTO_USE( NL3D_Render_DriverClearBuffer )
64 #define NL3D_HAUTO_SWAP_DRIVER H_AUTO_USE( NL3D_Render_DriverSwapBuffer )
65 #define NL3D_HAUTO_TEX_DRIVER H_AUTO_USE( NL3D_Texture_Driver )
67 // ***************************************************************************
68 // ***************************************************************************
69 // UDriver implementation (gcc link bug force to not put them in .h).
70 // ***************************************************************************
71 // ***************************************************************************
74 // ***************************************************************************
75 UDriver::UDriver()
78 // ***************************************************************************
79 UDriver::~UDriver()
81 purgeMemory();
84 // ***************************************************************************
85 void UDriver::setMatrixMode2D11()
87 setMatrixMode2D(CFrustum(0.0f,1.0f,0.0f,1.0f,-1.0f,1.0f,false));
90 // ***************************************************************************
91 void UDriver::setMatrixMode2D43()
93 setMatrixMode2D(CFrustum(0.0f,4.0f/3.0f,0.0f,1.0f,-1.0f,1.0f,false));
96 // ***************************************************************************
97 UDriver *UDriver::createDriver(uintptr_t windowIcon, bool direct3d, emptyProc exitFunc)
99 return new CDriverUser (windowIcon, direct3d ? CDriverUser::Direct3d:CDriverUser::OpenGl, exitFunc);
102 // ***************************************************************************
103 UDriver *UDriver::createDriver(uintptr_t windowIcon, TDriver driver, emptyProc exitFunc)
105 return new CDriverUser (windowIcon, (CDriverUser::TDriver)driver, exitFunc);
108 // ***************************************************************************
109 void UDriver::purgeMemory()
111 CPointLight::purge ();
112 GetWaterPoolManager().reset();
113 contReset(CLandscapeGlobals::PassTriArray);
117 // ***************************************************************************
118 // ***************************************************************************
119 // WINDOWS Management.
120 // ***************************************************************************
121 // ***************************************************************************
124 // ***************************************************************************
125 CDriverUser::CDriverUser (uintptr_t windowIcon, TDriver driver, emptyProc exitFunc)
127 // The enum of IDriver and UDriver MUST be the same!!!
128 nlassert((uint)IDriver::idCount == (uint)UDriver::idCount);
129 nlassert((uint)IDriver::typeCount == (uint)UDriver::typeCount);
130 nlassert((uint)IDriver::iconCount == (uint)UDriver::iconCount);
133 NL3D::init3d();
135 _Driver = NULL;
137 // Create/Init Driver.
138 #if defined(NL_OS_WINDOWS)
139 if (driver == Direct3d)
140 _Driver= CDRU::createD3DDriver();
141 #endif
143 if (!_Driver && driver == OpenGl)
144 _Driver= CDRU::createGlDriver();
146 if (!_Driver && driver == OpenGlEs)
147 _Driver= CDRU::createGlEsDriver();
149 nlassert(_Driver);
150 _Driver->init (windowIcon, exitFunc);
152 _WindowInit= false;
154 // Init of VBuffers/PBs for 2D/3D interface.
155 _VBFlat.setVertexFormat(CVertexBuffer::PositionFlag);
156 _VBColor.setVertexFormat(CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag);
157 _VBUv.setVertexFormat(CVertexBuffer::PositionFlag | CVertexBuffer::TexCoord0Flag);
158 _VBColorUv.setVertexFormat(CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag | CVertexBuffer::TexCoord0Flag);
159 _VBQuadsColUv.setVertexFormat(CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag | CVertexBuffer::TexCoord0Flag);
160 _VBTrisColUv.setVertexFormat(CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag | CVertexBuffer::TexCoord0Flag);
161 _VBQuadsColUv2.setVertexFormat(CVertexBuffer::PositionFlag | CVertexBuffer::PrimaryColorFlag | CVertexBuffer::TexCoord0Flag | CVertexBuffer::TexCoord1Flag);
162 // max is quad.
163 _VBFlat.setNumVertices(4);
164 _VBColor.setNumVertices(4);
165 _VBUv.setNumVertices(4);
166 _VBColorUv.setNumVertices(4);
167 // memory management
168 _VBFlat.setPreferredMemory(CVertexBuffer::RAMVolatile, false);
169 _VBColor.setPreferredMemory(CVertexBuffer::RAMVolatile, false);
170 _VBUv.setPreferredMemory(CVertexBuffer::RAMVolatile, false);
171 _VBColorUv.setPreferredMemory(CVertexBuffer::RAMVolatile, false);
172 _VBQuadsColUv.setPreferredMemory (CVertexBuffer::RAMVolatile, false);
173 _VBTrisColUv.setPreferredMemory (CVertexBuffer::RAMVolatile, false);
174 _VBQuadsColUv2.setPreferredMemory (CVertexBuffer::RAMVolatile, false);
175 // names
176 _VBFlat.setName("_VBFlat");
177 _VBColor.setName("_VBColor");
178 _VBUv.setName("_VBUv");
179 _VBColorUv.setName("_VBColorUv");
180 _VBQuadsColUv.setName("_VBQuadsColUv");
181 _VBTrisColUv.setName("_VBTrisColUv");
182 _VBQuadsColUv2.setName("_VBQuadsColUv2");
184 _PBLine.setFormat(NL_DEFAULT_INDEX_BUFFER_FORMAT);
185 _PBLine.setNumIndexes(2);
186 CIndexBufferReadWrite iba;
187 _PBLine.lock (iba);
188 iba.setLine(0, 0, 1);
189 _PBTri.setFormat(NL_DEFAULT_INDEX_BUFFER_FORMAT);
190 _PBTri.setNumIndexes(3);
191 _PBTri.lock (iba);
192 iba.setTri(0, 0, 1, 2);
194 _RenderTargetManager.m_Driver = this;
195 _ShapeBank._DriverUser = this;
197 _EffectRenderTarget = NULL;
199 NL_SET_IB_NAME(_PBLine, "CDriverUser::_PBLine");
200 NL_SET_IB_NAME(_PBTri, "CDriverUser::_PBTri");
202 // ***************************************************************************
203 CDriverUser::~CDriverUser()
205 release();
207 delete _Driver;
208 _Driver= NULL;
211 // ***************************************************************************
212 void CDriverUser::disableHardwareVertexProgram()
214 NL3D_HAUTO_UI_DRIVER;
216 _Driver->disableHardwareVertexProgram();
218 void CDriverUser::disableHardwarePixelProgram()
220 NL3D_HAUTO_UI_DRIVER;
222 _Driver->disableHardwarePixelProgram();
224 void CDriverUser::disableHardwareVertexArrayAGP()
226 NL3D_HAUTO_UI_DRIVER;
228 _Driver->disableHardwareVertexArrayAGP();
230 void CDriverUser::disableHardwareTextureShader()
232 NL3D_HAUTO_UI_DRIVER;
234 _Driver->disableHardwareTextureShader();
237 // ***************************************************************************
238 bool CDriverUser::setDisplay(const CMode &mode, bool show, bool resizeable)
240 NL3D_HAUTO_UI_DRIVER;
242 return setDisplay(EmptyWindow, mode, show, resizeable);
245 // ***************************************************************************
246 bool CDriverUser::setDisplay(nlWindow wnd, const CMode &mode, bool show, bool resizeable)
248 NL3D_HAUTO_UI_DRIVER;
250 // window init.
251 if (_Driver->setDisplay(wnd, GfxMode(mode.Width, mode.Height, mode.Depth, mode.Windowed, false, mode.Frequency, mode.AntiAlias, mode.DisplayDevice), show, resizeable))
253 // Always true
254 nlverify (activate());
256 _WindowInit= true;
258 // Event init.
259 AsyncListener.reset ();
260 EventServer.addEmitter(_Driver->getEventEmitter());
261 AsyncListener.addToServer(EventServer);
263 // Matrix Context (2D).
264 _CurrentMatrixContext.Viewport.initFullScreen();
265 _CurrentMatrixContext.Scissor.initFullScreen();
266 setMatrixMode2D11();
268 // 2D Material.
269 _MatFlat.attach (&_MatFlatInternal);
270 _MatFlat.initUnlit();
271 _MatFlat.setZFunc(UMaterial::always);
272 _MatFlat.setZWrite(false);
273 _MatText.attach (&_MatFlatInternal);
274 _MatText.initUnlit();
275 _MatText.setZFunc(UMaterial::always);
276 _MatText.setZWrite(false);
277 _MatStretchText.attach (&_MatTextStretchInternal);
278 _MatStretchText.initUnlit();
279 _MatStretchText.setZFunc(UMaterial::always);
280 _MatStretchText.setZWrite(false);
281 _MatTextStretchInternal.setDoubleSided(true);
283 // make CTextureFile aware if 3d driver support non power of two textures
284 NL3D::CTextureFile::setSupportNonPowerOfTwoTextures(_Driver->supportNonPowerOfTwoTextures());
286 // Done
287 return true;
289 return false;
292 // ***************************************************************************
293 bool CDriverUser::setMode(const CMode& mode)
295 return _Driver->setMode(GfxMode(mode.Width, mode.Height, mode.Depth, mode.Windowed, false, mode.Frequency, mode.AntiAlias, mode.DisplayDevice));
298 // ----------------------------------------------------------------------------
299 struct CModeSorter
301 bool operator()(const UDriver::CMode &mode1, const UDriver::CMode &mode2) const
303 if (mode1.Width == mode2.Width)
305 if (mode1.Height == mode2.Height) return mode1.Frequency < mode2.Frequency;
307 return mode1.Height < mode2.Height;
310 return mode1.Width < mode2.Width;
314 // ***************************************************************************
315 bool CDriverUser::getModes(std::vector<CMode> &modes)
317 std::vector<GfxMode> vTmp;
318 bool res = _Driver->getModes(vTmp);
319 modes.clear();
320 for (uint i = 0; i < vTmp.size(); ++i)
321 modes.push_back(CMode(vTmp[i].Width, vTmp[i].Height, vTmp[i].Depth, vTmp[i].Windowed, vTmp[i].Frequency, vTmp[i].AntiAlias, vTmp[i].DisplayDevice));
323 std::sort(modes.begin(), modes.end(), CModeSorter());
325 return res;
328 // ***************************************************************************
329 bool CDriverUser::getCurrentScreenMode(CMode &mode)
331 GfxMode gfxMode;
332 bool res= _Driver->getCurrentScreenMode(gfxMode);
333 mode.Windowed= gfxMode.Windowed;
334 mode.DisplayDevice= gfxMode.DisplayDevice;
335 mode.Width= gfxMode.Width;
336 mode.Height= gfxMode.Height;
337 mode.Depth= gfxMode.Depth;
338 mode.Frequency= gfxMode.Frequency;
339 mode.AntiAlias= gfxMode.AntiAlias;
340 return res;
343 // ***************************************************************************
344 void CDriverUser::setWindowTitle(const ucstring &title)
346 NL3D_HAUTO_UI_DRIVER;
347 _Driver->setWindowTitle(title);
350 // ***************************************************************************
351 void CDriverUser::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
353 NL3D_HAUTO_UI_DRIVER;
354 _Driver->setWindowIcon(bitmaps);
357 // ***************************************************************************
358 void CDriverUser::setWindowPos(sint32 x, sint32 y)
360 NL3D_HAUTO_UI_DRIVER;
361 _Driver->setWindowPos(x, y);
364 // ***************************************************************************
365 void CDriverUser::showWindow(bool show)
367 NL3D_HAUTO_UI_DRIVER;
368 _Driver->showWindow(show);
371 // ***************************************************************************
372 void CDriverUser::release()
374 NL3D_HAUTO_UI_DRIVER;
376 if(!_WindowInit)
377 return;
379 // 2D Material.
380 _MatFlat.initUnlit();
381 _MatText.initUnlit();
382 _MatStretchText.initUnlit();
384 // delete Texture, mat ... list.
385 _Textures.clear();
386 _TextContexts.clear();
387 _Scenes.clear();
389 // release event.
390 AsyncListener.removeFromServer(EventServer);
391 EventServer.removeEmitter(_Driver->getEventEmitter());
393 // release window.
394 _Driver->release();
395 _WindowInit= false;
399 // ***************************************************************************
400 bool CDriverUser::activate(void)
402 NL3D_HAUTO_UI_DRIVER;
404 return _Driver->activate();
407 // ***************************************************************************
408 bool CDriverUser::isActive()
410 NL3D_HAUTO_UI_DRIVER;
412 return _Driver->isActive();
416 // ***************************************************************************
417 nlWindow CDriverUser::getDisplay ()
419 NL3D_HAUTO_UI_DRIVER;
421 return _Driver->getDisplay ();
426 // ***************************************************************************
427 // ***************************************************************************
428 // Matrix context.
429 // ***************************************************************************
430 // ***************************************************************************
433 // ***************************************************************************
434 void CDriverUser::restoreMatrixContextMatrixOnly()
436 NL3D_HAUTO_UI_DRIVER;
438 CFrustum &f= _CurrentMatrixContext.Frustum;
439 _Driver->setFrustum(f.Left, f.Right, f.Bottom, f.Top, f.Near, f.Far, f.Perspective);
440 _Driver->setupViewMatrix(_CurrentMatrixContext.ViewMatrix);
441 _Driver->setupModelMatrix(_CurrentMatrixContext.ModelMatrix);
444 // ***************************************************************************
445 void CDriverUser::setupMatrixContext()
447 NL3D_HAUTO_UI_DRIVER;
449 _Driver->setupScissor(_CurrentMatrixContext.Scissor);
450 _Driver->setupViewport(_CurrentMatrixContext.Viewport);
451 CFrustum &f= _CurrentMatrixContext.Frustum;
452 _Driver->setFrustum(f.Left, f.Right, f.Bottom, f.Top, f.Near, f.Far, f.Perspective);
453 _Driver->setupViewMatrix(_CurrentMatrixContext.ViewMatrix);
454 _Driver->setupModelMatrix(_CurrentMatrixContext.ModelMatrix);
456 // ***************************************************************************
457 void CDriverUser::setScissor(const CScissor &sc)
459 NL3D_HAUTO_UI_DRIVER;
461 _CurrentMatrixContext.Scissor= sc;
462 setupMatrixContext();
464 // ***************************************************************************
465 CScissor CDriverUser::getScissor()
467 NL3D_HAUTO_UI_DRIVER;
469 return _CurrentMatrixContext.Scissor;
471 // ***************************************************************************
472 void CDriverUser::setViewport(const CViewport &vp)
474 NL3D_HAUTO_UI_DRIVER;
476 _CurrentMatrixContext.Viewport= vp;
477 setupMatrixContext();
479 // ***************************************************************************
480 CViewport CDriverUser::getViewport()
482 NL3D_HAUTO_UI_DRIVER;
484 return _CurrentMatrixContext.Viewport;
486 // ***************************************************************************
487 void CDriverUser::setFrustum(const CFrustum &frust)
489 NL3D_HAUTO_UI_DRIVER;
491 _CurrentMatrixContext.Frustum= frust;
492 setupMatrixContext();
494 // ***************************************************************************
495 CFrustum CDriverUser::getFrustum()
497 NL3D_HAUTO_UI_DRIVER;
499 return _CurrentMatrixContext.Frustum;
501 // ***************************************************************************
502 void CDriverUser::setFrustumMatrix(CMatrix &frust)
504 NL3D_HAUTO_UI_DRIVER;
506 _Driver->setFrustumMatrix(frust);
508 // ***************************************************************************
509 CMatrix CDriverUser::getFrustumMatrix()
511 NL3D_HAUTO_UI_DRIVER;
513 return _Driver->getFrustumMatrix();
515 // ***************************************************************************
517 float CDriverUser::getClipSpaceZMin() const
519 return _Driver->getClipSpaceZMin();
521 // ***************************************************************************
523 void CDriverUser::setViewMatrix(const CMatrix &mat)
525 NL3D_HAUTO_UI_DRIVER;
527 _CurrentMatrixContext.ViewMatrix= mat;
528 setupMatrixContext();
530 // ***************************************************************************
531 CMatrix CDriverUser::getViewMatrix()
533 NL3D_HAUTO_UI_DRIVER;
535 return _CurrentMatrixContext.ViewMatrix;
537 // ***************************************************************************
538 void CDriverUser::setModelMatrix(const CMatrix &mat)
540 NL3D_HAUTO_UI_DRIVER;
542 _CurrentMatrixContext.ModelMatrix= mat;
543 setupMatrixContext();
545 // ***************************************************************************
546 CMatrix CDriverUser::getModelMatrix()
548 NL3D_HAUTO_UI_DRIVER;
550 return _CurrentMatrixContext.ModelMatrix;
555 // ***************************************************************************
556 void CDriverUser::setMatrixMode2D(const CFrustum &frust)
558 NL3D_HAUTO_UI_DRIVER;
560 _CurrentMatrixContext.Frustum= frust;
561 // We still work in NL3D coordinates, so must convert y to z.
562 CVector I(1,0,0);
563 CVector J(0,0,1);
564 CVector K(0,-1,0);
566 _CurrentMatrixContext.ViewMatrix.identity();
567 _CurrentMatrixContext.ViewMatrix.setRot(I,J,K, true);
568 _CurrentMatrixContext.ModelMatrix.identity();
570 setupMatrixContext();
572 // ***************************************************************************
573 void CDriverUser::setMatrixMode3D(UCamera &camera)
575 NL3D_HAUTO_UI_DRIVER;
577 // Retrieve the matrix and frustum from the camera.
578 CMatrix viewMat;
579 viewMat= camera.getMatrix();
580 viewMat.invert();
581 setViewMatrix(viewMat);
582 setModelMatrix(CMatrix::Identity);
583 setFrustum(camera.getFrustum());
586 // ***************************************************************************
587 void CDriverUser::setDepthRange(float znear, float zfar)
589 NL3D_HAUTO_UI_DRIVER;
590 _Driver->setDepthRange(znear, zfar);
593 // ***************************************************************************
594 void CDriverUser::getDepthRange(float & znear, float & zfar)
596 NL3D_HAUTO_UI_DRIVER;
597 _Driver->getDepthRange(znear, zfar);
600 // ***************************************************************************
601 void CDriverUser::setColorMask (bool bRed, bool bGreen, bool bBlue, bool bAlpha)
603 _Driver->setColorMask(bRed, bGreen, bBlue, bAlpha);
606 // ***************************************************************************
607 // ***************************************************************************
608 // 2D/3D INTERFACE.
609 // ***************************************************************************
610 // ***************************************************************************
612 // ***************************************************************************
613 void CDriverUser::drawLine(const NLMISC::CLine &shp, UMaterial &mat)
615 H_AUTO2;
617 CVertexBuffer &vb= _VBFlat;
618 CIndexBuffer &pb= _PBLine;
621 CVertexBufferReadWrite vba;
622 vb.lock (vba);
623 vba.setVertexCoord (0, shp.V0);
624 vba.setVertexCoord (1, shp.V1);
627 _Driver->activeVertexBuffer(vb);
628 _Driver->activeIndexBuffer(pb);
629 _Driver->renderLines(convMat(mat), 0, 1);
631 // ***************************************************************************
632 void CDriverUser::drawLine(const NLMISC::CLineColor &shp, UMaterial &mat)
634 H_AUTO2;
636 CVertexBuffer &vb= _VBColor;
637 CIndexBuffer &pb= _PBLine;
640 CVertexBufferReadWrite vba;
641 vb.lock (vba);
642 vba.setVertexCoord (0, shp.V0);
643 vba.setVertexCoord (1, shp.V1);
644 vba.setColor(0, shp.Color0);
645 vba.setColor(1, shp.Color1);
648 _Driver->activeVertexBuffer(vb);
649 _Driver->activeIndexBuffer(pb);
650 _Driver->renderLines(convMat(mat), 0, 1);
652 // ***************************************************************************
653 void CDriverUser::drawLine(const NLMISC::CLineUV &shp, UMaterial &mat)
655 H_AUTO2;
657 CVertexBuffer &vb= _VBUv;
658 CIndexBuffer &pb= _PBLine;
661 CVertexBufferReadWrite vba;
662 vb.lock (vba);
663 vba.setVertexCoord (0, shp.V0);
664 vba.setVertexCoord (1, shp.V1);
665 vba.setTexCoord (0, 0, shp.Uv0);
666 vba.setTexCoord (1, 0, shp.Uv1);
669 _Driver->activeVertexBuffer(vb);
670 _Driver->activeIndexBuffer(pb);
671 _Driver->renderLines(convMat(mat), 0, 1);
673 // ***************************************************************************
674 void CDriverUser::drawLine(const NLMISC::CLineColorUV &shp, UMaterial &mat)
676 H_AUTO2;
678 CVertexBuffer &vb= _VBColorUv;
679 CIndexBuffer &pb= _PBLine;
682 CVertexBufferReadWrite vba;
683 vb.lock (vba);
684 vba.setVertexCoord (0, shp.V0);
685 vba.setVertexCoord (1, shp.V1);
686 vba.setColor(0, shp.Color0);
687 vba.setColor(1, shp.Color1);
688 vba.setTexCoord (0, 0, shp.Uv0);
689 vba.setTexCoord (1, 0, shp.Uv1);
692 _Driver->activeVertexBuffer(vb);
693 _Driver->activeIndexBuffer(pb);
694 _Driver->renderLines(convMat(mat), 0, 1);
699 // ***************************************************************************
700 void CDriverUser::drawTriangle(const NLMISC::CTriangle &shp, UMaterial &mat)
702 H_AUTO2;
704 CVertexBuffer &vb= _VBFlat;
705 CIndexBuffer &pb= _PBTri;
708 CVertexBufferReadWrite vba;
709 vb.lock (vba);
710 vba.setVertexCoord (0, shp.V0);
711 vba.setVertexCoord (1, shp.V1);
712 vba.setVertexCoord (2, shp.V2);
715 _Driver->activeVertexBuffer(vb);
716 _Driver->activeIndexBuffer(pb);
717 _Driver->renderTriangles(convMat(mat), 0, 1);
719 // ***************************************************************************
720 void CDriverUser::drawTriangle(const NLMISC::CTriangleColor &shp, UMaterial &mat)
722 H_AUTO2;
724 CVertexBuffer &vb= _VBColor;
725 CIndexBuffer &pb= _PBTri;
728 CVertexBufferReadWrite vba;
729 vb.lock (vba);
730 vba.setVertexCoord (0, shp.V0);
731 vba.setVertexCoord (1, shp.V1);
732 vba.setVertexCoord (2, shp.V2);
733 vba.setColor(0, shp.Color0);
734 vba.setColor(1, shp.Color1);
735 vba.setColor(2, shp.Color2);
738 _Driver->activeVertexBuffer(vb);
739 _Driver->activeIndexBuffer(pb);
740 _Driver->renderTriangles(convMat(mat), 0, 1);
742 // ***************************************************************************
743 void CDriverUser::drawTriangle(const NLMISC::CTriangleUV &shp, UMaterial &mat)
745 H_AUTO2;
747 CVertexBuffer &vb= _VBUv;
748 CIndexBuffer &pb= _PBTri;
751 CVertexBufferReadWrite vba;
752 vb.lock (vba);
753 vba.setVertexCoord (0, shp.V0);
754 vba.setVertexCoord (1, shp.V1);
755 vba.setVertexCoord (2, shp.V2);
756 vba.setTexCoord (0, 0, shp.Uv0);
757 vba.setTexCoord (1, 0, shp.Uv1);
758 vba.setTexCoord (2, 0, shp.Uv2);
761 _Driver->activeVertexBuffer(vb);
762 _Driver->activeIndexBuffer(pb);
763 _Driver->renderTriangles(convMat(mat), 0, 1);
765 // ***************************************************************************
766 void CDriverUser::drawTriangle(const NLMISC::CTriangleColorUV &shp, UMaterial &mat)
768 H_AUTO2;
770 CVertexBuffer &vb= _VBColorUv;
771 CIndexBuffer &pb= _PBTri;
774 CVertexBufferReadWrite vba;
775 vb.lock (vba);
776 vba.setVertexCoord (0, shp.V0);
777 vba.setVertexCoord (1, shp.V1);
778 vba.setVertexCoord (2, shp.V2);
779 vba.setColor(0, shp.Color0);
780 vba.setColor(1, shp.Color1);
781 vba.setColor(2, shp.Color2);
782 vba.setTexCoord (0, 0, shp.Uv0);
783 vba.setTexCoord (1, 0, shp.Uv1);
784 vba.setTexCoord (2, 0, shp.Uv2);
787 _Driver->activeVertexBuffer(vb);
788 _Driver->activeIndexBuffer(pb);
789 _Driver->renderTriangles(convMat(mat), 0, 1);
794 // ***************************************************************************
795 void CDriverUser::drawQuad(const NLMISC::CQuad &shp, UMaterial &mat)
797 H_AUTO2;
799 CVertexBuffer &vb= _VBFlat;
802 CVertexBufferReadWrite vba;
803 vb.lock (vba);
804 vba.setVertexCoord (0, shp.V0);
805 vba.setVertexCoord (1, shp.V1);
806 vba.setVertexCoord (2, shp.V2);
807 vba.setVertexCoord (3, shp.V3);
810 _Driver->activeVertexBuffer(vb);
811 _Driver->renderRawQuads(convMat(mat), 0, 1);
813 // ***************************************************************************
814 void CDriverUser::drawQuad(const NLMISC::CQuadColor &shp, UMaterial &mat)
816 H_AUTO2;
818 CVertexBuffer &vb= _VBColor;
821 CVertexBufferReadWrite vba;
822 vb.lock (vba);
823 vba.setVertexCoord (0, shp.V0);
824 vba.setVertexCoord (1, shp.V1);
825 vba.setVertexCoord (2, shp.V2);
826 vba.setVertexCoord (3, shp.V3);
827 vba.setColor(0, shp.Color0);
828 vba.setColor(1, shp.Color1);
829 vba.setColor(2, shp.Color2);
830 vba.setColor(3, shp.Color3);
833 _Driver->activeVertexBuffer(vb);
834 _Driver->renderRawQuads(convMat(mat), 0, 1);
836 // ***************************************************************************
837 void CDriverUser::drawQuad(const NLMISC::CQuadUV &shp, UMaterial &mat)
839 H_AUTO2;
841 CVertexBuffer &vb= _VBUv;
844 CVertexBufferReadWrite vba;
845 vb.lock (vba);
846 vba.setVertexCoord (0, shp.V0);
847 vba.setVertexCoord (1, shp.V1);
848 vba.setVertexCoord (2, shp.V2);
849 vba.setVertexCoord (3, shp.V3);
850 vba.setTexCoord (0, 0, shp.Uv0);
851 vba.setTexCoord (1, 0, shp.Uv1);
852 vba.setTexCoord (2, 0, shp.Uv2);
853 vba.setTexCoord (3, 0, shp.Uv3);
856 _Driver->activeVertexBuffer(vb);
857 _Driver->renderRawQuads(convMat(mat), 0, 1);
859 // ***************************************************************************
860 void CDriverUser::drawQuad(const NLMISC::CQuadColorUV &shp, UMaterial &mat)
862 H_AUTO2;
864 CVertexBuffer &vb= _VBColorUv;
867 CVertexBufferReadWrite vba;
868 vb.lock (vba);
869 vba.setVertexCoord (0, shp.V0);
870 vba.setVertexCoord (1, shp.V1);
871 vba.setVertexCoord (2, shp.V2);
872 vba.setVertexCoord (3, shp.V3);
873 vba.setColor(0, shp.Color0);
874 vba.setColor(1, shp.Color1);
875 vba.setColor(2, shp.Color2);
876 vba.setColor(3, shp.Color3);
877 vba.setTexCoord (0, 0, shp.Uv0);
878 vba.setTexCoord (1, 0, shp.Uv1);
879 vba.setTexCoord (2, 0, shp.Uv2);
880 vba.setTexCoord (3, 0, shp.Uv3);
883 _Driver->activeVertexBuffer(vb);
884 _Driver->renderRawQuads(convMat(mat), 0, 1);
886 // ***************************************************************************
887 void CDriverUser::drawQuads(const std::vector<NLMISC::CQuadColorUV> &q, UMaterial &mat)
889 H_AUTO2;
891 const CQuadColorUV *qptr = &(q[0]);
892 drawQuads(qptr , (uint32)q.size(), mat);
895 // ***************************************************************************
896 void CDriverUser::drawQuads(const std::vector<NLMISC::CQuadColorUV2> &q, UMaterial &mat)
898 H_AUTO2;
900 const CQuadColorUV2 *qptr = &(q[0]);
901 drawQuads(qptr , (uint32)q.size(), mat);
904 // ***************************************************************************
905 void CDriverUser::drawQuads(const NLMISC::CQuadColorUV *quads, uint32 nbQuads, UMaterial &mat)
907 H_AUTO2;
909 CVertexBuffer &vb = _VBQuadsColUv;
911 vb.setNumVertices (4*nbQuads);
913 CVertexBufferReadWrite vba;
914 vb.lock (vba);
916 uint8 *dstPtr= (uint8*)vba.getVertexCoordPointer();
917 uint32 colorOfs= vb.getColorOff();
918 uint32 uvOfs= vb.getTexCoordOff();
919 uint32 vSize= vb.getVertexSize();
921 if (vb.getVertexColorFormat() == CVertexBuffer::TRGBA)
923 for (uint32 i = 0; i < nbQuads; ++i)
925 const NLMISC::CQuadColorUV &qcuv = quads[i];
926 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
927 *(CVector*)(dstPtr+0)= qcuv.V0;
928 CHECK_VBA_RANGE(vba, dstPtr+uvOfs, sizeof(CUV))
929 *(CUV*)(dstPtr+uvOfs)= qcuv.Uv0;
930 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
931 *(CRGBA*)(dstPtr+colorOfs)= qcuv.Color0;
932 dstPtr+= vSize;
933 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
934 *(CVector*)(dstPtr+0)= qcuv.V1;
935 CHECK_VBA_RANGE(vba, dstPtr+uvOfs, sizeof(CUV))
936 *(CUV*)(dstPtr+uvOfs)= qcuv.Uv1;
937 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
938 *(CRGBA*)(dstPtr+colorOfs)= qcuv.Color1;
939 dstPtr+= vSize;
940 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
941 *(CVector*)(dstPtr+0)= qcuv.V2;
942 CHECK_VBA_RANGE(vba, dstPtr+uvOfs, sizeof(CUV))
943 *(CUV*)(dstPtr+uvOfs)= qcuv.Uv2;
944 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
945 *(CRGBA*)(dstPtr+colorOfs)= qcuv.Color2;
946 dstPtr+= vSize;
947 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
948 *(CVector*)(dstPtr+0)= qcuv.V3;
949 CHECK_VBA_RANGE(vba, dstPtr+uvOfs, sizeof(CUV))
950 *(CUV*)(dstPtr+uvOfs)= qcuv.Uv3;
951 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
952 *(CRGBA*)(dstPtr+colorOfs)= qcuv.Color3;
953 dstPtr+= vSize;
956 else
958 for (uint32 i = 0; i < nbQuads; ++i)
960 const NLMISC::CQuadColorUV &qcuv = quads[i];
961 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
962 *(CVector*)(dstPtr+0)= qcuv.V0;
963 CHECK_VBA_RANGE(vba, dstPtr+uvOfs, sizeof(CUV))
964 *(CUV*)(dstPtr+uvOfs)= qcuv.Uv0;
965 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
966 *(CBGRA*)(dstPtr+colorOfs)= qcuv.Color0;
967 dstPtr+= vSize;
968 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
969 *(CVector*)(dstPtr+0)= qcuv.V1;
970 CHECK_VBA_RANGE(vba, dstPtr+uvOfs, sizeof(CUV))
971 *(CUV*)(dstPtr+uvOfs)= qcuv.Uv1;
972 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
973 *(CBGRA*)(dstPtr+colorOfs)= qcuv.Color1;
974 dstPtr+= vSize;
975 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
976 *(CVector*)(dstPtr+0)= qcuv.V2;
977 CHECK_VBA_RANGE(vba, dstPtr+uvOfs, sizeof(CUV))
978 *(CUV*)(dstPtr+uvOfs)= qcuv.Uv2;
979 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CBGRA))
980 *(CBGRA*)(dstPtr+colorOfs)= qcuv.Color2;
981 dstPtr+= vSize;
982 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
983 *(CVector*)(dstPtr+0)= qcuv.V3;
984 CHECK_VBA_RANGE(vba, dstPtr+uvOfs, sizeof(CUV))
985 *(CUV*)(dstPtr+uvOfs)= qcuv.Uv3;
986 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
987 *(CBGRA*)(dstPtr+colorOfs)= qcuv.Color3;
988 dstPtr+= vSize;
993 _Driver->activeVertexBuffer(vb);
994 _Driver->renderRawQuads(convMat(mat), 0, nbQuads);
998 // ***************************************************************************
999 void CDriverUser::drawQuads(const NLMISC::CQuadColorUV2 *quads, uint32 nbQuads, UMaterial &mat)
1001 H_AUTO2;
1003 CVertexBuffer &vb = _VBQuadsColUv2;
1005 vb.setNumVertices (4*nbQuads);
1007 CVertexBufferReadWrite vba;
1008 vb.lock (vba);
1009 uint8 *dstPtr= (uint8*)vba.getVertexCoordPointer();
1010 uint32 colorOfs= vb.getColorOff();
1011 uint32 uvOfs0= vb.getTexCoordOff(0);
1012 uint32 uvOfs1= vb.getTexCoordOff(1);
1013 uint32 vSize= vb.getVertexSize();
1015 if (vb.getVertexColorFormat() == CVertexBuffer::TRGBA)
1017 for (uint32 i = 0; i < nbQuads; ++i)
1019 const NLMISC::CQuadColorUV2 &qcuv = quads[i];
1020 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1021 *(CVector*)(dstPtr+0)= qcuv.V0;
1022 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1023 *(CUV*)(dstPtr+uvOfs0)= qcuv.Uv0;
1024 CHECK_VBA_RANGE(vba, dstPtr+uvOfs1, sizeof(CUV))
1025 *(CUV*)(dstPtr+uvOfs1)= qcuv.Uv02;
1026 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1027 *(CRGBA*)(dstPtr+colorOfs)= qcuv.Color0;
1028 dstPtr+= vSize;
1029 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1030 *(CVector*)(dstPtr+0)= qcuv.V1;
1031 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1032 *(CUV*)(dstPtr+uvOfs0)= qcuv.Uv1;
1033 CHECK_VBA_RANGE(vba, dstPtr+uvOfs1, sizeof(CUV))
1034 *(CUV*)(dstPtr+uvOfs1)= qcuv.Uv12;
1035 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1036 *(CRGBA*)(dstPtr+colorOfs)= qcuv.Color1;
1037 dstPtr+= vSize;
1038 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1039 *(CVector*)(dstPtr+0)= qcuv.V2;
1040 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1041 *(CUV*)(dstPtr+uvOfs0)= qcuv.Uv2;
1042 CHECK_VBA_RANGE(vba, dstPtr+uvOfs1, sizeof(CUV))
1043 *(CUV*)(dstPtr+uvOfs1)= qcuv.Uv22;
1044 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1045 *(CRGBA*)(dstPtr+colorOfs)= qcuv.Color2;
1046 dstPtr+= vSize;
1047 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1048 *(CVector*)(dstPtr+0)= qcuv.V3;
1049 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1050 *(CUV*)(dstPtr+uvOfs0)= qcuv.Uv3;
1051 CHECK_VBA_RANGE(vba, dstPtr+uvOfs1, sizeof(CUV))
1052 *(CUV*)(dstPtr+uvOfs1)= qcuv.Uv32;
1053 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1054 *(CRGBA*)(dstPtr+colorOfs)= qcuv.Color3;
1055 dstPtr+= vSize;
1058 else
1060 for (uint32 i = 0; i < nbQuads; ++i)
1062 const NLMISC::CQuadColorUV2 &qcuv = quads[i];
1063 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1064 *(CVector*)(dstPtr+0)= qcuv.V0;
1065 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1066 *(CUV*)(dstPtr+uvOfs0)= qcuv.Uv0;
1067 CHECK_VBA_RANGE(vba, dstPtr+uvOfs1, sizeof(CUV))
1068 *(CUV*)(dstPtr+uvOfs1)= qcuv.Uv02;
1069 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1070 *(CBGRA*)(dstPtr+colorOfs)= qcuv.Color0;
1071 dstPtr+= vSize;
1072 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1073 *(CVector*)(dstPtr+0)= qcuv.V1;
1074 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1075 *(CUV*)(dstPtr+uvOfs0)= qcuv.Uv1;
1076 CHECK_VBA_RANGE(vba, dstPtr+uvOfs1, sizeof(CUV))
1077 *(CUV*)(dstPtr+uvOfs1)= qcuv.Uv12;
1078 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1079 *(CBGRA*)(dstPtr+colorOfs)= qcuv.Color1;
1080 dstPtr+= vSize;
1081 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1082 *(CVector*)(dstPtr+0)= qcuv.V2;
1083 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1084 *(CUV*)(dstPtr+uvOfs0)= qcuv.Uv2;
1085 CHECK_VBA_RANGE(vba, dstPtr+uvOfs1, sizeof(CUV))
1086 *(CUV*)(dstPtr+uvOfs1)= qcuv.Uv22;
1087 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1088 *(CBGRA*)(dstPtr+colorOfs)= qcuv.Color2;
1089 dstPtr+= vSize;
1090 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1091 *(CVector*)(dstPtr+0)= qcuv.V3;
1092 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1093 *(CUV*)(dstPtr+uvOfs0)= qcuv.Uv3;
1094 CHECK_VBA_RANGE(vba, dstPtr+uvOfs1, sizeof(CUV))
1095 *(CUV*)(dstPtr+uvOfs1)= qcuv.Uv32;
1096 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1097 *(CBGRA*)(dstPtr+colorOfs)= qcuv.Color3;
1098 dstPtr+= vSize;
1103 _Driver->activeVertexBuffer(vb);
1104 _Driver->renderRawQuads(convMat(mat), 0, nbQuads);
1108 // ***************************************************************************
1109 void CDriverUser::drawTriangles(const std::vector<NLMISC::CTriangleColorUV> &tris, UMaterial &mat)
1111 drawTriangles(&tris[0], (uint32) tris.size(), mat);
1114 // ***************************************************************************
1115 void CDriverUser::drawTriangles(const NLMISC::CTriangleColorUV *tris, uint32 nbTris, UMaterial &mat)
1117 if (nbTris == 0) return;
1118 CVertexBuffer &vb= _VBTrisColUv;
1119 vb.setNumVertices (3*nbTris);
1121 CVertexBufferReadWrite vba;
1122 vb.lock (vba);
1123 uint8 *dstPtr= (uint8*)vba.getVertexCoordPointer();
1124 uint32 colorOfs= vb.getColorOff();
1125 uint32 uvOfs0= vb.getTexCoordOff(0);
1126 uint32 vSize= vb.getVertexSize();
1127 const NLMISC::CTriangleColorUV *lastTri = tris + nbTris;
1128 if (vb.getVertexColorFormat() == CVertexBuffer::TRGBA)
1133 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1134 *(CVector*)(dstPtr+0)= tris->V0;
1135 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1136 *(CUV*)(dstPtr+uvOfs0)= tris->Uv0;
1137 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1138 *(CRGBA*)(dstPtr+colorOfs)= tris->Color0;
1139 dstPtr+= vSize;
1141 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1142 *(CVector*)(dstPtr+0)= tris->V1;
1143 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1144 *(CUV*)(dstPtr+uvOfs0)= tris->Uv1;
1145 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1146 *(CRGBA*)(dstPtr+colorOfs)= tris->Color1;
1147 dstPtr+= vSize;
1149 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1150 *(CVector*)(dstPtr+0)= tris->V2;
1151 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1152 *(CUV*)(dstPtr+uvOfs0)= tris->Uv2;
1153 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1154 *(CRGBA*)(dstPtr+colorOfs)= tris->Color2;
1155 dstPtr+= vSize;
1156 ++ tris;
1158 while (tris != lastTri);
1160 else
1165 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1166 *(CVector*)(dstPtr+0)= tris->V0;
1167 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1168 *(CUV*)(dstPtr+uvOfs0)= tris->Uv0;
1169 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1170 *(CBGRA*)(dstPtr+colorOfs)= tris->Color0;
1171 dstPtr+= vSize;
1173 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1174 *(CVector*)(dstPtr+0)= tris->V1;
1175 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1176 *(CUV*)(dstPtr+uvOfs0)= tris->Uv1;
1177 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1178 *(CBGRA*)(dstPtr+colorOfs)= tris->Color1;
1179 dstPtr+= vSize;
1181 CHECK_VBA_RANGE(vba, dstPtr+0, sizeof(CVector))
1182 *(CVector*)(dstPtr+0)= tris->V2;
1183 CHECK_VBA_RANGE(vba, dstPtr+uvOfs0, sizeof(CUV))
1184 *(CUV*)(dstPtr+uvOfs0)= tris->Uv2;
1185 CHECK_VBA_RANGE(vba, dstPtr+colorOfs, sizeof(CRGBA))
1186 *(CBGRA*)(dstPtr+colorOfs)= tris->Color2;
1187 dstPtr+= vSize;
1188 ++ tris;
1190 while (tris != lastTri);
1194 _Driver->activeVertexBuffer(vb);
1195 _Driver->renderRawTriangles(convMat(mat), 0, nbTris);
1198 // ***************************************************************************
1199 // ***************************************************************************
1200 // 2D TOOLS.
1201 // ***************************************************************************
1202 // ***************************************************************************
1205 // ***************************************************************************
1206 void CDriverUser::drawBitmap (float x, float y, float width, float height, class UTexture& texture, bool blend, CRGBA col)
1208 H_AUTO2;
1210 _MatText.setTexture(0, &texture);
1211 _MatText.setColor(col);
1212 _MatText.setBlend(blend);
1214 CQuadUV quad;
1215 quad.V0.set(x,y,0);
1216 quad.V1.set(x+width,y,0);
1217 quad.V2.set(x+width,y+height,0);
1218 quad.V3.set(x,y+height,0);
1219 quad.Uv0.U= 0.f;
1220 quad.Uv0.V= 1.f;
1221 quad.Uv1.U= 1.f;
1222 quad.Uv1.V= 1.f;
1223 quad.Uv2.U= 1.f;
1224 quad.Uv2.V= 0.f;
1225 quad.Uv3.U= 0.f;
1226 quad.Uv3.V= 0.f;
1228 drawQuad(quad, _MatText);
1230 // ***************************************************************************
1231 void CDriverUser::drawLine (float x0, float y0, float x1, float y1, CRGBA col)
1233 H_AUTO2;
1235 _MatFlat.setColor(col);
1236 _MatFlat.setBlend(true);
1238 CLine line;
1239 line.V0.set(x0,y0,0);
1240 line.V1.set(x1,y1,0);
1242 drawLine(line, _MatFlat);
1244 // ***************************************************************************
1245 void CDriverUser::drawTriangle (float x0, float y0, float x1, float y1, float x2, float y2, CRGBA col)
1247 H_AUTO2;
1249 _MatFlat.setColor(col);
1250 _MatFlat.setBlend(true);
1252 CTriangle tri;
1253 tri.V0.set(x0,y0,0);
1254 tri.V1.set(x1,y1,0);
1255 tri.V2.set(x2,y2,0);
1257 drawTriangle(tri, _MatFlat);
1259 // ***************************************************************************
1260 void CDriverUser::drawQuad (float x0, float y0, float x1, float y1, CRGBA col)
1262 H_AUTO2;
1264 _MatFlat.setColor(col);
1265 _MatFlat.setBlend(true);
1266 _MatFlat.setBlendFunc(UMaterial::srcalpha, UMaterial::invsrcalpha);
1268 CQuad quad;
1269 quad.V0.set(x0,y0,0);
1270 quad.V1.set(x1,y0,0);
1271 quad.V2.set(x1,y1,0);
1272 quad.V3.set(x0,y1,0);
1274 drawQuad(quad, _MatFlat);
1276 // ***************************************************************************
1277 void CDriverUser::drawQuad (float xcenter, float ycenter, float radius, CRGBA col)
1279 H_AUTO2;
1281 drawQuad(xcenter-radius, ycenter-radius, xcenter+radius, ycenter+radius, col);
1283 // ***************************************************************************
1284 void CDriverUser::drawWiredQuad (float x0, float y0, float x1, float y1, CRGBA col)
1286 H_AUTO2;
1288 // v-left
1289 drawLine(x0,y0,x0,y1,col);
1290 // v-right
1291 drawLine(x1,y0,x1,y1,col);
1292 // h-up
1293 drawLine(x0,y1,x1,y1,col);
1294 // h-bottom
1295 drawLine(x0,y0,x1,y0,col);
1297 // ***************************************************************************
1298 void CDriverUser::drawWiredQuad (float xcenter, float ycenter, float radius, CRGBA col)
1300 H_AUTO2;
1302 drawWiredQuad(xcenter-radius, ycenter-radius, xcenter+radius, ycenter+radius, col);
1306 // ***************************************************************************
1307 // ***************************************************************************
1308 // MISC.
1309 // ***************************************************************************
1310 // ***************************************************************************
1313 // ***************************************************************************
1314 UDriver::TMessageBoxId CDriverUser::systemMessageBox (const char* message, const char* title, TMessageBoxType type, TMessageBoxIcon icon)
1317 IDriver::TMessageBoxId dret;
1318 IDriver::TMessageBoxType dtype= (IDriver::TMessageBoxType)(uint32)type;
1319 IDriver::TMessageBoxIcon dicon= (IDriver::TMessageBoxIcon)(uint32)icon;
1320 dret= _Driver->systemMessageBox (message, title, dtype, dicon);
1322 return (UDriver::TMessageBoxId)(uint32)dret;
1326 // ***************************************************************************
1327 CMaterial &CDriverUser::convMat(UMaterial &mat)
1330 return *mat.getObjectPtr();
1334 // ***************************************************************************
1335 void CDriverUser::clearRGBABuffer(CRGBA col)
1337 NL3D_HAUTO_CLEAR_DRIVER;
1339 _Driver->clear2D(col);
1341 // ***************************************************************************
1342 void CDriverUser::clearZBuffer()
1344 NL3D_HAUTO_CLEAR_DRIVER;
1346 _Driver->clearZBuffer();
1348 // ***************************************************************************
1349 void CDriverUser::clearBuffers(CRGBA col)
1351 NL3D_HAUTO_CLEAR_DRIVER;
1353 _Driver->clear2D(col);
1354 _Driver->clearZBuffer();
1355 _Driver->clearStencilBuffer();
1357 // ***************************************************************************
1358 void CDriverUser::swapBuffers()
1360 NL3D_HAUTO_SWAP_DRIVER;
1362 _Driver->swapBuffers();
1363 _RenderTargetManager.cleanup();
1366 // ***************************************************************************
1367 void CDriverUser::finish()
1369 NL3D_HAUTO_SWAP_DRIVER;
1371 _Driver->finish();
1374 // ***************************************************************************
1375 void CDriverUser::flush()
1377 NL3D_HAUTO_SWAP_DRIVER;
1379 _Driver->flush();
1382 // ***************************************************************************
1383 bool CDriverUser::fogEnabled()
1385 NL3D_HAUTO_UI_DRIVER;
1387 return _Driver->fogEnabled();
1389 // ***************************************************************************
1390 void CDriverUser::enableFog(bool enable)
1392 NL3D_HAUTO_UI_DRIVER;
1394 _Driver->enableFog(enable);
1396 // ***************************************************************************
1397 void CDriverUser::setupFog(float start, float end, CRGBA color)
1399 NL3D_HAUTO_UI_DRIVER;
1401 _Driver->setupFog(start, end, color);
1405 // ***************************************************************************
1406 void CDriverUser::setLight (uint8 num, const ULight& light)
1408 NL3D_HAUTO_UI_DRIVER;
1410 CLightUser *plight= (CLightUser*)&light;
1411 _Driver->setLight (num, plight->_Light);
1413 // ***************************************************************************
1414 void CDriverUser::enableLight (uint8 num, bool enable)
1416 NL3D_HAUTO_UI_DRIVER;
1418 _Driver->enableLight (num, enable);
1420 // ***************************************************************************
1421 void CDriverUser::setAmbientColor (CRGBA color)
1423 NL3D_HAUTO_UI_DRIVER;
1425 _Driver->setAmbientColor (color);
1429 // ***************************************************************************
1430 void CDriverUser::setPolygonMode (TPolygonMode mode)
1432 NL3D_HAUTO_UI_DRIVER;
1434 IDriver::TPolygonMode dmode=IDriver::Filled;
1435 switch(mode)
1437 case Filled: dmode= IDriver::Filled; break;
1438 case Line: dmode= IDriver::Line; break;
1439 case Point: dmode= IDriver::Point; break;
1440 default: nlstop;
1442 _Driver->setPolygonMode (dmode);
1444 U3dMouseListener* CDriverUser::create3dMouseListener ()
1446 NL3D_HAUTO_UI_DRIVER;
1448 // Alloc the listener
1449 CEvent3dMouseListener *listener=new CEvent3dMouseListener();
1451 // register it
1452 listener->addToServer (EventServer);
1454 return listener;
1456 void CDriverUser::delete3dMouseListener (U3dMouseListener *listener)
1458 NL3D_HAUTO_UI_DRIVER;
1460 // Unregister
1461 ((CEvent3dMouseListener*)listener)->removeFromServer (EventServer);
1463 delete (CEvent3dMouseListener*)listener;
1465 UDriver::TPolygonMode CDriverUser::getPolygonMode ()
1467 NL3D_HAUTO_UI_DRIVER;
1469 IDriver::TPolygonMode dmode;
1470 UDriver::TPolygonMode umode=UDriver::Filled;
1471 dmode= _Driver->getPolygonMode();
1472 switch(dmode)
1474 case IDriver::Filled: umode= UDriver::Filled; break;
1475 case IDriver::Line: umode= UDriver::Line; break;
1476 case IDriver::Point: umode= UDriver::Point; break;
1477 default: nlstop;
1480 return umode;
1483 void CDriverUser::forceDXTCCompression(bool dxtcComp)
1485 NL3D_HAUTO_UI_DRIVER;
1487 _Driver->forceDXTCCompression(dxtcComp);
1490 void CDriverUser::setAnisotropicFilter(sint filter)
1492 NL3D_HAUTO_UI_DRIVER;
1494 _Driver->setAnisotropicFilter(filter);
1497 uint CDriverUser::getAnisotropicFilter() const
1499 NL3D_HAUTO_UI_DRIVER;
1501 return _Driver->getAnisotropicFilter();
1504 uint CDriverUser::getAnisotropicFilterMaximum() const
1506 NL3D_HAUTO_UI_DRIVER;
1508 return _Driver->getAnisotropicFilterMaximum();
1511 void CDriverUser::forceTextureResize(uint divisor)
1513 NL3D_HAUTO_UI_DRIVER;
1515 _Driver->forceTextureResize(divisor);
1517 bool CDriverUser::setMonitorColorProperties (const CMonitorColorProperties &properties)
1519 NL3D_HAUTO_UI_DRIVER;
1521 return _Driver->setMonitorColorProperties (properties);
1526 // ***************************************************************************
1527 // ***************************************************************************
1528 /// Driver information/Queries
1529 // ***************************************************************************
1530 // ***************************************************************************
1532 uint32 CDriverUser::getImplementationVersion () const
1534 NL3D_HAUTO_UI_DRIVER;
1536 return _Driver->getImplementationVersion ();
1538 const char* CDriverUser::getDriverInformation ()
1540 NL3D_HAUTO_UI_DRIVER;
1542 return _Driver->getDriverInformation();
1544 const char* CDriverUser::getVideocardInformation ()
1546 NL3D_HAUTO_UI_DRIVER;
1548 return _Driver->getVideocardInformation ();
1550 sint CDriverUser::getTotalVideoMemory () const
1552 NL3D_HAUTO_UI_DRIVER;
1554 return _Driver->getTotalVideoMemory ();
1556 uint CDriverUser::getNbTextureStages()
1558 NL3D_HAUTO_UI_DRIVER;
1560 return _Driver->getNbTextureStages();
1562 void CDriverUser::getWindowSize (uint32 &width, uint32 &height)
1564 NL3D_HAUTO_UI_DRIVER;
1566 _Driver->getWindowSize (width, height);
1568 uint CDriverUser::getWindowWidth ()
1570 NL3D_HAUTO_UI_DRIVER;
1572 uint32 width, height;
1573 _Driver->getWindowSize (width, height);
1574 return width;
1576 uint CDriverUser::getWindowHeight ()
1578 NL3D_HAUTO_UI_DRIVER;
1580 uint32 width, height;
1581 _Driver->getWindowSize (width, height);
1582 return height;
1584 void CDriverUser::getWindowPos (sint32 &x, sint32 &y)
1586 NL3D_HAUTO_UI_DRIVER;
1588 _Driver->getWindowPos (x, y);
1590 uint32 CDriverUser::getAvailableVertexAGPMemory ()
1592 return _Driver->getAvailableVertexAGPMemory ();
1594 uint32 CDriverUser::getAvailableVertexVRAMMemory ()
1596 return _Driver->getAvailableVertexVRAMMemory ();
1598 void CDriverUser::getBuffer (CBitmap &bitmap)
1600 NL3D_HAUTO_UI_DRIVER;
1602 _Driver->getBuffer (bitmap) ;
1604 void CDriverUser::getZBuffer (std::vector<float> &zbuffer)
1606 NL3D_HAUTO_UI_DRIVER;
1608 _Driver->getZBuffer (zbuffer) ;
1610 void CDriverUser::getBufferPart (CBitmap &bitmap, NLMISC::CRect &rect)
1612 NL3D_HAUTO_UI_DRIVER;
1614 _Driver->getBufferPart (bitmap, rect) ;
1616 void CDriverUser::getZBufferPart (std::vector<float> &zbuffer, NLMISC::CRect &rect)
1618 NL3D_HAUTO_UI_DRIVER;
1620 _Driver->getZBufferPart (zbuffer, rect) ;
1622 bool CDriverUser::fillBuffer (CBitmap &bitmap)
1624 NL3D_HAUTO_UI_DRIVER;
1626 return _Driver->fillBuffer(bitmap);
1630 // ***************************************************************************
1631 // ***************************************************************************
1632 // Mouse / Keyboards / Game devices
1633 // ***************************************************************************
1634 // ***************************************************************************
1636 void CDriverUser::showCursor (bool b)
1638 NL3D_HAUTO_UI_DRIVER;
1640 _Driver->showCursor(b);
1642 void CDriverUser::setMousePos (float x, float y)
1644 NL3D_HAUTO_UI_DRIVER;
1646 _Driver->setMousePos (x, y);
1648 void CDriverUser::setCapture (bool b)
1650 NL3D_HAUTO_UI_DRIVER;
1652 _Driver->setCapture (b);
1655 bool CDriverUser::isSystemCursorCaptured()
1657 NL3D_HAUTO_UI_DRIVER;
1659 return _Driver->isSystemCursorCaptured();
1662 void CDriverUser::addCursor(const std::string &name, const NLMISC::CBitmap &bitmap)
1664 NL3D_HAUTO_UI_DRIVER;
1666 _Driver->addCursor(name, bitmap);
1669 void CDriverUser::setCursor(const std::string &name, NLMISC::CRGBA col, uint8 rot, sint hotSpotX, sint hotSpotY, bool forceRebuild)
1671 NL3D_HAUTO_UI_DRIVER;
1673 _Driver->setCursor(name, col, rot, hotSpotX, hotSpotY, forceRebuild);
1676 void CDriverUser::setCursorScale(float scale)
1678 NL3D_HAUTO_UI_DRIVER;
1680 _Driver->setCursorScale(scale);
1683 // ***************************************************************************
1684 // ***************************************************************************
1685 // Async Texture loading mgt
1686 // ***************************************************************************
1687 // ***************************************************************************
1690 // ***************************************************************************
1691 void CDriverUser::setupAsyncTextureLod(uint baseLevel, uint maxLevel)
1693 NL3D_HAUTO_TEX_DRIVER;
1695 _AsyncTextureManager.setupLod(baseLevel, maxLevel);
1697 // ***************************************************************************
1698 void CDriverUser::setupAsyncTextureMaxUploadPerFrame(uint maxup)
1700 NL3D_HAUTO_TEX_DRIVER;
1702 _AsyncTextureManager.setupMaxUploadPerFrame(maxup);
1704 // ***************************************************************************
1705 void CDriverUser::updateAsyncTexture()
1707 NL3D_HAUTO_TEX_DRIVER;
1709 _AsyncTextureManager.update(getDriver());
1713 // ***************************************************************************
1714 void CDriverUser::setupMaxTotalAsyncTextureSize(uint maxText)
1716 NL3D_HAUTO_TEX_DRIVER;
1718 _AsyncTextureManager.setupMaxTotalTextureSize(maxText);
1720 // ***************************************************************************
1721 uint CDriverUser::getTotalAsyncTextureSizeAsked() const
1723 NL3D_HAUTO_TEX_DRIVER;
1725 return _AsyncTextureManager.getTotalTextureSizeAsked();
1727 // ***************************************************************************
1728 uint CDriverUser::getLastAsyncTextureSizeGot() const
1730 NL3D_HAUTO_TEX_DRIVER;
1732 return _AsyncTextureManager.getLastTextureSizeGot();
1735 // ***************************************************************************
1736 void CDriverUser::setupMaxHLSColoringPerFrame(uint maxCol)
1738 NL3D_HAUTO_TEX_DRIVER;
1740 _AsyncTextureManager.setupMaxHLSColoringPerFrame(maxCol);
1743 // ***************************************************************************
1744 void CDriverUser::loadHLSBank(const std::string &fileName)
1746 NL3D_HAUTO_TEX_DRIVER;
1748 // load it.
1749 CHLSTextureBank *hlsBank= new CHLSTextureBank;
1752 std::string path= CPath::lookup(fileName);
1753 CIFile fIn;
1754 if(!fIn.open(path))
1755 throw EPathNotFound(path);
1756 fIn.serial(*hlsBank);
1758 catch(const Exception &)
1760 delete hlsBank;
1761 throw;
1764 // add it to the manager.
1765 _AsyncTextureManager.HLSManager.addBank(hlsBank);
1769 // ***************************************************************************
1770 void CDriverUser::setSwapVBLInterval(uint interval)
1772 NL3D_HAUTO_UI_DRIVER
1774 _Driver->setSwapVBLInterval(interval);
1777 // ***************************************************************************
1778 uint CDriverUser::getSwapVBLInterval()
1780 NL3D_HAUTO_UI_DRIVER
1782 return _Driver->getSwapVBLInterval();
1785 // ***************************************************************************
1786 bool CDriverUser::supportMADOperator() const
1788 NL3D_HAUTO_UI_DRIVER
1790 return _Driver->supportMADOperator();
1793 // ***************************************************************************
1794 bool CDriverUser::supportBloomEffect() const
1796 NL3D_HAUTO_UI_DRIVER
1798 return _Driver->supportBloomEffect();
1801 // ***************************************************************************
1803 void CDriverUser::startBench (bool wantStandardDeviation, bool quick, bool reset)
1805 _Driver->startBench (wantStandardDeviation, quick, reset);
1808 // ***************************************************************************
1810 void CDriverUser::endBench ()
1812 _Driver->endBench ();
1815 // ***************************************************************************
1817 void CDriverUser::displayBench (class NLMISC::CLog *log)
1819 _Driver->displayBench (log);
1822 // ***************************************************************************
1823 UWaterEnvMap *CDriverUser::createWaterEnvMap()
1825 CWaterEnvMapUser *wem = new CWaterEnvMapUser;
1826 wem->EnvMap.Driver = this;
1827 return wem;
1830 // ***************************************************************************
1831 void CDriverUser::deleteWaterEnvMap(UWaterEnvMap *map)
1833 delete (CWaterEnvMapUser *) map;
1836 // ***************************************************************************
1837 void CDriverUser::setCullMode(TCullMode cullMode)
1839 NL3D_HAUTO_UI_DRIVER
1840 _Driver->setCullMode((IDriver::TCullMode) cullMode);
1843 // ***************************************************************************
1844 UDriver::TCullMode CDriverUser::getCullMode() const
1846 NL3D_HAUTO_UI_DRIVER
1847 return (TCullMode) _Driver->getCullMode();
1850 // ***************************************************************************
1851 bool CDriverUser::isLost() const
1853 NL3D_HAUTO_UI_DRIVER
1854 return _Driver->isLost();
1857 // ***************************************************************************
1858 void CDriverUser::beginDialogMode()
1860 NL3D_HAUTO_UI_DRIVER
1861 _Driver->beginDialogMode();
1864 // ***************************************************************************
1865 void CDriverUser::endDialogMode()
1867 NL3D_HAUTO_UI_DRIVER
1868 _Driver->endDialogMode();
1871 // ***************************************************************************
1872 void CDriverUser::enableStencilTest(bool enable)
1874 NL3D_HAUTO_UI_DRIVER
1875 _Driver->enableStencilTest(enable);
1878 // ***************************************************************************
1879 bool CDriverUser::isStencilTestEnabled() const
1881 NL3D_HAUTO_UI_DRIVER
1882 return _Driver->isStencilTestEnabled();
1885 // ***************************************************************************
1886 void CDriverUser::stencilFunc(TStencilFunc stencilFunc, int ref, uint mask)
1888 NL3D_HAUTO_UI_DRIVER
1889 _Driver->stencilFunc((IDriver::TStencilFunc)stencilFunc, ref, mask);
1892 // ***************************************************************************
1893 void CDriverUser::stencilOp(TStencilOp fail, TStencilOp zfail, TStencilOp zpass)
1895 NL3D_HAUTO_UI_DRIVER
1896 _Driver->stencilOp((IDriver::TStencilOp)fail, (IDriver::TStencilOp)zfail,
1897 (IDriver::TStencilOp)zpass);
1900 // ***************************************************************************
1901 void CDriverUser::stencilMask(uint mask)
1903 NL3D_HAUTO_UI_DRIVER
1904 _Driver->stencilMask(mask);
1907 // ***************************************************************************
1908 uint64 CDriverUser::getSwapBufferCounter()
1910 NL3D_HAUTO_UI_DRIVER
1911 return _Driver->getSwapBufferCounter();
1914 // ***************************************************************************
1916 bool CDriverUser::stretchRect(UScene * scene, class UTexture & srcUText, NLMISC::CRect &srcRect,
1917 class UTexture & destUText, NLMISC::CRect &destRect)
1919 NL3D_HAUTO_UI_DRIVER
1921 ITexture * srcText = (dynamic_cast<CTextureUser *>(&srcUText))->getITexture();
1922 ITexture * destText = (dynamic_cast<CTextureUser *>(&destUText))->getITexture();
1924 if(!_Driver->stretchRect(srcText, srcRect, destText, destRect))
1926 setRenderTarget(destUText, 0, 0, destRect.Width, destRect.Height);
1928 // init quad
1929 NLMISC::CQuadUV quad;
1930 quad.V0 = CVector(0.f, 0.f, 0.5f);
1931 quad.V1 = CVector(1.f, 0.f, 0.5f);
1932 quad.V2 = CVector(1.f, 1.f, 0.5f);
1933 quad.V3 = CVector(0.f, 1.f, 0.5f);
1934 float newU = _Driver->isTextureRectangle(srcText) ? (float)srcRect.Width : 1.f;
1935 float newV = _Driver->isTextureRectangle(srcText) ? (float)srcRect.Height : 1.f;
1936 quad.Uv0 = CUV(0.0f, 0.0f);
1937 quad.Uv1 = CUV(newU, 0.0f);
1938 quad.Uv2 = CUV(newU, newV);
1939 quad.Uv3 = CUV(0.0f, newV);
1941 // init material
1942 _MatTextStretchInternal.setTexture(0, srcText);
1944 // display
1945 UCamera pCam = scene->getCam();
1946 setMatrixMode2D11();
1947 drawQuad(quad, _MatStretchText);
1948 setMatrixMode3D(pCam);
1950 _MatTextStretchInternal.setTexture(0, NULL);
1951 CTextureUser cu;
1952 setRenderTarget(cu, 0, 0, 0, 0);
1955 return true;
1958 // ***************************************************************************
1959 bool CDriverUser::setRenderTarget(class UTexture & uTex, uint32 x, uint32 y, uint32 width, uint32 height, uint32 mipmapLevel, uint32 cubeFace)
1961 ITexture * tex = (dynamic_cast<CTextureUser *>(&uTex))->getITexture();
1963 if(tex!=NULL)
1965 CTextureUser cu;
1966 setRenderTarget(cu);
1969 bool result = _Driver->setRenderTarget(tex, x, y, width, height, mipmapLevel, cubeFace);
1971 setupMatrixContext();
1973 return result;
1975 bool CDriverUser::copyTextToClipboard(const std::string &text)
1977 return _Driver->copyTextToClipboard(text);
1980 bool CDriverUser::pasteTextFromClipboard(std::string &text)
1982 return _Driver->pasteTextFromClipboard(text);
1985 } // NL3D