PageRenderTime 38ms CodeModel.GetById 1ms app.highlight 33ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llvoground.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 168 lines | 101 code | 31 blank | 36 comment | 7 complexity | d5c127a96e67c31ba681a3d08f6f3093 MD5 | raw file
  1/** 
  2 * @file llvoground.cpp
  3 * @brief LLVOGround class implementation
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llvoground.h"
 30#include "lldrawpoolground.h"
 31
 32#include "llviewercontrol.h"
 33
 34#include "lldrawable.h"
 35#include "llface.h"
 36#include "llsky.h"
 37#include "llviewercamera.h"
 38#include "llviewerregion.h"
 39#include "pipeline.h"
 40
 41LLVOGround::LLVOGround(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
 42:	LLStaticViewerObject(id, pcode, regionp, TRUE)
 43{
 44	mbCanSelect = FALSE;
 45}
 46
 47
 48LLVOGround::~LLVOGround()
 49{
 50}
 51
 52BOOL LLVOGround::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time)
 53{
 54 	if (mDead || !(gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_GROUND)))
 55	{
 56		return TRUE;
 57	}
 58	
 59	/*if (mDrawable)
 60	{
 61		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE);
 62	}*/
 63	return TRUE;
 64}
 65
 66
 67void LLVOGround::updateTextures()
 68{
 69}
 70
 71
 72LLDrawable *LLVOGround::createDrawable(LLPipeline *pipeline)
 73{
 74	pipeline->allocDrawable(this);
 75	mDrawable->setLit(FALSE);
 76
 77	mDrawable->setRenderType(LLPipeline::RENDER_TYPE_GROUND);
 78	LLDrawPoolGround *poolp = (LLDrawPoolGround*) gPipeline.getPool(LLDrawPool::POOL_GROUND);
 79
 80	mDrawable->addFace(poolp, NULL);
 81
 82	return mDrawable;
 83}
 84
 85BOOL LLVOGround::updateGeometry(LLDrawable *drawable)
 86{
 87	LLStrider<LLVector3> verticesp;
 88	LLStrider<LLVector3> normalsp;
 89	LLStrider<LLVector2> texCoordsp;
 90	LLStrider<U16> indicesp;
 91	S32 index_offset;
 92	LLFace *face;	
 93
 94	LLDrawPoolGround *poolp = (LLDrawPoolGround*) gPipeline.getPool(LLDrawPool::POOL_GROUND);
 95
 96	if (drawable->getNumFaces() < 1)
 97		drawable->addFace(poolp, NULL);
 98	face = drawable->getFace(0); 
 99		
100	if (!face->getVertexBuffer())
101	{
102		face->setSize(5, 12);
103		LLVertexBuffer* buff = new LLVertexBuffer(LLDrawPoolGround::VERTEX_DATA_MASK, GL_STREAM_DRAW_ARB);
104		buff->allocateBuffer(face->getGeomCount(), face->getIndicesCount(), TRUE);
105		face->setGeomIndex(0);
106		face->setIndicesIndex(0);
107		face->setVertexBuffer(buff);
108	}
109	
110	index_offset = face->getGeometry(verticesp,normalsp,texCoordsp, indicesp);
111	if (-1 == index_offset)
112	{
113		return TRUE;
114	}
115
116	///////////////////////////////////////
117	//
118	//
119	//
120	LLVector3 at_dir = LLViewerCamera::getInstance()->getAtAxis();
121	at_dir.mV[VZ] = 0.f;
122	if (at_dir.normVec() < 0.01)
123	{
124		// We really don't care, as we're not looking anywhere near the horizon.
125	}
126	LLVector3 left_dir = LLViewerCamera::getInstance()->getLeftAxis();
127	left_dir.mV[VZ] = 0.f;
128	left_dir.normVec();
129
130	// Our center top point
131	LLColor4 ground_color = gSky.getFogColor();
132	ground_color.mV[3] = 1.f;
133	face->setFaceColor(ground_color);
134	
135	*(verticesp++)  = LLVector3(64, 64, 0);
136	*(verticesp++)  = LLVector3(-64, 64, 0);
137	*(verticesp++)  = LLVector3(-64, -64, 0);
138	*(verticesp++)  = LLVector3(64, -64, 0);
139	*(verticesp++)  = LLVector3(0, 0, -1024);
140	
141	
142	// Triangles for each side
143	*indicesp++ = index_offset + 0;
144	*indicesp++ = index_offset + 1;
145	*indicesp++ = index_offset + 4;
146
147	*indicesp++ = index_offset + 1;
148	*indicesp++ = index_offset + 2;
149	*indicesp++ = index_offset + 4;
150
151	*indicesp++ = index_offset + 2;
152	*indicesp++ = index_offset + 3;
153	*indicesp++ = index_offset + 4;
154
155	*indicesp++ = index_offset + 3;
156	*indicesp++ = index_offset + 0;
157	*indicesp++ = index_offset + 4;
158
159	*(texCoordsp++) = LLVector2(0.f, 0.f);
160	*(texCoordsp++) = LLVector2(1.f, 0.f);
161	*(texCoordsp++) = LLVector2(1.f, 1.f);
162	*(texCoordsp++) = LLVector2(0.f, 1.f);
163	*(texCoordsp++) = LLVector2(0.5f, 0.5f);
164	
165	face->getVertexBuffer()->flush();
166	LLPipeline::sCompiles++;
167	return TRUE;
168}