From 378c076d1df5d911e07959638fbd61a9094384d2 Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 17 Nov 2011 13:32:04 -0500 Subject: WIP: navmesh station posts to a url, responder receives llsd and then has the llpathing library extract and render the navmesh (if desired). --- indra/llrender/llgl.h | 2 +- indra/llrender/llrendersegment.cpp | 54 ++++++++++++++++++++++++++++++++++++++ indra/llrender/llrendersegment.h | 49 ++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 indra/llrender/llrendersegment.cpp create mode 100644 indra/llrender/llrendersegment.h (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h index d736133f3f..5b2fcf422c 100644 --- a/indra/llrender/llgl.h +++ b/indra/llrender/llgl.h @@ -33,7 +33,7 @@ #include #include -#include "llerror.h" +//#include "llerror.h" #include "v4color.h" #include "llstring.h" #include "stdtypes.h" diff --git a/indra/llrender/llrendersegment.cpp b/indra/llrender/llrendersegment.cpp new file mode 100644 index 0000000000..8f856f62f3 --- /dev/null +++ b/indra/llrender/llrendersegment.cpp @@ -0,0 +1,54 @@ +/** + * @file llrendersegment.cpp + * @brief + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +// Sphere creates a set of display lists that can then be called to create +// a lit sphere at different LOD levels. You only need one instance of sphere +// per viewer - then call the appropriate list. + +#include "linden_common.h" +#include "llrendersegment.h" +#include "llerror.h" +#include "llglheaders.h" + +LLRenderSegment gSegment; +//============================================================================= +void LLRenderSegment::renderSegment( const LLVector3& start, const LLVector3& end, int color ) +{ + LLColor4 colorA = LLColor4::yellow; + + gGL.color4fv( colorA.mV ); + + gGL.begin(LLRender::LINES); + { + gGL.vertex3fv( start.mV ); + + gGL.vertex3fv( end.mV ); + } + + gGL.end(); + +} +//============================================================================= \ No newline at end of file diff --git a/indra/llrender/llrendersegment.h b/indra/llrender/llrendersegment.h new file mode 100644 index 0000000000..d929d6f628 --- /dev/null +++ b/indra/llrender/llrendersegment.h @@ -0,0 +1,49 @@ +/** + * @file llrendersegment.h + * @brief + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLRENDERSEGMENT_H +#define LL_LLRENDERSEGMENT_H + +#include "llmath.h" +#include "v3math.h" +#include "v4math.h" +#include "m3math.h" +#include "m4math.h" +#include "v4color.h" +#include "llgl.h" + + +class LLRenderSegment +{ +public: + void renderSegment( const LLVector3& start, const LLVector3& end, int color ); + +private: +}; + +extern LLRenderSegment gSegment; + +#endif -- cgit v1.2.3 From 38b7f033b28027711a03e5a28d6ea384be909318 Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 17 Nov 2011 17:33:49 -0500 Subject: navmeshdata is now parsed as binary --- indra/llrender/llgl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h index 5b2fcf422c..d736133f3f 100644 --- a/indra/llrender/llgl.h +++ b/indra/llrender/llgl.h @@ -33,7 +33,7 @@ #include #include -//#include "llerror.h" +#include "llerror.h" #include "v4color.h" #include "llstring.h" #include "stdtypes.h" -- cgit v1.2.3 From 0538dcf62e3c13b50fc0828e930fa50e4050302d Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 1 Dec 2011 10:54:21 -0500 Subject: New navmesh viewer options, rendering improvements, etc. --- indra/llrender/llrendersegment.cpp | 31 ++++++++++++++++++++++++------- indra/llrender/llrendersegment.h | 1 + 2 files changed, 25 insertions(+), 7 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendersegment.cpp b/indra/llrender/llrendersegment.cpp index 8f856f62f3..1f57af174e 100644 --- a/indra/llrender/llrendersegment.cpp +++ b/indra/llrender/llrendersegment.cpp @@ -36,19 +36,36 @@ LLRenderSegment gSegment; //============================================================================= void LLRenderSegment::renderSegment( const LLVector3& start, const LLVector3& end, int color ) -{ - LLColor4 colorA = LLColor4::yellow; - - gGL.color4fv( colorA.mV ); +{ + + LLColor4 colorA( color ); + glLineWidth(1.5f); + gGL.color3fv( colorA.mV ); gGL.begin(LLRender::LINES); { gGL.vertex3fv( start.mV ); - gGL.vertex3fv( end.mV ); } - + gGL.end(); + glLineWidth(1.0f); +} +//============================================================================= +void LLRenderSegment::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) +{ + LLGLEnable offset(GL_POLYGON_OFFSET_LINE); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glLineWidth(1.5f); + LLColor4 colorA( color ); + gGL.color4fv( colorA.mV ); + gGL.begin(LLRender::TRIANGLES); + { + gGL.vertex3fv( a.mV ); + gGL.vertex3fv( b.mV ); + gGL.vertex3fv( c.mV ); + } gGL.end(); - + + glLineWidth(1.f); } //============================================================================= \ No newline at end of file diff --git a/indra/llrender/llrendersegment.h b/indra/llrender/llrendersegment.h index d929d6f628..58bc083e25 100644 --- a/indra/llrender/llrendersegment.h +++ b/indra/llrender/llrendersegment.h @@ -40,6 +40,7 @@ class LLRenderSegment { public: void renderSegment( const LLVector3& start, const LLVector3& end, int color ); + void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ); private: }; -- cgit v1.2.3 From 0539b08370392385831f631fbdd8cb41977636b9 Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 1 Dec 2011 11:38:16 -0500 Subject: Renamed segment rendering class into RenderNavPrim --- indra/llrender/llrendernavprim.cpp | 69 ++++++++++++++++++++++++++++++++++++ indra/llrender/llrendernavprim.h | 50 +++++++++++++++++++++++++++ indra/llrender/llrendersegment.cpp | 71 -------------------------------------- indra/llrender/llrendersegment.h | 50 --------------------------- 4 files changed, 119 insertions(+), 121 deletions(-) create mode 100644 indra/llrender/llrendernavprim.cpp create mode 100644 indra/llrender/llrendernavprim.h delete mode 100644 indra/llrender/llrendersegment.cpp delete mode 100644 indra/llrender/llrendersegment.h (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp new file mode 100644 index 0000000000..eea65b3a0d --- /dev/null +++ b/indra/llrender/llrendernavprim.cpp @@ -0,0 +1,69 @@ +/** + * @file LLRenderNavPrim.cpp + * @brief + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + + +#include "linden_common.h" +#include "llrendernavprim.h" +#include "llerror.h" +#include "llglheaders.h" + +//============================================================================= +LLRenderNavPrim gRenderNav; +//============================================================================= +void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color ) +{ + + LLColor4 colorA( color ); + glLineWidth(1.5f); + gGL.color3fv( colorA.mV ); + + gGL.begin(LLRender::LINES); + { + gGL.vertex3fv( start.mV ); + gGL.vertex3fv( end.mV ); + } + gGL.end(); + glLineWidth(1.0f); +} +//============================================================================= +void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) +{ + LLGLEnable offset(GL_POLYGON_OFFSET_LINE); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glLineWidth(1.5f); + LLColor4 colorA( color ); + gGL.color4fv( colorA.mV ); + gGL.begin(LLRender::TRIANGLES); + { + gGL.vertex3fv( a.mV ); + gGL.vertex3fv( b.mV ); + gGL.vertex3fv( c.mV ); + } + gGL.end(); + + glLineWidth(1.f); +} +//============================================================================= \ No newline at end of file diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h new file mode 100644 index 0000000000..697c344d21 --- /dev/null +++ b/indra/llrender/llrendernavprim.h @@ -0,0 +1,50 @@ +/** + * @file LLRenderNavPrim.h + * @brief + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_RENDER_NAVPRIM_H +#define LL_RENDER_NAVPRIM_H + +#include "llmath.h" +#include "v3math.h" +#include "v4math.h" +#include "m3math.h" +#include "m4math.h" +#include "v4color.h" +#include "llgl.h" + + +class LLRenderNavPrim +{ +public: + void renderSegment( const LLVector3& start, const LLVector3& end, int color ); + void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ); + +private: +}; + +extern LLRenderNavPrim gRenderNav; + +#endif diff --git a/indra/llrender/llrendersegment.cpp b/indra/llrender/llrendersegment.cpp deleted file mode 100644 index 1f57af174e..0000000000 --- a/indra/llrender/llrendersegment.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/** - * @file llrendersegment.cpp - * @brief - * - * $LicenseInfo:firstyear=2001&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -// Sphere creates a set of display lists that can then be called to create -// a lit sphere at different LOD levels. You only need one instance of sphere -// per viewer - then call the appropriate list. - -#include "linden_common.h" -#include "llrendersegment.h" -#include "llerror.h" -#include "llglheaders.h" - -LLRenderSegment gSegment; -//============================================================================= -void LLRenderSegment::renderSegment( const LLVector3& start, const LLVector3& end, int color ) -{ - - LLColor4 colorA( color ); - glLineWidth(1.5f); - gGL.color3fv( colorA.mV ); - - gGL.begin(LLRender::LINES); - { - gGL.vertex3fv( start.mV ); - gGL.vertex3fv( end.mV ); - } - gGL.end(); - glLineWidth(1.0f); -} -//============================================================================= -void LLRenderSegment::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) -{ - LLGLEnable offset(GL_POLYGON_OFFSET_LINE); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glLineWidth(1.5f); - LLColor4 colorA( color ); - gGL.color4fv( colorA.mV ); - gGL.begin(LLRender::TRIANGLES); - { - gGL.vertex3fv( a.mV ); - gGL.vertex3fv( b.mV ); - gGL.vertex3fv( c.mV ); - } - gGL.end(); - - glLineWidth(1.f); -} -//============================================================================= \ No newline at end of file diff --git a/indra/llrender/llrendersegment.h b/indra/llrender/llrendersegment.h deleted file mode 100644 index 58bc083e25..0000000000 --- a/indra/llrender/llrendersegment.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @file llrendersegment.h - * @brief - * - * $LicenseInfo:firstyear=2001&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_LLRENDERSEGMENT_H -#define LL_LLRENDERSEGMENT_H - -#include "llmath.h" -#include "v3math.h" -#include "v4math.h" -#include "m3math.h" -#include "m4math.h" -#include "v4color.h" -#include "llgl.h" - - -class LLRenderSegment -{ -public: - void renderSegment( const LLVector3& start, const LLVector3& end, int color ); - void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ); - -private: -}; - -extern LLRenderSegment gSegment; - -#endif -- cgit v1.2.3 From 0b99da8ba522da1a4a1e4b6dba24ee8dac42de60 Mon Sep 17 00:00:00 2001 From: prep Date: Mon, 5 Dec 2011 17:20:54 -0500 Subject: WIP: Implementing VB manager for complex physics shapes --- indra/llrender/llrendernavprim.cpp | 14 ++++++++++---- indra/llrender/llrendernavprim.h | 8 ++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index eea65b3a0d..e88972219d 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -29,11 +29,11 @@ #include "llrendernavprim.h" #include "llerror.h" #include "llglheaders.h" - +#include "llvertexbuffer.h" //============================================================================= LLRenderNavPrim gRenderNav; //============================================================================= -void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color ) +void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color ) const { LLColor4 colorA( color ); @@ -49,13 +49,13 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en glLineWidth(1.0f); } //============================================================================= -void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) +void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const { LLGLEnable offset(GL_POLYGON_OFFSET_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glLineWidth(1.5f); LLColor4 colorA( color ); - gGL.color4fv( colorA.mV ); + gGL.color4fv( colorA.mV ); gGL.begin(LLRender::TRIANGLES); { gGL.vertex3fv( a.mV ); @@ -66,4 +66,10 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L glLineWidth(1.f); } +//============================================================================= +void LLRenderNavPrim::renderNavMeshVB( const LLVertexBuffer* pVBO, int vertCnt ) const +{ + //pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX ); + pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); +} //============================================================================= \ No newline at end of file diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index 697c344d21..f8fabfa95f 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -39,8 +39,12 @@ class LLRenderNavPrim { public: - void renderSegment( const LLVector3& start, const LLVector3& end, int color ); - void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ); + //Draw a line + void renderSegment( const LLVector3& start, const LLVector3& end, int color ) const; + //Draw simple tri + void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const; + //Draw the contents of vertex buffer + void renderNavMeshVB( const LLVertexBuffer* pVBO, int vertCnt ) const; private: }; -- cgit v1.2.3 From 8974278746932fe470e2cbc52511fbc915f1e893 Mon Sep 17 00:00:00 2001 From: prep Date: Wed, 7 Dec 2011 17:56:02 -0500 Subject: Turning on navmesh rendering toggles normal renderables --- indra/llrender/llrendernavprim.cpp | 18 ++++++++++-------- indra/llrender/llrendernavprim.h | 2 +- indra/llrender/llvertexbuffer.cpp | 3 ++- 3 files changed, 13 insertions(+), 10 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index e88972219d..73bc21ab7c 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -51,25 +51,27 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en //============================================================================= void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const { - LLGLEnable offset(GL_POLYGON_OFFSET_LINE); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glPolygonMode(GL_NONE, GL_FILL); + LLGLDisable cull(GL_CULL_FACE); + LLGLEnable lighting( GL_LIGHTING ); + //glEnable(GL_POLYGON_STIPPLE); glLineWidth(1.5f); - LLColor4 colorA( color ); + LLColor4 colorA( color ); gGL.color4fv( colorA.mV ); + gGL.begin(LLRender::TRIANGLES); { gGL.vertex3fv( a.mV ); gGL.vertex3fv( b.mV ); gGL.vertex3fv( c.mV ); } - gGL.end(); - - glLineWidth(1.f); + gGL.end(); + gGL.flush(); } //============================================================================= -void LLRenderNavPrim::renderNavMeshVB( const LLVertexBuffer* pVBO, int vertCnt ) const +void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) { - //pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX ); + //pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR ); pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); } //============================================================================= \ No newline at end of file diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index f8fabfa95f..cd57fd2223 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -44,7 +44,7 @@ public: //Draw simple tri void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const; //Draw the contents of vertex buffer - void renderNavMeshVB( const LLVertexBuffer* pVBO, int vertCnt ) const; + void renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ); private: }; diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 8fd1193780..701944ea61 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -411,7 +411,8 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const llerrs << "Bad vertex buffer draw range: [" << first << ", " << first+count << "]" << llendl; } - if (mGLBuffer != sGLRenderBuffer || useVBOs() != sVBOActive) + BOOL uvb = useVBOs(); + if (mGLBuffer != sGLRenderBuffer || uvb != sVBOActive) { llerrs << "Wrong vertex buffer bound." << llendl; } -- cgit v1.2.3 From a5e2dad53dda8585b82a2e6ae84f178aa25bcb67 Mon Sep 17 00:00:00 2001 From: prep Date: Wed, 7 Dec 2011 18:09:16 -0500 Subject: Turning on navmesh rendering toggles normal renderables --- indra/llrender/llrendernavprim.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 73bc21ab7c..3e14c34168 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -53,10 +53,11 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L { glPolygonMode(GL_NONE, GL_FILL); LLGLDisable cull(GL_CULL_FACE); - LLGLEnable lighting( GL_LIGHTING ); + //LLGLEnable lighting( GL_LIGHTING ); //glEnable(GL_POLYGON_STIPPLE); glLineWidth(1.5f); LLColor4 colorA( color ); + colorA*=2.0f; gGL.color4fv( colorA.mV ); gGL.begin(LLRender::TRIANGLES); -- cgit v1.2.3 From 4c60c59610493c5f95776af2ac93ff34f741b427 Mon Sep 17 00:00:00 2001 From: prep Date: Fri, 9 Dec 2011 15:56:12 -0500 Subject: added vbo support for physics shapes & fixed navmesh/shape menu toggle --- indra/llrender/llrendernavprim.cpp | 48 ++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 3e14c34168..96027ba65b 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -24,7 +24,7 @@ * $/LicenseInfo$ */ - + #include "linden_common.h" #include "llrendernavprim.h" #include "llerror.h" @@ -34,17 +34,17 @@ LLRenderNavPrim gRenderNav; //============================================================================= void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color ) const -{ +{ LLColor4 colorA( color ); glLineWidth(1.5f); - gGL.color3fv( colorA.mV ); - - gGL.begin(LLRender::LINES); - { - gGL.vertex3fv( start.mV ); - gGL.vertex3fv( end.mV ); - } + gGL.color3fv( colorA.mV ); + + gGL.begin(LLRender::LINES); + { + gGL.vertex3fv( start.mV ); + gGL.vertex3fv( end.mV ); + } gGL.end(); glLineWidth(1.0f); } @@ -58,21 +58,29 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L glLineWidth(1.5f); LLColor4 colorA( color ); colorA*=2.0f; - gGL.color4fv( colorA.mV ); - - gGL.begin(LLRender::TRIANGLES); - { - gGL.vertex3fv( a.mV ); - gGL.vertex3fv( b.mV ); - gGL.vertex3fv( c.mV ); - } - gGL.end(); + gGL.color4fv( colorA.mV ); + + gGL.begin(LLRender::TRIANGLES); + { + gGL.vertex3fv( a.mV ); + gGL.vertex3fv( b.mV ); + gGL.vertex3fv( c.mV ); + } + gGL.end(); gGL.flush(); } //============================================================================= void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) { - //pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR ); + glPolygonMode(GL_NONE, GL_FILL); + LLGLDisable cull(GL_CULL_FACE); + glColor3f ( 1.0f, 0.0f, 0.0f ) ; + glDisable( GL_COLOR_MATERIAL ); + + pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR ); pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); + gGL.flush(); + glEnable( GL_COLOR_MATERIAL ); + } -//============================================================================= \ No newline at end of file +//============================================================================= -- cgit v1.2.3 From df6b11f098d1096741bb1b11ecba89d94674bce2 Mon Sep 17 00:00:00 2001 From: Todd Stinson Date: Mon, 12 Dec 2011 09:51:04 -0800 Subject: comparing with ssh://hg@bitbucket.org/prep/viewer-development-havokai searching for changes changeset: 21247:08315c2b1a89 user: Todd Stinson date: Wed Dec 07 12:21:58 2011 -0800 summary: Adding additional source files to the project builds. --- indra/llrender/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/CMakeLists.txt b/indra/llrender/CMakeLists.txt index 5c13df9f81..516af93316 100644 --- a/indra/llrender/CMakeLists.txt +++ b/indra/llrender/CMakeLists.txt @@ -36,6 +36,7 @@ set(llrender_SOURCE_FILES llglslshader.cpp llimagegl.cpp llpostprocess.cpp + llrendernavprim.cpp llrendersphere.cpp llshadermgr.cpp lltexture.cpp @@ -59,6 +60,7 @@ set(llrender_HEADER_FILES llimagegl.h llpostprocess.h llrender.h + llrendernavprim.h llrendersphere.h llshadermgr.h lltexture.h -- cgit v1.2.3 From 6fd6815dac5069400cd8b6b9ae9b2d518995f6f4 Mon Sep 17 00:00:00 2001 From: prep Date: Tue, 13 Dec 2011 18:13:23 -0500 Subject: WIP: VBO fixes - still an issue where the physics shape inherit the navmehs color. --- indra/llrender/llrendernavprim.cpp | 45 +++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 96027ba65b..8d55f840f4 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -30,6 +30,7 @@ #include "llerror.h" #include "llglheaders.h" #include "llvertexbuffer.h" + //============================================================================= LLRenderNavPrim gRenderNav; //============================================================================= @@ -51,11 +52,9 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en //============================================================================= void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const { - glPolygonMode(GL_NONE, GL_FILL); + glLineWidth(1.5f); + glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); LLGLDisable cull(GL_CULL_FACE); - //LLGLEnable lighting( GL_LIGHTING ); - //glEnable(GL_POLYGON_STIPPLE); - glLineWidth(1.5f); LLColor4 colorA( color ); colorA*=2.0f; gGL.color4fv( colorA.mV ); @@ -71,16 +70,42 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L } //============================================================================= void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) -{ - glPolygonMode(GL_NONE, GL_FILL); +{ /* LLGLDisable cull(GL_CULL_FACE); - glColor3f ( 1.0f, 0.0f, 0.0f ) ; - glDisable( GL_COLOR_MATERIAL ); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glLineWidth(1.f); + + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + LLColor4 colorA( 255); + colorA*=2.0f; + gGL.color4fv( colorA.mV ); pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR ); pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); - gGL.flush(); - glEnable( GL_COLOR_MATERIAL ); + */ + //2 + //gGL.setSceneBlendType(LLRender::BT_REPLACE); + //glEnable(GL_COLOR_MATERIAL); + //glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT ); + //glShadeModel( GL_FLAT ); + //F32 ambient[4] = {1.f,0.f,1.f,1.f }; + //gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + //LLColor4 colorA( 255.0f ); + //colorA*=2.0f; + //gGL.color4fv( colorA.mV ); + glLineWidth(1.5f); + glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); + LLGLDisable cull(GL_CULL_FACE); + LLColor4 colorA( 4278190335 ); + colorA*=2.0f; + gGL.color4fv( colorA.mV ); + + pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX ); + pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); + //gGL.flush(); + + + } //============================================================================= -- cgit v1.2.3 From b022048f8710502cb6c099c134fca64bccbc209f Mon Sep 17 00:00:00 2001 From: prep Date: Wed, 14 Dec 2011 11:13:55 -0500 Subject: Cleanup --- indra/llrender/llrendernavprim.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 96027ba65b..ec9ed7f25b 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -34,8 +34,7 @@ LLRenderNavPrim gRenderNav; //============================================================================= void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color ) const -{ - +{ LLColor4 colorA( color ); glLineWidth(1.5f); gGL.color3fv( colorA.mV ); @@ -46,18 +45,17 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en gGL.vertex3fv( end.mV ); } gGL.end(); + glLineWidth(1.0f); } //============================================================================= void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const { - glPolygonMode(GL_NONE, GL_FILL); + glLineWidth(1.5f); + glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); LLGLDisable cull(GL_CULL_FACE); - //LLGLEnable lighting( GL_LIGHTING ); - //glEnable(GL_POLYGON_STIPPLE); - glLineWidth(1.5f); LLColor4 colorA( color ); - colorA*=2.0f; + //colorA*=2.0f; gGL.color4fv( colorA.mV ); gGL.begin(LLRender::TRIANGLES); @@ -67,20 +65,17 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L gGL.vertex3fv( c.mV ); } gGL.end(); + gGL.flush(); } //============================================================================= void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) { - glPolygonMode(GL_NONE, GL_FILL); + glLineWidth(1.5f); + glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); LLGLDisable cull(GL_CULL_FACE); - glColor3f ( 1.0f, 0.0f, 0.0f ) ; - glDisable( GL_COLOR_MATERIAL ); - - pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR ); + gGL.color4fv( LLColor4::white.mV ); + pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX ); pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); - gGL.flush(); - glEnable( GL_COLOR_MATERIAL ); - } //============================================================================= -- cgit v1.2.3 From 10599b5e8c776a45bc0f14e8fd3f70e0f81196f2 Mon Sep 17 00:00:00 2001 From: prep Date: Wed, 14 Dec 2011 11:25:30 -0500 Subject: merge --- indra/llrender/llrendernavprim.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index c07d93ab0a..5c7a669fd2 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -56,7 +56,7 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); LLGLDisable cull(GL_CULL_FACE); LLColor4 colorA( color ); - //colorA*=2.0f; + colorA*=1.5f; gGL.color4fv( colorA.mV ); gGL.begin(LLRender::TRIANGLES); @@ -75,7 +75,7 @@ void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) glLineWidth(1.5f); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); LLGLDisable cull(GL_CULL_FACE); - gGL.color4fv( LLColor4::white.mV ); pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX ); + pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); } //============================================================================= -- cgit v1.2.3 From 6c9b33286788057489a894edea477ee58509f2ef Mon Sep 17 00:00:00 2001 From: prep Date: Wed, 14 Dec 2011 11:59:36 -0500 Subject: Make shapes a little bit transparent --- indra/llrender/llrendernavprim.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 5c7a669fd2..c80ad3e180 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -74,7 +74,7 @@ void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) { glLineWidth(1.5f); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - LLGLDisable cull(GL_CULL_FACE); + LLGLDisable cull(GL_CULL_FACE); pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX ); pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); } -- cgit v1.2.3 From 35b6450d10b826a6bbb60e9dc00e8eaafa8b0d26 Mon Sep 17 00:00:00 2001 From: prep Date: Wed, 14 Dec 2011 15:38:15 -0500 Subject: Enabled fix function when in navmesh rendering mode --- indra/llrender/llrendernavprim.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index c80ad3e180..3b217b426f 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -30,6 +30,7 @@ #include "llerror.h" #include "llglheaders.h" #include "llvertexbuffer.h" +#include "llglslshader.h" //============================================================================= LLRenderNavPrim gRenderNav; @@ -58,16 +59,16 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L LLColor4 colorA( color ); colorA*=1.5f; gGL.color4fv( colorA.mV ); - + LLGLSLShader::sNoFixedFunction = false; gGL.begin(LLRender::TRIANGLES); { gGL.vertex3fv( a.mV ); gGL.vertex3fv( b.mV ); gGL.vertex3fv( c.mV ); } - gGL.end(); - + gGL.end(); gGL.flush(); + LLGLSLShader::sNoFixedFunction = true; } //============================================================================= void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) @@ -75,7 +76,9 @@ void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) glLineWidth(1.5f); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); LLGLDisable cull(GL_CULL_FACE); + LLGLSLShader::sNoFixedFunction = false; pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX ); pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); + LLGLSLShader::sNoFixedFunction = true; } //============================================================================= -- cgit v1.2.3 From e9058099d0405ce89905bd2393fb0264327d4230 Mon Sep 17 00:00:00 2001 From: prep Date: Tue, 20 Dec 2011 12:57:32 -0500 Subject: Allow for the overlaying of an unblended navmesh ontop of the scenes normal renderables --- indra/llrender/llrendernavprim.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 3b217b426f..11e60548e2 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -36,7 +36,8 @@ LLRenderNavPrim gRenderNav; //============================================================================= void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color ) const -{ +{ + LLGLSLShader::sNoFixedFunction = false; LLColor4 colorA( color ); glLineWidth(1.5f); gGL.color3fv( colorA.mV ); @@ -48,6 +49,8 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en } gGL.end(); + gGL.flush(); + LLGLSLShader::sNoFixedFunction = true; glLineWidth(1.0f); } //============================================================================= -- cgit v1.2.3 From e2fd0266ca7249e2008b68f11050973d1e429a62 Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 5 Jan 2012 10:20:18 -0500 Subject: path-149 overlay of navmesh on onto renderables --- indra/llrender/llrendernavprim.cpp | 17 +++++++++++++---- indra/llrender/llrendernavprim.h | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 11e60548e2..1a0103e8f0 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -35,7 +35,7 @@ //============================================================================= LLRenderNavPrim gRenderNav; //============================================================================= -void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color ) const +void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color,bool overlayMode ) const { LLGLSLShader::sNoFixedFunction = false; LLColor4 colorA( color ); @@ -54,10 +54,17 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en glLineWidth(1.0f); } //============================================================================= -void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const +void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color,bool overlayMode ) const { - glLineWidth(1.5f); - glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); + glLineWidth(1.5f); + if ( overlayMode ) + { + glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); + } + else + { + glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); + } LLGLDisable cull(GL_CULL_FACE); LLColor4 colorA( color ); colorA*=1.5f; @@ -71,6 +78,8 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L } gGL.end(); gGL.flush(); + glLineWidth(1.0f); + glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); LLGLSLShader::sNoFixedFunction = true; } //============================================================================= diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index cd57fd2223..a30a14551d 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -40,9 +40,9 @@ class LLRenderNavPrim { public: //Draw a line - void renderSegment( const LLVector3& start, const LLVector3& end, int color ) const; + void renderSegment( const LLVector3& start, const LLVector3& end, int color,bool overlayMode ) const; //Draw simple tri - void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const; + void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color,bool overlayMode ) const; //Draw the contents of vertex buffer void renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ); -- cgit v1.2.3 From 22b877e70a6f72256ff585465232bed93792571d Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 5 Jan 2012 17:02:22 -0500 Subject: WIP: Navmesh vbos rendering fixes (added normal and color maps). --- indra/llrender/llrendernavprim.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 1a0103e8f0..9a114609d2 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -67,7 +67,7 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L } LLGLDisable cull(GL_CULL_FACE); LLColor4 colorA( color ); - colorA*=1.5f; + colorA*=1.25f; gGL.color4fv( colorA.mV ); LLGLSLShader::sNoFixedFunction = false; gGL.begin(LLRender::TRIANGLES); @@ -86,11 +86,22 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) { glLineWidth(1.5f); - glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - LLGLDisable cull(GL_CULL_FACE); LLGLSLShader::sNoFixedFunction = false; - pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX ); - pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); + + LLGLEnable depth(GL_DEPTH_TEST); + glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); + LLGLEnable cull( GL_CULL_FACE ); + + //pass 1 filled + pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); + pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); + //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); + //static GLubyte red[]= { 255.0f, 0.0f, 0.0f, 255.0f }; + //glColor4ubv( red ); + //pass 2 outlined + //pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); LLGLSLShader::sNoFixedFunction = true; + glLineWidth(1.0f); + glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } //============================================================================= -- cgit v1.2.3 From e31a0a7f0843266fe8a803dea954cae70e5d7506 Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 5 Jan 2012 17:10:13 -0500 Subject: Remove already enabled depth test --- indra/llrender/llrendernavprim.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 9a114609d2..0965f00e0b 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -88,7 +88,6 @@ void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) glLineWidth(1.5f); LLGLSLShader::sNoFixedFunction = false; - LLGLEnable depth(GL_DEPTH_TEST); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); LLGLEnable cull( GL_CULL_FACE ); -- cgit v1.2.3 From 1e45d1ae4c25ae8ec73d2b4dc40a5d4efb23121c Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 5 Jan 2012 17:43:36 -0500 Subject: vbos for physics shapes are rendering correctly --- indra/llrender/llrendernavprim.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 0965f00e0b..ac8d45789c 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -85,20 +85,18 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L //============================================================================= void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) { + LLGLSUIDefault gls_ui; glLineWidth(1.5f); LLGLSLShader::sNoFixedFunction = false; glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - LLGLEnable cull( GL_CULL_FACE ); - + LLGLEnable cull( GL_CULL_FACE ); //pass 1 filled pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); - //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); - //static GLubyte red[]= { 255.0f, 0.0f, 0.0f, 255.0f }; - //glColor4ubv( red ); + glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); //pass 2 outlined - //pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); + pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); LLGLSLShader::sNoFixedFunction = true; glLineWidth(1.0f); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); -- cgit v1.2.3 From b2c024cd79efab92e920f37521ae1c34021b2aa6 Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 5 Jan 2012 18:00:41 -0500 Subject: Some gl state cleanup for physic shapes vbos.' --- indra/llrender/llrendernavprim.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index ac8d45789c..3d76f08496 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -86,11 +86,10 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) { LLGLSUIDefault gls_ui; + glEnable( GL_DEPTH_TEST ); + LLGLEnable cull( GL_CULL_FACE ); glLineWidth(1.5f); - LLGLSLShader::sNoFixedFunction = false; - - glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - LLGLEnable cull( GL_CULL_FACE ); + LLGLSLShader::sNoFixedFunction = false; //pass 1 filled pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); -- cgit v1.2.3 From e2ef5a5edce6a01724d91fde5b471b0bae18d045 Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 19 Jan 2012 14:38:16 -0500 Subject: Path-196 : vbo cleanup, visual fixes (path-222) --- indra/llrender/llrendernavprim.cpp | 19 ++++++++++++++++--- indra/llrender/llrendernavprim.h | 8 +++++--- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 3d76f08496..71e808d04e 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -1,6 +1,6 @@ /** * @file LLRenderNavPrim.cpp - * @brief + * @brief Renderable primitives used by the pathing library * * $LicenseInfo:firstyear=2001&license=viewerlgpl$ * Second Life Viewer Source Code @@ -35,7 +35,7 @@ //============================================================================= LLRenderNavPrim gRenderNav; //============================================================================= -void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color,bool overlayMode ) const +void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color, bool overlayMode ) const { LLGLSLShader::sNoFixedFunction = false; LLColor4 colorA( color ); @@ -54,7 +54,7 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en glLineWidth(1.0f); } //============================================================================= -void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color,bool overlayMode ) const +void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color, bool overlayMode ) const { glLineWidth(1.5f); if ( overlayMode ) @@ -101,3 +101,16 @@ void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } //============================================================================= +void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, int color ) const +{ + for (int k=0; k<3; k++) + { + LLVector3 star, pt1, pt2; + star = LLVector3( 0.0f,0.0f,0.0f); + star[k] = 0.5f; + pt1 = center + star; + pt2 = center - star; + renderSegment( pt1, pt2, color, false ); + } +} +//============================================================================= diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index a30a14551d..d88fe656b7 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -40,11 +40,13 @@ class LLRenderNavPrim { public: //Draw a line - void renderSegment( const LLVector3& start, const LLVector3& end, int color,bool overlayMode ) const; + void renderSegment( const LLVector3& start, const LLVector3& end, int color, bool overlayMode ) const; //Draw simple tri - void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color,bool overlayMode ) const; + void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color, bool overlayMode ) const; //Draw the contents of vertex buffer - void renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ); + void renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ); + //Draw a star + void renderStar( const LLVector3& center, const float scale, int color ) const; private: }; -- cgit v1.2.3 From 6d6c38f21688eb99691a8273e0779c50dfa69db7 Mon Sep 17 00:00:00 2001 From: prep Date: Mon, 13 Feb 2012 10:10:57 -0500 Subject: Path-197. Navmeshes are converted into vbos. --- indra/llrender/llrendernavprim.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 71e808d04e..b99a8cdc86 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -38,6 +38,7 @@ LLRenderNavPrim gRenderNav; void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color, bool overlayMode ) const { LLGLSLShader::sNoFixedFunction = false; + LLGLEnable smooth(GL_LINE_SMOOTH); LLColor4 colorA( color ); glLineWidth(1.5f); gGL.color3fv( colorA.mV ); @@ -51,6 +52,7 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en gGL.flush(); LLGLSLShader::sNoFixedFunction = true; + LLGLDisable smoothout(GL_LINE_SMOOTH); glLineWidth(1.0f); } //============================================================================= @@ -86,7 +88,7 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) { LLGLSUIDefault gls_ui; - glEnable( GL_DEPTH_TEST ); + LLGLEnable depth( GL_DEPTH_TEST ); LLGLEnable cull( GL_CULL_FACE ); glLineWidth(1.5f); LLGLSLShader::sNoFixedFunction = false; @@ -94,11 +96,13 @@ void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); + LLGLEnable smooth(GL_LINE_SMOOTH); //pass 2 outlined pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); LLGLSLShader::sNoFixedFunction = true; glLineWidth(1.0f); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); + LLGLDisable smoothout(GL_LINE_SMOOTH); } //============================================================================= void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, int color ) const -- cgit v1.2.3 From c618c0d6211f26c1f49382356f27f400698965be Mon Sep 17 00:00:00 2001 From: prep Date: Wed, 15 Feb 2012 16:31:11 -0500 Subject: Path-266: Navmesh is backfaced culled --- indra/llrender/llrendernavprim.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index b99a8cdc86..30d470729f 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -67,7 +67,7 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L { glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } - LLGLDisable cull(GL_CULL_FACE); + LLGLEnable cull(GL_CULL_FACE); LLColor4 colorA( color ); colorA*=1.25f; gGL.color4fv( colorA.mV ); -- cgit v1.2.3 From b7d93d8adf9f604a2f345336bd0e37c08a0d10cb Mon Sep 17 00:00:00 2001 From: prep Date: Fri, 24 Feb 2012 13:16:35 -0500 Subject: Path-267: Add support for rendering of walkable objects, obstacles and material phantoms. --- indra/llrender/llrendernavprim.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 30d470729f..bd05f05751 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -87,8 +87,7 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L //============================================================================= void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) { - LLGLSUIDefault gls_ui; - LLGLEnable depth( GL_DEPTH_TEST ); + LLGLEnable blend( GL_BLEND ); LLGLEnable cull( GL_CULL_FACE ); glLineWidth(1.5f); LLGLSLShader::sNoFixedFunction = false; @@ -96,13 +95,13 @@ void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); - LLGLEnable smooth(GL_LINE_SMOOTH); + LLGLEnable smooth( GL_LINE_SMOOTH ); //pass 2 outlined pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); LLGLSLShader::sNoFixedFunction = true; glLineWidth(1.0f); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - LLGLDisable smoothout(GL_LINE_SMOOTH); + LLGLDisable smoothout( GL_LINE_SMOOTH ); } //============================================================================= void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, int color ) const -- cgit v1.2.3 From b64773bf2d18ae7cb560977e89d10d70a4483290 Mon Sep 17 00:00:00 2001 From: prep Date: Fri, 24 Feb 2012 14:34:53 -0500 Subject: Fix for nacmesh viewing on low gfx setting and llpathinglib update. --- indra/llrender/llrendernavprim.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index bd05f05751..47cc996043 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -37,6 +37,7 @@ LLRenderNavPrim gRenderNav; //============================================================================= void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color, bool overlayMode ) const { + bool ff = LLGLSLShader::sNoFixedFunction; LLGLSLShader::sNoFixedFunction = false; LLGLEnable smooth(GL_LINE_SMOOTH); LLColor4 colorA( color ); @@ -51,7 +52,7 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en gGL.end(); gGL.flush(); - LLGLSLShader::sNoFixedFunction = true; + LLGLSLShader::sNoFixedFunction = ff; LLGLDisable smoothout(GL_LINE_SMOOTH); glLineWidth(1.0f); } @@ -70,7 +71,8 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L LLGLEnable cull(GL_CULL_FACE); LLColor4 colorA( color ); colorA*=1.25f; - gGL.color4fv( colorA.mV ); + gGL.color4fv( colorA.mV ); + bool ff = LLGLSLShader::sNoFixedFunction; LLGLSLShader::sNoFixedFunction = false; gGL.begin(LLRender::TRIANGLES); { @@ -82,14 +84,15 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L gGL.flush(); glLineWidth(1.0f); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - LLGLSLShader::sNoFixedFunction = true; + LLGLSLShader::sNoFixedFunction = ff; } //============================================================================= void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) { LLGLEnable blend( GL_BLEND ); LLGLEnable cull( GL_CULL_FACE ); - glLineWidth(1.5f); + glLineWidth(1.5f); + bool ff = LLGLSLShader::sNoFixedFunction; LLGLSLShader::sNoFixedFunction = false; //pass 1 filled pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); @@ -98,7 +101,7 @@ void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) LLGLEnable smooth( GL_LINE_SMOOTH ); //pass 2 outlined pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); - LLGLSLShader::sNoFixedFunction = true; + LLGLSLShader::sNoFixedFunction = ff; glLineWidth(1.0f); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); LLGLDisable smoothout( GL_LINE_SMOOTH ); -- cgit v1.2.3 From 34a0a98f9d9557620b7586d343e8173a43164316 Mon Sep 17 00:00:00 2001 From: prep Date: Wed, 7 Mar 2012 10:34:49 -0500 Subject: Partial fix for Path-387. Path-287 Viewer perfomance tweaks. --- indra/llrender/llrendernavprim.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 47cc996043..1114d132c7 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -37,9 +37,6 @@ LLRenderNavPrim gRenderNav; //============================================================================= void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color, bool overlayMode ) const { - bool ff = LLGLSLShader::sNoFixedFunction; - LLGLSLShader::sNoFixedFunction = false; - LLGLEnable smooth(GL_LINE_SMOOTH); LLColor4 colorA( color ); glLineWidth(1.5f); gGL.color3fv( colorA.mV ); @@ -50,16 +47,12 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en gGL.vertex3fv( end.mV ); } gGL.end(); - - gGL.flush(); - LLGLSLShader::sNoFixedFunction = ff; - LLGLDisable smoothout(GL_LINE_SMOOTH); - glLineWidth(1.0f); + //glLineWidth(1.0f); } //============================================================================= void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color, bool overlayMode ) const { - glLineWidth(1.5f); + //glLineWidth(1.5f); if ( overlayMode ) { glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); @@ -68,12 +61,10 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L { glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } - LLGLEnable cull(GL_CULL_FACE); + LLColor4 colorA( color ); colorA*=1.25f; gGL.color4fv( colorA.mV ); - bool ff = LLGLSLShader::sNoFixedFunction; - LLGLSLShader::sNoFixedFunction = false; gGL.begin(LLRender::TRIANGLES); { gGL.vertex3fv( a.mV ); @@ -81,10 +72,8 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L gGL.vertex3fv( c.mV ); } gGL.end(); - gGL.flush(); - glLineWidth(1.0f); - glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - LLGLSLShader::sNoFixedFunction = ff; + //glLineWidth(1.0f); + //move out ...glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } //============================================================================= void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) @@ -98,13 +87,11 @@ void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); - LLGLEnable smooth( GL_LINE_SMOOTH ); //pass 2 outlined pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); LLGLSLShader::sNoFixedFunction = ff; glLineWidth(1.0f); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - LLGLDisable smoothout( GL_LINE_SMOOTH ); } //============================================================================= void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, int color ) const -- cgit v1.2.3 From 790554b218e49141d999b4ef21ecaaa567535665 Mon Sep 17 00:00:00 2001 From: prep Date: Wed, 7 Mar 2012 11:19:13 -0500 Subject: Fix for overlaying navmesh on renderable geometry. --- indra/llrender/llrendernavprim.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 1114d132c7..b697946a1d 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -38,7 +38,7 @@ LLRenderNavPrim gRenderNav; void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color, bool overlayMode ) const { LLColor4 colorA( color ); - glLineWidth(1.5f); + //glLineWidth(1.5f); gGL.color3fv( colorA.mV ); gGL.begin(LLRender::LINES); @@ -52,16 +52,6 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en //============================================================================= void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color, bool overlayMode ) const { - //glLineWidth(1.5f); - if ( overlayMode ) - { - glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); - } - else - { - glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - } - LLColor4 colorA( color ); colorA*=1.25f; gGL.color4fv( colorA.mV ); @@ -72,8 +62,6 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L gGL.vertex3fv( c.mV ); } gGL.end(); - //glLineWidth(1.0f); - //move out ...glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } //============================================================================= void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) -- cgit v1.2.3 From 41e095deb8f40de24c26ef10dda03951566e03c6 Mon Sep 17 00:00:00 2001 From: prep Date: Wed, 7 Mar 2012 17:48:17 -0500 Subject: Path-287: VB bug fixes. Cleaned up rendering prims. Navmesh shape rendering fixes. Code cleanup --- indra/llrender/llrendernavprim.cpp | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index b697946a1d..ebc453a32c 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -38,7 +38,6 @@ LLRenderNavPrim gRenderNav; void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color, bool overlayMode ) const { LLColor4 colorA( color ); - //glLineWidth(1.5f); gGL.color3fv( colorA.mV ); gGL.begin(LLRender::LINES); @@ -47,7 +46,6 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en gGL.vertex3fv( end.mV ); } gGL.end(); - //glLineWidth(1.0f); } //============================================================================= void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color, bool overlayMode ) const @@ -65,21 +63,9 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L } //============================================================================= void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) -{ - LLGLEnable blend( GL_BLEND ); - LLGLEnable cull( GL_CULL_FACE ); - glLineWidth(1.5f); - bool ff = LLGLSLShader::sNoFixedFunction; - LLGLSLShader::sNoFixedFunction = false; - //pass 1 filled +{ pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); - glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); - //pass 2 outlined - pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); - LLGLSLShader::sNoFixedFunction = ff; - glLineWidth(1.0f); - glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } //============================================================================= void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, int color ) const -- cgit v1.2.3 From 72f6df493cacdd8ccf160dd785081e5b2b579862 Mon Sep 17 00:00:00 2001 From: prep Date: Wed, 14 Mar 2012 16:22:19 -0400 Subject: Updated header for flush. --- indra/llrender/llrendernavprim.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index d88fe656b7..158093690e 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -47,7 +47,8 @@ public: void renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ); //Draw a star void renderStar( const LLVector3& center, const float scale, int color ) const; - + //Flush the device + void flushDevice() { gGL.flush(); } private: }; -- cgit v1.2.3 From 2f4ad07633264688f5335022f65bfab095c19815 Mon Sep 17 00:00:00 2001 From: Todd Stinson Date: Tue, 20 Mar 2012 17:38:58 -0700 Subject: Cleaning up miscellaneous differences between the pathfinding repository and the latest viewer-development. --- indra/llrender/llvertexbuffer.cpp | 4583 ++++++++++++++++++------------------- 1 file changed, 2290 insertions(+), 2293 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index b562c91e3e..e4a5cd0299 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -1,2293 +1,2290 @@ -/** - * @file llvertexbuffer.cpp - * @brief LLVertexBuffer implementation - * - * $LicenseInfo:firstyear=2003&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#include "linden_common.h" - -#include -#include "llsys.h" -#include "llvertexbuffer.h" -// #include "llrender.h" -#include "llglheaders.h" -#include "llmemtype.h" -#include "llrender.h" -#include "llvector4a.h" -#include "llshadermgr.h" -#include "llglslshader.h" -#include "llmemory.h" - -//Next Highest Power Of Two -//helper function, returns first number > v that is a power of 2, or v if v is already a power of 2 -U32 nhpo2(U32 v) -{ - U32 r = 1; - while (r < v) { - r *= 2; - } - return r; -} - - -//============================================================================ - -//static -LLVBOPool LLVertexBuffer::sStreamVBOPool(GL_STREAM_DRAW_ARB, GL_ARRAY_BUFFER_ARB); -LLVBOPool LLVertexBuffer::sDynamicVBOPool(GL_DYNAMIC_DRAW_ARB, GL_ARRAY_BUFFER_ARB); -LLVBOPool LLVertexBuffer::sStreamIBOPool(GL_STREAM_DRAW_ARB, GL_ELEMENT_ARRAY_BUFFER_ARB); -LLVBOPool LLVertexBuffer::sDynamicIBOPool(GL_DYNAMIC_DRAW_ARB, GL_ELEMENT_ARRAY_BUFFER_ARB); -U32 LLVBOPool::sBytesPooled = 0; - -LLPrivateMemoryPool* LLVertexBuffer::sPrivatePoolp = NULL; -U32 LLVertexBuffer::sBindCount = 0; -U32 LLVertexBuffer::sSetCount = 0; -S32 LLVertexBuffer::sCount = 0; -S32 LLVertexBuffer::sGLCount = 0; -S32 LLVertexBuffer::sMappedCount = 0; -bool LLVertexBuffer::sDisableVBOMapping = false; -bool LLVertexBuffer::sEnableVBOs = true; -U32 LLVertexBuffer::sGLRenderBuffer = 0; -U32 LLVertexBuffer::sGLRenderArray = 0; -U32 LLVertexBuffer::sGLRenderIndices = 0; -U32 LLVertexBuffer::sLastMask = 0; -bool LLVertexBuffer::sVBOActive = false; -bool LLVertexBuffer::sIBOActive = false; -U32 LLVertexBuffer::sAllocatedBytes = 0; -bool LLVertexBuffer::sMapped = false; -bool LLVertexBuffer::sUseStreamDraw = true; -bool LLVertexBuffer::sUseVAO = false; -bool LLVertexBuffer::sPreferStreamDraw = false; - -const U32 FENCE_WAIT_TIME_NANOSECONDS = 10000; //1 ms - -class LLGLSyncFence : public LLGLFence -{ -public: -#ifdef GL_ARB_sync - GLsync mSync; -#endif - - LLGLSyncFence() - { -#ifdef GL_ARB_sync - mSync = 0; -#endif - } - - virtual ~LLGLSyncFence() - { -#ifdef GL_ARB_sync - if (mSync) - { - glDeleteSync(mSync); - } -#endif - } - - void placeFence() - { -#ifdef GL_ARB_sync - if (mSync) - { - glDeleteSync(mSync); - } - mSync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); -#endif - } - - void wait() - { -#ifdef GL_ARB_sync - if (mSync) - { - while (glClientWaitSync(mSync, 0, FENCE_WAIT_TIME_NANOSECONDS) == GL_TIMEOUT_EXPIRED) - { //track the number of times we've waited here - static S32 waits = 0; - waits++; - } - } -#endif - } - - -}; - - -//which power of 2 is i? -//assumes i is a power of 2 > 0 -U32 wpo2(U32 i) -{ - llassert(i > 0); - llassert(nhpo2(i) == i); - - U32 r = 0; - - while (i >>= 1) ++r; - - return r; -} - -volatile U8* LLVBOPool::allocate(U32& name, U32 size) -{ - llassert(nhpo2(size) == size); - - U32 i = wpo2(size); - - if (mFreeList.size() <= i) - { - mFreeList.resize(i+1); - } - - volatile U8* ret = NULL; - - if (mFreeList[i].empty()) - { - //make a new buffer - glGenBuffersARB(1, &name); - glBindBufferARB(mType, name); - LLVertexBuffer::sAllocatedBytes += size; - - if (LLVertexBuffer::sDisableVBOMapping || mUsage != GL_DYNAMIC_DRAW_ARB) - { - glBufferDataARB(mType, size, 0, mUsage); - ret = (U8*) ll_aligned_malloc_16(size); - } - else - { //always use a true hint of static draw when allocating non-client-backed buffers - glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB); - } - - glBindBufferARB(mType, 0); - } - else - { - name = mFreeList[i].front().mGLName; - ret = mFreeList[i].front().mClientData; - - sBytesPooled -= size; - - mFreeList[i].pop_front(); - } - - return ret; -} - -void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size) -{ - llassert(nhpo2(size) == size); - - U32 i = wpo2(size); - - llassert(mFreeList.size() > i); - - Record rec; - rec.mGLName = name; - rec.mClientData = buffer; - - if (buffer == NULL) - - { - glDeleteBuffersARB(1, &rec.mGLName); - } - else - { - sBytesPooled += size; - mFreeList[i].push_back(rec); -} -} - -void LLVBOPool::cleanup() -{ - U32 size = 1; - - for (U32 i = 0; i < mFreeList.size(); ++i) - { - record_list_t& l = mFreeList[i]; - - while (!l.empty()) - { - Record& r = l.front(); - - glDeleteBuffersARB(1, &r.mGLName); - - if (r.mClientData) - { - ll_aligned_free_16((void*) r.mClientData); - } - - l.pop_front(); - - LLVertexBuffer::sAllocatedBytes -= size; - sBytesPooled -= size; - } - - size *= 2; - } -} - - -//NOTE: each component must be AT LEAST 4 bytes in size to avoid a performance penalty on AMD hardware -S32 LLVertexBuffer::sTypeSize[LLVertexBuffer::TYPE_MAX] = -{ - sizeof(LLVector4), // TYPE_VERTEX, - sizeof(LLVector4), // TYPE_NORMAL, - sizeof(LLVector2), // TYPE_TEXCOORD0, - sizeof(LLVector2), // TYPE_TEXCOORD1, - sizeof(LLVector2), // TYPE_TEXCOORD2, - sizeof(LLVector2), // TYPE_TEXCOORD3, - sizeof(LLColor4U), // TYPE_COLOR, - sizeof(LLColor4U), // TYPE_EMISSIVE, only alpha is used currently - sizeof(LLVector4), // TYPE_BINORMAL, - sizeof(F32), // TYPE_WEIGHT, - sizeof(LLVector4), // TYPE_WEIGHT4, - sizeof(LLVector4), // TYPE_CLOTHWEIGHT, - sizeof(LLVector4), // TYPE_TEXTURE_INDEX (actually exists as position.w), no extra data, but stride is 16 bytes -}; - -U32 LLVertexBuffer::sGLMode[LLRender::NUM_MODES] = -{ - GL_TRIANGLES, - GL_TRIANGLE_STRIP, - GL_TRIANGLE_FAN, - GL_POINTS, - GL_LINES, - GL_LINE_STRIP, - GL_QUADS, - GL_LINE_LOOP, -}; - - -//static -void LLVertexBuffer::setupClientArrays(U32 data_mask) -{ - if (sLastMask != data_mask) - { - bool error = false; - - if (LLGLSLShader::sNoFixedFunction) - { - for (U32 i = 0; i < TYPE_MAX; ++i) - { - S32 loc = i; - - U32 mask = 1 << i; - - if (sLastMask & (1 << i)) - { //was enabled - if (!(data_mask & mask)) - { //needs to be disabled - glDisableVertexAttribArrayARB(loc); - } - } - else - { //was disabled - if (data_mask & mask) - { //needs to be enabled - glEnableVertexAttribArrayARB(loc); - } - } - } - } - else - { - - GLenum array[] = - { - GL_VERTEX_ARRAY, - GL_NORMAL_ARRAY, - GL_TEXTURE_COORD_ARRAY, - GL_COLOR_ARRAY, - }; - - GLenum mask[] = - { - MAP_VERTEX, - MAP_NORMAL, - MAP_TEXCOORD0, - MAP_COLOR - }; - - - - for (U32 i = 0; i < 4; ++i) - { - if (sLastMask & mask[i]) - { //was enabled - if (!(data_mask & mask[i])) - { //needs to be disabled - glDisableClientState(array[i]); - } - else if (gDebugGL) - { //needs to be enabled, make sure it was (DEBUG) - if (!glIsEnabled(array[i])) - { - if (gDebugSession) - { - error = true; - gFailLog << "Bad client state! " << array[i] << " disabled." << std::endl; - } - else - { - llerrs << "Bad client state! " << array[i] << " disabled." << llendl; - } - } - } - } - else - { //was disabled - if (data_mask & mask[i]) - { //needs to be enabled - glEnableClientState(array[i]); - } - else if (gDebugGL && glIsEnabled(array[i])) - { //needs to be disabled, make sure it was (DEBUG TEMPORARY) - if (gDebugSession) - { - error = true; - gFailLog << "Bad client state! " << array[i] << " enabled." << std::endl; - } - else - { - llerrs << "Bad client state! " << array[i] << " enabled." << llendl; - } - } - } - } - - U32 map_tc[] = - { - MAP_TEXCOORD1, - MAP_TEXCOORD2, - MAP_TEXCOORD3 - }; - - for (U32 i = 0; i < 3; i++) - { - if (sLastMask & map_tc[i]) - { - if (!(data_mask & map_tc[i])) - { //disable - glClientActiveTextureARB(GL_TEXTURE1_ARB+i); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glClientActiveTextureARB(GL_TEXTURE0_ARB); - } - } - else if (data_mask & map_tc[i]) - { - glClientActiveTextureARB(GL_TEXTURE1_ARB+i); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glClientActiveTextureARB(GL_TEXTURE0_ARB); - } - } - - if (sLastMask & MAP_BINORMAL) - { - if (!(data_mask & MAP_BINORMAL)) - { - glClientActiveTextureARB(GL_TEXTURE2_ARB); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glClientActiveTextureARB(GL_TEXTURE0_ARB); - } - } - else if (data_mask & MAP_BINORMAL) - { - glClientActiveTextureARB(GL_TEXTURE2_ARB); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glClientActiveTextureARB(GL_TEXTURE0_ARB); - } - } - - sLastMask = data_mask; - } -} - -//static -void LLVertexBuffer::drawArrays(U32 mode, const std::vector& pos, const std::vector& norm) -{ - llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShaderPtr != NULL); - gGL.syncMatrices(); - - U32 count = pos.size(); - llassert_always(norm.size() >= pos.size()); - llassert_always(count > 0); - - unbind(); - - setupClientArrays(MAP_VERTEX | MAP_NORMAL); - - LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; - - if (shader) - { - S32 loc = LLVertexBuffer::TYPE_VERTEX; - if (loc > -1) - { - glVertexAttribPointerARB(loc, 3, GL_FLOAT, GL_FALSE, 0, pos[0].mV); - } - loc = LLVertexBuffer::TYPE_NORMAL; - if (loc > -1) - { - glVertexAttribPointerARB(loc, 3, GL_FLOAT, GL_FALSE, 0, norm[0].mV); - } - } - else - { - glVertexPointer(3, GL_FLOAT, 0, pos[0].mV); - glNormalPointer(GL_FLOAT, 0, norm[0].mV); - } - - glDrawArrays(sGLMode[mode], 0, count); -} - -//static -void LLVertexBuffer::drawElements(U32 mode, const LLVector4a* pos, const LLVector2* tc, S32 num_indices, const U16* indicesp) -{ - llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShaderPtr != NULL); - - gGL.syncMatrices(); - - U32 mask = LLVertexBuffer::MAP_VERTEX; - if (tc) - { - mask = mask | LLVertexBuffer::MAP_TEXCOORD0; - } - - unbind(); - - setupClientArrays(mask); - - if (LLGLSLShader::sNoFixedFunction) - { - S32 loc = LLVertexBuffer::TYPE_VERTEX; - glVertexAttribPointerARB(loc, 3, GL_FLOAT, GL_FALSE, 16, pos); - - if (tc) - { - loc = LLVertexBuffer::TYPE_TEXCOORD0; - glVertexAttribPointerARB(loc, 2, GL_FLOAT, GL_FALSE, 0, tc); - } - } - else - { - glTexCoordPointer(2, GL_FLOAT, 0, tc); - glVertexPointer(3, GL_FLOAT, 16, pos); - } - - glDrawElements(sGLMode[mode], num_indices, GL_UNSIGNED_SHORT, indicesp); -} - -void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_offset) const -{ - if (start >= (U32) mNumVerts || - end >= (U32) mNumVerts) - { - llerrs << "Bad vertex buffer draw range: [" << start << ", " << end << "] vs " << mNumVerts << llendl; - } - - llassert(mNumIndices >= 0); - - if (indices_offset >= (U32) mNumIndices || - indices_offset + count > (U32) mNumIndices) - { - llerrs << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << llendl; - } - - if (gDebugGL && !useVBOs()) - { - U16* idx = ((U16*) getIndicesPointer())+indices_offset; - for (U32 i = 0; i < count; ++i) - { - if (idx[i] < start || idx[i] > end) - { - llerrs << "Index out of range: " << idx[i] << " not in [" << start << ", " << end << "]" << llendl; - } - } - - LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; - - if (shader && shader->mFeatures.mIndexedTextureChannels > 1) - { - LLStrider v; - //hack to get non-const reference - LLVertexBuffer* vb = (LLVertexBuffer*) this; - vb->getVertexStrider(v); - - for (U32 i = start; i < end; i++) - { - S32 idx = (S32) (v[i][3]+0.25f); - if (idx < 0 || idx >= shader->mFeatures.mIndexedTextureChannels) - { - llerrs << "Bad texture index found in vertex data stream." << llendl; - } - } - } - } -} - -void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const -{ - validateRange(start, end, count, indices_offset); - mMappable = false; - gGL.syncMatrices(); - - llassert(mNumVerts >= 0); - llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShaderPtr != NULL); - - if (mGLArray) - { - if (mGLArray != sGLRenderArray) - { - llerrs << "Wrong vertex array bound." << llendl; - } - } - else - { - if (mGLIndices != sGLRenderIndices) - { - llerrs << "Wrong index buffer bound." << llendl; - } - - if (mGLBuffer != sGLRenderBuffer) - { - llerrs << "Wrong vertex buffer bound." << llendl; - } - } - - if (gDebugGL && !mGLArray && useVBOs()) - { - GLint elem = 0; - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &elem); - - if (elem != mGLIndices) - { - llerrs << "Wrong index buffer bound!" << llendl; - } - } - - if (mode >= LLRender::NUM_MODES) - { - llerrs << "Invalid draw mode: " << mode << llendl; - return; - } - - U16* idx = ((U16*) getIndicesPointer())+indices_offset; - - stop_glerror(); - glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, - idx); - stop_glerror(); - placeFence(); -} - -void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const -{ - llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShaderPtr != NULL); - mMappable = false; - gGL.syncMatrices(); - - llassert(mNumIndices >= 0); - if (indices_offset >= (U32) mNumIndices || - indices_offset + count > (U32) mNumIndices) - { - llerrs << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << llendl; - } - - if (mGLArray) - { - if (mGLArray != sGLRenderArray) - { - llerrs << "Wrong vertex array bound." << llendl; - } - } - else - { - if (mGLIndices != sGLRenderIndices) - { - llerrs << "Wrong index buffer bound." << llendl; - } - - if (mGLBuffer != sGLRenderBuffer) - { - llerrs << "Wrong vertex buffer bound." << llendl; - } - } - - if (mode >= LLRender::NUM_MODES) - { - llerrs << "Invalid draw mode: " << mode << llendl; - return; - } - - stop_glerror(); - glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, - ((U16*) getIndicesPointer()) + indices_offset); - stop_glerror(); - placeFence(); -} - -void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const -{ - llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShaderPtr != NULL); - mMappable = false; - gGL.syncMatrices(); - - llassert(mNumVerts >= 0); - if (first >= (U32) mNumVerts || - first + count > (U32) mNumVerts) - { - llerrs << "Bad vertex buffer draw range: [" << first << ", " << first+count << "]" << llendl; - } - - if (mGLArray) - { - if (mGLArray != sGLRenderArray) - { - llerrs << "Wrong vertex array bound." << llendl; - } - } - else - { - bool uvb = useVBOs(); - if (mGLBuffer != sGLRenderBuffer || uvb != sVBOActive) - { - llerrs << "Wrong vertex buffer bound." << llendl; - } - } - - if (mode >= LLRender::NUM_MODES) - { - llerrs << "Invalid draw mode: " << mode << llendl; - return; - } - - stop_glerror(); - glDrawArrays(sGLMode[mode], first, count); - stop_glerror(); - placeFence(); -} - -//static -void LLVertexBuffer::initClass(bool use_vbo, bool no_vbo_mapping) -{ - sEnableVBOs = use_vbo && gGLManager.mHasVertexBufferObject; - sDisableVBOMapping = sEnableVBOs && no_vbo_mapping; - - if (!sPrivatePoolp) - { - sPrivatePoolp = LLPrivateMemoryPoolManager::getInstance()->newPool(LLPrivateMemoryPool::STATIC); - } -} - -//static -void LLVertexBuffer::unbind() -{ - if (sGLRenderArray) - { -#if GL_ARB_vertex_array_object - glBindVertexArray(0); -#endif - sGLRenderArray = 0; - sGLRenderIndices = 0; - sIBOActive = false; - } - - if (sVBOActive) - { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); - sVBOActive = false; - } - if (sIBOActive) - { - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); - sIBOActive = false; - } - - sGLRenderBuffer = 0; - sGLRenderIndices = 0; - - setupClientArrays(0); -} - -//static -void LLVertexBuffer::cleanupClass() -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_CLEANUP_CLASS); - unbind(); - - sStreamIBOPool.cleanup(); - sDynamicIBOPool.cleanup(); - sStreamVBOPool.cleanup(); - sDynamicVBOPool.cleanup(); - - if(sPrivatePoolp) - { - LLPrivateMemoryPoolManager::getInstance()->deletePool(sPrivatePoolp); - sPrivatePoolp = NULL; - } -} - -//---------------------------------------------------------------------------- - -S32 LLVertexBuffer::determineUsage(S32 usage) -{ - S32 ret_usage = usage; - - if (!sEnableVBOs) - { - ret_usage = 0; - } - - if (ret_usage == GL_STREAM_DRAW_ARB && !sUseStreamDraw) - { - ret_usage = 0; - } - - if (ret_usage == GL_DYNAMIC_DRAW_ARB && sPreferStreamDraw) - { - ret_usage = GL_STREAM_DRAW_ARB; - } - - if (ret_usage == 0 && LLRender::sGLCoreProfile) - { //MUST use VBOs for all rendering - ret_usage = GL_STREAM_DRAW_ARB; - } - - if (ret_usage && ret_usage != GL_STREAM_DRAW_ARB) - { //only stream_draw and dynamic_draw are supported when using VBOs, dynamic draw is the default - if (sDisableVBOMapping) - { //always use stream draw if VBO mapping is disabled - ret_usage = GL_STREAM_DRAW_ARB; - } - else - { -ret_usage = GL_DYNAMIC_DRAW_ARB; - - } - } - - return ret_usage; -} - -LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) : - LLRefCount(), - - mNumVerts(0), - mNumIndices(0), - mAlignedOffset(0), - mAlignedIndexOffset(0), - mSize(0), - mIndicesSize(0), - mTypeMask(typemask), - mUsage(LLVertexBuffer::determineUsage(usage)), - mGLBuffer(0), - mGLIndices(0), - mGLArray(0), - mMappedData(NULL), - mMappedIndexData(NULL), - mMappedDataUsingVBOs(false), - mMappedIndexDataUsingVBOs(false), - mVertexLocked(false), - mIndexLocked(false), - mFinal(false), - mEmpty(true), - mMappable(false), - mFence(NULL) -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_CONSTRUCTOR); - - mMappable = (mUsage == GL_DYNAMIC_DRAW_ARB && !sDisableVBOMapping); - - //zero out offsets - for (U32 i = 0; i < TYPE_MAX; i++) - { - mOffsets[i] = 0; - } - - sCount++; -} - -//static -S32 LLVertexBuffer::calcOffsets(const U32& typemask, S32* offsets, S32 num_vertices) -{ - S32 offset = 0; - for (S32 i=0; iplaceFence(); - }*/ -} - -void LLVertexBuffer::waitFence() const -{ - /*if (mFence) - { - mFence->wait(); - }*/ -} - -//---------------------------------------------------------------------------- - -void LLVertexBuffer::genBuffer(U32 size) -{ - mSize = nhpo2(size); - - if (mUsage == GL_STREAM_DRAW_ARB) - { - mMappedData = sStreamVBOPool.allocate(mGLBuffer, mSize); - } - else - { - mMappedData = sDynamicVBOPool.allocate(mGLBuffer, mSize); - } - - sGLCount++; -} - -void LLVertexBuffer::genIndices(U32 size) -{ - mIndicesSize = nhpo2(size); - - if (mUsage == GL_STREAM_DRAW_ARB) - { - mMappedIndexData = sStreamIBOPool.allocate(mGLIndices, mIndicesSize); - } - else - { - mMappedIndexData = sDynamicIBOPool.allocate(mGLIndices, mIndicesSize); - } - - sGLCount++; -} - -void LLVertexBuffer::releaseBuffer() -{ - if (mUsage == GL_STREAM_DRAW_ARB) - { - sStreamVBOPool.release(mGLBuffer, mMappedData, mSize); - } - else - { - sDynamicVBOPool.release(mGLBuffer, mMappedData, mSize); - } - - mGLBuffer = 0; - mMappedData = NULL; - - sGLCount--; -} - -void LLVertexBuffer::releaseIndices() -{ - if (mUsage == GL_STREAM_DRAW_ARB) - { - sStreamIBOPool.release(mGLIndices, mMappedIndexData, mIndicesSize); - } - else - { - sDynamicIBOPool.release(mGLIndices, mMappedIndexData, mIndicesSize); - } - - mGLIndices = 0; - mMappedIndexData = NULL; - - sGLCount--; -} - -void LLVertexBuffer::createGLBuffer(U32 size) -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_CREATE_VERTICES); - - if (mGLBuffer) - { - destroyGLBuffer(); - } - - if (size == 0) - { - return; - } - - mEmpty = true; - - mMappedDataUsingVBOs = useVBOs(); - - if (mMappedDataUsingVBOs) - { - genBuffer(size); - } - else - { - static int gl_buffer_idx = 0; - mGLBuffer = ++gl_buffer_idx; - mMappedData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); - mSize = size; - } -} - -void LLVertexBuffer::createGLIndices(U32 size) -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_CREATE_INDICES); - - if (mGLIndices) - { - destroyGLIndices(); - } - - if (size == 0) - { - return; - } - - mEmpty = true; - - //pad by 16 bytes for aligned copies - size += 16; - - mMappedIndexDataUsingVBOs = useVBOs(); - - if (mMappedIndexDataUsingVBOs) - { - //pad by another 16 bytes for VBO pointer adjustment - size += 16; - genIndices(size); - } - else - { - mMappedIndexData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); - static int gl_buffer_idx = 0; - mGLIndices = ++gl_buffer_idx; - mIndicesSize = size; - } -} - -void LLVertexBuffer::destroyGLBuffer() -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_DESTROY_BUFFER); - if (mGLBuffer) - { - if (mMappedDataUsingVBOs) - { - releaseBuffer(); - } - else - { - FREE_MEM(sPrivatePoolp, (void*) mMappedData); - mMappedData = NULL; - mEmpty = true; - } - } - - mGLBuffer = 0; - //unbind(); -} - -void LLVertexBuffer::destroyGLIndices() -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_DESTROY_INDICES); - if (mGLIndices) - { - if (mMappedIndexDataUsingVBOs) - { - releaseIndices(); - } - else - { - FREE_MEM(sPrivatePoolp, (void*) mMappedIndexData); - mMappedIndexData = NULL; - mEmpty = true; - } - } - - mGLIndices = 0; - //unbind(); -} - -void LLVertexBuffer::updateNumVerts(S32 nverts) -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_UPDATE_VERTS); - - llassert(nverts >= 0); - - if (nverts >= 65535) - { - llwarns << "Vertex buffer overflow!" << llendl; - nverts = 65535; - } - - U32 needed_size = calcOffsets(mTypeMask, mOffsets, nverts); - - if (needed_size > mSize || needed_size <= mSize/2) - { - createGLBuffer(needed_size); - } - - mNumVerts = nverts; -} - -void LLVertexBuffer::updateNumIndices(S32 nindices) -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_UPDATE_INDICES); - - llassert(nindices >= 0); - - U32 needed_size = sizeof(U16) * nindices; - - if (needed_size > mIndicesSize || needed_size <= mIndicesSize/2) - { - createGLIndices(needed_size); - } - - mNumIndices = nindices; -} - -void LLVertexBuffer::allocateBuffer(S32 nverts, S32 nindices, bool create) -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_ALLOCATE_BUFFER); - - stop_glerror(); - - if (nverts < 0 || nindices < 0 || - nverts > 65536) - { - llerrs << "Bad vertex buffer allocation: " << nverts << " : " << nindices << llendl; - } - - updateNumVerts(nverts); - updateNumIndices(nindices); - - if (create && (nverts || nindices)) - { - //actually allocate space for the vertex buffer if using VBO mapping - flush(); - - if (gGLManager.mHasVertexArrayObject && useVBOs() && (LLRender::sGLCoreProfile || sUseVAO)) - { -#if GL_ARB_vertex_array_object - glGenVertexArrays(1, &mGLArray); -#endif - setupVertexArray(); - } - } -} - -static LLFastTimer::DeclareTimer FTM_SETUP_VERTEX_ARRAY("Setup VAO"); - -void LLVertexBuffer::setupVertexArray() -{ - if (!mGLArray) - { - return; - } - - LLFastTimer t(FTM_SETUP_VERTEX_ARRAY); -#if GL_ARB_vertex_array_object - glBindVertexArray(mGLArray); -#endif - sGLRenderArray = mGLArray; - - U32 attrib_size[] = - { - 3, //TYPE_VERTEX, - 3, //TYPE_NORMAL, - 2, //TYPE_TEXCOORD0, - 2, //TYPE_TEXCOORD1, - 2, //TYPE_TEXCOORD2, - 2, //TYPE_TEXCOORD3, - 4, //TYPE_COLOR, - 4, //TYPE_EMISSIVE, - 3, //TYPE_BINORMAL, - 1, //TYPE_WEIGHT, - 4, //TYPE_WEIGHT4, - 4, //TYPE_CLOTHWEIGHT, - 1, //TYPE_TEXTURE_INDEX - }; - - U32 attrib_type[] = - { - GL_FLOAT, //TYPE_VERTEX, - GL_FLOAT, //TYPE_NORMAL, - GL_FLOAT, //TYPE_TEXCOORD0, - GL_FLOAT, //TYPE_TEXCOORD1, - GL_FLOAT, //TYPE_TEXCOORD2, - GL_FLOAT, //TYPE_TEXCOORD3, - GL_UNSIGNED_BYTE, //TYPE_COLOR, - GL_UNSIGNED_BYTE, //TYPE_EMISSIVE, - GL_FLOAT, //TYPE_BINORMAL, - GL_FLOAT, //TYPE_WEIGHT, - GL_FLOAT, //TYPE_WEIGHT4, - GL_FLOAT, //TYPE_CLOTHWEIGHT, - GL_FLOAT, //TYPE_TEXTURE_INDEX - }; - - U32 attrib_normalized[] = - { - GL_FALSE, //TYPE_VERTEX, - GL_FALSE, //TYPE_NORMAL, - GL_FALSE, //TYPE_TEXCOORD0, - GL_FALSE, //TYPE_TEXCOORD1, - GL_FALSE, //TYPE_TEXCOORD2, - GL_FALSE, //TYPE_TEXCOORD3, - GL_TRUE, //TYPE_COLOR, - GL_TRUE, //TYPE_EMISSIVE, - GL_FALSE, //TYPE_BINORMAL, - GL_FALSE, //TYPE_WEIGHT, - GL_FALSE, //TYPE_WEIGHT4, - GL_FALSE, //TYPE_CLOTHWEIGHT, - GL_FALSE, //TYPE_TEXTURE_INDEX - }; - - bindGLBuffer(true); - bindGLIndices(true); - - for (U32 i = 0; i < TYPE_MAX; ++i) - { - if (mTypeMask & (1 << i)) - { - glEnableVertexAttribArrayARB(i); - glVertexAttribPointerARB(i, attrib_size[i], attrib_type[i], attrib_normalized[i], sTypeSize[i], (void*) mOffsets[i]); - } - else - { - glDisableVertexAttribArrayARB(i); - } - } - - //draw a dummy triangle to set index array pointer - //glDrawElements(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT, NULL); - - unbind(); -} - -void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) -{ - llassert(newnverts >= 0); - llassert(newnindices >= 0); - - LLMemType mt2(LLMemType::MTYPE_VERTEX_RESIZE_BUFFER); - - updateNumVerts(newnverts); - updateNumIndices(newnindices); - - if (useVBOs()) - { - flush(); - - if (mGLArray) - { //if size changed, offsets changed - setupVertexArray(); - } - } -} - -bool LLVertexBuffer::useVBOs() const -{ - //it's generally ineffective to use VBO for things that are streaming on apple - return (mUsage != 0); -} - -//---------------------------------------------------------------------------- - -bool expand_region(LLVertexBuffer::MappedRegion& region, S32 index, S32 count) -{ - S32 end = index+count; - S32 region_end = region.mIndex+region.mCount; - - if (end < region.mIndex || - index > region_end) - { //gap exists, do not merge - return false; - } - - S32 new_end = llmax(end, region_end); - S32 new_index = llmin(index, region.mIndex); - region.mIndex = new_index; - region.mCount = new_end-new_index; - return true; -} - -static LLFastTimer::DeclareTimer FTM_VBO_MAP_BUFFER_RANGE("VBO Map Range"); -static LLFastTimer::DeclareTimer FTM_VBO_MAP_BUFFER("VBO Map"); - -// Map for data access -volatile U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_range) -{ - bindGLBuffer(true); - LLMemType mt2(LLMemType::MTYPE_VERTEX_MAP_BUFFER); - if (mFinal) - { - llerrs << "LLVertexBuffer::mapVeretxBuffer() called on a finalized buffer." << llendl; - } - if (!useVBOs() && !mMappedData && !mMappedIndexData) - { - llerrs << "LLVertexBuffer::mapVertexBuffer() called on unallocated buffer." << llendl; - } - - if (useVBOs()) - { - if (!mMappable || gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange) - { - if (count == -1) - { - count = mNumVerts-index; - } - - bool mapped = false; - //see if range is already mapped - for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) - { - MappedRegion& region = mMappedVertexRegions[i]; - if (region.mType == type) - { - if (expand_region(region, index, count)) - { - mapped = true; - break; - } - } - } - - if (!mapped) - { - //not already mapped, map new region - MappedRegion region(type, mMappable && map_range ? -1 : index, count); - mMappedVertexRegions.push_back(region); - } - } - - if (mVertexLocked && map_range) - { - llerrs << "Attempted to map a specific range of a buffer that was already mapped." << llendl; - } - - if (!mVertexLocked) - { - LLMemType mt_v(LLMemType::MTYPE_VERTEX_MAP_BUFFER_VERTICES); - mVertexLocked = true; - sMappedCount++; - stop_glerror(); - - if(!mMappable) - { - map_range = false; - } - else - { - volatile U8* src = NULL; - waitFence(); - if (gGLManager.mHasMapBufferRange) - { - if (map_range) - { -#ifdef GL_ARB_map_buffer_range - LLFastTimer t(FTM_VBO_MAP_BUFFER_RANGE); - S32 offset = mOffsets[type] + sTypeSize[type]*index; - S32 length = (sTypeSize[type]*count+0xF) & ~0xF; - src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER_ARB, offset, length, - GL_MAP_WRITE_BIT | - GL_MAP_FLUSH_EXPLICIT_BIT | - GL_MAP_INVALIDATE_RANGE_BIT); -#endif - } - else - { -#ifdef GL_ARB_map_buffer_range - - if (gDebugGL) - { - GLint size = 0; - glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); - - if (size < mSize) - { - llerrs << "Invalid buffer size." << llendl; - } - } - - LLFastTimer t(FTM_VBO_MAP_BUFFER); - src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER_ARB, 0, mSize, - GL_MAP_WRITE_BIT | - GL_MAP_FLUSH_EXPLICIT_BIT); -#endif - } - } - else if (gGLManager.mHasFlushBufferRange) - { - if (map_range) - { - glBufferParameteriAPPLE(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE); - glBufferParameteriAPPLE(GL_ARRAY_BUFFER_ARB, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); - src = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); - } - else - { - src = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); - } - } - else - { - map_range = false; - src = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); - } - - llassert(src != NULL); - - mMappedData = LL_NEXT_ALIGNED_ADDRESS(src); - mAlignedOffset = mMappedData - src; - - stop_glerror(); - } - - if (!mMappedData) - { - log_glerror(); - - //check the availability of memory - LLMemory::logMemoryInfo(true); - - if(mMappable) - { - //-------------------- - //print out more debug info before crash - llinfos << "vertex buffer size: (num verts : num indices) = " << getNumVerts() << " : " << getNumIndices() << llendl; - GLint size; - glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); - llinfos << "GL_ARRAY_BUFFER_ARB size is " << size << llendl; - //-------------------- - - GLint buff; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &buff); - if ((GLuint)buff != mGLBuffer) - { - llerrs << "Invalid GL vertex buffer bound: " << buff << llendl; - } - - - llerrs << "glMapBuffer returned NULL (no vertex data)" << llendl; - } - else - { - llerrs << "memory allocation for vertex data failed." << llendl; - } - } - } - } - else - { - map_range = false; - } - - if (map_range && gGLManager.mHasMapBufferRange && mMappable) - { - return mMappedData; - } - else - { - return mMappedData+mOffsets[type]+sTypeSize[type]*index; - } -} - - -static LLFastTimer::DeclareTimer FTM_VBO_MAP_INDEX_RANGE("IBO Map Range"); -static LLFastTimer::DeclareTimer FTM_VBO_MAP_INDEX("IBO Map"); - -volatile U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_MAP_BUFFER); - bindGLIndices(true); - if (mFinal) - { - llerrs << "LLVertexBuffer::mapIndexBuffer() called on a finalized buffer." << llendl; - } - if (!useVBOs() && !mMappedData && !mMappedIndexData) - { - llerrs << "LLVertexBuffer::mapIndexBuffer() called on unallocated buffer." << llendl; - } - - if (useVBOs()) - { - if (!mMappable || gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange) - { - if (count == -1) - { - count = mNumIndices-index; - } - - bool mapped = false; - //see if range is already mapped - for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) - { - MappedRegion& region = mMappedIndexRegions[i]; - if (expand_region(region, index, count)) - { - mapped = true; - break; - } - } - - if (!mapped) - { - //not already mapped, map new region - MappedRegion region(TYPE_INDEX, mMappable && map_range ? -1 : index, count); - mMappedIndexRegions.push_back(region); - } - } - - if (mIndexLocked && map_range) - { - llerrs << "Attempted to map a specific range of a buffer that was already mapped." << llendl; - } - - if (!mIndexLocked) - { - LLMemType mt_v(LLMemType::MTYPE_VERTEX_MAP_BUFFER_INDICES); - - mIndexLocked = true; - sMappedCount++; - stop_glerror(); - - if (gDebugGL && useVBOs()) - { - GLint elem = 0; - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &elem); - - if (elem != mGLIndices) - { - llerrs << "Wrong index buffer bound!" << llendl; - } - } - - if(!mMappable) - { - map_range = false; - } - else - { - volatile U8* src = NULL; - waitFence(); - if (gGLManager.mHasMapBufferRange) - { - if (map_range) - { -#ifdef GL_ARB_map_buffer_range - LLFastTimer t(FTM_VBO_MAP_INDEX_RANGE); - S32 offset = sizeof(U16)*index; - S32 length = sizeof(U16)*count; - src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, - GL_MAP_WRITE_BIT | - GL_MAP_FLUSH_EXPLICIT_BIT | - GL_MAP_INVALIDATE_RANGE_BIT); -#endif - } - else - { -#ifdef GL_ARB_map_buffer_range - LLFastTimer t(FTM_VBO_MAP_INDEX); - src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, sizeof(U16)*mNumIndices, - GL_MAP_WRITE_BIT | - GL_MAP_FLUSH_EXPLICIT_BIT); -#endif - } - } - else if (gGLManager.mHasFlushBufferRange) - { - if (map_range) - { - glBufferParameteriAPPLE(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE); - glBufferParameteriAPPLE(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); - src = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); - } - else - { - src = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); - } - } - else - { - LLFastTimer t(FTM_VBO_MAP_INDEX); - map_range = false; - src = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); - } - - llassert(src != NULL); - - - mMappedIndexData = src; //LL_NEXT_ALIGNED_ADDRESS(src); - mAlignedIndexOffset = mMappedIndexData - src; - stop_glerror(); - } - } - - if (!mMappedIndexData) - { - log_glerror(); - LLMemory::logMemoryInfo(true); - - if(mMappable) - { - GLint buff; - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &buff); - if ((GLuint)buff != mGLIndices) - { - llerrs << "Invalid GL index buffer bound: " << buff << llendl; - } - - llerrs << "glMapBuffer returned NULL (no index data)" << llendl; - } - else - { - llerrs << "memory allocation for Index data failed. " << llendl; - } - } - } - else - { - map_range = false; - } - - if (map_range && gGLManager.mHasMapBufferRange && mMappable) - { - return mMappedIndexData; - } - else - { - return mMappedIndexData + sizeof(U16)*index; - } -} - -static LLFastTimer::DeclareTimer FTM_VBO_UNMAP("VBO Unmap"); -static LLFastTimer::DeclareTimer FTM_VBO_FLUSH_RANGE("Flush VBO Range"); - - -static LLFastTimer::DeclareTimer FTM_IBO_UNMAP("IBO Unmap"); -static LLFastTimer::DeclareTimer FTM_IBO_FLUSH_RANGE("Flush IBO Range"); - -void LLVertexBuffer::unmapBuffer() -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_UNMAP_BUFFER); - if (!useVBOs()) - { - return; //nothing to unmap - } - - bool updated_all = false; - - if (mMappedData && mVertexLocked) - { - LLFastTimer t(FTM_VBO_UNMAP); - bindGLBuffer(true); - updated_all = mIndexLocked; //both vertex and index buffers done updating - - if(!mMappable) - { - if (!mMappedVertexRegions.empty()) - { - stop_glerror(); - for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) - { - const MappedRegion& region = mMappedVertexRegions[i]; - S32 offset = region.mIndex >= 0 ? mOffsets[region.mType]+sTypeSize[region.mType]*region.mIndex : 0; - S32 length = sTypeSize[region.mType]*region.mCount; - glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, offset, length, (U8*) mMappedData+offset); - stop_glerror(); - } - - mMappedVertexRegions.clear(); - } - else - { - stop_glerror(); - glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, getSize(), (U8*) mMappedData); - stop_glerror(); - } - } - else - { - if (gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange) - { - if (!mMappedVertexRegions.empty()) - { - stop_glerror(); - for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) - { - const MappedRegion& region = mMappedVertexRegions[i]; - S32 offset = region.mIndex >= 0 ? mOffsets[region.mType]+sTypeSize[region.mType]*region.mIndex : 0; - S32 length = sTypeSize[region.mType]*region.mCount; - if (gGLManager.mHasMapBufferRange) - { - LLFastTimer t(FTM_VBO_FLUSH_RANGE); -#ifdef GL_ARB_map_buffer_range - glFlushMappedBufferRange(GL_ARRAY_BUFFER_ARB, offset, length); -#endif - } - else if (gGLManager.mHasFlushBufferRange) - { - glFlushMappedBufferRangeAPPLE(GL_ARRAY_BUFFER_ARB, offset, length); - } - stop_glerror(); - } - - mMappedVertexRegions.clear(); - } - } - stop_glerror(); - glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); - stop_glerror(); - - mMappedData = NULL; - } - - mVertexLocked = false; - sMappedCount--; - } - - if (mMappedIndexData && mIndexLocked) - { - LLFastTimer t(FTM_IBO_UNMAP); - bindGLIndices(); - if(!mMappable) - { - if (!mMappedIndexRegions.empty()) - { - for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) - { - const MappedRegion& region = mMappedIndexRegions[i]; - S32 offset = region.mIndex >= 0 ? sizeof(U16)*region.mIndex : 0; - S32 length = sizeof(U16)*region.mCount; - glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, (U8*) mMappedIndexData+offset); - stop_glerror(); - } - - mMappedIndexRegions.clear(); - } - else - { - stop_glerror(); - glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, getIndicesSize(), (U8*) mMappedIndexData); - stop_glerror(); - } - } - else - { - if (gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange) - { - if (!mMappedIndexRegions.empty()) - { - for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) - { - const MappedRegion& region = mMappedIndexRegions[i]; - S32 offset = region.mIndex >= 0 ? sizeof(U16)*region.mIndex : 0; - S32 length = sizeof(U16)*region.mCount; - if (gGLManager.mHasMapBufferRange) - { - LLFastTimer t(FTM_IBO_FLUSH_RANGE); -#ifdef GL_ARB_map_buffer_range - glFlushMappedBufferRange(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length); -#endif - } - else if (gGLManager.mHasFlushBufferRange) - { -#ifdef GL_APPLE_flush_buffer_range - glFlushMappedBufferRangeAPPLE(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length); -#endif - } - stop_glerror(); - } - - mMappedIndexRegions.clear(); - } - } - stop_glerror(); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); - stop_glerror(); - - mMappedIndexData = NULL; - } - - mIndexLocked = false; - sMappedCount--; - } - - if(updated_all) - { - mEmpty = false; - } -} - -//---------------------------------------------------------------------------- - -template struct VertexBufferStrider -{ - typedef LLStrider strider_t; - static bool get(LLVertexBuffer& vbo, - strider_t& strider, - S32 index, S32 count, bool map_range) - { - if (type == LLVertexBuffer::TYPE_INDEX) - { - volatile U8* ptr = vbo.mapIndexBuffer(index, count, map_range); - - if (ptr == NULL) - { - llwarns << "mapIndexBuffer failed!" << llendl; - return false; - } - - strider = (T*)ptr; - strider.setStride(0); - return true; - } - else if (vbo.hasDataType(type)) - { - S32 stride = LLVertexBuffer::sTypeSize[type]; - - volatile U8* ptr = vbo.mapVertexBuffer(type, index, count, map_range); - - if (ptr == NULL) - { - llwarns << "mapVertexBuffer failed!" << llendl; - return false; - } - - strider = (T*)ptr; - strider.setStride(stride); - return true; - } - else - { - llerrs << "VertexBufferStrider could not find valid vertex data." << llendl; - } - return false; - } -}; - -bool LLVertexBuffer::getVertexStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} -bool LLVertexBuffer::getVertexStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} -bool LLVertexBuffer::getIndexStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} -bool LLVertexBuffer::getTexCoord0Strider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} -bool LLVertexBuffer::getTexCoord1Strider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} - -bool LLVertexBuffer::getNormalStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} -bool LLVertexBuffer::getBinormalStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} -bool LLVertexBuffer::getColorStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} -bool LLVertexBuffer::getEmissiveStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} -bool LLVertexBuffer::getWeightStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} - -bool LLVertexBuffer::getWeight4Strider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} - -bool LLVertexBuffer::getClothWeightStrider(LLStrider& strider, S32 index, S32 count, bool map_range) -{ - return VertexBufferStrider::get(*this, strider, index, count, map_range); -} - -//---------------------------------------------------------------------------- - -static LLFastTimer::DeclareTimer FTM_BIND_GL_ARRAY("Bind Array"); -bool LLVertexBuffer::bindGLArray() -{ - if (mGLArray && sGLRenderArray != mGLArray) - { - { - LLFastTimer t(FTM_BIND_GL_ARRAY); -#if GL_ARB_vertex_array_object - glBindVertexArray(mGLArray); -#endif - sGLRenderArray = mGLArray; - } - - //really shouldn't be necessary, but some drivers don't properly restore the - //state of GL_ELEMENT_ARRAY_BUFFER_BINDING - bindGLIndices(); - - return true; - } - - return false; -} - -static LLFastTimer::DeclareTimer FTM_BIND_GL_BUFFER("Bind Buffer"); - -bool LLVertexBuffer::bindGLBuffer(bool force_bind) -{ - bindGLArray(); - - bool ret = false; - - if (useVBOs() && (force_bind || (mGLBuffer && (mGLBuffer != sGLRenderBuffer || !sVBOActive)))) - { - LLFastTimer t(FTM_BIND_GL_BUFFER); - /*if (sMapped) - { - llerrs << "VBO bound while another VBO mapped!" << llendl; - }*/ - glBindBufferARB(GL_ARRAY_BUFFER_ARB, mGLBuffer); - sGLRenderBuffer = mGLBuffer; - sBindCount++; - sVBOActive = true; - - if (mGLArray) - { - llassert(sGLRenderArray == mGLArray); - //mCachedRenderBuffer = mGLBuffer; - } - - ret = true; - } - - return ret; -} - -static LLFastTimer::DeclareTimer FTM_BIND_GL_INDICES("Bind Indices"); - -bool LLVertexBuffer::bindGLIndices(bool force_bind) -{ - bindGLArray(); - - bool ret = false; - if (useVBOs() && (force_bind || (mGLIndices && (mGLIndices != sGLRenderIndices || !sIBOActive)))) - { - LLFastTimer t(FTM_BIND_GL_INDICES); - /*if (sMapped) - { - llerrs << "VBO bound while another VBO mapped!" << llendl; - }*/ - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mGLIndices); - sGLRenderIndices = mGLIndices; - stop_glerror(); - sBindCount++; - sIBOActive = true; - ret = true; - } - - return ret; -} - -void LLVertexBuffer::flush() -{ - if (useVBOs()) - { - unmapBuffer(); - } -} - -// Set for rendering -void LLVertexBuffer::setBuffer(U32 data_mask) -{ - flush(); - - LLMemType mt2(LLMemType::MTYPE_VERTEX_SET_BUFFER); - //set up pointers if the data mask is different ... - bool setup = (sLastMask != data_mask); - - if (gDebugGL && data_mask != 0) - { //make sure data requirements are fulfilled - LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; - if (shader) - { - U32 required_mask = 0; - for (U32 i = 0; i < LLVertexBuffer::TYPE_TEXTURE_INDEX; ++i) - { - if (shader->getAttribLocation(i) > -1) - { - U32 required = 1 << i; - if ((data_mask & required) == 0) - { - llwarns << "Missing attribute: " << LLShaderMgr::instance()->mReservedAttribs[i] << llendl; - } - - required_mask |= required; - } - } - - if ((data_mask & required_mask) != required_mask) - { - llerrs << "Shader consumption mismatches data provision." << llendl; - } - } - } - - if (useVBOs()) - { - if (mGLArray) - { - bindGLArray(); - setup = false; //do NOT perform pointer setup if using VAO - } - else - { - const bool bindBuffer = bindGLBuffer(); - const bool bindIndices = bindGLIndices(); - - setup = setup || bindBuffer || bindIndices; - } - - bool error = false; - if (gDebugGL && !mGLArray) - { - GLint buff; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &buff); - if ((GLuint)buff != mGLBuffer) - { - if (gDebugSession) - { - error = true; - gFailLog << "Invalid GL vertex buffer bound: " << buff << std::endl; - } - else - { - llerrs << "Invalid GL vertex buffer bound: " << buff << llendl; - } - } - - if (mGLIndices) - { - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &buff); - if ((GLuint)buff != mGLIndices) - { - if (gDebugSession) - { - error = true; - gFailLog << "Invalid GL index buffer bound: " << buff << std::endl; - } - else - { - llerrs << "Invalid GL index buffer bound: " << buff << llendl; - } - } - } - } - - - } - else - { - if (sGLRenderArray) - { -#if GL_ARB_vertex_array_object - glBindVertexArray(0); -#endif - sGLRenderArray = 0; - sGLRenderIndices = 0; - sIBOActive = false; - } - - if (mGLBuffer) - { - if (sVBOActive) - { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); - sBindCount++; - sVBOActive = false; - setup = true; // ... or a VBO is deactivated - } - if (sGLRenderBuffer != mGLBuffer) - { - sGLRenderBuffer = mGLBuffer; - setup = true; // ... or a client memory pointer changed - } - } - if (mGLIndices) - { - if (sIBOActive) - { - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); - sBindCount++; - sIBOActive = false; - } - - sGLRenderIndices = mGLIndices; - } - } - - if (!mGLArray) - { - setupClientArrays(data_mask); - } - - if (mGLBuffer) - { - if (data_mask && setup) - { - setupVertexBuffer(data_mask); // subclass specific setup (virtual function) - sSetCount++; - } - } -} - -// virtual (default) -void LLVertexBuffer::setupVertexBuffer(U32 data_mask) -{ - LLMemType mt2(LLMemType::MTYPE_VERTEX_SETUP_VERTEX_BUFFER); - stop_glerror(); - volatile U8* base = useVBOs() ? (U8*) mAlignedOffset : mMappedData; - - /*if ((data_mask & mTypeMask) != data_mask) - { - llerrs << "LLVertexBuffer::setupVertexBuffer missing required components for supplied data mask." << llendl; - }*/ - - if (LLGLSLShader::sNoFixedFunction) - { - if (data_mask & MAP_NORMAL) - { - S32 loc = TYPE_NORMAL; - void* ptr = (void*)(base + mOffsets[TYPE_NORMAL]); - glVertexAttribPointerARB(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL], ptr); - } - if (data_mask & MAP_TEXCOORD3) - { - S32 loc = TYPE_TEXCOORD3; - void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD3]); - glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], ptr); - } - if (data_mask & MAP_TEXCOORD2) - { - S32 loc = TYPE_TEXCOORD2; - void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD2]); - glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], ptr); - } - if (data_mask & MAP_TEXCOORD1) - { - S32 loc = TYPE_TEXCOORD1; - void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD1]); - glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], ptr); - } - if (data_mask & MAP_BINORMAL) - { - S32 loc = TYPE_BINORMAL; - void* ptr = (void*)(base + mOffsets[TYPE_BINORMAL]); - glVertexAttribPointerARB(loc, 3,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_BINORMAL], ptr); - } - if (data_mask & MAP_TEXCOORD0) - { - S32 loc = TYPE_TEXCOORD0; - void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD0]); - glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], ptr); - } - if (data_mask & MAP_COLOR) - { - S32 loc = TYPE_COLOR; - void* ptr = (void*)(base + mOffsets[TYPE_COLOR]); - glVertexAttribPointerARB(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_COLOR], ptr); - } - if (data_mask & MAP_EMISSIVE) - { - S32 loc = TYPE_EMISSIVE; - void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE]); - glVertexAttribPointerARB(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); - } - if (data_mask & MAP_WEIGHT) - { - S32 loc = TYPE_WEIGHT; - void* ptr = (void*)(base + mOffsets[TYPE_WEIGHT]); - glVertexAttribPointerARB(loc, 1, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT], ptr); - } - if (data_mask & MAP_WEIGHT4) - { - S32 loc = TYPE_WEIGHT4; - void* ptr = (void*)(base+mOffsets[TYPE_WEIGHT4]); - glVertexAttribPointerARB(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT4], ptr); - } - if (data_mask & MAP_CLOTHWEIGHT) - { - S32 loc = TYPE_CLOTHWEIGHT; - void* ptr = (void*)(base + mOffsets[TYPE_CLOTHWEIGHT]); - glVertexAttribPointerARB(loc, 4, GL_FLOAT, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_CLOTHWEIGHT], ptr); - } - if (data_mask & MAP_TEXTURE_INDEX) - { - S32 loc = TYPE_TEXTURE_INDEX; - void *ptr = (void*) (base + mOffsets[TYPE_VERTEX] + 12); - glVertexAttribPointerARB(loc, 1, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); - } - if (data_mask & MAP_VERTEX) - { - S32 loc = TYPE_VERTEX; - void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); - glVertexAttribPointerARB(loc, 3,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); - } - } - else - { - if (data_mask & MAP_NORMAL) - { - glNormalPointer(GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_NORMAL], (void*)(base + mOffsets[TYPE_NORMAL])); - } - if (data_mask & MAP_TEXCOORD3) - { - glClientActiveTextureARB(GL_TEXTURE3_ARB); - glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], (void*)(base + mOffsets[TYPE_TEXCOORD3])); - glClientActiveTextureARB(GL_TEXTURE0_ARB); - } - if (data_mask & MAP_TEXCOORD2) - { - glClientActiveTextureARB(GL_TEXTURE2_ARB); - glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], (void*)(base + mOffsets[TYPE_TEXCOORD2])); - glClientActiveTextureARB(GL_TEXTURE0_ARB); - } - if (data_mask & MAP_TEXCOORD1) - { - glClientActiveTextureARB(GL_TEXTURE1_ARB); - glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], (void*)(base + mOffsets[TYPE_TEXCOORD1])); - glClientActiveTextureARB(GL_TEXTURE0_ARB); - } - if (data_mask & MAP_BINORMAL) - { - glClientActiveTextureARB(GL_TEXTURE2_ARB); - glTexCoordPointer(3,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_BINORMAL], (void*)(base + mOffsets[TYPE_BINORMAL])); - glClientActiveTextureARB(GL_TEXTURE0_ARB); - } - if (data_mask & MAP_TEXCOORD0) - { - glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], (void*)(base + mOffsets[TYPE_TEXCOORD0])); - } - if (data_mask & MAP_COLOR) - { - glColorPointer(4, GL_UNSIGNED_BYTE, LLVertexBuffer::sTypeSize[TYPE_COLOR], (void*)(base + mOffsets[TYPE_COLOR])); - } - if (data_mask & MAP_VERTEX) - { - glVertexPointer(3,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_VERTEX], (void*)(base + 0)); - } - } - - llglassertok(); -} - -LLVertexBuffer::MappedRegion::MappedRegion(S32 type, S32 index, S32 count) -: mType(type), mIndex(index), mCount(count) -{ - llassert(mType == LLVertexBuffer::TYPE_INDEX || - mType < LLVertexBuffer::TYPE_TEXTURE_INDEX); -} - - +/** + * @file llvertexbuffer.cpp + * @brief LLVertexBuffer implementation + * + * $LicenseInfo:firstyear=2003&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include +#include "llsys.h" +#include "llvertexbuffer.h" +// #include "llrender.h" +#include "llglheaders.h" +#include "llmemtype.h" +#include "llrender.h" +#include "llvector4a.h" +#include "llshadermgr.h" +#include "llglslshader.h" +#include "llmemory.h" + +//Next Highest Power Of Two +//helper function, returns first number > v that is a power of 2, or v if v is already a power of 2 +U32 nhpo2(U32 v) +{ + U32 r = 1; + while (r < v) { + r *= 2; + } + return r; +} + + +//============================================================================ + +//static +LLVBOPool LLVertexBuffer::sStreamVBOPool(GL_STREAM_DRAW_ARB, GL_ARRAY_BUFFER_ARB); +LLVBOPool LLVertexBuffer::sDynamicVBOPool(GL_DYNAMIC_DRAW_ARB, GL_ARRAY_BUFFER_ARB); +LLVBOPool LLVertexBuffer::sStreamIBOPool(GL_STREAM_DRAW_ARB, GL_ELEMENT_ARRAY_BUFFER_ARB); +LLVBOPool LLVertexBuffer::sDynamicIBOPool(GL_DYNAMIC_DRAW_ARB, GL_ELEMENT_ARRAY_BUFFER_ARB); +U32 LLVBOPool::sBytesPooled = 0; + +LLPrivateMemoryPool* LLVertexBuffer::sPrivatePoolp = NULL; +U32 LLVertexBuffer::sBindCount = 0; +U32 LLVertexBuffer::sSetCount = 0; +S32 LLVertexBuffer::sCount = 0; +S32 LLVertexBuffer::sGLCount = 0; +S32 LLVertexBuffer::sMappedCount = 0; +bool LLVertexBuffer::sDisableVBOMapping = false; +bool LLVertexBuffer::sEnableVBOs = true; +U32 LLVertexBuffer::sGLRenderBuffer = 0; +U32 LLVertexBuffer::sGLRenderArray = 0; +U32 LLVertexBuffer::sGLRenderIndices = 0; +U32 LLVertexBuffer::sLastMask = 0; +bool LLVertexBuffer::sVBOActive = false; +bool LLVertexBuffer::sIBOActive = false; +U32 LLVertexBuffer::sAllocatedBytes = 0; +bool LLVertexBuffer::sMapped = false; +bool LLVertexBuffer::sUseStreamDraw = true; +bool LLVertexBuffer::sUseVAO = false; +bool LLVertexBuffer::sPreferStreamDraw = false; + +const U32 FENCE_WAIT_TIME_NANOSECONDS = 10000; //1 ms + +class LLGLSyncFence : public LLGLFence +{ +public: +#ifdef GL_ARB_sync + GLsync mSync; +#endif + + LLGLSyncFence() + { +#ifdef GL_ARB_sync + mSync = 0; +#endif + } + + virtual ~LLGLSyncFence() + { +#ifdef GL_ARB_sync + if (mSync) + { + glDeleteSync(mSync); + } +#endif + } + + void placeFence() + { +#ifdef GL_ARB_sync + if (mSync) + { + glDeleteSync(mSync); + } + mSync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); +#endif + } + + void wait() + { +#ifdef GL_ARB_sync + if (mSync) + { + while (glClientWaitSync(mSync, 0, FENCE_WAIT_TIME_NANOSECONDS) == GL_TIMEOUT_EXPIRED) + { //track the number of times we've waited here + static S32 waits = 0; + waits++; + } + } +#endif + } + + +}; + + +//which power of 2 is i? +//assumes i is a power of 2 > 0 +U32 wpo2(U32 i) +{ + llassert(i > 0); + llassert(nhpo2(i) == i); + + U32 r = 0; + + while (i >>= 1) ++r; + + return r; +} + +volatile U8* LLVBOPool::allocate(U32& name, U32 size) +{ + llassert(nhpo2(size) == size); + + U32 i = wpo2(size); + + if (mFreeList.size() <= i) + { + mFreeList.resize(i+1); + } + + volatile U8* ret = NULL; + + if (mFreeList[i].empty()) + { + //make a new buffer + glGenBuffersARB(1, &name); + glBindBufferARB(mType, name); + LLVertexBuffer::sAllocatedBytes += size; + + if (LLVertexBuffer::sDisableVBOMapping || mUsage != GL_DYNAMIC_DRAW_ARB) + { + glBufferDataARB(mType, size, 0, mUsage); + ret = (U8*) ll_aligned_malloc_16(size); + } + else + { //always use a true hint of static draw when allocating non-client-backed buffers + glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB); + } + + glBindBufferARB(mType, 0); + } + else + { + name = mFreeList[i].front().mGLName; + ret = mFreeList[i].front().mClientData; + + sBytesPooled -= size; + + mFreeList[i].pop_front(); + } + + return ret; +} + +void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size) +{ + llassert(nhpo2(size) == size); + + U32 i = wpo2(size); + + llassert(mFreeList.size() > i); + + Record rec; + rec.mGLName = name; + rec.mClientData = buffer; + + if (buffer == NULL) + { + glDeleteBuffersARB(1, &rec.mGLName); + } + else + { + sBytesPooled += size; + mFreeList[i].push_back(rec); + } +} + +void LLVBOPool::cleanup() +{ + U32 size = 1; + + for (U32 i = 0; i < mFreeList.size(); ++i) + { + record_list_t& l = mFreeList[i]; + + while (!l.empty()) + { + Record& r = l.front(); + + glDeleteBuffersARB(1, &r.mGLName); + + if (r.mClientData) + { + ll_aligned_free_16((void*) r.mClientData); + } + + l.pop_front(); + + LLVertexBuffer::sAllocatedBytes -= size; + sBytesPooled -= size; + } + + size *= 2; + } +} + + +//NOTE: each component must be AT LEAST 4 bytes in size to avoid a performance penalty on AMD hardware +S32 LLVertexBuffer::sTypeSize[LLVertexBuffer::TYPE_MAX] = +{ + sizeof(LLVector4), // TYPE_VERTEX, + sizeof(LLVector4), // TYPE_NORMAL, + sizeof(LLVector2), // TYPE_TEXCOORD0, + sizeof(LLVector2), // TYPE_TEXCOORD1, + sizeof(LLVector2), // TYPE_TEXCOORD2, + sizeof(LLVector2), // TYPE_TEXCOORD3, + sizeof(LLColor4U), // TYPE_COLOR, + sizeof(LLColor4U), // TYPE_EMISSIVE, only alpha is used currently + sizeof(LLVector4), // TYPE_BINORMAL, + sizeof(F32), // TYPE_WEIGHT, + sizeof(LLVector4), // TYPE_WEIGHT4, + sizeof(LLVector4), // TYPE_CLOTHWEIGHT, + sizeof(LLVector4), // TYPE_TEXTURE_INDEX (actually exists as position.w), no extra data, but stride is 16 bytes +}; + +U32 LLVertexBuffer::sGLMode[LLRender::NUM_MODES] = +{ + GL_TRIANGLES, + GL_TRIANGLE_STRIP, + GL_TRIANGLE_FAN, + GL_POINTS, + GL_LINES, + GL_LINE_STRIP, + GL_QUADS, + GL_LINE_LOOP, +}; + + +//static +void LLVertexBuffer::setupClientArrays(U32 data_mask) +{ + if (sLastMask != data_mask) + { + bool error = false; + + if (LLGLSLShader::sNoFixedFunction) + { + for (U32 i = 0; i < TYPE_MAX; ++i) + { + S32 loc = i; + + U32 mask = 1 << i; + + if (sLastMask & (1 << i)) + { //was enabled + if (!(data_mask & mask)) + { //needs to be disabled + glDisableVertexAttribArrayARB(loc); + } + } + else + { //was disabled + if (data_mask & mask) + { //needs to be enabled + glEnableVertexAttribArrayARB(loc); + } + } + } + } + else + { + + GLenum array[] = + { + GL_VERTEX_ARRAY, + GL_NORMAL_ARRAY, + GL_TEXTURE_COORD_ARRAY, + GL_COLOR_ARRAY, + }; + + GLenum mask[] = + { + MAP_VERTEX, + MAP_NORMAL, + MAP_TEXCOORD0, + MAP_COLOR + }; + + + + for (U32 i = 0; i < 4; ++i) + { + if (sLastMask & mask[i]) + { //was enabled + if (!(data_mask & mask[i])) + { //needs to be disabled + glDisableClientState(array[i]); + } + else if (gDebugGL) + { //needs to be enabled, make sure it was (DEBUG) + if (!glIsEnabled(array[i])) + { + if (gDebugSession) + { + error = true; + gFailLog << "Bad client state! " << array[i] << " disabled." << std::endl; + } + else + { + llerrs << "Bad client state! " << array[i] << " disabled." << llendl; + } + } + } + } + else + { //was disabled + if (data_mask & mask[i]) + { //needs to be enabled + glEnableClientState(array[i]); + } + else if (gDebugGL && glIsEnabled(array[i])) + { //needs to be disabled, make sure it was (DEBUG TEMPORARY) + if (gDebugSession) + { + error = true; + gFailLog << "Bad client state! " << array[i] << " enabled." << std::endl; + } + else + { + llerrs << "Bad client state! " << array[i] << " enabled." << llendl; + } + } + } + } + + U32 map_tc[] = + { + MAP_TEXCOORD1, + MAP_TEXCOORD2, + MAP_TEXCOORD3 + }; + + for (U32 i = 0; i < 3; i++) + { + if (sLastMask & map_tc[i]) + { + if (!(data_mask & map_tc[i])) + { //disable + glClientActiveTextureARB(GL_TEXTURE1_ARB+i); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + } + else if (data_mask & map_tc[i]) + { + glClientActiveTextureARB(GL_TEXTURE1_ARB+i); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + } + + if (sLastMask & MAP_BINORMAL) + { + if (!(data_mask & MAP_BINORMAL)) + { + glClientActiveTextureARB(GL_TEXTURE2_ARB); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + } + else if (data_mask & MAP_BINORMAL) + { + glClientActiveTextureARB(GL_TEXTURE2_ARB); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + } + + sLastMask = data_mask; + } +} + +//static +void LLVertexBuffer::drawArrays(U32 mode, const std::vector& pos, const std::vector& norm) +{ + llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShaderPtr != NULL); + gGL.syncMatrices(); + + U32 count = pos.size(); + llassert_always(norm.size() >= pos.size()); + llassert_always(count > 0); + + unbind(); + + setupClientArrays(MAP_VERTEX | MAP_NORMAL); + + LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; + + if (shader) + { + S32 loc = LLVertexBuffer::TYPE_VERTEX; + if (loc > -1) + { + glVertexAttribPointerARB(loc, 3, GL_FLOAT, GL_FALSE, 0, pos[0].mV); + } + loc = LLVertexBuffer::TYPE_NORMAL; + if (loc > -1) + { + glVertexAttribPointerARB(loc, 3, GL_FLOAT, GL_FALSE, 0, norm[0].mV); + } + } + else + { + glVertexPointer(3, GL_FLOAT, 0, pos[0].mV); + glNormalPointer(GL_FLOAT, 0, norm[0].mV); + } + + glDrawArrays(sGLMode[mode], 0, count); +} + +//static +void LLVertexBuffer::drawElements(U32 mode, const LLVector4a* pos, const LLVector2* tc, S32 num_indices, const U16* indicesp) +{ + llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShaderPtr != NULL); + + gGL.syncMatrices(); + + U32 mask = LLVertexBuffer::MAP_VERTEX; + if (tc) + { + mask = mask | LLVertexBuffer::MAP_TEXCOORD0; + } + + unbind(); + + setupClientArrays(mask); + + if (LLGLSLShader::sNoFixedFunction) + { + S32 loc = LLVertexBuffer::TYPE_VERTEX; + glVertexAttribPointerARB(loc, 3, GL_FLOAT, GL_FALSE, 16, pos); + + if (tc) + { + loc = LLVertexBuffer::TYPE_TEXCOORD0; + glVertexAttribPointerARB(loc, 2, GL_FLOAT, GL_FALSE, 0, tc); + } + } + else + { + glTexCoordPointer(2, GL_FLOAT, 0, tc); + glVertexPointer(3, GL_FLOAT, 16, pos); + } + + glDrawElements(sGLMode[mode], num_indices, GL_UNSIGNED_SHORT, indicesp); +} + +void LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_offset) const +{ + if (start >= (U32) mNumVerts || + end >= (U32) mNumVerts) + { + llerrs << "Bad vertex buffer draw range: [" << start << ", " << end << "] vs " << mNumVerts << llendl; + } + + llassert(mNumIndices >= 0); + + if (indices_offset >= (U32) mNumIndices || + indices_offset + count > (U32) mNumIndices) + { + llerrs << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << llendl; + } + + if (gDebugGL && !useVBOs()) + { + U16* idx = ((U16*) getIndicesPointer())+indices_offset; + for (U32 i = 0; i < count; ++i) + { + if (idx[i] < start || idx[i] > end) + { + llerrs << "Index out of range: " << idx[i] << " not in [" << start << ", " << end << "]" << llendl; + } + } + + LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; + + if (shader && shader->mFeatures.mIndexedTextureChannels > 1) + { + LLStrider v; + //hack to get non-const reference + LLVertexBuffer* vb = (LLVertexBuffer*) this; + vb->getVertexStrider(v); + + for (U32 i = start; i < end; i++) + { + S32 idx = (S32) (v[i][3]+0.25f); + if (idx < 0 || idx >= shader->mFeatures.mIndexedTextureChannels) + { + llerrs << "Bad texture index found in vertex data stream." << llendl; + } + } + } + } +} + +void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const +{ + validateRange(start, end, count, indices_offset); + mMappable = false; + gGL.syncMatrices(); + + llassert(mNumVerts >= 0); + llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShaderPtr != NULL); + + if (mGLArray) + { + if (mGLArray != sGLRenderArray) + { + llerrs << "Wrong vertex array bound." << llendl; + } + } + else + { + if (mGLIndices != sGLRenderIndices) + { + llerrs << "Wrong index buffer bound." << llendl; + } + + if (mGLBuffer != sGLRenderBuffer) + { + llerrs << "Wrong vertex buffer bound." << llendl; + } + } + + if (gDebugGL && !mGLArray && useVBOs()) + { + GLint elem = 0; + glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &elem); + + if (elem != mGLIndices) + { + llerrs << "Wrong index buffer bound!" << llendl; + } + } + + if (mode >= LLRender::NUM_MODES) + { + llerrs << "Invalid draw mode: " << mode << llendl; + return; + } + + U16* idx = ((U16*) getIndicesPointer())+indices_offset; + + stop_glerror(); + glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, + idx); + stop_glerror(); + placeFence(); +} + +void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const +{ + llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShaderPtr != NULL); + mMappable = false; + gGL.syncMatrices(); + + llassert(mNumIndices >= 0); + if (indices_offset >= (U32) mNumIndices || + indices_offset + count > (U32) mNumIndices) + { + llerrs << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << llendl; + } + + if (mGLArray) + { + if (mGLArray != sGLRenderArray) + { + llerrs << "Wrong vertex array bound." << llendl; + } + } + else + { + if (mGLIndices != sGLRenderIndices) + { + llerrs << "Wrong index buffer bound." << llendl; + } + + if (mGLBuffer != sGLRenderBuffer) + { + llerrs << "Wrong vertex buffer bound." << llendl; + } + } + + if (mode >= LLRender::NUM_MODES) + { + llerrs << "Invalid draw mode: " << mode << llendl; + return; + } + + stop_glerror(); + glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, + ((U16*) getIndicesPointer()) + indices_offset); + stop_glerror(); + placeFence(); +} + +void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const +{ + llassert(!LLGLSLShader::sNoFixedFunction || LLGLSLShader::sCurBoundShaderPtr != NULL); + mMappable = false; + gGL.syncMatrices(); + + llassert(mNumVerts >= 0); + if (first >= (U32) mNumVerts || + first + count > (U32) mNumVerts) + { + llerrs << "Bad vertex buffer draw range: [" << first << ", " << first+count << "]" << llendl; + } + + if (mGLArray) + { + if (mGLArray != sGLRenderArray) + { + llerrs << "Wrong vertex array bound." << llendl; + } + } + else + { + if (mGLBuffer != sGLRenderBuffer || useVBOs() != sVBOActive) + { + llerrs << "Wrong vertex buffer bound." << llendl; + } + } + + if (mode >= LLRender::NUM_MODES) + { + llerrs << "Invalid draw mode: " << mode << llendl; + return; + } + + stop_glerror(); + glDrawArrays(sGLMode[mode], first, count); + stop_glerror(); + placeFence(); +} + +//static +void LLVertexBuffer::initClass(bool use_vbo, bool no_vbo_mapping) +{ + sEnableVBOs = use_vbo && gGLManager.mHasVertexBufferObject; + sDisableVBOMapping = sEnableVBOs && no_vbo_mapping; + + if (!sPrivatePoolp) + { + sPrivatePoolp = LLPrivateMemoryPoolManager::getInstance()->newPool(LLPrivateMemoryPool::STATIC); + } +} + +//static +void LLVertexBuffer::unbind() +{ + if (sGLRenderArray) + { +#if GL_ARB_vertex_array_object + glBindVertexArray(0); +#endif + sGLRenderArray = 0; + sGLRenderIndices = 0; + sIBOActive = false; + } + + if (sVBOActive) + { + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + sVBOActive = false; + } + if (sIBOActive) + { + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + sIBOActive = false; + } + + sGLRenderBuffer = 0; + sGLRenderIndices = 0; + + setupClientArrays(0); +} + +//static +void LLVertexBuffer::cleanupClass() +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_CLEANUP_CLASS); + unbind(); + + sStreamIBOPool.cleanup(); + sDynamicIBOPool.cleanup(); + sStreamVBOPool.cleanup(); + sDynamicVBOPool.cleanup(); + + if(sPrivatePoolp) + { + LLPrivateMemoryPoolManager::getInstance()->deletePool(sPrivatePoolp); + sPrivatePoolp = NULL; + } +} + +//---------------------------------------------------------------------------- + +S32 LLVertexBuffer::determineUsage(S32 usage) +{ + S32 ret_usage = usage; + + if (!sEnableVBOs) + { + ret_usage = 0; + } + + if (ret_usage == GL_STREAM_DRAW_ARB && !sUseStreamDraw) + { + ret_usage = 0; + } + + if (ret_usage == GL_DYNAMIC_DRAW_ARB && sPreferStreamDraw) + { + ret_usage = GL_STREAM_DRAW_ARB; + } + + if (ret_usage == 0 && LLRender::sGLCoreProfile) + { //MUST use VBOs for all rendering + ret_usage = GL_STREAM_DRAW_ARB; + } + + if (ret_usage && ret_usage != GL_STREAM_DRAW_ARB) + { //only stream_draw and dynamic_draw are supported when using VBOs, dynamic draw is the default + if (sDisableVBOMapping) + { //always use stream draw if VBO mapping is disabled + ret_usage = GL_STREAM_DRAW_ARB; + } + else + { + ret_usage = GL_DYNAMIC_DRAW_ARB; + } + } + + return ret_usage; +} + +LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) : + LLRefCount(), + + mNumVerts(0), + mNumIndices(0), + mAlignedOffset(0), + mAlignedIndexOffset(0), + mSize(0), + mIndicesSize(0), + mTypeMask(typemask), + mUsage(LLVertexBuffer::determineUsage(usage)), + mGLBuffer(0), + mGLIndices(0), + mGLArray(0), + mMappedData(NULL), + mMappedIndexData(NULL), + mMappedDataUsingVBOs(false), + mMappedIndexDataUsingVBOs(false), + mVertexLocked(false), + mIndexLocked(false), + mFinal(false), + mEmpty(true), + mMappable(false), + mFence(NULL) +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_CONSTRUCTOR); + + mMappable = (mUsage == GL_DYNAMIC_DRAW_ARB && !sDisableVBOMapping); + + //zero out offsets + for (U32 i = 0; i < TYPE_MAX; i++) + { + mOffsets[i] = 0; + } + + sCount++; +} + +//static +S32 LLVertexBuffer::calcOffsets(const U32& typemask, S32* offsets, S32 num_vertices) +{ + S32 offset = 0; + for (S32 i=0; iplaceFence(); + }*/ +} + +void LLVertexBuffer::waitFence() const +{ + /*if (mFence) + { + mFence->wait(); + }*/ +} + +//---------------------------------------------------------------------------- + +void LLVertexBuffer::genBuffer(U32 size) +{ + mSize = nhpo2(size); + + if (mUsage == GL_STREAM_DRAW_ARB) + { + mMappedData = sStreamVBOPool.allocate(mGLBuffer, mSize); + } + else + { + mMappedData = sDynamicVBOPool.allocate(mGLBuffer, mSize); + } + + sGLCount++; +} + +void LLVertexBuffer::genIndices(U32 size) +{ + mIndicesSize = nhpo2(size); + + if (mUsage == GL_STREAM_DRAW_ARB) + { + mMappedIndexData = sStreamIBOPool.allocate(mGLIndices, mIndicesSize); + } + else + { + mMappedIndexData = sDynamicIBOPool.allocate(mGLIndices, mIndicesSize); + } + + sGLCount++; +} + +void LLVertexBuffer::releaseBuffer() +{ + if (mUsage == GL_STREAM_DRAW_ARB) + { + sStreamVBOPool.release(mGLBuffer, mMappedData, mSize); + } + else + { + sDynamicVBOPool.release(mGLBuffer, mMappedData, mSize); + } + + mGLBuffer = 0; + mMappedData = NULL; + + sGLCount--; +} + +void LLVertexBuffer::releaseIndices() +{ + if (mUsage == GL_STREAM_DRAW_ARB) + { + sStreamIBOPool.release(mGLIndices, mMappedIndexData, mIndicesSize); + } + else + { + sDynamicIBOPool.release(mGLIndices, mMappedIndexData, mIndicesSize); + } + + mGLIndices = 0; + mMappedIndexData = NULL; + + sGLCount--; +} + +void LLVertexBuffer::createGLBuffer(U32 size) +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_CREATE_VERTICES); + + if (mGLBuffer) + { + destroyGLBuffer(); + } + + if (size == 0) + { + return; + } + + mEmpty = true; + + mMappedDataUsingVBOs = useVBOs(); + + if (mMappedDataUsingVBOs) + { + genBuffer(size); + } + else + { + static int gl_buffer_idx = 0; + mGLBuffer = ++gl_buffer_idx; + mMappedData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); + mSize = size; + } +} + +void LLVertexBuffer::createGLIndices(U32 size) +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_CREATE_INDICES); + + if (mGLIndices) + { + destroyGLIndices(); + } + + if (size == 0) + { + return; + } + + mEmpty = true; + + //pad by 16 bytes for aligned copies + size += 16; + + mMappedIndexDataUsingVBOs = useVBOs(); + + if (mMappedIndexDataUsingVBOs) + { + //pad by another 16 bytes for VBO pointer adjustment + size += 16; + genIndices(size); + } + else + { + mMappedIndexData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); + static int gl_buffer_idx = 0; + mGLIndices = ++gl_buffer_idx; + mIndicesSize = size; + } +} + +void LLVertexBuffer::destroyGLBuffer() +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_DESTROY_BUFFER); + if (mGLBuffer) + { + if (mMappedDataUsingVBOs) + { + releaseBuffer(); + } + else + { + FREE_MEM(sPrivatePoolp, (void*) mMappedData); + mMappedData = NULL; + mEmpty = true; + } + } + + mGLBuffer = 0; + //unbind(); +} + +void LLVertexBuffer::destroyGLIndices() +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_DESTROY_INDICES); + if (mGLIndices) + { + if (mMappedIndexDataUsingVBOs) + { + releaseIndices(); + } + else + { + FREE_MEM(sPrivatePoolp, (void*) mMappedIndexData); + mMappedIndexData = NULL; + mEmpty = true; + } + } + + mGLIndices = 0; + //unbind(); +} + +void LLVertexBuffer::updateNumVerts(S32 nverts) +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_UPDATE_VERTS); + + llassert(nverts >= 0); + + if (nverts >= 65535) + { + llwarns << "Vertex buffer overflow!" << llendl; + nverts = 65535; + } + + U32 needed_size = calcOffsets(mTypeMask, mOffsets, nverts); + + if (needed_size > mSize || needed_size <= mSize/2) + { + createGLBuffer(needed_size); + } + + mNumVerts = nverts; +} + +void LLVertexBuffer::updateNumIndices(S32 nindices) +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_UPDATE_INDICES); + + llassert(nindices >= 0); + + U32 needed_size = sizeof(U16) * nindices; + + if (needed_size > mIndicesSize || needed_size <= mIndicesSize/2) + { + createGLIndices(needed_size); + } + + mNumIndices = nindices; +} + +void LLVertexBuffer::allocateBuffer(S32 nverts, S32 nindices, bool create) +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_ALLOCATE_BUFFER); + + stop_glerror(); + + if (nverts < 0 || nindices < 0 || + nverts > 65536) + { + llerrs << "Bad vertex buffer allocation: " << nverts << " : " << nindices << llendl; + } + + updateNumVerts(nverts); + updateNumIndices(nindices); + + if (create && (nverts || nindices)) + { + //actually allocate space for the vertex buffer if using VBO mapping + flush(); + + if (gGLManager.mHasVertexArrayObject && useVBOs() && (LLRender::sGLCoreProfile || sUseVAO)) + { +#if GL_ARB_vertex_array_object + glGenVertexArrays(1, &mGLArray); +#endif + setupVertexArray(); + } + } +} + +static LLFastTimer::DeclareTimer FTM_SETUP_VERTEX_ARRAY("Setup VAO"); + +void LLVertexBuffer::setupVertexArray() +{ + if (!mGLArray) + { + return; + } + + LLFastTimer t(FTM_SETUP_VERTEX_ARRAY); +#if GL_ARB_vertex_array_object + glBindVertexArray(mGLArray); +#endif + sGLRenderArray = mGLArray; + + U32 attrib_size[] = + { + 3, //TYPE_VERTEX, + 3, //TYPE_NORMAL, + 2, //TYPE_TEXCOORD0, + 2, //TYPE_TEXCOORD1, + 2, //TYPE_TEXCOORD2, + 2, //TYPE_TEXCOORD3, + 4, //TYPE_COLOR, + 4, //TYPE_EMISSIVE, + 3, //TYPE_BINORMAL, + 1, //TYPE_WEIGHT, + 4, //TYPE_WEIGHT4, + 4, //TYPE_CLOTHWEIGHT, + 1, //TYPE_TEXTURE_INDEX + }; + + U32 attrib_type[] = + { + GL_FLOAT, //TYPE_VERTEX, + GL_FLOAT, //TYPE_NORMAL, + GL_FLOAT, //TYPE_TEXCOORD0, + GL_FLOAT, //TYPE_TEXCOORD1, + GL_FLOAT, //TYPE_TEXCOORD2, + GL_FLOAT, //TYPE_TEXCOORD3, + GL_UNSIGNED_BYTE, //TYPE_COLOR, + GL_UNSIGNED_BYTE, //TYPE_EMISSIVE, + GL_FLOAT, //TYPE_BINORMAL, + GL_FLOAT, //TYPE_WEIGHT, + GL_FLOAT, //TYPE_WEIGHT4, + GL_FLOAT, //TYPE_CLOTHWEIGHT, + GL_FLOAT, //TYPE_TEXTURE_INDEX + }; + + U32 attrib_normalized[] = + { + GL_FALSE, //TYPE_VERTEX, + GL_FALSE, //TYPE_NORMAL, + GL_FALSE, //TYPE_TEXCOORD0, + GL_FALSE, //TYPE_TEXCOORD1, + GL_FALSE, //TYPE_TEXCOORD2, + GL_FALSE, //TYPE_TEXCOORD3, + GL_TRUE, //TYPE_COLOR, + GL_TRUE, //TYPE_EMISSIVE, + GL_FALSE, //TYPE_BINORMAL, + GL_FALSE, //TYPE_WEIGHT, + GL_FALSE, //TYPE_WEIGHT4, + GL_FALSE, //TYPE_CLOTHWEIGHT, + GL_FALSE, //TYPE_TEXTURE_INDEX + }; + + bindGLBuffer(true); + bindGLIndices(true); + + for (U32 i = 0; i < TYPE_MAX; ++i) + { + if (mTypeMask & (1 << i)) + { + glEnableVertexAttribArrayARB(i); + glVertexAttribPointerARB(i, attrib_size[i], attrib_type[i], attrib_normalized[i], sTypeSize[i], (void*) mOffsets[i]); + } + else + { + glDisableVertexAttribArrayARB(i); + } + } + + //draw a dummy triangle to set index array pointer + //glDrawElements(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT, NULL); + + unbind(); +} + +void LLVertexBuffer::resizeBuffer(S32 newnverts, S32 newnindices) +{ + llassert(newnverts >= 0); + llassert(newnindices >= 0); + + LLMemType mt2(LLMemType::MTYPE_VERTEX_RESIZE_BUFFER); + + updateNumVerts(newnverts); + updateNumIndices(newnindices); + + if (useVBOs()) + { + flush(); + + if (mGLArray) + { //if size changed, offsets changed + setupVertexArray(); + } + } +} + +bool LLVertexBuffer::useVBOs() const +{ + //it's generally ineffective to use VBO for things that are streaming on apple + return (mUsage != 0); +} + +//---------------------------------------------------------------------------- + +bool expand_region(LLVertexBuffer::MappedRegion& region, S32 index, S32 count) +{ + S32 end = index+count; + S32 region_end = region.mIndex+region.mCount; + + if (end < region.mIndex || + index > region_end) + { //gap exists, do not merge + return false; + } + + S32 new_end = llmax(end, region_end); + S32 new_index = llmin(index, region.mIndex); + region.mIndex = new_index; + region.mCount = new_end-new_index; + return true; +} + +static LLFastTimer::DeclareTimer FTM_VBO_MAP_BUFFER_RANGE("VBO Map Range"); +static LLFastTimer::DeclareTimer FTM_VBO_MAP_BUFFER("VBO Map"); + +// Map for data access +volatile U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_range) +{ + bindGLBuffer(true); + LLMemType mt2(LLMemType::MTYPE_VERTEX_MAP_BUFFER); + if (mFinal) + { + llerrs << "LLVertexBuffer::mapVeretxBuffer() called on a finalized buffer." << llendl; + } + if (!useVBOs() && !mMappedData && !mMappedIndexData) + { + llerrs << "LLVertexBuffer::mapVertexBuffer() called on unallocated buffer." << llendl; + } + + if (useVBOs()) + { + if (!mMappable || gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange) + { + if (count == -1) + { + count = mNumVerts-index; + } + + bool mapped = false; + //see if range is already mapped + for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) + { + MappedRegion& region = mMappedVertexRegions[i]; + if (region.mType == type) + { + if (expand_region(region, index, count)) + { + mapped = true; + break; + } + } + } + + if (!mapped) + { + //not already mapped, map new region + MappedRegion region(type, mMappable && map_range ? -1 : index, count); + mMappedVertexRegions.push_back(region); + } + } + + if (mVertexLocked && map_range) + { + llerrs << "Attempted to map a specific range of a buffer that was already mapped." << llendl; + } + + if (!mVertexLocked) + { + LLMemType mt_v(LLMemType::MTYPE_VERTEX_MAP_BUFFER_VERTICES); + mVertexLocked = true; + sMappedCount++; + stop_glerror(); + + if(!mMappable) + { + map_range = false; + } + else + { + volatile U8* src = NULL; + waitFence(); + if (gGLManager.mHasMapBufferRange) + { + if (map_range) + { +#ifdef GL_ARB_map_buffer_range + LLFastTimer t(FTM_VBO_MAP_BUFFER_RANGE); + S32 offset = mOffsets[type] + sTypeSize[type]*index; + S32 length = (sTypeSize[type]*count+0xF) & ~0xF; + src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER_ARB, offset, length, + GL_MAP_WRITE_BIT | + GL_MAP_FLUSH_EXPLICIT_BIT | + GL_MAP_INVALIDATE_RANGE_BIT); +#endif + } + else + { +#ifdef GL_ARB_map_buffer_range + + if (gDebugGL) + { + GLint size = 0; + glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); + + if (size < mSize) + { + llerrs << "Invalid buffer size." << llendl; + } + } + + LLFastTimer t(FTM_VBO_MAP_BUFFER); + src = (U8*) glMapBufferRange(GL_ARRAY_BUFFER_ARB, 0, mSize, + GL_MAP_WRITE_BIT | + GL_MAP_FLUSH_EXPLICIT_BIT); +#endif + } + } + else if (gGLManager.mHasFlushBufferRange) + { + if (map_range) + { + glBufferParameteriAPPLE(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE); + glBufferParameteriAPPLE(GL_ARRAY_BUFFER_ARB, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); + src = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + } + else + { + src = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + } + } + else + { + map_range = false; + src = (U8*) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + } + + llassert(src != NULL); + + mMappedData = LL_NEXT_ALIGNED_ADDRESS(src); + mAlignedOffset = mMappedData - src; + + stop_glerror(); + } + + if (!mMappedData) + { + log_glerror(); + + //check the availability of memory + LLMemory::logMemoryInfo(true); + + if(mMappable) + { + //-------------------- + //print out more debug info before crash + llinfos << "vertex buffer size: (num verts : num indices) = " << getNumVerts() << " : " << getNumIndices() << llendl; + GLint size; + glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &size); + llinfos << "GL_ARRAY_BUFFER_ARB size is " << size << llendl; + //-------------------- + + GLint buff; + glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &buff); + if ((GLuint)buff != mGLBuffer) + { + llerrs << "Invalid GL vertex buffer bound: " << buff << llendl; + } + + + llerrs << "glMapBuffer returned NULL (no vertex data)" << llendl; + } + else + { + llerrs << "memory allocation for vertex data failed." << llendl; + } + } + } + } + else + { + map_range = false; + } + + if (map_range && gGLManager.mHasMapBufferRange && mMappable) + { + return mMappedData; + } + else + { + return mMappedData+mOffsets[type]+sTypeSize[type]*index; + } +} + + +static LLFastTimer::DeclareTimer FTM_VBO_MAP_INDEX_RANGE("IBO Map Range"); +static LLFastTimer::DeclareTimer FTM_VBO_MAP_INDEX("IBO Map"); + +volatile U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_MAP_BUFFER); + bindGLIndices(true); + if (mFinal) + { + llerrs << "LLVertexBuffer::mapIndexBuffer() called on a finalized buffer." << llendl; + } + if (!useVBOs() && !mMappedData && !mMappedIndexData) + { + llerrs << "LLVertexBuffer::mapIndexBuffer() called on unallocated buffer." << llendl; + } + + if (useVBOs()) + { + if (!mMappable || gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange) + { + if (count == -1) + { + count = mNumIndices-index; + } + + bool mapped = false; + //see if range is already mapped + for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + { + MappedRegion& region = mMappedIndexRegions[i]; + if (expand_region(region, index, count)) + { + mapped = true; + break; + } + } + + if (!mapped) + { + //not already mapped, map new region + MappedRegion region(TYPE_INDEX, mMappable && map_range ? -1 : index, count); + mMappedIndexRegions.push_back(region); + } + } + + if (mIndexLocked && map_range) + { + llerrs << "Attempted to map a specific range of a buffer that was already mapped." << llendl; + } + + if (!mIndexLocked) + { + LLMemType mt_v(LLMemType::MTYPE_VERTEX_MAP_BUFFER_INDICES); + + mIndexLocked = true; + sMappedCount++; + stop_glerror(); + + if (gDebugGL && useVBOs()) + { + GLint elem = 0; + glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &elem); + + if (elem != mGLIndices) + { + llerrs << "Wrong index buffer bound!" << llendl; + } + } + + if(!mMappable) + { + map_range = false; + } + else + { + volatile U8* src = NULL; + waitFence(); + if (gGLManager.mHasMapBufferRange) + { + if (map_range) + { +#ifdef GL_ARB_map_buffer_range + LLFastTimer t(FTM_VBO_MAP_INDEX_RANGE); + S32 offset = sizeof(U16)*index; + S32 length = sizeof(U16)*count; + src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, + GL_MAP_WRITE_BIT | + GL_MAP_FLUSH_EXPLICIT_BIT | + GL_MAP_INVALIDATE_RANGE_BIT); +#endif + } + else + { +#ifdef GL_ARB_map_buffer_range + LLFastTimer t(FTM_VBO_MAP_INDEX); + src = (U8*) glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, sizeof(U16)*mNumIndices, + GL_MAP_WRITE_BIT | + GL_MAP_FLUSH_EXPLICIT_BIT); +#endif + } + } + else if (gGLManager.mHasFlushBufferRange) + { + if (map_range) + { + glBufferParameteriAPPLE(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE); + glBufferParameteriAPPLE(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); + src = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + } + else + { + src = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + } + } + else + { + LLFastTimer t(FTM_VBO_MAP_INDEX); + map_range = false; + src = (U8*) glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + } + + llassert(src != NULL); + + + mMappedIndexData = src; //LL_NEXT_ALIGNED_ADDRESS(src); + mAlignedIndexOffset = mMappedIndexData - src; + stop_glerror(); + } + } + + if (!mMappedIndexData) + { + log_glerror(); + LLMemory::logMemoryInfo(true); + + if(mMappable) + { + GLint buff; + glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &buff); + if ((GLuint)buff != mGLIndices) + { + llerrs << "Invalid GL index buffer bound: " << buff << llendl; + } + + llerrs << "glMapBuffer returned NULL (no index data)" << llendl; + } + else + { + llerrs << "memory allocation for Index data failed. " << llendl; + } + } + } + else + { + map_range = false; + } + + if (map_range && gGLManager.mHasMapBufferRange && mMappable) + { + return mMappedIndexData; + } + else + { + return mMappedIndexData + sizeof(U16)*index; + } +} + +static LLFastTimer::DeclareTimer FTM_VBO_UNMAP("VBO Unmap"); +static LLFastTimer::DeclareTimer FTM_VBO_FLUSH_RANGE("Flush VBO Range"); + + +static LLFastTimer::DeclareTimer FTM_IBO_UNMAP("IBO Unmap"); +static LLFastTimer::DeclareTimer FTM_IBO_FLUSH_RANGE("Flush IBO Range"); + +void LLVertexBuffer::unmapBuffer() +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_UNMAP_BUFFER); + if (!useVBOs()) + { + return; //nothing to unmap + } + + bool updated_all = false; + + if (mMappedData && mVertexLocked) + { + LLFastTimer t(FTM_VBO_UNMAP); + bindGLBuffer(true); + updated_all = mIndexLocked; //both vertex and index buffers done updating + + if(!mMappable) + { + if (!mMappedVertexRegions.empty()) + { + stop_glerror(); + for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) + { + const MappedRegion& region = mMappedVertexRegions[i]; + S32 offset = region.mIndex >= 0 ? mOffsets[region.mType]+sTypeSize[region.mType]*region.mIndex : 0; + S32 length = sTypeSize[region.mType]*region.mCount; + glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, offset, length, (U8*) mMappedData+offset); + stop_glerror(); + } + + mMappedVertexRegions.clear(); + } + else + { + stop_glerror(); + glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, getSize(), (U8*) mMappedData); + stop_glerror(); + } + } + else + { + if (gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange) + { + if (!mMappedVertexRegions.empty()) + { + stop_glerror(); + for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) + { + const MappedRegion& region = mMappedVertexRegions[i]; + S32 offset = region.mIndex >= 0 ? mOffsets[region.mType]+sTypeSize[region.mType]*region.mIndex : 0; + S32 length = sTypeSize[region.mType]*region.mCount; + if (gGLManager.mHasMapBufferRange) + { + LLFastTimer t(FTM_VBO_FLUSH_RANGE); +#ifdef GL_ARB_map_buffer_range + glFlushMappedBufferRange(GL_ARRAY_BUFFER_ARB, offset, length); +#endif + } + else if (gGLManager.mHasFlushBufferRange) + { + glFlushMappedBufferRangeAPPLE(GL_ARRAY_BUFFER_ARB, offset, length); + } + stop_glerror(); + } + + mMappedVertexRegions.clear(); + } + } + stop_glerror(); + glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); + stop_glerror(); + + mMappedData = NULL; + } + + mVertexLocked = false; + sMappedCount--; + } + + if (mMappedIndexData && mIndexLocked) + { + LLFastTimer t(FTM_IBO_UNMAP); + bindGLIndices(); + if(!mMappable) + { + if (!mMappedIndexRegions.empty()) + { + for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + { + const MappedRegion& region = mMappedIndexRegions[i]; + S32 offset = region.mIndex >= 0 ? sizeof(U16)*region.mIndex : 0; + S32 length = sizeof(U16)*region.mCount; + glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, (U8*) mMappedIndexData+offset); + stop_glerror(); + } + + mMappedIndexRegions.clear(); + } + else + { + stop_glerror(); + glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, getIndicesSize(), (U8*) mMappedIndexData); + stop_glerror(); + } + } + else + { + if (gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange) + { + if (!mMappedIndexRegions.empty()) + { + for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + { + const MappedRegion& region = mMappedIndexRegions[i]; + S32 offset = region.mIndex >= 0 ? sizeof(U16)*region.mIndex : 0; + S32 length = sizeof(U16)*region.mCount; + if (gGLManager.mHasMapBufferRange) + { + LLFastTimer t(FTM_IBO_FLUSH_RANGE); +#ifdef GL_ARB_map_buffer_range + glFlushMappedBufferRange(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length); +#endif + } + else if (gGLManager.mHasFlushBufferRange) + { +#ifdef GL_APPLE_flush_buffer_range + glFlushMappedBufferRangeAPPLE(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length); +#endif + } + stop_glerror(); + } + + mMappedIndexRegions.clear(); + } + } + stop_glerror(); + glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); + stop_glerror(); + + mMappedIndexData = NULL; + } + + mIndexLocked = false; + sMappedCount--; + } + + if(updated_all) + { + mEmpty = false; + } +} + +//---------------------------------------------------------------------------- + +template struct VertexBufferStrider +{ + typedef LLStrider strider_t; + static bool get(LLVertexBuffer& vbo, + strider_t& strider, + S32 index, S32 count, bool map_range) + { + if (type == LLVertexBuffer::TYPE_INDEX) + { + volatile U8* ptr = vbo.mapIndexBuffer(index, count, map_range); + + if (ptr == NULL) + { + llwarns << "mapIndexBuffer failed!" << llendl; + return false; + } + + strider = (T*)ptr; + strider.setStride(0); + return true; + } + else if (vbo.hasDataType(type)) + { + S32 stride = LLVertexBuffer::sTypeSize[type]; + + volatile U8* ptr = vbo.mapVertexBuffer(type, index, count, map_range); + + if (ptr == NULL) + { + llwarns << "mapVertexBuffer failed!" << llendl; + return false; + } + + strider = (T*)ptr; + strider.setStride(stride); + return true; + } + else + { + llerrs << "VertexBufferStrider could not find valid vertex data." << llendl; + } + return false; + } +}; + +bool LLVertexBuffer::getVertexStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} +bool LLVertexBuffer::getVertexStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} +bool LLVertexBuffer::getIndexStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} +bool LLVertexBuffer::getTexCoord0Strider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} +bool LLVertexBuffer::getTexCoord1Strider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} + +bool LLVertexBuffer::getNormalStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} +bool LLVertexBuffer::getBinormalStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} +bool LLVertexBuffer::getColorStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} +bool LLVertexBuffer::getEmissiveStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} +bool LLVertexBuffer::getWeightStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} + +bool LLVertexBuffer::getWeight4Strider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} + +bool LLVertexBuffer::getClothWeightStrider(LLStrider& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider::get(*this, strider, index, count, map_range); +} + +//---------------------------------------------------------------------------- + +static LLFastTimer::DeclareTimer FTM_BIND_GL_ARRAY("Bind Array"); +bool LLVertexBuffer::bindGLArray() +{ + if (mGLArray && sGLRenderArray != mGLArray) + { + { + LLFastTimer t(FTM_BIND_GL_ARRAY); +#if GL_ARB_vertex_array_object + glBindVertexArray(mGLArray); +#endif + sGLRenderArray = mGLArray; + } + + //really shouldn't be necessary, but some drivers don't properly restore the + //state of GL_ELEMENT_ARRAY_BUFFER_BINDING + bindGLIndices(); + + return true; + } + + return false; +} + +static LLFastTimer::DeclareTimer FTM_BIND_GL_BUFFER("Bind Buffer"); + +bool LLVertexBuffer::bindGLBuffer(bool force_bind) +{ + bindGLArray(); + + bool ret = false; + + if (useVBOs() && (force_bind || (mGLBuffer && (mGLBuffer != sGLRenderBuffer || !sVBOActive)))) + { + LLFastTimer t(FTM_BIND_GL_BUFFER); + /*if (sMapped) + { + llerrs << "VBO bound while another VBO mapped!" << llendl; + }*/ + glBindBufferARB(GL_ARRAY_BUFFER_ARB, mGLBuffer); + sGLRenderBuffer = mGLBuffer; + sBindCount++; + sVBOActive = true; + + if (mGLArray) + { + llassert(sGLRenderArray == mGLArray); + //mCachedRenderBuffer = mGLBuffer; + } + + ret = true; + } + + return ret; +} + +static LLFastTimer::DeclareTimer FTM_BIND_GL_INDICES("Bind Indices"); + +bool LLVertexBuffer::bindGLIndices(bool force_bind) +{ + bindGLArray(); + + bool ret = false; + if (useVBOs() && (force_bind || (mGLIndices && (mGLIndices != sGLRenderIndices || !sIBOActive)))) + { + LLFastTimer t(FTM_BIND_GL_INDICES); + /*if (sMapped) + { + llerrs << "VBO bound while another VBO mapped!" << llendl; + }*/ + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mGLIndices); + sGLRenderIndices = mGLIndices; + stop_glerror(); + sBindCount++; + sIBOActive = true; + ret = true; + } + + return ret; +} + +void LLVertexBuffer::flush() +{ + if (useVBOs()) + { + unmapBuffer(); + } +} + +// Set for rendering +void LLVertexBuffer::setBuffer(U32 data_mask) +{ + flush(); + + LLMemType mt2(LLMemType::MTYPE_VERTEX_SET_BUFFER); + //set up pointers if the data mask is different ... + bool setup = (sLastMask != data_mask); + + if (gDebugGL && data_mask != 0) + { //make sure data requirements are fulfilled + LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; + if (shader) + { + U32 required_mask = 0; + for (U32 i = 0; i < LLVertexBuffer::TYPE_TEXTURE_INDEX; ++i) + { + if (shader->getAttribLocation(i) > -1) + { + U32 required = 1 << i; + if ((data_mask & required) == 0) + { + llwarns << "Missing attribute: " << LLShaderMgr::instance()->mReservedAttribs[i] << llendl; + } + + required_mask |= required; + } + } + + if ((data_mask & required_mask) != required_mask) + { + llerrs << "Shader consumption mismatches data provision." << llendl; + } + } + } + + if (useVBOs()) + { + if (mGLArray) + { + bindGLArray(); + setup = false; //do NOT perform pointer setup if using VAO + } + else + { + const bool bindBuffer = bindGLBuffer(); + const bool bindIndices = bindGLIndices(); + + setup = setup || bindBuffer || bindIndices; + } + + bool error = false; + if (gDebugGL && !mGLArray) + { + GLint buff; + glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &buff); + if ((GLuint)buff != mGLBuffer) + { + if (gDebugSession) + { + error = true; + gFailLog << "Invalid GL vertex buffer bound: " << buff << std::endl; + } + else + { + llerrs << "Invalid GL vertex buffer bound: " << buff << llendl; + } + } + + if (mGLIndices) + { + glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &buff); + if ((GLuint)buff != mGLIndices) + { + if (gDebugSession) + { + error = true; + gFailLog << "Invalid GL index buffer bound: " << buff << std::endl; + } + else + { + llerrs << "Invalid GL index buffer bound: " << buff << llendl; + } + } + } + } + + + } + else + { + if (sGLRenderArray) + { +#if GL_ARB_vertex_array_object + glBindVertexArray(0); +#endif + sGLRenderArray = 0; + sGLRenderIndices = 0; + sIBOActive = false; + } + + if (mGLBuffer) + { + if (sVBOActive) + { + glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); + sBindCount++; + sVBOActive = false; + setup = true; // ... or a VBO is deactivated + } + if (sGLRenderBuffer != mGLBuffer) + { + sGLRenderBuffer = mGLBuffer; + setup = true; // ... or a client memory pointer changed + } + } + if (mGLIndices) + { + if (sIBOActive) + { + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + sBindCount++; + sIBOActive = false; + } + + sGLRenderIndices = mGLIndices; + } + } + + if (!mGLArray) + { + setupClientArrays(data_mask); + } + + if (mGLBuffer) + { + if (data_mask && setup) + { + setupVertexBuffer(data_mask); // subclass specific setup (virtual function) + sSetCount++; + } + } +} + +// virtual (default) +void LLVertexBuffer::setupVertexBuffer(U32 data_mask) +{ + LLMemType mt2(LLMemType::MTYPE_VERTEX_SETUP_VERTEX_BUFFER); + stop_glerror(); + volatile U8* base = useVBOs() ? (U8*) mAlignedOffset : mMappedData; + + /*if ((data_mask & mTypeMask) != data_mask) + { + llerrs << "LLVertexBuffer::setupVertexBuffer missing required components for supplied data mask." << llendl; + }*/ + + if (LLGLSLShader::sNoFixedFunction) + { + if (data_mask & MAP_NORMAL) + { + S32 loc = TYPE_NORMAL; + void* ptr = (void*)(base + mOffsets[TYPE_NORMAL]); + glVertexAttribPointerARB(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL], ptr); + } + if (data_mask & MAP_TEXCOORD3) + { + S32 loc = TYPE_TEXCOORD3; + void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD3]); + glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], ptr); + } + if (data_mask & MAP_TEXCOORD2) + { + S32 loc = TYPE_TEXCOORD2; + void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD2]); + glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], ptr); + } + if (data_mask & MAP_TEXCOORD1) + { + S32 loc = TYPE_TEXCOORD1; + void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD1]); + glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], ptr); + } + if (data_mask & MAP_BINORMAL) + { + S32 loc = TYPE_BINORMAL; + void* ptr = (void*)(base + mOffsets[TYPE_BINORMAL]); + glVertexAttribPointerARB(loc, 3,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_BINORMAL], ptr); + } + if (data_mask & MAP_TEXCOORD0) + { + S32 loc = TYPE_TEXCOORD0; + void* ptr = (void*)(base + mOffsets[TYPE_TEXCOORD0]); + glVertexAttribPointerARB(loc,2,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], ptr); + } + if (data_mask & MAP_COLOR) + { + S32 loc = TYPE_COLOR; + void* ptr = (void*)(base + mOffsets[TYPE_COLOR]); + glVertexAttribPointerARB(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_COLOR], ptr); + } + if (data_mask & MAP_EMISSIVE) + { + S32 loc = TYPE_EMISSIVE; + void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE]); + glVertexAttribPointerARB(loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE], ptr); + } + if (data_mask & MAP_WEIGHT) + { + S32 loc = TYPE_WEIGHT; + void* ptr = (void*)(base + mOffsets[TYPE_WEIGHT]); + glVertexAttribPointerARB(loc, 1, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT], ptr); + } + if (data_mask & MAP_WEIGHT4) + { + S32 loc = TYPE_WEIGHT4; + void* ptr = (void*)(base+mOffsets[TYPE_WEIGHT4]); + glVertexAttribPointerARB(loc, 4, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_WEIGHT4], ptr); + } + if (data_mask & MAP_CLOTHWEIGHT) + { + S32 loc = TYPE_CLOTHWEIGHT; + void* ptr = (void*)(base + mOffsets[TYPE_CLOTHWEIGHT]); + glVertexAttribPointerARB(loc, 4, GL_FLOAT, GL_TRUE, LLVertexBuffer::sTypeSize[TYPE_CLOTHWEIGHT], ptr); + } + if (data_mask & MAP_TEXTURE_INDEX) + { + S32 loc = TYPE_TEXTURE_INDEX; + void *ptr = (void*) (base + mOffsets[TYPE_VERTEX] + 12); + glVertexAttribPointerARB(loc, 1, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); + } + if (data_mask & MAP_VERTEX) + { + S32 loc = TYPE_VERTEX; + void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); + glVertexAttribPointerARB(loc, 3,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); + } + } + else + { + if (data_mask & MAP_NORMAL) + { + glNormalPointer(GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_NORMAL], (void*)(base + mOffsets[TYPE_NORMAL])); + } + if (data_mask & MAP_TEXCOORD3) + { + glClientActiveTextureARB(GL_TEXTURE3_ARB); + glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD3], (void*)(base + mOffsets[TYPE_TEXCOORD3])); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + if (data_mask & MAP_TEXCOORD2) + { + glClientActiveTextureARB(GL_TEXTURE2_ARB); + glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD2], (void*)(base + mOffsets[TYPE_TEXCOORD2])); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + if (data_mask & MAP_TEXCOORD1) + { + glClientActiveTextureARB(GL_TEXTURE1_ARB); + glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD1], (void*)(base + mOffsets[TYPE_TEXCOORD1])); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + if (data_mask & MAP_BINORMAL) + { + glClientActiveTextureARB(GL_TEXTURE2_ARB); + glTexCoordPointer(3,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_BINORMAL], (void*)(base + mOffsets[TYPE_BINORMAL])); + glClientActiveTextureARB(GL_TEXTURE0_ARB); + } + if (data_mask & MAP_TEXCOORD0) + { + glTexCoordPointer(2,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_TEXCOORD0], (void*)(base + mOffsets[TYPE_TEXCOORD0])); + } + if (data_mask & MAP_COLOR) + { + glColorPointer(4, GL_UNSIGNED_BYTE, LLVertexBuffer::sTypeSize[TYPE_COLOR], (void*)(base + mOffsets[TYPE_COLOR])); + } + if (data_mask & MAP_VERTEX) + { + glVertexPointer(3,GL_FLOAT, LLVertexBuffer::sTypeSize[TYPE_VERTEX], (void*)(base + 0)); + } + } + + llglassertok(); +} + +LLVertexBuffer::MappedRegion::MappedRegion(S32 type, S32 index, S32 count) +: mType(type), mIndex(index), mCount(count) +{ + llassert(mType == LLVertexBuffer::TYPE_INDEX || + mType < LLVertexBuffer::TYPE_TEXTURE_INDEX); +} + + -- cgit v1.2.3 From 154e569923d0caf99fb0d24af8475731f5ceaf33 Mon Sep 17 00:00:00 2001 From: prep Date: Wed, 21 Mar 2012 09:53:32 -0400 Subject: Path-282: Added support for viewing the walkability map for various character types --- indra/llrender/llrendernavprim.cpp | 13 +++++++++++++ indra/llrender/llrendernavprim.h | 2 ++ 2 files changed, 15 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index ebc453a32c..21ba29741e 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -62,6 +62,19 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L gGL.end(); } //============================================================================= +void LLRenderNavPrim::renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, bool overlayMode ) const +{ + LLColor4 cV(color); + gGL.color4fv( cV.mV ); + gGL.begin(LLRender::TRIANGLES); + { + gGL.vertex3fv( a.mV ); + gGL.vertex3fv( b.mV ); + gGL.vertex3fv( c.mV ); + } + gGL.end(); +} +//============================================================================= void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) { pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index 158093690e..b5509d9c5e 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -43,6 +43,8 @@ public: void renderSegment( const LLVector3& start, const LLVector3& end, int color, bool overlayMode ) const; //Draw simple tri void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color, bool overlayMode ) const; + //Draw simple tri + void renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, bool overlayMode ) const; //Draw the contents of vertex buffer void renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ); //Draw a star -- cgit v1.2.3 From 89d20b750cbedc682dd203c0727c9e8fa5ebad6c Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 22 Mar 2012 15:56:00 -0400 Subject: Removed dead code --- indra/llrender/llrendernavprim.cpp | 8 ++++---- indra/llrender/llrendernavprim.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 21ba29741e..fb762b0870 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -35,7 +35,7 @@ //============================================================================= LLRenderNavPrim gRenderNav; //============================================================================= -void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color, bool overlayMode ) const +void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color ) const { LLColor4 colorA( color ); gGL.color3fv( colorA.mV ); @@ -48,7 +48,7 @@ void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& en gGL.end(); } //============================================================================= -void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color, bool overlayMode ) const +void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const { LLColor4 colorA( color ); colorA*=1.25f; @@ -62,7 +62,7 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L gGL.end(); } //============================================================================= -void LLRenderNavPrim::renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, bool overlayMode ) const +void LLRenderNavPrim::renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color ) const { LLColor4 cV(color); gGL.color4fv( cV.mV ); @@ -90,7 +90,7 @@ void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, in star[k] = 0.5f; pt1 = center + star; pt2 = center - star; - renderSegment( pt1, pt2, color, false ); + renderSegment( pt1, pt2, color ); } } //============================================================================= diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index b5509d9c5e..044a20f0fe 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -40,11 +40,11 @@ class LLRenderNavPrim { public: //Draw a line - void renderSegment( const LLVector3& start, const LLVector3& end, int color, bool overlayMode ) const; + void renderSegment( const LLVector3& start, const LLVector3& end, int color ) const; //Draw simple tri - void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color, bool overlayMode ) const; + void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const; //Draw simple tri - void renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, bool overlayMode ) const; + void renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color ) const; //Draw the contents of vertex buffer void renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ); //Draw a star -- cgit v1.2.3 From b73f0f103d433432a661fe416bd4d5ab91991cfc Mon Sep 17 00:00:00 2001 From: prep Date: Tue, 27 Mar 2012 15:33:04 -0400 Subject: Navmesh rendering api update to ll color structs --- indra/llrender/llrendernavprim.cpp | 6 +++--- indra/llrender/llrendernavprim.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index fb762b0870..d6da722e0c 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -35,7 +35,7 @@ //============================================================================= LLRenderNavPrim gRenderNav; //============================================================================= -void LLRenderNavPrim::renderSegment( const LLVector3& start, const LLVector3& end, int color ) const +void LLRenderNavPrim::renderLLSegment( const LLVector3& start, const LLVector3& end, const LLColor4U& color ) const { LLColor4 colorA( color ); gGL.color3fv( colorA.mV ); @@ -81,7 +81,7 @@ void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); } //============================================================================= -void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, int color ) const +void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, const LLColor4U& color ) const { for (int k=0; k<3; k++) { @@ -90,7 +90,7 @@ void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, in star[k] = 0.5f; pt1 = center + star; pt2 = center - star; - renderSegment( pt1, pt2, color ); + renderLLSegment( pt1, pt2, color ); } } //============================================================================= diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index 044a20f0fe..d5899471a6 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -40,7 +40,7 @@ class LLRenderNavPrim { public: //Draw a line - void renderSegment( const LLVector3& start, const LLVector3& end, int color ) const; + void renderLLSegment( const LLVector3& start, const LLVector3& end, const LLColor4U& color ) const; //Draw simple tri void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const; //Draw simple tri @@ -48,7 +48,7 @@ public: //Draw the contents of vertex buffer void renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ); //Draw a star - void renderStar( const LLVector3& center, const float scale, int color ) const; + void renderStar( const LLVector3& center, const float scale, const LLColor4U& color ) const; //Flush the device void flushDevice() { gGL.flush(); } private: -- cgit v1.2.3 From 2388de3f958f019255c1eb50cafb540e87a3ca3a Mon Sep 17 00:00:00 2001 From: prep Date: Tue, 3 Apr 2012 13:06:21 -0400 Subject: Added normal support to navmesh tri renderer. --- indra/llrender/llrendernavprim.cpp | 3 ++- indra/llrender/llrendernavprim.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index d6da722e0c..7dd042271a 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -62,12 +62,13 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L gGL.end(); } //============================================================================= -void LLRenderNavPrim::renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color ) const +void LLRenderNavPrim::renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, const LLVector3& n ) const { LLColor4 cV(color); gGL.color4fv( cV.mV ); gGL.begin(LLRender::TRIANGLES); { + glNormal3f( n.mV[0],n.mV[1],n.mV[2] ); gGL.vertex3fv( a.mV ); gGL.vertex3fv( b.mV ); gGL.vertex3fv( c.mV ); diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index d5899471a6..7fbd02de93 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -43,8 +43,8 @@ public: void renderLLSegment( const LLVector3& start, const LLVector3& end, const LLColor4U& color ) const; //Draw simple tri void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const; - //Draw simple tri - void renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color ) const; + //Draw simple tri + void renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, const LLVector3& n ) const; //Draw the contents of vertex buffer void renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ); //Draw a star -- cgit v1.2.3 From 68a4e0ee992fc6f2f1e3a733788f6fe31b85b549 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 3 Apr 2012 16:12:33 -0500 Subject: Fix build. Axe deprecated glNormal call. Don't show the world just because navmesh isn't checked. --- indra/llrender/llrendernavprim.cpp | 193 ++++++++++++++++++------------------- 1 file changed, 96 insertions(+), 97 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 7dd042271a..56b176d39c 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -1,97 +1,96 @@ -/** - * @file LLRenderNavPrim.cpp - * @brief Renderable primitives used by the pathing library - * - * $LicenseInfo:firstyear=2001&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - - -#include "linden_common.h" -#include "llrendernavprim.h" -#include "llerror.h" -#include "llglheaders.h" -#include "llvertexbuffer.h" -#include "llglslshader.h" - -//============================================================================= -LLRenderNavPrim gRenderNav; -//============================================================================= -void LLRenderNavPrim::renderLLSegment( const LLVector3& start, const LLVector3& end, const LLColor4U& color ) const -{ - LLColor4 colorA( color ); - gGL.color3fv( colorA.mV ); - - gGL.begin(LLRender::LINES); - { - gGL.vertex3fv( start.mV ); - gGL.vertex3fv( end.mV ); - } - gGL.end(); -} -//============================================================================= -void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const -{ - LLColor4 colorA( color ); - colorA*=1.25f; - gGL.color4fv( colorA.mV ); - gGL.begin(LLRender::TRIANGLES); - { - gGL.vertex3fv( a.mV ); - gGL.vertex3fv( b.mV ); - gGL.vertex3fv( c.mV ); - } - gGL.end(); -} -//============================================================================= -void LLRenderNavPrim::renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, const LLVector3& n ) const -{ - LLColor4 cV(color); - gGL.color4fv( cV.mV ); - gGL.begin(LLRender::TRIANGLES); - { - glNormal3f( n.mV[0],n.mV[1],n.mV[2] ); - gGL.vertex3fv( a.mV ); - gGL.vertex3fv( b.mV ); - gGL.vertex3fv( c.mV ); - } - gGL.end(); -} -//============================================================================= -void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) -{ - pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); - pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); -} -//============================================================================= -void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, const LLColor4U& color ) const -{ - for (int k=0; k<3; k++) - { - LLVector3 star, pt1, pt2; - star = LLVector3( 0.0f,0.0f,0.0f); - star[k] = 0.5f; - pt1 = center + star; - pt2 = center - star; - renderLLSegment( pt1, pt2, color ); - } -} -//============================================================================= +/** + * @file LLRenderNavPrim.cpp + * @brief Renderable primitives used by the pathing library + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + + +#include "linden_common.h" +#include "llrendernavprim.h" +#include "llerror.h" +#include "llglheaders.h" +#include "llvertexbuffer.h" +#include "llglslshader.h" + +//============================================================================= +LLRenderNavPrim gRenderNav; +//============================================================================= +void LLRenderNavPrim::renderLLSegment( const LLVector3& start, const LLVector3& end, const LLColor4U& color ) const +{ + LLColor4 colorA( color ); + gGL.color3fv( colorA.mV ); + + gGL.begin(LLRender::LINES); + { + gGL.vertex3fv( start.mV ); + gGL.vertex3fv( end.mV ); + } + gGL.end(); +} +//============================================================================= +void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const +{ + LLColor4 colorA( color ); + colorA*=1.25f; + gGL.color4fv( colorA.mV ); + gGL.begin(LLRender::TRIANGLES); + { + gGL.vertex3fv( a.mV ); + gGL.vertex3fv( b.mV ); + gGL.vertex3fv( c.mV ); + } + gGL.end(); +} +//============================================================================= +void LLRenderNavPrim::renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, const LLVector3& n ) const +{ + LLColor4 cV(color); + gGL.color4fv( cV.mV ); + gGL.begin(LLRender::TRIANGLES); + { + gGL.vertex3fv( a.mV ); + gGL.vertex3fv( b.mV ); + gGL.vertex3fv( c.mV ); + } + gGL.end(); +} +//============================================================================= +void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) +{ + pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); + pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); +} +//============================================================================= +void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, const LLColor4U& color ) const +{ + for (int k=0; k<3; k++) + { + LLVector3 star, pt1, pt2; + star = LLVector3( 0.0f,0.0f,0.0f); + star[k] = 0.5f; + pt1 = center + star; + pt2 = center - star; + renderLLSegment( pt1, pt2, color ); + } +} +//============================================================================= -- cgit v1.2.3 From b752a3a689ea2000398c9f93e801d87a2681223c Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 5 Apr 2012 11:08:31 -0400 Subject: Navmesh edges are now rendered via vertex buffers. Enjoy the speedup! --- indra/llrender/llrendernavprim.cpp | 6 ++ indra/llrender/llrendernavprim.h | 120 +++++++++++++++++++------------------ 2 files changed, 67 insertions(+), 59 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 56b176d39c..2632428dfd 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -81,6 +81,12 @@ void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); } //============================================================================= +void LLRenderNavPrim::renderNavMeshEdgeVB( LLVertexBuffer* pVBO, int vertCnt ) +{ + pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); + pVBO->drawArrays( LLRender::LINES, 0, vertCnt ); +} +//============================================================================= void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, const LLColor4U& color ) const { for (int k=0; k<3; k++) diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index 7fbd02de93..809debb006 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -1,59 +1,61 @@ -/** - * @file LLRenderNavPrim.h - * @brief - * - * $LicenseInfo:firstyear=2001&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_RENDER_NAVPRIM_H -#define LL_RENDER_NAVPRIM_H - -#include "llmath.h" -#include "v3math.h" -#include "v4math.h" -#include "m3math.h" -#include "m4math.h" -#include "v4color.h" -#include "llgl.h" - - -class LLRenderNavPrim -{ -public: - //Draw a line - void renderLLSegment( const LLVector3& start, const LLVector3& end, const LLColor4U& color ) const; - //Draw simple tri - void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const; - //Draw simple tri - void renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, const LLVector3& n ) const; - //Draw the contents of vertex buffer - void renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ); - //Draw a star - void renderStar( const LLVector3& center, const float scale, const LLColor4U& color ) const; - //Flush the device - void flushDevice() { gGL.flush(); } -private: -}; - -extern LLRenderNavPrim gRenderNav; - -#endif +/** + * @file LLRenderNavPrim.h + * @brief + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_RENDER_NAVPRIM_H +#define LL_RENDER_NAVPRIM_H + +#include "llmath.h" +#include "v3math.h" +#include "v4math.h" +#include "m3math.h" +#include "m4math.h" +#include "v4color.h" +#include "llgl.h" + + +class LLRenderNavPrim +{ +public: + //Draw a line + void renderLLSegment( const LLVector3& start, const LLVector3& end, const LLColor4U& color ) const; + //Draw simple tri + void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const; + //Draw simple tri + void renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, const LLVector3& n ) const; + //Draw the contents of vertex buffer + void renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ); + //Draw the contents of the edge vertex buffer + void renderNavMeshEdgeVB( LLVertexBuffer* pVBO, int vertCnt ); + //Draw a star + void renderStar( const LLVector3& center, const float scale, const LLColor4U& color ) const; + //Flush the device + void flushDevice() { gGL.flush(); } +private: +}; + +extern LLRenderNavPrim gRenderNav; + +#endif -- cgit v1.2.3 From fef78653cd2a81efb032d7570fc5e5a0814086b7 Mon Sep 17 00:00:00 2001 From: prep Date: Thu, 5 Apr 2012 14:27:05 -0400 Subject: consolidate navmesh rendering calls --- indra/llrender/llrendernavprim.cpp | 10 ++-------- indra/llrender/llrendernavprim.h | 4 +--- 2 files changed, 3 insertions(+), 11 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 2632428dfd..100b614aae 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -75,16 +75,10 @@ void LLRenderNavPrim::renderLLTri( const LLVector3& a, const LLVector3& b, const gGL.end(); } //============================================================================= -void LLRenderNavPrim::renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ) +void LLRenderNavPrim::renderNavMeshVB( U32 mode, LLVertexBuffer* pVBO, int vertCnt ) { pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); - pVBO->drawArrays( LLRender::TRIANGLES, 0, vertCnt ); -} -//============================================================================= -void LLRenderNavPrim::renderNavMeshEdgeVB( LLVertexBuffer* pVBO, int vertCnt ) -{ - pVBO->setBuffer( LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL ); - pVBO->drawArrays( LLRender::LINES, 0, vertCnt ); + pVBO->drawArrays( mode, 0, vertCnt ); } //============================================================================= void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, const LLColor4U& color ) const diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index 809debb006..97d1c805af 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -46,9 +46,7 @@ public: //Draw simple tri void renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, const LLVector3& n ) const; //Draw the contents of vertex buffer - void renderNavMeshVB( LLVertexBuffer* pVBO, int vertCnt ); - //Draw the contents of the edge vertex buffer - void renderNavMeshEdgeVB( LLVertexBuffer* pVBO, int vertCnt ); + void renderNavMeshVB( U32 mode, LLVertexBuffer* pVBO, int vertCnt ); //Draw a star void renderStar( const LLVector3& center, const float scale, const LLColor4U& color ) const; //Flush the device -- cgit v1.2.3 From 31543e637bcb0e6ddc83d21a3efdbe242fcf9f71 Mon Sep 17 00:00:00 2001 From: prep Date: Tue, 10 Apr 2012 14:34:28 -0400 Subject: Fixed default character width bug. Updated rendertri api for new path rendering bookends. --- indra/llrender/llrendernavprim.cpp | 2 +- indra/llrender/llrendernavprim.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index 100b614aae..c24a09028f 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -62,7 +62,7 @@ void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const L gGL.end(); } //============================================================================= -void LLRenderNavPrim::renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, const LLVector3& n ) const +void LLRenderNavPrim::renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color ) const { LLColor4 cV(color); gGL.color4fv( cV.mV ); diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index 97d1c805af..eb45e259d2 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -43,8 +43,8 @@ public: void renderLLSegment( const LLVector3& start, const LLVector3& end, const LLColor4U& color ) const; //Draw simple tri void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const; - //Draw simple tri - void renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color, const LLVector3& n ) const; + //Draw simple tri + void renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color ) const; //Draw the contents of vertex buffer void renderNavMeshVB( U32 mode, LLVertexBuffer* pVBO, int vertCnt ); //Draw a star -- cgit v1.2.3 From b93a23aa828a2ee6de206fe3c74d1b0f3e116db1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 13 Jun 2012 18:05:56 -0500 Subject: MAINT-1147 Fix for frame stall on region crossing. --- indra/llrender/llimagegl.cpp | 2 ++ indra/llrender/llrendertarget.cpp | 36 ++++++++++++++++++++++++++++++++++++ indra/llrender/llrendertarget.h | 8 ++++++-- 3 files changed, 44 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 793fd4be31..fb03b3f956 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -285,9 +285,11 @@ S32 LLImageGL::dataFormatComponents(S32 dataformat) //---------------------------------------------------------------------------- +static LLFastTimer::DeclareTimer FTM_IMAGE_UPDATE_STATS("Image Stats"); // static void LLImageGL::updateStats(F32 current_time) { + LLFastTimer t(FTM_IMAGE_UPDATE_STATS); sLastFrameTime = current_time; sBoundTextureMemoryInBytes = sCurBoundTextureMemory; sCurBoundTextureMemory = 0; diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 99f0da330c..cc5c232380 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -69,6 +69,42 @@ LLRenderTarget::~LLRenderTarget() release(); } +void LLRenderTarget::resize(U32 resx, U32 resy, U32 color_fmt) +{ + //for accounting, get the number of pixels added/subtracted + S32 pix_diff = (resx*resy)-(mResX*mResY); + + mResX = resx; + mResY = resy; + + for (U32 i = 0; i < mTex.size(); ++i) + { //resize color attachments + gGL.getTexUnit(0)->bindManual(mUsage, mTex[i]); + LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage), 0, color_fmt, mResX, mResY, GL_RGBA, GL_UNSIGNED_BYTE, NULL, false); + sBytesAllocated += pix_diff*4; + } + + if (mDepth) + { //resize depth attachment + if (mStencil) + { + //use render buffers where stencil buffers are in play + glBindRenderbuffer(GL_RENDERBUFFER, mDepth); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, mResX, mResY); + glBindRenderbuffer(GL_RENDERBUFFER, 0); + } + else + { + gGL.getTexUnit(0)->bindManual(mUsage, mDepth); + U32 internal_type = LLTexUnit::getInternalType(mUsage); + LLImageGL::setManualImage(internal_type, 0, GL_DEPTH_COMPONENT24, mResX, mResY, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false); + } + + sBytesAllocated += pix_diff*4; + } +} + + bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, bool stencil, LLTexUnit::eTextureType usage, bool use_fbo, S32 samples) { stop_glerror(); diff --git a/indra/llrender/llrendertarget.h b/indra/llrender/llrendertarget.h index 8360458840..e1a51304f1 100644 --- a/indra/llrender/llrendertarget.h +++ b/indra/llrender/llrendertarget.h @@ -57,8 +57,6 @@ */ -class LLMultisampleBuffer; - class LLRenderTarget { public: @@ -74,6 +72,12 @@ public: //multiple calls will release previously allocated resources bool allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, bool stencil, LLTexUnit::eTextureType usage = LLTexUnit::TT_TEXTURE, bool use_fbo = false, S32 samples = 0); + //resize existing attachments to use new resolution and color format + // CAUTION: if the GL runs out of memory attempting to resize, this render target will be undefined + // DO NOT use for screen space buffers or for scratch space for an image that might be uploaded + // DO use for render targets that resize often and aren't likely to ruin someone's day if they break + void resize(U32 resx, U32 resy, U32 color_fmt); + //add color buffer attachment //limit of 4 color attachments per render target bool addColorAttachment(U32 color_fmt); -- cgit v1.2.3 From 78910cf3016fc55eaf8214640b348df0f8bcdeda Mon Sep 17 00:00:00 2001 From: Todd Stinson Date: Tue, 26 Jun 2012 18:04:19 -0700 Subject: Updating the header licensing comments. --- indra/llrender/llrendernavprim.cpp | 53 +++++++++++++++++++----------------- indra/llrender/llrendernavprim.h | 56 +++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 53 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index c24a09028f..e7bc89396c 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -1,36 +1,39 @@ /** - * @file LLRenderNavPrim.cpp - * @brief Renderable primitives used by the pathing library - * - * $LicenseInfo:firstyear=2001&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ +* @file llrendernavprim.cpp +* @brief Implementation of llrendernavprim +* @author Prep@lindenlab.com +* +* $LicenseInfo:firstyear=2012&license=viewerlgpl$ +* Second Life Viewer Source Code +* Copyright (C) 2012, Linden Research, Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License only. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA +* $/LicenseInfo$ +*/ #include "linden_common.h" + #include "llrendernavprim.h" + #include "llerror.h" #include "llglheaders.h" -#include "llvertexbuffer.h" #include "llglslshader.h" +#include "llvertexbuffer.h" //============================================================================= LLRenderNavPrim gRenderNav; diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index eb45e259d2..a0c5e4005d 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -1,31 +1,31 @@ /** - * @file LLRenderNavPrim.h - * @brief - * - * $LicenseInfo:firstyear=2001&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_RENDER_NAVPRIM_H -#define LL_RENDER_NAVPRIM_H +* @file llrendernavprim.h +* @brief Header file for llrendernavprim +* @author Prep@lindenlab.com +* +* $LicenseInfo:firstyear=2012&license=viewerlgpl$ +* Second Life Viewer Source Code +* Copyright (C) 2012, Linden Research, Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License only. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA +* $/LicenseInfo$ +*/ +#ifndef LL_LLRENDERNAVPRIM_H +#define LL_LLRENDERNAVPRIM_H #include "llmath.h" #include "v3math.h" @@ -56,4 +56,4 @@ private: extern LLRenderNavPrim gRenderNav; -#endif +#endif // LL_LLRENDERNAVPRIM_H -- cgit v1.2.3 From fa562d19cf9bc698ce883191b6eea2af6abc4164 Mon Sep 17 00:00:00 2001 From: Todd Stinson Date: Wed, 27 Jun 2012 18:12:57 -0700 Subject: Removing unreferenced methods from the LLRenderNavPrim class. --- indra/llrender/llrendernavprim.cpp | 46 +++----------------------------------- indra/llrender/llrendernavprim.h | 20 +++++------------ 2 files changed, 8 insertions(+), 58 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrendernavprim.cpp b/indra/llrender/llrendernavprim.cpp index e7bc89396c..ca72964832 100644 --- a/indra/llrender/llrendernavprim.cpp +++ b/indra/llrender/llrendernavprim.cpp @@ -30,41 +30,14 @@ #include "llrendernavprim.h" -#include "llerror.h" -#include "llglheaders.h" -#include "llglslshader.h" +#include "llrender.h" #include "llvertexbuffer.h" +#include "v4coloru.h" +#include "v3math.h" //============================================================================= LLRenderNavPrim gRenderNav; //============================================================================= -void LLRenderNavPrim::renderLLSegment( const LLVector3& start, const LLVector3& end, const LLColor4U& color ) const -{ - LLColor4 colorA( color ); - gGL.color3fv( colorA.mV ); - - gGL.begin(LLRender::LINES); - { - gGL.vertex3fv( start.mV ); - gGL.vertex3fv( end.mV ); - } - gGL.end(); -} -//============================================================================= -void LLRenderNavPrim::renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const -{ - LLColor4 colorA( color ); - colorA*=1.25f; - gGL.color4fv( colorA.mV ); - gGL.begin(LLRender::TRIANGLES); - { - gGL.vertex3fv( a.mV ); - gGL.vertex3fv( b.mV ); - gGL.vertex3fv( c.mV ); - } - gGL.end(); -} -//============================================================================= void LLRenderNavPrim::renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color ) const { LLColor4 cV(color); @@ -84,16 +57,3 @@ void LLRenderNavPrim::renderNavMeshVB( U32 mode, LLVertexBuffer* pVBO, int vertC pVBO->drawArrays( mode, 0, vertCnt ); } //============================================================================= -void LLRenderNavPrim::renderStar( const LLVector3& center, const float scale, const LLColor4U& color ) const -{ - for (int k=0; k<3; k++) - { - LLVector3 star, pt1, pt2; - star = LLVector3( 0.0f,0.0f,0.0f); - star[k] = 0.5f; - pt1 = center + star; - pt2 = center - star; - renderLLSegment( pt1, pt2, color ); - } -} -//============================================================================= diff --git a/indra/llrender/llrendernavprim.h b/indra/llrender/llrendernavprim.h index a0c5e4005d..a3a5dfec3a 100644 --- a/indra/llrender/llrendernavprim.h +++ b/indra/llrender/llrendernavprim.h @@ -27,30 +27,20 @@ #ifndef LL_LLRENDERNAVPRIM_H #define LL_LLRENDERNAVPRIM_H -#include "llmath.h" -#include "v3math.h" -#include "v4math.h" -#include "m3math.h" -#include "m4math.h" -#include "v4color.h" -#include "llgl.h" +#include "stdtypes.h" + +class LLColor4U; +class LLVector3; +class LLVertexBuffer; class LLRenderNavPrim { public: - //Draw a line - void renderLLSegment( const LLVector3& start, const LLVector3& end, const LLColor4U& color ) const; - //Draw simple tri - void renderTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, int color ) const; //Draw simple tri void renderLLTri( const LLVector3& a, const LLVector3& b, const LLVector3& c, const LLColor4U& color ) const; //Draw the contents of vertex buffer void renderNavMeshVB( U32 mode, LLVertexBuffer* pVBO, int vertCnt ); - //Draw a star - void renderStar( const LLVector3& center, const float scale, const LLColor4U& color ) const; - //Flush the device - void flushDevice() { gGL.flush(); } private: }; -- cgit v1.2.3 From 56d563ba7f8ed4a6284627c36f9c55935b7a9ff2 Mon Sep 17 00:00:00 2001 From: "simon@Simon-PC.lindenlab.com" Date: Wed, 11 Jul 2012 17:14:25 -0700 Subject: Fix merge issues - duplicate insertions of code --- indra/llrender/llvertexbuffer.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index ece794b7f1..739b31204d 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -286,7 +286,6 @@ void LLVBOPool::seedPool() allocate(dummy_name, size, true); } } - } } } -- cgit v1.2.3