1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "nel/misc/path.h"
20 #include "nel/misc/file.h"
22 #include "nel/3d/nelu.h"
23 #include "nel/3d/dru.h"
24 #include "nel/3d/camera.h"
25 #include "nel/3d/register_3d.h"
26 #include "nel/3d/init_3d.h"
27 #include "nel/3d/vertex_stream_manager.h"
28 #include "nel/misc/debug.h"
31 using namespace NLMISC
;
40 const float CNELU::DefLx
=0.26f
;
41 const float CNELU::DefLy
=0.2f
;
42 const float CNELU::DefLzNear
=0.15f
;
43 const float CNELU::DefLzFar
=1000.0f
;
45 IDriver
*CNELU::Driver
=NULL
;
46 CScene
*CNELU::Scene
=NULL
;
47 CShapeBank
*CNELU::ShapeBank
=NULL
;
48 CVertexStreamManager
*CNELU::MeshSkinManager
=NULL
;
49 CRefPtr
<CCamera
> CNELU::Camera
;
50 CEventServer
CNELU::EventServer
;
51 CEventListenerAsync
CNELU::AsyncListener
;
54 bool CNELU::initDriver (uint w
, uint h
, uint bpp
, bool windowed
, nlWindow systemWindow
, bool offscreen
, bool direct3d
)
57 // NLMISC::InitDebug();
59 ShapeBank
= new CShapeBank
;
67 CNELU::Driver
= CDRU::createD3DDriver();
73 CNELU::Driver
= CDRU::createGlDriver();
78 nlwarning ("CNELU::initDriver: no driver found");
82 if (!CNELU::Driver
->init())
84 nlwarning ("CNELU::initDriver: init() failed");
87 if (!CNELU::Driver
->setDisplay(systemWindow
, GfxMode(uint16(w
), uint16(h
), uint8(bpp
), windowed
, offscreen
)))
89 nlwarning ("CNELU::initDriver: setDisplay() failed");
92 if (!CNELU::Driver
->activate())
94 nlwarning ("CNELU::initDriver: activate() failed");
98 // Create a skin manager
99 MeshSkinManager
= new CVertexStreamManager
;
105 void CNELU::initScene(CViewport viewport
)
107 // Register basic csene.
108 CScene::registerBasics();
110 if (CNELU::Scene
== NULL
)
111 CNELU::Scene
= new CScene(false);
113 // init default Roots.
114 CNELU::Scene
->initDefaultRoots();
117 CNELU::Scene
->setDriver(CNELU::Driver
);
120 CNELU::Scene
->setViewport (viewport
);
122 // init QuadGridClipManager
123 CNELU::Scene
->initQuadGridClipManager ();
125 // Create/link a camera.
126 CNELU::Camera
= (CCamera
*)CNELU::Scene
->createModel(NL3D::CameraId
);
127 CNELU::Scene
->setCam(CNELU::Camera
);
128 CNELU::Camera
->setFrustum(DefLx
, DefLy
, DefLzNear
, DefLzFar
);
130 // Link to the shape bank
131 CNELU::Scene
->setShapeBank(CNELU::ShapeBank
);
133 // set the MeshSkin Vertex Streams
134 CNELU::Scene
->getRenderTrav().setMeshSkinManager(MeshSkinManager
);
138 void CNELU::initEventServer()
140 CNELU::AsyncListener
.reset ();
141 CNELU::EventServer
.addEmitter(CNELU::Driver
->getEventEmitter());
142 CNELU::AsyncListener
.addToServer(CNELU::EventServer
);
146 void CNELU::releaseEventServer()
148 CNELU::AsyncListener
.removeFromServer(CNELU::EventServer
);
149 if (CNELU::Driver
!= NULL
)
151 CNELU::EventServer
.removeEmitter(CNELU::Driver
->getEventEmitter());
156 void CNELU::releaseScene()
158 // Release the camera.
161 // "Release" the Scene.
162 CNELU::Scene
->setDriver(NULL
);
163 CNELU::Scene
->release();
167 void CNELU::releaseDriver()
170 delete MeshSkinManager
;
172 // "Release" the driver.
173 if (CNELU::Driver
!= NULL
)
175 CNELU::Driver
->release();
176 delete CNELU::Driver
;
177 CNELU::Driver
= NULL
;
179 if( CNELU::ShapeBank
!= NULL
)
181 delete CNELU::ShapeBank
;
182 CNELU::ShapeBank
= NULL
;
186 bool CNELU::init (uint w
, uint h
, CViewport viewport
, uint bpp
, bool windowed
, nlWindow systemWindow
, bool offscreen
, bool direct3d
)
188 NL3D::registerSerial3d();
189 if (initDriver(w
,h
,bpp
,windowed
,systemWindow
,offscreen
,direct3d
))
199 void CNELU::release()
201 releaseEventServer();
206 void CNELU::screenshot()
208 if (AsyncListener
.isKeyPushed(KeyF12
))
211 CNELU::Driver
->getBuffer(btm
);
212 string filename
= CFile::findNewFile ("screenshot.tga");
214 btm
.writeTGA (fs
,24);
215 nlinfo("Screenshot '%s' saved", filename
.c_str());
220 void CNELU::clearBuffers(CRGBA col
)
222 CNELU::Driver
->clear2D(col
);
223 CNELU::Driver
->clearZBuffer();
226 void CNELU::swapBuffers()
228 CNELU::Driver
->swapBuffers();