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 484994b43b65f19d3d64c7ea3760313277e9e138 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 11 Apr 2012 12:20:03 -0500 Subject: MAINT-870 Fix for crash from out of control lawns. --- indra/llrender/llvertexbuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index b4899209c4..879888d185 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -1207,10 +1207,10 @@ void LLVertexBuffer::updateNumVerts(S32 nverts) llassert(nverts >= 0); - if (nverts >= 65535) + if (nverts > 65536) { llwarns << "Vertex buffer overflow!" << llendl; - nverts = 65535; + nverts = 65536; } U32 needed_size = calcOffsets(mTypeMask, mOffsets, nverts); -- cgit v1.2.3 From 3efa013ee4e037c2ba20aaf550aa06bcf578b145 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 13 Apr 2012 11:55:44 -0500 Subject: MAINT-939 Potential fix for crash when editing objects. --- indra/llrender/llgl.cpp | 1 + indra/llrender/llvertexbuffer.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 628a8d6131..013b86f32c 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -1964,6 +1964,7 @@ LLGLState::LLGLState(LLGLenum state, S32 enabled) : case GL_COLOR_MATERIAL: case GL_FOG: case GL_LINE_STIPPLE: + case GL_POLYGON_STIPPLE: mState = 0; break; } diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 879888d185..1b179bdbb1 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -2287,10 +2287,10 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) stop_glerror(); volatile U8* base = useVBOs() ? (U8*) mAlignedOffset : mMappedData; - /*if ((data_mask & mTypeMask) != data_mask) + if (gDebugGL && ((data_mask & mTypeMask) != data_mask)) { llerrs << "LLVertexBuffer::setupVertexBuffer missing required components for supplied data mask." << llendl; - }*/ + } if (LLGLSLShader::sNoFixedFunction) { -- cgit v1.2.3 From 1de63bec5089e64b1bf6bc7eaad95d5210f0fd05 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 13 Apr 2012 15:47:44 -0500 Subject: MAINT-861 Fix for crash on exit due to bad matrix mode --- indra/llrender/llrender.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index b0ddacbb05..51f45ca91e 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -416,12 +416,14 @@ void LLTexUnit::unbind(eTextureType type) if (mIndex < 0) return; + //always flush and activate for consistency + // some code paths assume unbind always flushes and sets the active texture + gGL.flush(); + activate(); + // Disabled caching of binding state. if (mCurrTexType == type) { - gGL.flush(); - - activate(); mCurrTexture = 0; if (LLGLSLShader::sNoFixedFunction && type == LLTexUnit::TT_TEXTURE) { -- 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 c946408519450a577a81e741091bf84e3822a4b6 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 11 May 2012 14:42:29 -0500 Subject: MAINT-586 Starting logging OpenGL version and shader level to simulator --- indra/llrender/llgl.cpp | 7 +++++-- indra/llrender/llgl.h | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 013b86f32c..639d967853 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -558,7 +558,8 @@ bool LLGLManager::initGL() parse_gl_version( &mDriverVersionMajor, &mDriverVersionMinor, &mDriverVersionRelease, - &mDriverVersionVendorString ); + &mDriverVersionVendorString, + &mGLVersionString); mGLVersion = mDriverVersionMajor + mDriverVersionMinor * .1f; @@ -2053,7 +2054,7 @@ void LLGLManager::initGLStates() //////////////////////////////////////////////////////////////////////////////// -void parse_gl_version( S32* major, S32* minor, S32* release, std::string* vendor_specific ) +void parse_gl_version( S32* major, S32* minor, S32* release, std::string* vendor_specific, std::string* version_string ) { // GL_VERSION returns a null-terminated string with the format: // .[.] [] @@ -2069,6 +2070,8 @@ void parse_gl_version( S32* major, S32* minor, S32* release, std::string* vendor return; } + version_string->assign(version); + std::string ver_copy( version ); S32 len = (S32)strlen( version ); /* Flawfinder: ignore */ S32 i = 0; diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h index 5a33c98708..9c3a47bd50 100644 --- a/indra/llrender/llgl.h +++ b/indra/llrender/llgl.h @@ -141,6 +141,7 @@ public: S32 mGLSLVersionMajor; S32 mGLSLVersionMinor; std::string mDriverVersionVendorString; + std::string mGLVersionString; S32 mVRAM; // VRAM in MB S32 mGLMaxVertexRange; @@ -423,7 +424,7 @@ extern LLMatrix4 gGLObliqueProjectionInverse; void init_glstates(); -void parse_gl_version( S32* major, S32* minor, S32* release, std::string* vendor_specific ); +void parse_gl_version( S32* major, S32* minor, S32* release, std::string* vendor_specific, std::string* version_string ); extern BOOL gClothRipple; extern BOOL gHeadlessClient; -- cgit v1.2.3 From 34e7226ac88e14d4cfed6bc0d63da215afe0ac88 Mon Sep 17 00:00:00 2001 From: Kitty Barnett Date: Tue, 15 May 2012 13:13:44 +0200 Subject: STORM-276 FIXED Squiggles overflow line editor height when font size is set to large - Also reduced squiggle width from 6 to 4 and prevented running past the end of a word --- indra/llrender/llfontgl.cpp | 10 ++++++++++ indra/llrender/llfontgl.h | 2 ++ 2 files changed, 12 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp index fccbf37a8d..4dc2fcd714 100644 --- a/indra/llrender/llfontgl.cpp +++ b/indra/llrender/llfontgl.cpp @@ -422,6 +422,16 @@ S32 LLFontGL::renderUTF8(const std::string &text, S32 begin_offset, S32 x, S32 y } // font metrics - override for LLFontFreetype that returns units of virtual pixels +F32 LLFontGL::getAscenderHeight() const +{ + return mFontFreetype->getAscenderHeight() / sScaleY; +} + +F32 LLFontGL::getDescenderHeight() const +{ + return mFontFreetype->getDescenderHeight() / sScaleY; +} + S32 LLFontGL::getLineHeight() const { return llceil(mFontFreetype->getAscenderHeight() / sScaleY) + llceil(mFontFreetype->getDescenderHeight() / sScaleY); diff --git a/indra/llrender/llfontgl.h b/indra/llrender/llfontgl.h index 74bdbb43e7..5ed5d2c4eb 100644 --- a/indra/llrender/llfontgl.h +++ b/indra/llrender/llfontgl.h @@ -115,6 +115,8 @@ public: S32 renderUTF8(const std::string &text, S32 begin_offset, S32 x, S32 y, const LLColor4 &color, HAlign halign, VAlign valign, U8 style = NORMAL, ShadowType shadow = NO_SHADOW) const; // font metrics - override for LLFontFreetype that returns units of virtual pixels + F32 getAscenderHeight() const; + F32 getDescenderHeight() const; S32 getLineHeight() const; S32 getWidth(const std::string& utf8text) const; -- cgit v1.2.3 From 89b0b6ac7198653d989dea78ee1c3d3f4f61161f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 15 May 2012 16:42:04 -0500 Subject: MAINT-616 Different VBO Pooling scheme -- populate VBO pool with buffers that are likely to be requested, but never reuse a previously used buffer. --- indra/llrender/llvertexbuffer.cpp | 79 +++++++++++++++++++++++++++++++++++++-- indra/llrender/llvertexbuffer.h | 16 +++++--- 2 files changed, 85 insertions(+), 10 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 1b179bdbb1..7b12304967 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -38,7 +38,7 @@ #include "llglslshader.h" #include "llmemory.h" -#define LL_VBO_POOLING 0 +#define LL_VBO_POOLING 1 //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 @@ -67,6 +67,7 @@ U32 wpo2(U32 i) const U32 LL_VBO_BLOCK_SIZE = 2048; +const U32 LL_VBO_POOL_MAX_SEED_SIZE = 256*1024; U32 vbo_block_size(U32 size) { //what block size will fit size? @@ -79,6 +80,7 @@ U32 vbo_block_index(U32 size) return vbo_block_size(size)/LL_VBO_BLOCK_SIZE; } +const U32 LL_VBO_POOL_SEED_COUNT = vbo_block_index(LL_VBO_POOL_MAX_SEED_SIZE); //============================================================================ @@ -169,8 +171,15 @@ public: }; +LLVBOPool::LLVBOPool(U32 vboUsage, U32 vboType) +: mUsage(vboUsage), mType(vboType) +{ + mMissCount.resize(LL_VBO_POOL_SEED_COUNT); + std::fill(mMissCount.begin(), mMissCount.end(), 0); +} + -volatile U8* LLVBOPool::allocate(U32& name, U32 size) +volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) { llassert(vbo_block_size(size) == size); @@ -183,14 +192,20 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size) if (mFreeList.size() <= i) { mFreeList.resize(i+1); + mMissCount.resize(i+1); } - if (mFreeList[i].empty()) + if (mFreeList[i].empty() || for_seed) { //make a new buffer glGenBuffersARB(1, &name); glBindBufferARB(mType, name); + if (!for_seed && i < LL_VBO_POOL_SEED_COUNT) + { //record this miss + mMissCount[i]++; + } + if (mType == GL_ARRAY_BUFFER_ARB) { LLVertexBuffer::sAllocatedBytes += size; @@ -211,6 +226,25 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size) } glBindBufferARB(mType, 0); + + if (for_seed) + { //put into pool for future use + llassert(mFreeList.size() > i); + + Record rec; + rec.mGLName = name; + rec.mClientData = ret; + + if (mType == GL_ARRAY_BUFFER_ARB) + { + sBytesPooled += size; + } + else + { + sIndexBytesPooled += size; + } + mFreeList[i].push_back(rec); + } } else { @@ -263,7 +297,7 @@ void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size) { llassert(vbo_block_size(size) == size); -#if LL_VBO_POOLING +#if 0 && LL_VBO_POOLING U32 i = vbo_block_index(size); @@ -304,6 +338,31 @@ void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size) #endif } +void LLVBOPool::seedPool() +{ + U32 dummy_name = 0; + + if (mFreeList.size() < LL_VBO_POOL_SEED_COUNT) + { + mFreeList.resize(LL_VBO_POOL_SEED_COUNT); + } + + for (U32 i = 0; i < LL_VBO_POOL_SEED_COUNT; i++) + { + if (mMissCount[i] > mFreeList[i].size()) + { + U32 size = i*LL_VBO_BLOCK_SIZE; + + S32 count = mMissCount[i] - mFreeList[i].size(); + for (U32 j = 0; j < count; ++j) + { + allocate(dummy_name, size, true); + } + } + } +} + + void LLVBOPool::cleanup() { U32 size = 1; @@ -339,6 +398,9 @@ void LLVBOPool::cleanup() size *= 2; } + + //reset miss counts + std::fill(mMissCount.begin(), mMissCount.end(), 0); } @@ -373,6 +435,15 @@ U32 LLVertexBuffer::sGLMode[LLRender::NUM_MODES] = }; +//static +void LLVertexBuffer::seedPools() +{ + sStreamVBOPool.seedPool(); + sDynamicVBOPool.seedPool(); + sStreamIBOPool.seedPool(); + sDynamicIBOPool.seedPool(); +} + //static void LLVertexBuffer::setupClientArrays(U32 data_mask) { diff --git a/indra/llrender/llvertexbuffer.h b/indra/llrender/llvertexbuffer.h index 7477dec3ad..a64daa1a90 100644 --- a/indra/llrender/llvertexbuffer.h +++ b/indra/llrender/llvertexbuffer.h @@ -57,20 +57,20 @@ public: static U32 sBytesPooled; static U32 sIndexBytesPooled; - LLVBOPool(U32 vboUsage, U32 vboType) - : mUsage(vboUsage) - , mType(vboType) - {} - + LLVBOPool(U32 vboUsage, U32 vboType); + const U32 mUsage; const U32 mType; //size MUST be a power of 2 - volatile U8* allocate(U32& name, U32 size); + volatile U8* allocate(U32& name, U32 size, bool for_seed = false); //size MUST be the size provided to allocate that returned the given name void release(U32 name, volatile U8* buffer, U32 size); + //batch allocate buffers to be provided to the application on demand + void seedPool(); + //destroy all records in mFreeList void cleanup(); @@ -83,6 +83,8 @@ public: typedef std::list record_list_t; std::vector mFreeList; + std::vector mMissCount; + }; class LLGLFence @@ -129,6 +131,8 @@ public: static bool sUseVAO; static bool sPreferStreamDraw; + static void seedPools(); + static void initClass(bool use_vbo, bool no_vbo_mapping); static void cleanupClass(); static void setupClientArrays(U32 data_mask); -- cgit v1.2.3 From b7cfd8c7f09a1a913c5678a5a25a951307593eb3 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 21 May 2012 23:33:25 -0500 Subject: MAINT-616 Factor out calls to glGenFoo where possible, add setting to control synchronizing strategy WRT occlusion queries, add experimental transform feedback driven LoD update --- indra/llrender/llcubemap.cpp | 2 +- indra/llrender/llgl.cpp | 79 ++++++++++++++++++++++++- indra/llrender/llgl.h | 26 ++++++++ indra/llrender/llglheaders.h | 13 ++++ indra/llrender/llglslshader.cpp | 9 ++- indra/llrender/llglslshader.h | 4 +- indra/llrender/llimagegl.cpp | 62 +++++++++++++------ indra/llrender/llimagegl.h | 10 ++-- indra/llrender/llrendertarget.cpp | 8 +-- indra/llrender/llvertexbuffer.cpp | 121 +++++++++++++++++++++++--------------- indra/llrender/llvertexbuffer.h | 25 +++++--- 11 files changed, 273 insertions(+), 86 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llcubemap.cpp b/indra/llrender/llcubemap.cpp index 45a3b18179..32e4c0d18e 100644 --- a/indra/llrender/llcubemap.cpp +++ b/indra/llrender/llcubemap.cpp @@ -81,7 +81,7 @@ void LLCubeMap::initGL() { U32 texname = 0; - LLImageGL::generateTextures(1, &texname); + LLImageGL::generateTextures(LLTexUnit::TT_CUBE_MAP, 1, &texname); for (int i = 0; i < 6; i++) { diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 639d967853..3946c43929 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -249,6 +249,12 @@ PFNGLTEXIMAGE3DMULTISAMPLEPROC glTexImage3DMultisample = NULL; PFNGLGETMULTISAMPLEFVPROC glGetMultisamplefv = NULL; PFNGLSAMPLEMASKIPROC glSampleMaski = NULL; +//transform feedback (4.0 core) +PFNGLBEGINTRANSFORMFEEDBACKPROC glBeginTransformFeedback = NULL; +PFNGLENDTRANSFORMFEEDBACKPROC glEndTransformFeedback = NULL; +PFNGLTRANSFORMFEEDBACKVARYINGSPROC glTransformFeedbackVaryings = NULL; +PFNGLBINDBUFFERRANGEPROC glBindBufferRange = NULL; + //GL_ARB_debug_output PFNGLDEBUGMESSAGECONTROLARBPROC glDebugMessageControlARB = NULL; PFNGLDEBUGMESSAGEINSERTARBPROC glDebugMessageInsertARB = NULL; @@ -421,6 +427,7 @@ LLGLManager::LLGLManager() : mHasDrawBuffers(FALSE), mHasTextureRectangle(FALSE), mHasTextureMultisample(FALSE), + mHasTransformFeedback(FALSE), mMaxSampleMaskWords(0), mMaxColorTextureSamples(0), mMaxDepthTextureSamples(0), @@ -969,6 +976,7 @@ void LLGLManager::initExtensions() mHasTextureRectangle = ExtensionExists("GL_ARB_texture_rectangle", gGLHExts.mSysExts); mHasTextureMultisample = ExtensionExists("GL_ARB_texture_multisample", gGLHExts.mSysExts); mHasDebugOutput = ExtensionExists("GL_ARB_debug_output", gGLHExts.mSysExts); + mHasTransformFeedback = mGLVersion >= 4.f ? TRUE : FALSE; #if !LL_DARWIN mHasPointParameters = !mIsATI && ExtensionExists("GL_ARB_point_parameters", gGLHExts.mSysExts); #endif @@ -1208,7 +1216,14 @@ void LLGLManager::initExtensions() glTexImage3DMultisample = (PFNGLTEXIMAGE3DMULTISAMPLEPROC) GLH_EXT_GET_PROC_ADDRESS("glTexImage3DMultisample"); glGetMultisamplefv = (PFNGLGETMULTISAMPLEFVPROC) GLH_EXT_GET_PROC_ADDRESS("glGetMultisamplefv"); glSampleMaski = (PFNGLSAMPLEMASKIPROC) GLH_EXT_GET_PROC_ADDRESS("glSampleMaski"); - } + } + if (mHasTransformFeedback) + { + glBeginTransformFeedback = (PFNGLBEGINTRANSFORMFEEDBACKPROC) GLH_EXT_GET_PROC_ADDRESS("glBeginTransformFeedback"); + glEndTransformFeedback = (PFNGLENDTRANSFORMFEEDBACKPROC) GLH_EXT_GET_PROC_ADDRESS("glEndTransformFeedback"); + glTransformFeedbackVaryings = (PFNGLTRANSFORMFEEDBACKVARYINGSPROC) GLH_EXT_GET_PROC_ADDRESS("glTransformFeedbackVaryings"); + glBindBufferRange = (PFNGLBINDBUFFERRANGEPROC) GLH_EXT_GET_PROC_ADDRESS("glBindBufferRange"); + } if (mHasDebugOutput) { glDebugMessageControlARB = (PFNGLDEBUGMESSAGECONTROLARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDebugMessageControlARB"); @@ -2433,3 +2448,65 @@ LLGLSquashToFarClip::~LLGLSquashToFarClip() gGL.matrixMode(LLRender::MM_MODELVIEW); } + + +LLGLSyncFence::LLGLSyncFence() +{ +#ifdef GL_ARB_sync + mSync = 0; +#endif +} + +LLGLSyncFence::~LLGLSyncFence() +{ +#ifdef GL_ARB_sync + if (mSync) + { + glDeleteSync(mSync); + } +#endif +} + +void LLGLSyncFence::placeFence() +{ +#ifdef GL_ARB_sync + if (mSync) + { + glDeleteSync(mSync); + } + mSync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); +#endif +} + +bool LLGLSyncFence::isCompleted() +{ + bool ret = true; +#ifdef GL_ARB_sync + if (mSync) + { + GLenum status = glClientWaitSync(mSync, 0, 1); + if (status == GL_TIMEOUT_EXPIRED) + { + ret = false; + } + } +#endif + return ret; +} + +void LLGLSyncFence::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 +} + + + diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h index 9c3a47bd50..c26b75eff7 100644 --- a/indra/llrender/llgl.h +++ b/indra/llrender/llgl.h @@ -104,6 +104,7 @@ public: BOOL mHasDepthClamp; BOOL mHasTextureRectangle; BOOL mHasTextureMultisample; + BOOL mHasTransformFeedback; S32 mMaxSampleMaskWords; S32 mMaxColorTextureSamples; S32 mMaxDepthTextureSamples; @@ -418,6 +419,31 @@ public: virtual void updateGL() = 0; }; +const U32 FENCE_WAIT_TIME_NANOSECONDS = 10000; //1 ms + +class LLGLFence +{ +public: + virtual void placeFence() = 0; + virtual bool isCompleted() = 0; + virtual void wait() = 0; +}; + +class LLGLSyncFence : public LLGLFence +{ +public: +#ifdef GL_ARB_sync + GLsync mSync; +#endif + + LLGLSyncFence(); + virtual ~LLGLSyncFence(); + + void placeFence(); + bool isCompleted(); + void wait(); +}; + extern LLMatrix4 gGLObliqueProjectionInverse; #include "llglstates.h" diff --git a/indra/llrender/llglheaders.h b/indra/llrender/llglheaders.h index d61ec707f0..a0727b8686 100644 --- a/indra/llrender/llglheaders.h +++ b/indra/llrender/llglheaders.h @@ -528,6 +528,13 @@ extern PFNGLTEXIMAGE3DMULTISAMPLEPROC glTexImage3DMultisample; extern PFNGLGETMULTISAMPLEFVPROC glGetMultisamplefv; extern PFNGLSAMPLEMASKIPROC glSampleMaski; +//transform feedback (4.0 core) +extern PFNGLBEGINTRANSFORMFEEDBACKPROC glBeginTransformFeedback; +extern PFNGLENDTRANSFORMFEEDBACKPROC glEndTransformFeedback; +extern PFNGLTRANSFORMFEEDBACKVARYINGSPROC glTransformFeedbackVaryings; +extern PFNGLBINDBUFFERRANGEPROC glBindBufferRange; + + #elif LL_WINDOWS //---------------------------------------------------------------------------- // LL_WINDOWS @@ -759,6 +766,12 @@ extern PFNGLTEXIMAGE3DMULTISAMPLEPROC glTexImage3DMultisample; extern PFNGLGETMULTISAMPLEFVPROC glGetMultisamplefv; extern PFNGLSAMPLEMASKIPROC glSampleMaski; +//transform feedback (4.0 core) +extern PFNGLBEGINTRANSFORMFEEDBACKPROC glBeginTransformFeedback; +extern PFNGLENDTRANSFORMFEEDBACKPROC glEndTransformFeedback; +extern PFNGLTRANSFORMFEEDBACKVARYINGSPROC glTransformFeedbackVaryings; +extern PFNGLBINDBUFFERRANGEPROC glBindBufferRange; + //GL_ARB_debug_output extern PFNGLDEBUGMESSAGECONTROLARBPROC glDebugMessageControlARB; extern PFNGLDEBUGMESSAGEINSERTARBPROC glDebugMessageInsertARB; diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 4b7e639aed..149e8cc548 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -129,7 +129,9 @@ void LLGLSLShader::unload() } BOOL LLGLSLShader::createShader(vector * attributes, - vector * uniforms) + vector * uniforms, + U32 varying_count, + const char** varyings) { //reloading, reset matrix hash values for (U32 i = 0; i < LLRender::NUM_MATRIX_MODES; ++i) @@ -172,6 +174,11 @@ BOOL LLGLSLShader::createShader(vector * attributes, mFeatures.mIndexedTextureChannels = llmin(mFeatures.mIndexedTextureChannels, 1); } + if (varying_count > 0 && varyings) + { + glTransformFeedbackVaryings(mProgramObject, varying_count, varyings, GL_INTERLEAVED_ATTRIBS); + } + // Map attributes and uniforms if (success) { diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 7873fe3c4e..5c68cb46eb 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -76,7 +76,9 @@ public: void unload(); BOOL createShader(std::vector * attributes, - std::vector * uniforms); + std::vector * uniforms, + U32 varying_count = 0, + const char** varyings = NULL); BOOL attachObject(std::string object); void attachObject(GLhandleARB object); void attachObjects(GLhandleARB* objects = NULL, S32 count = 0); diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 17131c9d8a..3bdee6cade 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -51,7 +51,8 @@ S32 LLImageGL::sGlobalTextureMemoryInBytes = 0; S32 LLImageGL::sBoundTextureMemoryInBytes = 0; S32 LLImageGL::sCurBoundTextureMemory = 0; S32 LLImageGL::sCount = 0; -std::list LLImageGL::sDeadTextureList; +std::list LLImageGL::sDeadTextureList[LLTexUnit::TT_NONE]; +U32 LLImageGL::sCurTexName = 1; BOOL LLImageGL::sGlobalUseAnisotropic = FALSE; F32 LLImageGL::sLastFrameTime = 0.f; @@ -1093,23 +1094,49 @@ BOOL LLImageGL::setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_ } // static -void LLImageGL::generateTextures(S32 numTextures, U32 *textures) +void LLImageGL::generateTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures) { - glGenTextures(numTextures, (GLuint*)textures); + for (S32 i = 0; i < numTextures; ++i) + { + if (!sDeadTextureList[type].empty()) + { + textures[i] = sDeadTextureList[type].front(); + sDeadTextureList[type].pop_front(); + } + else + { + textures[i] = sCurTexName++; + } + } } // static -void LLImageGL::deleteTextures(S32 numTextures, U32 *textures, bool immediate) +void LLImageGL::deleteTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures, bool immediate) { - for (S32 i = 0; i < numTextures; i++) - { - sDeadTextureList.push_back(textures[i]); - } + for (S32 i = 0; i < numTextures; ++i) + { //remove texture from VRAM by setting its size to zero + gGL.getTexUnit(0)->bindManual(type, textures[i]); - if (immediate) + if (type == LLTexUnit::TT_CUBE_MAP) + { + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + else + { + glTexImage2D(LLTexUnit::getInternalType(type), 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + sDeadTextureList[type].push_back(textures[i]); + } + + /*if (immediate) { LLImageGL::deleteDeadTextures(); - } + }*/ } // static @@ -1234,10 +1261,11 @@ BOOL LLImageGL::createGLTexture() if(mTexName) { - glDeleteTextures(1, (reinterpret_cast(&mTexName))) ; + LLImageGL::deleteTextures(mBindTarget, 1, (reinterpret_cast(&mTexName))) ; } - glGenTextures(1, (GLuint*)&mTexName); + + LLImageGL::generateTextures(mBindTarget, 1, &mTexName); stop_glerror(); if (!mTexName) { @@ -1350,7 +1378,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_ } else { - LLImageGL::generateTextures(1, &mTexName); + LLImageGL::generateTextures(mBindTarget, 1, &mTexName); stop_glerror(); { llverify(gGL.getTexUnit(0)->bind(this)); @@ -1400,7 +1428,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_ decTextureCounter(mTextureMemory, mComponents, mCategory) ; } - LLImageGL::deleteTextures(1, &old_name); + LLImageGL::deleteTextures(mBindTarget,1, &old_name); stop_glerror(); } @@ -1533,7 +1561,7 @@ void LLImageGL::deleteDeadTextures() { bool reset = false; - while (!sDeadTextureList.empty()) + /*while (!sDeadTextureList.empty()) { GLuint tex = sDeadTextureList.front(); sDeadTextureList.pop_front(); @@ -1555,7 +1583,7 @@ void LLImageGL::deleteDeadTextures() glDeleteTextures(1, &tex); stop_glerror(); - } + }*/ if (reset) { @@ -1577,7 +1605,7 @@ void LLImageGL::destroyGLTexture() mTextureMemory = 0; } - LLImageGL::deleteTextures(1, &mTexName); + LLImageGL::deleteTextures(mBindTarget, 1, &mTexName); mTexName = 0; mCurrentDiscardLevel = -1 ; //invalidate mCurrentDiscardLevel. mGLTextureCreated = FALSE ; diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h index e23005fe29..8c9cea111e 100644 --- a/indra/llrender/llimagegl.h +++ b/indra/llrender/llimagegl.h @@ -45,8 +45,12 @@ class LLImageGL : public LLRefCount { friend class LLTexUnit; public: - static std::list sDeadTextureList; + static U32 sCurTexName; + static std::list sDeadTextureList[LLTexUnit::TT_NONE]; + // These 2 functions replace glGenTextures() and glDeleteTextures() + static void generateTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures); + static void deleteTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures, bool immediate = false); static void deleteDeadTextures(); // Size calculation @@ -96,10 +100,6 @@ public: void setComponents(S32 ncomponents) { mComponents = (S8)ncomponents ;} void setAllowCompression(bool allow) { mAllowCompression = allow; } - // These 3 functions currently wrap glGenTextures(), glDeleteTextures(), and glTexImage2D() - // for tracking purposes and will be deprecated in the future - static void generateTextures(S32 numTextures, U32 *textures); - static void deleteTextures(S32 numTextures, U32 *textures, bool immediate = false); static void setManualImage(U32 target, S32 miplevel, S32 intformat, S32 width, S32 height, U32 pixformat, U32 pixtype, const void *pixels, bool allow_compression = true); BOOL createGLTexture() ; diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 780f1dc484..f0dd6f3bd6 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -135,7 +135,7 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) } U32 tex; - LLImageGL::generateTextures(1, &tex); + LLImageGL::generateTextures(mUsage, 1, &tex); gGL.getTexUnit(0)->bindManual(mUsage, tex); stop_glerror(); @@ -217,7 +217,7 @@ bool LLRenderTarget::allocateDepth() } else { - LLImageGL::generateTextures(1, &mDepth); + LLImageGL::generateTextures(mUsage, 1, &mDepth); gGL.getTexUnit(0)->bindManual(mUsage, mDepth); U32 internal_type = LLTexUnit::getInternalType(mUsage); @@ -294,7 +294,7 @@ void LLRenderTarget::release() } else { - LLImageGL::deleteTextures(1, &mDepth, true); + LLImageGL::deleteTextures(mUsage, 1, &mDepth, true); stop_glerror(); } mDepth = 0; @@ -326,7 +326,7 @@ void LLRenderTarget::release() if (mTex.size() > 0) { sBytesAllocated -= mResX*mResY*4*mTex.size(); - LLImageGL::deleteTextures(mTex.size(), &mTex[0], true); + LLImageGL::deleteTextures(mUsage, mTex.size(), &mTex[0], true); mTex.clear(); } diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 7b12304967..6a218e7734 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -93,6 +93,11 @@ LLVBOPool LLVertexBuffer::sDynamicIBOPool(GL_DYNAMIC_DRAW_ARB, GL_ELEMENT_ARRAY_ U32 LLVBOPool::sBytesPooled = 0; U32 LLVBOPool::sIndexBytesPooled = 0; +U32 LLVBOPool::sCurGLName = 1; + +std::list LLVertexBuffer::sAvailableVAOName; +U32 LLVertexBuffer::sCurVAOName = 1; + U32 LLVertexBuffer::sAllocatedIndexBytes = 0; U32 LLVertexBuffer::sIndexCount = 0; @@ -117,59 +122,38 @@ 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 +U32 LLVBOPool::genBuffer() { -public: -#ifdef GL_ARB_sync - GLsync mSync; -#endif - - LLGLSyncFence() - { -#ifdef GL_ARB_sync - mSync = 0; -#endif - } + U32 ret = 0; - virtual ~LLGLSyncFence() + if (mGLNamePool.empty()) { -#ifdef GL_ARB_sync - if (mSync) - { - glDeleteSync(mSync); - } -#endif + ret = sCurGLName++; } - - void placeFence() + else { -#ifdef GL_ARB_sync - if (mSync) - { - glDeleteSync(mSync); - } - mSync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); -#endif + ret = mGLNamePool.front(); + mGLNamePool.pop_front(); } - 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 - } + return ret; +} + +void LLVBOPool::deleteBuffer(U32 name) +{ + LLVertexBuffer::unbind(); + glBindBufferARB(mType, name); + glBufferDataARB(mType, 0, NULL, mUsage); + + llassert(std::find(mGLNamePool.begin(), mGLNamePool.end(), name) == mGLNamePool.end()); + + mGLNamePool.push_back(name); + + LLVertexBuffer::unbind(); +} -}; LLVBOPool::LLVBOPool(U32 vboUsage, U32 vboType) : mUsage(vboUsage), mType(vboType) @@ -178,6 +162,9 @@ LLVBOPool::LLVBOPool(U32 vboUsage, U32 vboType) std::fill(mMissCount.begin(), mMissCount.end(), 0); } +static LLFastTimer::DeclareTimer FTM_VBO_GEN_BUFFER("gen buffers"); +static LLFastTimer::DeclareTimer FTM_VBO_BUFFER_DATA("glBufferData"); + volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) { @@ -198,7 +185,10 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) if (mFreeList[i].empty() || for_seed) { //make a new buffer - glGenBuffersARB(1, &name); + { + LLFastTimer t(FTM_VBO_GEN_BUFFER); + name = genBuffer(); + } glBindBufferARB(mType, name); if (!for_seed && i < LL_VBO_POOL_SEED_COUNT) @@ -222,6 +212,7 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) } else { //always use a true hint of static draw when allocating non-client-backed buffers + LLFastTimer t(FTM_VBO_BUFFER_DATA); glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB); } @@ -324,7 +315,7 @@ void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size) mFreeList[i].push_back(rec); } #else //no pooling - glDeleteBuffersARB(1, &name); + deleteBuffer(name); ll_aligned_free_16((U8*) buffer); if (mType == GL_ARRAY_BUFFER_ARB) @@ -375,8 +366,8 @@ void LLVBOPool::cleanup() { Record& r = l.front(); - glDeleteBuffersARB(1, &r.mGLName); - + deleteBuffer(r.mGLName); + if (r.mClientData) { ll_aligned_free_16((void*) r.mClientData); @@ -434,6 +425,30 @@ U32 LLVertexBuffer::sGLMode[LLRender::NUM_MODES] = GL_LINE_LOOP, }; +//static +U32 LLVertexBuffer::getVAOName() +{ + U32 ret = 0; + + if (!sAvailableVAOName.empty()) + { + ret = sAvailableVAOName.front(); + sAvailableVAOName.pop_front(); + } + else + { + glGenVertexArrays(1, &ret); + } + + return ret; +} + +//static +void LLVertexBuffer::releaseVAOName(U32 name) +{ + sAvailableVAOName.push_back(name); +} + //static void LLVertexBuffer::seedPools() @@ -1052,7 +1067,7 @@ LLVertexBuffer::~LLVertexBuffer() if (mGLArray) { #if GL_ARB_vertex_array_object - glDeleteVertexArrays(1, &mGLArray); + releaseVAOName(mGLArray); #endif } @@ -1337,7 +1352,7 @@ void LLVertexBuffer::allocateBuffer(S32 nverts, S32 nindices, bool create) if (gGLManager.mHasVertexArrayObject && useVBOs() && (LLRender::sGLCoreProfile || sUseVAO)) { #if GL_ARB_vertex_array_object - glGenVertexArrays(1, &mGLArray); + mGLArray = getVAOName(); #endif setupVertexArray(); } @@ -2207,6 +2222,14 @@ void LLVertexBuffer::flush() } } +// bind for transform feedback (quick 'n dirty) +void LLVertexBuffer::bindForFeedback(U32 channel, U32 type, U32 index, U32 count) +{ + U32 offset = mOffsets[type] + sTypeSize[type]*index; + U32 size= (sTypeSize[type]*count); + glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, channel, mGLBuffer, offset, size); +} + // Set for rendering void LLVertexBuffer::setBuffer(U32 data_mask) { diff --git a/indra/llrender/llvertexbuffer.h b/indra/llrender/llvertexbuffer.h index a64daa1a90..11fa4ab6a0 100644 --- a/indra/llrender/llvertexbuffer.h +++ b/indra/llrender/llvertexbuffer.h @@ -57,6 +57,8 @@ public: static U32 sBytesPooled; static U32 sIndexBytesPooled; + static U32 sCurGLName; + LLVBOPool(U32 vboUsage, U32 vboType); const U32 mUsage; @@ -74,6 +76,9 @@ public: //destroy all records in mFreeList void cleanup(); + U32 genBuffer(); + void deleteBuffer(U32 name); + class Record { public: @@ -81,18 +86,14 @@ public: volatile U8* mClientData; }; + std::list mGLNamePool; + typedef std::list record_list_t; std::vector mFreeList; std::vector mMissCount; }; -class LLGLFence -{ -public: - virtual void placeFence() = 0; - virtual void wait() = 0; -}; //============================================================================ // base class @@ -127,15 +128,22 @@ public: static LLVBOPool sStreamIBOPool; static LLVBOPool sDynamicIBOPool; + static std::list sAvailableVAOName; + static U32 sCurVAOName; + static bool sUseStreamDraw; static bool sUseVAO; static bool sPreferStreamDraw; static void seedPools(); + static U32 getVAOName(); + static void releaseVAOName(U32 name); + static void initClass(bool use_vbo, bool no_vbo_mapping); static void cleanupClass(); static void setupClientArrays(U32 data_mask); + static void pushPositions(U32 mode, const LLVector4a* pos, U32 count); static void drawArrays(U32 mode, const std::vector& pos, const std::vector& norm); static void drawElements(U32 mode, const LLVector4a* pos, const LLVector2* tc, S32 num_indices, const U16* indicesp); @@ -212,7 +220,6 @@ protected: void destroyGLIndices(); void updateNumVerts(S32 nverts); void updateNumIndices(S32 nindices); - bool useVBOs() const; void unmapBuffer(); public: @@ -222,6 +229,8 @@ public: volatile U8* mapVertexBuffer(S32 type, S32 index, S32 count, bool map_range); volatile U8* mapIndexBuffer(S32 index, S32 count, bool map_range); + void bindForFeedback(U32 channel, U32 type, U32 index, U32 count); + // set for rendering virtual void setBuffer(U32 data_mask); // calls setupVertexBuffer() if data_mask is not 0 void flush(); //flush pending data to GL memory @@ -244,12 +253,14 @@ public: bool getNormalStrider(LLStrider& strider, S32 index=0, S32 count = -1, bool map_range = false); bool getBinormalStrider(LLStrider& strider, S32 index=0, S32 count = -1, bool map_range = false); bool getColorStrider(LLStrider& strider, S32 index=0, S32 count = -1, bool map_range = false); + bool getTextureIndexStrider(LLStrider& strider, S32 index=0, S32 count = -1, bool map_range = false); bool getEmissiveStrider(LLStrider& strider, S32 index=0, S32 count = -1, bool map_range = false); bool getWeightStrider(LLStrider& strider, S32 index=0, S32 count = -1, bool map_range = false); bool getWeight4Strider(LLStrider& strider, S32 index=0, S32 count = -1, bool map_range = false); bool getClothWeightStrider(LLStrider& strider, S32 index=0, S32 count = -1, bool map_range = false); + bool useVBOs() const; bool isEmpty() const { return mEmpty; } bool isLocked() const { return mVertexLocked || mIndexLocked; } S32 getNumVerts() const { return mNumVerts; } -- cgit v1.2.3 From 534168c452c10b1616b883e63321edd1ccd96fb2 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 22 May 2012 00:49:07 -0500 Subject: MAINT-616 Fix for crash on shutdown caused by previous changes. --- indra/llrender/llimagegl.cpp | 35 +++++++++++++++++++---------------- indra/llrender/llvertexbuffer.cpp | 15 +++++++++------ 2 files changed, 28 insertions(+), 22 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 3bdee6cade..2d3762135a 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -1113,24 +1113,27 @@ void LLImageGL::generateTextures(LLTexUnit::eTextureType type, S32 numTextures, // static void LLImageGL::deleteTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures, bool immediate) { - for (S32 i = 0; i < numTextures; ++i) - { //remove texture from VRAM by setting its size to zero - gGL.getTexUnit(0)->bindManual(type, textures[i]); + if (gGLManager.mInited) + { + for (S32 i = 0; i < numTextures; ++i) + { //remove texture from VRAM by setting its size to zero + gGL.getTexUnit(0)->bindManual(type, textures[i]); - if (type == LLTexUnit::TT_CUBE_MAP) - { - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - } - else - { - glTexImage2D(LLTexUnit::getInternalType(type), 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + if (type == LLTexUnit::TT_CUBE_MAP) + { + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + else + { + glTexImage2D(LLTexUnit::getInternalType(type), 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + sDeadTextureList[type].push_back(textures[i]); } - sDeadTextureList[type].push_back(textures[i]); } /*if (immediate) diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 6a218e7734..0e037fdd21 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -142,16 +142,19 @@ U32 LLVBOPool::genBuffer() void LLVBOPool::deleteBuffer(U32 name) { - LLVertexBuffer::unbind(); + if (gGLManager.mInited) + { + LLVertexBuffer::unbind(); - glBindBufferARB(mType, name); - glBufferDataARB(mType, 0, NULL, mUsage); + glBindBufferARB(mType, name); + glBufferDataARB(mType, 0, NULL, mUsage); - llassert(std::find(mGLNamePool.begin(), mGLNamePool.end(), name) == mGLNamePool.end()); + llassert(std::find(mGLNamePool.begin(), mGLNamePool.end(), name) == mGLNamePool.end()); - mGLNamePool.push_back(name); + mGLNamePool.push_back(name); - LLVertexBuffer::unbind(); + LLVertexBuffer::unbind(); + } } -- cgit v1.2.3 From 78df56e1b55637eefcf8223c3b49adba66eba7e9 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 22 May 2012 13:49:52 -0500 Subject: MAINT-616 Fix for crash on teleport from previous changes --- indra/llrender/llvertexbuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 0e037fdd21..ca7c9deff2 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -153,7 +153,7 @@ void LLVBOPool::deleteBuffer(U32 name) mGLNamePool.push_back(name); - LLVertexBuffer::unbind(); + glBindBufferARB(mType, 0); } } -- cgit v1.2.3 From efda0814cbae7917fde634c5e245c81915b17a9c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 24 May 2012 10:50:48 -0500 Subject: MAINT-616 Fix for corrupted mipmaps. Cleanup based on code review feedback. --- indra/llrender/llcubemap.cpp | 2 +- indra/llrender/llgl.h | 2 +- indra/llrender/llimagegl.cpp | 74 +++++++++++++++++++++++++-------------- indra/llrender/llimagegl.h | 10 ++++-- indra/llrender/llrendertarget.cpp | 11 +++--- indra/llrender/llrendertarget.h | 1 + indra/llrender/llvertexbuffer.cpp | 71 ++----------------------------------- 7 files changed, 65 insertions(+), 106 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llcubemap.cpp b/indra/llrender/llcubemap.cpp index 32e4c0d18e..362452d837 100644 --- a/indra/llrender/llcubemap.cpp +++ b/indra/llrender/llcubemap.cpp @@ -81,7 +81,7 @@ void LLCubeMap::initGL() { U32 texname = 0; - LLImageGL::generateTextures(LLTexUnit::TT_CUBE_MAP, 1, &texname); + LLImageGL::generateTextures(LLTexUnit::TT_CUBE_MAP, GL_RGB8, 1, &texname); for (int i = 0; i < 6; i++) { diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h index c26b75eff7..964495a3ab 100644 --- a/indra/llrender/llgl.h +++ b/indra/llrender/llgl.h @@ -419,7 +419,7 @@ public: virtual void updateGL() = 0; }; -const U32 FENCE_WAIT_TIME_NANOSECONDS = 10000; //1 ms +const U32 FENCE_WAIT_TIME_NANOSECONDS = 1000; //1 ms class LLGLFence { diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 2d3762135a..bb585cc49c 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -51,7 +51,7 @@ S32 LLImageGL::sGlobalTextureMemoryInBytes = 0; S32 LLImageGL::sBoundTextureMemoryInBytes = 0; S32 LLImageGL::sCurBoundTextureMemory = 0; S32 LLImageGL::sCount = 0; -std::list LLImageGL::sDeadTextureList[LLTexUnit::TT_NONE]; +LLImageGL::dead_texturelist_t LLImageGL::sDeadTextureList[LLTexUnit::TT_NONE]; U32 LLImageGL::sCurTexName = 1; BOOL LLImageGL::sGlobalUseAnisotropic = FALSE; @@ -766,6 +766,9 @@ void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips) if (gGLManager.mHasFramebufferObject) { + gGL.getTexUnit(0)->unbind(mBindTarget); + gGL.getTexUnit(0)->bind(this); + glGenerateMipmap(LLTexUnit::getInternalType(mBindTarget)); } } @@ -1094,14 +1097,24 @@ BOOL LLImageGL::setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_ } // static -void LLImageGL::generateTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures) +void LLImageGL::generateTextures(LLTexUnit::eTextureType type, U32 format, S32 numTextures, U32 *textures) { + bool empty = true; + + dead_texturelist_t::iterator iter = sDeadTextureList[type].find(format); + + if (iter != sDeadTextureList[type].end()) + { + empty = iter->second.empty(); + } + for (S32 i = 0; i < numTextures; ++i) { - if (!sDeadTextureList[type].empty()) + if (!empty) { - textures[i] = sDeadTextureList[type].front(); - sDeadTextureList[type].pop_front(); + textures[i] = iter->second.front(); + iter->second.pop_front(); + empty = iter->second.empty(); } else { @@ -1111,28 +1124,35 @@ void LLImageGL::generateTextures(LLTexUnit::eTextureType type, S32 numTextures, } // static -void LLImageGL::deleteTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures, bool immediate) +void LLImageGL::deleteTextures(LLTexUnit::eTextureType type, U32 format, S32 numTextures, U32 *textures, bool immediate) { if (gGLManager.mInited) { - for (S32 i = 0; i < numTextures; ++i) - { //remove texture from VRAM by setting its size to zero - gGL.getTexUnit(0)->bindManual(type, textures[i]); + if (format == 0) + { //unknown internal format, not safe to reuse + glDeleteTextures(numTextures, textures); + } + else + { + for (S32 i = 0; i < numTextures; ++i) + { //remove texture from VRAM by setting its size to zero + gGL.getTexUnit(0)->bindManual(type, textures[i]); - if (type == LLTexUnit::TT_CUBE_MAP) - { - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - } - else - { - glTexImage2D(LLTexUnit::getInternalType(type), 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + if (type == LLTexUnit::TT_CUBE_MAP) + { + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + else + { + glTexImage2D(LLTexUnit::getInternalType(type), 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + sDeadTextureList[type][format].push_back(textures[i]); } - sDeadTextureList[type].push_back(textures[i]); } } @@ -1264,11 +1284,11 @@ BOOL LLImageGL::createGLTexture() if(mTexName) { - LLImageGL::deleteTextures(mBindTarget, 1, (reinterpret_cast(&mTexName))) ; + LLImageGL::deleteTextures(mBindTarget, mFormatInternal, 1, (reinterpret_cast(&mTexName))) ; } - LLImageGL::generateTextures(mBindTarget, 1, &mTexName); + LLImageGL::generateTextures(mBindTarget, mFormatInternal, 1, &mTexName); stop_glerror(); if (!mTexName) { @@ -1381,7 +1401,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_ } else { - LLImageGL::generateTextures(mBindTarget, 1, &mTexName); + LLImageGL::generateTextures(mBindTarget, mFormatInternal, 1, &mTexName); stop_glerror(); { llverify(gGL.getTexUnit(0)->bind(this)); @@ -1431,7 +1451,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_ decTextureCounter(mTextureMemory, mComponents, mCategory) ; } - LLImageGL::deleteTextures(mBindTarget,1, &old_name); + LLImageGL::deleteTextures(mBindTarget, mFormatInternal, 1, &old_name); stop_glerror(); } @@ -1608,7 +1628,7 @@ void LLImageGL::destroyGLTexture() mTextureMemory = 0; } - LLImageGL::deleteTextures(mBindTarget, 1, &mTexName); + LLImageGL::deleteTextures(mBindTarget, mFormatInternal, 1, &mTexName); mTexName = 0; mCurrentDiscardLevel = -1 ; //invalidate mCurrentDiscardLevel. mGLTextureCreated = FALSE ; diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h index 8c9cea111e..34efafb015 100644 --- a/indra/llrender/llimagegl.h +++ b/indra/llrender/llimagegl.h @@ -46,11 +46,15 @@ class LLImageGL : public LLRefCount friend class LLTexUnit; public: static U32 sCurTexName; - static std::list sDeadTextureList[LLTexUnit::TT_NONE]; + + //previously used but now available texture names + // sDeadTextureList[][] + typedef std::map > dead_texturelist_t; + static dead_texturelist_t sDeadTextureList[LLTexUnit::TT_NONE]; // These 2 functions replace glGenTextures() and glDeleteTextures() - static void generateTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures); - static void deleteTextures(LLTexUnit::eTextureType type, S32 numTextures, U32 *textures, bool immediate = false); + static void generateTextures(LLTexUnit::eTextureType type, U32 format, S32 numTextures, U32 *textures); + static void deleteTextures(LLTexUnit::eTextureType type, U32 format, S32 numTextures, U32 *textures, bool immediate = false); static void deleteDeadTextures(); // Size calculation diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index f0dd6f3bd6..ced6b013ec 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -55,7 +55,6 @@ bool LLRenderTarget::sUseFBO = false; LLRenderTarget::LLRenderTarget() : mResX(0), mResY(0), - mTex(0), mFBO(0), mDepth(0), mStencil(0), @@ -135,7 +134,7 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) } U32 tex; - LLImageGL::generateTextures(mUsage, 1, &tex); + LLImageGL::generateTextures(mUsage, color_fmt, 1, &tex); gGL.getTexUnit(0)->bindManual(mUsage, tex); stop_glerror(); @@ -193,6 +192,7 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) } mTex.push_back(tex); + mInternalFormat.push_back(color_fmt); if (gDebugGL) { //bind and unbind to validate target @@ -217,7 +217,7 @@ bool LLRenderTarget::allocateDepth() } else { - LLImageGL::generateTextures(mUsage, 1, &mDepth); + LLImageGL::generateTextures(mUsage, GL_DEPTH_COMPONENT24, 1, &mDepth); gGL.getTexUnit(0)->bindManual(mUsage, mDepth); U32 internal_type = LLTexUnit::getInternalType(mUsage); @@ -294,7 +294,7 @@ void LLRenderTarget::release() } else { - LLImageGL::deleteTextures(mUsage, 1, &mDepth, true); + LLImageGL::deleteTextures(mUsage, 0, 1, &mDepth, true); stop_glerror(); } mDepth = 0; @@ -326,8 +326,9 @@ void LLRenderTarget::release() if (mTex.size() > 0) { sBytesAllocated -= mResX*mResY*4*mTex.size(); - LLImageGL::deleteTextures(mUsage, mTex.size(), &mTex[0], true); + LLImageGL::deleteTextures(mUsage, mInternalFormat[0], mTex.size(), &mTex[0], true); mTex.clear(); + mInternalFormat.clear(); } mResX = mResY = 0; diff --git a/indra/llrender/llrendertarget.h b/indra/llrender/llrendertarget.h index 2735ab21c5..8360458840 100644 --- a/indra/llrender/llrendertarget.h +++ b/indra/llrender/llrendertarget.h @@ -142,6 +142,7 @@ protected: U32 mResX; U32 mResY; std::vector mTex; + std::vector mInternalFormat; U32 mFBO; U32 mDepth; bool mStencil; diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index ca7c9deff2..f4bf744e3c 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -38,8 +38,6 @@ #include "llglslshader.h" #include "llmemory.h" -#define LL_VBO_POOLING 1 - //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) @@ -165,33 +163,24 @@ LLVBOPool::LLVBOPool(U32 vboUsage, U32 vboType) std::fill(mMissCount.begin(), mMissCount.end(), 0); } -static LLFastTimer::DeclareTimer FTM_VBO_GEN_BUFFER("gen buffers"); -static LLFastTimer::DeclareTimer FTM_VBO_BUFFER_DATA("glBufferData"); - - volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) { llassert(vbo_block_size(size) == size); volatile U8* ret = NULL; -#if LL_VBO_POOLING - U32 i = vbo_block_index(size); if (mFreeList.size() <= i) { mFreeList.resize(i+1); - mMissCount.resize(i+1); } if (mFreeList[i].empty() || for_seed) { //make a new buffer - { - LLFastTimer t(FTM_VBO_GEN_BUFFER); - name = genBuffer(); - } + name = genBuffer(); + glBindBufferARB(mType, name); if (!for_seed && i < LL_VBO_POOL_SEED_COUNT) @@ -215,7 +204,6 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) } else { //always use a true hint of static draw when allocating non-client-backed buffers - LLFastTimer t(FTM_VBO_BUFFER_DATA); glBufferDataARB(mType, size, 0, GL_STATIC_DRAW_ARB); } @@ -256,33 +244,6 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) mFreeList[i].pop_front(); } -#else //no pooling - - glGenBuffersARB(1, &name); - glBindBufferARB(mType, name); - - if (mType == GL_ARRAY_BUFFER_ARB) - { - LLVertexBuffer::sAllocatedBytes += size; - } - else - { - LLVertexBuffer::sAllocatedIndexBytes += 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); - -#endif return ret; } @@ -291,33 +252,6 @@ void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size) { llassert(vbo_block_size(size) == size); -#if 0 && LL_VBO_POOLING - - U32 i = vbo_block_index(size); - - llassert(mFreeList.size() > i); - - Record rec; - rec.mGLName = name; - rec.mClientData = buffer; - - if (buffer == NULL) - { - glDeleteBuffersARB(1, &rec.mGLName); - } - else - { - if (mType == GL_ARRAY_BUFFER_ARB) - { - sBytesPooled += size; - } - else - { - sIndexBytesPooled += size; - } - mFreeList[i].push_back(rec); - } -#else //no pooling deleteBuffer(name); ll_aligned_free_16((U8*) buffer); @@ -329,7 +263,6 @@ void LLVBOPool::release(U32 name, volatile U8* buffer, U32 size) { LLVertexBuffer::sAllocatedIndexBytes -= size; } -#endif } void LLVBOPool::seedPool() -- cgit v1.2.3 From abaf0155b47c5e020efa7e4600524c0c6d49319f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 25 May 2012 10:51:38 -0500 Subject: MAINT-616 Faster issuance of occlusion queries. --- indra/llrender/llshadermgr.cpp | 3 +++ indra/llrender/llshadermgr.h | 2 ++ 2 files changed, 5 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 7d384450e6..bf917d4474 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1026,6 +1026,9 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("size"); mReservedUniforms.push_back("falloff"); + mReservedUniforms.push_back("box_center"); + mReservedUniforms.push_back("box_size"); + mReservedUniforms.push_back("minLuminance"); mReservedUniforms.push_back("maxExtractAlpha"); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index e28bda6de2..aa669925ee 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -97,6 +97,8 @@ public: LIGHT_CENTER, LIGHT_SIZE, LIGHT_FALLOFF, + BOX_CENTER, + BOX_SIZE, GLOW_MIN_LUMINANCE, GLOW_MAX_EXTRACT_ALPHA, -- cgit v1.2.3 From e3a5125b41def6dbc27c6852f48b45da7377bb50 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 25 May 2012 17:58:12 -0500 Subject: MAINT-616 Potential fix for corrupted mip maps. --- indra/llrender/llgl.cpp | 3 +- indra/llrender/llimagegl.cpp | 84 +++++++++++++++++++++++---------------- indra/llrender/llimagegl.h | 5 ++- indra/llrender/llrender.cpp | 18 ++++++++- indra/llrender/llrendertarget.cpp | 4 +- 5 files changed, 72 insertions(+), 42 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 3946c43929..0b56b3889c 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -946,7 +946,6 @@ void LLGLManager::initExtensions() mHasMultitexture = glh_init_extensions("GL_ARB_multitexture"); mHasATIMemInfo = ExtensionExists("GL_ATI_meminfo", gGLHExts.mSysExts); mHasNVXMemInfo = ExtensionExists("GL_NVX_gpu_memory_info", gGLHExts.mSysExts); - mHasMipMapGeneration = glh_init_extensions("GL_SGIS_generate_mipmap"); mHasSeparateSpecularColor = glh_init_extensions("GL_EXT_separate_specular_color"); mHasAnisotropic = glh_init_extensions("GL_EXT_texture_filter_anisotropic"); glh_init_extensions("GL_ARB_texture_cube_map"); @@ -971,6 +970,8 @@ void LLGLManager::initExtensions() ExtensionExists("GL_EXT_packed_depth_stencil", gGLHExts.mSysExts); #endif + mHasMipMapGeneration = mHasFramebufferObject || mGLVersion >= 1.4f; + mHasDrawBuffers = ExtensionExists("GL_ARB_draw_buffers", gGLHExts.mSysExts); mHasBlendFuncSeparate = ExtensionExists("GL_EXT_blend_func_separate", gGLHExts.mSysExts); mHasTextureRectangle = ExtensionExists("GL_ARB_texture_rectangle", gGLHExts.mSysExts); diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index bb585cc49c..793fd4be31 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -42,6 +42,10 @@ //---------------------------------------------------------------------------- const F32 MIN_TEXTURE_LIFETIME = 10.f; +//which power of 2 is i? +//assumes i is a power of 2 > 0 +U32 wpo2(U32 i); + //statics LLGLuint LLImageGL::sCurrentBoundTextures[MAX_GL_TEXTURE_UNITS] = { 0 }; @@ -485,6 +489,7 @@ void LLImageGL::init(BOOL usemipmaps) mTarget = GL_TEXTURE_2D; mBindTarget = LLTexUnit::TT_TEXTURE; mHasMipMaps = false; + mMipLevels = -1; mIsResident = 0; @@ -675,8 +680,24 @@ void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips) is_compressed = true; } + + + if (mUseMipMaps) + { + //set has mip maps to true before binding image so tex parameters get set properly + gGL.getTexUnit(0)->unbind(mBindTarget); + mHasMipMaps = true; + mTexOptionsDirty = true; + setFilteringOption(LLTexUnit::TFO_ANISOTROPIC); + } + else + { + mHasMipMaps = false; + } + llverify(gGL.getTexUnit(0)->bind(this)); + if (mUseMipMaps) { if (data_hasmips) @@ -689,6 +710,9 @@ void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips) S32 w = getWidth(d); S32 h = getHeight(d); S32 gl_level = d-mCurrentDiscardLevel; + + mMipLevels = llmax(mMipLevels, gl_level); + if (d > mCurrentDiscardLevel) { data_in -= dataFormatBytes(mFormatPrimary, w, h); // see above comment @@ -731,10 +755,6 @@ void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips) { if (mAutoGenMips) { - if (!gGLManager.mHasFramebufferObject) - { - glTexParameteri(LLTexUnit::getInternalType(mBindTarget), GL_GENERATE_MIPMAP_SGIS, TRUE); - } stop_glerror(); { // LLFastTimer t2(FTM_TEMP4); @@ -748,6 +768,11 @@ void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips) S32 w = getWidth(mCurrentDiscardLevel); S32 h = getHeight(mCurrentDiscardLevel); + mMipLevels = wpo2(llmax(w, h)); + + //use legacy mipmap generation mode + glTexParameteri(mTarget, GL_GENERATE_MIPMAP, GL_TRUE); + LLImageGL::setManualImage(mTarget, 0, mFormatInternal, w, h, mFormatPrimary, mFormatType, @@ -763,19 +788,10 @@ void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips) stop_glerror(); } } - - if (gGLManager.mHasFramebufferObject) - { - gGL.getTexUnit(0)->unbind(mBindTarget); - gGL.getTexUnit(0)->bind(this); - - glGenerateMipmap(LLTexUnit::getInternalType(mBindTarget)); - } } else { // Create mips by hand - // about 30% faster than autogen on ATI 9800, 50% slower on nVidia 4800 // ~4x faster than gluBuild2DMipmaps S32 width = getWidth(mCurrentDiscardLevel); S32 height = getHeight(mCurrentDiscardLevel); @@ -785,6 +801,9 @@ void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips) const U8* cur_mip_data = 0; S32 prev_mip_size = 0; S32 cur_mip_size = 0; + + mMipLevels = nummips; + for (int m=0; mbindManual(type, textures[i]); - - if (type == LLTexUnit::TT_CUBE_MAP) - { - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - } - else + for (S32 j = 0; j <= mip_levels; j++) { - glTexImage2D(LLTexUnit::getInternalType(type), 0, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + gGL.getTexUnit(0)->bindManual(type, textures[i]); + + glTexImage2D(LLTexUnit::getInternalType(type), j, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); } + + llassert(std::find(sDeadTextureList[type][format].begin(), + sDeadTextureList[type][format].end(), textures[i]) == + sDeadTextureList[type][format].end()); + sDeadTextureList[type][format].push_back(textures[i]); - } + } } } @@ -1284,7 +1298,7 @@ BOOL LLImageGL::createGLTexture() if(mTexName) { - LLImageGL::deleteTextures(mBindTarget, mFormatInternal, 1, (reinterpret_cast(&mTexName))) ; + LLImageGL::deleteTextures(mBindTarget, mFormatInternal, mMipLevels, 1, (reinterpret_cast(&mTexName))) ; } @@ -1451,7 +1465,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_ decTextureCounter(mTextureMemory, mComponents, mCategory) ; } - LLImageGL::deleteTextures(mBindTarget, mFormatInternal, 1, &old_name); + LLImageGL::deleteTextures(mBindTarget, mFormatInternal, mMipLevels, 1, &old_name); stop_glerror(); } @@ -1628,7 +1642,7 @@ void LLImageGL::destroyGLTexture() mTextureMemory = 0; } - LLImageGL::deleteTextures(mBindTarget, mFormatInternal, 1, &mTexName); + LLImageGL::deleteTextures(mBindTarget, mFormatInternal, mMipLevels, 1, &mTexName); mTexName = 0; mCurrentDiscardLevel = -1 ; //invalidate mCurrentDiscardLevel. mGLTextureCreated = FALSE ; diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h index 34efafb015..0d5785d3bf 100644 --- a/indra/llrender/llimagegl.h +++ b/indra/llrender/llimagegl.h @@ -54,7 +54,7 @@ public: // These 2 functions replace glGenTextures() and glDeleteTextures() static void generateTextures(LLTexUnit::eTextureType type, U32 format, S32 numTextures, U32 *textures); - static void deleteTextures(LLTexUnit::eTextureType type, U32 format, S32 numTextures, U32 *textures, bool immediate = false); + static void deleteTextures(LLTexUnit::eTextureType type, U32 format, S32 mip_levels, S32 numTextures, U32 *textures, bool immediate = false); static void deleteDeadTextures(); // Size calculation @@ -220,7 +220,8 @@ protected: LLGLenum mTarget; // Normally GL_TEXTURE2D, sometimes something else (ex. cube maps) LLTexUnit::eTextureType mBindTarget; // Normally TT_TEXTURE, sometimes something else (ex. cube maps) bool mHasMipMaps; - + S32 mMipLevels; + LLGLboolean mIsResident; S8 mComponents; diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 51f45ca91e..b45ff1a6b7 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -474,11 +474,25 @@ void LLTexUnit::setTextureFilteringOption(LLTexUnit::eTextureFilterOptions optio } else if (option >= TFO_BILINEAR) { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_LINEAR); + if (mHasMipMaps) + { + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + } + else + { + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_LINEAR); + } } else { - glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_NEAREST); + if (mHasMipMaps) + { + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + } + else + { + glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_NEAREST); + } } if (gGLManager.mHasAnisotropic) diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index ced6b013ec..99f0da330c 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -294,7 +294,7 @@ void LLRenderTarget::release() } else { - LLImageGL::deleteTextures(mUsage, 0, 1, &mDepth, true); + LLImageGL::deleteTextures(mUsage, 0, 0, 1, &mDepth, true); stop_glerror(); } mDepth = 0; @@ -326,7 +326,7 @@ void LLRenderTarget::release() if (mTex.size() > 0) { sBytesAllocated -= mResX*mResY*4*mTex.size(); - LLImageGL::deleteTextures(mUsage, mInternalFormat[0], mTex.size(), &mTex[0], true); + LLImageGL::deleteTextures(mUsage, mInternalFormat[0], 0, mTex.size(), &mTex[0], true); mTex.clear(); mInternalFormat.clear(); } -- cgit v1.2.3 From 2e26dc3971f80fb177c53bc20c06798bbe4391a6 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 30 May 2012 13:22:04 -0500 Subject: Minor instrumentation tweaks -- add a couple of asserts, a timer, and fix VBO accounting. --- indra/llrender/llvertexbuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index f4bf744e3c..2e7c8a0e8f 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -292,7 +292,7 @@ void LLVBOPool::seedPool() void LLVBOPool::cleanup() { - U32 size = 1; + U32 size = LL_VBO_BLOCK_SIZE; for (U32 i = 0; i < mFreeList.size(); ++i) { @@ -323,7 +323,7 @@ void LLVBOPool::cleanup() } } - size *= 2; + size += LL_VBO_BLOCK_SIZE; } //reset miss counts -- cgit v1.2.3 From 67221663fe46a29daf05e1e19282ad2228908991 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 30 May 2012 14:55:34 -0500 Subject: MAINT-616 Fix for mac build. --- indra/llrender/llglslshader.cpp | 2 ++ indra/llrender/llvertexbuffer.cpp | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'indra/llrender') diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 149e8cc548..7cbf39096e 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -174,10 +174,12 @@ BOOL LLGLSLShader::createShader(vector * attributes, mFeatures.mIndexedTextureChannels = llmin(mFeatures.mIndexedTextureChannels, 1); } +#ifdef GL_INTERLEAVED_ATTRIBS if (varying_count > 0 && varyings) { glTransformFeedbackVaryings(mProgramObject, varying_count, varyings, GL_INTERLEAVED_ATTRIBS); } +#endif // Map attributes and uniforms if (success) diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 2e7c8a0e8f..0092df6587 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -373,7 +373,9 @@ U32 LLVertexBuffer::getVAOName() } else { +#ifdef GL_ARB_vertex_array_object glGenVertexArrays(1, &ret); +#endif } return ret; @@ -2161,9 +2163,11 @@ void LLVertexBuffer::flush() // bind for transform feedback (quick 'n dirty) void LLVertexBuffer::bindForFeedback(U32 channel, U32 type, U32 index, U32 count) { +#ifdef GL_TRANSFORM_FEEDBACK_BUFFER U32 offset = mOffsets[type] + sTypeSize[type]*index; U32 size= (sTypeSize[type]*count); glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, channel, mGLBuffer, offset, size); +#endif } // Set for rendering -- 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 997b360747bb21564f0ef89c3b3e065ea3ec0716 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 11 Jul 2012 15:17:13 -0500 Subject: MAINT-794 Fix for assert on loading some types of objects before their parents. --- indra/llrender/llshadermgr.cpp | 39 ++++++++++++++++++++++++++------------- indra/llrender/llvertexbuffer.cpp | 6 +++--- 2 files changed, 29 insertions(+), 16 deletions(-) (limited to 'indra/llrender') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index d3b2d9fa74..a9248d4d73 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -702,7 +702,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade if (texture_index_channels > 1) { - text[count++] = strdup("VARYING_FLAT ivec4 vary_texture_index;\n"); + text[count++] = strdup("VARYING_FLAT int vary_texture_index;\n"); } text[count++] = strdup("vec4 diffuseLookup(vec2 texcoord)\n"); @@ -716,20 +716,33 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade } else if (major_version > 1 || minor_version >= 30) { //switches are supported in GLSL 1.30 and later - text[count++] = strdup("\tvec4 ret = vec4(1,0,1,1);\n"); - text[count++] = strdup("\tswitch (vary_texture_index.r)\n"); - text[count++] = strdup("\t{\n"); - - //switch body - for (S32 i = 0; i < texture_index_channels; ++i) - { - std::string case_str = llformat("\t\tcase %d: ret = texture2D(tex%d, texcoord); break;\n", i, i); - text[count++] = strdup(case_str.c_str()); + if (gGLManager.mIsNVIDIA) + { //switches are unreliable on some NVIDIA drivers + for (U32 i = 0; i < texture_index_channels; ++i) + { + std::string if_string = llformat("\t%sif (vary_texture_index == %d) { return texture2D(tex%d, texcoord); }\n", i > 0 ? "else " : "", i, i); + text[count++] = strdup(if_string.c_str()); + } + text[count++] = strdup("\treturn vec4(1,0,1,1);\n"); + text[count++] = strdup("}\n"); } + else + { + text[count++] = strdup("\tvec4 ret = vec4(1,0,1,1);\n"); + text[count++] = strdup("\tswitch (vary_texture_index)\n"); + text[count++] = strdup("\t{\n"); + + //switch body + for (S32 i = 0; i < texture_index_channels; ++i) + { + std::string case_str = llformat("\t\tcase %d: return texture2D(tex%d, texcoord);\n", i, i); + text[count++] = strdup(case_str.c_str()); + } - text[count++] = strdup("\t}\n"); - text[count++] = strdup("\treturn ret;\n"); - text[count++] = strdup("}\n"); + text[count++] = strdup("\t}\n"); + text[count++] = strdup("\treturn ret;\n"); + text[count++] = strdup("}\n"); + } } else { //should never get here. Indexed texture rendering requires GLSL 1.30 or later diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 953546a36f..80752231d7 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -1330,7 +1330,7 @@ void LLVertexBuffer::setupVertexArray() 1, //TYPE_WEIGHT, 4, //TYPE_WEIGHT4, 4, //TYPE_CLOTHWEIGHT, - 4, //TYPE_TEXTURE_INDEX + 1, //TYPE_TEXTURE_INDEX }; U32 attrib_type[] = @@ -1347,7 +1347,7 @@ void LLVertexBuffer::setupVertexArray() GL_FLOAT, //TYPE_WEIGHT, GL_FLOAT, //TYPE_WEIGHT4, GL_FLOAT, //TYPE_CLOTHWEIGHT, - GL_UNSIGNED_BYTE, //TYPE_TEXTURE_INDEX + GL_UNSIGNED_INT, //TYPE_TEXTURE_INDEX }; bool attrib_integer[] = @@ -2404,7 +2404,7 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) #if !LL_DARWIN S32 loc = TYPE_TEXTURE_INDEX; void *ptr = (void*) (base + mOffsets[TYPE_VERTEX] + 12); - glVertexAttribIPointer(loc, 4, GL_UNSIGNED_BYTE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); + glVertexAttribIPointer(loc, 1, GL_UNSIGNED_INT, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); #endif } if (data_mask & MAP_VERTEX) -- 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