Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / src / 3d / driver_user2.cpp
blob3383832ad5fd54b764c13db7f08b46216e7cfd59
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) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "std3d.h"
22 // ***************************************************************************
23 // THIS FILE IS DIVIDED IN TWO PARTS BECAUSE IT MAKES VISUAL CRASH.
24 // fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit
25 // ***************************************************************************
27 #include "nel/3d/driver_user.h"
28 #include "nel/3d/scene_user.h"
29 #include "nel/3d/text_context_user.h"
30 #include "nel/3d/u_driver.h"
31 #include "nel/3d/dru.h"
32 #include "nel/3d/scene.h"
33 #include "nel/3d/texture_user.h"
34 #include "nel/3d/u_camera.h"
35 #include "nel/misc/file.h"
36 #include "nel/misc/path.h"
37 #include "nel/misc/hierarchical_timer.h"
40 using namespace std;
41 using namespace NLMISC;
43 #ifdef DEBUG_NEW
44 #define new DEBUG_NEW
45 #endif
47 namespace NL3D
51 // ***************************************************************************
52 // ***************************************************************************
53 // Component Management.
54 // ***************************************************************************
55 // ***************************************************************************
59 // ***************************************************************************
60 UScene *CDriverUser::createScene(bool bSmallScene)
62 CSceneUser *pSU = new CSceneUser(this, bSmallScene);
64 // set the shape bank
65 pSU->getScene().setShapeBank( &_ShapeBank._ShapeBank );
66 // set the MeshSkin Vertex Streams
67 pSU->getScene().getRenderTrav().setMeshSkinManager(&_MeshSkinManager);
68 pSU->getScene().getRenderTrav().setShadowMeshSkinManager(&_ShadowMeshSkinManager);
69 // set the AsyncTextureManager
70 pSU->getScene().setAsyncTextureManager(&_AsyncTextureManager);
71 // set the lodManager
72 pSU->getScene().setLodCharacterManager(&_LodCharacterManager);
73 return _Scenes.insert(pSU);
75 // ***************************************************************************
76 void CDriverUser::deleteScene(UScene *scene)
79 _Scenes.erase((CSceneUser*)scene, "deleteScene(): Bad scene ptr");
82 // ***************************************************************************
84 void CDriverUser::beginDefaultRenderTarget(uint32 width, uint32 height)
86 if (_MatRenderTarget.empty())
88 _MatRenderTarget.attach(&_MatRenderTargetInt);
89 UMaterial &umat = _MatRenderTarget;
90 CMaterial &mat = _MatRenderTargetInt;
91 umat.initUnlit();
92 umat.setColor(CRGBA::White);
93 umat.setBlend(false);
94 umat.setAlphaTest(false);
95 mat.setBlendFunc(CMaterial::one, CMaterial::zero);
96 mat.setZWrite(false);
97 mat.setZFunc(CMaterial::always);
98 mat.setDoubleSided(true);
100 _RenderTargetQuad.V0 = CVector(0.f, 0.f, 0.5f);
101 _RenderTargetQuad.V1 = CVector(1.f, 0.f, 0.5f);
102 _RenderTargetQuad.V2 = CVector(1.f, 1.f, 0.5f);
103 _RenderTargetQuad.V3 = CVector(0.f, 1.f, 0.5f);
104 _RenderTargetQuad.Uv0 = CUV(0.f, 0.f);
105 _RenderTargetQuad.Uv1 = CUV(1.f, 0.f);
106 _RenderTargetQuad.Uv2 = CUV(1.f, 1.f);
107 _RenderTargetQuad.Uv3 = CUV(0.f, 1.f);
110 nlassert(!_EffectRenderTarget);
111 if (width == 0 || height == 0)
112 getWindowSize(width, height);
113 _EffectRenderTarget = getRenderTargetManager().getRenderTarget(width, height);
114 setRenderTarget(*_EffectRenderTarget);
117 // ***************************************************************************
119 void CDriverUser::endDefaultRenderTarget(UScene *scene)
121 nlassert(_EffectRenderTarget);
123 CTextureUser texNull;
124 setRenderTarget(texNull);
126 _MatRenderTarget.getObjectPtr()->setTexture(0, _EffectRenderTarget->getITexture());
128 UCamera pCam;
129 if (scene)
131 pCam = scene->getCam();
133 CViewport oldVp = getViewport();
134 CViewport vp = CViewport();
135 setViewport(vp);
136 setMatrixMode2D11();
137 bool fog = fogEnabled();
138 enableFog(false);
139 drawQuad(_RenderTargetQuad, _MatRenderTarget);
140 enableFog(fog);
141 setViewport(oldVp);
142 if (scene)
144 setMatrixMode3D(pCam);
147 _MatRenderTarget.getObjectPtr()->setTexture(0, NULL);
149 getRenderTargetManager().recycleRenderTarget(_EffectRenderTarget);
150 _EffectRenderTarget = NULL;
153 // ***************************************************************************
154 UTextContext *CDriverUser::createTextContext(const std::string fontFileName, const std::string fontExFileName)
157 return _TextContexts.insert(new CTextContextUser(fontFileName, fontExFileName, this, &_FontManager));
159 // ***************************************************************************
160 void CDriverUser::deleteTextContext(UTextContext *textContext)
163 _TextContexts.erase((CTextContextUser*)textContext, "deleteTextContext: Bad TextContext");
165 // ***************************************************************************
166 void CDriverUser::setFontManagerMaxMemory(uint maxMem)
169 _FontManager.setMaxMemory(maxMem);
171 // ***************************************************************************
172 std::string CDriverUser::getFontManagerCacheInformation() const
175 return _FontManager.getCacheInformation();
178 // ***************************************************************************
179 UTextureFile *CDriverUser::createTextureFile(const std::string &file)
182 CTextureFileUser *text= new CTextureFileUser(file);
183 _Textures.insert(text);
184 return text;
186 // ***************************************************************************
187 void CDriverUser::deleteTextureFile(UTextureFile *textfile)
190 _Textures.erase(dynamic_cast<CTextureFileUser*>(textfile), "deleteTextureFile: Bad textfile");
192 // ***************************************************************************
193 UTextureMem *CDriverUser::createTextureMem(uint width, uint height, CBitmap::TType texType)
196 CTextureMemUser *pTx= new CTextureMemUser(width, height, texType);
197 _Textures.insert(pTx);
198 return pTx;
200 // ***************************************************************************
201 void CDriverUser::deleteTextureMem(UTextureMem *pTx)
204 _Textures.erase(dynamic_cast<CTextureMemUser*>(pTx), "deleteTextureMem: Bad pTx");
206 // ***************************************************************************
207 UMaterial CDriverUser::createMaterial()
210 return UMaterial(new CMaterial);
212 // ***************************************************************************
213 void CDriverUser::deleteMaterial(UMaterial &umat)
215 delete umat.getObjectPtr();
216 umat.detach();
219 // ***************************************************************************
220 UAnimationSet *CDriverUser::createAnimationSet(bool headerOptim)
222 return _AnimationSets.insert(new CAnimationSetUser(this, headerOptim));
225 // ***************************************************************************
226 UAnimationSet *CDriverUser::createAnimationSet(const std::string &animationSetFile)
228 H_AUTO( NL3D_Load_AnimationSet )
230 NLMISC::CIFile f;
231 // throw exception if not found.
232 std::string path= CPath::lookup(animationSetFile);
233 f.open(path);
234 return _AnimationSets.insert(new CAnimationSetUser(this, f));
237 // ***************************************************************************
238 void CDriverUser::deleteAnimationSet(UAnimationSet *animationSet)
240 _AnimationSets.erase((CAnimationSetUser*)animationSet, "deleteAnimationSet(): Bad AnimationSet ptr");
245 // ***************************************************************************
246 // ***************************************************************************
247 // Profile.
248 // ***************************************************************************
249 // ***************************************************************************
252 // ***************************************************************************
253 void CDriverUser::profileRenderedPrimitives(CPrimitiveProfile &pIn, CPrimitiveProfile &pOut)
256 _Driver->profileRenderedPrimitives(pIn, pOut);
260 // ***************************************************************************
261 uint32 CDriverUser::profileAllocatedTextureMemory()
264 return _Driver->profileAllocatedTextureMemory();
268 // ***************************************************************************
269 uint32 CDriverUser::profileSetupedMaterials() const
272 return _Driver->profileSetupedMaterials();
276 // ***************************************************************************
277 uint32 CDriverUser::profileSetupedModelMatrix() const
279 return _Driver->profileSetupedModelMatrix();
283 // ***************************************************************************
284 void CDriverUser::enableUsedTextureMemorySum (bool enable)
286 _Driver->enableUsedTextureMemorySum (enable);
290 // ***************************************************************************
291 uint32 CDriverUser::getUsedTextureMemory () const
293 return _Driver->getUsedTextureMemory ();
297 // ***************************************************************************
298 void CDriverUser::startProfileVBHardLock()
300 _Driver->startProfileVBHardLock();
303 // ***************************************************************************
304 void CDriverUser::endProfileVBHardLock(std::vector<std::string> &result)
306 _Driver->endProfileVBHardLock(result);
309 // ***************************************************************************
310 void CDriverUser::profileVBHardAllocation(std::vector<std::string> &result)
312 _Driver->profileVBHardAllocation(result);
315 // ***************************************************************************
316 void CDriverUser::startProfileIBLock()
318 _Driver->startProfileIBLock();
321 // ***************************************************************************
322 void CDriverUser::endProfileIBLock(std::vector<std::string> &result)
324 _Driver->endProfileIBLock(result);
327 // ***************************************************************************
328 void CDriverUser::profileIBAllocation(std::vector<std::string> &result)
330 _Driver->profileIBAllocation(result);
334 // ***************************************************************************
335 void CDriverUser::profileTextureUsage(std::vector<std::string> &result)
337 _Driver->profileTextureUsage(result);
342 } // NL3D