diff options
author | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
commit | 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch) | |
tree | bcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/newview/llvosurfacepatch.cpp | |
parent | Second Life viewer sources 1.13.3.2 (diff) | |
download | meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2 meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz |
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/newview/llvosurfacepatch.cpp')
-rw-r--r-- | linden/indra/newview/llvosurfacepatch.cpp | 280 |
1 files changed, 179 insertions, 101 deletions
diff --git a/linden/indra/newview/llvosurfacepatch.cpp b/linden/indra/newview/llvosurfacepatch.cpp index d49d78c..88e610b 100644 --- a/linden/indra/newview/llvosurfacepatch.cpp +++ b/linden/indra/newview/llvosurfacepatch.cpp | |||
@@ -29,6 +29,8 @@ | |||
29 | 29 | ||
30 | #include "llvosurfacepatch.h" | 30 | #include "llvosurfacepatch.h" |
31 | 31 | ||
32 | #include "lldrawpoolterrain.h" | ||
33 | |||
32 | #include "lldrawable.h" | 34 | #include "lldrawable.h" |
33 | #include "llface.h" | 35 | #include "llface.h" |
34 | #include "llprimitive.h" | 36 | #include "llprimitive.h" |
@@ -41,8 +43,52 @@ | |||
41 | #include "llvovolume.h" | 43 | #include "llvovolume.h" |
42 | #include "pipeline.h" | 44 | #include "pipeline.h" |
43 | 45 | ||
46 | //============================================================================ | ||
47 | |||
48 | class LLVertexBufferTerrain : public LLVertexBuffer | ||
49 | { | ||
50 | public: | ||
51 | LLVertexBufferTerrain() : | ||
52 | LLVertexBuffer(MAP_VERTEX | MAP_NORMAL | MAP_TEXCOORD | MAP_TEXCOORD2 | MAP_COLOR, GL_DYNAMIC_DRAW_ARB) | ||
53 | { | ||
54 | }; | ||
55 | |||
56 | // virtual | ||
57 | void setupVertexBuffer(U32 data_mask) const | ||
58 | { | ||
59 | if (LLDrawPoolTerrain::getDetailMode() == 0) | ||
60 | { | ||
61 | LLVertexBuffer::setupVertexBuffer(data_mask); | ||
62 | } | ||
63 | else if (data_mask & LLVertexBuffer::MAP_TEXCOORD2) | ||
64 | { | ||
65 | U8* base = useVBOs() ? NULL : mMappedData; | ||
66 | |||
67 | glVertexPointer(3,GL_FLOAT, mStride, (void*)(base + 0)); | ||
68 | glNormalPointer(GL_FLOAT, mStride, (void*)(base + mOffsets[TYPE_NORMAL])); | ||
69 | glColorPointer(4, GL_UNSIGNED_BYTE, mStride, (void*)(base + mOffsets[TYPE_COLOR])); | ||
70 | |||
71 | glClientActiveTextureARB(GL_TEXTURE3_ARB); | ||
72 | glTexCoordPointer(2,GL_FLOAT, mStride, (void*)(base + mOffsets[TYPE_TEXCOORD2])); | ||
73 | glClientActiveTextureARB(GL_TEXTURE2_ARB); | ||
74 | glTexCoordPointer(2,GL_FLOAT, mStride, (void*)(base + mOffsets[TYPE_TEXCOORD2])); | ||
75 | glClientActiveTextureARB(GL_TEXTURE1_ARB); | ||
76 | glTexCoordPointer(2,GL_FLOAT, mStride, (void*)(base + mOffsets[TYPE_TEXCOORD2])); | ||
77 | glClientActiveTextureARB(GL_TEXTURE0_ARB); | ||
78 | glTexCoordPointer(2,GL_FLOAT, mStride, (void*)(base + mOffsets[TYPE_TEXCOORD2])); | ||
79 | } | ||
80 | else | ||
81 | { | ||
82 | LLVertexBuffer::setupVertexBuffer(data_mask); | ||
83 | } | ||
84 | llglassertok(); | ||
85 | } | ||
86 | }; | ||
87 | |||
88 | //============================================================================ | ||
89 | |||
44 | LLVOSurfacePatch::LLVOSurfacePatch(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) | 90 | LLVOSurfacePatch::LLVOSurfacePatch(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) |
45 | : LLViewerObject(id, LL_VO_SURFACE_PATCH, regionp) | 91 | : LLStaticViewerObject(id, LL_VO_SURFACE_PATCH, regionp) |
46 | { | 92 | { |
47 | // Terrain must draw during selection passes so it can block objects behind it. | 93 | // Terrain must draw during selection passes so it can block objects behind it. |
48 | mbCanSelect = TRUE; | 94 | mbCanSelect = TRUE; |
@@ -95,9 +141,9 @@ void LLVOSurfacePatch::updateTextures(LLAgent &agent) | |||
95 | } | 141 | } |
96 | 142 | ||
97 | 143 | ||
98 | LLDrawPool *LLVOSurfacePatch::getPool() | 144 | LLFacePool *LLVOSurfacePatch::getPool() |
99 | { | 145 | { |
100 | mPool = gPipeline.getPool(LLDrawPool::POOL_TERRAIN, mPatchp->getSurface()->getSTexture()); | 146 | mPool = (LLDrawPoolTerrain*) gPipeline.getPool(LLDrawPool::POOL_TERRAIN, mPatchp->getSurface()->getSTexture()); |
101 | 147 | ||
102 | return mPool; | 148 | return mPool; |
103 | } | 149 | } |
@@ -125,15 +171,18 @@ LLDrawable *LLVOSurfacePatch::createDrawable(LLPipeline *pipeline) | |||
125 | range = 3; | 171 | range = 3; |
126 | } | 172 | } |
127 | 173 | ||
128 | LLDrawPool *poolp = getPool(); | 174 | LLFacePool *poolp = getPool(); |
129 | 175 | ||
130 | mDrawable->addFace(poolp, NULL); | 176 | mDrawable->addFace(poolp, NULL); |
177 | |||
131 | return mDrawable; | 178 | return mDrawable; |
132 | } | 179 | } |
133 | 180 | ||
134 | 181 | ||
135 | BOOL LLVOSurfacePatch::updateGeometry(LLDrawable *drawable) | 182 | BOOL LLVOSurfacePatch::updateGeometry(LLDrawable *drawable) |
136 | { | 183 | { |
184 | LLFastTimer ftm(LLFastTimer::FTM_UPDATE_TERRAIN); | ||
185 | |||
137 | S32 min_comp, max_comp, range; | 186 | S32 min_comp, max_comp, range; |
138 | min_comp = lltrunc(mPatchp->getMinComposition()); | 187 | min_comp = lltrunc(mPatchp->getMinComposition()); |
139 | max_comp = lltrunc(ceil(mPatchp->getMaxComposition())); | 188 | max_comp = lltrunc(ceil(mPatchp->getMaxComposition())); |
@@ -185,57 +234,63 @@ BOOL LLVOSurfacePatch::updateGeometry(LLDrawable *drawable) | |||
185 | east_stride = render_stride; | 234 | east_stride = render_stride; |
186 | } | 235 | } |
187 | 236 | ||
237 | mLastLength = length; | ||
238 | mLastStride = render_stride; | ||
239 | mLastNorthStride = north_stride; | ||
240 | mLastEastStride = east_stride; | ||
241 | |||
242 | return TRUE; | ||
243 | } | ||
244 | |||
245 | void LLVOSurfacePatch::updateFaceSize(S32 idx) | ||
246 | { | ||
247 | if (idx != 0) | ||
248 | { | ||
249 | llwarns << "Terrain partition requested invalid face!!!" << llendl; | ||
250 | return; | ||
251 | } | ||
252 | |||
253 | LLFace* facep = mDrawable->getFace(idx); | ||
254 | |||
188 | S32 num_vertices = 0; | 255 | S32 num_vertices = 0; |
189 | S32 num_indices = 0; | 256 | S32 num_indices = 0; |
190 | S32 new_north_offset = 0; | 257 | |
191 | S32 new_east_offset = 0; | 258 | if (mLastStride) |
192 | |||
193 | getGeomSizesMain(render_stride, num_vertices, num_indices); | ||
194 | new_north_offset = num_vertices; | ||
195 | getGeomSizesNorth(render_stride, north_stride, num_vertices, num_indices); | ||
196 | new_east_offset = num_vertices; | ||
197 | getGeomSizesEast(render_stride, east_stride, num_vertices, num_indices); | ||
198 | S32 new_num_vertices = num_vertices; | ||
199 | S32 new_num_indices = num_indices; | ||
200 | |||
201 | LLFace *facep = NULL; | ||
202 | |||
203 | // Update the allocated face | ||
204 | LLStrider<LLVector3> verticesp; | ||
205 | LLStrider<LLVector3> normalsp; | ||
206 | LLStrider<LLVector2> texCoords0p; | ||
207 | LLStrider<LLVector2> texCoords1p; | ||
208 | LLStrider<LLColor4U> colorsp; | ||
209 | U32* indicesp = NULL; | ||
210 | S32 index_offset; | ||
211 | |||
212 | facep = mDrawable->getFace(0); | ||
213 | |||
214 | facep->setSize(new_num_vertices, new_num_indices); | ||
215 | facep->setPrimType(LLTriangles); | ||
216 | |||
217 | index_offset = facep->getGeometryTerrain( | ||
218 | verticesp, | ||
219 | normalsp, | ||
220 | colorsp, | ||
221 | texCoords0p, | ||
222 | texCoords1p, | ||
223 | indicesp); | ||
224 | if (-1 == index_offset) | ||
225 | { | 259 | { |
226 | return TRUE; | 260 | getGeomSizesMain(mLastStride, num_vertices, num_indices); |
261 | getGeomSizesNorth(mLastStride, mLastNorthStride, num_vertices, num_indices); | ||
262 | getGeomSizesEast(mLastStride, mLastEastStride, num_vertices, num_indices); | ||
227 | } | 263 | } |
228 | 264 | ||
229 | mDrawable->updateLightSet(); | 265 | facep->setSize(num_vertices, num_indices); |
266 | } | ||
267 | |||
268 | BOOL LLVOSurfacePatch::updateLOD() | ||
269 | { | ||
270 | //mDrawable->updateLightSet(); | ||
271 | mDrawable->setState(LLDrawable::LIGHTING_BUILT); | ||
272 | return TRUE; | ||
273 | } | ||
274 | |||
275 | void LLVOSurfacePatch::getGeometry(LLStrider<LLVector3> &verticesp, | ||
276 | LLStrider<LLVector3> &normalsp, | ||
277 | LLStrider<LLColor4U> &colorsp, | ||
278 | LLStrider<LLVector2> &texCoords0p, | ||
279 | LLStrider<LLVector2> &texCoords1p, | ||
280 | LLStrider<U32> &indicesp) | ||
281 | { | ||
282 | LLFace* facep = mDrawable->getFace(0); | ||
283 | |||
284 | U32 index_offset = facep->getGeomIndex(); | ||
230 | 285 | ||
231 | updateMainGeometry(facep, | 286 | updateMainGeometry(facep, |
232 | verticesp, | 287 | verticesp, |
233 | normalsp, | 288 | normalsp, |
234 | colorsp, | 289 | colorsp, |
235 | texCoords0p, | 290 | texCoords0p, |
236 | texCoords1p, | 291 | texCoords1p, |
237 | indicesp, | 292 | indicesp, |
238 | index_offset); | 293 | index_offset); |
239 | updateNorthGeometry(facep, | 294 | updateNorthGeometry(facep, |
240 | verticesp, | 295 | verticesp, |
241 | normalsp, | 296 | normalsp, |
@@ -252,24 +307,6 @@ BOOL LLVOSurfacePatch::updateGeometry(LLDrawable *drawable) | |||
252 | texCoords1p, | 307 | texCoords1p, |
253 | indicesp, | 308 | indicesp, |
254 | index_offset); | 309 | index_offset); |
255 | |||
256 | if (mLastLength != 0) | ||
257 | { | ||
258 | // lazy, should cache the geom sizes so we know the offsets. | ||
259 | num_vertices = 0; | ||
260 | num_indices = 0; | ||
261 | |||
262 | } | ||
263 | |||
264 | mLastLength = length; | ||
265 | mLastStride = render_stride; | ||
266 | mLastNorthStride = north_stride; | ||
267 | mLastEastStride = east_stride; | ||
268 | |||
269 | mDrawable->setState(LLDrawable::LIGHTING_BUILT); | ||
270 | |||
271 | LLPipeline::sCompiles++; | ||
272 | return TRUE; | ||
273 | } | 310 | } |
274 | 311 | ||
275 | void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, | 312 | void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, |
@@ -278,8 +315,8 @@ void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, | |||
278 | LLStrider<LLColor4U> &colorsp, | 315 | LLStrider<LLColor4U> &colorsp, |
279 | LLStrider<LLVector2> &texCoords0p, | 316 | LLStrider<LLVector2> &texCoords0p, |
280 | LLStrider<LLVector2> &texCoords1p, | 317 | LLStrider<LLVector2> &texCoords1p, |
281 | U32* &indicesp, | 318 | LLStrider<U32> &indicesp, |
282 | S32 &index_offset) | 319 | U32 &index_offset) |
283 | { | 320 | { |
284 | S32 i, j, x, y; | 321 | S32 i, j, x, y; |
285 | 322 | ||
@@ -287,7 +324,7 @@ void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, | |||
287 | S32 num_vertices, num_indices; | 324 | S32 num_vertices, num_indices; |
288 | U32 index; | 325 | U32 index; |
289 | 326 | ||
290 | render_stride = mPatchp->getRenderStride(); | 327 | render_stride = mLastStride; |
291 | patch_size = mPatchp->getSurface()->getGridsPerPatchEdge(); | 328 | patch_size = mPatchp->getSurface()->getGridsPerPatchEdge(); |
292 | S32 vert_size = patch_size / render_stride; | 329 | S32 vert_size = patch_size / render_stride; |
293 | 330 | ||
@@ -383,29 +420,20 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, | |||
383 | LLStrider<LLColor4U> &colorsp, | 420 | LLStrider<LLColor4U> &colorsp, |
384 | LLStrider<LLVector2> &texCoords0p, | 421 | LLStrider<LLVector2> &texCoords0p, |
385 | LLStrider<LLVector2> &texCoords1p, | 422 | LLStrider<LLVector2> &texCoords1p, |
386 | U32* &indicesp, | 423 | LLStrider<U32> &indicesp, |
387 | S32 &index_offset) | 424 | U32 &index_offset) |
388 | { | 425 | { |
389 | S32 vertex_count = 0; | 426 | S32 vertex_count = 0; |
390 | S32 i, x, y; | 427 | S32 i, x, y; |
391 | 428 | ||
392 | S32 num_vertices, num_indices; | 429 | S32 num_vertices, num_indices; |
393 | 430 | ||
394 | U32 render_stride = mPatchp->getRenderStride(); | 431 | U32 render_stride = mLastStride; |
395 | S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge(); | 432 | S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge(); |
396 | S32 length = patch_size / render_stride; | 433 | S32 length = patch_size / render_stride; |
397 | S32 half_length = length / 2; | 434 | S32 half_length = length / 2; |
398 | 435 | U32 north_stride = mLastNorthStride; | |
399 | U32 north_stride; | 436 | |
400 | if (mPatchp->getNeighborPatch(NORTH)) | ||
401 | { | ||
402 | north_stride = mPatchp->getNeighborPatch(NORTH)->getRenderStride(); | ||
403 | } | ||
404 | else | ||
405 | { | ||
406 | north_stride = render_stride; | ||
407 | } | ||
408 | |||
409 | /////////////////////////// | 437 | /////////////////////////// |
410 | // | 438 | // |
411 | // Render the north strip | 439 | // Render the north strip |
@@ -605,27 +633,19 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, | |||
605 | LLStrider<LLColor4U> &colorsp, | 633 | LLStrider<LLColor4U> &colorsp, |
606 | LLStrider<LLVector2> &texCoords0p, | 634 | LLStrider<LLVector2> &texCoords0p, |
607 | LLStrider<LLVector2> &texCoords1p, | 635 | LLStrider<LLVector2> &texCoords1p, |
608 | U32* &indicesp, | 636 | LLStrider<U32> &indicesp, |
609 | S32 &index_offset) | 637 | U32 &index_offset) |
610 | { | 638 | { |
611 | S32 i, x, y; | 639 | S32 i, x, y; |
612 | 640 | ||
613 | S32 num_vertices, num_indices; | 641 | S32 num_vertices, num_indices; |
614 | 642 | ||
615 | U32 render_stride = mPatchp->getRenderStride(); | 643 | U32 render_stride = mLastStride; |
616 | S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge(); | 644 | S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge(); |
617 | S32 length = patch_size / render_stride; | 645 | S32 length = patch_size / render_stride; |
618 | S32 half_length = length / 2; | 646 | S32 half_length = length / 2; |
619 | 647 | ||
620 | U32 east_stride; | 648 | U32 east_stride = mLastEastStride; |
621 | if (mPatchp->getNeighborPatch(EAST)) | ||
622 | { | ||
623 | east_stride = mPatchp->getNeighborPatch(EAST)->getRenderStride(); | ||
624 | } | ||
625 | else | ||
626 | { | ||
627 | east_stride = render_stride; | ||
628 | } | ||
629 | 649 | ||
630 | // Stride lengths are the same | 650 | // Stride lengths are the same |
631 | if (east_stride == render_stride) | 651 | if (east_stride == render_stride) |
@@ -844,10 +864,6 @@ void LLVOSurfacePatch::setPatch(LLSurfacePatch *patchp) | |||
844 | 864 | ||
845 | void LLVOSurfacePatch::dirtyPatch() | 865 | void LLVOSurfacePatch::dirtyPatch() |
846 | { | 866 | { |
847 | if (mDrawable) | ||
848 | { | ||
849 | gPipeline.markMoved(mDrawable); | ||
850 | } | ||
851 | mDirtiedPatch = TRUE; | 867 | mDirtiedPatch = TRUE; |
852 | dirtyGeom(); | 868 | dirtyGeom(); |
853 | mDirtyTerrain = TRUE; | 869 | mDirtyTerrain = TRUE; |
@@ -865,6 +881,8 @@ void LLVOSurfacePatch::dirtyGeom() | |||
865 | if (mDrawable) | 881 | if (mDrawable) |
866 | { | 882 | { |
867 | gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL, TRUE); | 883 | gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL, TRUE); |
884 | mDrawable->getFace(0)->mVertexBuffer = NULL; | ||
885 | mDrawable->movePartition(); | ||
868 | } | 886 | } |
869 | } | 887 | } |
870 | 888 | ||
@@ -937,7 +955,67 @@ void LLVOSurfacePatch::updateSpatialExtents(LLVector3& newMin, LLVector3 &newMax | |||
937 | { | 955 | { |
938 | LLVector3 posAgent = getPositionAgent(); | 956 | LLVector3 posAgent = getPositionAgent(); |
939 | LLVector3 scale = getScale(); | 957 | LLVector3 scale = getScale(); |
940 | newMin = posAgent-scale; | 958 | newMin = posAgent-scale*0.5f; |
941 | newMax = posAgent+scale; | 959 | newMax = posAgent+scale*0.5f; |
942 | mDrawable->setPositionGroup((newMin+newMax)*0.5f); | 960 | mDrawable->setPositionGroup((newMin+newMax)*0.5f); |
943 | } | 961 | } |
962 | |||
963 | U32 LLVOSurfacePatch::getPartitionType() const | ||
964 | { | ||
965 | return LLPipeline::PARTITION_TERRAIN; | ||
966 | } | ||
967 | |||
968 | LLTerrainPartition::LLTerrainPartition() | ||
969 | : LLSpatialPartition(LLDrawPoolTerrain::VERTEX_DATA_MASK) | ||
970 | { | ||
971 | mRenderByGroup = FALSE; | ||
972 | mBufferUsage = GL_DYNAMIC_DRAW_ARB; | ||
973 | mDrawableType = LLPipeline::RENDER_TYPE_TERRAIN; | ||
974 | mPartitionType = LLPipeline::PARTITION_TERRAIN; | ||
975 | } | ||
976 | |||
977 | LLVertexBuffer* LLTerrainPartition::createVertexBuffer(U32 type_mask, U32 usage) | ||
978 | { | ||
979 | return new LLVertexBufferTerrain(); | ||
980 | } | ||
981 | |||
982 | void LLTerrainPartition::getGeometry(LLSpatialGroup* group) | ||
983 | { | ||
984 | LLVertexBuffer* buffer = group->mVertexBuffer; | ||
985 | |||
986 | //get vertex buffer striders | ||
987 | LLStrider<LLVector3> vertices; | ||
988 | LLStrider<LLVector3> normals; | ||
989 | LLStrider<LLVector2> texcoords2; | ||
990 | LLStrider<LLVector2> texcoords; | ||
991 | LLStrider<LLColor4U> colors; | ||
992 | LLStrider<U32> indices; | ||
993 | |||
994 | buffer->getVertexStrider(vertices); | ||
995 | buffer->getNormalStrider(normals); | ||
996 | buffer->getTexCoordStrider(texcoords); | ||
997 | buffer->getTexCoord2Strider(texcoords2); | ||
998 | buffer->getColorStrider(colors); | ||
999 | buffer->getIndexStrider(indices); | ||
1000 | |||
1001 | U32 indices_index = 0; | ||
1002 | U32 index_offset = 0; | ||
1003 | |||
1004 | for (std::vector<LLFace*>::iterator i = mFaceList.begin(); i != mFaceList.end(); ++i) | ||
1005 | { | ||
1006 | LLFace* facep = *i; | ||
1007 | |||
1008 | facep->setIndicesIndex(indices_index); | ||
1009 | facep->setGeomIndex(index_offset); | ||
1010 | facep->mVertexBuffer = buffer; | ||
1011 | |||
1012 | LLVOSurfacePatch* patchp = (LLVOSurfacePatch*) facep->getViewerObject(); | ||
1013 | patchp->getGeometry(vertices, normals, colors, texcoords, texcoords2, indices); | ||
1014 | |||
1015 | indices_index += facep->getIndicesCount(); | ||
1016 | index_offset += facep->getGeomCount(); | ||
1017 | } | ||
1018 | |||
1019 | mFaceList.clear(); | ||
1020 | } | ||
1021 | |||