aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/pipeline.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/pipeline.cpp')
-rw-r--r--linden/indra/newview/pipeline.cpp269
1 files changed, 208 insertions, 61 deletions
diff --git a/linden/indra/newview/pipeline.cpp b/linden/indra/newview/pipeline.cpp
index e7db166..0406520 100644
--- a/linden/indra/newview/pipeline.cpp
+++ b/linden/indra/newview/pipeline.cpp
@@ -4,7 +4,7 @@
4 * 4 *
5 * $LicenseInfo:firstyear=2005&license=viewergpl$ 5 * $LicenseInfo:firstyear=2005&license=viewergpl$
6 * 6 *
7 * Copyright (c) 2005-2008, Linden Research, Inc. 7 * Copyright (c) 2005-2009, Linden Research, Inc.
8 * 8 *
9 * Second Life Viewer Source Code 9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab 10 * The source code in this file ("Source Code") is provided by Linden Lab
@@ -220,6 +220,7 @@ void display_update_camera();
220 220
221S32 LLPipeline::sCompiles = 0; 221S32 LLPipeline::sCompiles = 0;
222 222
223BOOL LLPipeline::sPickAvatar = TRUE;
223BOOL LLPipeline::sDynamicLOD = TRUE; 224BOOL LLPipeline::sDynamicLOD = TRUE;
224BOOL LLPipeline::sShowHUDAttachments = TRUE; 225BOOL LLPipeline::sShowHUDAttachments = TRUE;
225BOOL LLPipeline::sRenderPhysicalBeacons = TRUE; 226BOOL LLPipeline::sRenderPhysicalBeacons = TRUE;
@@ -330,8 +331,15 @@ void LLPipeline::init()
330 mRenderDebugFeatureMask = 0xffffffff; // All debugging features on 331 mRenderDebugFeatureMask = 0xffffffff; // All debugging features on
331 mRenderDebugMask = 0; // All debug starts off 332 mRenderDebugMask = 0; // All debug starts off
332 333
334 // Don't turn on ground when this is set
335 // Mac Books with intel 950s need this
336 if(!gSavedSettings.getBOOL("RenderGround"))
337 {
338 toggleRenderType(RENDER_TYPE_GROUND);
339 }
340
333 mOldRenderDebugMask = mRenderDebugMask; 341 mOldRenderDebugMask = mRenderDebugMask;
334 342
335 mBackfaceCull = TRUE; 343 mBackfaceCull = TRUE;
336 344
337 stop_glerror(); 345 stop_glerror();
@@ -454,7 +462,7 @@ void LLPipeline::resizeScreenTexture()
454 } 462 }
455 463
456 mScreen.release(); 464 mScreen.release();
457 mScreen.allocate(resX, resY, GL_RGBA, TRUE, GL_TEXTURE_RECTANGLE_ARB); 465 mScreen.allocate(resX, resY, GL_RGBA, TRUE, LLTexUnit::TT_RECT_TEXTURE);
458 466
459 llinfos << "RESIZED SCREEN TEXTURE: " << resX << "x" << resY << llendl; 467 llinfos << "RESIZED SCREEN TEXTURE: " << resX << "x" << resY << llendl;
460 } 468 }
@@ -556,7 +564,7 @@ void LLPipeline::createGLBuffers()
556 564
557 for (U32 j = 0; j < 3; j++) 565 for (U32 j = 0; j < 3; j++)
558 { 566 {
559 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, mBlurCubeTexture[j]); 567 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_CUBE_MAP, mBlurCubeTexture[j]);
560 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 568 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
561 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 569 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
562 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 570 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -583,10 +591,11 @@ void LLPipeline::createGLBuffers()
583 mGlow[i].allocate(512,glow_res,GL_RGBA,FALSE); 591 mGlow[i].allocate(512,glow_res,GL_RGBA,FALSE);
584 } 592 }
585 593
594
586 GLuint resX = gViewerWindow->getWindowDisplayWidth(); 595 GLuint resX = gViewerWindow->getWindowDisplayWidth();
587 GLuint resY = gViewerWindow->getWindowDisplayHeight(); 596 GLuint resY = gViewerWindow->getWindowDisplayHeight();
588 597
589 mScreen.allocate(resX, resY, GL_RGBA, TRUE, GL_TEXTURE_RECTANGLE_ARB); 598 mScreen.allocate(resX, resY, GL_RGBA, TRUE, LLTexUnit::TT_RECT_TEXTURE);
590 } 599 }
591} 600}
592 601
@@ -1212,7 +1221,7 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result, S32 water_cl
1212 LLVertexBuffer::unbind(); 1221 LLVertexBuffer::unbind();
1213 LLGLDisable blend(GL_BLEND); 1222 LLGLDisable blend(GL_BLEND);
1214 LLGLDisable test(GL_ALPHA_TEST); 1223 LLGLDisable test(GL_ALPHA_TEST);
1215 LLViewerImage::unbindTexture(0, GL_TEXTURE_2D); 1224 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1216 1225
1217 gGL.setColorMask(false, false); 1226 gGL.setColorMask(false, false);
1218 LLGLDepthTest depth(GL_TRUE, GL_FALSE); 1227 LLGLDepthTest depth(GL_TRUE, GL_FALSE);
@@ -1357,7 +1366,7 @@ void LLPipeline::doOcclusion(LLCamera& camera)
1357 } 1366 }
1358 LLGLDisable blend(GL_BLEND); 1367 LLGLDisable blend(GL_BLEND);
1359 LLGLDisable test(GL_ALPHA_TEST); 1368 LLGLDisable test(GL_ALPHA_TEST);
1360 LLViewerImage::unbindTexture(0, GL_TEXTURE_2D); 1369 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1361 LLGLDepthTest depth(GL_TRUE, GL_FALSE); 1370 LLGLDepthTest depth(GL_TRUE, GL_FALSE);
1362 1371
1363 if (LLPipeline::sUseOcclusion > 1) 1372 if (LLPipeline::sUseOcclusion > 1)
@@ -2334,7 +2343,7 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate)
2334 } 2343 }
2335 } 2344 }
2336 2345
2337 2346 LLAppViewer::instance()->pingMainloopTimeout("Pipeline:ForceVBO");
2338 2347
2339 //by bao 2348 //by bao
2340 //fake vertex buffer updating 2349 //fake vertex buffer updating
@@ -2368,7 +2377,7 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate)
2368 sUnderWaterRender = FALSE; 2377 sUnderWaterRender = FALSE;
2369 } 2378 }
2370 2379
2371 LLViewerImage::sDefaultImagep->bind(0); 2380 gGL.getTexUnit(0)->bind(LLViewerImage::sDefaultImagep);
2372 LLViewerImage::sDefaultImagep->setClamp(FALSE, FALSE); 2381 LLViewerImage::sDefaultImagep->setClamp(FALSE, FALSE);
2373 2382
2374 ////////////////////////////////////////////// 2383 //////////////////////////////////////////////
@@ -2381,12 +2390,16 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate)
2381 2390
2382 U32 cur_type = 0; 2391 U32 cur_type = 0;
2383 2392
2393 LLAppViewer::instance()->pingMainloopTimeout("Pipeline:RenderDrawPools");
2394
2384 if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_PICKING)) 2395 if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_PICKING))
2385 { 2396 {
2397 LLAppViewer::instance()->pingMainloopTimeout("Pipeline:RenderForSelect");
2386 gObjectList.renderObjectsForSelect(camera, gViewerWindow->getVirtualWindowRect()); 2398 gObjectList.renderObjectsForSelect(camera, gViewerWindow->getVirtualWindowRect());
2387 } 2399 }
2388 else if (gSavedSettings.getBOOL("RenderDeferred")) 2400 else if (gSavedSettings.getBOOL("RenderDeferred"))
2389 { 2401 {
2402 LLAppViewer::instance()->pingMainloopTimeout("Pipeline:RenderDeferred");
2390 renderGeomDeferred(); 2403 renderGeomDeferred();
2391 } 2404 }
2392 else 2405 else
@@ -2474,6 +2487,8 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate)
2474 stop_glerror(); 2487 stop_glerror();
2475 } 2488 }
2476 } 2489 }
2490
2491 LLAppViewer::instance()->pingMainloopTimeout("Pipeline:RenderDrawPoolsEnd");
2477 2492
2478 LLVertexBuffer::unbind(); 2493 LLVertexBuffer::unbind();
2479 LLGLState::checkStates(); 2494 LLGLState::checkStates();
@@ -2497,6 +2512,8 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate)
2497 LLGLState::checkTextureChannels(); 2512 LLGLState::checkTextureChannels();
2498 LLGLState::checkClientArrays(); 2513 LLGLState::checkClientArrays();
2499 2514
2515 LLAppViewer::instance()->pingMainloopTimeout("Pipeline:RenderHighlights");
2516
2500 if (!sReflectionRender) 2517 if (!sReflectionRender)
2501 { 2518 {
2502 renderHighlights(); 2519 renderHighlights();
@@ -2506,6 +2523,8 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate)
2506 // have touch-handlers. 2523 // have touch-handlers.
2507 mHighlightFaces.clear(); 2524 mHighlightFaces.clear();
2508 2525
2526 LLAppViewer::instance()->pingMainloopTimeout("Pipeline:RenderDebug");
2527
2509 renderDebug(); 2528 renderDebug();
2510 2529
2511 LLVertexBuffer::unbind(); 2530 LLVertexBuffer::unbind();
@@ -2518,6 +2537,8 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate)
2518 gObjectList.resetObjectBeacons(); 2537 gObjectList.resetObjectBeacons();
2519 } 2538 }
2520 2539
2540 LLAppViewer::instance()->pingMainloopTimeout("Pipeline:RenderGeomEnd");
2541
2521 //HACK: preserve/restore matrices around HUD render 2542 //HACK: preserve/restore matrices around HUD render
2522 if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD)) 2543 if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD))
2523 { 2544 {
@@ -2604,11 +2625,11 @@ void LLPipeline::renderDebug()
2604 // Debug composition layers 2625 // Debug composition layers
2605 F32 x, y; 2626 F32 x, y;
2606 2627
2607 LLGLSNoTexture gls_no_texture; 2628 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
2608 2629
2609 if (gAgent.getRegion()) 2630 if (gAgent.getRegion())
2610 { 2631 {
2611 gGL.begin(LLVertexBuffer::POINTS); 2632 gGL.begin(LLRender::POINTS);
2612 // Draw the composition layer for the region that I'm in. 2633 // Draw the composition layer for the region that I'm in.
2613 for (x = 0; x <= 260; x++) 2634 for (x = 0; x <= 260; x++)
2614 { 2635 {
@@ -2654,6 +2675,7 @@ void LLPipeline::renderForSelect(std::set<LLViewerObject*>& objects, BOOL render
2654 2675
2655 LLGLSDefault gls_default; 2676 LLGLSDefault gls_default;
2656 LLGLSObjectSelect gls_object_select; 2677 LLGLSObjectSelect gls_object_select;
2678 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
2657 LLGLDepthTest gls_depth(GL_TRUE,GL_TRUE); 2679 LLGLDepthTest gls_depth(GL_TRUE,GL_TRUE);
2658 disableLights(); 2680 disableLights();
2659 2681
@@ -3101,7 +3123,7 @@ void LLPipeline::setupAvatarLights(BOOL for_edit)
3101 camera_rot.invert(); 3123 camera_rot.invert();
3102 LLVector4 light_pos = light_pos_cam * camera_rot; 3124 LLVector4 light_pos = light_pos_cam * camera_rot;
3103 3125
3104 light_pos.normVec(); 3126 light_pos.normalize();
3105 3127
3106 mHWLightColors[1] = diffuse; 3128 mHWLightColors[1] = diffuse;
3107 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse.mV); 3129 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse.mV);
@@ -3119,7 +3141,7 @@ void LLPipeline::setupAvatarLights(BOOL for_edit)
3119 LLVector3 opposite_pos = -1.f * mSunDir; 3141 LLVector3 opposite_pos = -1.f * mSunDir;
3120 LLVector3 orthog_light_pos = mSunDir % LLVector3::z_axis; 3142 LLVector3 orthog_light_pos = mSunDir % LLVector3::z_axis;
3121 LLVector4 backlight_pos = LLVector4(lerp(opposite_pos, orthog_light_pos, 0.3f), 0.0f); 3143 LLVector4 backlight_pos = LLVector4(lerp(opposite_pos, orthog_light_pos, 0.3f), 0.0f);
3122 backlight_pos.normVec(); 3144 backlight_pos.normalize();
3123 3145
3124 LLColor4 light_diffuse = mSunDiffuse; 3146 LLColor4 light_diffuse = mSunDiffuse;
3125 LLColor4 backlight_diffuse(1.f - light_diffuse.mV[VRED], 1.f - light_diffuse.mV[VGREEN], 1.f - light_diffuse.mV[VBLUE], 1.f); 3147 LLColor4 backlight_diffuse(1.f - light_diffuse.mV[VRED], 1.f - light_diffuse.mV[VGREEN], 1.f - light_diffuse.mV[VBLUE], 1.f);
@@ -3458,7 +3480,7 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
3458 atten = x / (light_radius); // % of brightness at radius 3480 atten = x / (light_radius); // % of brightness at radius
3459 quad = 0.0f; 3481 quad = 0.0f;
3460 } 3482 }
3461 //mHWLightColors[cur_light] = light_color; 3483 mHWLightColors[2] = light_color;
3462 S32 gllight = GL_LIGHT2; 3484 S32 gllight = GL_LIGHT2;
3463 glLightfv(gllight, GL_POSITION, light_pos_gl.mV); 3485 glLightfv(gllight, GL_POSITION, light_pos_gl.mV);
3464 glLightfv(gllight, GL_DIFFUSE, light_color.mV); 3486 glLightfv(gllight, GL_DIFFUSE, light_color.mV);
@@ -3999,6 +4021,7 @@ BOOL LLPipeline::getRenderHighlights(void*)
3999} 4021}
4000 4022
4001LLViewerObject* LLPipeline::lineSegmentIntersectInWorld(const LLVector3& start, const LLVector3& end, 4023LLViewerObject* LLPipeline::lineSegmentIntersectInWorld(const LLVector3& start, const LLVector3& end,
4024 BOOL pick_transparent,
4002 S32* face_hit, 4025 S32* face_hit,
4003 LLVector3* intersection, // return the intersection point 4026 LLVector3* intersection, // return the intersection point
4004 LLVector2* tex_coord, // return the texture coordinates of the intersection point 4027 LLVector2* tex_coord, // return the texture coordinates of the intersection point
@@ -4008,6 +4031,12 @@ LLViewerObject* LLPipeline::lineSegmentIntersectInWorld(const LLVector3& start,
4008{ 4031{
4009 LLDrawable* drawable = NULL; 4032 LLDrawable* drawable = NULL;
4010 4033
4034 LLVector3 local_end = end;
4035
4036 LLVector3 position;
4037
4038 sPickAvatar = FALSE; //LLToolMgr::getInstance()->inBuildMode() ? FALSE : TRUE;
4039
4011 for (LLWorld::region_list_t::iterator iter = LLWorld::getInstance()->getRegionList().begin(); 4040 for (LLWorld::region_list_t::iterator iter = LLWorld::getInstance()->getRegionList().begin();
4012 iter != LLWorld::getInstance()->getRegionList().end(); ++iter) 4041 iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
4013 { 4042 {
@@ -4015,24 +4044,124 @@ LLViewerObject* LLPipeline::lineSegmentIntersectInWorld(const LLVector3& start,
4015 4044
4016 for (U32 j = 0; j < LLViewerRegion::NUM_PARTITIONS; j++) 4045 for (U32 j = 0; j < LLViewerRegion::NUM_PARTITIONS; j++)
4017 { 4046 {
4018 if ((j == LLViewerRegion::PARTITION_VOLUME) || (j == LLViewerRegion::PARTITION_BRIDGE)) // only check these partitions for now 4047 if ((j == LLViewerRegion::PARTITION_VOLUME) ||
4048 (j == LLViewerRegion::PARTITION_BRIDGE) ||
4049 (j == LLViewerRegion::PARTITION_TERRAIN) ||
4050 (j == LLViewerRegion::PARTITION_TREE) ||
4051 (j == LLViewerRegion::PARTITION_GRASS)) // only check these partitions for now
4019 { 4052 {
4020 LLSpatialPartition* part = region->getSpatialPartition(j); 4053 LLSpatialPartition* part = region->getSpatialPartition(j);
4021 if (part) 4054 if (part && hasRenderType(part->mDrawableType))
4022 { 4055 {
4023 LLDrawable* hit = part->lineSegmentIntersect(start, end, face_hit, intersection, tex_coord, normal, bi_normal); 4056 LLDrawable* hit = part->lineSegmentIntersect(start, local_end, pick_transparent, face_hit, &position, tex_coord, normal, bi_normal);
4024 if (hit) 4057 if (hit)
4025 { 4058 {
4026 drawable = hit; 4059 drawable = hit;
4060 local_end = position;
4061 }
4062 }
4063 }
4064 }
4065 }
4066
4067 if (!sPickAvatar)
4068 {
4069 //save hit info in case we need to restore
4070 //due to attachment override
4071 LLVector3 local_normal;
4072 LLVector3 local_binormal;
4073 LLVector2 local_texcoord;
4074 S32 local_face_hit = -1;
4075
4076 if (face_hit)
4077 {
4078 local_face_hit = *face_hit;
4079 }
4080 if (tex_coord)
4081 {
4082 local_texcoord = *tex_coord;
4083 }
4084 if (bi_normal)
4085 {
4086 local_binormal = *bi_normal;
4087 }
4088 if (normal)
4089 {
4090 local_normal = *normal;
4091 }
4092
4093 const F32 ATTACHMENT_OVERRIDE_DIST = 0.1f;
4094
4095 //check against avatars
4096 sPickAvatar = TRUE;
4097 for (LLWorld::region_list_t::iterator iter = LLWorld::getInstance()->getRegionList().begin();
4098 iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
4099 {
4100 LLViewerRegion* region = *iter;
4101
4102 LLSpatialPartition* part = region->getSpatialPartition(LLViewerRegion::PARTITION_BRIDGE);
4103 if (part && hasRenderType(part->mDrawableType))
4104 {
4105 LLDrawable* hit = part->lineSegmentIntersect(start, local_end, pick_transparent, face_hit, &position, tex_coord, normal, bi_normal);
4106 if (hit)
4107 {
4108 if (!drawable ||
4109 !drawable->getVObj()->isAttachment() ||
4110 (position-local_end).magVec() > ATTACHMENT_OVERRIDE_DIST)
4111 { //avatar overrides if previously hit drawable is not an attachment or
4112 //attachment is far enough away from detected intersection
4113 drawable = hit;
4114 local_end = position;
4115 }
4116 else
4117 { //prioritize attachments over avatars
4118 position = local_end;
4119
4120 if (face_hit)
4121 {
4122 *face_hit = local_face_hit;
4123 }
4124 if (tex_coord)
4125 {
4126 *tex_coord = local_texcoord;
4127 }
4128 if (bi_normal)
4129 {
4130 *bi_normal = local_binormal;
4131 }
4132 if (normal)
4133 {
4134 *normal = local_normal;
4135 }
4027 } 4136 }
4028 } 4137 }
4029 } 4138 }
4030 } 4139 }
4031 } 4140 }
4141
4142 //check all avatar nametags (silly, isn't it?)
4143 for (std::vector< LLCharacter* >::iterator iter = LLCharacter::sInstances.begin();
4144 iter != LLCharacter::sInstances.end();
4145 ++iter)
4146 {
4147 LLVOAvatar* av = (LLVOAvatar*) *iter;
4148 if (av->mNameText.notNull() && av->mNameText->lineSegmentIntersect(start, local_end, position))
4149 {
4150 drawable = av->mDrawable;
4151 local_end = position;
4152 }
4153 }
4154
4155 if (intersection)
4156 {
4157 *intersection = position;
4158 }
4159
4032 return drawable ? drawable->getVObj().get() : NULL; 4160 return drawable ? drawable->getVObj().get() : NULL;
4033} 4161}
4034 4162
4035LLViewerObject* LLPipeline::lineSegmentIntersectInHUD(const LLVector3& start, const LLVector3& end, 4163LLViewerObject* LLPipeline::lineSegmentIntersectInHUD(const LLVector3& start, const LLVector3& end,
4164 BOOL pick_transparent,
4036 S32* face_hit, 4165 S32* face_hit,
4037 LLVector3* intersection, // return the intersection point 4166 LLVector3* intersection, // return the intersection point
4038 LLVector2* tex_coord, // return the texture coordinates of the intersection point 4167 LLVector2* tex_coord, // return the texture coordinates of the intersection point
@@ -4047,15 +4176,27 @@ LLViewerObject* LLPipeline::lineSegmentIntersectInHUD(const LLVector3& start, co
4047 { 4176 {
4048 LLViewerRegion* region = *iter; 4177 LLViewerRegion* region = *iter;
4049 4178
4179 BOOL toggle = FALSE;
4180 if (!hasRenderType(LLPipeline::RENDER_TYPE_HUD))
4181 {
4182 toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
4183 toggle = TRUE;
4184 }
4185
4050 LLSpatialPartition* part = region->getSpatialPartition(LLViewerRegion::PARTITION_HUD); 4186 LLSpatialPartition* part = region->getSpatialPartition(LLViewerRegion::PARTITION_HUD);
4051 if (part) 4187 if (part)
4052 { 4188 {
4053 LLDrawable* hit = part->lineSegmentIntersect(start, end, face_hit, intersection, tex_coord, normal, bi_normal); 4189 LLDrawable* hit = part->lineSegmentIntersect(start, end, pick_transparent, face_hit, intersection, tex_coord, normal, bi_normal);
4054 if (hit) 4190 if (hit)
4055 { 4191 {
4056 drawable = hit; 4192 drawable = hit;
4057 } 4193 }
4058 } 4194 }
4195
4196 if (toggle)
4197 {
4198 toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
4199 }
4059 } 4200 }
4060 return drawable ? drawable->getVObj().get() : NULL; 4201 return drawable ? drawable->getVObj().get() : NULL;
4061} 4202}
@@ -4209,7 +4350,8 @@ void LLPipeline::generateReflectionMap(LLCubeMap* cube_map, LLCamera& cube_cam)
4209 4350
4210 LLPipeline::sReflectionRender = TRUE; 4351 LLPipeline::sReflectionRender = TRUE;
4211 4352
4212 cube_map->bind(); 4353 gGL.getTexUnit(cube_map->getStage())->bind(cube_map);
4354 gGL.getTexUnit(0)->activate();
4213 GLint width; 4355 GLint width;
4214 glGetTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL_TEXTURE_WIDTH, &width); 4356 glGetTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL_TEXTURE_WIDTH, &width);
4215 if (width != res) 4357 if (width != res)
@@ -4221,8 +4363,10 @@ void LLPipeline::generateReflectionMap(LLCubeMap* cube_map, LLCamera& cube_cam)
4221 glTexImage2D(gl_cube_face[i], 0, GL_RGBA, res, res, 0, GL_RGBA, GL_FLOAT, NULL); 4363 glTexImage2D(gl_cube_face[i], 0, GL_RGBA, res, res, 0, GL_RGBA, GL_FLOAT, NULL);
4222 } 4364 }
4223 } 4365 }
4224 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, 0); 4366 gGL.getTexUnit(cube_map->getStage())->unbind(LLTexUnit::TT_CUBE_MAP);
4225 cube_map->disable(); 4367 gGL.getTexUnit(cube_map->getStage())->disable();
4368 gGL.getTexUnit(0)->activate();
4369 gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
4226 4370
4227 BOOL toggle_ui = gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI); 4371 BOOL toggle_ui = gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI);
4228 if (toggle_ui) 4372 if (toggle_ui)
@@ -4266,7 +4410,7 @@ void LLPipeline::generateReflectionMap(LLCubeMap* cube_map, LLCamera& cube_cam)
4266 gPipeline.calcNearbyLights(cube_cam); 4410 gPipeline.calcNearbyLights(cube_cam);
4267 4411
4268 stop_glerror(); 4412 stop_glerror();
4269 LLViewerImage::unbindTexture(0, GL_TEXTURE_2D); 4413 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
4270 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mCubeFrameBuffer); 4414 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mCubeFrameBuffer);
4271 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, 4415 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
4272 GL_RENDERBUFFER_EXT, mCubeDepth); 4416 GL_RENDERBUFFER_EXT, mCubeDepth);
@@ -4422,7 +4566,8 @@ void LLPipeline::blurReflectionMap(LLCubeMap* cube_in, LLCubeMap* cube_out)
4422 glPushMatrix(); 4566 glPushMatrix();
4423 4567
4424 cube_out->enableTexture(0); 4568 cube_out->enableTexture(0);
4425 cube_out->bind(); 4569 gGL.getTexUnit(cube_out->getStage())->bind(cube_out);
4570 gGL.getTexUnit(0)->activate();
4426 GLint width; 4571 GLint width;
4427 glGetTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL_TEXTURE_WIDTH, &width); 4572 glGetTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL_TEXTURE_WIDTH, &width);
4428 if (width != res) 4573 if (width != res)
@@ -4434,8 +4579,8 @@ void LLPipeline::blurReflectionMap(LLCubeMap* cube_in, LLCubeMap* cube_out)
4434 glTexImage2D(gl_cube_face[i], 0, GL_RGBA, res, res, 0, GL_RGBA, GL_FLOAT, NULL); 4579 glTexImage2D(gl_cube_face[i], 0, GL_RGBA, res, res, 0, GL_RGBA, GL_FLOAT, NULL);
4435 } 4580 }
4436 } 4581 }
4437 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, 0); 4582 gGL.getTexUnit(cube_out->getStage())->unbind(LLTexUnit::TT_CUBE_MAP);
4438 4583 gGL.getTexUnit(0)->activate();
4439 glViewport(0, 0, res, res); 4584 glViewport(0, 0, res, res);
4440 LLGLEnable blend(GL_BLEND); 4585 LLGLEnable blend(GL_BLEND);
4441 4586
@@ -4463,16 +4608,17 @@ void LLPipeline::blurReflectionMap(LLCubeMap* cube_in, LLCubeMap* cube_out)
4463 4608
4464 if (j == 0) 4609 if (j == 0)
4465 { 4610 {
4466 cube_in->bind(); 4611 gGL.getTexUnit(cube_in->getStage())->bind(cube_in);
4467 } 4612 }
4468 else 4613 else
4469 { 4614 {
4470 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, mBlurCubeTexture[j-1]); 4615 gGL.getTexUnit(cube_in->getStage())->bindManual(LLTexUnit::TT_CUBE_MAP, mBlurCubeTexture[j-1]);
4471 } 4616 }
4617 gGL.getTexUnit(0)->activate();
4472 4618
4473 stop_glerror(); 4619 stop_glerror();
4474 4620
4475 LLViewerImage::unbindTexture(0, GL_TEXTURE_2D); 4621 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
4476 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mBlurCubeBuffer[j]); 4622 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mBlurCubeBuffer[j]);
4477 stop_glerror(); 4623 stop_glerror();
4478 4624
@@ -4501,7 +4647,7 @@ void LLPipeline::blurReflectionMap(LLCubeMap* cube_in, LLCubeMap* cube_out)
4501 4647
4502 stop_glerror(); 4648 stop_glerror();
4503 4649
4504 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, 0); 4650 gGL.getTexUnit(cube_in->getStage())->unbind(LLTexUnit::TT_CUBE_MAP);
4505 4651
4506 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 4652 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
4507 gGL.setColorMask(true, false); 4653 gGL.setColorMask(true, false);
@@ -4510,7 +4656,8 @@ void LLPipeline::blurReflectionMap(LLCubeMap* cube_in, LLCubeMap* cube_out)
4510 glMatrixMode(GL_MODELVIEW); 4656 glMatrixMode(GL_MODELVIEW);
4511 glPopMatrix(); 4657 glPopMatrix();
4512 4658
4513 cube_in->disableTexture(); 4659 gGL.getTexUnit(cube_in->getStage())->disable();
4660 gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
4514 gViewerWindow->setupViewport(); 4661 gViewerWindow->setupViewport();
4515 gGL.setSceneBlendType(LLRender::BT_ALPHA); 4662 gGL.setSceneBlendType(LLRender::BT_ALPHA);
4516 4663
@@ -4578,7 +4725,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot)
4578 4725
4579 if (for_snapshot) 4726 if (for_snapshot)
4580 { 4727 {
4581 mGlow[1].bindTexture(); 4728 gGL.getTexUnit(0)->bind(&mGlow[1]);
4582 { 4729 {
4583 //LLGLEnable stencil(GL_STENCIL_TEST); 4730 //LLGLEnable stencil(GL_STENCIL_TEST);
4584 //glStencilFunc(GL_NOTEQUAL, 255, 0xFFFFFFFF); 4731 //glStencilFunc(GL_NOTEQUAL, 255, 0xFFFFFFFF);
@@ -4587,7 +4734,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot)
4587 LLGLEnable blend(GL_BLEND); 4734 LLGLEnable blend(GL_BLEND);
4588 gGL.setSceneBlendType(LLRender::BT_ADD); 4735 gGL.setSceneBlendType(LLRender::BT_ADD);
4589 tc2.setVec(1,1); 4736 tc2.setVec(1,1);
4590 gGL.begin(LLVertexBuffer::TRIANGLE_STRIP); 4737 gGL.begin(LLRender::TRIANGLE_STRIP);
4591 gGL.color4f(1,1,1,1); 4738 gGL.color4f(1,1,1,1);
4592 gGL.texCoord2f(tc1.mV[0], tc1.mV[1]); 4739 gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
4593 gGL.vertex2f(-1,-1); 4740 gGL.vertex2f(-1,-1);
@@ -4637,15 +4784,15 @@ void LLPipeline::renderBloom(BOOL for_snapshot)
4637 LLGLEnable test(GL_ALPHA_TEST); 4784 LLGLEnable test(GL_ALPHA_TEST);
4638 gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT); 4785 gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
4639 gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA); 4786 gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
4640 LLViewerImage::unbindTexture(0, GL_TEXTURE_2D);
4641 4787
4642 glDisable(GL_TEXTURE_2D); 4788 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
4643 glEnable(GL_TEXTURE_RECTANGLE_ARB); 4789 gGL.getTexUnit(0)->disable();
4644 mScreen.bindTexture(); 4790 gGL.getTexUnit(0)->enable(LLTexUnit::TT_RECT_TEXTURE);
4791 gGL.getTexUnit(0)->bind(&mScreen);
4645 4792
4646 gGL.color4f(1,1,1,1); 4793 gGL.color4f(1,1,1,1);
4647 gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); 4794 gPipeline.enableLightsFullbright(LLColor4(1,1,1,1));
4648 gGL.begin(LLVertexBuffer::TRIANGLE_STRIP); 4795 gGL.begin(LLRender::TRIANGLE_STRIP);
4649 gGL.texCoord2f(tc1.mV[0], tc1.mV[1]); 4796 gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
4650 gGL.vertex2f(-1,-1); 4797 gGL.vertex2f(-1,-1);
4651 4798
@@ -4659,8 +4806,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot)
4659 gGL.vertex2f(1,1); 4806 gGL.vertex2f(1,1);
4660 gGL.end(); 4807 gGL.end();
4661 4808
4662 glEnable(GL_TEXTURE_2D); 4809 gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
4663 glDisable(GL_TEXTURE_RECTANGLE_ARB);
4664 4810
4665 mGlow[2].flush(); 4811 mGlow[2].flush();
4666 } 4812 }
@@ -4690,7 +4836,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot)
4690 4836
4691 for (S32 i = 0; i < kernel; i++) 4837 for (S32 i = 0; i < kernel; i++)
4692 { 4838 {
4693 LLViewerImage::unbindTexture(0, GL_TEXTURE_2D); 4839 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
4694 { 4840 {
4695 LLFastTimer ftm(LLFastTimer::FTM_RENDER_BLOOM_FBO); 4841 LLFastTimer ftm(LLFastTimer::FTM_RENDER_BLOOM_FBO);
4696 mGlow[i%2].bindTarget(); 4842 mGlow[i%2].bindTarget();
@@ -4699,11 +4845,11 @@ void LLPipeline::renderBloom(BOOL for_snapshot)
4699 4845
4700 if (i == 0) 4846 if (i == 0)
4701 { 4847 {
4702 mGlow[2].bindTexture(); 4848 gGL.getTexUnit(0)->bind(&mGlow[2]);
4703 } 4849 }
4704 else 4850 else
4705 { 4851 {
4706 mGlow[(i-1)%2].bindTexture(); 4852 gGL.getTexUnit(0)->bind(&mGlow[(i-1)%2]);
4707 } 4853 }
4708 4854
4709 if (i%2 == 0) 4855 if (i%2 == 0)
@@ -4715,7 +4861,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot)
4715 gGlowProgram.uniform2f("glowDelta", 0, delta); 4861 gGlowProgram.uniform2f("glowDelta", 0, delta);
4716 } 4862 }
4717 4863
4718 gGL.begin(LLVertexBuffer::TRIANGLE_STRIP); 4864 gGL.begin(LLRender::TRIANGLE_STRIP);
4719 gGL.texCoord2f(tc1.mV[0], tc1.mV[1]); 4865 gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
4720 gGL.vertex2f(-1,-1); 4866 gGL.vertex2f(-1,-1);
4721 4867
@@ -4780,8 +4926,8 @@ void LLPipeline::renderBloom(BOOL for_snapshot)
4780 LLGLEnable blend(GL_BLEND); 4926 LLGLEnable blend(GL_BLEND);
4781 gGL.blendFunc(GL_ONE, GL_ONE); 4927 gGL.blendFunc(GL_ONE, GL_ONE);
4782 4928
4783 glDisable(GL_TEXTURE_2D); 4929 gGL.getTexUnit(0)->disable();
4784 glEnable(GL_TEXTURE_RECTANGLE_ARB); 4930 gGL.getTexUnit(0)->enable(LLTexUnit::TT_RECT_TEXTURE);
4785 mScreen.bindTexture(); 4931 mScreen.bindTexture();
4786 4932
4787 gGL.begin(LLVertexBuffer::TRIANGLE_STRIP); 4933 gGL.begin(LLVertexBuffer::TRIANGLE_STRIP);
@@ -4801,8 +4947,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot)
4801 4947
4802 gGL.flush(); 4948 gGL.flush();
4803 4949
4804 glEnable(GL_TEXTURE_2D); 4950 gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
4805 glDisable(GL_TEXTURE_RECTANGLE_ARB);
4806 4951
4807 gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 4952 gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
4808 }*/ 4953 }*/
@@ -4847,12 +4992,12 @@ void LLPipeline::renderBloom(BOOL for_snapshot)
4847 4992
4848 //tex unit 0 4993 //tex unit 0
4849 gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_TEX_COLOR); 4994 gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_TEX_COLOR);
4850 4995
4851 mGlow[1].bindTexture(); 4996 gGL.getTexUnit(0)->bind(&mGlow[1]);
4852 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 4997 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
4853 glTexCoordPointer(2, GL_FLOAT, 0, uv0); 4998 glTexCoordPointer(2, GL_FLOAT, 0, uv0);
4854 gGL.getTexUnit(1)->activate(); 4999 gGL.getTexUnit(1)->activate();
4855 glEnable(GL_TEXTURE_RECTANGLE_ARB); 5000 gGL.getTexUnit(1)->enable(LLTexUnit::TT_RECT_TEXTURE);
4856 5001
4857 //tex unit 1 5002 //tex unit 1
4858 gGL.getTexUnit(1)->setTextureColorBlend(LLTexUnit::TBO_ADD, LLTexUnit::TBS_TEX_COLOR, LLTexUnit::TBS_PREV_COLOR); 5003 gGL.getTexUnit(1)->setTextureColorBlend(LLTexUnit::TBO_ADD, LLTexUnit::TBS_TEX_COLOR, LLTexUnit::TBS_PREV_COLOR);
@@ -4863,14 +5008,16 @@ void LLPipeline::renderBloom(BOOL for_snapshot)
4863 5008
4864 glVertexPointer(2, GL_FLOAT, 0, v); 5009 glVertexPointer(2, GL_FLOAT, 0, v);
4865 5010
4866 mScreen.bindTexture(); 5011 gGL.getTexUnit(1)->bind(&mScreen);
5012 gGL.getTexUnit(1)->activate();
4867 5013
4868 LLGLEnable multisample(GL_MULTISAMPLE_ARB); 5014 LLGLEnable multisample(GL_MULTISAMPLE_ARB);
4869 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 5015 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
4870 5016
4871 glDisable(GL_TEXTURE_RECTANGLE_ARB); 5017 gGL.getTexUnit(1)->disable();
4872 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 5018 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
4873 gGL.getTexUnit(1)->setTextureBlendType(LLTexUnit::TB_MULT); 5019 gGL.getTexUnit(1)->setTextureBlendType(LLTexUnit::TB_MULT);
5020
4874 glClientActiveTextureARB(GL_TEXTURE0_ARB); 5021 glClientActiveTextureARB(GL_TEXTURE0_ARB);
4875 gGL.getTexUnit(0)->activate(); 5022 gGL.getTexUnit(0)->activate();
4876 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 5023 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
@@ -4948,7 +5095,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in)
4948 5095
4949 if (!LLViewerCamera::getInstance()->cameraUnderWater()) 5096 if (!LLViewerCamera::getInstance()->cameraUnderWater())
4950 { //generate planar reflection map 5097 { //generate planar reflection map
4951 LLViewerImage::unbindTexture(0, GL_TEXTURE_2D); 5098 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
4952 glClearColor(0,0,0,0); 5099 glClearColor(0,0,0,0);
4953 gGL.setColorMask(true, true); 5100 gGL.setColorMask(true, true);
4954 mWaterRef.bindTarget(); 5101 mWaterRef.bindTarget();
@@ -5053,7 +5200,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in)
5053 } 5200 }
5054 LLViewerCamera::updateFrustumPlanes(camera); 5201 LLViewerCamera::updateFrustumPlanes(camera);
5055 5202
5056 LLViewerImage::unbindTexture(0, GL_TEXTURE_2D); 5203 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
5057 LLColor4& col = LLDrawPoolWater::sWaterFogColor; 5204 LLColor4& col = LLDrawPoolWater::sWaterFogColor;
5058 glClearColor(col.mV[0], col.mV[1], col.mV[2], 0.f); 5205 glClearColor(col.mV[0], col.mV[1], col.mV[2], 0.f);
5059 gGL.setColorMask(true, true); 5206 gGL.setColorMask(true, true);
@@ -5185,11 +5332,11 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar)
5185 5332
5186 LLVector3 left = camera.getLeftAxis(); 5333 LLVector3 left = camera.getLeftAxis();
5187 left *= left; 5334 left *= left;
5188 left.normVec(); 5335 left.normalize();
5189 5336
5190 LLVector3 up = camera.getUpAxis(); 5337 LLVector3 up = camera.getUpAxis();
5191 up *= up; 5338 up *= up;
5192 up.normVec(); 5339 up.normalize();
5193 5340
5194 tdim.mV[0] = fabsf(half_height * left); 5341 tdim.mV[0] = fabsf(half_height * left);
5195 tdim.mV[1] = fabsf(half_height * up); 5342 tdim.mV[1] = fabsf(half_height * up);
@@ -5230,10 +5377,10 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar)
5230 resY != avatar->mImpostor.getHeight()) 5377 resY != avatar->mImpostor.getHeight())
5231 { 5378 {
5232 avatar->mImpostor.allocate(resX,resY,GL_RGBA,TRUE); 5379 avatar->mImpostor.allocate(resX,resY,GL_RGBA,TRUE);
5233 avatar->mImpostor.bindTexture(); 5380 gGL.getTexUnit(0)->bind(&avatar->mImpostor);
5234 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 5381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
5235 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 5382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
5236 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 5383 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
5237 } 5384 }
5238 5385
5239 { 5386 {
@@ -5270,13 +5417,13 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar)
5270 } 5417 }
5271 5418
5272 gGL.setSceneBlendType(LLRender::BT_ADD); 5419 gGL.setSceneBlendType(LLRender::BT_ADD);
5273 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 5420 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
5274 5421
5275 LLGLDepthTest depth(GL_FALSE, GL_FALSE); 5422 LLGLDepthTest depth(GL_FALSE, GL_FALSE);
5276 5423
5277 gGL.color4f(1,1,1,1); 5424 gGL.color4f(1,1,1,1);
5278 gGL.color4ub(64,64,64,255); 5425 gGL.color4ub(64,64,64,255);
5279 gGL.begin(LLVertexBuffer::QUADS); 5426 gGL.begin(LLRender::QUADS);
5280 gGL.vertex3fv((pos+left-up).mV); 5427 gGL.vertex3fv((pos+left-up).mV);
5281 gGL.vertex3fv((pos-left-up).mV); 5428 gGL.vertex3fv((pos-left-up).mV);
5282 gGL.vertex3fv((pos-left+up).mV); 5429 gGL.vertex3fv((pos-left+up).mV);