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/3d/vertex_stream_manager.h"
20 #include "nel/misc/hierarchical_timer.h"
23 using namespace NLMISC
;
34 // ***************************************************************************
35 CVertexStreamManager::CVertexStreamManager()
38 _SupportVolatileVB
= false;
46 // ***************************************************************************
47 CVertexStreamManager::~CVertexStreamManager()
52 // ***************************************************************************
53 void CVertexStreamManager::init(IDriver
*driver
, uint vertexFormat
, uint maxVertices
, uint numVBHard
, const std::string
&vbName
, bool allowVolatileVertexBuffer
/*= false*/)
59 // Create VBHard placeholder
60 if(numVBHard
==0 || maxVertices
==0)
66 // setup, => correct for possible release below
69 // create the VBHard, if possible
73 _VB
[i
].setVertexFormat(vertexFormat
);
75 // For the moment, all UV channel are routed to UV0
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
));
87 _VertexFormat
= _VB
[0].getVertexFormat();
88 _VertexSize
= _VB
[0].getVertexSize();
89 _MaxVertices
= maxVertices
;
92 if (driver
->supportVolatileVertexBuffer() && allowVolatileVertexBuffer
)
94 _VBVolatile
.setVertexFormat(vertexFormat
);
95 // For the moment, all UV channel are routed to UV0
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;
106 _SupportVolatileVB
= false;
109 // ***************************************************************************
110 void CVertexStreamManager::release()
112 // release driver/VBHard
126 // ***************************************************************************
127 uint8
*CVertexStreamManager::lock()
129 H_AUTO( NL3D_VertexStreamManager_lock
)
131 nlassert(!_LockDone
);
133 if (_SupportVolatileVB
)
135 _VBVolatile
.lock (_VBA
);
136 return (uint8
*)_VBA
.getVertexCoordPointer();
140 _VB
[_CurentVB
].lock (_VBA
);
141 return (uint8
*)_VBA
.getVertexCoordPointer();
144 // ***************************************************************************
145 void CVertexStreamManager::unlock(uint numVertices
)
147 H_AUTO( NL3D_VertexStreamManager_unlock
)
150 _VBA
.touchVertices (0, numVertices
);
153 // ***************************************************************************
154 void CVertexStreamManager::activate()
156 H_AUTO( NL3D_VertexStreamManager_activate
)
158 if (_SupportVolatileVB
)
160 _Driver
->activeVertexBuffer(_VBVolatile
);
164 _Driver
->activeVertexBuffer(_VB
[_CurentVB
]);
167 // ***************************************************************************
168 void CVertexStreamManager::swapVBHard()
172 if (!_SupportVolatileVB
)
175 _CurentVB
= _CurentVB
%_NumVB
;
179 // ***************************************************************************
180 bool CVertexStreamManager::isBRGA() const
184 return _VBA
.getParent()->getVertexColorFormat()==CVertexBuffer::TBGRA
;