Annotation of /trunk/linden/indra/newview/llvoclouds.cpp
Parent Directory
|
Revision Log
Revision 61 - (view) (download)
| 1 : | mjm | 57 | /** |
| 2 : | * @file llvoclouds.cpp | ||
| 3 : | * @brief Implementation of LLVOClouds class which is a derivation fo LLViewerObject | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2001&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | * Copyright (c) 2001-2008, Linden Research, Inc. | ||
| 8 : | * | ||
| 9 : | * Second Life Viewer Source Code | ||
| 10 : | * The source code in this file ("Source Code") is provided by Linden Lab | ||
| 11 : | * to you under the terms of the GNU General Public License, version 2.0 | ||
| 12 : | * ("GPL"), unless you have obtained a separate licensing agreement | ||
| 13 : | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
| 14 : | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
| 15 : | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
| 16 : | * | ||
| 17 : | * There are special exceptions to the terms and conditions of the GPL as | ||
| 18 : | * it is applied to this Source Code. View the full text of the exception | ||
| 19 : | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
| 20 : | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 21 : | * | ||
| 22 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 23 : | * that you have read and understood your obligations described above, | ||
| 24 : | * and agree to abide by those obligations. | ||
| 25 : | * | ||
| 26 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 27 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 28 : | * COMPLETENESS OR PERFORMANCE. | ||
| 29 : | * $/LicenseInfo$ | ||
| 30 : | */ | ||
| 31 : | |||
| 32 : | #include "llviewerprecompiledheaders.h" | ||
| 33 : | |||
| 34 : | #include "llvoclouds.h" | ||
| 35 : | |||
| 36 : | #include "lldrawpoolalpha.h" | ||
| 37 : | |||
| 38 : | #include "llviewercontrol.h" | ||
| 39 : | |||
| 40 : | #include "llagent.h" // to get camera position | ||
| 41 : | #include "lldrawable.h" | ||
| 42 : | #include "llface.h" | ||
| 43 : | #include "llprimitive.h" | ||
| 44 : | #include "llsky.h" | ||
| 45 : | #include "llviewercamera.h" | ||
| 46 : | #include "llviewerimagelist.h" | ||
| 47 : | #include "llviewerobjectlist.h" | ||
| 48 : | #include "llviewerregion.h" | ||
| 49 : | #include "llvosky.h" | ||
| 50 : | #include "llworld.h" | ||
| 51 : | #include "pipeline.h" | ||
| 52 : | #include "llspatialpartition.h" | ||
| 53 : | |||
| 54 : | LLUUID gCloudTextureID = IMG_CLOUD_POOF; | ||
| 55 : | |||
| 56 : | |||
| 57 : | LLVOClouds::LLVOClouds(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) | ||
| 58 : | : LLAlphaObject(id, LL_VO_CLOUDS, regionp) | ||
| 59 : | { | ||
| 60 : | mCloudGroupp = NULL; | ||
| 61 : | mbCanSelect = FALSE; | ||
| 62 : | setNumTEs(1); | ||
| 63 : | LLViewerImage* image = gImageList.getImage(gCloudTextureID); | ||
| 64 : | image->setBoostLevel(LLViewerImage::BOOST_CLOUDS); | ||
| 65 : | setTEImage(0, image); | ||
| 66 : | } | ||
| 67 : | |||
| 68 : | |||
| 69 : | LLVOClouds::~LLVOClouds() | ||
| 70 : | { | ||
| 71 : | } | ||
| 72 : | |||
| 73 : | |||
| 74 : | BOOL LLVOClouds::isActive() const | ||
| 75 : | { | ||
| 76 : | return TRUE; | ||
| 77 : | } | ||
| 78 : | |||
| 79 : | |||
| 80 : | BOOL LLVOClouds::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time) | ||
| 81 : | { | ||
| 82 : | if (!(gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS))) | ||
| 83 : | { | ||
| 84 : | return TRUE; | ||
| 85 : | } | ||
| 86 : | |||
| 87 : | // Set dirty flag (so renderer will rebuild primitive) | ||
| 88 : | if (mDrawable) | ||
| 89 : | { | ||
| 90 : | gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE); | ||
| 91 : | } | ||
| 92 : | |||
| 93 : | return TRUE; | ||
| 94 : | } | ||
| 95 : | |||
| 96 : | |||
| 97 : | void LLVOClouds::setPixelAreaAndAngle(LLAgent &agent) | ||
| 98 : | { | ||
| 99 : | mAppAngle = 50; | ||
| 100 : | mPixelArea = 1500*100; | ||
| 101 : | } | ||
| 102 : | |||
| 103 : | void LLVOClouds::updateTextures(LLAgent &agent) | ||
| 104 : | { | ||
| 105 : | getTEImage(0)->addTextureStats(mPixelArea); | ||
| 106 : | } | ||
| 107 : | |||
| 108 : | LLDrawable* LLVOClouds::createDrawable(LLPipeline *pipeline) | ||
| 109 : | { | ||
| 110 : | pipeline->allocDrawable(this); | ||
| 111 : | mDrawable->setLit(FALSE); | ||
| 112 : | mDrawable->setRenderType(LLPipeline::RENDER_TYPE_CLOUDS); | ||
| 113 : | |||
| 114 : | return mDrawable; | ||
| 115 : | } | ||
| 116 : | |||
| 117 : | BOOL LLVOClouds::updateGeometry(LLDrawable *drawable) | ||
| 118 : | { | ||
| 119 : | LLFastTimer ftm(LLFastTimer::FTM_UPDATE_CLOUDS); | ||
| 120 : | if (!(gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS))) | ||
| 121 : | { | ||
| 122 : | return TRUE; | ||
| 123 : | } | ||
| 124 : | |||
| 125 : | dirtySpatialGroup(); | ||
| 126 : | |||
| 127 : | LLFace *facep; | ||
| 128 : | |||
| 129 : | S32 num_faces = mCloudGroupp->getNumPuffs(); | ||
| 130 : | |||
| 131 : | if (num_faces > drawable->getNumFaces()) | ||
| 132 : | { | ||
| 133 : | drawable->setNumFacesFast(num_faces, NULL, getTEImage(0)); | ||
| 134 : | } | ||
| 135 : | |||
| 136 : | mDepth = (getPositionAgent()-LLViewerCamera::getInstance()->getOrigin())*LLViewerCamera::getInstance()->getAtAxis(); | ||
| 137 : | |||
| 138 : | S32 face_indx = 0; | ||
| 139 : | for ( ; face_indx < num_faces; face_indx++) | ||
| 140 : | { | ||
| 141 : | facep = drawable->getFace(face_indx); | ||
| 142 : | if (!facep) | ||
| 143 : | { | ||
| 144 : | llwarns << "No facep for index " << face_indx << llendl; | ||
| 145 : | continue; | ||
| 146 : | } | ||
| 147 : | |||
| 148 : | facep->setSize(4, 6); | ||
| 149 : | |||
| 150 : | facep->setTEOffset(face_indx); | ||
| 151 : | facep->setTexture(getTEImage(0)); | ||
| 152 : | const LLCloudPuff &puff = mCloudGroupp->getPuff(face_indx); | ||
| 153 : | const LLVector3 puff_pos_agent = gAgent.getPosAgentFromGlobal(puff.getPositionGlobal()); | ||
| 154 : | facep->mCenterLocal = puff_pos_agent; | ||
| 155 : | /// Update cloud color based on sun color. | ||
| 156 : | LLColor4 float_color(LLColor3(gSky.getSunDiffuseColor() + gSky.getSunAmbientColor()),puff.getAlpha()); | ||
| 157 : | facep->setFaceColor(float_color); | ||
| 158 : | } | ||
| 159 : | for ( ; face_indx < drawable->getNumFaces(); face_indx++) | ||
| 160 : | { | ||
| 161 : | facep = drawable->getFace(face_indx); | ||
| 162 : | if (!facep) | ||
| 163 : | { | ||
| 164 : | llwarns << "No facep for index " << face_indx << llendl; | ||
| 165 : | continue; | ||
| 166 : | } | ||
| 167 : | |||
| 168 : | facep->setTEOffset(face_indx); | ||
| 169 : | facep->setSize(0,0); | ||
| 170 : | } | ||
| 171 : | |||
| 172 : | drawable->movePartition(); | ||
| 173 : | |||
| 174 : | return TRUE; | ||
| 175 : | } | ||
| 176 : | |||
| 177 : | F32 LLVOClouds::getPartSize(S32 idx) | ||
| 178 : | { | ||
| 179 : | return (CLOUD_PUFF_HEIGHT+CLOUD_PUFF_WIDTH)*0.5f; | ||
| 180 : | } | ||
| 181 : | |||
| 182 : | void LLVOClouds::getGeometry(S32 te, | ||
| 183 : | LLStrider<LLVector3>& verticesp, | ||
| 184 : | LLStrider<LLVector3>& normalsp, | ||
| 185 : | LLStrider<LLVector2>& texcoordsp, | ||
| 186 : | LLStrider<LLColor4U>& colorsp, | ||
| 187 : | LLStrider<U16>& indicesp) | ||
| 188 : | { | ||
| 189 : | |||
| 190 : | if (te >= mCloudGroupp->getNumPuffs()) | ||
| 191 : | { | ||
| 192 : | return; | ||
| 193 : | } | ||
| 194 : | |||
| 195 : | LLDrawable* drawable = mDrawable; | ||
| 196 : | LLFace *facep = drawable->getFace(te); | ||
| 197 : | |||
| 198 : | if (!facep->hasGeometry()) | ||
| 199 : | { | ||
| 200 : | return; | ||
| 201 : | } | ||
| 202 : | |||
| 203 : | LLVector3 normal(0.f,0.f,-1.f); | ||
| 204 : | |||
| 205 : | const LLCloudPuff &puff = mCloudGroupp->getPuff(te); | ||
| 206 : | S32 index_offset = facep->getGeomIndex(); | ||
| 207 : | LLColor4 float_color(LLColor3(gSky.getSunDiffuseColor() + gSky.getSunAmbientColor()),puff.getAlpha()); | ||
| 208 : | LLColor4U color; | ||
| 209 : | color.setVec(float_color); | ||
| 210 : | facep->setFaceColor(float_color); | ||
| 211 : | |||
| 212 : | |||
| 213 : | LLVector3 up; | ||
| 214 : | LLVector3 right; | ||
| 215 : | LLVector3 at; | ||
| 216 : | |||
| 217 : | const LLVector3& puff_pos_agent = facep->mCenterLocal; | ||
| 218 : | LLVector2 uvs[4]; | ||
| 219 : | |||
| 220 : | uvs[0].setVec(0.f, 1.f); | ||
| 221 : | uvs[1].setVec(0.f, 0.f); | ||
| 222 : | uvs[2].setVec(1.f, 1.f); | ||
| 223 : | uvs[3].setVec(1.f, 0.f); | ||
| 224 : | |||
| 225 : | LLVector3 vtx[4]; | ||
| 226 : | |||
| 227 : | at = LLViewerCamera::getInstance()->getAtAxis(); | ||
| 228 : | right = at % LLVector3(0.f, 0.f, 1.f); | ||
| 229 : | right.normVec(); | ||
| 230 : | up = right % at; | ||
| 231 : | up.normVec(); | ||
| 232 : | right *= 0.5f*CLOUD_PUFF_WIDTH; | ||
| 233 : | up *= 0.5f*CLOUD_PUFF_HEIGHT;; | ||
| 234 : | |||
| 235 : | *colorsp++ = color; | ||
| 236 : | *colorsp++ = color; | ||
| 237 : | *colorsp++ = color; | ||
| 238 : | *colorsp++ = color; | ||
| 239 : | |||
| 240 : | vtx[0] = puff_pos_agent - right + up; | ||
| 241 : | vtx[1] = puff_pos_agent - right - up; | ||
| 242 : | vtx[2] = puff_pos_agent + right + up; | ||
| 243 : | vtx[3] = puff_pos_agent + right - up; | ||
| 244 : | |||
| 245 : | *verticesp++ = vtx[0]; | ||
| 246 : | *verticesp++ = vtx[1]; | ||
| 247 : | *verticesp++ = vtx[2]; | ||
| 248 : | *verticesp++ = vtx[3]; | ||
| 249 : | |||
| 250 : | *texcoordsp++ = uvs[0]; | ||
| 251 : | *texcoordsp++ = uvs[1]; | ||
| 252 : | *texcoordsp++ = uvs[2]; | ||
| 253 : | *texcoordsp++ = uvs[3]; | ||
| 254 : | |||
| 255 : | *normalsp++ = normal; | ||
| 256 : | *normalsp++ = normal; | ||
| 257 : | *normalsp++ = normal; | ||
| 258 : | *normalsp++ = normal; | ||
| 259 : | |||
| 260 : | *indicesp++ = index_offset + 0; | ||
| 261 : | *indicesp++ = index_offset + 1; | ||
| 262 : | *indicesp++ = index_offset + 2; | ||
| 263 : | |||
| 264 : | *indicesp++ = index_offset + 1; | ||
| 265 : | *indicesp++ = index_offset + 3; | ||
| 266 : | *indicesp++ = index_offset + 2; | ||
| 267 : | } | ||
| 268 : | |||
| 269 : | U32 LLVOClouds::getPartitionType() const | ||
| 270 : | { | ||
| 271 : | return LLViewerRegion::PARTITION_CLOUD; | ||
| 272 : | } | ||
| 273 : | |||
| 274 : | // virtual | ||
| 275 : | void LLVOClouds::updateDrawable(BOOL force_damped) | ||
| 276 : | { | ||
| 277 : | // Force an immediate rebuild on any update | ||
| 278 : | if (mDrawable.notNull()) | ||
| 279 : | { | ||
| 280 : | mDrawable->updateXform(TRUE); | ||
| 281 : | gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL, TRUE); | ||
| 282 : | } | ||
| 283 : | clearChanged(SHIFTED); | ||
| 284 : | } | ||
| 285 : | |||
| 286 : | LLCloudPartition::LLCloudPartition() | ||
| 287 : | { | ||
| 288 : | mDrawableType = LLPipeline::RENDER_TYPE_CLOUDS; | ||
| 289 : | mPartitionType = LLViewerRegion::PARTITION_CLOUD; | ||
| 290 : | } | ||
| 291 : |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

