Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / src / 3d / landscapevb_info.cpp
blobf5955e6229a632b657410b690bf63b6cd9ba70ca
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/landscapevb_info.h"
20 #include "nel/3d/vertex_buffer.h"
21 #include "nel/3d/landscapevb_allocator.h"
23 #ifdef DEBUG_NEW
24 #define new DEBUG_NEW
25 #endif
27 namespace NL3D
31 // ***************************************************************************
32 // ***************************************************************************
33 // VertexBufferInfo.
34 // ***************************************************************************
35 // ***************************************************************************
38 // ***************************************************************************
39 void CFarVertexBufferInfo::setupNullPointers()
41 Accessor.unlock();
42 VertexCoordPointer= NULL;
43 TexCoordPointer0= NULL;
44 TexCoordPointer1= NULL;
45 ColorPointer= NULL;
46 GeomInfoPointer= NULL;
47 DeltaPosPointer= NULL;
48 AlphaInfoPointer= NULL;
52 // ***************************************************************************
53 void CFarVertexBufferInfo::setupPointersForVertexProgram()
55 // see CLandscapeVBAllocator for program definition.
56 uint8 *vcoord= (uint8*)VertexCoordPointer;
58 TexCoordPointer0= vcoord + TexCoordOff0;
59 TexCoordPointer1= vcoord + TexCoordOff1;
60 GeomInfoPointer= vcoord + GeomInfoOff;
61 DeltaPosPointer= vcoord + DeltaPosOff;
62 AlphaInfoPointer= vcoord + AlphaInfoOff;
66 // ***************************************************************************
67 void CFarVertexBufferInfo::setupVertexBuffer(CVertexBuffer &vb, bool forVertexProgram)
69 VertexFormat= vb.getVertexFormat();
70 VertexSize= vb.getVertexSize();
71 NumVertices= vb.getNumVertices();
73 if(NumVertices==0)
75 setupNullPointers();
76 return;
79 vb.lock (Accessor);
80 VertexCoordPointer = Accessor.getVertexCoordPointer();
82 if(forVertexProgram)
84 // With VertexCoordPointer setuped, init for VP.
85 TexCoordOff0= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_TEX0); // v[8]= Tex0.
86 TexCoordOff1= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_TEX1); // v[9]= Tex1.
87 GeomInfoOff= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_GEOMINFO); // v[10]= GeomInfos.
88 DeltaPosOff= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_DELTAPOS); // v[11]= EndPos-StartPos
89 // Init Alpha Infos only if enabled (enabled if Value 5 are).
90 AlphaInfoOff= 0;
91 if( vb.getVertexFormat() & (1<<NL3D_LANDSCAPE_VPPOS_ALPHAINFO) )
92 AlphaInfoOff= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_ALPHAINFO); // v[12]= AlphaInfos
94 // update Ptrs.
95 setupPointersForVertexProgram();
97 else
99 TexCoordOff0= vb.getTexCoordOff(0);
100 TexCoordOff1= vb.getTexCoordOff(1);
101 TexCoordPointer0= Accessor.getTexCoordPointer(0, 0);
102 TexCoordPointer1= Accessor.getTexCoordPointer(0, 1);
104 // In Far0, we don't have Color component.
105 if(VertexFormat & CVertexBuffer::PrimaryColorFlag)
107 ColorOff= vb.getColorOff();
108 // todo hulud d3d vertex color RGBA / BGRA
109 ColorPointer= Accessor.getColorPointer();
111 else
113 ColorOff= 0;
114 ColorPointer= NULL;
121 // ***************************************************************************
122 void CNearVertexBufferInfo::setupNullPointers()
124 Accessor.unlock();
125 VertexCoordPointer= NULL;
126 TexCoordPointer0= NULL;
127 TexCoordPointer1= NULL;
128 TexCoordPointer2= NULL;
129 GeomInfoPointer= NULL;
130 DeltaPosPointer= NULL;
134 // ***************************************************************************
135 void CNearVertexBufferInfo::setupPointersForVertexProgram()
137 // see CLandscapeVBAllocator for program definition.
138 uint8 *vcoord= (uint8*)VertexCoordPointer;
140 TexCoordPointer0= vcoord + TexCoordOff0;
141 TexCoordPointer1= vcoord + TexCoordOff1;
142 TexCoordPointer2= vcoord + TexCoordOff2;
143 GeomInfoPointer= vcoord + GeomInfoOff;
144 DeltaPosPointer= vcoord + DeltaPosOff;
149 // ***************************************************************************
150 void CNearVertexBufferInfo::setupVertexBuffer(CVertexBuffer &vb, bool forVertexProgram)
152 VertexFormat= vb.getVertexFormat();
153 VertexSize= vb.getVertexSize();
154 NumVertices= vb.getNumVertices();
156 if(NumVertices==0)
158 setupNullPointers();
159 return;
162 vb.lock (Accessor);
163 VertexCoordPointer= Accessor.getVertexCoordPointer();
165 if(forVertexProgram)
167 // With VertexCoordPointer setuped, init for VP.
168 TexCoordOff0= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_TEX0); // v[8]= Tex0.
169 TexCoordOff1= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_TEX1); // v[9]= Tex1.
170 TexCoordOff2= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_TEX2); // v[13]= Tex1.
171 GeomInfoOff= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_GEOMINFO); // v[10]= GeomInfos.
172 DeltaPosOff= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_DELTAPOS); // v[11]= EndPos-StartPos
174 // update Ptrs.
175 setupPointersForVertexProgram();
177 else
179 TexCoordPointer0= Accessor.getTexCoordPointer(0, 0);
180 TexCoordPointer1= Accessor.getTexCoordPointer(0, 1);
181 TexCoordPointer2= Accessor.getTexCoordPointer(0, 2);
183 TexCoordOff0= vb.getTexCoordOff(0);
184 TexCoordOff1= vb.getTexCoordOff(1);
185 TexCoordOff2= vb.getTexCoordOff(2);
190 } // NL3D