aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llviewerwindow.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-12-01 17:39:58 -0600
committerJacek Antonelli2008-12-01 17:40:06 -0600
commit7abecb48babe6a6f09bf6692ba55076546cfced9 (patch)
tree8d18a88513fb97adf32c10aae78f4be1984942db /linden/indra/newview/llviewerwindow.cpp
parentSecond Life viewer sources 1.21.6 (diff)
downloadmeta-impy-7abecb48babe6a6f09bf6692ba55076546cfced9.zip
meta-impy-7abecb48babe6a6f09bf6692ba55076546cfced9.tar.gz
meta-impy-7abecb48babe6a6f09bf6692ba55076546cfced9.tar.bz2
meta-impy-7abecb48babe6a6f09bf6692ba55076546cfced9.tar.xz
Second Life viewer sources 1.22.0-RC
Diffstat (limited to 'linden/indra/newview/llviewerwindow.cpp')
-rw-r--r--linden/indra/newview/llviewerwindow.cpp254
1 files changed, 178 insertions, 76 deletions
diff --git a/linden/indra/newview/llviewerwindow.cpp b/linden/indra/newview/llviewerwindow.cpp
index 64c042a..106ad08 100644
--- a/linden/indra/newview/llviewerwindow.cpp
+++ b/linden/indra/newview/llviewerwindow.cpp
@@ -168,6 +168,7 @@
168#include "llviewerobjectlist.h" 168#include "llviewerobjectlist.h"
169#include "llviewerparcelmgr.h" 169#include "llviewerparcelmgr.h"
170#include "llviewerregion.h" 170#include "llviewerregion.h"
171#include "llviewershadermgr.h"
171#include "llviewerstats.h" 172#include "llviewerstats.h"
172#include "llvoavatar.h" 173#include "llvoavatar.h"
173#include "llvovolume.h" 174#include "llvovolume.h"
@@ -182,7 +183,6 @@
182#include "llviewernetwork.h" 183#include "llviewernetwork.h"
183 184
184#if LL_WINDOWS 185#if LL_WINDOWS
185#include "llwindebug.h"
186#include <tchar.h> // For Unicode conversion methods 186#include <tchar.h> // For Unicode conversion methods
187#endif 187#endif
188 188
@@ -218,6 +218,7 @@ LLVector3 gDebugRaycastIntersection;
218LLVector2 gDebugRaycastTexCoord; 218LLVector2 gDebugRaycastTexCoord;
219LLVector3 gDebugRaycastNormal; 219LLVector3 gDebugRaycastNormal;
220LLVector3 gDebugRaycastBinormal; 220LLVector3 gDebugRaycastBinormal;
221S32 gDebugRaycastFaceHit;
221 222
222// HUD display lines in lower right 223// HUD display lines in lower right
223BOOL gDisplayWindInfo = FALSE; 224BOOL gDisplayWindInfo = FALSE;
@@ -1102,6 +1103,7 @@ void LLViewerWindow::handleQuit(LLWindow *window)
1102void LLViewerWindow::handleResize(LLWindow *window, S32 width, S32 height) 1103void LLViewerWindow::handleResize(LLWindow *window, S32 width, S32 height)
1103{ 1104{
1104 reshape(width, height); 1105 reshape(width, height);
1106 mResDirty = true;
1105} 1107}
1106 1108
1107// The top-level window has gained focus (e.g. via ALT-TAB) 1109// The top-level window has gained focus (e.g. via ALT-TAB)
@@ -1258,6 +1260,8 @@ BOOL LLViewerWindow::handleActivate(LLWindow *window, BOOL activated)
1258 1260
1259BOOL LLViewerWindow::handleActivateApp(LLWindow *window, BOOL activating) 1261BOOL LLViewerWindow::handleActivateApp(LLWindow *window, BOOL activating)
1260{ 1262{
1263 //if (!activating) gAgent.changeCameraToDefault();
1264
1261 LLViewerJoystick::getInstance()->setNeedsReset(true); 1265 LLViewerJoystick::getInstance()->setNeedsReset(true);
1262 return FALSE; 1266 return FALSE;
1263} 1267}
@@ -1410,7 +1414,11 @@ LLViewerWindow::LLViewerWindow(
1410 mHideCursorPermanent( FALSE ), 1414 mHideCursorPermanent( FALSE ),
1411 mCursorHidden(FALSE), 1415 mCursorHidden(FALSE),
1412 mIgnoreActivate( FALSE ), 1416 mIgnoreActivate( FALSE ),
1413 mHoverPick() 1417 mHoverPick(),
1418 mResDirty(false),
1419 mStatesDirty(false),
1420 mIsFullscreenChecked(false),
1421 mCurrResolutionIndex(0)
1414{ 1422{
1415 // Default to application directory. 1423 // Default to application directory.
1416 LLViewerWindow::sSnapshotBaseName = "Snapshot"; 1424 LLViewerWindow::sSnapshotBaseName = "Snapshot";
@@ -1426,12 +1434,12 @@ LLViewerWindow::LLViewerWindow(
1426 !gNoRender, 1434 !gNoRender,
1427 ignore_pixel_depth, 1435 ignore_pixel_depth,
1428 gSavedSettings.getU32("RenderFSAASamples")); 1436 gSavedSettings.getU32("RenderFSAASamples"));
1429#if LL_WINDOWS 1437
1430 if (!LLWinDebug::checkExceptionHandler()) 1438 if (!LLAppViewer::instance()->restoreErrorTrap())
1431 { 1439 {
1432 LL_WARNS("Window") << " Someone took over my exception handler (post createWindow)!" << LL_ENDL; 1440 LL_WARNS("Window") << " Someone took over my signal/exception handler (post createWindow)!" << LL_ENDL;
1433 } 1441 }
1434#endif 1442
1435 1443
1436 if (NULL == mWindow) 1444 if (NULL == mWindow)
1437 { 1445 {
@@ -1545,7 +1553,7 @@ void LLViewerWindow::initGLDefaults()
1545 glPixelStorei(GL_PACK_ALIGNMENT,1); 1553 glPixelStorei(GL_PACK_ALIGNMENT,1);
1546 glPixelStorei(GL_UNPACK_ALIGNMENT,1); 1554 glPixelStorei(GL_UNPACK_ALIGNMENT,1);
1547 1555
1548 glEnable(GL_TEXTURE_2D); 1556 gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
1549 1557
1550 // lights for objects 1558 // lights for objects
1551 glShadeModel( GL_SMOOTH ); 1559 glShadeModel( GL_SMOOTH );
@@ -3042,8 +3050,9 @@ BOOL LLViewerWindow::handlePerFrameHover()
3042 3050
3043 if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_RAYCAST)) 3051 if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_RAYCAST))
3044 { 3052 {
3045 gDebugRaycastObject = cursorIntersect(-1, -1, 512.f, NULL, -1, 3053 gDebugRaycastFaceHit = -1;
3046 NULL, 3054 gDebugRaycastObject = cursorIntersect(-1, -1, 512.f, NULL, -1, FALSE,
3055 &gDebugRaycastFaceHit,
3047 &gDebugRaycastIntersection, 3056 &gDebugRaycastIntersection,
3048 &gDebugRaycastTexCoord, 3057 &gDebugRaycastTexCoord,
3049 &gDebugRaycastNormal, 3058 &gDebugRaycastNormal,
@@ -3184,7 +3193,7 @@ void LLViewerWindow::renderSelections( BOOL for_gl_pick, BOOL pick_parcel_walls,
3184 // Render light for editing 3193 // Render light for editing
3185 if (LLSelectMgr::sRenderLightRadius && LLToolMgr::getInstance()->inEdit()) 3194 if (LLSelectMgr::sRenderLightRadius && LLToolMgr::getInstance()->inEdit())
3186 { 3195 {
3187 LLImageGL::unbindTexture(0); 3196 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
3188 LLGLEnable gls_blend(GL_BLEND); 3197 LLGLEnable gls_blend(GL_BLEND);
3189 LLGLEnable gls_cull(GL_CULL_FACE); 3198 LLGLEnable gls_cull(GL_CULL_FACE);
3190 LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); 3199 LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
@@ -3398,7 +3407,7 @@ void LLViewerWindow::schedulePick(LLPickInfo& pick_info)
3398 llassert_always(pick_info.mScreenRegion.notNull()); 3407 llassert_always(pick_info.mScreenRegion.notNull());
3399 mPicks.push_back(pick_info); 3408 mPicks.push_back(pick_info);
3400 3409
3401 S32 scaled_x = llround((F32)pick_info.mMousePt.mX * mDisplayScale.mV[VX]); 3410 /*S32 scaled_x = llround((F32)pick_info.mMousePt.mX * mDisplayScale.mV[VX]);
3402 S32 scaled_y = llround((F32)pick_info.mMousePt.mY * mDisplayScale.mV[VY]); 3411 S32 scaled_y = llround((F32)pick_info.mMousePt.mY * mDisplayScale.mV[VY]);
3403 3412
3404 // Default to not hitting anything 3413 // Default to not hitting anything
@@ -3467,7 +3476,7 @@ void LLViewerWindow::schedulePick(LLPickInfo& pick_info)
3467 3476
3468 setup3DRender(); 3477 setup3DRender();
3469 setup2DRender(); 3478 setup2DRender();
3470 setupViewport(); 3479 setupViewport();*/
3471 3480
3472 // delay further event processing until we receive results of pick 3481 // delay further event processing until we receive results of pick
3473 mWindow->delayInputProcessing(); 3482 mWindow->delayInputProcessing();
@@ -3529,6 +3538,7 @@ LLPickInfo LLViewerWindow::pickImmediate(S32 x, S32 y_from_bot, BOOL pick_trans
3529LLViewerObject* LLViewerWindow::cursorIntersect(S32 mouse_x, S32 mouse_y, F32 depth, 3538LLViewerObject* LLViewerWindow::cursorIntersect(S32 mouse_x, S32 mouse_y, F32 depth,
3530 LLViewerObject *this_object, 3539 LLViewerObject *this_object,
3531 S32 this_face, 3540 S32 this_face,
3541 BOOL pick_transparent,
3532 S32* face_hit, 3542 S32* face_hit,
3533 LLVector3 *intersection, 3543 LLVector3 *intersection,
3534 LLVector2 *uv, 3544 LLVector2 *uv,
@@ -3562,7 +3572,7 @@ LLViewerObject* LLViewerWindow::cursorIntersect(S32 mouse_x, S32 mouse_y, F32 de
3562 { 3572 {
3563 if (this_object->isHUDAttachment()) // is a HUD object? 3573 if (this_object->isHUDAttachment()) // is a HUD object?
3564 { 3574 {
3565 if (this_object->lineSegmentIntersect(mouse_hud_start, mouse_hud_end, this_face, 3575 if (this_object->lineSegmentIntersect(mouse_hud_start, mouse_hud_end, this_face, pick_transparent,
3566 face_hit, intersection, uv, normal, binormal)) 3576 face_hit, intersection, uv, normal, binormal))
3567 { 3577 {
3568 found = this_object; 3578 found = this_object;
@@ -3571,7 +3581,7 @@ LLViewerObject* LLViewerWindow::cursorIntersect(S32 mouse_x, S32 mouse_y, F32 de
3571 3581
3572 else // is a world object 3582 else // is a world object
3573 { 3583 {
3574 if (this_object->lineSegmentIntersect(mouse_world_start, mouse_world_end, this_face, 3584 if (this_object->lineSegmentIntersect(mouse_world_start, mouse_world_end, this_face, pick_transparent,
3575 face_hit, intersection, uv, normal, binormal)) 3585 face_hit, intersection, uv, normal, binormal))
3576 { 3586 {
3577 found = this_object; 3587 found = this_object;
@@ -3581,13 +3591,13 @@ LLViewerObject* LLViewerWindow::cursorIntersect(S32 mouse_x, S32 mouse_y, F32 de
3581 3591
3582 else // check ALL objects 3592 else // check ALL objects
3583 { 3593 {
3584 found = gPipeline.lineSegmentIntersectInHUD(mouse_hud_start, mouse_hud_end, 3594 found = gPipeline.lineSegmentIntersectInHUD(mouse_hud_start, mouse_hud_end, pick_transparent,
3585 face_hit, intersection, uv, normal, binormal); 3595 face_hit, intersection, uv, normal, binormal);
3586 3596
3587 if (!found) // if not found in HUD, look in world: 3597 if (!found) // if not found in HUD, look in world:
3588 3598
3589 { 3599 {
3590 found = gPipeline.lineSegmentIntersectInWorld(mouse_world_start, mouse_world_end, 3600 found = gPipeline.lineSegmentIntersectInWorld(mouse_world_start, mouse_world_end, pick_transparent,
3591 face_hit, intersection, uv, normal, binormal); 3601 face_hit, intersection, uv, normal, binormal);
3592 } 3602 }
3593 3603
@@ -3811,13 +3821,8 @@ BOOL LLViewerWindow::saveImageNumbered(LLImageFormatted *image)
3811 return FALSE; 3821 return FALSE;
3812 } 3822 }
3813 3823
3814 std::string extension("." + image->getExtension());
3815 if (extension.empty())
3816 {
3817 extension = (gSavedSettings.getBOOL("CompressSnapshotsToDisk")) ? ".j2c" : ".bmp";
3818 }
3819
3820 LLFilePicker::ESaveFilter pick_type; 3824 LLFilePicker::ESaveFilter pick_type;
3825 std::string extension("." + image->getExtension());
3821 if (extension == ".j2c") 3826 if (extension == ".j2c")
3822 pick_type = LLFilePicker::FFSAVE_J2C; 3827 pick_type = LLFilePicker::FFSAVE_J2C;
3823 else if (extension == ".bmp") 3828 else if (extension == ".bmp")
@@ -3835,7 +3840,8 @@ BOOL LLViewerWindow::saveImageNumbered(LLImageFormatted *image)
3835 if ( ! isSnapshotLocSet()) 3840 if ( ! isSnapshotLocSet())
3836 { 3841 {
3837 std::string proposed_name( sSnapshotBaseName ); 3842 std::string proposed_name( sSnapshotBaseName );
3838 proposed_name.append( extension ); 3843
3844 // getSaveFile will append an appropriate extension to the proposed name, based on the ESaveFilter constant passed in.
3839 3845
3840 // pick a directory in which to save 3846 // pick a directory in which to save
3841 LLFilePicker& picker = LLFilePicker::instance(); 3847 LLFilePicker& picker = LLFilePicker::instance();
@@ -4152,7 +4158,7 @@ BOOL LLViewerWindow::rawSnapshot(LLImageRaw *raw, S32 image_width, S32 image_hei
4152 4158
4153 snapshot_width = image_width; 4159 snapshot_width = image_width;
4154 snapshot_height = image_height; 4160 snapshot_height = image_height;
4155 target.allocate(snapshot_width, snapshot_height, GL_RGBA, TRUE, GL_TEXTURE_RECTANGLE_ARB, TRUE); 4161 target.allocate(snapshot_width, snapshot_height, GL_RGBA, TRUE, LLTexUnit::TT_RECT_TEXTURE, TRUE);
4156 window_width = snapshot_width; 4162 window_width = snapshot_width;
4157 window_height = snapshot_height; 4163 window_height = snapshot_height;
4158 scale_factor = 1.f; 4164 scale_factor = 1.f;
@@ -4380,7 +4386,7 @@ void LLViewerWindow::drawMouselookInstructions()
4380 llround(font->getLineHeight() + 2 * INSTRUCTIONS_PAD)); 4386 llround(font->getLineHeight() + 2 * INSTRUCTIONS_PAD));
4381 4387
4382 { 4388 {
4383 LLGLSNoTexture gls_no_texture; 4389 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
4384 gGL.color4f( 0.9f, 0.9f, 0.9f, 1.0f ); 4390 gGL.color4f( 0.9f, 0.9f, 0.9f, 1.0f );
4385 gl_rect_2d( instructions_rect ); 4391 gl_rect_2d( instructions_rect );
4386 } 4392 }
@@ -4586,12 +4592,10 @@ void LLViewerWindow::restoreGL(const std::string& progress_message)
4586 setProgressString(progress_message); 4592 setProgressString(progress_message);
4587 } 4593 }
4588 llinfos << "...Restoring GL done" << llendl; 4594 llinfos << "...Restoring GL done" << llendl;
4589#if LL_WINDOWS 4595 if(!LLAppViewer::instance()->restoreErrorTrap())
4590 if(!LLWinDebug::checkExceptionHandler())
4591 { 4596 {
4592 llwarns << " Someone took over my exception handler (post restoreGL)!" << llendl; 4597 llwarns << " Someone took over my signal/exception handler (post restoreGL)!" << llendl;
4593 } 4598 }
4594#endif
4595 4599
4596 } 4600 }
4597} 4601}
@@ -4647,9 +4651,97 @@ void LLViewerWindow::getTargetWindow(BOOL& fullscreen, S32& width, S32& height)
4647 } 4651 }
4648} 4652}
4649 4653
4654bool LLViewerWindow::updateResolution()
4655{
4656 if (gSavedSettings.getBOOL("FullScreenAutoDetectAspectRatio"))
4657 {
4658 getWindow()->setNativeAspectRatio(0.f);
4659 }
4660 else
4661 {
4662 getWindow()->setNativeAspectRatio(gSavedSettings.getF32("FullScreenAspectRatio"));
4663 }
4664
4665 reshape(getWindowDisplayWidth(), getWindowDisplayHeight());
4666
4667 // Screen resolution
4668 S32 num_resolutions;
4669 LLWindow::LLWindowResolution* supported_resolutions = getWindow()->getSupportedResolutions(num_resolutions);
4670
4671 // check if resolution has changed
4672 BOOL targetFullscreen;
4673 S32 targetWidth;
4674 S32 targetHeight;
4675
4676 getTargetWindow(targetFullscreen, targetWidth, targetHeight);
4677
4678 if ((mIsFullscreenChecked != (bool) targetFullscreen) ||
4679 (mIsFullscreenChecked &&
4680 (supported_resolutions[mCurrResolutionIndex].mWidth != targetWidth ||
4681 supported_resolutions[mCurrResolutionIndex].mHeight != targetHeight)
4682 ))
4683 {
4684 // change fullscreen resolution or switch in/out of windowed mode
4685 BOOL result;
4686
4687 BOOL logged_in = (LLStartUp::getStartupState() >= STATE_STARTED);
4688 if (mIsFullscreenChecked)
4689 {
4690 result = changeDisplaySettings(TRUE,
4691 LLCoordScreen( supported_resolutions[mCurrResolutionIndex].mWidth,
4692 supported_resolutions[mCurrResolutionIndex].mHeight),
4693 gSavedSettings.getBOOL("DisableVerticalSync"),
4694 logged_in);
4695 }
4696 else
4697 {
4698 result = changeDisplaySettings(FALSE,
4699 LLCoordScreen(gSavedSettings.getS32("WindowWidth"), gSavedSettings.getS32("WindowHeight")),
4700 TRUE,
4701 logged_in);
4702 }
4703 if (!result)
4704 {
4705
4706 // GL is non-existent at this point, so we can't continue.
4707 llerrs << "LLPanelDisplay::apply() failed" << llendl;
4708 }
4709 }
4710
4711 // force aspect ratio
4712 if (mIsFullscreenChecked)
4713 {
4714 LLViewerCamera::getInstance()->setAspect( getDisplayAspectRatio() );
4715 }
4716 return true;
4717}
4718
4719void LLViewerWindow::requestResolutionUpdate(bool fullscreen_checked, U32 resolution_index)
4720{
4721 mResDirty = true;
4722 mIsFullscreenChecked = fullscreen_checked;
4723 mCurrResolutionIndex = resolution_index;
4724}
4725
4650 4726
4651BOOL LLViewerWindow::checkSettings() 4727BOOL LLViewerWindow::checkSettings()
4652{ 4728{
4729 if (mStatesDirty)
4730 {
4731 gGL.refreshState();
4732 LLViewerShaderMgr::instance()->setShaders();
4733 mStatesDirty = false;
4734 }
4735
4736 // We want to update the resolution AFTER the states getting refreshed not before.
4737 if (mResDirty)
4738 {
4739 updateResolution();
4740 mResDirty = false;
4741 // This will force a state update the next frame.
4742 mStatesDirty = true;
4743 }
4744
4653 BOOL is_fullscreen = mWindow->getFullscreen(); 4745 BOOL is_fullscreen = mWindow->getFullscreen();
4654 if (is_fullscreen && !mWantFullscreen) 4746 if (is_fullscreen && !mWantFullscreen)
4655 { 4747 {
@@ -4658,6 +4750,7 @@ BOOL LLViewerWindow::checkSettings()
4658 gSavedSettings.getS32("WindowHeight")), 4750 gSavedSettings.getS32("WindowHeight")),
4659 TRUE, 4751 TRUE,
4660 mShowFullscreenProgress); 4752 mShowFullscreenProgress);
4753 mStatesDirty = true;
4661 return TRUE; 4754 return TRUE;
4662 } 4755 }
4663 else if (!is_fullscreen && mWantFullscreen) 4756 else if (!is_fullscreen && mWantFullscreen)
@@ -4677,6 +4770,7 @@ BOOL LLViewerWindow::checkSettings()
4677 4770
4678 LLGLState::checkStates(); 4771 LLGLState::checkStates();
4679 LLGLState::checkTextureChannels(); 4772 LLGLState::checkTextureChannels();
4773 mStatesDirty = true;
4680 return TRUE; 4774 return TRUE;
4681 } 4775 }
4682 return FALSE; 4776 return FALSE;
@@ -5103,25 +5197,34 @@ LLPickInfo::~LLPickInfo()
5103 5197
5104void LLPickInfo::fetchResults() 5198void LLPickInfo::fetchResults()
5105{ 5199{
5200
5201 S32 face_hit = -1;
5202 LLVector3 intersection, normal, binormal;
5203 LLVector2 uv;
5204
5205 LLViewerObject* hit_object = gViewerWindow->cursorIntersect(-1, -1, 512.f,
5206 NULL, -1, mPickTransparent, &face_hit,
5207 &intersection, &uv, &normal, &binormal);
5208
5106 // read back colors and depth values from buffer 5209 // read back colors and depth values from buffer
5107 glReadPixels(mScreenRegion.mLeft, mScreenRegion.mBottom, mScreenRegion.getWidth(), mScreenRegion.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, mPickBuffer); 5210 //glReadPixels(mScreenRegion.mLeft, mScreenRegion.mBottom, mScreenRegion.getWidth(), mScreenRegion.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, mPickBuffer);
5108 glReadPixels(mScreenRegion.mLeft, mScreenRegion.mBottom, mScreenRegion.getWidth(), mScreenRegion.getHeight(), GL_DEPTH_COMPONENT, GL_FLOAT, mPickDepthBuffer ); 5211 //glReadPixels(mScreenRegion.mLeft, mScreenRegion.mBottom, mScreenRegion.getWidth(), mScreenRegion.getHeight(), GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, mPickDepthBuffer );
5109 5212
5110 // find pick region that is fully onscreen 5213 // find pick region that is fully onscreen
5111 LLCoordGL scaled_pick_point;; 5214 LLCoordGL scaled_pick_point;;
5112 scaled_pick_point.mX = llclamp(llround((F32)mMousePt.mX * gViewerWindow->getDisplayScale().mV[VX]), PICK_HALF_WIDTH, gViewerWindow->getWindowDisplayWidth() - PICK_HALF_WIDTH); 5215 scaled_pick_point.mX = llclamp(llround((F32)mMousePt.mX * gViewerWindow->getDisplayScale().mV[VX]), PICK_HALF_WIDTH, gViewerWindow->getWindowDisplayWidth() - PICK_HALF_WIDTH);
5113 scaled_pick_point.mY = llclamp(llround((F32)mMousePt.mY * gViewerWindow->getDisplayScale().mV[VY]), PICK_HALF_WIDTH, gViewerWindow->getWindowDisplayHeight() - PICK_HALF_WIDTH); 5216 scaled_pick_point.mY = llclamp(llround((F32)mMousePt.mY * gViewerWindow->getDisplayScale().mV[VY]), PICK_HALF_WIDTH, gViewerWindow->getWindowDisplayHeight() - PICK_HALF_WIDTH);
5114 S32 pixel_index = PICK_HALF_WIDTH * PICK_DIAMETER + PICK_HALF_WIDTH; 5217 //S32 pixel_index = PICK_HALF_WIDTH * PICK_DIAMETER + PICK_HALF_WIDTH;
5115 S32 pick_id = (U32)mPickBuffer[(pixel_index * 4) + 0] << 16 | (U32)mPickBuffer[(pixel_index * 4) + 1] << 8 | (U32)mPickBuffer[(pixel_index * 4) + 2]; 5218 //S32 pick_id = (U32)mPickBuffer[(pixel_index * 4) + 0] << 16 | (U32)mPickBuffer[(pixel_index * 4) + 1] << 8 | (U32)mPickBuffer[(pixel_index * 4) + 2];
5116 F32 depth = mPickDepthBuffer[pixel_index]; 5219 //F32 depth = mPickDepthBuffer[pixel_index];
5117 5220
5118 S32 x_offset = mMousePt.mX - llround((F32)scaled_pick_point.mX / gViewerWindow->getDisplayScale().mV[VX]); 5221 //S32 x_offset = mMousePt.mX - llround((F32)scaled_pick_point.mX / gViewerWindow->getDisplayScale().mV[VX]);
5119 S32 y_offset = mMousePt.mY - llround((F32)scaled_pick_point.mY / gViewerWindow->getDisplayScale().mV[VY]); 5222 //S32 y_offset = mMousePt.mY - llround((F32)scaled_pick_point.mY / gViewerWindow->getDisplayScale().mV[VY]);
5120 5223
5121 mPickPt = mMousePt; 5224 mPickPt = mMousePt;
5122 5225
5123 // we hit nothing, scan surrounding pixels for something useful 5226 // we hit nothing, scan surrounding pixels for something useful
5124 if (!pick_id) 5227 /*if (!pick_id)
5125 { 5228 {
5126 S32 closest_distance = 10000; 5229 S32 closest_distance = 10000;
5127 //S32 closest_pick_name = 0; 5230 //S32 closest_pick_name = 0;
@@ -5142,25 +5245,21 @@ void LLPickInfo::fetchResults()
5142 } 5245 }
5143 } 5246 }
5144 } 5247 }
5145 } 5248 }*/
5146 5249
5147 U32 te_offset = ((U32)pick_id >> 20);
5148 pick_id &= 0x000fffff;
5149 5250
5150 //unproject relative clicked coordinate from window coordinate using GL 5251 U32 te_offset = face_hit > -1 ? face_hit : 0;
5151 GLint viewport[4]; 5252 //pick_id &= 0x000fffff;
5152 GLdouble modelview[16];
5153 GLdouble projection[16];
5154 GLfloat winX, winY;
5155 GLdouble posX, posY, posZ;
5156 5253
5157 LLViewerObject* objectp = gObjectList.getSelectedObject(pick_id); 5254 //unproject relative clicked coordinate from window coordinate using GL
5255
5256 LLViewerObject* objectp = hit_object;
5158 5257
5159 if (pick_id == (S32)GL_NAME_PARCEL_WALL) 5258 //if (pick_id == (S32)GL_NAME_PARCEL_WALL)
5160 { 5259 //{
5161 mPickType = PICK_PARCEL_WALL; 5260 // mPickType = PICK_PARCEL_WALL;
5162 } 5261 //}
5163 else if (objectp) 5262 if (objectp)
5164 { 5263 {
5165 if( objectp->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH ) 5264 if( objectp->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH )
5166 { 5265 {
@@ -5186,11 +5285,11 @@ void LLPickInfo::fetchResults()
5186 { 5285 {
5187 mPickType = PICK_OBJECT; 5286 mPickType = PICK_OBJECT;
5188 } 5287 }
5189 mObjectOffset = gAgent.calcFocusOffset(objectp, mPickPt.mX, mPickPt.mY); 5288 mObjectOffset = gAgent.calcFocusOffset(objectp, intersection, mPickPt.mX, mPickPt.mY);
5190 mObjectID = objectp->mID; 5289 mObjectID = objectp->mID;
5191 mObjectFace = (te_offset == NO_FACE) ? -1 : (S32)te_offset; 5290 mObjectFace = (te_offset == NO_FACE) ? -1 : (S32)te_offset;
5192 5291
5193 glh::matrix4f newModel((F32*)LLViewerCamera::getInstance()->getModelview().mMatrix); 5292 /*glh::matrix4f newModel((F32*)LLViewerCamera::getInstance()->getModelview().mMatrix);
5194 5293
5195 for(U32 i = 0; i < 16; ++i) 5294 for(U32 i = 0; i < 16; ++i)
5196 { 5295 {
@@ -5202,9 +5301,9 @@ void LLPickInfo::fetchResults()
5202 winX = ((F32)mPickPt.mX) * gViewerWindow->getDisplayScale().mV[VX]; 5301 winX = ((F32)mPickPt.mX) * gViewerWindow->getDisplayScale().mV[VX];
5203 winY = ((F32)mPickPt.mY) * gViewerWindow->getDisplayScale().mV[VY]; 5302 winY = ((F32)mPickPt.mY) * gViewerWindow->getDisplayScale().mV[VY];
5204 5303
5205 gluUnProject( winX, winY, depth, modelview, projection, viewport, &posX, &posY, &posZ); 5304 gluUnProject( winX, winY, depth, modelview, projection, viewport, &posX, &posY, &posZ);*/
5206 5305
5207 mPosGlobal = gAgent.getPosGlobalFromAgent(LLVector3(posX, posY, posZ)); 5306 mPosGlobal = gAgent.getPosGlobalFromAgent(intersection);
5208 5307
5209 if (mWantSurfaceInfo) 5308 if (mWantSurfaceInfo)
5210 { 5309 {
@@ -5212,16 +5311,16 @@ void LLPickInfo::fetchResults()
5212 } 5311 }
5213 } 5312 }
5214 } 5313 }
5215 else 5314 //else
5216 { 5315 //{
5217 // was this name referring to a hud icon? 5316 // was this name referring to a hud icon?
5218 mHUDIcon = LLHUDIcon::handlePick(pick_id); 5317 // mHUDIcon = LLHUDIcon::handlePick(pick_id);
5219 if (mHUDIcon) 5318 // if (mHUDIcon)
5220 { 5319 // {
5221 mPickType = PICK_ICON; 5320 // mPickType = PICK_ICON;
5222 mPosGlobal = mHUDIcon->getPositionGlobal(); 5321 // mPosGlobal = mHUDIcon->getPositionGlobal();
5223 } 5322 // }
5224 } 5323 //}
5225 5324
5226 if (mPickCallback) 5325 if (mPickCallback)
5227 { 5326 {
@@ -5236,16 +5335,19 @@ LLPointer<LLViewerObject> LLPickInfo::getObject() const
5236 5335
5237void LLPickInfo::updateXYCoords() 5336void LLPickInfo::updateXYCoords()
5238{ 5337{
5239 const LLTextureEntry* tep = getObject()->getTE(mObjectFace); 5338 if (mObjectFace > -1)
5240 LLPointer<LLViewerImage> imagep = gImageList.getImage(tep->getID());
5241 if(mUVCoords.mV[VX] >= 0.f && mUVCoords.mV[VY] >= 0.f && imagep.notNull())
5242 { 5339 {
5243 LLCoordGL coords; 5340 const LLTextureEntry* tep = getObject()->getTE(mObjectFace);
5244 5341 LLPointer<LLViewerImage> imagep = gImageList.getImage(tep->getID());
5245 coords.mX = llround(mUVCoords.mV[VX] * (F32)imagep->getWidth()); 5342 if(mUVCoords.mV[VX] >= 0.f && mUVCoords.mV[VY] >= 0.f && imagep.notNull())
5246 coords.mY = llround(mUVCoords.mV[VY] * (F32)imagep->getHeight()); 5343 {
5344 LLCoordGL coords;
5345
5346 coords.mX = llround(mUVCoords.mV[VX] * (F32)imagep->getWidth());
5347 coords.mY = llround(mUVCoords.mV[VY] * (F32)imagep->getHeight());
5247 5348
5248 gViewerWindow->getWindow()->convertCoords(coords, &mXYCoords); 5349 gViewerWindow->getWindow()->convertCoords(coords, &mXYCoords);
5350 }
5249 } 5351 }
5250} 5352}
5251 5353
@@ -5256,7 +5358,7 @@ void LLPickInfo::drawPickBuffer() const
5256 gGL.pushMatrix(); 5358 gGL.pushMatrix();
5257 LLGLDisable no_blend(GL_BLEND); 5359 LLGLDisable no_blend(GL_BLEND);
5258 LLGLDisable no_alpha_test(GL_ALPHA_TEST); 5360 LLGLDisable no_alpha_test(GL_ALPHA_TEST);
5259 LLGLSNoTexture no_texture; 5361 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
5260 glPixelZoom(10.f, 10.f); 5362 glPixelZoom(10.f, 10.f);
5261 LLVector2 display_scale = gViewerWindow->getDisplayScale(); 5363 LLVector2 display_scale = gViewerWindow->getDisplayScale();
5262 glRasterPos2f(((F32)mMousePt.mX * display_scale.mV[VX] + 10.f), 5364 glRasterPos2f(((F32)mMousePt.mX * display_scale.mV[VX] + 10.f),
@@ -5308,7 +5410,7 @@ void LLPickInfo::getSurfaceInfo()
5308 if (objectp) 5410 if (objectp)
5309 { 5411 {
5310 if (gViewerWindow->cursorIntersect(llround((F32)mMousePt.mX), llround((F32)mMousePt.mY), 1024.f, 5412 if (gViewerWindow->cursorIntersect(llround((F32)mMousePt.mX), llround((F32)mMousePt.mY), 1024.f,
5311 objectp, -1, 5413 objectp, -1, mPickTransparent,
5312 &mObjectFace, 5414 &mObjectFace,
5313 &mIntersection, 5415 &mIntersection,
5314 &mSTCoords, 5416 &mSTCoords,
@@ -5317,7 +5419,7 @@ void LLPickInfo::getSurfaceInfo()
5317 { 5419 {
5318 // if we succeeded with the intersect above, compute the texture coordinates: 5420 // if we succeeded with the intersect above, compute the texture coordinates:
5319 5421
5320 if (objectp->mDrawable.notNull()) 5422 if (objectp->mDrawable.notNull() && mObjectFace > -1)
5321 { 5423 {
5322 LLFace* facep = objectp->mDrawable->getFace(mObjectFace); 5424 LLFace* facep = objectp->mDrawable->getFace(mObjectFace);
5323 5425