diff options
Diffstat (limited to 'linden/indra/newview/llspatialpartition.cpp')
-rw-r--r-- | linden/indra/newview/llspatialpartition.cpp | 87 |
1 files changed, 57 insertions, 30 deletions
diff --git a/linden/indra/newview/llspatialpartition.cpp b/linden/indra/newview/llspatialpartition.cpp index 9f5d115..127fca2 100644 --- a/linden/indra/newview/llspatialpartition.cpp +++ b/linden/indra/newview/llspatialpartition.cpp | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * $LicenseInfo:firstyear=2003&license=viewergpl$ | 5 | * $LicenseInfo:firstyear=2003&license=viewergpl$ |
6 | * | 6 | * |
7 | * Copyright (c) 2003-2008, Linden Research, Inc. | 7 | * Copyright (c) 2003-2009, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | 9 | * Second Life Viewer Source Code |
10 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * The source code in this file ("Source Code") is provided by Linden Lab |
@@ -46,6 +46,7 @@ | |||
46 | #include "pipeline.h" | 46 | #include "pipeline.h" |
47 | #include "llrender.h" | 47 | #include "llrender.h" |
48 | #include "lloctree.h" | 48 | #include "lloctree.h" |
49 | #include "llvoavatar.h" | ||
49 | 50 | ||
50 | const F32 SG_OCCLUSION_FUDGE = 1.01f; | 51 | const F32 SG_OCCLUSION_FUDGE = 1.01f; |
51 | #define SG_DISCARD_TOLERANCE 0.01f | 52 | #define SG_DISCARD_TOLERANCE 0.01f |
@@ -117,10 +118,14 @@ void validate_drawable(LLDrawable* drawablep) | |||
117 | 118 | ||
118 | S32 AABBSphereIntersect(const LLVector3& min, const LLVector3& max, const LLVector3 &origin, const F32 &rad) | 119 | S32 AABBSphereIntersect(const LLVector3& min, const LLVector3& max, const LLVector3 &origin, const F32 &rad) |
119 | { | 120 | { |
121 | return AABBSphereIntersectR2(min, max, origin, rad*rad); | ||
122 | } | ||
123 | |||
124 | S32 AABBSphereIntersectR2(const LLVector3& min, const LLVector3& max, const LLVector3 &origin, const F32 &r) | ||
125 | { | ||
120 | F32 d = 0.f; | 126 | F32 d = 0.f; |
121 | F32 t; | 127 | F32 t; |
122 | F32 r = rad*rad; | 128 | |
123 | |||
124 | if ((min-origin).magVecSquared() < r && | 129 | if ((min-origin).magVecSquared() < r && |
125 | (max-origin).magVecSquared() < r) | 130 | (max-origin).magVecSquared() < r) |
126 | { | 131 | { |
@@ -1624,7 +1629,7 @@ public: | |||
1624 | 1629 | ||
1625 | void drawBox(const LLVector3& c, const LLVector3& r) | 1630 | void drawBox(const LLVector3& c, const LLVector3& r) |
1626 | { | 1631 | { |
1627 | gGL.begin(LLVertexBuffer::TRIANGLE_STRIP); | 1632 | gGL.begin(LLRender::TRIANGLE_STRIP); |
1628 | //left front | 1633 | //left front |
1629 | gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,-1))).mV); | 1634 | gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,-1))).mV); |
1630 | gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,1))).mV); | 1635 | gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,1))).mV); |
@@ -1643,7 +1648,7 @@ void drawBox(const LLVector3& c, const LLVector3& r) | |||
1643 | gGL.end(); | 1648 | gGL.end(); |
1644 | 1649 | ||
1645 | //bottom | 1650 | //bottom |
1646 | gGL.begin(LLVertexBuffer::TRIANGLE_STRIP); | 1651 | gGL.begin(LLRender::TRIANGLE_STRIP); |
1647 | gGL.vertex3fv((c+r.scaledVec(LLVector3(1,1,-1))).mV); | 1652 | gGL.vertex3fv((c+r.scaledVec(LLVector3(1,1,-1))).mV); |
1648 | gGL.vertex3fv((c+r.scaledVec(LLVector3(1,-1,-1))).mV); | 1653 | gGL.vertex3fv((c+r.scaledVec(LLVector3(1,-1,-1))).mV); |
1649 | gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,-1))).mV); | 1654 | gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,-1))).mV); |
@@ -1651,7 +1656,7 @@ void drawBox(const LLVector3& c, const LLVector3& r) | |||
1651 | gGL.end(); | 1656 | gGL.end(); |
1652 | 1657 | ||
1653 | //top | 1658 | //top |
1654 | gGL.begin(LLVertexBuffer::TRIANGLE_STRIP); | 1659 | gGL.begin(LLRender::TRIANGLE_STRIP); |
1655 | gGL.vertex3fv((c+r.scaledVec(LLVector3(1,1,1))).mV); | 1660 | gGL.vertex3fv((c+r.scaledVec(LLVector3(1,1,1))).mV); |
1656 | gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,1))).mV); | 1661 | gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,1))).mV); |
1657 | gGL.vertex3fv((c+r.scaledVec(LLVector3(1,-1,1))).mV); | 1662 | gGL.vertex3fv((c+r.scaledVec(LLVector3(1,-1,1))).mV); |
@@ -1666,7 +1671,7 @@ void drawBoxOutline(const LLVector3& pos, const LLVector3& size) | |||
1666 | LLVector3 v3 = size.scaledVec(LLVector3(-1,-1,1)); | 1671 | LLVector3 v3 = size.scaledVec(LLVector3(-1,-1,1)); |
1667 | LLVector3 v4 = size.scaledVec(LLVector3( 1,-1,1)); | 1672 | LLVector3 v4 = size.scaledVec(LLVector3( 1,-1,1)); |
1668 | 1673 | ||
1669 | gGL.begin(LLVertexBuffer::LINES); | 1674 | gGL.begin(LLRender::LINES); |
1670 | 1675 | ||
1671 | //top | 1676 | //top |
1672 | gGL.vertex3fv((pos+v1).mV); | 1677 | gGL.vertex3fv((pos+v1).mV); |
@@ -1814,7 +1819,7 @@ void pushVerts(LLDrawInfo* params, U32 mask) | |||
1814 | { | 1819 | { |
1815 | LLRenderPass::applyModelMatrix(*params); | 1820 | LLRenderPass::applyModelMatrix(*params); |
1816 | params->mVertexBuffer->setBuffer(mask); | 1821 | params->mVertexBuffer->setBuffer(mask); |
1817 | params->mVertexBuffer->drawRange(params->mParticle ? LLVertexBuffer::POINTS : LLVertexBuffer::TRIANGLES, | 1822 | params->mVertexBuffer->drawRange(params->mParticle ? LLRender::POINTS : LLRender::TRIANGLES, |
1818 | params->mStart, params->mEnd, params->mCount, params->mOffset); | 1823 | params->mStart, params->mEnd, params->mCount, params->mOffset); |
1819 | } | 1824 | } |
1820 | 1825 | ||
@@ -1843,7 +1848,7 @@ void pushVerts(LLFace* face, U32 mask) | |||
1843 | U16 end = start + face->getGeomCount()-1; | 1848 | U16 end = start + face->getGeomCount()-1; |
1844 | U32 count = face->getIndicesCount(); | 1849 | U32 count = face->getIndicesCount(); |
1845 | U16 offset = face->getIndicesStart(); | 1850 | U16 offset = face->getIndicesStart(); |
1846 | buffer->drawRange(LLVertexBuffer::TRIANGLES, start, end, count, offset); | 1851 | buffer->drawRange(LLRender::TRIANGLES, start, end, count, offset); |
1847 | } | 1852 | } |
1848 | 1853 | ||
1849 | } | 1854 | } |
@@ -1853,7 +1858,7 @@ void pushBufferVerts(LLVertexBuffer* buffer, U32 mask) | |||
1853 | if (buffer) | 1858 | if (buffer) |
1854 | { | 1859 | { |
1855 | buffer->setBuffer(mask); | 1860 | buffer->setBuffer(mask); |
1856 | buffer->drawRange(LLVertexBuffer::TRIANGLES, 0, buffer->getRequestedVerts()-1, buffer->getRequestedIndices(), 0); | 1861 | buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getRequestedVerts()-1, buffer->getRequestedIndices(), 0); |
1857 | } | 1862 | } |
1858 | } | 1863 | } |
1859 | 1864 | ||
@@ -1902,7 +1907,7 @@ void pushVertsColorCoded(LLSpatialGroup* group, U32 mask) | |||
1902 | LLRenderPass::applyModelMatrix(*params); | 1907 | LLRenderPass::applyModelMatrix(*params); |
1903 | glColor4f(colors[col].mV[0], colors[col].mV[1], colors[col].mV[2], 0.5f); | 1908 | glColor4f(colors[col].mV[0], colors[col].mV[1], colors[col].mV[2], 0.5f); |
1904 | params->mVertexBuffer->setBuffer(mask); | 1909 | params->mVertexBuffer->setBuffer(mask); |
1905 | params->mVertexBuffer->drawRange(params->mParticle ? LLVertexBuffer::POINTS : LLVertexBuffer::TRIANGLES, | 1910 | params->mVertexBuffer->drawRange(params->mParticle ? LLRender::POINTS : LLRender::TRIANGLES, |
1906 | params->mStart, params->mEnd, params->mCount, params->mOffset); | 1911 | params->mStart, params->mEnd, params->mCount, params->mOffset); |
1907 | col = (col+1)%col_count; | 1912 | col = (col+1)%col_count; |
1908 | } | 1913 | } |
@@ -1972,7 +1977,7 @@ void renderOctree(LLSpatialGroup* group) | |||
1972 | face->mVertexBuffer->setBuffer(LLVertexBuffer::MAP_VERTEX); | 1977 | face->mVertexBuffer->setBuffer(LLVertexBuffer::MAP_VERTEX); |
1973 | //drawBox((face->mExtents[0] + face->mExtents[1])*0.5f, | 1978 | //drawBox((face->mExtents[0] + face->mExtents[1])*0.5f, |
1974 | // (face->mExtents[1]-face->mExtents[0])*0.5f); | 1979 | // (face->mExtents[1]-face->mExtents[0])*0.5f); |
1975 | face->mVertexBuffer->draw(LLVertexBuffer::TRIANGLES, face->getIndicesCount(), face->getIndicesStart()); | 1980 | face->mVertexBuffer->draw(LLRender::TRIANGLES, face->getIndicesCount(), face->getIndicesStart()); |
1976 | } | 1981 | } |
1977 | } | 1982 | } |
1978 | 1983 | ||
@@ -2103,6 +2108,7 @@ void renderBoundingBox(LLDrawable* drawable) | |||
2103 | gGL.color4f(0.5f,0.5f,0.5f,1.0f); | 2108 | gGL.color4f(0.5f,0.5f,0.5f,1.0f); |
2104 | break; | 2109 | break; |
2105 | case LLViewerObject::LL_VO_PART_GROUP: | 2110 | case LLViewerObject::LL_VO_PART_GROUP: |
2111 | case LLViewerObject::LL_VO_HUD_PART_GROUP: | ||
2106 | gGL.color4f(0,0,1,1); | 2112 | gGL.color4f(0,0,1,1); |
2107 | break; | 2113 | break; |
2108 | case LLViewerObject::LL_VO_WATER: | 2114 | case LLViewerObject::LL_VO_WATER: |
@@ -2222,7 +2228,7 @@ void renderPoints(LLDrawable* drawablep) | |||
2222 | LLGLDepthTest depth(GL_FALSE, GL_FALSE); | 2228 | LLGLDepthTest depth(GL_FALSE, GL_FALSE); |
2223 | if (drawablep->getNumFaces()) | 2229 | if (drawablep->getNumFaces()) |
2224 | { | 2230 | { |
2225 | gGL.begin(LLVertexBuffer::POINTS); | 2231 | gGL.begin(LLRender::POINTS); |
2226 | gGL.color3f(1,1,1); | 2232 | gGL.color3f(1,1,1); |
2227 | LLVector3 center(drawablep->getPositionGroup()); | 2233 | LLVector3 center(drawablep->getPositionGroup()); |
2228 | for (S32 i = 0; i < drawablep->getNumFaces(); i++) | 2234 | for (S32 i = 0; i < drawablep->getNumFaces(); i++) |
@@ -2298,9 +2304,17 @@ void renderRaycast(LLDrawable* drawablep) | |||
2298 | LLGLEnable blend(GL_BLEND); | 2304 | LLGLEnable blend(GL_BLEND); |
2299 | gGL.color4f(0,1,1,0.5f); | 2305 | gGL.color4f(0,1,1,0.5f); |
2300 | 2306 | ||
2301 | for (S32 i = 0; i < drawablep->getNumFaces(); i++) | 2307 | if (drawablep->getVOVolume() && gDebugRaycastFaceHit != -1) |
2302 | { | 2308 | { |
2303 | pushVerts(drawablep->getFace(i), LLVertexBuffer::MAP_VERTEX); | 2309 | glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); |
2310 | pushVerts(drawablep->getFace(gDebugRaycastFaceHit), LLVertexBuffer::MAP_VERTEX); | ||
2311 | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | ||
2312 | } | ||
2313 | else if (drawablep->isAvatar()) | ||
2314 | { | ||
2315 | LLGLDepthTest depth(GL_FALSE); | ||
2316 | LLVOAvatar* av = (LLVOAvatar*) drawablep->getVObj().get(); | ||
2317 | av->renderCollisionVolumes(); | ||
2304 | } | 2318 | } |
2305 | 2319 | ||
2306 | // draw intersection point | 2320 | // draw intersection point |
@@ -2468,7 +2482,7 @@ void LLSpatialPartition::renderDebug() | |||
2468 | LLGLDisable cullface(GL_CULL_FACE); | 2482 | LLGLDisable cullface(GL_CULL_FACE); |
2469 | LLGLEnable blend(GL_BLEND); | 2483 | LLGLEnable blend(GL_BLEND); |
2470 | gGL.setSceneBlendType(LLRender::BT_ALPHA); | 2484 | gGL.setSceneBlendType(LLRender::BT_ALPHA); |
2471 | LLImageGL::unbindTexture(0); | 2485 | gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); |
2472 | gPipeline.disableLights(); | 2486 | gPipeline.disableLights(); |
2473 | 2487 | ||
2474 | LLSpatialBridge* bridge = asBridge(); | 2488 | LLSpatialBridge* bridge = asBridge(); |
@@ -2508,8 +2522,9 @@ public: | |||
2508 | LLVector3 *mNormal; | 2522 | LLVector3 *mNormal; |
2509 | LLVector3 *mBinormal; | 2523 | LLVector3 *mBinormal; |
2510 | LLDrawable* mHit; | 2524 | LLDrawable* mHit; |
2511 | 2525 | BOOL mPickTransparent; | |
2512 | LLOctreeIntersect(LLVector3 start, LLVector3 end, | 2526 | |
2527 | LLOctreeIntersect(LLVector3 start, LLVector3 end, BOOL pick_transparent, | ||
2513 | S32* face_hit, LLVector3* intersection, LLVector2* tex_coord, LLVector3* normal, LLVector3* binormal) | 2528 | S32* face_hit, LLVector3* intersection, LLVector2* tex_coord, LLVector3* normal, LLVector3* binormal) |
2514 | : mStart(start), | 2529 | : mStart(start), |
2515 | mEnd(end), | 2530 | mEnd(end), |
@@ -2518,14 +2533,15 @@ public: | |||
2518 | mTexCoord(tex_coord), | 2533 | mTexCoord(tex_coord), |
2519 | mNormal(normal), | 2534 | mNormal(normal), |
2520 | mBinormal(binormal), | 2535 | mBinormal(binormal), |
2521 | mHit(NULL) | 2536 | mHit(NULL), |
2537 | mPickTransparent(pick_transparent) | ||
2522 | { | 2538 | { |
2523 | } | 2539 | } |
2524 | 2540 | ||
2525 | virtual void visit(const LLSpatialGroup::OctreeNode* branch) | 2541 | virtual void visit(const LLSpatialGroup::OctreeNode* branch) |
2526 | { | 2542 | { |
2527 | for (LLSpatialGroup::OctreeNode::const_element_iter i = branch->getData().begin(); i != branch->getData().end(); ++i) | 2543 | for (LLSpatialGroup::OctreeNode::const_element_iter i = branch->getData().begin(); i != branch->getData().end(); ++i) |
2528 | { | 2544 | { |
2529 | check(*i); | 2545 | check(*i); |
2530 | } | 2546 | } |
2531 | } | 2547 | } |
@@ -2570,25 +2586,35 @@ public: | |||
2570 | 2586 | ||
2571 | virtual bool check(LLDrawable* drawable) | 2587 | virtual bool check(LLDrawable* drawable) |
2572 | { | 2588 | { |
2589 | LLVector3 local_start = mStart; | ||
2590 | LLVector3 local_end = mEnd; | ||
2591 | |||
2592 | if (!gPipeline.hasRenderType(drawable->getRenderType()) || !drawable->isVisible()) | ||
2593 | { | ||
2594 | return false; | ||
2595 | } | ||
2596 | |||
2573 | if (drawable->isSpatialBridge()) | 2597 | if (drawable->isSpatialBridge()) |
2574 | { | 2598 | { |
2575 | LLSpatialPartition *part = drawable->asPartition(); | 2599 | LLSpatialPartition *part = drawable->asPartition(); |
2576 | 2600 | LLSpatialBridge* bridge = part->asBridge(); | |
2577 | check(part->mOctree); | 2601 | if (bridge && gPipeline.hasRenderType(bridge->mDrawableType)) |
2578 | } | 2602 | { |
2579 | 2603 | check(part->mOctree); | |
2604 | } | ||
2605 | } | ||
2580 | else | 2606 | else |
2581 | { | 2607 | { |
2582 | LLViewerObject* vobj = drawable->getVObj(); | 2608 | LLViewerObject* vobj = drawable->getVObj(); |
2583 | 2609 | ||
2584 | if (vobj) | 2610 | if (vobj) |
2585 | { | 2611 | { |
2586 | LLVector3 intersection; | 2612 | LLVector3 intersection; |
2587 | if (vobj->lineSegmentIntersect(mStart, mEnd, -1, mFaceHit, &intersection, mTexCoord, mNormal, mBinormal)) | 2613 | if (vobj->lineSegmentIntersect(mStart, mEnd, -1, mPickTransparent, mFaceHit, &intersection, mTexCoord, mNormal, mBinormal)) |
2588 | { | 2614 | { |
2589 | mEnd = intersection; // shorten ray so we only find CLOSER hits | 2615 | mEnd = intersection; // shorten ray so we only find CLOSER hits |
2590 | if (mIntersection) | 2616 | if (mIntersection) |
2591 | { | 2617 | { |
2592 | *mIntersection = intersection; | 2618 | *mIntersection = intersection; |
2593 | } | 2619 | } |
2594 | 2620 | ||
@@ -2596,12 +2622,13 @@ public: | |||
2596 | } | 2622 | } |
2597 | } | 2623 | } |
2598 | } | 2624 | } |
2599 | 2625 | ||
2600 | return false; | 2626 | return false; |
2601 | } | 2627 | } |
2602 | }; | 2628 | }; |
2603 | 2629 | ||
2604 | LLDrawable* LLSpatialPartition::lineSegmentIntersect(const LLVector3& start, const LLVector3& end, | 2630 | LLDrawable* LLSpatialPartition::lineSegmentIntersect(const LLVector3& start, const LLVector3& end, |
2631 | BOOL pick_transparent, | ||
2605 | S32* face_hit, // return the face hit | 2632 | S32* face_hit, // return the face hit |
2606 | LLVector3* intersection, // return the intersection point | 2633 | LLVector3* intersection, // return the intersection point |
2607 | LLVector2* tex_coord, // return the texture coordinates of the intersection point | 2634 | LLVector2* tex_coord, // return the texture coordinates of the intersection point |
@@ -2610,7 +2637,7 @@ LLDrawable* LLSpatialPartition::lineSegmentIntersect(const LLVector3& start, con | |||
2610 | ) | 2637 | ) |
2611 | 2638 | ||
2612 | { | 2639 | { |
2613 | LLOctreeIntersect intersect(start, end, face_hit, intersection, tex_coord, normal, bi_normal); | 2640 | LLOctreeIntersect intersect(start, end, pick_transparent, face_hit, intersection, tex_coord, normal, bi_normal); |
2614 | LLDrawable* drawable = intersect.check(mOctree); | 2641 | LLDrawable* drawable = intersect.check(mOctree); |
2615 | 2642 | ||
2616 | return drawable; | 2643 | return drawable; |