Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / 3d / vertex_stream_manager.cpp
blob74d2727dde34384159a7ea9f794bf3c19b50c0a8
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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/>.
17 #include "std3d.h"
19 #include "nel/3d/vertex_stream_manager.h"
20 #include "nel/misc/hierarchical_timer.h"
23 using namespace NLMISC;
25 #ifdef DEBUG_NEW
26 #define new DEBUG_NEW
27 #endif
29 namespace NL3D
34 // ***************************************************************************
35 CVertexStreamManager::CVertexStreamManager()
37 _InitOk= false;
38 _SupportVolatileVB = false;
39 _VertexFormat= 0;
40 _VertexSize= 0;
41 _MaxVertices= 0;
42 _CurentVB= 0;
43 _NumVB= 0;
44 _LockDone = false;
46 // ***************************************************************************
47 CVertexStreamManager::~CVertexStreamManager()
49 release();
52 // ***************************************************************************
53 void CVertexStreamManager::init(IDriver *driver, uint vertexFormat, uint maxVertices, uint numVBHard, const std::string &vbName, bool allowVolatileVertexBuffer /*= false*/)
55 nlassert(driver);
56 // clean before.
57 release();
59 // Create VBHard placeholder
60 if(numVBHard==0 || maxVertices==0)
61 return;
63 _NumVB= numVBHard;
64 _VB.resize(_NumVB);
66 // setup, => correct for possible release below
67 _Driver= driver;
69 // create the VBHard, if possible
70 uint i;
71 for(i=0;i<_NumVB;i++)
73 _VB[i].setVertexFormat(vertexFormat);
75 // For the moment, all UV channel are routed to UV0
76 uint j;
77 for (j=0; j<CVertexBuffer::MaxStage; j++)
78 _VB[i].setUVRouting (j, 0);
80 _VB[i].setNumVertices (maxVertices);
81 _VB[i].setPreferredMemory (CVertexBuffer::AGPPreferred, false);
82 _VB[i].setName(vbName + NLMISC::toString(i));
85 // init misc
86 _InitOk= true;
87 _VertexFormat= _VB[0].getVertexFormat();
88 _VertexSize= _VB[0].getVertexSize();
89 _MaxVertices= maxVertices;
90 _CurentVB= 0;
92 if (driver->supportVolatileVertexBuffer() && allowVolatileVertexBuffer)
94 _VBVolatile.setVertexFormat(vertexFormat);
95 // For the moment, all UV channel are routed to UV0
96 uint j;
97 for (j=0; j<CVertexBuffer::MaxStage; j++)
98 _VBVolatile.setUVRouting (j, 0);
99 _VBVolatile.setNumVertices (maxVertices);
100 _VBVolatile.setPreferredMemory (CVertexBuffer::AGPVolatile, false);
101 _VBVolatile.setName(vbName + "Volatile");
102 _SupportVolatileVB = true;
104 else
106 _SupportVolatileVB = false;
109 // ***************************************************************************
110 void CVertexStreamManager::release()
112 // release driver/VBHard
113 if(_Driver)
114 _Driver= NULL;
116 _VB.clear();
118 // misc
119 _InitOk= false;
120 _VertexFormat= 0;
121 _VertexSize= 0;
122 _MaxVertices= 0;
123 _CurentVB= 0;
124 _NumVB= 0;
126 // ***************************************************************************
127 uint8 *CVertexStreamManager::lock()
129 H_AUTO( NL3D_VertexStreamManager_lock )
130 nlassert(_InitOk);
131 nlassert(!_LockDone);
132 _LockDone = true;
133 if (_SupportVolatileVB)
135 _VBVolatile.lock (_VBA);
136 return (uint8*)_VBA.getVertexCoordPointer();
138 else
140 _VB[_CurentVB].lock (_VBA);
141 return (uint8*)_VBA.getVertexCoordPointer();
144 // ***************************************************************************
145 void CVertexStreamManager::unlock(uint numVertices)
147 H_AUTO( NL3D_VertexStreamManager_unlock )
148 nlassert(_InitOk);
149 nlassert(_LockDone);
150 _VBA.touchVertices (0, numVertices);
151 _VBA.unlock ();
153 // ***************************************************************************
154 void CVertexStreamManager::activate()
156 H_AUTO( NL3D_VertexStreamManager_activate )
157 nlassert(_InitOk);
158 if (_SupportVolatileVB)
160 _Driver->activeVertexBuffer(_VBVolatile);
162 else
164 _Driver->activeVertexBuffer(_VB[_CurentVB]);
167 // ***************************************************************************
168 void CVertexStreamManager::swapVBHard()
170 nlassert(_InitOk);
171 _LockDone = false;
172 if (!_SupportVolatileVB)
174 _CurentVB++;
175 _CurentVB= _CurentVB%_NumVB;
179 // ***************************************************************************
180 bool CVertexStreamManager::isBRGA() const
182 nlassert(_InitOk);
183 nlassert(_LockDone);
184 return _VBA.getParent()->getVertexColorFormat()==CVertexBuffer::TBGRA;
188 } // NL3D