Change Encyclo button name and macros icon
[ryzomcore.git] / nel / src / 3d / vertex_buffer_heap.cpp
blobe6dd574b0d5055a00a904a85e95470fabf8e49c3
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) 2019 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 #include "nel/3d/vertex_buffer_heap.h"
23 #include "nel/misc/common.h"
25 using namespace NLMISC;
27 #ifdef DEBUG_NEW
28 #define new DEBUG_NEW
29 #endif
31 void vertex_buffer_heap_dummy_cpp() { }
33 // This code is not used actually and doesn't compile
34 // just preproc comment it
35 #if 0
37 namespace NL3D
40 // ***************************************************************************
41 CVertexBufferHeap::CVertexBufferHeap()
43 _Enabled= false;
44 _HardMode= false;
46 _HeapStart= NULL;
47 _VertexFormat= 0;
48 _VertexSize= 0;
49 _MaxVertices= 0;
52 // ***************************************************************************
53 CVertexBufferHeap::~CVertexBufferHeap()
55 release();
58 // ***************************************************************************
59 void CVertexBufferHeap::init(IDriver *driver, uint vertexFormat, uint maxVertices)
61 nlassert(driver);
62 // clean before.
63 release();
65 // setup
66 _Driver= driver;
68 // setup the vertexBuffer soft with queried info.
69 _VBSoft.setVertexFormat(vertexFormat);
70 // VertexSize must be a multitple of 4 (Heap alignement ...)
71 nlassert( (_VBSoft.getVertexSize()&3) == 0);
73 // create the VBHard, if possible
74 _VBHard= driver->createVertexBufferHard(_VBSoft.getVertexFormat(), _VBSoft.getValueTypePointer(), maxVertices, IDriver::VBHardAGP, _VBSoft.getUVRouting());
76 // Ok
77 _Enabled= true;
78 _VertexFormat= _VBSoft.getVertexFormat();
79 _VertexSize= _VBSoft.getVertexSize();
80 _MaxVertices= maxVertices;
82 // Use hard or soft ???
83 if(_VBHard)
85 _HardMode= true;
86 // setup heap start with good AGP ptr.
87 _HeapStart= (uint8*)_VBHard->lock();
88 // just a gestion lock, no vertices have changed.
89 _VBHard->unlock(0,0);
90 // In essence, the VBHeap is rarely modified (but on mesh loading). => set it static
91 _VBHard->lockHintStatic(true);
93 else
95 _HardMode= false;
96 // => allocate soft one.
97 _VBSoft.setNumVertices(maxVertices);
98 // setup heap start with good ptr.
99 _HeapStart= (uint8*)_VBSoft.getVertexCoordPointer();
102 // setup heap Manager with good ptr.
103 _HeapManager.initHeap(_HeapStart, _MaxVertices*_VertexSize);
105 // ***************************************************************************
106 void CVertexBufferHeap::release()
108 if(_VBHard)
110 nlassert(_Driver);
111 _Driver->deleteVertexBufferHard(_VBHard);
113 _VBHard= NULL;
114 _Driver= NULL;
115 _HeapStart= NULL;
116 // release all memory
117 contReset(_VBSoft);
118 contReset(_HeapManager);
120 _Enabled= false;
121 _HardMode= false;
122 _VertexFormat= 0;
123 _VertexSize= 0;
124 _MaxVertices= 0;
127 // ***************************************************************************
128 bool CVertexBufferHeap::allocate(uint numVertices, uint &indexStart)
130 nlassert(enabled());
132 // allocate into the heap ?
133 uint8 *ptr= (uint8*)_HeapManager.allocate(numVertices*getVertexSize());
134 if(!ptr)
135 return false;
136 else
138 // compute vertex index
139 indexStart= (uint)(ptr-_HeapStart);
140 indexStart/= _VertexSize;
141 return true;
144 // ***************************************************************************
145 void CVertexBufferHeap::free(uint indexStart)
147 nlassert(enabled());
149 // compute ptr to free
150 uint8 *ptr= _HeapStart + indexStart*_VertexSize;
151 // free it.
152 _HeapManager.free(ptr);
155 // ***************************************************************************
156 uint8 *CVertexBufferHeap::lock(uint indexStart)
158 nlassert(enabled());
160 uint8 *ptr;
161 if(_HardMode)
163 // lock the vbHard
164 ptr= (uint8*)_VBHard->lock();
165 nlassert(ptr==_HeapStart);
167 else
168 ptr= _HeapStart;
170 // index it with index
171 return ptr + indexStart*_VertexSize;
173 // ***************************************************************************
174 void CVertexBufferHeap::unlock(uint startVert, uint endVert)
176 nlassert(enabled());
178 if(_HardMode)
179 _VBHard->unlock(startVert, endVert);
181 // ***************************************************************************
182 void CVertexBufferHeap::activate()
184 nlassert(enabled());
186 if(_HardMode)
187 _Driver->activeVertexBufferHard(_VBHard);
188 else
189 _Driver->activeVertexBuffer(_VBSoft);
193 } // NL3D
195 #endif // 0