From 7abecb48babe6a6f09bf6692ba55076546cfced9 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Mon, 1 Dec 2008 17:39:58 -0600 Subject: Second Life viewer sources 1.22.0-RC --- linden/indra/newview/llviewerwindow.cpp | 254 ++++++++++++++++++++++---------- 1 file changed, 178 insertions(+), 76 deletions(-) (limited to 'linden/indra/newview/llviewerwindow.cpp') 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 @@ #include "llviewerobjectlist.h" #include "llviewerparcelmgr.h" #include "llviewerregion.h" +#include "llviewershadermgr.h" #include "llviewerstats.h" #include "llvoavatar.h" #include "llvovolume.h" @@ -182,7 +183,6 @@ #include "llviewernetwork.h" #if LL_WINDOWS -#include "llwindebug.h" #include <tchar.h> // For Unicode conversion methods #endif @@ -218,6 +218,7 @@ LLVector3 gDebugRaycastIntersection; LLVector2 gDebugRaycastTexCoord; LLVector3 gDebugRaycastNormal; LLVector3 gDebugRaycastBinormal; +S32 gDebugRaycastFaceHit; // HUD display lines in lower right BOOL gDisplayWindInfo = FALSE; @@ -1102,6 +1103,7 @@ void LLViewerWindow::handleQuit(LLWindow *window) void LLViewerWindow::handleResize(LLWindow *window, S32 width, S32 height) { reshape(width, height); + mResDirty = true; } // The top-level window has gained focus (e.g. via ALT-TAB) @@ -1258,6 +1260,8 @@ BOOL LLViewerWindow::handleActivate(LLWindow *window, BOOL activated) BOOL LLViewerWindow::handleActivateApp(LLWindow *window, BOOL activating) { + //if (!activating) gAgent.changeCameraToDefault(); + LLViewerJoystick::getInstance()->setNeedsReset(true); return FALSE; } @@ -1410,7 +1414,11 @@ LLViewerWindow::LLViewerWindow( mHideCursorPermanent( FALSE ), mCursorHidden(FALSE), mIgnoreActivate( FALSE ), - mHoverPick() + mHoverPick(), + mResDirty(false), + mStatesDirty(false), + mIsFullscreenChecked(false), + mCurrResolutionIndex(0) { // Default to application directory. LLViewerWindow::sSnapshotBaseName = "Snapshot"; @@ -1426,12 +1434,12 @@ LLViewerWindow::LLViewerWindow( !gNoRender, ignore_pixel_depth, gSavedSettings.getU32("RenderFSAASamples")); -#if LL_WINDOWS - if (!LLWinDebug::checkExceptionHandler()) + + if (!LLAppViewer::instance()->restoreErrorTrap()) { - LL_WARNS("Window") << " Someone took over my exception handler (post createWindow)!" << LL_ENDL; + LL_WARNS("Window") << " Someone took over my signal/exception handler (post createWindow)!" << LL_ENDL; } -#endif + if (NULL == mWindow) { @@ -1545,7 +1553,7 @@ void LLViewerWindow::initGLDefaults() glPixelStorei(GL_PACK_ALIGNMENT,1); glPixelStorei(GL_UNPACK_ALIGNMENT,1); - glEnable(GL_TEXTURE_2D); + gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE); // lights for objects glShadeModel( GL_SMOOTH ); @@ -3042,8 +3050,9 @@ BOOL LLViewerWindow::handlePerFrameHover() if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_RAYCAST)) { - gDebugRaycastObject = cursorIntersect(-1, -1, 512.f, NULL, -1, - NULL, + gDebugRaycastFaceHit = -1; + gDebugRaycastObject = cursorIntersect(-1, -1, 512.f, NULL, -1, FALSE, + &gDebugRaycastFaceHit, &gDebugRaycastIntersection, &gDebugRaycastTexCoord, &gDebugRaycastNormal, @@ -3184,7 +3193,7 @@ void LLViewerWindow::renderSelections( BOOL for_gl_pick, BOOL pick_parcel_walls, // Render light for editing if (LLSelectMgr::sRenderLightRadius && LLToolMgr::getInstance()->inEdit()) { - LLImageGL::unbindTexture(0); + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); LLGLEnable gls_blend(GL_BLEND); LLGLEnable gls_cull(GL_CULL_FACE); LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); @@ -3398,7 +3407,7 @@ void LLViewerWindow::schedulePick(LLPickInfo& pick_info) llassert_always(pick_info.mScreenRegion.notNull()); mPicks.push_back(pick_info); - S32 scaled_x = llround((F32)pick_info.mMousePt.mX * mDisplayScale.mV[VX]); + /*S32 scaled_x = llround((F32)pick_info.mMousePt.mX * mDisplayScale.mV[VX]); S32 scaled_y = llround((F32)pick_info.mMousePt.mY * mDisplayScale.mV[VY]); // Default to not hitting anything @@ -3467,7 +3476,7 @@ void LLViewerWindow::schedulePick(LLPickInfo& pick_info) setup3DRender(); setup2DRender(); - setupViewport(); + setupViewport();*/ // delay further event processing until we receive results of pick mWindow->delayInputProcessing(); @@ -3529,6 +3538,7 @@ LLPickInfo LLViewerWindow::pickImmediate(S32 x, S32 y_from_bot, BOOL pick_trans LLViewerObject* LLViewerWindow::cursorIntersect(S32 mouse_x, S32 mouse_y, F32 depth, LLViewerObject *this_object, S32 this_face, + BOOL pick_transparent, S32* face_hit, LLVector3 *intersection, LLVector2 *uv, @@ -3562,7 +3572,7 @@ LLViewerObject* LLViewerWindow::cursorIntersect(S32 mouse_x, S32 mouse_y, F32 de { if (this_object->isHUDAttachment()) // is a HUD object? { - if (this_object->lineSegmentIntersect(mouse_hud_start, mouse_hud_end, this_face, + if (this_object->lineSegmentIntersect(mouse_hud_start, mouse_hud_end, this_face, pick_transparent, face_hit, intersection, uv, normal, binormal)) { found = this_object; @@ -3571,7 +3581,7 @@ LLViewerObject* LLViewerWindow::cursorIntersect(S32 mouse_x, S32 mouse_y, F32 de else // is a world object { - if (this_object->lineSegmentIntersect(mouse_world_start, mouse_world_end, this_face, + if (this_object->lineSegmentIntersect(mouse_world_start, mouse_world_end, this_face, pick_transparent, face_hit, intersection, uv, normal, binormal)) { found = this_object; @@ -3581,13 +3591,13 @@ LLViewerObject* LLViewerWindow::cursorIntersect(S32 mouse_x, S32 mouse_y, F32 de else // check ALL objects { - found = gPipeline.lineSegmentIntersectInHUD(mouse_hud_start, mouse_hud_end, + found = gPipeline.lineSegmentIntersectInHUD(mouse_hud_start, mouse_hud_end, pick_transparent, face_hit, intersection, uv, normal, binormal); if (!found) // if not found in HUD, look in world: { - found = gPipeline.lineSegmentIntersectInWorld(mouse_world_start, mouse_world_end, + found = gPipeline.lineSegmentIntersectInWorld(mouse_world_start, mouse_world_end, pick_transparent, face_hit, intersection, uv, normal, binormal); } @@ -3811,13 +3821,8 @@ BOOL LLViewerWindow::saveImageNumbered(LLImageFormatted *image) return FALSE; } - std::string extension("." + image->getExtension()); - if (extension.empty()) - { - extension = (gSavedSettings.getBOOL("CompressSnapshotsToDisk")) ? ".j2c" : ".bmp"; - } - LLFilePicker::ESaveFilter pick_type; + std::string extension("." + image->getExtension()); if (extension == ".j2c") pick_type = LLFilePicker::FFSAVE_J2C; else if (extension == ".bmp") @@ -3835,7 +3840,8 @@ BOOL LLViewerWindow::saveImageNumbered(LLImageFormatted *image) if ( ! isSnapshotLocSet()) { std::string proposed_name( sSnapshotBaseName ); - proposed_name.append( extension ); + + // getSaveFile will append an appropriate extension to the proposed name, based on the ESaveFilter constant passed in. // pick a directory in which to save LLFilePicker& picker = LLFilePicker::instance(); @@ -4152,7 +4158,7 @@ BOOL LLViewerWindow::rawSnapshot(LLImageRaw *raw, S32 image_width, S32 image_hei snapshot_width = image_width; snapshot_height = image_height; - target.allocate(snapshot_width, snapshot_height, GL_RGBA, TRUE, GL_TEXTURE_RECTANGLE_ARB, TRUE); + target.allocate(snapshot_width, snapshot_height, GL_RGBA, TRUE, LLTexUnit::TT_RECT_TEXTURE, TRUE); window_width = snapshot_width; window_height = snapshot_height; scale_factor = 1.f; @@ -4380,7 +4386,7 @@ void LLViewerWindow::drawMouselookInstructions() llround(font->getLineHeight() + 2 * INSTRUCTIONS_PAD)); { - LLGLSNoTexture gls_no_texture; + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); gGL.color4f( 0.9f, 0.9f, 0.9f, 1.0f ); gl_rect_2d( instructions_rect ); } @@ -4586,12 +4592,10 @@ void LLViewerWindow::restoreGL(const std::string& progress_message) setProgressString(progress_message); } llinfos << "...Restoring GL done" << llendl; -#if LL_WINDOWS - if(!LLWinDebug::checkExceptionHandler()) + if(!LLAppViewer::instance()->restoreErrorTrap()) { - llwarns << " Someone took over my exception handler (post restoreGL)!" << llendl; + llwarns << " Someone took over my signal/exception handler (post restoreGL)!" << llendl; } -#endif } } @@ -4647,9 +4651,97 @@ void LLViewerWindow::getTargetWindow(BOOL& fullscreen, S32& width, S32& height) } } +bool LLViewerWindow::updateResolution() +{ + if (gSavedSettings.getBOOL("FullScreenAutoDetectAspectRatio")) + { + getWindow()->setNativeAspectRatio(0.f); + } + else + { + getWindow()->setNativeAspectRatio(gSavedSettings.getF32("FullScreenAspectRatio")); + } + + reshape(getWindowDisplayWidth(), getWindowDisplayHeight()); + + // Screen resolution + S32 num_resolutions; + LLWindow::LLWindowResolution* supported_resolutions = getWindow()->getSupportedResolutions(num_resolutions); + + // check if resolution has changed + BOOL targetFullscreen; + S32 targetWidth; + S32 targetHeight; + + getTargetWindow(targetFullscreen, targetWidth, targetHeight); + + if ((mIsFullscreenChecked != (bool) targetFullscreen) || + (mIsFullscreenChecked && + (supported_resolutions[mCurrResolutionIndex].mWidth != targetWidth || + supported_resolutions[mCurrResolutionIndex].mHeight != targetHeight) + )) + { + // change fullscreen resolution or switch in/out of windowed mode + BOOL result; + + BOOL logged_in = (LLStartUp::getStartupState() >= STATE_STARTED); + if (mIsFullscreenChecked) + { + result = changeDisplaySettings(TRUE, + LLCoordScreen( supported_resolutions[mCurrResolutionIndex].mWidth, + supported_resolutions[mCurrResolutionIndex].mHeight), + gSavedSettings.getBOOL("DisableVerticalSync"), + logged_in); + } + else + { + result = changeDisplaySettings(FALSE, + LLCoordScreen(gSavedSettings.getS32("WindowWidth"), gSavedSettings.getS32("WindowHeight")), + TRUE, + logged_in); + } + if (!result) + { + + // GL is non-existent at this point, so we can't continue. + llerrs << "LLPanelDisplay::apply() failed" << llendl; + } + } + + // force aspect ratio + if (mIsFullscreenChecked) + { + LLViewerCamera::getInstance()->setAspect( getDisplayAspectRatio() ); + } + return true; +} + +void LLViewerWindow::requestResolutionUpdate(bool fullscreen_checked, U32 resolution_index) +{ + mResDirty = true; + mIsFullscreenChecked = fullscreen_checked; + mCurrResolutionIndex = resolution_index; +} + BOOL LLViewerWindow::checkSettings() { + if (mStatesDirty) + { + gGL.refreshState(); + LLViewerShaderMgr::instance()->setShaders(); + mStatesDirty = false; + } + + // We want to update the resolution AFTER the states getting refreshed not before. + if (mResDirty) + { + updateResolution(); + mResDirty = false; + // This will force a state update the next frame. + mStatesDirty = true; + } + BOOL is_fullscreen = mWindow->getFullscreen(); if (is_fullscreen && !mWantFullscreen) { @@ -4658,6 +4750,7 @@ BOOL LLViewerWindow::checkSettings() gSavedSettings.getS32("WindowHeight")), TRUE, mShowFullscreenProgress); + mStatesDirty = true; return TRUE; } else if (!is_fullscreen && mWantFullscreen) @@ -4677,6 +4770,7 @@ BOOL LLViewerWindow::checkSettings() LLGLState::checkStates(); LLGLState::checkTextureChannels(); + mStatesDirty = true; return TRUE; } return FALSE; @@ -5103,25 +5197,34 @@ LLPickInfo::~LLPickInfo() void LLPickInfo::fetchResults() { + + S32 face_hit = -1; + LLVector3 intersection, normal, binormal; + LLVector2 uv; + + LLViewerObject* hit_object = gViewerWindow->cursorIntersect(-1, -1, 512.f, + NULL, -1, mPickTransparent, &face_hit, + &intersection, &uv, &normal, &binormal); + // read back colors and depth values from buffer - glReadPixels(mScreenRegion.mLeft, mScreenRegion.mBottom, mScreenRegion.getWidth(), mScreenRegion.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, mPickBuffer); - glReadPixels(mScreenRegion.mLeft, mScreenRegion.mBottom, mScreenRegion.getWidth(), mScreenRegion.getHeight(), GL_DEPTH_COMPONENT, GL_FLOAT, mPickDepthBuffer ); + //glReadPixels(mScreenRegion.mLeft, mScreenRegion.mBottom, mScreenRegion.getWidth(), mScreenRegion.getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, mPickBuffer); + //glReadPixels(mScreenRegion.mLeft, mScreenRegion.mBottom, mScreenRegion.getWidth(), mScreenRegion.getHeight(), GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, mPickDepthBuffer ); // find pick region that is fully onscreen LLCoordGL scaled_pick_point;; scaled_pick_point.mX = llclamp(llround((F32)mMousePt.mX * gViewerWindow->getDisplayScale().mV[VX]), PICK_HALF_WIDTH, gViewerWindow->getWindowDisplayWidth() - PICK_HALF_WIDTH); scaled_pick_point.mY = llclamp(llround((F32)mMousePt.mY * gViewerWindow->getDisplayScale().mV[VY]), PICK_HALF_WIDTH, gViewerWindow->getWindowDisplayHeight() - PICK_HALF_WIDTH); - S32 pixel_index = PICK_HALF_WIDTH * PICK_DIAMETER + PICK_HALF_WIDTH; - S32 pick_id = (U32)mPickBuffer[(pixel_index * 4) + 0] << 16 | (U32)mPickBuffer[(pixel_index * 4) + 1] << 8 | (U32)mPickBuffer[(pixel_index * 4) + 2]; - F32 depth = mPickDepthBuffer[pixel_index]; + //S32 pixel_index = PICK_HALF_WIDTH * PICK_DIAMETER + PICK_HALF_WIDTH; + //S32 pick_id = (U32)mPickBuffer[(pixel_index * 4) + 0] << 16 | (U32)mPickBuffer[(pixel_index * 4) + 1] << 8 | (U32)mPickBuffer[(pixel_index * 4) + 2]; + //F32 depth = mPickDepthBuffer[pixel_index]; - S32 x_offset = mMousePt.mX - llround((F32)scaled_pick_point.mX / gViewerWindow->getDisplayScale().mV[VX]); - S32 y_offset = mMousePt.mY - llround((F32)scaled_pick_point.mY / gViewerWindow->getDisplayScale().mV[VY]); + //S32 x_offset = mMousePt.mX - llround((F32)scaled_pick_point.mX / gViewerWindow->getDisplayScale().mV[VX]); + //S32 y_offset = mMousePt.mY - llround((F32)scaled_pick_point.mY / gViewerWindow->getDisplayScale().mV[VY]); mPickPt = mMousePt; // we hit nothing, scan surrounding pixels for something useful - if (!pick_id) + /*if (!pick_id) { S32 closest_distance = 10000; //S32 closest_pick_name = 0; @@ -5142,25 +5245,21 @@ void LLPickInfo::fetchResults() } } } - } + }*/ - U32 te_offset = ((U32)pick_id >> 20); - pick_id &= 0x000fffff; - //unproject relative clicked coordinate from window coordinate using GL - GLint viewport[4]; - GLdouble modelview[16]; - GLdouble projection[16]; - GLfloat winX, winY; - GLdouble posX, posY, posZ; + U32 te_offset = face_hit > -1 ? face_hit : 0; + //pick_id &= 0x000fffff; - LLViewerObject* objectp = gObjectList.getSelectedObject(pick_id); + //unproject relative clicked coordinate from window coordinate using GL + + LLViewerObject* objectp = hit_object; - if (pick_id == (S32)GL_NAME_PARCEL_WALL) - { - mPickType = PICK_PARCEL_WALL; - } - else if (objectp) + //if (pick_id == (S32)GL_NAME_PARCEL_WALL) + //{ + // mPickType = PICK_PARCEL_WALL; + //} + if (objectp) { if( objectp->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH ) { @@ -5186,11 +5285,11 @@ void LLPickInfo::fetchResults() { mPickType = PICK_OBJECT; } - mObjectOffset = gAgent.calcFocusOffset(objectp, mPickPt.mX, mPickPt.mY); + mObjectOffset = gAgent.calcFocusOffset(objectp, intersection, mPickPt.mX, mPickPt.mY); mObjectID = objectp->mID; mObjectFace = (te_offset == NO_FACE) ? -1 : (S32)te_offset; - glh::matrix4f newModel((F32*)LLViewerCamera::getInstance()->getModelview().mMatrix); + /*glh::matrix4f newModel((F32*)LLViewerCamera::getInstance()->getModelview().mMatrix); for(U32 i = 0; i < 16; ++i) { @@ -5202,9 +5301,9 @@ void LLPickInfo::fetchResults() winX = ((F32)mPickPt.mX) * gViewerWindow->getDisplayScale().mV[VX]; winY = ((F32)mPickPt.mY) * gViewerWindow->getDisplayScale().mV[VY]; - gluUnProject( winX, winY, depth, modelview, projection, viewport, &posX, &posY, &posZ); + gluUnProject( winX, winY, depth, modelview, projection, viewport, &posX, &posY, &posZ);*/ - mPosGlobal = gAgent.getPosGlobalFromAgent(LLVector3(posX, posY, posZ)); + mPosGlobal = gAgent.getPosGlobalFromAgent(intersection); if (mWantSurfaceInfo) { @@ -5212,16 +5311,16 @@ void LLPickInfo::fetchResults() } } } - else - { + //else + //{ // was this name referring to a hud icon? - mHUDIcon = LLHUDIcon::handlePick(pick_id); - if (mHUDIcon) - { - mPickType = PICK_ICON; - mPosGlobal = mHUDIcon->getPositionGlobal(); - } - } + // mHUDIcon = LLHUDIcon::handlePick(pick_id); + // if (mHUDIcon) + // { + // mPickType = PICK_ICON; + // mPosGlobal = mHUDIcon->getPositionGlobal(); + // } + //} if (mPickCallback) { @@ -5236,16 +5335,19 @@ LLPointer<LLViewerObject> LLPickInfo::getObject() const void LLPickInfo::updateXYCoords() { - const LLTextureEntry* tep = getObject()->getTE(mObjectFace); - LLPointer<LLViewerImage> imagep = gImageList.getImage(tep->getID()); - if(mUVCoords.mV[VX] >= 0.f && mUVCoords.mV[VY] >= 0.f && imagep.notNull()) + if (mObjectFace > -1) { - LLCoordGL coords; - - coords.mX = llround(mUVCoords.mV[VX] * (F32)imagep->getWidth()); - coords.mY = llround(mUVCoords.mV[VY] * (F32)imagep->getHeight()); + const LLTextureEntry* tep = getObject()->getTE(mObjectFace); + LLPointer<LLViewerImage> imagep = gImageList.getImage(tep->getID()); + if(mUVCoords.mV[VX] >= 0.f && mUVCoords.mV[VY] >= 0.f && imagep.notNull()) + { + LLCoordGL coords; + + coords.mX = llround(mUVCoords.mV[VX] * (F32)imagep->getWidth()); + coords.mY = llround(mUVCoords.mV[VY] * (F32)imagep->getHeight()); - gViewerWindow->getWindow()->convertCoords(coords, &mXYCoords); + gViewerWindow->getWindow()->convertCoords(coords, &mXYCoords); + } } } @@ -5256,7 +5358,7 @@ void LLPickInfo::drawPickBuffer() const gGL.pushMatrix(); LLGLDisable no_blend(GL_BLEND); LLGLDisable no_alpha_test(GL_ALPHA_TEST); - LLGLSNoTexture no_texture; + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); glPixelZoom(10.f, 10.f); LLVector2 display_scale = gViewerWindow->getDisplayScale(); glRasterPos2f(((F32)mMousePt.mX * display_scale.mV[VX] + 10.f), @@ -5308,7 +5410,7 @@ void LLPickInfo::getSurfaceInfo() if (objectp) { if (gViewerWindow->cursorIntersect(llround((F32)mMousePt.mX), llround((F32)mMousePt.mY), 1024.f, - objectp, -1, + objectp, -1, mPickTransparent, &mObjectFace, &mIntersection, &mSTCoords, @@ -5317,7 +5419,7 @@ void LLPickInfo::getSurfaceInfo() { // if we succeeded with the intersect above, compute the texture coordinates: - if (objectp->mDrawable.notNull()) + if (objectp->mDrawable.notNull() && mObjectFace > -1) { LLFace* facep = objectp->mDrawable->getFace(mObjectFace); -- cgit v1.1