From 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:44:46 -0500 Subject: Second Life viewer sources 1.13.2.12 --- linden/indra/newview/llpatchvertexarray.cpp | 250 ++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 linden/indra/newview/llpatchvertexarray.cpp (limited to 'linden/indra/newview/llpatchvertexarray.cpp') diff --git a/linden/indra/newview/llpatchvertexarray.cpp b/linden/indra/newview/llpatchvertexarray.cpp new file mode 100644 index 0000000..992423e --- /dev/null +++ b/linden/indra/newview/llpatchvertexarray.cpp @@ -0,0 +1,250 @@ +/** + * @file llpatchvertexarray.cpp + * @brief Implementation of the LLSurfaceVertexArray class. + * + * Copyright (c) 2001-2007, Linden Research, Inc. + * + * The source code in this file ("Source Code") is provided by Linden Lab + * to you under the terms of the GNU General Public License, version 2.0 + * ("GPL"), unless you have obtained a separate licensing agreement + * ("Other License"), formally executed by you and Linden Lab. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlife.com/developers/opensource/gplv2 + * + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at http://secondlife.com/developers/opensource/flossexception + * + * By copying, modifying or distributing this software, you acknowledge + * that you have read and understood your obligations described above, + * and agree to abide by those obligations. + * + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. + */ + +#include "llviewerprecompiledheaders.h" + +#include "llpatchvertexarray.h" +#include "llsurfacepatch.h" + +// constructors + +LLPatchVertexArray::LLPatchVertexArray() : + mSurfaceWidth(0), + mPatchWidth(0), + mPatchOrder(0), + mRenderLevelp(NULL), + mRenderStridep(NULL) +{ +} + +LLPatchVertexArray::LLPatchVertexArray(U32 surface_width, U32 patch_width, F32 meters_per_grid) : + mRenderLevelp(NULL), + mRenderStridep(NULL) +{ + create(surface_width, patch_width, meters_per_grid); +} + + +LLPatchVertexArray::~LLPatchVertexArray() +{ + destroy(); +} + + +void LLPatchVertexArray::create(U32 surface_width, U32 patch_width, F32 meters_per_grid) +{ + // PART 1 -- Make sure the arguments are good... + // Make sure patch_width is not greater than surface_width + if (patch_width > surface_width) + { + U32 temp = patch_width; + patch_width = surface_width; + surface_width = temp; + } + + // Make sure (surface_width-1) is equal to a power_of_two. + // (The -1 is there because an LLSurface has a buffer of 1 on + // its East and North edges). + U32 power_of_two = 1; + U32 surface_order = 0; + while (power_of_two < (surface_width-1)) + { + power_of_two *= 2; + surface_order += 1; + } + + if (power_of_two == (surface_width-1)) + { + mSurfaceWidth = surface_width; + + // Make sure patch_width is a factor of (surface_width - 1) + U32 ratio = (surface_width - 1) / patch_width; + F32 fratio = ((float)(surface_width - 1)) / ((float)(patch_width)); + if ( fratio == (float)(ratio)) + { + // Make sure patch_width is a power of two + power_of_two = 1; + U32 patch_order = 0; + while (power_of_two < patch_width) + { + power_of_two *= 2; + patch_order += 1; + } + if (power_of_two == patch_width) + { + mPatchWidth = patch_width; + mPatchOrder = patch_order; + } + else // patch_width is not a power of two... + { + mPatchWidth = 0; + mPatchOrder = 0; + } + } + else // patch_width is not a factor of (surface_width - 1)... + { + mPatchWidth = 0; + mPatchOrder = 0; + } + } + else // surface_width is not a power of two... + { + mSurfaceWidth = 0; + mPatchWidth = 0; + mPatchOrder = 0; + } + + // PART 2 -- Allocate memory for the render level table + if (mPatchWidth > 0) + { + mRenderLevelp = new U32 [2*mPatchWidth + 1]; + mRenderStridep = new U32 [mPatchOrder + 1]; + } + + + // Now that we've allocated memory, we can initialize the arrays... + init(); +} + + +void LLPatchVertexArray::destroy() +{ + if (mPatchWidth == 0) + { + return; + } + + delete [] mRenderLevelp; + delete [] mRenderStridep; + mSurfaceWidth = 0; + mPatchWidth = 0; + mPatchOrder = 0; +} + + +void LLPatchVertexArray::init() +// Initializes the triangle strip arrays. +{ + U32 j; + U32 level, stride; + U32 k; + + // We need to build two look-up tables... + + // render_level -> render_stride + // A 16x16 patch has 5 render levels : 2^0 to 2^4 + // render_level render_stride + // 4 1 + // 3 2 + // 2 4 + // 1 8 + // 0 16 + stride = mPatchWidth; + for (level=0; level 2.1f * mRenderStridep[level]) + { + level--; + }; + mRenderLevelp[stride] = level; + } + */ + + // This method is more agressive about putting triangles onscreen + level = mPatchOrder; + k = 2; + mRenderLevelp[0] = mPatchOrder; + mRenderLevelp[1] = mPatchOrder; + stride = 2; + while(stride < 2*mPatchWidth) + { + for (j=0; j