From c8aa1fb7c8ed44886599ea4e04eed403392e2e34 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 17 Dec 2012 18:00:30 -0500 Subject: LLWindow: Move to using Cocoa for window and view creation along with setting up callbacks for event handling as such. --- indra/llwindow/CMakeLists.txt | 2 + indra/llwindow/llkeyboardmacosx.cpp | 33 +- indra/llwindow/llkeyboardmacosx.h | 9 + indra/llwindow/llopenglview-objc.h | 72 + indra/llwindow/llopenglview-objc.mm | 352 +++++ indra/llwindow/llwindowmacosx-objc.h | 53 +- indra/llwindow/llwindowmacosx-objc.mm | 221 ++- indra/llwindow/llwindowmacosx.cpp | 2632 ++++++--------------------------- indra/llwindow/llwindowmacosx.h | 52 +- indra/newview/llviewerkeyboard.cpp | 2 + indra/newview/llviewerwindow.cpp | 1 + 11 files changed, 1217 insertions(+), 2212 deletions(-) create mode 100644 indra/llwindow/llopenglview-objc.h create mode 100644 indra/llwindow/llopenglview-objc.mm diff --git a/indra/llwindow/CMakeLists.txt b/indra/llwindow/CMakeLists.txt index 341bddfffd..8a38db751e 100644 --- a/indra/llwindow/CMakeLists.txt +++ b/indra/llwindow/CMakeLists.txt @@ -75,11 +75,13 @@ if (DARWIN) llkeyboardmacosx.cpp llwindowmacosx.cpp llwindowmacosx-objc.mm + llopenglview-objc.mm ) list(APPEND llwindow_HEADER_FILES llkeyboardmacosx.h llwindowmacosx.h llwindowmacosx-objc.h + llopenglview-objc.h ) # We use a bunch of deprecated system APIs. diff --git a/indra/llwindow/llkeyboardmacosx.cpp b/indra/llwindow/llkeyboardmacosx.cpp index 7f8f303517..3f357c600e 100644 --- a/indra/llwindow/llkeyboardmacosx.cpp +++ b/indra/llwindow/llkeyboardmacosx.cpp @@ -30,7 +30,7 @@ #include "llkeyboardmacosx.h" #include "llwindowcallbacks.h" -#include +#include "llwindowmacosx-objc.h" LLKeyboardMacOSX::LLKeyboardMacOSX() { @@ -162,23 +162,23 @@ LLKeyboardMacOSX::LLKeyboardMacOSX() void LLKeyboardMacOSX::resetMaskKeys() { - U32 mask = GetCurrentEventKeyModifiers(); + U32 mask = getModifiers(); // MBW -- XXX -- This mirrors the operation of the Windows version of resetMaskKeys(). // It looks a bit suspicious, as it won't correct for keys that have been released. // Is this the way it's supposed to work? - if(mask & shiftKey) + if(mask & MAC_SHIFT_KEY) { mKeyLevel[KEY_SHIFT] = TRUE; } - if(mask & (controlKey)) + if(mask & (MAC_CTRL_KEY)) { mKeyLevel[KEY_CONTROL] = TRUE; } - if(mask & optionKey) + if(mask & MAC_ALT_KEY) { mKeyLevel[KEY_ALT] = TRUE; } @@ -201,17 +201,17 @@ MASK LLKeyboardMacOSX::updateModifiers(const U32 mask) // translate the mask MASK out_mask = 0; - if(mask & shiftKey) + if(mask & MAC_SHIFT_KEY) { out_mask |= MASK_SHIFT; } - if(mask & (controlKey | cmdKey)) + if(mask & (MAC_CTRL_KEY | MAC_CMD_KEY)) { out_mask |= MASK_CONTROL; } - if(mask & optionKey) + if(mask & MAC_ALT_KEY) { out_mask |= MASK_ALT; } @@ -231,7 +231,12 @@ BOOL LLKeyboardMacOSX::handleKeyDown(const U16 key, const U32 mask) { handled = handleTranslatedKeyDown(translated_key, translated_mask); } - + if (!handled) + { + LL_INFOS("Keyboard") << "Unhandled key: " << mTranslateKeyMap[key] << LL_ENDL; + } else { + LL_INFOS("Keyboard") << "Handled key: " << mTranslateKeyMap[key] << LL_ENDL; + } return handled; } @@ -255,16 +260,16 @@ BOOL LLKeyboardMacOSX::handleKeyUp(const U16 key, const U32 mask) MASK LLKeyboardMacOSX::currentMask(BOOL for_mouse_event) { MASK result = MASK_NONE; - U32 mask = GetCurrentEventKeyModifiers(); + U32 mask = getModifiers(); - if (mask & shiftKey) result |= MASK_SHIFT; - if (mask & controlKey) result |= MASK_CONTROL; - if (mask & optionKey) result |= MASK_ALT; + if (mask & MAC_SHIFT_KEY) result |= MASK_SHIFT; + if (mask & MAC_CTRL_KEY) result |= MASK_CONTROL; + if (mask & MAC_ALT_KEY) result |= MASK_ALT; // For keyboard events, consider Command equivalent to Control if (!for_mouse_event) { - if (mask & cmdKey) result |= MASK_CONTROL; + if (mask & MAC_CMD_KEY) result |= MASK_CONTROL; } return result; diff --git a/indra/llwindow/llkeyboardmacosx.h b/indra/llwindow/llkeyboardmacosx.h index f09ff720ce..6e1f4d3b96 100644 --- a/indra/llwindow/llkeyboardmacosx.h +++ b/indra/llwindow/llkeyboardmacosx.h @@ -29,6 +29,15 @@ #include "llkeyboard.h" +// These more or less mirror their equivalents in NSEvent.h. +enum EMacEventKeys { + MAC_SHIFT_KEY = 1 << 17, + MAC_CTRL_KEY = 1 << 18, + MAC_ALT_KEY = 1 << 19, + MAC_CMD_KEY = 1 << 20, + MAC_FN_KEY = 1 << 23 +}; + class LLKeyboardMacOSX : public LLKeyboard { public: diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h new file mode 100644 index 0000000000..8abe81ce9e --- /dev/null +++ b/indra/llwindow/llopenglview-objc.h @@ -0,0 +1,72 @@ +// +// LLOpenGLView.h +// SecondLife +// +// Created by Geenz on 10/2/12. +// +// + +#import +#include "llwindowmacosx-objc.h" + +// Some nasty shovelling of LLOpenGLView from LLNativeBindings to prevent any C++ <-> Obj-C interop oddities. +// Redraw callback handling removed (for now) due to being unneeded in the patch that preceeds this addition. + +@interface LLOpenGLView : NSOpenGLView +{ + NSPoint mousePos; + ResizeCallback mResizeCallback; +} + +- (id) initWithFrame:(NSRect)frame withSamples:(NSUInteger)samples andVsync:(BOOL)vsync; + +// rebuildContext +// Destroys and recreates a context with the view's internal format set via setPixelFormat; +// Use this in event of needing to rebuild a context for whatever reason, without needing to assign a new pixel format. +- (BOOL) rebuildContext; + +// rebuildContextWithFormat +// Destroys and recreates a context with the specified pixel format. +- (BOOL) rebuildContextWithFormat:(NSOpenGLPixelFormat *)format; + +// These are mostly just for C++ <-> Obj-C interop. We can manipulate the CGLContext from C++ without reprecussions. +- (CGLContextObj) getCGLContextObj; +- (CGLPixelFormatObj*)getCGLPixelFormatObj; + +- (void) registerResizeCallback:(ResizeCallback)callback; +@end + +@interface LLNSWindow : NSWindow { + float mMousePos[2]; + unsigned int mModifiers; + + KeyCallback mKeyDownCallback; + KeyCallback mKeyUpCallback; + UnicodeCallback mUnicodeCallback; + ModifierCallback mModifierCallback; + MouseCallback mMouseDownCallback; + MouseCallback mMouseUpCallback; + MouseCallback mMouseDoubleClickCallback; + MouseCallback mRightMouseDownCallback; + MouseCallback mRightMouseUpCallback; + MouseCallback mMouseMovedCallback; + ScrollWheelCallback mScrollWhellCallback; + VoidCallback mMouseExitCallback; + MouseCallback mDeltaUpdateCallback; +} + +- (void) registerKeyDownCallback:(KeyCallback)callback; +- (void) registerKeyUpCallback:(KeyCallback)callback; +- (void) registerUnicodeCallback:(UnicodeCallback)callback; +- (void) registerModifierCallback:(ModifierCallback)callback; +- (void) registerMouseDownCallback:(MouseCallback)callback; +- (void) registerMouseUpCallback:(MouseCallback)callback; +- (void) registerRightMouseDownCallback:(MouseCallback)callback; +- (void) registerRightMouseUpCallback:(MouseCallback)callback; +- (void) registerDoubleClickCallback:(MouseCallback)callback; +- (void) registerMouseMovedCallback:(MouseCallback)callback; +- (void) registerScrollCallback:(ScrollWheelCallback)callback; +- (void) registerMouseExitCallback:(VoidCallback)callback; +- (void) registerDeltaUpdateCallback:(MouseCallback)callback; + +@end \ No newline at end of file diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm new file mode 100644 index 0000000000..a96c4cf82c --- /dev/null +++ b/indra/llwindow/llopenglview-objc.mm @@ -0,0 +1,352 @@ +// +// LLOpenGLView.m +// SecondLife +// +// Created by Geenz on 10/2/12. +// +// + +#import "llopenglview-objc.h" + +@implementation LLOpenGLView + +- (void)viewDidMoveToWindow +{ + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(windowResized:) name:NSWindowDidResizeNotification + object:[self window]]; +} + +- (void)windowResized:(NSNotification *)notification; +{ + NSSize size = [[self window] frame].size; + + mResizeCallback(size.width, size.height); +} + +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; +} + +- (id) initWithFrame:(NSRect)frame withSamples:(NSUInteger)samples andVsync:(BOOL)vsync +{ + + [self initWithFrame:frame]; + + // Initialize with a default "safe" pixel format that will work with versions dating back to OS X 10.6. + // Any specialized pixel formats, i.e. a core profile pixel format, should be initialized through rebuildContextWithFormat. + // 10.7 and 10.8 don't really care if we're defining a profile or not. If we don't explicitly request a core or legacy profile, it'll always assume a legacy profile (for compatibility reasons). + NSOpenGLPixelFormatAttribute attrs[] = { + NSOpenGLPFANoRecovery, + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAClosestPolicy, + NSOpenGLPFAAccelerated, + NSOpenGLPFASampleBuffers, (samples > 0 ? 1 : 0), + NSOpenGLPFASamples, samples, + NSOpenGLPFAStencilSize, 8, + NSOpenGLPFADepthSize, 24, + NSOpenGLPFAAlphaSize, 8, + NSOpenGLPFAColorSize, 24, + 0 + }; + + NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs] autorelease]; + + if (pixelFormat == nil) + { + NSLog(@"Failed to create pixel format!", nil); + return nil; + } + + NSOpenGLContext *glContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil]; + + if (glContext == nil) + { + NSLog(@"Failed to create OpenGL context!", nil); + return nil; + } + + [self setPixelFormat:pixelFormat]; + + [self setOpenGLContext:glContext]; + + [glContext setView:self]; + + [glContext makeCurrentContext]; + + if (vsync) + { + [glContext setValues:(const GLint*)1 forParameter:NSOpenGLCPSwapInterval]; + } else { + [glContext setValues:(const GLint*)0 forParameter:NSOpenGLCPSwapInterval]; + } + + return self; +} + +- (BOOL) rebuildContext +{ + return [self rebuildContextWithFormat:[self pixelFormat]]; +} + +- (BOOL) rebuildContextWithFormat:(NSOpenGLPixelFormat *)format +{ + NSOpenGLContext *ctx = [self openGLContext]; + + [ctx clearDrawable]; + [ctx initWithFormat:format shareContext:nil]; + + if (ctx == nil) + { + NSLog(@"Failed to create OpenGL context!", nil); + return false; + } + + [self setOpenGLContext:ctx]; + [ctx setView:self]; + [ctx makeCurrentContext]; + return true; +} + +- (CGLContextObj)getCGLContextObj +{ + NSOpenGLContext *ctx = [self openGLContext]; + return (CGLContextObj)[ctx CGLContextObj]; +} + +- (CGLPixelFormatObj*)getCGLPixelFormatObj +{ + NSOpenGLPixelFormat *fmt = [self pixelFormat]; + return (CGLPixelFormatObj*)[fmt CGLPixelFormatObj]; +} + +- (void) registerResizeCallback:(ResizeCallback)callback +{ + mResizeCallback = callback; +} + +// Various events can be intercepted by our view, thus not reaching our window. +// Intercept these events, and pass them to the window as needed. - Geenz + +- (void) mouseDragged:(NSEvent *)theEvent +{ + [super mouseDragged:theEvent]; +} + +- (void) scrollWheel:(NSEvent *)theEvent +{ + [super scrollWheel:theEvent]; +} + +- (void) mouseDown:(NSEvent *)theEvent +{ + [super mouseDown:theEvent]; +} + +- (void) mouseUp:(NSEvent *)theEvent +{ + [super mouseUp:theEvent]; +} + +- (void) rightMouseDown:(NSEvent *)theEvent +{ + [super rightMouseDown:theEvent]; +} + +- (void) rightMouseUp:(NSEvent *)theEvent +{ + [super rightMouseUp:theEvent]; +} + +- (void) keyUp:(NSEvent *)theEvent +{ + [super keyUp:theEvent]; +} + +- (void) keyDown:(NSEvent *)theEvent +{ + [super keyDown:theEvent]; +} + +- (void) mouseMoved:(NSEvent *)theEvent +{ + [super mouseMoved:theEvent]; +} + +- (void) flagsChanged:(NSEvent *)theEvent +{ + [super flagsChanged:theEvent]; +} + +@end + +// We use a custom NSWindow for our event handling. +// Why not an NSWindowController you may ask? +// Answer: this is easier. + +@implementation LLNSWindow + +- (id) init +{ + return self; +} + +- (void) keyDown:(NSEvent *)theEvent { + mKeyDownCallback([theEvent keyCode], [theEvent modifierFlags]); + + NSString *chars = [theEvent charactersIgnoringModifiers]; + for (uint i = 0; i < [chars length]; i++) + { + mUnicodeCallback([chars characterAtIndex:i], [theEvent modifierFlags]); + } + + // The viewer expects return to be submitted separately as a unicode character. + if ([theEvent keyCode] == 3 || [theEvent keyCode] == 13) + { + mUnicodeCallback([theEvent keyCode], [theEvent modifierFlags]); + } +} + +- (void) keyUp:(NSEvent *)theEvent { + mKeyUpCallback([theEvent keyCode], [theEvent modifierFlags]); +} + +- (void)flagsChanged:(NSEvent *)theEvent { + mModifiers = [theEvent modifierFlags]; +} + +- (void) mouseDown:(NSEvent *)theEvent +{ + if ([theEvent clickCount] == 2) + { + mMouseDoubleClickCallback(mMousePos, [theEvent modifierFlags]); + } else if ([theEvent clickCount] == 1) { + mMouseDownCallback(mMousePos, [theEvent modifierFlags]); + } +} + +- (void) mouseUp:(NSEvent *)theEvent +{ + mMouseUpCallback(mMousePos, [theEvent modifierFlags]); +} + +- (void) rightMouseDown:(NSEvent *)theEvent +{ + mRightMouseDownCallback(mMousePos, [theEvent modifierFlags]); +} + +- (void) rightMouseUp:(NSEvent *)theEvent +{ + mRightMouseUpCallback(mMousePos, [theEvent modifierFlags]); +} + +- (void)mouseMoved:(NSEvent *)theEvent { + float mouseDeltas[2] = { + [theEvent deltaX], + [theEvent deltaZ] + }; + + mDeltaUpdateCallback(mouseDeltas, 0); + + NSPoint mPoint = [theEvent locationInWindow]; + mMousePos[0] = mPoint.x; + mMousePos[1] = mPoint.y; + mMouseMovedCallback(mMousePos, 0); +} + +// NSWindow doesn't trigger mouseMoved when the mouse is being clicked and dragged. +// Use mouseDragged for situations like this to trigger our movement callback instead. + +- (void) mouseDragged:(NSEvent *)theEvent +{ + float mouseDeltas[2] = { + [theEvent deltaX], + [theEvent deltaZ] + }; + + mDeltaUpdateCallback(mouseDeltas, 0); + + NSPoint mPoint = [theEvent locationInWindow]; + mMousePos[0] = mPoint.x; + mMousePos[1] = mPoint.y; + mMouseMovedCallback(mMousePos, 0); +} + +- (void) scrollWheel:(NSEvent *)theEvent +{ + mScrollWhellCallback(-[theEvent deltaY]); +} + +- (void) mouseExited:(NSEvent *)theEvent +{ + mMouseExitCallback(); +} + +- (void) registerKeyDownCallback:(KeyCallback)callback +{ + mKeyDownCallback = callback; +} + +- (void) registerKeyUpCallback:(KeyCallback)callback +{ + mKeyUpCallback = callback; +} + +- (void) registerUnicodeCallback:(UnicodeCallback)callback +{ + mUnicodeCallback = callback; +} + +- (void) registerModifierCallback:(ModifierCallback)callback +{ + mModifierCallback = callback; +} + +- (void) registerMouseDownCallback:(MouseCallback)callback +{ + mMouseDownCallback = callback; +} + +- (void) registerMouseUpCallback:(MouseCallback)callback +{ + mMouseUpCallback = callback; +} + +- (void) registerRightMouseDownCallback:(MouseCallback)callback +{ + mRightMouseDownCallback = callback; +} + +- (void) registerRightMouseUpCallback:(MouseCallback)callback +{ + mRightMouseUpCallback = callback; +} + +- (void) registerDoubleClickCallback:(MouseCallback)callback +{ + mMouseDoubleClickCallback = callback; +} + +- (void) registerMouseMovedCallback:(MouseCallback)callback +{ + mMouseMovedCallback = callback; +} + +- (void) registerScrollCallback:(ScrollWheelCallback)callback +{ + mScrollWhellCallback = callback; +} + +- (void) registerMouseExitCallback:(VoidCallback)callback +{ + mMouseExitCallback = callback; +} + +- (void) registerDeltaUpdateCallback:(MouseCallback)callback +{ + mDeltaUpdateCallback = callback; +} + +@end \ No newline at end of file diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 7893dedda4..47ae13cb25 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -24,14 +24,61 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - +#include +typedef std::tr1::function KeyCallback; +typedef std::tr1::function ModifierCallback; +typedef std::tr1::function MouseCallback; +typedef std::tr1::function UnicodeCallback; +typedef std::tr1::function ResizeCallback; +typedef std::tr1::function ScrollWheelCallback; +typedef std::tr1::function VoidCallback; // This will actually hold an NSCursor*, but that type is only available in objective C. typedef void *CursorRef; +typedef void *NSWindowRef; +typedef void *GLViewRef; /* Defined in llwindowmacosx-objc.mm: */ void setupCocoa(); CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY); -OSErr releaseImageCursor(CursorRef ref); -OSErr setImageCursor(CursorRef ref); +short releaseImageCursor(CursorRef ref); +short setImageCursor(CursorRef ref); +void setArrowCursor(); +void setIBeamCursor(); +void setPointingHandCursor(); +void setCopyCursor(); +void setCrossCursor(); +void hideNSCursor(); +void showNSCursor(); +void hideNSCursorTillMove(bool hide); + +NSWindowRef createNSWindow(int x, int y, int width, int height); + +#include +GLViewRef createOpenGLView(NSWindowRef window); +void glSwapBuffers(void* context); +CGLContextObj getCGLContextObj(NSWindowRef window); +void getContentViewBounds(NSWindowRef window, float* bounds); +void getWindowSize(NSWindowRef window, float* size); +void setWindowSize(NSWindowRef window, int width, int height); +void getCursorPos(NSWindowRef window, float* pos); +void makeWindowOrderFront(NSWindowRef window); +void convertScreenToWindow(NSWindowRef window, float *coord); +void convertWindowToScreen(NSWindowRef window, float *coord); +void setWindowPos(NSWindowRef window, float* pos); + +void registerKeyUpCallback(NSWindowRef window, KeyCallback callback); +void registerKeyDownCallback(NSWindowRef window, KeyCallback callback); +void registerUnicodeCallback(NSWindowRef window, UnicodeCallback callback); +void registerMouseUpCallback(NSWindowRef window, MouseCallback callback); +void registerMouseDownCallback(NSWindowRef window, MouseCallback callback); +void registerRightMouseUpCallback(NSWindowRef window, MouseCallback callback); +void registerRightMouseDownCallback(NSWindowRef window, MouseCallback callback); +void registerDoubleClickCallback(NSWindowRef window, MouseCallback callback); +void registerResizeEventCallback(GLViewRef window, ResizeCallback callback); +void registerMouseMovedCallback(NSWindowRef window, MouseCallback callback); +void registerScrollCallback(NSWindowRef window, ScrollWheelCallback callback); +void registerMouseExitCallback(NSWindowRef window, VoidCallback callback); +void registerDeltaUpdateCallback(NSWindowRef window, MouseCallback callback); +unsigned int getModifiers(); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index bebb537cd8..03c0f55883 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -26,6 +26,9 @@ */ #include +#include +#include "llwindowmacosx-objc.h" +#include "llopenglview-objc.h" /* * These functions are broken out into a separate file because the @@ -34,8 +37,6 @@ * linden headers with any objective-C++ source. */ -#include "llwindowmacosx-objc.h" - void setupCocoa() { static bool inited = false; @@ -83,6 +84,51 @@ CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY) return (CursorRef)cursor; } +void setArrowCursor() +{ + NSCursor *cursor = [NSCursor arrowCursor]; + [cursor set]; +} + +void setIBeamCursor() +{ + NSCursor *cursor = [NSCursor IBeamCursor]; + [cursor set]; +} + +void setPointingHandCursor() +{ + NSCursor *cursor = [NSCursor pointingHandCursor]; + [cursor set]; +} + +void setCopyCursor() +{ + NSCursor *cursor = [NSCursor dragCopyCursor]; + [cursor set]; +} + +void setCrossCursor() +{ + NSCursor *cursor = [NSCursor crosshairCursor]; + [cursor set]; +} + +void hideNSCursor() +{ + [NSCursor hide]; +} + +void showNSCursor() +{ + [NSCursor unhide]; +} + +void hideNSCursorTillMove(bool hide) +{ + [NSCursor setHiddenUntilMouseMoves:hide]; +} + // This is currently unused, since we want all our cursors to persist for the life of the app, but I've included it for completeness. OSErr releaseImageCursor(CursorRef ref) { @@ -118,3 +164,174 @@ OSErr setImageCursor(CursorRef ref) return noErr; } +// Now for some unholy juggling between generic pointers and casting them to Obj-C objects! +// Note: things can get a bit hairy from here. This is not for the faint of heart. + +NSWindowRef createNSWindow(int x, int y, int width, int height) +{ + LLNSWindow *window = [[LLNSWindow alloc]initWithContentRect:NSMakeRect(x, y, width, height) + styleMask:NSTitledWindowMask | NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTexturedBackgroundWindowMask backing:NSBackingStoreBuffered defer:NO]; + [window makeKeyAndOrderFront:nil]; + [window setAcceptsMouseMovedEvents:TRUE]; + return window; +} + +GLViewRef createOpenGLView(NSWindowRef window) +{ + LLOpenGLView *glview = [[LLOpenGLView alloc]initWithFrame:[(LLNSWindow*)window frame] withSamples:0 andVsync:FALSE]; + [(LLNSWindow*)window setContentView:glview]; + return glview; +} + +void glSwapBuffers(void* context) +{ + [(NSOpenGLContext*)context flushBuffer]; +} + +CGLContextObj getCGLContextObj(NSWindowRef window) +{ + LLOpenGLView *glview = [(LLNSWindow*)window contentView]; + return [glview getCGLContextObj]; +} + +CGLPixelFormatObj* getCGLPixelFormatObj(NSWindowRef window) +{ + LLOpenGLView *glview = [(LLNSWindow*)window contentView]; + return [glview getCGLPixelFormatObj]; +} + +void getContentViewBounds(NSWindowRef window, float* bounds) +{ + bounds[0] = [[(LLNSWindow*)window contentView] bounds].origin.x; + bounds[1] = [[(LLNSWindow*)window contentView] bounds].origin.y; + bounds[2] = [[(LLNSWindow*)window contentView] bounds].size.width; + bounds[3] = [[(LLNSWindow*)window contentView] bounds].size.height; +} + +void getWindowSize(NSWindowRef window, float* size) +{ + NSRect frame = [(LLNSWindow*)window frame]; + size[0] = frame.origin.x; + size[1] = frame.origin.y; + size[2] = frame.size.width; + size[3] = frame.size.height; +} + +void setWindowSize(NSWindowRef window, int width, int height) +{ + NSRect frame = [(LLNSWindow*)window frame]; + frame.size.width = width; + frame.size.height = height; + [(LLNSWindow*)window setFrame:frame display:TRUE]; +} + +void setWindowPos(NSWindowRef window, float* pos) +{ + NSPoint point; + point.x = pos[0]; + point.y = pos[1]; + [(LLNSWindow*)window setFrameOrigin:point]; +} + +void getCursorPos(NSWindowRef window, float* pos) +{ + NSPoint mLoc; + mLoc = [(LLNSWindow*)window mouseLocationOutsideOfEventStream]; + pos[0] = mLoc.x; + pos[1] = mLoc.y; +} + +void makeWindowOrderFront(NSWindowRef window) +{ + [(LLNSWindow*)window makeKeyAndOrderFront:nil]; +} + +void convertScreenToWindow(NSWindowRef window, float *coord) +{ + NSPoint point; + point.x = coord[0]; + point.y = coord[1]; + point = [(LLNSWindow*)window convertScreenToBase:point]; + coord[0] = point.x; + coord[1] = point.y; +} + +void convertWindowToScreen(NSWindowRef window, float *coord) +{ + NSPoint point; + point.x = coord[0]; + point.y = coord[1]; + point = [(LLNSWindow*)window convertBaseToScreen:point]; + coord[0] = point.x; + coord[1] = point.y; +} + +void registerKeyUpCallback(NSWindowRef window, std::tr1::function callback) +{ + [(LLNSWindow*)window registerKeyUpCallback:callback]; +} + +void registerKeyDownCallback(NSWindowRef window, std::tr1::function callback) +{ + [(LLNSWindow*)window registerKeyDownCallback:callback]; +} + +void registerUnicodeCallback(NSWindowRef window, std::tr1::function callback) +{ + [(LLNSWindow*)window registerUnicodeCallback:callback]; +} + +void registerMouseUpCallback(NSWindowRef window, MouseCallback callback) +{ + [(LLNSWindow*)window registerMouseUpCallback:callback]; +} + +void registerMouseDownCallback(NSWindowRef window, MouseCallback callback) +{ + [(LLNSWindow*)window registerMouseDownCallback:callback]; +} + +void registerRightMouseUpCallback(NSWindowRef window, MouseCallback callback) +{ + [(LLNSWindow*)window registerRightMouseUpCallback:callback]; +} + +void registerRightMouseDownCallback(NSWindowRef window, MouseCallback callback) +{ + [(LLNSWindow*)window registerRightMouseDownCallback:callback]; +} + +void registerDoubleClickCallback(NSWindowRef window, MouseCallback callback) +{ + [(LLNSWindow*)window registerDoubleClickCallback:callback]; +} + +void registerResizeEventCallback(GLViewRef glview, ResizeCallback callback) +{ + [(LLOpenGLView*)glview registerResizeCallback:callback]; +} + +void registerMouseMovedCallback(NSWindowRef window, MouseCallback callback) +{ + [(LLNSWindow*)window registerMouseMovedCallback:callback]; +} + +void registerScrollCallback(NSWindowRef window, ScrollWheelCallback callback) +{ + [(LLNSWindow*)window registerScrollCallback:callback]; +} + +void registerMouseExitCallback(NSWindowRef window, VoidCallback callback) +{ + [(LLNSWindow*)window registerMouseExitCallback:callback]; +} + +void registerDeltaUpdateCallback(NSWindowRef window, MouseCallback callback) +{ + [(LLNSWindow*)window registerDeltaUpdateCallback:callback]; +} + +unsigned int getModifiers() +{ + return [NSEvent modifierFlags]; +} diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 97637c937f..1fb8bea802 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -30,7 +30,6 @@ #include "llkeyboardmacosx.h" #include "llwindowcallbacks.h" -#include "llwindowmacosx-objc.h" #include "llpreeditor.h" #include "llerror.h" @@ -58,7 +57,6 @@ const S32 MAX_NUM_RESOLUTIONS = 32; // BOOL LLWindowMacOSX::sUseMultGL = FALSE; -WindowRef LLWindowMacOSX::sMediaWindow = NULL; // Cross-platform bits: @@ -98,105 +96,9 @@ BOOL check_for_card(const char* RENDERER, const char* bad_card) // We may want to base this on the setting of _DEBUG... #define CAPTURE_ALL_DISPLAYS 0 -static double getDictDouble (CFDictionaryRef refDict, CFStringRef key); +//static double getDictDouble (CFDictionaryRef refDict, CFStringRef key); static long getDictLong (CFDictionaryRef refDict, CFStringRef key); - - - -// CarbonEvents we're interested in. -static EventTypeSpec WindowHandlerEventList[] = -{ - // Window-related events - { kEventClassWindow, kEventWindowActivated }, - { kEventClassWindow, kEventWindowDeactivated }, - { kEventClassWindow, kEventWindowShown }, - { kEventClassWindow, kEventWindowHidden }, - { kEventClassWindow, kEventWindowCollapsed }, - { kEventClassWindow, kEventWindowExpanded }, - { kEventClassWindow, kEventWindowGetClickActivation }, - { kEventClassWindow, kEventWindowClose }, - { kEventClassWindow, kEventWindowBoundsChanging }, - { kEventClassWindow, kEventWindowBoundsChanged }, - { kEventClassWindow, kEventWindowGetIdealSize }, - - // Mouse events - { kEventClassMouse, kEventMouseDown }, - { kEventClassMouse, kEventMouseUp }, - { kEventClassMouse, kEventMouseDragged }, - { kEventClassMouse, kEventMouseWheelMoved }, - { kEventClassMouse, kEventMouseMoved }, - - // Keyboard events - // No longer handle raw key down events directly. - // When text input events come in, extract the raw key events from them and process at that point. - // This allows input methods to eat keystrokes the way they're supposed to. -// { kEventClassKeyboard, kEventRawKeyDown }, -// { kEventClassKeyboard, kEventRawKeyRepeat }, - { kEventClassKeyboard, kEventRawKeyUp }, - { kEventClassKeyboard, kEventRawKeyModifiersChanged }, - - // Text input events - { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, - { kEventClassTextInput, kEventTextInputUpdateActiveInputArea }, - { kEventClassTextInput, kEventTextInputOffsetToPos }, - { kEventClassTextInput, kEventTextInputPosToOffset }, - { kEventClassTextInput, kEventTextInputShowHideBottomWindow }, - { kEventClassTextInput, kEventTextInputGetSelectedText }, - { kEventClassTextInput, kEventTextInputFilterText }, - - // TSM Document Access events (advanced input method support) - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetLength }, - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetSelectedRange }, - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetCharacters }, - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetFont }, - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetGlyphInfo }, - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessLockDocument }, - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessUnlockDocument } -}; - -static EventTypeSpec GlobalHandlerEventList[] = -{ - // Mouse events - { kEventClassMouse, kEventMouseDown }, - { kEventClassMouse, kEventMouseUp }, - { kEventClassMouse, kEventMouseDragged }, - { kEventClassMouse, kEventMouseWheelMoved }, - { kEventClassMouse, kEventMouseMoved }, - - // Keyboard events - // No longer handle raw key down events directly. - // When text input events come in, extract the raw key events from them and process at that point. - // This allows input methods to eat keystrokes the way they're supposed to. -// { kEventClassKeyboard, kEventRawKeyDown }, -// { kEventClassKeyboard, kEventRawKeyRepeat }, - { kEventClassKeyboard, kEventRawKeyUp }, - { kEventClassKeyboard, kEventRawKeyModifiersChanged }, - - // Text input events - { kEventClassTextInput, kEventTextInputUpdateActiveInputArea }, - { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, - { kEventClassTextInput, kEventTextInputOffsetToPos }, - { kEventClassTextInput, kEventTextInputPosToOffset }, - { kEventClassTextInput, kEventTextInputShowHideBottomWindow }, - { kEventClassTextInput, kEventTextInputGetSelectedText }, - { kEventClassTextInput, kEventTextInputFilterText }, - - // TSM Document Access events (advanced input method support) - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetLength }, - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetSelectedRange }, - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetCharacters }, - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetFont }, - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessGetGlyphInfo }, - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessLockDocument }, - { kEventClassTSMDocumentAccess, kEventTSMDocumentAccessUnlockDocument } -}; - -static EventTypeSpec CommandHandlerEventList[] = -{ - { kEventClassCommand, kEventCommandProcess } -}; - // MBW -- HACK ALERT // On the Mac, to put up an OS dialog in full screen mode, we must first switch OUT of full screen mode. // The proper way to do this is to bracket the dialog with calls to beforeDialog() and afterDialog(), but these @@ -204,8 +106,6 @@ static EventTypeSpec CommandHandlerEventList[] = // This assumes that there will be only one object of this class at any time. Hopefully this is true. static LLWindowMacOSX *gWindowImplementation = NULL; - - LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height, U32 flags, @@ -233,8 +133,6 @@ LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, mContext = NULL; mPixelFormat = NULL; mDisplay = CGMainDisplayID(); - mOldDisplayMode = NULL; - mTimer = NULL; mSimulatedRightClick = FALSE; mLastModifiers = 0; mHandsOffEvents = FALSE; @@ -246,12 +144,8 @@ LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, mOverrideAspectRatio = 0.f; mMaximized = FALSE; mMinimized = FALSE; - mTSMDocument = NULL; // Just in case. mLanguageTextInputAllowed = FALSE; - mTSMScriptCode = 0; - mTSMLangCode = 0; mPreeditor = NULL; - mRawKeyEvent = NULL; mFSAASamples = fsaa_samples; mForceRebuild = FALSE; @@ -263,43 +157,23 @@ LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, mOriginalAspectRatio = (double)CGDisplayPixelsWide(mDisplay) / (double)CGDisplayPixelsHigh(mDisplay); // Stash the window title - strcpy((char*)mWindowTitle + 1, title.c_str()); /* Flawfinder: ignore */ - mWindowTitle[0] = title.length(); - - mEventHandlerUPP = NewEventHandlerUPP(staticEventHandler); - mMoveEventCampartorUPP = NewEventComparatorUPP(staticMoveEventComparator); - mGlobalHandlerRef = NULL; - mWindowHandlerRef = NULL; + mWindowTitle = title; + //mWindowTitle[0] = title.length(); mDragOverrideCursor = -1; - // We're not clipping yet - SetRect( &mOldMouseClip, 0, 0, 0, 0 ); - // Set up global event handlers (the fullscreen case needs this) - InstallStandardEventHandler(GetApplicationEventTarget()); + //InstallStandardEventHandler(GetApplicationEventTarget()); // Stash an object pointer for OSMessageBox() gWindowImplementation = this; - // Create the GL context and set it up for windowed or fullscreen, as appropriate. + LL_INFOS("Window") << "Creating context..." << LL_ENDL; if(createContext(x, y, width, height, 32, fullscreen, disable_vsync)) { if(mWindow != NULL) { - // MBW -- XXX -- I think we can now do this here? - // Constrain the window to the screen it's mostly on, resizing if necessary. - ConstrainWindowToScreen( - mWindow, - kWindowStructureRgn, - kWindowConstrainMayResize | - // kWindowConstrainStandardOptions | - 0, - NULL, - NULL); - - MacShowWindow(mWindow); - BringToFront(mWindow); + makeWindowOrderFront(mWindow); } if (!gGLManager.initGL()) @@ -321,463 +195,193 @@ LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, mCallbacks = callbacks; stop_glerror(); + + } -BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync) -{ - OSStatus err; - BOOL glNeedsInit = FALSE; - - if(mGlobalHandlerRef == NULL) - { - InstallApplicationEventHandler(mEventHandlerUPP, GetEventTypeCount (CommandHandlerEventList), CommandHandlerEventList, (void*)this, &mGlobalHandlerRef); - } - - mFullscreen = fullscreen; - - if (mFullscreen && (mOldDisplayMode == NULL)) - { - LL_INFOS("Window") << "createContext: setting up fullscreen " << width << "x" << height << LL_ENDL; - - // NOTE: The refresh rate will be REPORTED AS 0 for many DVI and notebook displays. Plan accordingly. - double refresh = getDictDouble (CGDisplayCurrentMode (mDisplay), kCGDisplayRefreshRate); +// These functions are used as callbacks for event handling within Cocoa. +// It's a good idea to wrap these to avoid reworking more code than we need to within LLWindow. - // If the requested width or height is 0, find the best default for the monitor. - if((width == 0) || (height == 0)) - { - // Scan through the list of modes, looking for one which has: - // height between 700 and 800 - // aspect ratio closest to the user's original mode - S32 resolutionCount = 0; - LLWindowResolution *resolutionList = getSupportedResolutions(resolutionCount); +void callKeyUp(unsigned short key, unsigned int mask) +{ + gKeyboard->handleKeyUp(key, mask); +} - if(resolutionList != NULL) - { - F32 closestAspect = 0; - U32 closestHeight = 0; - U32 closestWidth = 0; - int i; +void callKeyDown(unsigned short key, unsigned int mask) +{ + gKeyboard->handleKeyDown(key, mask); +} - LL_DEBUGS("Window") << "createContext: searching for a display mode, original aspect is " << mOriginalAspectRatio << LL_ENDL; +void callUnicodeCallback(wchar_t character, unsigned int mask) +{ + gWindowImplementation->getCallbacks()->handleUnicodeChar(character, mask); +} - for(i=0; i < resolutionCount; i++) - { - F32 aspect = (F32)resolutionList[i].mWidth / (F32)resolutionList[i].mHeight; +void callModifierCallback(unsigned int mask) +{ + +} - LL_DEBUGS("Window") << "createContext: width " << resolutionList[i].mWidth << " height " << resolutionList[i].mHeight << " aspect " << aspect << LL_ENDL; +void callRightMouseDown(float *pos, MASK mask) +{ + LLCoordGL outCoords; + outCoords.mX = llround(pos[0]); + outCoords.mY = llround(pos[1]); + gWindowImplementation->getCallbacks()->handleRightMouseDown(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); +} - if( (resolutionList[i].mHeight >= 700) && (resolutionList[i].mHeight <= 800) && - (fabs(aspect - mOriginalAspectRatio) < fabs(closestAspect - mOriginalAspectRatio))) - { - LL_DEBUGS("Window") << " (new closest mode) " << LL_ENDL; +void callRightMouseUp(float *pos, MASK mask) +{ + LLCoordGL outCoords; + outCoords.mX = llround(pos[0]); + outCoords.mY = llround(pos[1]); + gWindowImplementation->getCallbacks()->handleRightMouseUp(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); +} - // This is the closest mode we've seen yet. - closestWidth = resolutionList[i].mWidth; - closestHeight = resolutionList[i].mHeight; - closestAspect = aspect; - } - } +void callLeftMouseDown(float *pos, MASK mask) +{ + LLCoordGL outCoords; + outCoords.mX = llround(pos[0]); + outCoords.mY = llround(pos[1]); + gWindowImplementation->getCallbacks()->handleMouseDown(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); + LL_INFOS("Window") << outCoords.mX << ", " << outCoords.mY << LL_ENDL; +} - width = closestWidth; - height = closestHeight; - } - } +void callLeftMouseUp(float *pos, MASK mask) +{ + LLCoordGL outCoords; + outCoords.mX = llround(pos[0]); + outCoords.mY = llround(pos[1]); + gWindowImplementation->getCallbacks()->handleMouseUp(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); + +} - if((width == 0) || (height == 0)) - { - // Mode search failed for some reason. Use the old-school default. - width = 1024; - height = 768; - } +void callDoubleClick(float *pos, MASK mask) +{ + LLCoordGL outCoords; + outCoords.mX = llround(pos[0]); + outCoords.mY = llround(pos[1]); + gWindowImplementation->getCallbacks()->handleDoubleClick(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); +} - if (true) - { - // Fullscreen support - CFDictionaryRef refDisplayMode = 0; - boolean_t exactMatch = false; - -#if CAPTURE_ALL_DISPLAYS - // Capture all displays (may want to do this for final build) - CGCaptureAllDisplays (); -#else - // Capture only the main display (useful for debugging) - CGDisplayCapture (mDisplay); -#endif +void callResize(unsigned int width, unsigned int height) +{ + gWindowImplementation->getCallbacks()->handleResize(gWindowImplementation, width, height); +} - // Switch the display to the desired resolution and refresh - refDisplayMode = CGDisplayBestModeForParametersAndRefreshRate( - mDisplay, - BITS_PER_PIXEL, - width, - height, - refresh, - &exactMatch); +void callMouseMoved(float *pos, MASK mask) +{ + LLCoordGL outCoords; + outCoords.mX = llround(pos[0]); + outCoords.mY = llround(pos[1]); + float deltas[2]; + gWindowImplementation->getMouseDeltas(deltas); + outCoords.mX += deltas[0]; + outCoords.mY += deltas[1]; + gWindowImplementation->getCallbacks()->handleMouseMove(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); +} - if (refDisplayMode) - { - LL_DEBUGS("Window") << "createContext: switching display resolution" << LL_ENDL; - mOldDisplayMode = CGDisplayCurrentMode (mDisplay); - CGDisplaySwitchToMode (mDisplay, refDisplayMode); - // CFRelease(refDisplayMode); +void callScrollMoved(float delta) +{ + gWindowImplementation->getCallbacks()->handleScrollWheel(gWindowImplementation, delta); +} - AddEventTypesToHandler(mGlobalHandlerRef, GetEventTypeCount (GlobalHandlerEventList), GlobalHandlerEventList); - } +void callMouseExit() +{ + gWindowImplementation->getCallbacks()->handleMouseLeave(gWindowImplementation); +} +void callWindowFocus() +{ + gWindowImplementation->getCallbacks()->handleFocus(gWindowImplementation); +} - mFullscreen = TRUE; - mFullscreenWidth = CGDisplayPixelsWide(mDisplay); - mFullscreenHeight = CGDisplayPixelsHigh(mDisplay); - mFullscreenBits = CGDisplayBitsPerPixel(mDisplay); - mFullscreenRefresh = llround(getDictDouble (CGDisplayCurrentMode (mDisplay), kCGDisplayRefreshRate)); +void callWindowUnfocus() +{ + gWindowImplementation->getCallbacks()->handleFocusLost(gWindowImplementation); +} - LL_INFOS("Window") << "Running at " << mFullscreenWidth - << "x" << mFullscreenHeight - << "x" << mFullscreenBits - << " @ " << mFullscreenRefresh - << LL_ENDL; - } - else - { - // No fullscreen support - mFullscreen = FALSE; - mFullscreenWidth = -1; - mFullscreenHeight = -1; - mFullscreenBits = -1; - mFullscreenRefresh = -1; - - std::string error= llformat("Unable to run fullscreen at %d x %d.\nRunning in window.", width, height); - OSMessageBox(error, "Error", OSMB_OK); - } - } +void callDeltaUpdate(float *delta, MASK mask) +{ + gWindowImplementation->updateMouseDeltas(); +} - if(!mFullscreen && (mWindow == NULL)) +void LLWindowMacOSX::updateMouseDeltas() +{ + if (mCursorDecoupled) { - //int displayWidth = CGDisplayPixelsWide(mDisplay); - //int displayHeight = CGDisplayPixelsHigh(mDisplay); - //const int menuBarPlusTitleBar = 44; // Ugly magic number. - - LL_DEBUGS("Window") << "createContext: creating window" << LL_ENDL; - - mPreviousWindowRect.left = (long) x; - mPreviousWindowRect.right = (long) x + width; - mPreviousWindowRect.top = (long) y; - mPreviousWindowRect.bottom = (long) y + height; - - //----------------------------------------------------------------------- - // Create the window - //----------------------------------------------------------------------- - mWindow = NewCWindow( - NULL, - &mPreviousWindowRect, - mWindowTitle, - false, // Create the window invisible. Whoever calls createContext() should show it after any moving/resizing. - // noGrowDocProc, // Window with no grow box and no zoom box - zoomDocProc, // Window with a grow box and a zoom box - // zoomNoGrow, // Window with a zoom box but no grow box - kFirstWindowOfClass, - true, - (long)this); - - if (!mWindow) + CGMouseDelta x, y; + CGGetLastMouseDelta( &x, &y ); + mCursorLastEventDeltaX = x; + mCursorLastEventDeltaY = y; + + if (mCursorIgnoreNextDelta) { - setupFailure("Window creation error", "Error", OSMB_OK); - return FALSE; + mCursorLastEventDeltaX = 0; + mCursorLastEventDeltaY = 0; + mCursorIgnoreNextDelta = FALSE; } + } else { + mCursorLastEventDeltaX = 0; + mCursorLastEventDeltaY = 0; + } +} - // Turn on live resize. - // For this to work correctly, we need to be able to call LLViewerWindow::draw from - // the event handler for kEventWindowBoundsChanged. It's not clear that we have access from here. - // err = ChangeWindowAttributes(mWindow, kWindowLiveResizeAttribute, 0); +void LLWindowMacOSX::getMouseDeltas(float* delta) +{ + delta[0] = mCursorLastEventDeltaX; + delta[1] = mCursorLastEventDeltaY; +} - // Set up window event handlers (some window-related events ONLY go to window handlers.) - InstallStandardEventHandler(GetWindowEventTarget(mWindow)); - InstallWindowEventHandler(mWindow, mEventHandlerUPP, GetEventTypeCount (WindowHandlerEventList), WindowHandlerEventList, (void*)this, &mWindowHandlerRef); // add event handler -#if LL_OS_DRAGDROP_ENABLED - InstallTrackingHandler( dragTrackingHandler, mWindow, (void*)this ); - InstallReceiveHandler( dragReceiveHandler, mWindow, (void*)this ); -#endif // LL_OS_DRAGDROP_ENABLED - } +BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync) +{ + BOOL glNeedsInit = FALSE; - { - // Create and initialize our TSM document for language text input. - // If an error occured, we can do nothing better than simply ignore it. - // mTSMDocument will be kept NULL in case. - if (mTSMDocument) - { - DeactivateTSMDocument(mTSMDocument); - DeleteTSMDocument(mTSMDocument); - mTSMDocument = NULL; - } - static InterfaceTypeList types = { kUnicodeDocument }; - err = NewTSMDocument(1, types, &mTSMDocument, 0); - if (err != noErr) - { - LL_WARNS("Window") << "createContext: couldn't create a TSMDocument (" << err << ")" << LL_ENDL; - } - if (mTSMDocument) - { - ActivateTSMDocument(mTSMDocument); - allowLanguageTextInput(NULL, FALSE); - } + mFullscreen = fullscreen; + + if (mWindow == NULL) + { + LL_INFOS("Window") << "Creating window..." << LL_ENDL; + mWindow = createNSWindow(x, y, width, height); + LL_INFOS("Window") << "Registering key callbacks..." << LL_ENDL; + registerKeyDownCallback(mWindow, callKeyDown); + registerKeyUpCallback(mWindow, callKeyUp); + registerUnicodeCallback(mWindow, callUnicodeCallback); + registerMouseDownCallback(mWindow, callLeftMouseDown); + registerMouseUpCallback(mWindow, callLeftMouseUp); + registerRightMouseDownCallback(mWindow, callRightMouseDown); + registerRightMouseUpCallback(mWindow, callRightMouseUp); + registerDoubleClickCallback(mWindow, callDoubleClick); + registerMouseMovedCallback(mWindow, callMouseMoved); + registerScrollCallback(mWindow, callScrollMoved); + registerDeltaUpdateCallback(mWindow, callDeltaUpdate); + registerMouseExitCallback(mWindow, callMouseExit); } if(mContext == NULL) { - AGLRendererInfo rendererInfo = NULL; - - //----------------------------------------------------------------------- - // Create GL drawing context - //----------------------------------------------------------------------- - - if(mPixelFormat == NULL) - { - if(mFullscreen) - { - GLint fullscreenAttrib[] = - { - AGL_RGBA, - AGL_FULLSCREEN, - AGL_NO_RECOVERY, - AGL_SAMPLE_BUFFERS_ARB, mFSAASamples > 0 ? 1 : 0, - AGL_SAMPLES_ARB, mFSAASamples, - AGL_DOUBLEBUFFER, - AGL_CLOSEST_POLICY, - AGL_ACCELERATED, - AGL_RED_SIZE, 8, - AGL_GREEN_SIZE, 8, - AGL_BLUE_SIZE, 8, - AGL_ALPHA_SIZE, 8, - AGL_DEPTH_SIZE, 24, - AGL_STENCIL_SIZE, 8, - AGL_NONE - }; - - LL_DEBUGS("Window") << "createContext: creating fullscreen pixelformat" << LL_ENDL; - - GDHandle gdhDisplay = NULL; - err = DMGetGDeviceByDisplayID ((DisplayIDType)mDisplay, &gdhDisplay, false); - - mPixelFormat = aglChoosePixelFormat(&gdhDisplay, 1, fullscreenAttrib); - rendererInfo = aglQueryRendererInfo(&gdhDisplay, 1); - } - else - { - // NOTE from Leslie: - // - // AGL_NO_RECOVERY, when combined with AGL_ACCELERATED prevents software rendering - // fallback which means we won't hvae shaders that compile and link but then don't - // work. The drawback is that our shader compilation will be a bit more finicky though. - - GLint windowedAttrib[] = - { - AGL_RGBA, - AGL_NO_RECOVERY, - AGL_DOUBLEBUFFER, - AGL_CLOSEST_POLICY, - AGL_ACCELERATED, - AGL_SAMPLE_BUFFERS_ARB, mFSAASamples > 0 ? 1 : 0, - AGL_SAMPLES_ARB, mFSAASamples, - AGL_RED_SIZE, 8, - AGL_GREEN_SIZE, 8, - AGL_BLUE_SIZE, 8, - AGL_ALPHA_SIZE, 8, - AGL_DEPTH_SIZE, 24, - AGL_STENCIL_SIZE, 8, - AGL_NONE - }; - - LL_DEBUGS("Window") << "createContext: creating windowed pixelformat" << LL_ENDL; - - mPixelFormat = aglChoosePixelFormat(NULL, 0, windowedAttrib); - - GDHandle gdhDisplay = GetMainDevice(); - rendererInfo = aglQueryRendererInfo(&gdhDisplay, 1); - } - - // May want to get the real error text like this: - // (char *) aglErrorString(aglGetError()); - - if(aglGetError() != AGL_NO_ERROR) - { - setupFailure("Can't find suitable pixel format", "Error", OSMB_OK); - return FALSE; - } - } - - if(mPixelFormat) - { - LL_DEBUGS("Window") << "createContext: creating GL context" << LL_ENDL; - mContext = aglCreateContext(mPixelFormat, NULL); - } - - if(mContext == NULL) - { - setupFailure("Can't make GL context", "Error", OSMB_OK); - return FALSE; - } - - gGLManager.mVRAM = 0; - - if(rendererInfo != NULL) - { - GLint result; - - if(aglDescribeRenderer(rendererInfo, AGL_VIDEO_MEMORY, &result)) - { - // llinfos << "createContext: aglDescribeRenderer(AGL_VIDEO_MEMORY) returned " << result << llendl; - gGLManager.mVRAM = result / (1024 * 1024); - } - else - { - // llinfos << "createContext: aglDescribeRenderer(AGL_VIDEO_MEMORY) failed." << llendl; - } - - // This could be useful at some point, if it takes into account the memory already used by screen buffers, etc... - if(aglDescribeRenderer(rendererInfo, AGL_TEXTURE_MEMORY, &result)) - { - // llinfos << "createContext: aglDescribeRenderer(AGL_TEXTURE_MEMORY) returned " << result << llendl; - } - else - { - // llinfos << "createContext: aglDescribeRenderer(AGL_TEXTURE_MEMORY) failed." << llendl; - } - - aglDestroyRendererInfo(rendererInfo); - } - + LL_INFOS("Window") << "Creating GL view..." << LL_ENDL; + mGLView = createOpenGLView(mWindow); + registerResizeEventCallback(mGLView, callResize); + mContext = getCGLContextObj(mWindow); // Since we just created the context, it needs to be set up. glNeedsInit = TRUE; } // Hook up the context to a drawable - if (mFullscreen && (mOldDisplayMode != NULL)) - { - // We successfully captured the display. Use a fullscreen drawable - - LL_DEBUGS("Window") << "createContext: attaching fullscreen drawable" << LL_ENDL; - -#if CAPTURE_ALL_DISPLAYS - // Capture all displays (may want to do this for final build) - aglDisable (mContext, AGL_FS_CAPTURE_SINGLE); -#else - // Capture only the main display (useful for debugging) - aglEnable (mContext, AGL_FS_CAPTURE_SINGLE); -#endif - - if (!aglSetFullScreen (mContext, 0, 0, 0, 0)) - { - setupFailure("Can't set GL fullscreen", "Error", OSMB_OK); - return FALSE; - } - } - else if(!mFullscreen && (mWindow != NULL)) - { - LL_DEBUGS("Window") << "createContext: attaching windowed drawable" << LL_ENDL; - - // We created a window. Use it as the drawable. - if(!aglSetDrawable(mContext, GetWindowPort (mWindow))) - { - setupFailure("Can't set GL drawable", "Error", OSMB_OK); - return FALSE; - } - } - else - { - setupFailure("Can't get fullscreen or windowed drawable.", "Error", OSMB_OK); - return FALSE; - } if(mContext != NULL) { + LL_INFOS("Window") << "Setting CGL Context..." << LL_ENDL; LL_DEBUGS("Window") << "createContext: setting current context" << LL_ENDL; - - if (!aglSetCurrentContext(mContext)) + U32 err = CGLSetCurrentContext(mContext); + if (err != kCGLNoError) { setupFailure("Can't activate GL rendering context", "Error", OSMB_OK); return FALSE; } } - if(glNeedsInit) - { - // Check for some explicitly unsupported cards. - const char* RENDERER = (const char*) glGetString(GL_RENDERER); - - const char* CARD_LIST[] = - { "RAGE 128", - "RIVA TNT2", - "Intel 810", - "3Dfx/Voodoo3", - "Radeon 7000", - "Radeon 7200", - "Radeon 7500", - "Radeon DDR", - "Radeon VE", - "GDI Generic" }; - const S32 CARD_COUNT = LL_ARRAY_SIZE(CARD_LIST); - - // Future candidates: - // ProSavage/Twister - // SuperSavage - - S32 i; - for (i = 0; i < CARD_COUNT; i++) - { - if (check_for_card(RENDERER, CARD_LIST[i])) - { - close(); - return FALSE; - } - } - } - - GLint colorBits, alphaBits, depthBits, stencilBits; - - if( !aglDescribePixelFormat(mPixelFormat, AGL_BUFFER_SIZE, &colorBits) || - !aglDescribePixelFormat(mPixelFormat, AGL_ALPHA_SIZE, &alphaBits) || - !aglDescribePixelFormat(mPixelFormat, AGL_DEPTH_SIZE, &depthBits) || - !aglDescribePixelFormat(mPixelFormat, AGL_STENCIL_SIZE, &stencilBits)) - { - close(); - setupFailure("Can't get pixel format description", "Error", OSMB_OK); - return FALSE; - } - - LL_INFOS("GLInit") << "GL buffer: Color Bits " << S32(colorBits) - << " Alpha Bits " << S32(alphaBits) - << " Depth Bits " << S32(depthBits) - << " Stencil Bits" << S32(stencilBits) - << LL_ENDL; - - if (colorBits < 32) - { - close(); - setupFailure( - "Second Life requires True Color (32-bit) to run in a window.\n" - "Please go to Control Panels -> Display -> Settings and\n" - "set the screen to 32-bit color.\n" - "Alternately, if you choose to run fullscreen, Second Life\n" - "will automatically adjust the screen each time it runs.", - "Error", - OSMB_OK); - return FALSE; - } - - if (alphaBits < 8) - { - close(); - setupFailure( - "Second Life is unable to run because it can't get an 8 bit alpha\n" - "channel. Usually this is due to video card driver issues.\n" - "Please make sure you have the latest video card drivers installed.\n" - "Also be sure your monitor is set to True Color (32-bit) in\n" - "Control Panels -> Display -> Settings.\n" - "If you continue to receive this message, contact customer service.", - "Error", - OSMB_OK); - return FALSE; - } - // Disable vertical sync for swap GLint frames_per_swap = 0; if (disable_vsync) @@ -790,7 +394,8 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits LL_DEBUGS("GLinit") << "Keeping vertical sync" << LL_ENDL; frames_per_swap = 1; } - aglSetInteger(mContext, AGL_SWAP_INTERVAL, &frames_per_swap); + + CGLSetParameter(mContext, kCGLCPSwapInterval, &frames_per_swap); //enable multi-threaded OpenGL if (sUseMultGL) @@ -809,109 +414,17 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits LL_DEBUGS("GLInit") << "Multi-threaded OpenGL enabled." << LL_ENDL; } } - + LL_INFOS("Window") << "Completed context creation." << LL_ENDL; // Don't need to get the current gamma, since there's a call that restores it to the system defaults. return TRUE; } -// changing fullscreen resolution, or switching between windowed and fullscreen mode. +// We only support OS X 10.7's fullscreen app mode which is literally a full screen window that fills a virtual desktop. +// This makes this method obsolete. BOOL LLWindowMacOSX::switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp) { - BOOL needsRebuild = FALSE; - BOOL result = true; - - if(fullscreen) - { - if(mFullscreen) - { - // Switching resolutions in fullscreen mode. Don't need to rebuild for this. - // Fullscreen support - CFDictionaryRef refDisplayMode = 0; - boolean_t exactMatch = false; - - // Switch the display to the desired resolution and refresh - refDisplayMode = CGDisplayBestModeForParametersAndRefreshRate( - mDisplay, - BITS_PER_PIXEL, - size.mX, - size.mY, - getDictDouble (CGDisplayCurrentMode (mDisplay), kCGDisplayRefreshRate), - &exactMatch); - - if (refDisplayMode) - { - CGDisplaySwitchToMode (mDisplay, refDisplayMode); - // CFRelease(refDisplayMode); - } - - mFullscreenWidth = CGDisplayPixelsWide(mDisplay); - mFullscreenHeight = CGDisplayPixelsHigh(mDisplay); - mFullscreenBits = CGDisplayBitsPerPixel(mDisplay); - mFullscreenRefresh = llround(getDictDouble (CGDisplayCurrentMode (mDisplay), kCGDisplayRefreshRate)); - - LL_INFOS("Window") << "Switched resolution to " << mFullscreenWidth - << "x" << mFullscreenHeight - << "x" << mFullscreenBits - << " @ " << mFullscreenRefresh - << LL_ENDL; - - // Update the GL context to the new screen size - if (!aglUpdateContext(mContext)) - { - setupFailure("Can't set GL fullscreen", "Error", OSMB_OK); - result = FALSE; - } - } - else - { - // Switching from windowed to fullscreen - needsRebuild = TRUE; - } - } - else - { - if(mFullscreen) - { - // Switching from fullscreen to windowed - needsRebuild = TRUE; - } - else - { - // Windowed to windowed -- not sure why we would be called like this. Just change the window size. - // The bounds changed event handler will do the rest. - if(mWindow != NULL) - { - ::SizeWindow(mWindow, size.mX, size.mY, true); - } - } - } - - stop_glerror(); - if(needsRebuild || mForceRebuild) - { - mForceRebuild = FALSE; - destroyContext(); - result = createContext(0, 0, size.mX, size.mY, 0, fullscreen, disable_vsync); - if (result) - { - if(mWindow != NULL) - { - MacShowWindow(mWindow); - BringToFront(mWindow); - } - - llverify(gGLManager.initGL()); - - //start with arrow cursor - initCursors(); - setCursor( UI_CURSOR_ARROW ); - } - } - - stop_glerror(); - - return result; + return FALSE; } void LLWindowMacOSX::destroyContext() @@ -926,31 +439,8 @@ void LLWindowMacOSX::destroyContext() { LL_DEBUGS("Window") << "destroyContext: unhooking drawable " << LL_ENDL; - aglSetCurrentContext (NULL); - aglSetDrawable(mContext, NULL); - } - - // Make sure the display resolution gets restored - if(mOldDisplayMode != NULL) - { - LL_DEBUGS("Window") << "destroyContext: restoring display resolution " << LL_ENDL; - - CGDisplaySwitchToMode (mDisplay, mOldDisplayMode); - -#if CAPTURE_ALL_DISPLAYS - // Uncapture all displays (may want to do this for final build) - CGReleaseAllDisplays (); -#else - // Uncapture only the main display (useful for debugging) - CGDisplayRelease (mDisplay); -#endif - - // CFRelease(mOldDisplayMode); - - mOldDisplayMode = NULL; - - // Remove the global event handlers the fullscreen case needed - RemoveEventTypesFromHandler(mGlobalHandlerRef, GetEventTypeCount (GlobalHandlerEventList), GlobalHandlerEventList); + CGLSetCurrentContext(NULL); + mContext = NULL; } // Clean up remaining GL state before blowing away window @@ -959,49 +449,19 @@ void LLWindowMacOSX::destroyContext() // Clean up the pixel format if(mPixelFormat != NULL) { - LL_DEBUGS("Window") << "destroyContext: destroying pixel format " << LL_ENDL; - aglDestroyPixelFormat(mPixelFormat); + CGLDestroyPixelFormat(mPixelFormat); mPixelFormat = NULL; } - // Remove any Carbon Event handlers we installed - if(mGlobalHandlerRef != NULL) - { - LL_DEBUGS("Window") << "destroyContext: removing global event handler" << LL_ENDL; - RemoveEventHandler(mGlobalHandlerRef); - mGlobalHandlerRef = NULL; - } - - if(mWindowHandlerRef != NULL) - { - LL_DEBUGS("Window") << "destroyContext: removing window event handler" << LL_ENDL; - RemoveEventHandler(mWindowHandlerRef); - mWindowHandlerRef = NULL; - } - - // Cleanup any TSM document we created. - if(mTSMDocument != NULL) - { - LL_DEBUGS("Window") << "destroyContext: deleting TSM document" << LL_ENDL; - DeactivateTSMDocument(mTSMDocument); - DeleteTSMDocument(mTSMDocument); - mTSMDocument = NULL; - } - // Close the window if(mWindow != NULL) { - LL_DEBUGS("Window") << "destroyContext: disposing window" << LL_ENDL; - DisposeWindow(mWindow); - mWindow = NULL; } // Clean up the GL context if(mContext != NULL) { - LL_DEBUGS("Window") << "destroyContext: destroying GL context" << LL_ENDL; - aglDestroyContext(mContext); - mContext = NULL; + CGLDestroyContext(mContext); } } @@ -1022,17 +482,11 @@ LLWindowMacOSX::~LLWindowMacOSX() void LLWindowMacOSX::show() { - if(IsWindowCollapsed(mWindow)) - CollapseWindow(mWindow, false); - - MacShowWindow(mWindow); - BringToFront(mWindow); } void LLWindowMacOSX::hide() { setMouseClipping(FALSE); - HideWindow(mWindow); } //virtual @@ -1040,7 +494,6 @@ void LLWindowMacOSX::minimize() { setMouseClipping(FALSE); showCursor(); - CollapseWindow(mWindow, true); } //virtual @@ -1086,7 +539,6 @@ BOOL LLWindowMacOSX::getVisible() result = TRUE; }if (mWindow) { - if(MacIsWindowVisible(mWindow)) result = TRUE; } @@ -1107,7 +559,6 @@ BOOL LLWindowMacOSX::maximize() { if (mWindow && !mMaximized) { - ZoomWindow(mWindow, inContent, true); } return mMaximized; @@ -1125,17 +576,14 @@ void LLWindowMacOSX::gatherInput() { stopDockTileBounce(); } - - // Use the old-school version so we get AppleEvent handler dispatch and menuselect handling. - // Anything that has an event handler will get processed inside WaitNextEvent, so we only need to handle - // the odd stuff here. + EventRecord evt; while(WaitNextEvent(everyEvent, &evt, 0, NULL)) { // printf("WaitNextEvent returned true, event is %d.\n", evt.what); switch(evt.what) { - case mouseDown: + case mouseDown: { short part; WindowRef window; @@ -1143,35 +591,125 @@ void LLWindowMacOSX::gatherInput() part = FindWindow(evt.where, &window); switch ( part ) { - case inMenuBar: - selectResult = MenuSelect(evt.where); - - HiliteMenu(0); - break; + case inMenuBar: + selectResult = MenuSelect(evt.where); + + HiliteMenu(0); + break; } } - break; - - case kHighLevelEvent: - AEProcessAppleEvent (&evt); - break; - - case updateEvt: - // We shouldn't be getting these regularly (since our window will be buffered), but we need to handle them correctly... - BeginUpdate((WindowRef)evt.message); - EndUpdate((WindowRef)evt.message); - break; - + break; + + case kHighLevelEvent: + AEProcessAppleEvent (&evt); + break; + + case updateEvt: + // We shouldn't be getting these regularly (since our window will be buffered), but we need to handle them correctly... + BeginUpdate((WindowRef)evt.message); + EndUpdate((WindowRef)evt.message); + break; + } } + /* + U32 event = getLatestEvent(mWindow); + switch (event) { + case 0: + // Nothing's happened since our last handled event. + break; + + case 1: + { + gKeyboard->handleKeyDown(getKeyDown(mWindow), getModifiers(mWindow)); + mCallbacks->handleUnicodeChar(getLastCharacter(mWindow), gKeyboard->currentMask(FALSE)); // currentMask has the appropriately translated modifiers. + mLastModifiers = gKeyboard->currentMask(FALSE); + } + break; + + case 2: + gKeyboard->handleKeyUp(getKeyUp(mWindow), getModifiers(mWindow)); + mLastModifiers = gKeyboard->currentMask(FALSE); + break; + + case 3: + break; + + case 4: + { + LLCoordScreen inCoords; + LLCoordGL outCoords; + float* mouseCoords = getMouseDown(mWindow); + inCoords.mX = llround(mouseCoords[0]); + inCoords.mY = llround(mouseCoords[1]); + convertCoords(inCoords, &outCoords); + mCallbacks->handleMouseDown(this, outCoords, getModifiers(mWindow)); + mLastModifiers = gKeyboard->currentMask(FALSE); + } + break; + case 5: + { + LLCoordScreen inCoords; + LLCoordGL outCoords; + float* mouseCoords = getMouseUp(mWindow); + inCoords.mX = llround(mouseCoords[0]); + inCoords.mY = llround(mouseCoords[1]); + convertCoords(inCoords, &outCoords); + mCallbacks->handleMouseUp(this, outCoords, getModifiers(mWindow)); + mLastModifiers = gKeyboard->currentMask(FALSE); + } + break; + case 6: + { + LLCoordScreen inCoords; + LLCoordGL outCoords; + float* mouseCoords = getRightMouseDown(mWindow); + inCoords.mX = llround(mouseCoords[0]); + inCoords.mY = llround(mouseCoords[1]); + convertCoords(inCoords, &outCoords); + mCallbacks->handleRightMouseDown(this, outCoords, getModifiers(mWindow)); + mLastModifiers = gKeyboard->currentMask(FALSE); + } + break; + case 7: + { + LLCoordScreen inCoords; + LLCoordGL outCoords; + float* mouseCoords = getRightMouseDown(mWindow); + inCoords.mX = llround(mouseCoords[0]); + inCoords.mY = llround(mouseCoords[1]); + convertCoords(inCoords, &outCoords); + mCallbacks->handleRightMouseDown(this, outCoords, getModifiers(mWindow)); + mLastModifiers = gKeyboard->currentMask(FALSE); + } + break; + case 8: // Double click + { + LLCoordScreen inCoords; + LLCoordGL outCoords; + float* mouseCoords = getRightMouseDown(mWindow); + inCoords.mX = llround(mouseCoords[0]); + inCoords.mY = llround(mouseCoords[1]); + convertCoords(inCoords, &outCoords); + mCallbacks->handleDoubleClick(this, outCoords, getModifiers(mWindow)); + mLastModifiers = gKeyboard->currentMask(FALSE); + } + break; + case 10: // Text input (for IMEs) + + break; + default: + break; + + }*/ updateCursor(); } BOOL LLWindowMacOSX::getPosition(LLCoordScreen *position) { - Rect window_rect; - OSStatus err = -1; + float rect[4]; + S32 err = -1; if(mFullscreen) { @@ -1181,10 +719,10 @@ BOOL LLWindowMacOSX::getPosition(LLCoordScreen *position) } else if(mWindow) { - err = GetWindowBounds(mWindow, kWindowContentRgn, &window_rect); + getContentViewBounds(mWindow, rect); - position->mX = window_rect.left; - position->mY = window_rect.top; + position->mX = rect[0]; + position->mY = rect[1]; } else { @@ -1196,8 +734,8 @@ BOOL LLWindowMacOSX::getPosition(LLCoordScreen *position) BOOL LLWindowMacOSX::getSize(LLCoordScreen *size) { - Rect window_rect; - OSStatus err = -1; + float rect[4]; + S32 err = -1; if(mFullscreen) { @@ -1207,10 +745,10 @@ BOOL LLWindowMacOSX::getSize(LLCoordScreen *size) } else if(mWindow) { - err = GetWindowBounds(mWindow, kWindowContentRgn, &window_rect); + getContentViewBounds(mWindow, rect); - size->mX = window_rect.right - window_rect.left; - size->mY = window_rect.bottom - window_rect.top; + size->mX = rect[2]; + size->mY = rect[3]; } else { @@ -1222,9 +760,9 @@ BOOL LLWindowMacOSX::getSize(LLCoordScreen *size) BOOL LLWindowMacOSX::getSize(LLCoordWindow *size) { - Rect window_rect; - OSStatus err = -1; - + float rect[4]; + S32 err = -1; + if(mFullscreen) { size->mX = mFullscreenWidth; @@ -1233,16 +771,16 @@ BOOL LLWindowMacOSX::getSize(LLCoordWindow *size) } else if(mWindow) { - err = GetWindowBounds(mWindow, kWindowContentRgn, &window_rect); - - size->mX = window_rect.right - window_rect.left; - size->mY = window_rect.bottom - window_rect.top; + getContentViewBounds(mWindow, rect); + + size->mX = rect[2]; + size->mY = rect[3]; } else { llerrs << "LLWindowMacOSX::getPosition(): no window and not fullscreen!" << llendl; } - + return (err == noErr); } @@ -1250,7 +788,8 @@ BOOL LLWindowMacOSX::setPosition(const LLCoordScreen position) { if(mWindow) { - MacMoveWindow(mWindow, position.mX, position.mY, false); + float pos[2] = {position.mX, position.mY}; + setWindowPos(mWindow, pos); } return TRUE; @@ -1260,7 +799,7 @@ BOOL LLWindowMacOSX::setSizeImpl(const LLCoordScreen size) { if(mWindow) { - SizeWindow(mWindow, size.mX, size.mY, true); + setWindowSize(mWindow, size.mX, size.mY); } return TRUE; @@ -1268,15 +807,16 @@ BOOL LLWindowMacOSX::setSizeImpl(const LLCoordScreen size) BOOL LLWindowMacOSX::setSizeImpl(const LLCoordWindow size) { - Rect client_rect; + float client_rect[4]; if (mWindow) { - OSStatus err = GetWindowBounds(mWindow, kWindowContentRgn, &client_rect); + S32 err = noErr; + getContentViewBounds(mWindow, client_rect); if (err == noErr) { - client_rect.right = client_rect.left + size.mX; - client_rect.bottom = client_rect.top + size.mY; - err = SetWindowBounds(mWindow, kWindowContentRgn, &client_rect); + client_rect[2] += size.mX; + client_rect[3] += size.mY; + setWindowSize(mWindow, client_rect[2], client_rect[3]); } if (err == noErr) { @@ -1293,7 +833,7 @@ BOOL LLWindowMacOSX::setSizeImpl(const LLCoordWindow size) void LLWindowMacOSX::swapBuffers() { - aglSwapBuffers(mContext); + CGLFlushDrawable(mContext); } F32 LLWindowMacOSX::getGamma() @@ -1453,7 +993,7 @@ BOOL LLWindowMacOSX::setCursorPosition(const LLCoordWindow position) return result; } - +/* static void fixOrigin(void) { GrafPtr port; @@ -1467,26 +1007,16 @@ static void fixOrigin(void) ::SetOrigin(0,0); } } - +*/ BOOL LLWindowMacOSX::getCursorPosition(LLCoordWindow *position) { - Point cursor_point; + float cursor_point[2]; LLCoordScreen screen_pos; - GrafPtr save; if(mWindow == NULL) return FALSE; - - ::GetPort(&save); - ::SetPort(GetWindowPort(mWindow)); - fixOrigin(); - - // gets the mouse location in local coordinates - ::GetMouse(&cursor_point); - -// lldebugs << "getCursorPosition(): cursor is at " << cursor_point.h << ", " << cursor_point.v << " port origin: " << portrect.left << ", " << portrect.top << llendl; - - ::SetPort(save); + + getCursorPos(mWindow, cursor_point); if(mCursorDecoupled) { @@ -1499,12 +1029,12 @@ BOOL LLWindowMacOSX::getCursorPosition(LLCoordWindow *position) // CGGetLastMouseDelta may behave strangely when the cursor's first captured. // Stash in the event handler instead. - cursor_point.h += mCursorLastEventDeltaX; - cursor_point.v += mCursorLastEventDeltaY; + cursor_point[0] += mCursorLastEventDeltaX; + cursor_point[1] += mCursorLastEventDeltaY; } - position->mX = cursor_point.h; - position->mY = cursor_point.v; + position->mX = cursor_point[0]; + position->mY = cursor_point[1]; return TRUE; } @@ -1521,7 +1051,6 @@ void LLWindowMacOSX::adjustCursorDecouple(bool warpingMouse) // llinfos << "adjustCursorDecouple: decoupling cursor" << llendl; CGAssociateMouseAndMouseCursorPosition(false); mCursorDecoupled = true; - FlushSpecificEventsFromQueue(GetCurrentEventQueue(), mMoveEventCampartorUPP, NULL); mCursorIgnoreNextDelta = TRUE; } } @@ -1568,52 +1097,13 @@ F32 LLWindowMacOSX::getPixelAspectRatio() // MBW -- XXX -- There's got to be a better way than this. Find it, please... +// Since we're no longer supporting the "typical" fullscreen mode with CGL or NSOpenGL anymore, these are unnecessary. -Geenz void LLWindowMacOSX::beforeDialog() { - if(mFullscreen) - { - -#if CAPTURE_ALL_DISPLAYS - // Uncapture all displays (may want to do this for final build) - CGReleaseAllDisplays (); -#else - // Uncapture only the main display (useful for debugging) - CGDisplayRelease (mDisplay); -#endif - // kDocumentWindowClass - // kMovableModalWindowClass - // kAllWindowClasses - - // GLint order = 0; - // aglSetInteger(mContext, AGL_ORDER_CONTEXT_TO_FRONT, &order); - aglSetDrawable(mContext, NULL); - // GetWindowGroupLevel(GetWindowGroupOfClass(kAllWindowClasses), &oldWindowLevel); - // SetWindowGroupLevel(GetWindowGroupOfClass(kAllWindowClasses), CGShieldingWindowLevel()); - - mHandsOffEvents = TRUE; - - } } void LLWindowMacOSX::afterDialog() { - if(mFullscreen) - { - mHandsOffEvents = FALSE; - - // SetWindowGroupLevel(GetWindowGroupOfClass(kAllWindowClasses), oldWindowLevel); - aglSetFullScreen(mContext, 0, 0, 0, 0); - // GLint order = 1; - // aglSetInteger(mContext, AGL_ORDER_CONTEXT_TO_FRONT, &order); - -#if CAPTURE_ALL_DISPLAYS - // Capture all displays (may want to do this for final build) - CGCaptureAllDisplays (); -#else - // Capture only the main display (useful for debugging) - CGDisplayCapture (mDisplay); -#endif - } } @@ -1622,14 +1112,10 @@ void LLWindowMacOSX::flashIcon(F32 seconds) // Don't do this if we're already started, since this would try to install the NMRec twice. if(!mBounceTimer.getStarted()) { - OSErr err; - + S32 err = 0; + // TODO: Implement icon bouncing mBounceTime = seconds; - memset(&mBounceRec, 0, sizeof(mBounceRec)); - mBounceRec.qType = nmType; - mBounceRec.nmMark = 1; - err = NMInstall(&mBounceRec); - if(err == noErr) + if(err == 0) { mBounceTimer.start(); } @@ -1643,104 +1129,25 @@ void LLWindowMacOSX::flashIcon(F32 seconds) BOOL LLWindowMacOSX::isClipboardTextAvailable() { - OSStatus err; - ScrapRef scrap; - ScrapFlavorFlags flags; BOOL result = false; - - err = GetCurrentScrap(&scrap); - - if(err == noErr) - { - err = GetScrapFlavorFlags(scrap, kScrapFlavorTypeUnicode, &flags); - } - - if(err == noErr) - result = true; - + // TODO: Clipboard support. return result; } BOOL LLWindowMacOSX::pasteTextFromClipboard(LLWString &dst) { - OSStatus err; - ScrapRef scrap; - Size len; BOOL result = false; - - err = GetCurrentScrap(&scrap); - - if(err == noErr) - { - err = GetScrapFlavorSize(scrap, kScrapFlavorTypeUnicode, &len); - } - - if((err == noErr) && (len > 0)) - { - int u16len = len / sizeof(U16); - U16 *temp = new U16[u16len + 1]; - if (temp) - { - memset(temp, 0, (u16len + 1) * sizeof(temp[0])); - err = GetScrapFlavorData(scrap, kScrapFlavorTypeUnicode, &len, temp); - if (err == noErr) - { - // convert \r\n to \n and \r to \n in the incoming text. - U16 *s, *d; - for(s = d = temp; s[0] != '\0'; s++, d++) - { - if(s[0] == '\r') - { - if(s[1] == '\n') - { - // CRLF, a.k.a. DOS newline. Collapse to a single '\n'. - s++; - } - - d[0] = '\n'; - } - else - { - d[0] = s[0]; - } - } - - d[0] = '\0'; - - dst = utf16str_to_wstring(temp); - - result = true; - } - delete[] temp; - } - } + + // TODO: Clipboard support. return result; } BOOL LLWindowMacOSX::copyTextToClipboard(const LLWString &s) { - OSStatus err; - ScrapRef scrap; - //Size len; - //char *temp; BOOL result = false; - - if (!s.empty()) - { - err = GetCurrentScrap(&scrap); - if (err == noErr) - err = ClearScrap(&scrap); - - if (err == noErr) - { - llutf16string utf16str = wstring_to_utf16str(s); - size_t u16len = utf16str.length() * sizeof(U16); - err = PutScrapFlavor(scrap, kScrapFlavorTypeUnicode, kScrapFlavorMaskNone, u16len, utf16str.data()); - if (err == noErr) - result = true; - } - } + + // TODO: Clipboard support. return result; } @@ -1761,1048 +1168,162 @@ LLWindow::LLWindowResolution* LLWindowMacOSX::getSupportedResolutions(S32 &num_r CFArrayRef modes = CGDisplayAvailableModes(mDisplay); if(modes != NULL) - { - CFIndex index, cnt; - - mSupportedResolutions = new LLWindowResolution[MAX_NUM_RESOLUTIONS]; - mNumSupportedResolutions = 0; - - // Examine each mode - cnt = CFArrayGetCount( modes ); - - for ( index = 0; (index < cnt) && (mNumSupportedResolutions < MAX_NUM_RESOLUTIONS); index++ ) - { - // Pull the mode dictionary out of the CFArray - CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex( modes, index ); - long width = getDictLong(mode, kCGDisplayWidth); - long height = getDictLong(mode, kCGDisplayHeight); - long bits = getDictLong(mode, kCGDisplayBitsPerPixel); - - if(bits == BITS_PER_PIXEL && width >= 800 && height >= 600) - { - BOOL resolution_exists = FALSE; - for(S32 i = 0; i < mNumSupportedResolutions; i++) - { - if (mSupportedResolutions[i].mWidth == width && - mSupportedResolutions[i].mHeight == height) - { - resolution_exists = TRUE; - } - } - if (!resolution_exists) - { - mSupportedResolutions[mNumSupportedResolutions].mWidth = width; - mSupportedResolutions[mNumSupportedResolutions].mHeight = height; - mNumSupportedResolutions++; - } - } - } - } - } - - num_resolutions = mNumSupportedResolutions; - return mSupportedResolutions; -} - -BOOL LLWindowMacOSX::convertCoords(LLCoordGL from, LLCoordWindow *to) -{ - S32 client_height; - Rect client_rect; - - if(mFullscreen) - { - // In the fullscreen case, the "window" is the entire screen. - client_rect.left = 0; - client_rect.top = 0; - client_rect.right = mFullscreenWidth; - client_rect.bottom = mFullscreenHeight; - } - else if (!mWindow || - (GetWindowBounds(mWindow, kWindowContentRgn, &client_rect) != noErr) || - NULL == to) - { - return FALSE; - } - - to->mX = from.mX; - client_height = client_rect.bottom - client_rect.top; - to->mY = client_height - from.mY - 1; - - return TRUE; -} - -BOOL LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordGL* to) -{ - S32 client_height; - Rect client_rect; - - if(mFullscreen) - { - // In the fullscreen case, the "window" is the entire screen. - client_rect.left = 0; - client_rect.top = 0; - client_rect.right = mFullscreenWidth; - client_rect.bottom = mFullscreenHeight; - } - else if (!mWindow || - (GetWindowBounds(mWindow, kWindowContentRgn, &client_rect) != noErr) || - NULL == to) - { - return FALSE; - } - - to->mX = from.mX; - client_height = client_rect.bottom - client_rect.top; - to->mY = client_height - from.mY - 1; - - return TRUE; -} - -BOOL LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordWindow* to) -{ - if(mFullscreen) - { - // In the fullscreen case, window and screen coordinates are the same. - to->mX = from.mX; - to->mY = from.mY; - return TRUE; - } - else if(mWindow) - { - GrafPtr save; - Point mouse_point; - - mouse_point.h = from.mX; - mouse_point.v = from.mY; - - ::GetPort(&save); - ::SetPort(GetWindowPort(mWindow)); - fixOrigin(); - - ::GlobalToLocal(&mouse_point); - - to->mX = mouse_point.h; - to->mY = mouse_point.v; - - ::SetPort(save); - - return TRUE; - } - - return FALSE; -} - -BOOL LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordScreen *to) -{ - if(mFullscreen) - { - // In the fullscreen case, window and screen coordinates are the same. - to->mX = from.mX; - to->mY = from.mY; - return TRUE; - } - else if(mWindow) - { - GrafPtr save; - Point mouse_point; - - mouse_point.h = from.mX; - mouse_point.v = from.mY; - ::GetPort(&save); - ::SetPort(GetWindowPort(mWindow)); - fixOrigin(); - - LocalToGlobal(&mouse_point); - - to->mX = mouse_point.h; - to->mY = mouse_point.v; - - ::SetPort(save); - - return TRUE; - } - - return FALSE; -} - -BOOL LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordGL *to) -{ - LLCoordWindow window_coord; - - return(convertCoords(from, &window_coord) && convertCoords(window_coord, to)); -} - -BOOL LLWindowMacOSX::convertCoords(LLCoordGL from, LLCoordScreen *to) -{ - LLCoordWindow window_coord; - - return(convertCoords(from, &window_coord) && convertCoords(window_coord, to)); -} - - - - -void LLWindowMacOSX::setupFailure(const std::string& text, const std::string& caption, U32 type) -{ - destroyContext(); - - OSMessageBox(text, caption, type); -} - -pascal Boolean LLWindowMacOSX::staticMoveEventComparator( EventRef event, void* data) -{ - UInt32 evtClass = GetEventClass (event); - UInt32 evtKind = GetEventKind (event); - - if ((evtClass == kEventClassMouse) && ((evtKind == kEventMouseDragged) || (evtKind == kEventMouseMoved))) - { - return true; - } - - else - { - return false; - } -} - - -pascal OSStatus LLWindowMacOSX::staticEventHandler(EventHandlerCallRef myHandler, EventRef event, void* userData) -{ - LLWindowMacOSX *self = (LLWindowMacOSX*)userData; - - return(self->eventHandler(myHandler, event)); -} - -OSStatus LLWindowMacOSX::eventHandler (EventHandlerCallRef myHandler, EventRef event) -{ - OSStatus result = eventNotHandledErr; - UInt32 evtClass = GetEventClass (event); - UInt32 evtKind = GetEventKind (event); - - // Always handle command events, even in hands-off mode. - if((evtClass == kEventClassCommand) && (evtKind == kEventCommandProcess)) - { - HICommand command; - GetEventParameter (event, kEventParamDirectObject, typeHICommand, NULL, sizeof(command), NULL, &command); - - switch(command.commandID) - { - case kHICommandQuit: - if(mCallbacks->handleCloseRequest(this)) - { - // Get the app to initiate cleanup. - mCallbacks->handleQuit(this); - // The app is responsible for calling destroyWindow when done with GL - } - result = noErr; - break; - - default: - // MBW -- XXX -- Should we handle other events here? - break; - } - } - - if(mHandsOffEvents) - { - return(result); - } - - switch (evtClass) - { - case kEventClassTextInput: - { - switch (evtKind) - { - case kEventTextInputUpdateActiveInputArea: - { - EventParamType param_type; - - long fix_len; - UInt32 text_len; - if (mPreeditor - && (result = GetEventParameter(event, kEventParamTextInputSendFixLen, - typeLongInteger, ¶m_type, sizeof(fix_len), NULL, &fix_len)) == noErr - && typeLongInteger == param_type - && (result = GetEventParameter(event, kEventParamTextInputSendText, - typeUnicodeText, ¶m_type, 0, &text_len, NULL)) == noErr - && typeUnicodeText == param_type) - { - // Handle an optional (but essential to facilitate TSMDA) ReplaceRange param. - CFRange range; - if (GetEventParameter(event, kEventParamTextInputSendReplaceRange, - typeCFRange, ¶m_type, sizeof(range), NULL, &range) == noErr - && typeCFRange == param_type) - { - // Although the spec. is unclear, replace range should - // not present when there is an active preedit. We just - // ignore the case. markAsPreedit will detect the case and warn it. - const LLWString & text = mPreeditor->getPreeditString(); - const S32 location = wstring_wstring_length_from_utf16_length(text, 0, range.location); - const S32 length = wstring_wstring_length_from_utf16_length(text, location, range.length); - mPreeditor->markAsPreedit(location, length); - } - mPreeditor->resetPreedit(); - - // Receive the text from input method. - U16 *const text = new U16[text_len / sizeof(U16)]; - GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText, NULL, text_len, NULL, text); - if (fix_len < 0) - { - // Do we still need this? Seems obsolete... - fix_len = text_len; - } - const LLWString fix_string - = utf16str_to_wstring(llutf16string(text, fix_len / sizeof(U16))); - const LLWString preedit_string - = utf16str_to_wstring(llutf16string(text + fix_len / sizeof(U16), (text_len - fix_len) / sizeof(U16))); - delete[] text; - - // Handle fixed (comitted) string. - if (fix_string.length() > 0) - { - for (LLWString::const_iterator i = fix_string.begin(); i != fix_string.end(); i++) - { - mPreeditor->handleUnicodeCharHere(*i); - } - } - - // Receive the segment info and caret position. - LLPreeditor::segment_lengths_t preedit_segment_lengths; - LLPreeditor::standouts_t preedit_standouts; - S32 caret_position = preedit_string.length(); - UInt32 text_range_array_size; - if (GetEventParameter(event, kEventParamTextInputSendHiliteRng, typeTextRangeArray, - ¶m_type, 0, &text_range_array_size, NULL) == noErr - && typeTextRangeArray == param_type - && text_range_array_size > sizeof(TextRangeArray)) - { - // TextRangeArray is a variable-length struct. - TextRangeArray * const text_range_array = (TextRangeArray *) new char[text_range_array_size]; - GetEventParameter(event, kEventParamTextInputSendHiliteRng, typeTextRangeArray, - NULL, text_range_array_size, NULL, text_range_array); - - // WARNING: We assume ranges are in ascending order, - // although the condition is undocumented. It seems - // OK to assume this. I also assumed - // the ranges are contiguous in previous versions, but I - // have heard a rumore that older versions os ATOK may - // return ranges with some _gap_. I don't know whether - // it is true, but I'm preparing my code for the case. - - const S32 ranges = text_range_array->fNumOfRanges; - preedit_segment_lengths.reserve(ranges); - preedit_standouts.reserve(ranges); - - S32 last_bytes = 0; - S32 last_utf32 = 0; - for (S32 i = 0; i < ranges; i++) - { - const TextRange &range = text_range_array->fRange[i]; - if (range.fStart > last_bytes) - { - const S32 length_utf16 = (range.fStart - last_bytes) / sizeof(U16); - const S32 length_utf32 = wstring_wstring_length_from_utf16_length(preedit_string, last_utf32, length_utf16); - preedit_segment_lengths.push_back(length_utf32); - preedit_standouts.push_back(FALSE); - last_utf32 += length_utf32; - } - if (range.fEnd > range.fStart) - { - const S32 length_utf16 = (range.fEnd - range.fStart) / sizeof(U16); - const S32 length_utf32 = wstring_wstring_length_from_utf16_length(preedit_string, last_utf32, length_utf16); - preedit_segment_lengths.push_back(length_utf32); - preedit_standouts.push_back( - kTSMHiliteSelectedRawText == range.fHiliteStyle - || kTSMHiliteSelectedConvertedText == range.fHiliteStyle - || kTSMHiliteSelectedText == range.fHiliteStyle); - last_utf32 += length_utf32; - } - if (kTSMHiliteCaretPosition == range.fHiliteStyle) - { - caret_position = last_utf32; - } - last_bytes = range.fEnd; - } - if (preedit_string.length() > last_utf32) - { - preedit_segment_lengths.push_back(preedit_string.length() - last_utf32); - preedit_standouts.push_back(FALSE); - } - - delete[] (char *) text_range_array; - } - - // Handle preedit string. - if (preedit_string.length() == 0) - { - preedit_segment_lengths.clear(); - preedit_standouts.clear(); - } - else if (preedit_segment_lengths.size() == 0) - { - preedit_segment_lengths.push_back(preedit_string.length()); - preedit_standouts.push_back(FALSE); - } - mPreeditor->updatePreedit(preedit_string, preedit_segment_lengths, preedit_standouts, caret_position); - - result = noErr; - } - } - break; - - case kEventTextInputUnicodeForKeyEvent: - { - UInt32 modifiers = 0; - - - // First, process the raw event. - { - EventRef rawEvent = NULL; - - // Get the original event and extract the modifier keys, so we can ignore command-key events. - if (GetEventParameter(event, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL, sizeof(rawEvent), NULL, &rawEvent) == noErr) - { - // Grab the modifiers for later use in this function... - GetEventParameter (rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); - - // and call this function recursively to handle the raw key event. - eventHandler (myHandler, rawEvent); - - // save the raw event until we're done processing the unicode input as well. - mRawKeyEvent = rawEvent; - } - } - - OSStatus err = noErr; - EventParamType actualType = typeUnicodeText; - UInt32 actualSize = 0; - size_t actualCount = 0; - U16 *buffer = NULL; - - // Get the size of the unicode data - err = GetEventParameter (event, kEventParamTextInputSendText, typeUnicodeText, &actualType, 0, &actualSize, NULL); - if(err == noErr) - { - // allocate a buffer and get the actual data. - actualCount = actualSize / sizeof(U16); - buffer = new U16[actualCount]; - err = GetEventParameter (event, kEventParamTextInputSendText, typeUnicodeText, &actualType, actualSize, &actualSize, buffer); - } - - if(err == noErr) - { - if(modifiers & (cmdKey | controlKey)) - { - // This was a menu key equivalent. Ignore it. - } - else - { - MASK mask = LLWindowMacOSX::modifiersToMask(modifiers); - - llassert( actualType == typeUnicodeText ); - - // The result is a UTF16 buffer. Pass the characters in turn to handleUnicodeChar. - - // Convert to UTF32 and go character-by-character. - llutf16string utf16(buffer, actualCount); - LLWString utf32 = utf16str_to_wstring(utf16); - LLWString::iterator iter; - - for(iter = utf32.begin(); iter != utf32.end(); iter++) - { - mCallbacks->handleUnicodeChar(*iter, mask); - } - } - } - - if(buffer != NULL) - { - delete[] buffer; - } - - mRawKeyEvent = NULL; - result = err; - } - break; - - case kEventTextInputOffsetToPos: - { - EventParamType param_type; - long offset; - if (mPreeditor - && GetEventParameter(event, kEventParamTextInputSendTextOffset, typeLongInteger, - ¶m_type, sizeof(offset), NULL, &offset) == noErr - && typeLongInteger == param_type) - { - S32 preedit, preedit_length; - mPreeditor->getPreeditRange(&preedit, &preedit_length); - const LLWString & text = mPreeditor->getPreeditString(); - - LLCoordGL caret_coord; - LLRect preedit_bounds; - if (0 <= offset - && mPreeditor->getPreeditLocation(wstring_wstring_length_from_utf16_length(text, preedit, offset / sizeof(U16)), - &caret_coord, &preedit_bounds, NULL)) - { - LLCoordGL caret_base_coord(caret_coord.mX, preedit_bounds.mBottom); - LLCoordScreen caret_base_coord_screen; - convertCoords(caret_base_coord, &caret_base_coord_screen); - Point qd_point; - qd_point.h = caret_base_coord_screen.mX; - qd_point.v = caret_base_coord_screen.mY; - SetEventParameter(event, kEventParamTextInputReplyPoint, typeQDPoint, sizeof(qd_point), &qd_point); - - short line_height = (short) preedit_bounds.getHeight(); - SetEventParameter(event, kEventParamTextInputReplyLineHeight, typeShortInteger, sizeof(line_height), &line_height); - - result = noErr; - } - else - { - result = errOffsetInvalid; - } - } - } - break; - - case kEventTextInputGetSelectedText: - { - if (mPreeditor) - { - S32 selection, selection_length; - mPreeditor->getSelectionRange(&selection, &selection_length); - if (selection_length) - { - const LLWString text = mPreeditor->getPreeditString().substr(selection, selection_length); - const llutf16string text_utf16 = wstring_to_utf16str(text); - result = SetEventParameter(event, kEventParamTextInputReplyText, typeUnicodeText, - text_utf16.length() * sizeof(U16), text_utf16.c_str()); - } - } - } - break; - } - } - break; - - case kEventClassKeyboard: - { - UInt32 keyCode = 0; - char charCode = 0; - UInt32 modifiers = 0; - - // Some of these may fail for some event types. That's fine. - GetEventParameter (event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode); - GetEventParameter (event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); - - // save the raw event so getNativeKeyData can use it. - mRawKeyEvent = event; - - // printf("key event, key code = 0x%08x, char code = 0x%02x (%c), modifiers = 0x%08x\n", keyCode, charCode, (char)charCode, modifiers); - // fflush(stdout); - - switch (evtKind) - { - case kEventRawKeyDown: - case kEventRawKeyRepeat: - if (gDebugWindowProc) - { - printf("key down, key code = 0x%08x, char code = 0x%02x (%c), modifiers = 0x%08x\n", - (unsigned int)keyCode, charCode, (char)charCode, (unsigned int)modifiers); - fflush(stdout); - } - gKeyboard->handleKeyDown(keyCode, modifiers); - result = eventNotHandledErr; - break; - - case kEventRawKeyUp: - if (gDebugWindowProc) - { - printf("key up, key code = 0x%08x, char code = 0x%02x (%c), modifiers = 0x%08x\n", - (unsigned int)keyCode, charCode, (char)charCode, (unsigned int)modifiers); - fflush(stdout); - } - gKeyboard->handleKeyUp(keyCode, modifiers); - result = eventNotHandledErr; - break; - - case kEventRawKeyModifiersChanged: - // The keyboard input system wants key up/down events for modifier keys. - // Mac OS doesn't supply these directly, but can supply events when the collective modifier state changes. - // Use these events to generate up/down events for the modifiers. - - if((modifiers & shiftKey) && !(mLastModifiers & shiftKey)) - { - if (gDebugWindowProc) printf("Shift key down event\n"); - gKeyboard->handleKeyDown(0x38, (modifiers & 0x00FFFFFF) | ((0x38 << 24) & 0xFF000000)); - } - else if(!(modifiers & shiftKey) && (mLastModifiers & shiftKey)) - { - if (gDebugWindowProc) printf("Shift key up event\n"); - gKeyboard->handleKeyUp(0x38, (modifiers & 0x00FFFFFF) | ((0x38 << 24) & 0xFF000000)); - } - - if((modifiers & alphaLock) && !(mLastModifiers & alphaLock)) - { - if (gDebugWindowProc) printf("Caps lock down event\n"); - gKeyboard->handleKeyDown(0x39, (modifiers & 0x00FFFFFF) | ((0x39 << 24) & 0xFF000000)); - } - else if(!(modifiers & alphaLock) && (mLastModifiers & alphaLock)) - { - if (gDebugWindowProc) printf("Caps lock up event\n"); - gKeyboard->handleKeyUp(0x39, (modifiers & 0x00FFFFFF) | ((0x39 << 24) & 0xFF000000)); - } - - if((modifiers & controlKey) && !(mLastModifiers & controlKey)) - { - if (gDebugWindowProc) printf("Control key down event\n"); - gKeyboard->handleKeyDown(0x3b, (modifiers & 0x00FFFFFF) | ((0x3b << 24) & 0xFF000000)); - } - else if(!(modifiers & controlKey) && (mLastModifiers & controlKey)) - { - if (gDebugWindowProc) printf("Control key up event\n"); - gKeyboard->handleKeyUp(0x3b, (modifiers & 0x00FFFFFF) | ((0x3b << 24) & 0xFF000000)); - } - - if((modifiers & optionKey) && !(mLastModifiers & optionKey)) - { - if (gDebugWindowProc) printf("Option key down event\n"); - gKeyboard->handleKeyDown(0x3a, (modifiers & 0x00FFFFFF) | ((0x3a << 24) & 0xFF000000)); - } - else if(!(modifiers & optionKey) && (mLastModifiers & optionKey)) - { - if (gDebugWindowProc) printf("Option key up event\n"); - gKeyboard->handleKeyUp(0x3a, (modifiers & 0x00FFFFFF) | ((0x3a << 24) & 0xFF000000)); - } - - // When the state of the 'Fn' key (the one that changes some of the mappings on a powerbook/macbook keyboard - // to an embedded keypad) changes, it may subsequently cause a key up event to be lost, which may lead to - // a movement key getting "stuck" down. This is bad. - // This is an OS bug -- even the GetKeys() API doesn't tell you the key has been released. - // This workaround causes all held-down keys to be reset whenever the state of the Fn key changes. This isn't - // exactly what we want, but it does avoid the case where you get stuck running forward. - if((modifiers & kEventKeyModifierFnMask) != (mLastModifiers & kEventKeyModifierFnMask)) - { - if (gDebugWindowProc) printf("Fn key state change event\n"); - gKeyboard->resetKeys(); - } - - if (gDebugWindowProc) fflush(stdout); - - mLastModifiers = modifiers; - result = eventNotHandledErr; - break; - } - - mRawKeyEvent = NULL; - } - break; - - case kEventClassMouse: - { - result = CallNextEventHandler(myHandler, event); - if (eventNotHandledErr == result) - { // only handle events not already handled (prevents wierd resize interaction) - EventMouseButton button = kEventMouseButtonPrimary; - HIPoint location = {0.0f, 0.0f}; - UInt32 modifiers = 0; - UInt32 clickCount = 1; - long wheelDelta = 0; - LLCoordScreen inCoords; - LLCoordGL outCoords; - MASK mask = 0; - - GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button); - GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(location), NULL, &location); - GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifiers), NULL, &modifiers); - GetEventParameter(event, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(wheelDelta), NULL, &wheelDelta); - GetEventParameter(event, kEventParamClickCount, typeUInt32, NULL, sizeof(clickCount), NULL, &clickCount); - - inCoords.mX = llround(location.x); - inCoords.mY = llround(location.y); - - if(modifiers & shiftKey) { mask |= MASK_SHIFT; } - if(modifiers & controlKey) { mask |= MASK_CONTROL; } - if(modifiers & optionKey) { mask |= MASK_ALT; } - - if(mCursorDecoupled) - { - CGMouseDelta x, y; - - // If the cursor's decoupled, we need to read the latest movement delta as well. - CGGetLastMouseDelta( &x, &y ); - mCursorLastEventDeltaX = x; - mCursorLastEventDeltaY = y; - - if(mCursorIgnoreNextDelta) - { - mCursorLastEventDeltaX = 0; - mCursorLastEventDeltaY = 0; - mCursorIgnoreNextDelta = FALSE; - } - } - else - { - mCursorLastEventDeltaX = 0; - mCursorLastEventDeltaY = 0; - } - - inCoords.mX += mCursorLastEventDeltaX; - inCoords.mY += mCursorLastEventDeltaY; - - convertCoords(inCoords, &outCoords); - - // printf("coords in: %d, %d; coords out: %d, %d\n", inCoords.mX, inCoords.mY, outCoords.mX, outCoords.mY); - // fflush(stdout); - - - switch (evtKind) - { - case kEventMouseDown: - if (mLanguageTextInputAllowed) - { - // We need to interrupt before handling mouse events, - // so that the fixed string from IM are delivered to - // the currently focused UI component. - interruptLanguageTextInput(); - } - switch(button) - { - case kEventMouseButtonPrimary: - if(modifiers & cmdKey) - { - // Simulate a right click - mSimulatedRightClick = true; - mCallbacks->handleRightMouseDown(this, outCoords, mask); - } - else if(clickCount == 2) - { - // Windows double-click events replace the second mousedown event in a double-click. - mCallbacks->handleDoubleClick(this, outCoords, mask); - } - else - { - mCallbacks->handleMouseDown(this, outCoords, mask); - } - break; - case kEventMouseButtonSecondary: - mCallbacks->handleRightMouseDown(this, outCoords, mask); - break; - - case kEventMouseButtonTertiary: - mCallbacks->handleMiddleMouseDown(this, outCoords, mask); - break; - } - result = noErr; - break; - case kEventMouseUp: - - switch(button) - { - case kEventMouseButtonPrimary: - if(mSimulatedRightClick) - { - // End of simulated right click - mSimulatedRightClick = false; - mCallbacks->handleRightMouseUp(this, outCoords, mask); - } - else - { - mCallbacks->handleMouseUp(this, outCoords, mask); - } - break; - case kEventMouseButtonSecondary: - mCallbacks->handleRightMouseUp(this, outCoords, mask); - break; + { + CFIndex index, cnt; - case kEventMouseButtonTertiary: - mCallbacks->handleMiddleMouseUp(this, outCoords, mask); - break; - } - result = noErr; - break; + mSupportedResolutions = new LLWindowResolution[MAX_NUM_RESOLUTIONS]; + mNumSupportedResolutions = 0; - case kEventMouseWheelMoved: - { - static S32 z_delta = 0; + // Examine each mode + cnt = CFArrayGetCount( modes ); - z_delta += wheelDelta; + for ( index = 0; (index < cnt) && (mNumSupportedResolutions < MAX_NUM_RESOLUTIONS); index++ ) + { + // Pull the mode dictionary out of the CFArray + CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex( modes, index ); + long width = getDictLong(mode, kCGDisplayWidth); + long height = getDictLong(mode, kCGDisplayHeight); + long bits = getDictLong(mode, kCGDisplayBitsPerPixel); - if (z_delta <= -WHEEL_DELTA || WHEEL_DELTA <= z_delta) + if(bits == BITS_PER_PIXEL && width >= 800 && height >= 600) + { + BOOL resolution_exists = FALSE; + for(S32 i = 0; i < mNumSupportedResolutions; i++) + { + if (mSupportedResolutions[i].mWidth == width && + mSupportedResolutions[i].mHeight == height) { - mCallbacks->handleScrollWheel(this, -z_delta / WHEEL_DELTA); - z_delta = 0; + resolution_exists = TRUE; } } - result = noErr; - break; - - case kEventMouseDragged: - case kEventMouseMoved: - mCallbacks->handleMouseMove(this, outCoords, mask); - result = noErr; - break; - + if (!resolution_exists) + { + mSupportedResolutions[mNumSupportedResolutions].mWidth = width; + mSupportedResolutions[mNumSupportedResolutions].mHeight = height; + mNumSupportedResolutions++; + } } } } - break; - - case kEventClassWindow: - switch(evtKind) - { - case kEventWindowActivated: - if (mTSMDocument) - { - ActivateTSMDocument(mTSMDocument); - } - mCallbacks->handleFocus(this); - break; - case kEventWindowDeactivated: - if (mTSMDocument) - { - DeactivateTSMDocument(mTSMDocument); - } - mCallbacks->handleFocusLost(this); - break; - - case kEventWindowBoundsChanging: - { - // This is where we would constrain move/resize to a particular screen - - const S32 MIN_WIDTH = mMinWindowWidth; - const S32 MIN_HEIGHT = mMinWindowHeight; - - Rect currentBounds; - Rect previousBounds; - - GetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof(Rect), NULL, ¤tBounds); - GetEventParameter(event, kEventParamPreviousBounds, typeQDRectangle, NULL, sizeof(Rect), NULL, &previousBounds); - - // Put an offset into window un-maximize operation since the kEventWindowGetIdealSize - // event only allows the specification of size and not position. - if (mMaximized) - { - short leftOffset = mPreviousWindowRect.left - currentBounds.left; - currentBounds.left += leftOffset; - currentBounds.right += leftOffset; + } - short topOffset = mPreviousWindowRect.top - currentBounds.top; - currentBounds.top += topOffset; - currentBounds.bottom += topOffset; - } - else - { - // Store off the size for future un-maximize operations - mPreviousWindowRect = previousBounds; - } + num_resolutions = mNumSupportedResolutions; + return mSupportedResolutions; +} - if ((currentBounds.right - currentBounds.left) < MIN_WIDTH) - { - currentBounds.right = currentBounds.left + MIN_WIDTH; - } +BOOL LLWindowMacOSX::convertCoords(LLCoordGL from, LLCoordWindow *to) +{ + S32 client_height; + float client_rect[4]; + getContentViewBounds(mWindow, client_rect); + if (!mWindow || + NULL == to) + { + return FALSE; + } - if ((currentBounds.bottom - currentBounds.top) < MIN_HEIGHT) - { - currentBounds.bottom = currentBounds.top + MIN_HEIGHT; - } + to->mX = from.mX; + client_height = client_rect[3]; + to->mY = from.mY - 1; - SetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, sizeof(Rect), ¤tBounds); - result = noErr; - } - break; + return TRUE; +} - case kEventWindowBoundsChanged: - { - // Get new window bounds - Rect newBounds; - GetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof(Rect), NULL, &newBounds); +BOOL LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordGL* to) +{ + S32 client_height; + float client_rect[4]; + + getContentViewBounds(mWindow, client_rect); + + if (!mWindow || + NULL == to) + { + return FALSE; + } - // Get previous window bounds - Rect oldBounds; - GetEventParameter(event, kEventParamPreviousBounds, typeQDRectangle, NULL, sizeof(Rect), NULL, &oldBounds); + to->mX = from.mX; + client_height = client_rect[3]; + to->mY = from.mY - 1; - // Determine if the new size is larger than the old - bool newBoundsLarger = ((newBounds.right - newBounds.left) >= (oldBounds.right - oldBounds.left)); - newBoundsLarger &= ((newBounds.bottom - newBounds.top) >= (oldBounds.bottom - oldBounds.top)); + return TRUE; +} - // Check to see if this is a zoom event (+ button on window pane) - unsigned int eventParams; - GetEventParameter(event, kEventParamAttributes, typeUInt32, NULL, sizeof(int), NULL, &eventParams); - bool isZoomEvent = ((eventParams & kWindowBoundsChangeZoom) != 0); +BOOL LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordWindow* to) +{ + if(mFullscreen) + { + // In the fullscreen case, window and screen coordinates are the same. + to->mX = from.mX; + to->mY = from.mY; + return TRUE; + } + else if(mWindow) + { + float mouse_point[2]; - // Maximized flag is if zoom event and increasing window size - mMaximized = (isZoomEvent && newBoundsLarger); + mouse_point[0] = from.mX; + mouse_point[1] = from.mY; + + convertScreenToWindow(mWindow, mouse_point); - aglUpdateContext(mContext); + to->mX = mouse_point[0]; + to->mY = mouse_point[1]; - mCallbacks->handleResize(this, newBounds.right - newBounds.left, newBounds.bottom - newBounds.top); - } - break; + return TRUE; + } - case kEventWindowGetIdealSize: - // Only recommend a new ideal size when un-maximizing - if (mMaximized == TRUE) - { - Point nonMaximizedSize; + return FALSE; +} - nonMaximizedSize.v = mPreviousWindowRect.bottom - mPreviousWindowRect.top; - nonMaximizedSize.h = mPreviousWindowRect.right - mPreviousWindowRect.left; +BOOL LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordScreen *to) +{ + if(mFullscreen) + { + // In the fullscreen case, window and screen coordinates are the same. + to->mX = from.mX; + to->mY = from.mY; + return TRUE; + } + else if(mWindow) + { + float mouse_point[2]; - SetEventParameter(event, kEventParamDimensions, typeQDPoint, sizeof(Point), &nonMaximizedSize); - result = noErr; - } - break; + mouse_point[0] = from.mX; + mouse_point[1] = from.mY; + convertWindowToScreen(mWindow, mouse_point); - case kEventWindowClose: - if(mCallbacks->handleCloseRequest(this)) - { - // Get the app to initiate cleanup. - mCallbacks->handleQuit(this); - // The app is responsible for calling destroyWindow when done with GL - } - result = noErr; - break; + to->mX = mouse_point[0]; + to->mY = mouse_point[1]; - case kEventWindowHidden: - // llinfos << "LLWindowMacOSX: Deactivating on hide" << llendl; - mMinimized = TRUE; - mCallbacks->handleActivate(this, false); - // result = noErr; - break; + return TRUE; + } - case kEventWindowShown: - // llinfos << "LLWindowMacOSX: Activating on show" << llendl; - mMinimized = FALSE; - mCallbacks->handleActivate(this, true); - // result = noErr; - break; + return FALSE; +} - case kEventWindowCollapsed: - // llinfos << "LLWindowMacOSX: Deactivating on collapse" << llendl; - mMinimized = TRUE; - mCallbacks->handleActivate(this, false); - // result = noErr; - break; +BOOL LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordGL *to) +{ + LLCoordWindow window_coord; - case kEventWindowExpanded: - // llinfos << "LLWindowMacOSX: Activating on expand" << llendl; - mMinimized = FALSE; - mCallbacks->handleActivate(this, true); - // result = noErr; - break; + return(convertCoords(from, &window_coord) && convertCoords(window_coord, to)); +} - case kEventWindowGetClickActivation: - // BringToFront(mWindow); - // result = noErr; - break; - } - break; +BOOL LLWindowMacOSX::convertCoords(LLCoordGL from, LLCoordScreen *to) +{ + LLCoordWindow window_coord; - case kEventClassTSMDocumentAccess: - if (mPreeditor) - { - switch(evtKind) - { + return(convertCoords(from, &window_coord) && convertCoords(window_coord, to)); +} - case kEventTSMDocumentAccessGetLength: - { - // Return the number of UTF-16 units in the text, excluding those for preedit. - - S32 preedit, preedit_length; - mPreeditor->getPreeditRange(&preedit, &preedit_length); - const LLWString & text = mPreeditor->getPreeditString(); - const CFIndex length = wstring_utf16_length(text, 0, preedit) - + wstring_utf16_length(text, preedit + preedit_length, text.length()); - result = SetEventParameter(event, kEventParamTSMDocAccessCharacterCount, typeCFIndex, sizeof(length), &length); - } - break; - case kEventTSMDocumentAccessGetSelectedRange: - { - // Return the selected range, excluding preedit. - // In our preeditor, preedit and selection are exclusive, so, - // when it has a preedit, there is no selection and the - // insertion point is on the preedit that corrupses into the - // beginning of the preedit when the preedit was removed. - - S32 preedit, preedit_length; - mPreeditor->getPreeditRange(&preedit, &preedit_length); - const LLWString & text = mPreeditor->getPreeditString(); - - CFRange range; - if (preedit_length) - { - range.location = wstring_utf16_length(text, 0, preedit); - range.length = 0; - } - else - { - S32 selection, selection_length; - mPreeditor->getSelectionRange(&selection, &selection_length); - range.location = wstring_utf16_length(text, 0, selection); - range.length = wstring_utf16_length(text, selection, selection_length); - } - result = SetEventParameter(event, kEventParamTSMDocAccessReplyCharacterRange, typeCFRange, sizeof(range), &range); - } - break; - case kEventTSMDocumentAccessGetCharacters: - { - UniChar *target_pointer; - CFRange range; - EventParamType param_type; - if ((result = GetEventParameter(event, kEventParamTSMDocAccessSendCharacterRange, - typeCFRange, ¶m_type, sizeof(range), NULL, &range)) == noErr - && typeCFRange == param_type - && (result = GetEventParameter(event, kEventParamTSMDocAccessSendCharactersPtr, - typePtr, ¶m_type, sizeof(target_pointer), NULL, &target_pointer)) == noErr - && typePtr == param_type) - { - S32 preedit, preedit_length; - mPreeditor->getPreeditRange(&preedit, &preedit_length); - const LLWString & text = mPreeditor->getPreeditString(); - - // The GetCharacters event of TSMDA has a fundamental flaw; - // An input method need to decide the starting offset and length - // *before* it actually see the contents, so it is impossible - // to guarantee the character-aligned access. The event reply - // has no way to indicate a condition something like "Request - // was not fulfilled due to unaligned access. Please retry." - // Any error sent back to the input method stops use of TSMDA - // entirely during the session... - // We need to simulate very strictly the behaviour as if the - // underlying *text engine* holds the contents in UTF-16. - // I guess this is the reason why Apple repeats saying "all - // text handling application should use UTF-16." They are - // trying to _fix_ the flaw by changing the appliations... - // ... or, domination of UTF-16 in the industry may be a part - // of the company vision, and Apple is trying to force third - // party developers to obey their vision. Remember that use - // of 16 bits per _a_character_ was one of the very fundamental - // Unicode design policy on its early days (during late 80s) - // and the original Unicode design was by two Apple employees... - - const llutf16string text_utf16 - = wstring_to_utf16str(text, preedit) - + wstring_to_utf16str(text.substr(preedit + preedit_length)); - - llassert_always(sizeof(U16) == sizeof(UniChar)); - llassert(0 <= range.location && 0 <= range.length && range.location + range.length <= text_utf16.length()); - memcpy(target_pointer, text_utf16.c_str() + range.location, range.length * sizeof(UniChar)); - - // Note that result has already been set above. - } - } - break; +void LLWindowMacOSX::setupFailure(const std::string& text, const std::string& caption, U32 type) +{ + destroyContext(); - } - } - break; - } - return result; + OSMessageBox(text, caption, type); } const char* cursorIDToName(int id) @@ -2876,7 +1397,7 @@ static void initPixmapCursor(int cursorid, int hotspotX, int hotspotY) void LLWindowMacOSX::updateCursor() { - OSStatus result = noErr; + S32 result = 0; if (mDragOverrideCursor != -1) { @@ -2913,7 +1434,7 @@ void LLWindowMacOSX::updateCursor() if(mCursorHidden) { // Since InitCursor resets the hide level, correct for it here. - ::HideCursor(); + hideNSCursor(); } break; @@ -2921,12 +1442,12 @@ void LLWindowMacOSX::updateCursor() // Find out what they look like and replicate them. // These are essentially correct - case UI_CURSOR_WAIT: SetThemeCursor(kThemeWatchCursor); break; - case UI_CURSOR_IBEAM: SetThemeCursor(kThemeIBeamCursor); break; - case UI_CURSOR_CROSS: SetThemeCursor(kThemeCrossCursor); break; - case UI_CURSOR_HAND: SetThemeCursor(kThemePointingHandCursor); break; + case UI_CURSOR_WAIT: /* Apple purposely doesn't allow us to set the beachball cursor manually. */ break; + case UI_CURSOR_IBEAM: setIBeamCursor(); break; + case UI_CURSOR_CROSS: setCrossCursor(); break; + case UI_CURSOR_HAND: setPointingHandCursor(); break; // case UI_CURSOR_NO: SetThemeCursor(kThemeNotAllowedCursor); break; - case UI_CURSOR_ARROWCOPY: SetThemeCursor(kThemeCopyArrowCursor); break; + case UI_CURSOR_ARROWCOPY: setCopyCursor(); break; // Double-check these case UI_CURSOR_NO: @@ -3039,7 +1560,7 @@ void LLWindowMacOSX::hideCursor() // llinfos << "hideCursor: hiding" << llendl; mCursorHidden = TRUE; mHideCursorPermanent = TRUE; - ::HideCursor(); + hideNSCursor(); } else { @@ -3056,7 +1577,7 @@ void LLWindowMacOSX::showCursor() // llinfos << "showCursor: showing" << llendl; mCursorHidden = FALSE; mHideCursorPermanent = FALSE; - ::ShowCursor(); + showNSCursor(); } else { @@ -3102,7 +1623,7 @@ void LLSplashScreenMacOSX::showImpl() // This code _could_ be used to display a spash screen... #if 0 IBNibRef nib = NULL; - OSStatus err; + S32 err; err = CreateNibReference(CFSTR("SecondLife"), &nib); @@ -3127,25 +1648,6 @@ void LLSplashScreenMacOSX::updateImpl(const std::string& mesg) CFStringRef string = NULL; string = CFStringCreateWithCString(NULL, mesg.c_str(), kCFStringEncodingUTF8); - - if(string != NULL) - { - ControlRef progressText = NULL; - ControlID id; - OSStatus err; - - id.signature = 'what'; - id.id = 0; - - err = GetControlByID(mWindow, &id, &progressText); - if(err == noErr) - { - err = SetControlData(progressText, kControlEntireControl, kControlStaticTextCFStringTag, sizeof(CFStringRef), (Ptr)&string); - Draw1Control(progressText); - } - - CFRelease(string); - } } } @@ -3154,7 +1656,6 @@ void LLSplashScreenMacOSX::hideImpl() { if(mWindow != NULL) { - DisposeWindow(mWindow); mWindow = NULL; } } @@ -3163,102 +1664,16 @@ void LLSplashScreenMacOSX::hideImpl() S32 OSMessageBoxMacOSX(const std::string& text, const std::string& caption, U32 type) { - S32 result = OSBTN_CANCEL; - SInt16 retval_mac = 1; - AlertStdCFStringAlertParamRec params; - CFStringRef errorString = NULL; - CFStringRef explanationString = NULL; - DialogRef alert = NULL; - AlertType alertType = kAlertCautionAlert; - OSStatus err; - - explanationString = CFStringCreateWithCString(NULL, text.c_str(), kCFStringEncodingUTF8); - errorString = CFStringCreateWithCString(NULL, caption.c_str(), kCFStringEncodingUTF8); - - params.version = kStdCFStringAlertVersionOne; - params.movable = false; - params.helpButton = false; - params.defaultText = (CFStringRef)kAlertDefaultOKText; - params.cancelText = 0; - params.otherText = 0; - params.defaultButton = 1; - params.cancelButton = 0; - params.position = kWindowDefaultPosition; - params.flags = 0; - - switch(type) - { - case OSMB_OK: - default: - break; - case OSMB_OKCANCEL: - params.cancelText = (CFStringRef)kAlertDefaultCancelText; - params.cancelButton = 2; - break; - case OSMB_YESNO: - alertType = kAlertNoteAlert; - params.defaultText = CFSTR("Yes"); - params.cancelText = CFSTR("No"); - params.cancelButton = 2; - break; - } - - if(gWindowImplementation != NULL) - gWindowImplementation->beforeDialog(); - - err = CreateStandardAlert( - alertType, - errorString, - explanationString, - ¶ms, - &alert); - - if(err == noErr) - { - err = RunStandardAlert( - alert, - NULL, - &retval_mac); - } - - if(gWindowImplementation != NULL) - gWindowImplementation->afterDialog(); - - switch(type) - { - case OSMB_OK: - case OSMB_OKCANCEL: - default: - if(retval_mac == 1) - result = OSBTN_OK; - else - result = OSBTN_CANCEL; - break; - case OSMB_YESNO: - if(retval_mac == 1) - result = OSBTN_YES; - else - result = OSBTN_NO; - break; - } - - if(errorString != NULL) - { - CFRelease(errorString); - } - - if(explanationString != NULL) - { - CFRelease(explanationString); - } - - return result; + // TODO: Implement a native NSAlert function that replicates all of this. + return 0; } // Open a URL with the user's default web browser. // Must begin with protocol identifier. void LLWindowMacOSX::spawnWebBrowser(const std::string& escaped_url, bool async) { + // I'm fairly certain that this is all legitimate under Apple's currently supported APIs. + bool found = false; S32 i; for (i = 0; i < gURLProtocolWhitelistCount; i++) @@ -3276,7 +1691,7 @@ void LLWindowMacOSX::spawnWebBrowser(const std::string& escaped_url, bool async) return; } - OSStatus result = noErr; + S32 result = 0; CFURLRef urlRef = NULL; llinfos << "Opening URL " << escaped_url << llendl; @@ -3313,7 +1728,7 @@ void LLWindowMacOSX::spawnWebBrowser(const std::string& escaped_url, bool async) LLSD LLWindowMacOSX::getNativeKeyData() { LLSD result = LLSD::emptyMap(); - +#if 0 if(mRawKeyEvent) { char char_code = 0; @@ -3335,7 +1750,7 @@ LLSD LLWindowMacOSX::getNativeKeyData() // This causes trouble for control characters -- apparently character codes less than 32 (escape, control-A, etc) // cause llsd serialization to create XML that the llsd deserializer won't parse! std::string unicode; - OSStatus err = noErr; + S32 err = noErr; EventParamType actualType = typeUTF8Text; UInt32 actualSize = 0; char *buffer = NULL; @@ -3357,7 +1772,7 @@ LLSD LLWindowMacOSX::getNativeKeyData() #endif } - +#endif lldebugs << "native key data is: " << result << llendl; @@ -3367,34 +1782,9 @@ LLSD LLWindowMacOSX::getNativeKeyData() BOOL LLWindowMacOSX::dialogColorPicker( F32 *r, F32 *g, F32 *b) { + // Is this even used anywhere? Do we really need an OS color picker? BOOL retval = FALSE; - OSErr error = noErr; - NColorPickerInfo info; - - memset(&info, 0, sizeof(info)); - info.theColor.color.rgb.red = (UInt16)(*r * 65535.f); - info.theColor.color.rgb.green = (UInt16)(*g * 65535.f); - info.theColor.color.rgb.blue = (UInt16)(*b * 65535.f); - info.placeWhere = kCenterOnMainScreen; - - if(gWindowImplementation != NULL) - gWindowImplementation->beforeDialog(); - - error = NPickColor(&info); - - if(gWindowImplementation != NULL) - gWindowImplementation->afterDialog(); - - if (error == noErr) - { - retval = info.newColorChosen; - if (info.newColorChosen) - { - *r = ((float) info.theColor.color.rgb.red) / 65535.0; - *g = ((float) info.theColor.color.rgb.green) / 65535.0; - *b = ((float) info.theColor.color.rgb.blue) / 65535.0; - } - } + //S32 error = 0; return (retval); } @@ -3405,44 +1795,13 @@ void *LLWindowMacOSX::getPlatformWindow() return (void*)mWindow; } -void *LLWindowMacOSX::getMediaWindow() -{ - /* - Mozilla needs to be initialized with a WindowRef to function properly. - (There's no good reason for this, since it shouldn't be interacting with our window in any way, but that's another issue.) - If we're in windowed mode, we _could_ hand it our actual window pointer, but a subsequent switch to fullscreen will destroy that window, - which trips up Mozilla. - Instead of using our actual window, we create an invisible window which will persist for the lifetime of the application and pass that to Mozilla. - This satisfies its deep-seated need to latch onto a WindowRef and solves the issue with switching between fullscreen and windowed modes. - - Note that we will never destroy this window (by design!), but since only one will ever be created per run of the application, that's okay. - */ - - if(sMediaWindow == NULL) - { - Rect window_rect = {100, 100, 200, 200}; - - sMediaWindow = NewCWindow( - NULL, - &window_rect, - (ConstStr255Param) "\p", - false, // Create the window invisible. - zoomDocProc, // Window with a grow box and a zoom box - kLastWindowOfClass, // create it behind other windows - false, // no close box - 0); - } - - return (void*)sMediaWindow; -} - void LLWindowMacOSX::stopDockTileBounce() { - NMRemove(&mBounceRec); mBounceTimer.stop(); } // get a double value from a dictionary +/* static double getDictDouble (CFDictionaryRef refDict, CFStringRef key) { double double_value; @@ -3452,7 +1811,7 @@ static double getDictDouble (CFDictionaryRef refDict, CFStringRef key) if (!CFNumberGetValue(number_value, kCFNumberDoubleType, &double_value)) // or if cant convert it return -1; // fail return double_value; // otherwise return the long value -} +}*/ // get a long value from a dictionary static long getDictLong (CFDictionaryRef refDict, CFStringRef key) @@ -3468,71 +1827,12 @@ static long getDictLong (CFDictionaryRef refDict, CFStringRef key) void LLWindowMacOSX::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) { - ScriptLanguageRecord script_language; - - if (preeditor != mPreeditor && !b) - { - // This condition may occur by a call to - // setEnabled(BOOL) against LLTextEditor or LLLineEditor - // when the control is not focused. - // We need to silently ignore the case so that - // the language input status of the focused control - // is not disturbed. - return; - } - - UseInputWindow(mTSMDocument, !b); - - // Take care of old and new preeditors. - if (preeditor != mPreeditor || !b) - { - // We need to interrupt before updating mPreeditor, - // so that the fix string from input method goes to - // the old preeditor. - if (mLanguageTextInputAllowed) - { - interruptLanguageTextInput(); - } - mPreeditor = (b ? preeditor : NULL); - } - - if (b == mLanguageTextInputAllowed) - { - return; - } - mLanguageTextInputAllowed = b; - - if (b) - { - if (mTSMScriptCode != smRoman) - { - script_language.fScript = mTSMScriptCode; - script_language.fLanguage = mTSMLangCode; - SetTextServiceLanguage(&script_language); - } - } - else - { - GetTextServiceLanguage(&script_language); - mTSMScriptCode = script_language.fScript; - mTSMLangCode = script_language.fLanguage; - if (mTSMScriptCode != smRoman) - { - script_language.fScript = smRoman; - script_language.fLanguage = langEnglish; - SetTextServiceLanguage(&script_language); - } - } + // TODO: IME support } void LLWindowMacOSX::interruptLanguageTextInput() { - if (mTSMDocument) - { - FixTSMDocument(mTSMDocument); - } - // Don't we need to call resetPreedit here? - // Well, if Apple's TSM document is correct, we don't. + // TODO: IME support } //static @@ -3543,21 +1843,21 @@ std::vector LLWindowMacOSX::getDynamicFallbackFontList() } // static -MASK LLWindowMacOSX::modifiersToMask(SInt16 modifiers) +MASK LLWindowMacOSX::modifiersToMask(S16 modifiers) { MASK mask = 0; - if(modifiers & shiftKey) { mask |= MASK_SHIFT; } - if(modifiers & (cmdKey | controlKey)) { mask |= MASK_CONTROL; } - if(modifiers & optionKey) { mask |= MASK_ALT; } + if(modifiers & MAC_SHIFT_KEY) { mask |= MASK_SHIFT; } + if(modifiers & (MAC_CMD_KEY | MAC_CTRL_KEY)) { mask |= MASK_CONTROL; } + if(modifiers & MAC_ALT_KEY) { mask |= MASK_ALT; } return mask; } #if LL_OS_DRAGDROP_ENABLED - -OSErr LLWindowMacOSX::dragTrackingHandler(DragTrackingMessage message, WindowRef theWindow, +/* +S16 LLWindowMacOSX::dragTrackingHandler(DragTrackingMessage message, WindowRef theWindow, void * handlerRefCon, DragRef drag) { - OSErr result = noErr; + S16 result = 0; LLWindowMacOSX *self = (LLWindowMacOSX*)handlerRefCon; lldebugs << "drag tracking handler, message = " << message << llendl; @@ -3711,5 +2011,5 @@ OSErr LLWindowMacOSX::handleDragNDrop(DragRef drag, LLWindowCallbacks::DragNDrop return result; } - +*/ #endif // LL_OS_DRAGDROP_ENABLED diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h index af83b50097..a821dcabd8 100644 --- a/indra/llwindow/llwindowmacosx.h +++ b/indra/llwindow/llwindowmacosx.h @@ -29,11 +29,14 @@ #include "llwindow.h" #include "llwindowcallbacks.h" +#include "llwindowmacosx-objc.h" #include "lltimer.h" -#include -#include +//#include +//#include +#include +#include // AssertMacros.h does bad things. #include "fix_macros.h" @@ -106,7 +109,6 @@ public: /*virtual*/ BOOL dialogColorPicker(F32 *r, F32 *g, F32 *b); /*virtual*/ void *getPlatformWindow(); - /*virtual*/ void *getMediaWindow(); /*virtual*/ void bringToFront() {}; /*virtual*/ void allowLanguageTextInput(LLPreeditor *preeditor, BOOL b); @@ -117,6 +119,12 @@ public: // Provide native key event data /*virtual*/ LLSD getNativeKeyData(); + + void* getWindow() { return mWindow; } + LLWindowCallbacks* getCallbacks() { return mCallbacks; } + + void updateMouseDeltas(); + void getMouseDeltas(float* delta); protected: @@ -153,40 +161,35 @@ protected: BOOL createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync); void destroyContext(); void setupFailure(const std::string& text, const std::string& caption, U32 type); - static pascal OSStatus staticEventHandler (EventHandlerCallRef myHandler, EventRef event, void* userData); - static pascal Boolean staticMoveEventComparator( EventRef event, void* data); - OSStatus eventHandler (EventHandlerCallRef myHandler, EventRef event); void adjustCursorDecouple(bool warpingMouse = false); void stopDockTileBounce(); - static MASK modifiersToMask(SInt16 modifiers); + static MASK modifiersToMask(S16 modifiers); #if LL_OS_DRAGDROP_ENABLED + /* static OSErr dragTrackingHandler(DragTrackingMessage message, WindowRef theWindow, void * handlerRefCon, DragRef theDrag); static OSErr dragReceiveHandler(WindowRef theWindow, void * handlerRefCon, DragRef theDrag); OSErr handleDragNDrop(DragRef theDrag, LLWindowCallbacks::DragNDropAction action); + */ #endif // LL_OS_DRAGDROP_ENABLED // // Platform specific variables // - WindowRef mWindow; - AGLContext mContext; - AGLPixelFormat mPixelFormat; + + // Use generic pointers here. This lets us do some funky Obj-C interop using Obj-C objects without having to worry about any compilation problems that may arise. + NSWindowRef mWindow; + GLViewRef mGLView; + CGLContextObj mContext; + CGLPixelFormatObj mPixelFormat; CGDirectDisplayID mDisplay; - CFDictionaryRef mOldDisplayMode; - EventLoopTimerRef mTimer; - EventHandlerUPP mEventHandlerUPP; - EventHandlerRef mGlobalHandlerRef; - EventHandlerRef mWindowHandlerRef; - EventComparatorUPP mMoveEventCampartorUPP; - Rect mOldMouseClip; // Screen rect to which the mouse cursor was globally constrained before we changed it in clipMouse() - Rect mPreviousWindowRect; // Save previous window for un-maximize event - Str255 mWindowTitle; + LLRect mOldMouseClip; // Screen rect to which the mouse cursor was globally constrained before we changed it in clipMouse() + std::string mWindowTitle; double mOriginalAspectRatio; BOOL mSimulatedRightClick; - UInt32 mLastModifiers; + U32 mLastModifiers; BOOL mHandsOffEvents; // When true, temporarially disable CarbonEvent processing. // Used to allow event processing when putting up dialogs in fullscreen mode. BOOL mCursorDecoupled; @@ -204,22 +207,17 @@ protected: S32 mDragOverrideCursor; F32 mBounceTime; - NMRec mBounceRec; + //NMRec mBounceRec; LLTimer mBounceTimer; // Input method management through Text Service Manager. - TSMDocumentID mTSMDocument; BOOL mLanguageTextInputAllowed; - ScriptCode mTSMScriptCode; - LangCode mTSMLangCode; LLPreeditor* mPreeditor; static BOOL sUseMultGL; friend class LLWindowManager; - static WindowRef sMediaWindow; - EventRef mRawKeyEvent; - + }; diff --git a/indra/newview/llviewerkeyboard.cpp b/indra/newview/llviewerkeyboard.cpp index 1aa9fd8a45..6d91dad70e 100644 --- a/indra/newview/llviewerkeyboard.cpp +++ b/indra/newview/llviewerkeyboard.cpp @@ -653,6 +653,8 @@ BOOL LLViewerKeyboard::modeFromString(const std::string& string, S32 *mode) BOOL LLViewerKeyboard::handleKey(KEY translated_key, MASK translated_mask, BOOL repeated) { + LL_INFOS("Keyboard Handling") << "Handling key " << translated_key << LL_ENDL; + LL_INFOS("Keyboard Handling") << "Keyboard has focus? " << gFocusMgr.getKeyboardFocus() << LL_ENDL; // check for re-map EKeyboardMode mode = gViewerKeyboard.getMode(); U32 keyidx = (translated_mask<<16) | translated_key; diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index 1def2db829..7c0d49d1e2 100755 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -2428,6 +2428,7 @@ void LLViewerWindow::draw() // Takes a single keydown event, usually when UI is visible BOOL LLViewerWindow::handleKey(KEY key, MASK mask) { + LL_INFOS("Keyboard Handling") << "Handling key " << key << LL_ENDL; // hide tooltips on keypress LLToolTipMgr::instance().blockToolTips(); -- cgit v1.2.3 From bd152c1fb75c4a8d4b9271896c44243ca8759e58 Mon Sep 17 00:00:00 2001 From: Geenz Date: Sat, 29 Dec 2012 06:59:43 -0500 Subject: Huge amount of refactoring to use Cocoa here: - Updated to .xib format. To produce a new nib (which is required after changing the xib file), use "ibtool SecondLife.xib --compile SecondLife.nib" within the newview directory. - xib file now defines the viewer's window. VIews are still being pragmatically added to the main window. This may change in the future. - LLAppViewer's main loop has been slightly refactored to be executed on a timer for OS X. This probably needs a bit more work. - Event handling still needs more work to work within a timer based event loop. It works fairly sporadically at the moment, as if events are being dropped between timer executions, at least for the mouse. - Carbon has been purged from the viewer's startup, and from LLWindow entirely. There's likely still a few odds and ends fragmented throughout the viewer and its dependencies. Need to track these down. - LLAppViewerMacOSX now uses NSApplicationMain, and also implements the NSApplicationDelegate protocol in LLAppDelegate. - Fullscreen support has been implemented for OS X 10.7+ This is still a work in progress, however at this stage everything needed for a functional viewer is (mostly) complete. From here, it's mostly just bug hunting and fixing. --- indra/llwindow/llopenglview-objc.h | 7 +- indra/llwindow/llopenglview-objc.mm | 140 +- indra/llwindow/llwindowmacosx-objc.h | 4 +- indra/llwindow/llwindowmacosx-objc.mm | 19 +- indra/llwindow/llwindowmacosx.cpp | 133 +- indra/llwindow/llwindowmacosx.h | 2 - indra/media_plugins/webkit/mac_volume_catcher.cpp | 1 - indra/newview/CMakeLists.txt | 6 +- indra/newview/Info-SecondLife.plist | 4 + indra/newview/SecondLife.nib/classes.nib | 4 - indra/newview/SecondLife.nib/info.nib | 23 - indra/newview/SecondLife.nib/objects.xib | 259 --- indra/newview/SecondLife.xib | 1848 +++++++++++++++++++++ indra/newview/llappviewer.cpp | 118 +- indra/newview/llappviewer.h | 3 + indra/newview/llappviewermacosx-delegate.h | 24 + indra/newview/llappviewermacosx-delegate.mm | 49 + indra/newview/llappviewermacosx-objc.h | 19 + indra/newview/llappviewermacosx-objc.mm | 20 + indra/newview/llappviewermacosx.cpp | 234 +-- indra/newview/macutil_Prefix.h | 1 - 21 files changed, 2195 insertions(+), 723 deletions(-) delete mode 100644 indra/newview/SecondLife.nib/classes.nib delete mode 100644 indra/newview/SecondLife.nib/info.nib delete mode 100644 indra/newview/SecondLife.nib/objects.xib create mode 100644 indra/newview/SecondLife.xib create mode 100644 indra/newview/llappviewermacosx-delegate.h create mode 100644 indra/newview/llappviewermacosx-delegate.mm create mode 100644 indra/newview/llappviewermacosx-objc.h create mode 100644 indra/newview/llappviewermacosx-objc.mm diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 8abe81ce9e..6b055bc665 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -69,4 +69,9 @@ - (void) registerMouseExitCallback:(VoidCallback)callback; - (void) registerDeltaUpdateCallback:(MouseCallback)callback; -@end \ No newline at end of file +@end + +void setLLNSWindowRef(LLNSWindow* window); +void setLLOpenGLViewRef(LLOpenGLView* view); +LLNSWindow* winRef; +LLOpenGLView* glviewRef; diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index a96c4cf82c..7c148f4acd 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -19,9 +19,12 @@ - (void)windowResized:(NSNotification *)notification; { - NSSize size = [[self window] frame].size; - - mResizeCallback(size.width, size.height); + if (mResizeCallback != nil) + { + NSSize size = [[self window] frame].size; + + mResizeCallback(size.width, size.height); + } } - (void)dealloc @@ -194,23 +197,29 @@ } - (void) keyDown:(NSEvent *)theEvent { - mKeyDownCallback([theEvent keyCode], [theEvent modifierFlags]); - - NSString *chars = [theEvent charactersIgnoringModifiers]; - for (uint i = 0; i < [chars length]; i++) + if (mKeyDownCallback != nil && mUnicodeCallback != nil) { - mUnicodeCallback([chars characterAtIndex:i], [theEvent modifierFlags]); - } - - // The viewer expects return to be submitted separately as a unicode character. - if ([theEvent keyCode] == 3 || [theEvent keyCode] == 13) - { - mUnicodeCallback([theEvent keyCode], [theEvent modifierFlags]); + mKeyDownCallback([theEvent keyCode], [theEvent modifierFlags]); + + NSString *chars = [theEvent charactersIgnoringModifiers]; + for (uint i = 0; i < [chars length]; i++) + { + mUnicodeCallback([chars characterAtIndex:i], [theEvent modifierFlags]); + } + + // The viewer expects return to be submitted separately as a unicode character. + if ([theEvent keyCode] == 3 || [theEvent keyCode] == 13) + { + mUnicodeCallback([theEvent keyCode], [theEvent modifierFlags]); + } } } - (void) keyUp:(NSEvent *)theEvent { - mKeyUpCallback([theEvent keyCode], [theEvent modifierFlags]); + if (mKeyUpCallback != nil) + { + mKeyUpCallback([theEvent keyCode], [theEvent modifierFlags]); + } } - (void)flagsChanged:(NSEvent *)theEvent { @@ -219,41 +228,59 @@ - (void) mouseDown:(NSEvent *)theEvent { - if ([theEvent clickCount] == 2) + if (mMouseDoubleClickCallback != nil && mMouseDownCallback != nil) { - mMouseDoubleClickCallback(mMousePos, [theEvent modifierFlags]); - } else if ([theEvent clickCount] == 1) { - mMouseDownCallback(mMousePos, [theEvent modifierFlags]); + if ([theEvent clickCount] == 2) + { + mMouseDoubleClickCallback(mMousePos, [theEvent modifierFlags]); + } else if ([theEvent clickCount] == 1) { + mMouseDownCallback(mMousePos, [theEvent modifierFlags]); + } } } - (void) mouseUp:(NSEvent *)theEvent { - mMouseUpCallback(mMousePos, [theEvent modifierFlags]); + if (mMouseUpCallback != nil) + { + mMouseUpCallback(mMousePos, [theEvent modifierFlags]); + } } - (void) rightMouseDown:(NSEvent *)theEvent { - mRightMouseDownCallback(mMousePos, [theEvent modifierFlags]); + if (mRightMouseDownCallback != nil) + { + mRightMouseDownCallback(mMousePos, [theEvent modifierFlags]); + } } - (void) rightMouseUp:(NSEvent *)theEvent { - mRightMouseUpCallback(mMousePos, [theEvent modifierFlags]); + if (mRightMouseUpCallback != nil) + { + mRightMouseUpCallback(mMousePos, [theEvent modifierFlags]); + } } - (void)mouseMoved:(NSEvent *)theEvent { - float mouseDeltas[2] = { - [theEvent deltaX], - [theEvent deltaZ] - }; - - mDeltaUpdateCallback(mouseDeltas, 0); - - NSPoint mPoint = [theEvent locationInWindow]; - mMousePos[0] = mPoint.x; - mMousePos[1] = mPoint.y; - mMouseMovedCallback(mMousePos, 0); + if (mDeltaUpdateCallback != nil && mMouseMovedCallback != nil) + { + float mouseDeltas[2] = { + [theEvent deltaX], + [theEvent deltaZ] + }; + + mDeltaUpdateCallback(mouseDeltas, 0); + + NSPoint mPoint = [theEvent locationInWindow]; + mMousePos[0] = mPoint.x; + mMousePos[1] = mPoint.y; + if (mMouseMovedCallback != nil) + { + mMouseMovedCallback(mMousePos, 0); + } + } } // NSWindow doesn't trigger mouseMoved when the mouse is being clicked and dragged. @@ -261,27 +288,36 @@ - (void) mouseDragged:(NSEvent *)theEvent { - float mouseDeltas[2] = { - [theEvent deltaX], - [theEvent deltaZ] - }; - - mDeltaUpdateCallback(mouseDeltas, 0); - - NSPoint mPoint = [theEvent locationInWindow]; - mMousePos[0] = mPoint.x; - mMousePos[1] = mPoint.y; - mMouseMovedCallback(mMousePos, 0); + if (mDeltaUpdateCallback != nil && mMouseMovedCallback != nil) + { + float mouseDeltas[2] = { + [theEvent deltaX], + [theEvent deltaZ] + }; + + mDeltaUpdateCallback(mouseDeltas, 0); + + NSPoint mPoint = [theEvent locationInWindow]; + mMousePos[0] = mPoint.x; + mMousePos[1] = mPoint.y; + mMouseMovedCallback(mMousePos, 0); + } } - (void) scrollWheel:(NSEvent *)theEvent { - mScrollWhellCallback(-[theEvent deltaY]); + if (mScrollWhellCallback != nil) + { + mScrollWhellCallback(-[theEvent deltaY]); + } } - (void) mouseExited:(NSEvent *)theEvent { - mMouseExitCallback(); + if (mMouseExitCallback != nil) + { + mMouseExitCallback(); + } } - (void) registerKeyDownCallback:(KeyCallback)callback @@ -349,4 +385,14 @@ mDeltaUpdateCallback = callback; } -@end \ No newline at end of file +@end + +void setLLNSWindowRef(LLNSWindow* window) +{ + winRef = window; +} + +void setLLOpenGLViewRef(LLOpenGLView* view) +{ + glviewRef = view; +} diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 47ae13cb25..abaeda1f91 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -57,7 +57,7 @@ NSWindowRef createNSWindow(int x, int y, int width, int height); #include GLViewRef createOpenGLView(NSWindowRef window); void glSwapBuffers(void* context); -CGLContextObj getCGLContextObj(NSWindowRef window); +CGLContextObj getCGLContextObj(GLViewRef view); void getContentViewBounds(NSWindowRef window, float* bounds); void getWindowSize(NSWindowRef window, float* size); void setWindowSize(NSWindowRef window, int width, int height); @@ -80,5 +80,7 @@ void registerMouseMovedCallback(NSWindowRef window, MouseCallback callback); void registerScrollCallback(NSWindowRef window, ScrollWheelCallback callback); void registerMouseExitCallback(NSWindowRef window, VoidCallback callback); void registerDeltaUpdateCallback(NSWindowRef window, MouseCallback callback); +NSWindowRef getMainAppWindow(); +GLViewRef getGLView(NSWindowRef window); unsigned int getModifiers(); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 03c0f55883..07efc25ea6 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -54,10 +54,10 @@ void setupCocoa() // http://developer.apple.com/samplecode/CarbonCocoa_PictureCursor/index.html // Needed for Carbon based applications which call into Cocoa - NSApplicationLoad(); + // NSApplicationLoad(); // Must first call [[[NSWindow alloc] init] release] to get the NSWindow machinery set up so that NSCursor can use a window to cache the cursor image - [[[NSWindow alloc] init] release]; + //[[[NSWindow alloc] init] release]; [pool release]; @@ -188,10 +188,9 @@ void glSwapBuffers(void* context) [(NSOpenGLContext*)context flushBuffer]; } -CGLContextObj getCGLContextObj(NSWindowRef window) +CGLContextObj getCGLContextObj(GLViewRef view) { - LLOpenGLView *glview = [(LLNSWindow*)window contentView]; - return [glview getCGLContextObj]; + return [(LLOpenGLView *)view getCGLContextObj]; } CGLPixelFormatObj* getCGLPixelFormatObj(NSWindowRef window) @@ -331,6 +330,16 @@ void registerDeltaUpdateCallback(NSWindowRef window, MouseCallback callback) [(LLNSWindow*)window registerDeltaUpdateCallback:callback]; } +NSWindowRef getMainAppWindow() +{ + return winRef; +} + +GLViewRef getGLView(NSWindowRef window) +{ + return glviewRef; +} + unsigned int getModifiers() { return [NSEvent modifierFlags]; diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 1fb8bea802..a616b2df2d 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -38,7 +38,6 @@ #include "lldir.h" #include "indra_constants.h" -#include #include extern BOOL gDebugWindowProc; @@ -342,7 +341,7 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits if (mWindow == NULL) { LL_INFOS("Window") << "Creating window..." << LL_ENDL; - mWindow = createNSWindow(x, y, width, height); + mWindow = getMainAppWindow(); LL_INFOS("Window") << "Registering key callbacks..." << LL_ENDL; registerKeyDownCallback(mWindow, callKeyDown); registerKeyUpCallback(mWindow, callKeyUp); @@ -361,9 +360,11 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits if(mContext == NULL) { LL_INFOS("Window") << "Creating GL view..." << LL_ENDL; + // Our OpenGL view is already defined within SecondLife.xib. + // Get the view instead. mGLView = createOpenGLView(mWindow); registerResizeEventCallback(mGLView, callResize); - mContext = getCGLContextObj(mWindow); + mContext = getCGLContextObj(mGLView); // Since we just created the context, it needs to be set up. glNeedsInit = TRUE; } @@ -577,132 +578,6 @@ void LLWindowMacOSX::gatherInput() stopDockTileBounce(); } - EventRecord evt; - while(WaitNextEvent(everyEvent, &evt, 0, NULL)) - { - // printf("WaitNextEvent returned true, event is %d.\n", evt.what); - switch(evt.what) - { - case mouseDown: - { - short part; - WindowRef window; - long selectResult; - part = FindWindow(evt.where, &window); - switch ( part ) - { - case inMenuBar: - selectResult = MenuSelect(evt.where); - - HiliteMenu(0); - break; - } - } - break; - - case kHighLevelEvent: - AEProcessAppleEvent (&evt); - break; - - case updateEvt: - // We shouldn't be getting these regularly (since our window will be buffered), but we need to handle them correctly... - BeginUpdate((WindowRef)evt.message); - EndUpdate((WindowRef)evt.message); - break; - - } - } - /* - U32 event = getLatestEvent(mWindow); - switch (event) { - case 0: - // Nothing's happened since our last handled event. - break; - - case 1: - { - gKeyboard->handleKeyDown(getKeyDown(mWindow), getModifiers(mWindow)); - mCallbacks->handleUnicodeChar(getLastCharacter(mWindow), gKeyboard->currentMask(FALSE)); // currentMask has the appropriately translated modifiers. - mLastModifiers = gKeyboard->currentMask(FALSE); - } - break; - - case 2: - gKeyboard->handleKeyUp(getKeyUp(mWindow), getModifiers(mWindow)); - mLastModifiers = gKeyboard->currentMask(FALSE); - break; - - case 3: - break; - - case 4: - { - LLCoordScreen inCoords; - LLCoordGL outCoords; - float* mouseCoords = getMouseDown(mWindow); - inCoords.mX = llround(mouseCoords[0]); - inCoords.mY = llround(mouseCoords[1]); - convertCoords(inCoords, &outCoords); - mCallbacks->handleMouseDown(this, outCoords, getModifiers(mWindow)); - mLastModifiers = gKeyboard->currentMask(FALSE); - } - break; - case 5: - { - LLCoordScreen inCoords; - LLCoordGL outCoords; - float* mouseCoords = getMouseUp(mWindow); - inCoords.mX = llround(mouseCoords[0]); - inCoords.mY = llround(mouseCoords[1]); - convertCoords(inCoords, &outCoords); - mCallbacks->handleMouseUp(this, outCoords, getModifiers(mWindow)); - mLastModifiers = gKeyboard->currentMask(FALSE); - } - break; - case 6: - { - LLCoordScreen inCoords; - LLCoordGL outCoords; - float* mouseCoords = getRightMouseDown(mWindow); - inCoords.mX = llround(mouseCoords[0]); - inCoords.mY = llround(mouseCoords[1]); - convertCoords(inCoords, &outCoords); - mCallbacks->handleRightMouseDown(this, outCoords, getModifiers(mWindow)); - mLastModifiers = gKeyboard->currentMask(FALSE); - } - break; - case 7: - { - LLCoordScreen inCoords; - LLCoordGL outCoords; - float* mouseCoords = getRightMouseDown(mWindow); - inCoords.mX = llround(mouseCoords[0]); - inCoords.mY = llround(mouseCoords[1]); - convertCoords(inCoords, &outCoords); - mCallbacks->handleRightMouseDown(this, outCoords, getModifiers(mWindow)); - mLastModifiers = gKeyboard->currentMask(FALSE); - } - break; - case 8: // Double click - { - LLCoordScreen inCoords; - LLCoordGL outCoords; - float* mouseCoords = getRightMouseDown(mWindow); - inCoords.mX = llround(mouseCoords[0]); - inCoords.mY = llround(mouseCoords[1]); - convertCoords(inCoords, &outCoords); - mCallbacks->handleDoubleClick(this, outCoords, getModifiers(mWindow)); - mLastModifiers = gKeyboard->currentMask(FALSE); - } - break; - case 10: // Text input (for IMEs) - - break; - default: - break; - - }*/ - updateCursor(); } diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h index a821dcabd8..487af7658f 100644 --- a/indra/llwindow/llwindowmacosx.h +++ b/indra/llwindow/llwindowmacosx.h @@ -33,8 +33,6 @@ #include "lltimer.h" -//#include -//#include #include #include diff --git a/indra/media_plugins/webkit/mac_volume_catcher.cpp b/indra/media_plugins/webkit/mac_volume_catcher.cpp index 8a06bb8487..2f3f2211a3 100644 --- a/indra/media_plugins/webkit/mac_volume_catcher.cpp +++ b/indra/media_plugins/webkit/mac_volume_catcher.cpp @@ -35,7 +35,6 @@ #include "volume_catcher.h" -#include #include #include diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index dff2c04fbc..73f5ecc38c 100755 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -1231,6 +1231,10 @@ source_group("CMake Rules" FILES ViewerInstall.cmake) if (DARWIN) LIST(APPEND viewer_SOURCE_FILES llappviewermacosx.cpp) + LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-objc.h) + LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-objc.mm) + LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-delegate.h) + LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-delegate.mm) find_library(AGL_LIBRARY AGL) find_library(APPKIT_LIBRARY AppKit) @@ -1251,7 +1255,7 @@ if (DARWIN) macview.r gpu_table.txt Info-SecondLife.plist - SecondLife.nib/ + SecondLife.xib/ # CMake doesn't seem to support Xcode language variants well just yet English.lproj/InfoPlist.strings English.lproj/language.txt diff --git a/indra/newview/Info-SecondLife.plist b/indra/newview/Info-SecondLife.plist index f7b11b217c..5db52f040f 100644 --- a/indra/newview/Info-SecondLife.plist +++ b/indra/newview/Info-SecondLife.plist @@ -61,6 +61,10 @@ CFBundleVersion 2.1.0.13828 + NSPrincipalClass + NSApplication + NSMainNibFile + SecondLife CSResourcesFileMapped diff --git a/indra/newview/SecondLife.nib/classes.nib b/indra/newview/SecondLife.nib/classes.nib deleted file mode 100644 index ea58db1189..0000000000 --- a/indra/newview/SecondLife.nib/classes.nib +++ /dev/null @@ -1,4 +0,0 @@ -{ -IBClasses = (); -IBVersion = 1; -} diff --git a/indra/newview/SecondLife.nib/info.nib b/indra/newview/SecondLife.nib/info.nib deleted file mode 100644 index 1b531de104..0000000000 --- a/indra/newview/SecondLife.nib/info.nib +++ /dev/null @@ -1,23 +0,0 @@ - - - - - IBDocumentLocation - 85 13 356 240 0 0 1280 1002 - IBEditorPositions - - 29 - 27 314 247 44 0 0 1280 1002 - - IBFramework Version - 362.0 - IBOpenObjects - - 191 - - IBSystem Version - 7D24 - targetFramework - IBCarbonFramework - - diff --git a/indra/newview/SecondLife.nib/objects.xib b/indra/newview/SecondLife.nib/objects.xib deleted file mode 100644 index b7ff30f2b2..0000000000 --- a/indra/newview/SecondLife.nib/objects.xib +++ /dev/null @@ -1,259 +0,0 @@ - - - IBCarbonFramework - - NSApplication - - - - SecondLife - - - Second Life - - Second Life - - - TRUE - TRUE - About Second Life - 0 - abou - - - _NSAppleMenu - - - - File - - File - - - - Edit - - Edit - - - TRUE - Undo - z - undo - - - TRUE - Redo - Z - redo - - - TRUE - - - TRUE - Cut - x - cut - - - TRUE - Copy - c - copy - - - TRUE - Paste - v - past - - - TRUE - Delete - clea - - - TRUE - Select All - a - sall - - - TRUE - - - TRUE - Special Characters… - chrp - - - - - - Window - - Window - - - TRUE - TRUE - Minimize Window - m - mini - - - TRUE - TRUE - Minimize All Windows - m - 1572864 - mina - - - TRUE - Zoom - zoom - - - TRUE - - - TRUE - TRUE - Bring All to Front - bfrt - - - TRUE - TRUE - Arrange in Front - 1572864 - frnt - - - _NSWindowsMenu - - - - _NSMainMenu - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 0 482 694 - 0 0 694 482 - - - 442 604 462 674 - 604 442 70 20 - OK - ok - - 2 - 2 - - 1 - - - 20 20 422 674 - 20 20 654 402 - - - 20 20 422 659 - 0 0 639 402 - text - 5 - TRUE - - - FALSE - - - - - 84 72 566 766 - Release Notes - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - TRUE - TRUE - 4 - 1 - FALSE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Files Owner - - MenuBar - - Release Notes - - - 202 - diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib new file mode 100644 index 0000000000..2fc83bd009 --- /dev/null +++ b/indra/newview/SecondLife.xib @@ -0,0 +1,1848 @@ + + + + 1060 + 12C60 + 2844 + 1187.34 + 625.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 2844 + + + NSCustomObject + NSMenu + NSMenuItem + NSView + NSWindowTemplate + + + com.apple.InterfaceBuilder.CocoaPlugin + + + PluginDependencyRecalculationVersion + + + + + NSApplication + + + FirstResponder + + + NSApplication + + + Main Menu + + + + Second Life + + 2147483647 + + NSImage + NSMenuCheckmark + + + NSImage + NSMenuMixedState + + submenuAction: + + Second Life + + + + About Second Life + + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Preferences… + , + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Services + + 2147483647 + + + submenuAction: + + Services + + _NSServicesMenu + + + + + YES + YES + + + 2147483647 + + + + + + Hide NewApplication + h + 1048576 + 2147483647 + + + + + + Hide Others + h + 1572864 + 2147483647 + + + + + + Show All + + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Quit NewApplication + q + 1048576 + 2147483647 + + + + + _NSAppleMenu + + + + + File + + 2147483647 + + + submenuAction: + + File + + + + New + n + 1048576 + 2147483647 + + + + + + Open… + o + 1048576 + 2147483647 + + + + + + Open Recent + + 2147483647 + + + submenuAction: + + Open Recent + + + + Clear Menu + + 2147483647 + + + + + _NSRecentDocumentsMenu + + + + + YES + YES + + + 2147483647 + + + + + + Close + w + 1048576 + 2147483647 + + + + + + Save… + s + 1048576 + 2147483647 + + + + + + Revert to Saved + + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Page Setup... + P + 1179648 + 2147483647 + + + + + + + Print… + p + 1048576 + 2147483647 + + + + + + + + + Edit + + 2147483647 + + + submenuAction: + + Edit + + + + Undo + z + 1048576 + 2147483647 + + + + + + Redo + Z + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Cut + x + 1048576 + 2147483647 + + + + + + Copy + c + 1048576 + 2147483647 + + + + + + Paste + v + 1048576 + 2147483647 + + + + + + Paste and Match Style + V + 1572864 + 2147483647 + + + + + + Delete + + 2147483647 + + + + + + Select All + a + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Find + + 2147483647 + + + submenuAction: + + Find + + + + Find… + f + 1048576 + 2147483647 + + + 1 + + + + Find and Replace… + f + 1572864 + 2147483647 + + + 12 + + + + Find Next + g + 1048576 + 2147483647 + + + 2 + + + + Find Previous + G + 1048576 + 2147483647 + + + 3 + + + + Use Selection for Find + e + 1048576 + 2147483647 + + + 7 + + + + Jump to Selection + j + 1048576 + 2147483647 + + + + + + + + + Spelling and Grammar + + 2147483647 + + + submenuAction: + + Spelling + + + + Show Spelling and Grammar + : + 1048576 + 2147483647 + + + + + + Check Document Now + ; + 1048576 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Check Spelling While Typing + + 2147483647 + + + + + + Check Grammar With Spelling + + 2147483647 + + + + + + Correct Spelling Automatically + + 2147483647 + + + + + + + + + Substitutions + + 2147483647 + + + submenuAction: + + Substitutions + + + + Show Substitutions + + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Smart Copy/Paste + + 2147483647 + + + + + + Smart Quotes + + 2147483647 + + + + + + Smart Dashes + + 2147483647 + + + + + + Smart Links + + 2147483647 + + + + + + Data Detectors + + 2147483647 + + + + + + Text Replacement + + 2147483647 + + + + + + + + + Transformations + + 2147483647 + + + submenuAction: + + Transformations + + + + Make Upper Case + + 2147483647 + + + + + + Make Lower Case + + 2147483647 + + + + + + Capitalize + + 2147483647 + + + + + + + + + Speech + + 2147483647 + + + submenuAction: + + Speech + + + + Start Speaking + + 2147483647 + + + + + + Stop Speaking + + 2147483647 + + + + + + + + + + + + Window + + 2147483647 + + + submenuAction: + + Window + + + + Minimize + m + 1048576 + 2147483647 + + + + + + Zoom + + 2147483647 + + + + + + Enter Full Screen + f + 1310720 + 2147483647 + + + + + + YES + YES + + + 2147483647 + + + + + + Bring All to Front + + 2147483647 + + + + + _NSWindowsMenu + + + + + Help + + 2147483647 + + + submenuAction: + + Help + + + + NewApplication Help + ? + 1048576 + 2147483647 + + + + + _NSHelpMenu + + + + _NSMainMenu + + + LLAppDelegate + + + 15 + 2 + {{196, 240}, {1024, 768}} + 74974208 + Second Life + LLNSWindow + + + {1024, 768} + + + 256 + + {1024, 768} + + + + _NS:20 + + {{0, 0}, {1920, 1178}} + {1024, 790} + {10000000000000, 10000000000000} + 128 + YES + + + + + + + terminate: + + + + 823 + + + + orderFrontStandardAboutPanel: + + + + 142 + + + + delegate + + + + 845 + + + + performMiniaturize: + + + + 37 + + + + arrangeInFront: + + + + 39 + + + + print: + + + + 86 + + + + runPageLayout: + + + + 87 + + + + clearRecentDocuments: + + + + 127 + + + + performClose: + + + + 193 + + + + performZoom: + + + + 240 + + + + showHelp: + + + + 360 + + + + saveDocument: + + + + 362 + + + + revertDocumentToSaved: + + + + 364 + + + + hide: + + + + 369 + + + + hideOtherApplications: + + + + 370 + + + + unhideAllApplications: + + + + 372 + + + + cut: + + + + 768 + + + + paste: + + + + 769 + + + + toggleSmartInsertDelete: + + + + 770 + + + + toggleAutomaticDashSubstitution: + + + + 773 + + + + toggleContinuousSpellChecking: + + + + 774 + + + + toggleAutomaticDataDetection: + + + + 775 + + + + undo: + + + + 776 + + + + startSpeaking: + + + + 778 + + + + showGuessPanel: + + + + 779 + + + + checkSpelling: + + + + 780 + + + + copy: + + + + 782 + + + + delete: + + + + 783 + + + + selectAll: + + + + 785 + + + + stopSpeaking: + + + + 786 + + + + orderFrontSubstitutionsPanel: + + + + 787 + + + + toggleAutomaticTextReplacement: + + + + 788 + + + + toggleAutomaticSpellingCorrection: + + + + 790 + + + + toggleFullScreen: + + + + 842 + + + + window + + + + 850 + + + + + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 29 + + + + + + + + + + Main Menu + + + 19 + + + + + + + + 56 + + + + + + + + 103 + + + + + + + + 83 + + + + + + + + 81 + + + + + + + + + + + + + + + + + 75 + + + + + 78 + + + + + 72 + + + + + 82 + + + + + 124 + + + + + + + + 77 + + + + + 73 + + + + + 79 + + + + + 112 + + + + + 74 + + + + + 125 + + + + + + + + 126 + + + + + 106 + + + + + + + + 111 + + + + + 57 + + + + + + + + + + + + + + + + + + 58 + + + + + 134 + + + + + 150 + + + + + 136 + + + + + 144 + + + + + 129 + + + + + 143 + + + + + 236 + + + + + 131 + + + + + + + + 149 + + + + + 145 + + + + + 130 + + + + + 24 + + + + + + + + + + + + 92 + + + + + 5 + + + + + 239 + + + + + 23 + + + + + 711 + + + + + + + + 712 + + + + + + + + + + + + + + + + + + + + + + 713 + + + + + 714 + + + + + 715 + + + + + 716 + + + + + 717 + + + + + 718 + + + + + 719 + + + + + 720 + + + + + 721 + + + + + 722 + + + + + 723 + + + + + + + + 724 + + + + + + + + 725 + + + + + + + + 726 + + + + + + + + 727 + + + + + + + + 738 + + + + + + + + + 739 + + + + + 740 + + + + + 741 + + + + + + + + + + 742 + + + + + 743 + + + + + 744 + + + + + 745 + + + + + + + + + + + + + + + 746 + + + + + 747 + + + + + 748 + + + + + 749 + + + + + 750 + + + + + 751 + + + + + 752 + + + + + 753 + + + + + 754 + + + + + + + + + + + + + 755 + + + + + 756 + + + + + 757 + + + + + 758 + + + + + 759 + + + + + 760 + + + + + 761 + + + + + + + + + + + + + 762 + + + + + 763 + + + + + 764 + + + + + 765 + + + + + 766 + + + + + 821 + + + + + 824 + + + + + 841 + + + + + 828 + + + + + + + + 829 + + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + 852 + + + + + LLAppDelegate + NSObject + + LLOpenGLView + LLNSWindow + + + + glview + LLOpenGLView + + + window + LLNSWindow + + + + IBProjectSource + ./Classes/LLAppDelegate.h + + + + LLNSWindow + NSWindow + + IBProjectSource + ./Classes/LLNSWindow.h + + + + LLOpenGLView + NSOpenGLView + + IBProjectSource + ./Classes/LLOpenGLView.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + YES + 3 + + {11, 11} + {10, 3} + + YES + + diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 30f82926f1..6a87f7306d 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -250,10 +250,6 @@ static LLAppViewerListener sAppViewerListener(LLAppViewer::instance); //---------------------------------------------------------------------------- // viewer.cpp - these are only used in viewer, should be easily moved. -#if LL_DARWIN -extern void init_apple_menu(const char* product); -#endif // LL_DARWIN - extern BOOL gRandomizeFramerate; extern BOOL gPeriodicSlowFrame; extern BOOL gDebugGL; @@ -1196,43 +1192,56 @@ static LLFastTimer::DeclareTimer FTM_SERVICE_CALLBACK("Callback"); static LLFastTimer::DeclareTimer FTM_AGENT_AUTOPILOT("Autopilot"); static LLFastTimer::DeclareTimer FTM_AGENT_UPDATE("Update"); +LLMemType mt1(LLMemType::MTYPE_MAIN); + bool LLAppViewer::mainLoop() { - LLMemType mt1(LLMemType::MTYPE_MAIN); - mMainloopTimeout = new LLWatchdogTimeout(); + if (!mMainLoopInitialized) + { + mMainloopTimeout = new LLWatchdogTimeout(); + + //------------------------------------------- + // Run main loop until time to quit + //------------------------------------------- + + // Create IO Pump to use for HTTP Requests. + gServicePump = new LLPumpIO(gAPRPoolp); + LLHTTPClient::setPump(*gServicePump); + LLCurl::setCAFile(gDirUtilp->getCAFile()); + + // Note: this is where gLocalSpeakerMgr and gActiveSpeakerMgr used to be instantiated. + + LLVoiceChannel::initClass(); + LLVoiceClient::getInstance()->init(gServicePump); + LLVoiceChannel::setCurrentVoiceChannelChangedCallback(boost::bind(&LLCallFloater::sOnCurrentChannelChanged, _1), true); + + joystick = LLViewerJoystick::getInstance(); + joystick->setNeedsReset(true); + + + // As we do not (yet) send data on the mainloop LLEventPump that varies + // with each frame, no need to instantiate a new LLSD event object each + // time. Obviously, if that changes, just instantiate the LLSD at the + // point of posting. + mMainLoopInitialized = true; + } + LLEventPump& mainloop(LLEventPumps::instance().obtain("mainloop")); + + LLSD newFrame; - //------------------------------------------- - // Run main loop until time to quit - //------------------------------------------- - - // Create IO Pump to use for HTTP Requests. - gServicePump = new LLPumpIO(gAPRPoolp); - LLHTTPClient::setPump(*gServicePump); - LLCurl::setCAFile(gDirUtilp->getCAFile()); - - // Note: this is where gLocalSpeakerMgr and gActiveSpeakerMgr used to be instantiated. - - LLVoiceChannel::initClass(); - LLVoiceClient::getInstance()->init(gServicePump); - LLVoiceChannel::setCurrentVoiceChannelChangedCallback(boost::bind(&LLCallFloater::sOnCurrentChannelChanged, _1), true); LLTimer frameTimer,idleTimer; LLTimer debugTime; - LLViewerJoystick* joystick(LLViewerJoystick::getInstance()); - joystick->setNeedsReset(true); - - LLEventPump& mainloop(LLEventPumps::instance().obtain("mainloop")); - // As we do not (yet) send data on the mainloop LLEventPump that varies - // with each frame, no need to instantiate a new LLSD event object each - // time. Obviously, if that changes, just instantiate the LLSD at the - // point of posting. - LLSD newFrame; - + //LLPrivateMemoryPoolTester::getInstance()->run(false) ; //LLPrivateMemoryPoolTester::getInstance()->run(true) ; //LLPrivateMemoryPoolTester::destroy() ; // Handle messages +#ifdef LL_DARWIN + if (!LLApp::isExiting()) +#else while (!LLApp::isExiting()) +#endif { LLFastTimer::nextFrame(); // Should be outside of any timer instances @@ -1510,34 +1519,37 @@ bool LLAppViewer::mainLoop() } } - // Save snapshot for next time, if we made it through initialization - if (STATE_STARTED == LLStartUp::getStartupState()) + if (LLApp::isExiting()) { - try + // Save snapshot for next time, if we made it through initialization + if (STATE_STARTED == LLStartUp::getStartupState()) { - saveFinalSnapshot(); - } - catch(std::bad_alloc) - { - llwarns << "Bad memory allocation when saveFinalSnapshot() is called!" << llendl ; - - //stop memory leaking simulation - LLFloaterMemLeak* mem_leak_instance = - LLFloaterReg::findTypedInstance("mem_leaking"); - if(mem_leak_instance) + try { - mem_leak_instance->stop() ; - } + saveFinalSnapshot(); + } + catch(std::bad_alloc) + { + llwarns << "Bad memory allocation when saveFinalSnapshot() is called!" << llendl ; + + //stop memory leaking simulation + LLFloaterMemLeak* mem_leak_instance = + LLFloaterReg::findTypedInstance("mem_leaking"); + if(mem_leak_instance) + { + mem_leak_instance->stop() ; + } + } } + + delete gServicePump; + + destroyMainloopTimeout(); + + llinfos << "Exiting main_loop" << llendflush; } - - delete gServicePump; - - destroyMainloopTimeout(); - - llinfos << "Exiting main_loop" << llendflush; - return true; + return LLApp::isExiting(); } void LLAppViewer::flushVFSIO() @@ -2618,8 +2630,6 @@ bool LLAppViewer::initConfiguration() //} #if LL_DARWIN - // Initialize apple menubar and various callbacks - init_apple_menu(LLTrans::getString("APP_NAME").c_str()); #if __ppc__ // If the CPU doesn't have Altivec (i.e. it's not at least a G4), don't go any further. diff --git a/indra/newview/llappviewer.h b/indra/newview/llappviewer.h index 7a474f9122..a09bdb2496 100644 --- a/indra/newview/llappviewer.h +++ b/indra/newview/llappviewer.h @@ -41,6 +41,7 @@ class LLImageDecodeThread; class LLTextureFetch; class LLWatchdogTimeout; class LLUpdaterService; +class LLViewerJoystick; class LLAppViewer : public LLApp { @@ -250,6 +251,8 @@ private: std::string mSerialNumber; bool mPurgeCache; bool mPurgeOnExit; + bool mMainLoopInitialized; + LLViewerJoystick* joystick; bool mSavedFinalSnapshot; bool mSavePerAccountSettings; // only save per account settings if login succeeded diff --git a/indra/newview/llappviewermacosx-delegate.h b/indra/newview/llappviewermacosx-delegate.h new file mode 100644 index 0000000000..ac234c14be --- /dev/null +++ b/indra/newview/llappviewermacosx-delegate.h @@ -0,0 +1,24 @@ +// +// LLAppDelegate.h +// SecondLife +// +// Created by Geenz on 12/16/12. +// +// + +#import +#import "llopenglview-objc.h" +#include "llappviewermacosx-objc.h" + +@interface LLAppDelegate : NSObject { + LLNSWindow *window; + LLOpenGLView *glview; + NSTimer *frameTimer; +} + +@property (assign) IBOutlet LLNSWindow *window; +@property (assign) IBOutlet LLOpenGLView *glview; + +- (void) mainLoop; + +@end diff --git a/indra/newview/llappviewermacosx-delegate.mm b/indra/newview/llappviewermacosx-delegate.mm new file mode 100644 index 0000000000..80cc1010e9 --- /dev/null +++ b/indra/newview/llappviewermacosx-delegate.mm @@ -0,0 +1,49 @@ +// +// LLAppDelegate.m +// SecondLife +// +// Created by Geenz on 12/16/12. +// +// + +#import "llappviewermacosx-delegate.h" + +@implementation LLAppDelegate + +@synthesize window; +@synthesize glview; + +- (void)dealloc +{ + [super dealloc]; +} + +- (void) applicationDidFinishLaunching:(NSNotification *)notification +{ + frameTimer = nil; + + setLLNSWindowRef([self window]); + setLLOpenGLViewRef([self glview]); + if (initViewer()) + { + frameTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/60 target:self selector:@selector(mainLoop) userInfo:nil repeats:YES]; + } else { + handleQuit(); + } +} + +- (void) applicationWillTerminate:(NSNotification *)notification +{ +} + +- (void) mainLoop +{ + bool appExiting = runMainLoop(); + if (appExiting) + { + [frameTimer release]; + handleQuit(); + } +} + +@end diff --git a/indra/newview/llappviewermacosx-objc.h b/indra/newview/llappviewermacosx-objc.h new file mode 100644 index 0000000000..9ece6a1a6a --- /dev/null +++ b/indra/newview/llappviewermacosx-objc.h @@ -0,0 +1,19 @@ +// +// NSObject_llappviewermacosx_objc.h +// SecondLife +// +// Created by Geenz on 12/16/12. +// +// + +#include +typedef std::tr1::function VoidCallback; +typedef void* ViewerAppRef; + +int createNSApp(int argc, const char **argv); + +bool initViewer(); +void handleQuit(); +bool runMainLoop(); +void initMainLoop(); +void destroyMainLoop(); \ No newline at end of file diff --git a/indra/newview/llappviewermacosx-objc.mm b/indra/newview/llappviewermacosx-objc.mm new file mode 100644 index 0000000000..ca2090b790 --- /dev/null +++ b/indra/newview/llappviewermacosx-objc.mm @@ -0,0 +1,20 @@ +// +// llappviewermacosx.m +// SecondLife +// +// Created by Geenz on 12/12/12. +// +// + +#import +#import +#include "llappviewermacosx-objc.h" +#import "llappviewermacosx-delegate.h" + +int createNSApp(int argc, const char *argv[]) +{ + return NSApplicationMain(argc, argv); +} + + + diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp index c2916717bd..a1c8b7699d 100644 --- a/indra/newview/llappviewermacosx.cpp +++ b/indra/newview/llappviewermacosx.cpp @@ -31,6 +31,7 @@ #endif #include "llappviewermacosx.h" +#include "llappviewermacosx-objc.h" #include "llcommandlineparser.h" #include "llmemtype.h" @@ -53,7 +54,7 @@ namespace int gArgC; char** gArgV; - bool sCrashReporterIsRunning = false; + LLAppViewerMacOSX* gViewerAppPtr; OSErr AEQuitHandler(const AppleEvent *messagein, AppleEvent *reply, long refIn) { @@ -65,55 +66,61 @@ namespace } } -int main( int argc, char **argv ) +bool initViewer() { LLMemType mt1(LLMemType::MTYPE_STARTUP); - -#if LL_SOLARIS && defined(__sparc) - asm ("ta\t6"); // NOTE: Make sure memory alignment is enforced on SPARC -#endif - + // Set the working dir to /Contents/Resources if (chdir(gDirUtilp->getAppRODataDir().c_str()) == -1) { llwarns << "Could not change directory to " - << gDirUtilp->getAppRODataDir() << ": " << strerror(errno) - << llendl; + << gDirUtilp->getAppRODataDir() << ": " << strerror(errno) + << llendl; } - - LLAppViewerMacOSX* viewer_app_ptr = new LLAppViewerMacOSX(); - - viewer_app_ptr->setErrorHandler(LLAppViewer::handleViewerCrash); - - // Store off the command line args for use later. - gArgC = argc; - gArgV = argv; - bool ok = viewer_app_ptr->init(); + gViewerAppPtr = new LLAppViewerMacOSX(); + + gViewerAppPtr->setErrorHandler(LLAppViewer::handleViewerCrash); + + + + bool ok = gViewerAppPtr->init(); if(!ok) { llwarns << "Application init failed." << llendl; - return -1; } + + return ok; +} - // Run the application main loop - if(!LLApp::isQuitting()) +void handleQuit() +{ + if(!LLApp::isError()) { - viewer_app_ptr->mainLoop(); + gViewerAppPtr->cleanup(); } + + delete gViewerAppPtr; + gViewerAppPtr = NULL; +} - if (!LLApp::isError()) +bool runMainLoop() +{ + bool ret = LLApp::isQuitting(); + if (!ret) { - // - // We don't want to do cleanup here if the error handler got called - - // the assumption is that the error handler is responsible for doing - // app cleanup if there was a problem. - // - viewer_app_ptr->cleanup(); + ret = gViewerAppPtr->mainLoop(); } - delete viewer_app_ptr; - viewer_app_ptr = NULL; - return 0; + + return ret; +} + +int main( int argc, char **argv ) +{ + // Store off the command line args for use later. + gArgC = argc; + gArgV = argv; + return createNSApp(argc, (const char**)argv); } LLAppViewerMacOSX::LLAppViewerMacOSX() @@ -258,33 +265,6 @@ bool LLAppViewerMacOSX::restoreErrorTrap() return reset_count == 0; } -static OSStatus CarbonEventHandler(EventHandlerCallRef inHandlerCallRef, - EventRef inEvent, - void* inUserData) -{ - ProcessSerialNumber psn; - - GetEventParameter(inEvent, - kEventParamProcessID, - typeProcessSerialNumber, - NULL, - sizeof(psn), - NULL, - &psn); - - if( GetEventKind(inEvent) == kEventAppTerminated ) - { - Boolean matching_psn = FALSE; - OSErr os_result = SameProcess(&psn, (ProcessSerialNumber*)inUserData, &matching_psn); - if(os_result >= 0 && matching_psn) - { - sCrashReporterIsRunning = false; - QuitApplicationEventLoop(); - } - } - return noErr; -} - void LLAppViewerMacOSX::handleCrashReporting(bool reportFreeze) { // This used to use fork&exec, but is switched to LSOpenApplication to @@ -306,72 +286,6 @@ void LLAppViewerMacOSX::handleCrashReporting(bool reportFreeze) appParams.version = 0; appParams.flags = kLSLaunchNoParams | kLSLaunchStartClassic; appParams.application = &appRef; - - if(reportFreeze) - { - // Make sure freeze reporting launches the crash logger synchronously, lest - // Log files get changed by SL while the logger is running. - - // *NOTE:Mani A better way - make a copy of the data that the crash reporter will send - // and let SL go about its business. This way makes the mac work like windows and linux - // and is the smallest patch for the issue. - sCrashReporterIsRunning = false; - ProcessSerialNumber o_psn; - - static EventHandlerRef sCarbonEventsRef = NULL; - static const EventTypeSpec kEvents[] = - { - { kEventClassApplication, kEventAppTerminated } - }; - - // Install the handler to detect crash logger termination - InstallEventHandler(GetApplicationEventTarget(), - (EventHandlerUPP) CarbonEventHandler, - GetEventTypeCount(kEvents), - kEvents, - &o_psn, - &sCarbonEventsRef - ); - - // Remove, temporarily the quit handler - which has *crash* behavior before - // the mainloop gets running! - AERemoveEventHandler(kCoreEventClass, - kAEQuitApplication, - NewAEEventHandlerUPP(AEQuitHandler), - false); - - // Launch the crash reporter. - os_result = LSOpenApplication(&appParams, &o_psn); - - if(os_result >= 0) - { - sCrashReporterIsRunning = true; - } - - while(sCrashReporterIsRunning) - { - RunApplicationEventLoop(); - } - - // Re-install the apps quit handler. - AEInstallEventHandler(kCoreEventClass, - kAEQuitApplication, - NewAEEventHandlerUPP(AEQuitHandler), - 0, - false); - - // Remove the crash reporter quit handler. - RemoveEventHandler(sCarbonEventsRef); - } - else - { - appParams.flags |= kLSLaunchAsync; - clear_signals(); - - ProcessSerialNumber o_psn; - os_result = LSOpenApplication(&appParams, &o_psn); - } - } } @@ -505,73 +419,3 @@ OSErr AEGURLHandler(const AppleEvent *messagein, AppleEvent *reply, long refIn) return(result); } - -OSStatus simpleDialogHandler(EventHandlerCallRef handler, EventRef event, void *userdata) -{ - OSStatus result = eventNotHandledErr; - OSStatus err; - UInt32 evtClass = GetEventClass(event); - UInt32 evtKind = GetEventKind(event); - WindowRef window = (WindowRef)userdata; - - if((evtClass == kEventClassCommand) && (evtKind == kEventCommandProcess)) - { - HICommand cmd; - err = GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, sizeof(cmd), NULL, &cmd); - - if(err == noErr) - { - switch(cmd.commandID) - { - case kHICommandOK: - QuitAppModalLoopForWindow(window); - result = noErr; - break; - - case kHICommandCancel: - QuitAppModalLoopForWindow(window); - result = userCanceledErr; - break; - } - } - } - - return(result); -} - -void init_apple_menu(const char* product) -{ - // Load up a proper menu bar. - { - OSStatus err; - IBNibRef nib = NULL; - // NOTE: DO NOT translate or brand this string. It's an internal name in the .nib file, and MUST match exactly. - err = CreateNibReference(CFSTR("SecondLife"), &nib); - - if(err == noErr) - { - // NOTE: DO NOT translate or brand this string. It's an internal name in the .nib file, and MUST match exactly. - SetMenuBarFromNib(nib, CFSTR("MenuBar")); - } - - if(nib != NULL) - { - DisposeNibReference(nib); - } - } - - // Install a handler for 'gurl' AppleEvents. This is how secondlife:// URLs get passed to the viewer. - - if(AEInstallEventHandler('GURL', 'GURL', NewAEEventHandlerUPP(AEGURLHandler),0, false) != noErr) - { - // Couldn't install AppleEvent handler. This error shouldn't be fatal. - llinfos << "Couldn't install 'GURL' AppleEvent handler. Continuing..." << llendl; - } - - // Install a handler for 'quit' AppleEvents. This makes quitting the application from the dock work. - if(AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(AEQuitHandler),0, false) != noErr) - { - // Couldn't install AppleEvent handler. This error shouldn't be fatal. - llinfos << "Couldn't install Quit AppleEvent handler. Continuing..." << llendl; - } -} diff --git a/indra/newview/macutil_Prefix.h b/indra/newview/macutil_Prefix.h index b54a764a62..b8df961cac 100644 --- a/indra/newview/macutil_Prefix.h +++ b/indra/newview/macutil_Prefix.h @@ -32,7 +32,6 @@ * */ -#include #include "fix_macros.h" #undef verify -- cgit v1.2.3 From 7a1593c083a7ed6e3d6589d5dd656354d748b8ce Mon Sep 17 00:00:00 2001 From: Geenz Date: Sat, 29 Dec 2012 07:00:34 -0500 Subject: Added requisite SecondLife.nib file required for compiling the viewer. --- indra/newview/SecondLife.nib | Bin 0 -> 15670 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 indra/newview/SecondLife.nib diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib new file mode 100644 index 0000000000..b2495036a6 Binary files /dev/null and b/indra/newview/SecondLife.nib differ -- cgit v1.2.3 From ddb48d51d996b18063b111faa3b7e709160074d9 Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 1 Jan 2013 11:32:53 -0500 Subject: More things in this commit: - Removed the callback system in favor of simply defining functions in a header to later be implemented in whichever file is most convenient for what we want to do (i.e., calling LLWindow callbacks within LLWindowMacOSX, setting cursors in llwindowmacosx-objc.mm, etc.) - Viewer shutdown now works appropriately - Added a bit of debugging code to test if a key has been handled by the UI or not (useful for tracking down the mystery of the enter key not being handled) - Setup a cocoa quit handler within the application delegate that intercepts any termination requests --- indra/llwindow/llopenglview-objc.h | 30 ---- indra/llwindow/llopenglview-objc.mm | 214 ++++++++++------------------ indra/llwindow/llwindowmacosx-objc.h | 38 +++-- indra/llwindow/llwindowmacosx-objc.mm | 74 ++-------- indra/llwindow/llwindowmacosx.cpp | 73 +++++++--- indra/llwindow/llwindowmacosx.h | 2 +- indra/newview/llappviewermacosx-delegate.mm | 18 ++- indra/newview/llappviewermacosx-objc.h | 2 +- indra/newview/llappviewermacosx.cpp | 32 ++--- indra/newview/llviewerkeyboard.cpp | 2 +- 10 files changed, 201 insertions(+), 284 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 6b055bc665..20589e321d 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -15,7 +15,6 @@ @interface LLOpenGLView : NSOpenGLView { NSPoint mousePos; - ResizeCallback mResizeCallback; } - (id) initWithFrame:(NSRect)frame withSamples:(NSUInteger)samples andVsync:(BOOL)vsync; @@ -33,42 +32,13 @@ - (CGLContextObj) getCGLContextObj; - (CGLPixelFormatObj*)getCGLPixelFormatObj; -- (void) registerResizeCallback:(ResizeCallback)callback; @end @interface LLNSWindow : NSWindow { float mMousePos[2]; unsigned int mModifiers; - - KeyCallback mKeyDownCallback; - KeyCallback mKeyUpCallback; - UnicodeCallback mUnicodeCallback; - ModifierCallback mModifierCallback; - MouseCallback mMouseDownCallback; - MouseCallback mMouseUpCallback; - MouseCallback mMouseDoubleClickCallback; - MouseCallback mRightMouseDownCallback; - MouseCallback mRightMouseUpCallback; - MouseCallback mMouseMovedCallback; - ScrollWheelCallback mScrollWhellCallback; - VoidCallback mMouseExitCallback; - MouseCallback mDeltaUpdateCallback; } -- (void) registerKeyDownCallback:(KeyCallback)callback; -- (void) registerKeyUpCallback:(KeyCallback)callback; -- (void) registerUnicodeCallback:(UnicodeCallback)callback; -- (void) registerModifierCallback:(ModifierCallback)callback; -- (void) registerMouseDownCallback:(MouseCallback)callback; -- (void) registerMouseUpCallback:(MouseCallback)callback; -- (void) registerRightMouseDownCallback:(MouseCallback)callback; -- (void) registerRightMouseUpCallback:(MouseCallback)callback; -- (void) registerDoubleClickCallback:(MouseCallback)callback; -- (void) registerMouseMovedCallback:(MouseCallback)callback; -- (void) registerScrollCallback:(ScrollWheelCallback)callback; -- (void) registerMouseExitCallback:(VoidCallback)callback; -- (void) registerDeltaUpdateCallback:(MouseCallback)callback; - @end void setLLNSWindowRef(LLNSWindow* window); diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 7c148f4acd..cb8d7b315f 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -19,12 +19,9 @@ - (void)windowResized:(NSNotification *)notification; { - if (mResizeCallback != nil) - { - NSSize size = [[self window] frame].size; - - mResizeCallback(size.width, size.height); - } + NSSize size = [self frame].size; + + callResize(size.width, size.height); } - (void)dealloc @@ -125,11 +122,6 @@ return (CGLPixelFormatObj*)[fmt CGLPixelFormatObj]; } -- (void) registerResizeCallback:(ResizeCallback)callback -{ - mResizeCallback = callback; -} - // Various events can be intercepted by our view, thus not reaching our window. // Intercept these events, and pass them to the window as needed. - Geenz @@ -183,6 +175,16 @@ [super flagsChanged:theEvent]; } +- (BOOL) becomeFirstResponder +{ + return [super becomeFirstResponder]; +} + +- (BOOL) resignFirstResponder +{ + return [super resignFirstResponder]; +} + @end // We use a custom NSWindow for our event handling. @@ -196,30 +198,19 @@ return self; } -- (void) keyDown:(NSEvent *)theEvent { - if (mKeyDownCallback != nil && mUnicodeCallback != nil) +- (void) keyDown:(NSEvent *)theEvent +{ + callKeyDown([theEvent keyCode], [theEvent modifierFlags]); + + NSString *chars = [theEvent characters]; + for (uint i = 0; i < [chars length]; i++) { - mKeyDownCallback([theEvent keyCode], [theEvent modifierFlags]); - - NSString *chars = [theEvent charactersIgnoringModifiers]; - for (uint i = 0; i < [chars length]; i++) - { - mUnicodeCallback([chars characterAtIndex:i], [theEvent modifierFlags]); - } - - // The viewer expects return to be submitted separately as a unicode character. - if ([theEvent keyCode] == 3 || [theEvent keyCode] == 13) - { - mUnicodeCallback([theEvent keyCode], [theEvent modifierFlags]); - } + callUnicodeCallback([chars characterAtIndex:i], [theEvent modifierFlags]); } } - (void) keyUp:(NSEvent *)theEvent { - if (mKeyUpCallback != nil) - { - mKeyUpCallback([theEvent keyCode], [theEvent modifierFlags]); - } + callKeyUp([theEvent keyCode], [theEvent modifierFlags]); } - (void)flagsChanged:(NSEvent *)theEvent { @@ -228,59 +219,42 @@ - (void) mouseDown:(NSEvent *)theEvent { - if (mMouseDoubleClickCallback != nil && mMouseDownCallback != nil) + if ([theEvent clickCount] >= 2) { - if ([theEvent clickCount] == 2) - { - mMouseDoubleClickCallback(mMousePos, [theEvent modifierFlags]); - } else if ([theEvent clickCount] == 1) { - mMouseDownCallback(mMousePos, [theEvent modifierFlags]); - } + callDoubleClick(mMousePos, [theEvent modifierFlags]); + } else if ([theEvent clickCount] == 1) { + callLeftMouseDown(mMousePos, [theEvent modifierFlags]); } } - (void) mouseUp:(NSEvent *)theEvent { - if (mMouseUpCallback != nil) - { - mMouseUpCallback(mMousePos, [theEvent modifierFlags]); - } + callLeftMouseUp(mMousePos, [theEvent modifierFlags]); } - (void) rightMouseDown:(NSEvent *)theEvent { - if (mRightMouseDownCallback != nil) - { - mRightMouseDownCallback(mMousePos, [theEvent modifierFlags]); - } + callRightMouseDown(mMousePos, [theEvent modifierFlags]); } - (void) rightMouseUp:(NSEvent *)theEvent { - if (mRightMouseUpCallback != nil) - { - mRightMouseUpCallback(mMousePos, [theEvent modifierFlags]); - } + callRightMouseUp(mMousePos, [theEvent modifierFlags]); } -- (void)mouseMoved:(NSEvent *)theEvent { - if (mDeltaUpdateCallback != nil && mMouseMovedCallback != nil) - { - float mouseDeltas[2] = { - [theEvent deltaX], - [theEvent deltaZ] - }; - - mDeltaUpdateCallback(mouseDeltas, 0); - - NSPoint mPoint = [theEvent locationInWindow]; - mMousePos[0] = mPoint.x; - mMousePos[1] = mPoint.y; - if (mMouseMovedCallback != nil) - { - mMouseMovedCallback(mMousePos, 0); - } - } +- (void)mouseMoved:(NSEvent *)theEvent +{ + float mouseDeltas[2] = { + [theEvent deltaX], + [theEvent deltaY] + }; + + callDeltaUpdate(mouseDeltas, 0); + + NSPoint mPoint = [theEvent locationInWindow]; + mMousePos[0] = mPoint.x; + mMousePos[1] = mPoint.y; + callMouseMoved(mMousePos, 0); } // NSWindow doesn't trigger mouseMoved when the mouse is being clicked and dragged. @@ -288,101 +262,59 @@ - (void) mouseDragged:(NSEvent *)theEvent { - if (mDeltaUpdateCallback != nil && mMouseMovedCallback != nil) - { - float mouseDeltas[2] = { - [theEvent deltaX], - [theEvent deltaZ] - }; - - mDeltaUpdateCallback(mouseDeltas, 0); - - NSPoint mPoint = [theEvent locationInWindow]; - mMousePos[0] = mPoint.x; - mMousePos[1] = mPoint.y; - mMouseMovedCallback(mMousePos, 0); - } -} - -- (void) scrollWheel:(NSEvent *)theEvent -{ - if (mScrollWhellCallback != nil) - { - mScrollWhellCallback(-[theEvent deltaY]); - } -} - -- (void) mouseExited:(NSEvent *)theEvent -{ - if (mMouseExitCallback != nil) - { - mMouseExitCallback(); - } -} - -- (void) registerKeyDownCallback:(KeyCallback)callback -{ - mKeyDownCallback = callback; -} - -- (void) registerKeyUpCallback:(KeyCallback)callback -{ - mKeyUpCallback = callback; -} - -- (void) registerUnicodeCallback:(UnicodeCallback)callback -{ - mUnicodeCallback = callback; -} - -- (void) registerModifierCallback:(ModifierCallback)callback -{ - mModifierCallback = callback; -} - -- (void) registerMouseDownCallback:(MouseCallback)callback -{ - mMouseDownCallback = callback; -} - -- (void) registerMouseUpCallback:(MouseCallback)callback -{ - mMouseUpCallback = callback; + // Trust the deltas supplied by NSEvent. + // The old CoreGraphics APIs we previously relied on are now flagged as obsolete. + // NSEvent isn't obsolete, and provides us with the correct deltas. + float mouseDeltas[2] = { + [theEvent deltaX], + [theEvent deltaY] + }; + + callDeltaUpdate(mouseDeltas, 0); + + NSPoint mPoint = [theEvent locationInWindow]; + mMousePos[0] = mPoint.x; + mMousePos[1] = mPoint.y; + callMouseMoved(mMousePos, 0); } -- (void) registerRightMouseDownCallback:(MouseCallback)callback +- (void) otherMouseDown:(NSEvent *)theEvent { - mRightMouseDownCallback = callback; + callMiddleMouseDown(mMousePos, 0); } -- (void) registerRightMouseUpCallback:(MouseCallback)callback +- (void) otherMouseUp:(NSEvent *)theEvent { - mRightMouseUpCallback = callback; + callMiddleMouseUp(mMousePos, 0); } -- (void) registerDoubleClickCallback:(MouseCallback)callback +- (void) otherMouseDragged:(NSEvent *)theEvent { - mMouseDoubleClickCallback = callback; + } -- (void) registerMouseMovedCallback:(MouseCallback)callback +- (void) scrollWheel:(NSEvent *)theEvent { - mMouseMovedCallback = callback; + callScrollMoved(-[theEvent deltaY]); } -- (void) registerScrollCallback:(ScrollWheelCallback)callback +- (void) mouseExited:(NSEvent *)theEvent { - mScrollWhellCallback = callback; + callMouseExit(); } -- (void) registerMouseExitCallback:(VoidCallback)callback +- (BOOL) becomeFirstResponder { - mMouseExitCallback = callback; + NSLog(@"Window gained focus!"); + callFocus(); + return true; } -- (void) registerDeltaUpdateCallback:(MouseCallback)callback +- (BOOL) resignFirstResponder { - mDeltaUpdateCallback = callback; + NSLog(@"Window lost focus!"); + callFocus(); + return true; } @end diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index abaeda1f91..655d63ac12 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -65,21 +65,33 @@ void getCursorPos(NSWindowRef window, float* pos); void makeWindowOrderFront(NSWindowRef window); void convertScreenToWindow(NSWindowRef window, float *coord); void convertWindowToScreen(NSWindowRef window, float *coord); +void convertScreenToView(NSWindowRef window, float *coord); void setWindowPos(NSWindowRef window, float* pos); +void closeWindow(NSWindowRef window); +void removeGLView(GLViewRef view); + +// These are all implemented in llwindowmacosx.cpp. +// This is largely for easier interop between Obj-C and C++ (at least in the viewer's case due to the BOOL vs. BOOL conflict) +void callKeyUp(unsigned short key, unsigned int mask); +void callKeyDown(unsigned short key, unsigned int mask); +void callUnicodeCallback(wchar_t character, unsigned int mask); +void callRightMouseDown(float *pos, unsigned int mask); +void callRightMouseUp(float *pos, unsigned int mask); +void callLeftMouseDown(float *pos, unsigned int mask); +void callLeftMouseUp(float *pos, unsigned int mask); +void callDoubleClick(float *pos, unsigned int mask); +void callResize(unsigned int width, unsigned int height); +void callMouseMoved(float *pos, unsigned int mask); +void callScrollMoved(float delta); +void callMouseExit(); +void callWindowFocus(); +void callWindowUnfocus(); +void callDeltaUpdate(float *delta, unsigned int mask); +void callMiddleMouseDown(float *pos, unsigned int mask); +void callMiddleMouseUp(float *pos, unsigned int mask); +void callFocus(); +void callFocusLost(); -void registerKeyUpCallback(NSWindowRef window, KeyCallback callback); -void registerKeyDownCallback(NSWindowRef window, KeyCallback callback); -void registerUnicodeCallback(NSWindowRef window, UnicodeCallback callback); -void registerMouseUpCallback(NSWindowRef window, MouseCallback callback); -void registerMouseDownCallback(NSWindowRef window, MouseCallback callback); -void registerRightMouseUpCallback(NSWindowRef window, MouseCallback callback); -void registerRightMouseDownCallback(NSWindowRef window, MouseCallback callback); -void registerDoubleClickCallback(NSWindowRef window, MouseCallback callback); -void registerResizeEventCallback(GLViewRef window, ResizeCallback callback); -void registerMouseMovedCallback(NSWindowRef window, MouseCallback callback); -void registerScrollCallback(NSWindowRef window, ScrollWheelCallback callback); -void registerMouseExitCallback(NSWindowRef window, VoidCallback callback); -void registerDeltaUpdateCallback(NSWindowRef window, MouseCallback callback); NSWindowRef getMainAppWindow(); GLViewRef getGLView(NSWindowRef window); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 07efc25ea6..f3972303f1 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -255,6 +255,15 @@ void convertScreenToWindow(NSWindowRef window, float *coord) coord[1] = point.y; } +void convertScreenToView(NSWindowRef window, float *coord) +{ + NSRect point; + point.origin.x = coord[0]; + point.origin.y = coord[1]; + point.origin = [(LLNSWindow*)window convertScreenToBase:point.origin]; + point.origin = [[(LLNSWindow*)window contentView] convertPoint:point.origin fromView:nil]; +} + void convertWindowToScreen(NSWindowRef window, float *coord) { NSPoint point; @@ -265,73 +274,20 @@ void convertWindowToScreen(NSWindowRef window, float *coord) coord[1] = point.y; } -void registerKeyUpCallback(NSWindowRef window, std::tr1::function callback) -{ - [(LLNSWindow*)window registerKeyUpCallback:callback]; -} - -void registerKeyDownCallback(NSWindowRef window, std::tr1::function callback) -{ - [(LLNSWindow*)window registerKeyDownCallback:callback]; -} - -void registerUnicodeCallback(NSWindowRef window, std::tr1::function callback) -{ - [(LLNSWindow*)window registerUnicodeCallback:callback]; -} - -void registerMouseUpCallback(NSWindowRef window, MouseCallback callback) -{ - [(LLNSWindow*)window registerMouseUpCallback:callback]; -} - -void registerMouseDownCallback(NSWindowRef window, MouseCallback callback) -{ - [(LLNSWindow*)window registerMouseDownCallback:callback]; -} - -void registerRightMouseUpCallback(NSWindowRef window, MouseCallback callback) -{ - [(LLNSWindow*)window registerRightMouseUpCallback:callback]; -} - -void registerRightMouseDownCallback(NSWindowRef window, MouseCallback callback) -{ - [(LLNSWindow*)window registerRightMouseDownCallback:callback]; -} - -void registerDoubleClickCallback(NSWindowRef window, MouseCallback callback) -{ - [(LLNSWindow*)window registerDoubleClickCallback:callback]; -} - -void registerResizeEventCallback(GLViewRef glview, ResizeCallback callback) -{ - [(LLOpenGLView*)glview registerResizeCallback:callback]; -} - -void registerMouseMovedCallback(NSWindowRef window, MouseCallback callback) -{ - [(LLNSWindow*)window registerMouseMovedCallback:callback]; -} - -void registerScrollCallback(NSWindowRef window, ScrollWheelCallback callback) -{ - [(LLNSWindow*)window registerScrollCallback:callback]; -} - -void registerMouseExitCallback(NSWindowRef window, VoidCallback callback) +void closeWindow(NSWindowRef window) { - [(LLNSWindow*)window registerMouseExitCallback:callback]; + [(LLNSWindow*)window close]; } -void registerDeltaUpdateCallback(NSWindowRef window, MouseCallback callback) +void removeGLView(GLViewRef view) { - [(LLNSWindow*)window registerDeltaUpdateCallback:callback]; + [(LLOpenGLView*)view removeFromSuperview]; + [(LLOpenGLView*)view release]; } NSWindowRef getMainAppWindow() { + [(LLNSWindow*)winRef setAcceptsMouseMovedEvents:TRUE]; return winRef; } diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index a616b2df2d..cfdfbe2138 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -198,7 +198,7 @@ LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, } -// These functions are used as callbacks for event handling within Cocoa. +// These functions are used as wrappers for our internal event handling callbacks. // It's a good idea to wrap these to avoid reworking more code than we need to within LLWindow. void callKeyUp(unsigned short key, unsigned int mask) @@ -216,9 +216,14 @@ void callUnicodeCallback(wchar_t character, unsigned int mask) gWindowImplementation->getCallbacks()->handleUnicodeChar(character, mask); } -void callModifierCallback(unsigned int mask) +void callFocus() { - + gWindowImplementation->getCallbacks()->handleFocus(gWindowImplementation); +} + +void callFocusLost() +{ + gWindowImplementation->getCallbacks()->handleFocusLost(gWindowImplementation); } void callRightMouseDown(float *pos, MASK mask) @@ -302,17 +307,41 @@ void callWindowUnfocus() void callDeltaUpdate(float *delta, MASK mask) { - gWindowImplementation->updateMouseDeltas(); + gWindowImplementation->updateMouseDeltas(delta); +} + +void callMiddleMouseDown(float *pos, MASK mask) +{ + LLCoordGL outCoords; + outCoords.mX = llround(pos[0]); + outCoords.mY = llround(pos[1]); + float deltas[2]; + gWindowImplementation->getMouseDeltas(deltas); + outCoords.mX += deltas[0]; + outCoords.mY += deltas[1]; + gWindowImplementation->getCallbacks()->handleMiddleMouseDown(gWindowImplementation, outCoords, mask); +} + +void callMiddleMouseUp(float *pos, MASK mask) +{ + LLCoordGL outCoords; + outCoords.mX = llround(pos[0]); + outCoords.mY = llround(pos[1]); + float deltas[2]; + gWindowImplementation->getMouseDeltas(deltas); + outCoords.mX += deltas[0]; + outCoords.mY += deltas[1]; + gWindowImplementation->getCallbacks()->handleMiddleMouseUp(gWindowImplementation, outCoords, mask); } -void LLWindowMacOSX::updateMouseDeltas() +void LLWindowMacOSX::updateMouseDeltas(float* deltas) { if (mCursorDecoupled) { - CGMouseDelta x, y; - CGGetLastMouseDelta( &x, &y ); - mCursorLastEventDeltaX = x; - mCursorLastEventDeltaY = y; + mCursorLastEventDeltaX = llround(deltas[0]); + mCursorLastEventDeltaY = llround(-deltas[1]); + + if (mCursorIgnoreNextDelta) { @@ -320,6 +349,7 @@ void LLWindowMacOSX::updateMouseDeltas() mCursorLastEventDeltaY = 0; mCursorIgnoreNextDelta = FALSE; } + LL_INFOS("Delta Update") << "Last event delta: " << mCursorLastEventDeltaX << ", " << mCursorLastEventDeltaY << LL_ENDL; } else { mCursorLastEventDeltaX = 0; mCursorLastEventDeltaY = 0; @@ -342,6 +372,7 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits { LL_INFOS("Window") << "Creating window..." << LL_ENDL; mWindow = getMainAppWindow(); + /* LL_INFOS("Window") << "Registering key callbacks..." << LL_ENDL; registerKeyDownCallback(mWindow, callKeyDown); registerKeyUpCallback(mWindow, callKeyUp); @@ -355,6 +386,7 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits registerScrollCallback(mWindow, callScrollMoved); registerDeltaUpdateCallback(mWindow, callDeltaUpdate); registerMouseExitCallback(mWindow, callMouseExit); + */ } if(mContext == NULL) @@ -363,7 +395,7 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits // Our OpenGL view is already defined within SecondLife.xib. // Get the view instead. mGLView = createOpenGLView(mWindow); - registerResizeEventCallback(mGLView, callResize); + //registerResizeEventCallback(mGLView, callResize); mContext = getCGLContextObj(mGLView); // Since we just created the context, it needs to be set up. glNeedsInit = TRUE; @@ -439,9 +471,7 @@ void LLWindowMacOSX::destroyContext() if(mContext != NULL) { LL_DEBUGS("Window") << "destroyContext: unhooking drawable " << LL_ENDL; - CGLSetCurrentContext(NULL); - mContext = NULL; } // Clean up remaining GL state before blowing away window @@ -454,16 +484,25 @@ void LLWindowMacOSX::destroyContext() mPixelFormat = NULL; } - // Close the window - if(mWindow != NULL) - { - } - // Clean up the GL context if(mContext != NULL) { CGLDestroyContext(mContext); } + + // Destroy our LLOpenGLView + if(mGLView != NULL) + { + removeGLView(mGLView); + mGLView = NULL; + } + + // Close the window + if(mWindow != NULL) + { + closeWindow(mWindow); + mWindow = NULL; + } } diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h index 487af7658f..c5e1b2290b 100644 --- a/indra/llwindow/llwindowmacosx.h +++ b/indra/llwindow/llwindowmacosx.h @@ -121,7 +121,7 @@ public: void* getWindow() { return mWindow; } LLWindowCallbacks* getCallbacks() { return mCallbacks; } - void updateMouseDeltas(); + void updateMouseDeltas(float* deltas); void getMouseDeltas(float* delta); diff --git a/indra/newview/llappviewermacosx-delegate.mm b/indra/newview/llappviewermacosx-delegate.mm index 80cc1010e9..2e25997d32 100644 --- a/indra/newview/llappviewermacosx-delegate.mm +++ b/indra/newview/llappviewermacosx-delegate.mm @@ -23,17 +23,26 @@ frameTimer = nil; setLLNSWindowRef([self window]); - setLLOpenGLViewRef([self glview]); + //setLLOpenGLViewRef([self glview]); if (initViewer()) { - frameTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/60 target:self selector:@selector(mainLoop) userInfo:nil repeats:YES]; + frameTimer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(mainLoop) userInfo:nil repeats:YES]; } else { handleQuit(); } } -- (void) applicationWillTerminate:(NSNotification *)notification +- (NSApplicationDelegateReply) applicationShouldTerminate:(NSApplication *)sender { + if (!runMainLoop()) + { + handleQuit(); + return NSTerminateCancel; + } else { + [frameTimer release]; + cleanupViewer(); + return NSTerminateNow; + } } - (void) mainLoop @@ -42,7 +51,8 @@ if (appExiting) { [frameTimer release]; - handleQuit(); + cleanupViewer(); + [[NSApplication sharedApplication] terminate:self]; } } diff --git a/indra/newview/llappviewermacosx-objc.h b/indra/newview/llappviewermacosx-objc.h index 9ece6a1a6a..ed9017ca5d 100644 --- a/indra/newview/llappviewermacosx-objc.h +++ b/indra/newview/llappviewermacosx-objc.h @@ -16,4 +16,4 @@ bool initViewer(); void handleQuit(); bool runMainLoop(); void initMainLoop(); -void destroyMainLoop(); \ No newline at end of file +void cleanupViewer(); \ No newline at end of file diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp index a1c8b7699d..6e7b91347b 100644 --- a/indra/newview/llappviewermacosx.cpp +++ b/indra/newview/llappviewermacosx.cpp @@ -55,15 +55,6 @@ namespace char** gArgV; LLAppViewerMacOSX* gViewerAppPtr; - - OSErr AEQuitHandler(const AppleEvent *messagein, AppleEvent *reply, long refIn) - { - OSErr result = noErr; - - LLAppViewer::instance()->userQuit(); - - return(result); - } } bool initViewer() @@ -95,26 +86,33 @@ bool initViewer() void handleQuit() { - if(!LLApp::isError()) - { - gViewerAppPtr->cleanup(); - } - - delete gViewerAppPtr; - gViewerAppPtr = NULL; + LLAppViewer::instance()->userQuit(); } bool runMainLoop() { bool ret = LLApp::isQuitting(); - if (!ret) + if (!ret && gViewerAppPtr != NULL) { ret = gViewerAppPtr->mainLoop(); + } else { + ret = true; } return ret; } +void cleanupViewer() +{ + if(!LLApp::isError()) + { + gViewerAppPtr->cleanup(); + } + + delete gViewerAppPtr; + gViewerAppPtr = NULL; +} + int main( int argc, char **argv ) { // Store off the command line args for use later. diff --git a/indra/newview/llviewerkeyboard.cpp b/indra/newview/llviewerkeyboard.cpp index 6d91dad70e..92d8f2937e 100644 --- a/indra/newview/llviewerkeyboard.cpp +++ b/indra/newview/llviewerkeyboard.cpp @@ -654,7 +654,6 @@ BOOL LLViewerKeyboard::modeFromString(const std::string& string, S32 *mode) BOOL LLViewerKeyboard::handleKey(KEY translated_key, MASK translated_mask, BOOL repeated) { LL_INFOS("Keyboard Handling") << "Handling key " << translated_key << LL_ENDL; - LL_INFOS("Keyboard Handling") << "Keyboard has focus? " << gFocusMgr.getKeyboardFocus() << LL_ENDL; // check for re-map EKeyboardMode mode = gViewerKeyboard.getMode(); U32 keyidx = (translated_mask<<16) | translated_key; @@ -677,6 +676,7 @@ BOOL LLViewerKeyboard::handleKey(KEY translated_key, MASK translated_mask, BOOL if(mKeysSkippedByUI.find(translated_key) != mKeysSkippedByUI.end()) { mKeyHandledByUI[translated_key] = FALSE; + LL_INFOS("Keyboard Handling") << "Key wasn't handled by UI!" << LL_ENDL; } else { -- cgit v1.2.3 From 2b0f50dd821848d18ab35095623c3bdbcdeb910c Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 2 Jan 2013 15:57:21 -0500 Subject: Crash on exit fix + general code cleanup in LLWindowMacOSX. --- indra/llwindow/llwindowmacosx.cpp | 21 ++------------------- indra/newview/llappviewermacosx-delegate.mm | 1 - 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index cfdfbe2138..cc0959edf8 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -283,6 +283,7 @@ void callMouseMoved(float *pos, MASK mask) outCoords.mX += deltas[0]; outCoords.mY += deltas[1]; gWindowImplementation->getCallbacks()->handleMouseMove(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); + } void callScrollMoved(float delta) @@ -339,9 +340,7 @@ void LLWindowMacOSX::updateMouseDeltas(float* deltas) if (mCursorDecoupled) { mCursorLastEventDeltaX = llround(deltas[0]); - mCursorLastEventDeltaY = llround(-deltas[1]); - - + mCursorLastEventDeltaY = llround(deltas[1]); if (mCursorIgnoreNextDelta) { @@ -372,21 +371,6 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits { LL_INFOS("Window") << "Creating window..." << LL_ENDL; mWindow = getMainAppWindow(); - /* - LL_INFOS("Window") << "Registering key callbacks..." << LL_ENDL; - registerKeyDownCallback(mWindow, callKeyDown); - registerKeyUpCallback(mWindow, callKeyUp); - registerUnicodeCallback(mWindow, callUnicodeCallback); - registerMouseDownCallback(mWindow, callLeftMouseDown); - registerMouseUpCallback(mWindow, callLeftMouseUp); - registerRightMouseDownCallback(mWindow, callRightMouseDown); - registerRightMouseUpCallback(mWindow, callRightMouseUp); - registerDoubleClickCallback(mWindow, callDoubleClick); - registerMouseMovedCallback(mWindow, callMouseMoved); - registerScrollCallback(mWindow, callScrollMoved); - registerDeltaUpdateCallback(mWindow, callDeltaUpdate); - registerMouseExitCallback(mWindow, callMouseExit); - */ } if(mContext == NULL) @@ -395,7 +379,6 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits // Our OpenGL view is already defined within SecondLife.xib. // Get the view instead. mGLView = createOpenGLView(mWindow); - //registerResizeEventCallback(mGLView, callResize); mContext = getCGLContextObj(mGLView); // Since we just created the context, it needs to be set up. glNeedsInit = TRUE; diff --git a/indra/newview/llappviewermacosx-delegate.mm b/indra/newview/llappviewermacosx-delegate.mm index 2e25997d32..5c54736993 100644 --- a/indra/newview/llappviewermacosx-delegate.mm +++ b/indra/newview/llappviewermacosx-delegate.mm @@ -51,7 +51,6 @@ if (appExiting) { [frameTimer release]; - cleanupViewer(); [[NSApplication sharedApplication] terminate:self]; } } -- cgit v1.2.3 From 966a4c893c816fc699580092bd6e93a0e514798c Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 2 Jan 2013 16:16:07 -0500 Subject: OS X crash on startup fix: always ensure that mMainLoopInitialized is initialized properly within LLAppViewer::init(). Otherwise, the viewer will sporadically crash on start up. --- indra/newview/llappviewer.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 6a87f7306d..131f4c4031 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -676,6 +676,11 @@ bool LLAppViewer::init() // we run the "program crashed last time" error handler below. // LLFastTimer::reset(); + + +#ifdef LL_DARWIN + mMainLoopInitialized = false; +#endif // initialize SSE options LLVector4a::initClass(); @@ -1196,7 +1201,9 @@ LLMemType mt1(LLMemType::MTYPE_MAIN); bool LLAppViewer::mainLoop() { +#ifdef LL_DARWIN if (!mMainLoopInitialized) +#endif { mMainloopTimeout = new LLWatchdogTimeout(); @@ -1218,13 +1225,16 @@ bool LLAppViewer::mainLoop() joystick = LLViewerJoystick::getInstance(); joystick->setNeedsReset(true); - - // As we do not (yet) send data on the mainloop LLEventPump that varies - // with each frame, no need to instantiate a new LLSD event object each - // time. Obviously, if that changes, just instantiate the LLSD at the - // point of posting. +#ifdef LL_DARWIN + // Ensure that this section of code never gets called again on OS X. mMainLoopInitialized = true; +#endif } + // As we do not (yet) send data on the mainloop LLEventPump that varies + // with each frame, no need to instantiate a new LLSD event object each + // time. Obviously, if that changes, just instantiate the LLSD at the + // point of posting. + LLEventPump& mainloop(LLEventPumps::instance().obtain("mainloop")); LLSD newFrame; -- cgit v1.2.3 From 9ce3ab1a5248423eeea4d843bfb8407ed62b305e Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 2 Jan 2013 18:53:44 -0500 Subject: Fixed the enter and return keys not being sent appropriately as unicode characters. --- indra/llwindow/llkeyboardmacosx.cpp | 2 +- indra/llwindow/llopenglview-objc.mm | 14 +++++++++++++- indra/llwindow/llwindowmacosx-objc.h | 2 +- indra/llwindow/llwindowmacosx-objc.mm | 2 +- indra/llwindow/llwindowmacosx.cpp | 5 ++++- indra/newview/SecondLife.nib | Bin 15670 -> 15670 bytes indra/newview/SecondLife.xib | 2 +- indra/newview/llappviewermacosx-delegate.h | 2 -- indra/newview/llappviewermacosx-delegate.mm | 3 +-- 9 files changed, 22 insertions(+), 10 deletions(-) diff --git a/indra/llwindow/llkeyboardmacosx.cpp b/indra/llwindow/llkeyboardmacosx.cpp index 3f357c600e..077ebea909 100644 --- a/indra/llwindow/llkeyboardmacosx.cpp +++ b/indra/llwindow/llkeyboardmacosx.cpp @@ -206,7 +206,7 @@ MASK LLKeyboardMacOSX::updateModifiers(const U32 mask) out_mask |= MASK_SHIFT; } - if(mask & (MAC_CTRL_KEY | MAC_CMD_KEY)) + if(mask & MAC_CTRL_KEY || mask & MAC_CMD_KEY) { out_mask |= MASK_CONTROL; } diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index cb8d7b315f..e5e198b856 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -30,6 +30,11 @@ [super dealloc]; } +- (id) init +{ + return [self initWithFrame:[self bounds] withSamples:2 andVsync:TRUE]; +} + - (id) initWithFrame:(NSRect)frame withSamples:(NSUInteger)samples andVsync:(BOOL)vsync { @@ -205,7 +210,14 @@ NSString *chars = [theEvent characters]; for (uint i = 0; i < [chars length]; i++) { - callUnicodeCallback([chars characterAtIndex:i], [theEvent modifierFlags]); + // Enter and Return are special cases. + unichar returntest = [chars characterAtIndex:i]; + if ((returntest == NSCarriageReturnCharacter || returntest == NSEnterCharacter) && !([theEvent modifierFlags] & NSCommandKeyMask) && !([theEvent modifierFlags] & NSAlternateKeyMask) && !([theEvent modifierFlags] & NSControlKeyMask)) + { + callUnicodeCallback(returntest, 0); + } else { + callUnicodeCallback([chars characterAtIndex:i], [theEvent modifierFlags]); + } } } diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 655d63ac12..414491f948 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -93,6 +93,6 @@ void callFocus(); void callFocusLost(); NSWindowRef getMainAppWindow(); -GLViewRef getGLView(NSWindowRef window); +GLViewRef getGLView(); unsigned int getModifiers(); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index f3972303f1..5a024eda46 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -291,7 +291,7 @@ NSWindowRef getMainAppWindow() return winRef; } -GLViewRef getGLView(NSWindowRef window) +GLViewRef getGLView() { return glviewRef; } diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index cc0959edf8..902391e170 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -270,7 +270,10 @@ void callDoubleClick(float *pos, MASK mask) void callResize(unsigned int width, unsigned int height) { - gWindowImplementation->getCallbacks()->handleResize(gWindowImplementation, width, height); + if (gWindowImplementation != NULL) + { + gWindowImplementation->getCallbacks()->handleResize(gWindowImplementation, width, height); + } } void callMouseMoved(float *pos, MASK mask) diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib index b2495036a6..cd69b1b812 100644 Binary files a/indra/newview/SecondLife.nib and b/indra/newview/SecondLife.nib differ diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib index 2fc83bd009..212bc5830d 100644 --- a/indra/newview/SecondLife.xib +++ b/indra/newview/SecondLife.xib @@ -1787,7 +1787,7 @@ - 852 + 864 diff --git a/indra/newview/llappviewermacosx-delegate.h b/indra/newview/llappviewermacosx-delegate.h index ac234c14be..848ccbde62 100644 --- a/indra/newview/llappviewermacosx-delegate.h +++ b/indra/newview/llappviewermacosx-delegate.h @@ -12,12 +12,10 @@ @interface LLAppDelegate : NSObject { LLNSWindow *window; - LLOpenGLView *glview; NSTimer *frameTimer; } @property (assign) IBOutlet LLNSWindow *window; -@property (assign) IBOutlet LLOpenGLView *glview; - (void) mainLoop; diff --git a/indra/newview/llappviewermacosx-delegate.mm b/indra/newview/llappviewermacosx-delegate.mm index 5c54736993..7baeeb1de8 100644 --- a/indra/newview/llappviewermacosx-delegate.mm +++ b/indra/newview/llappviewermacosx-delegate.mm @@ -11,7 +11,6 @@ @implementation LLAppDelegate @synthesize window; -@synthesize glview; - (void)dealloc { @@ -23,7 +22,7 @@ frameTimer = nil; setLLNSWindowRef([self window]); - //setLLOpenGLViewRef([self glview]); + if (initViewer()) { frameTimer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(mainLoop) userInfo:nil repeats:YES]; -- cgit v1.2.3 From 09b07e3619a71f142c1a3af41244d756e1230142 Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 8 Jan 2013 16:22:54 -0500 Subject: Big change set: - LLAppDelegate header relocated to LLWindow. Definition is still present in secondlife-bin (for compatibility reasons when loading a nib). - Return key handling fixed. - Command key now acts the same as the control key by issuing control character codes when the command key is pressed. - We now retrieve the window pointer directly from the app delegate in LLWindow. --- indra/llwindow/CMakeLists.txt | 1 + indra/llwindow/llappdelegate-objc.h | 22 ++++++ indra/llwindow/llkeyboardmacosx.cpp | 35 ++------- indra/llwindow/llopenglview-objc.h | 5 -- indra/llwindow/llopenglview-objc.mm | 113 +++++++++++++++++++--------- indra/llwindow/llwindowmacosx-objc.h | 11 +++ indra/llwindow/llwindowmacosx-objc.mm | 56 ++++++++++---- indra/llwindow/llwindowmacosx.cpp | 22 +++--- indra/newview/CMakeLists.txt | 8 +- indra/newview/llappdelegate-objc.mm | 55 ++++++++++++++ indra/newview/llappviewermacosx-delegate.h | 22 ------ indra/newview/llappviewermacosx-delegate.mm | 57 -------------- indra/newview/llappviewermacosx-objc.h | 19 ----- indra/newview/llappviewermacosx-objc.mm | 20 ----- indra/newview/llappviewermacosx.cpp | 2 +- 15 files changed, 232 insertions(+), 216 deletions(-) create mode 100644 indra/llwindow/llappdelegate-objc.h create mode 100644 indra/newview/llappdelegate-objc.mm delete mode 100644 indra/newview/llappviewermacosx-delegate.h delete mode 100644 indra/newview/llappviewermacosx-delegate.mm delete mode 100644 indra/newview/llappviewermacosx-objc.h delete mode 100644 indra/newview/llappviewermacosx-objc.mm diff --git a/indra/llwindow/CMakeLists.txt b/indra/llwindow/CMakeLists.txt index 8a38db751e..84e0169826 100644 --- a/indra/llwindow/CMakeLists.txt +++ b/indra/llwindow/CMakeLists.txt @@ -82,6 +82,7 @@ if (DARWIN) llwindowmacosx.h llwindowmacosx-objc.h llopenglview-objc.h + llappdelegate-objc.h ) # We use a bunch of deprecated system APIs. diff --git a/indra/llwindow/llappdelegate-objc.h b/indra/llwindow/llappdelegate-objc.h new file mode 100644 index 0000000000..56b7a30797 --- /dev/null +++ b/indra/llwindow/llappdelegate-objc.h @@ -0,0 +1,22 @@ +// +// LLAppDelegate.h +// SecondLife +// +// Created by Geenz on 12/16/12. +// +// + +#import +#import "llopenglview-objc.h" +#include "llwindowmacosx-objc.h" + +@interface LLAppDelegate : NSObject { + LLNSWindow *window; + NSTimer *frameTimer; +} + +@property (assign) IBOutlet LLNSWindow *window; + +- (void) mainLoop; + +@end diff --git a/indra/llwindow/llkeyboardmacosx.cpp b/indra/llwindow/llkeyboardmacosx.cpp index 077ebea909..3db94e8835 100644 --- a/indra/llwindow/llkeyboardmacosx.cpp +++ b/indra/llwindow/llkeyboardmacosx.cpp @@ -167,13 +167,15 @@ void LLKeyboardMacOSX::resetMaskKeys() // MBW -- XXX -- This mirrors the operation of the Windows version of resetMaskKeys(). // It looks a bit suspicious, as it won't correct for keys that have been released. // Is this the way it's supposed to work? + + // We apply the modifier masks directly within getModifiers. So check to see which masks we've applied. if(mask & MAC_SHIFT_KEY) { mKeyLevel[KEY_SHIFT] = TRUE; } - if(mask & (MAC_CTRL_KEY)) + if(mask & MAC_CTRL_KEY) { mKeyLevel[KEY_CONTROL] = TRUE; } @@ -198,25 +200,9 @@ static BOOL translateKeyMac(const U16 key, const U32 mask, KEY &outKey, U32 &out MASK LLKeyboardMacOSX::updateModifiers(const U32 mask) { - // translate the mask - MASK out_mask = 0; - - if(mask & MAC_SHIFT_KEY) - { - out_mask |= MASK_SHIFT; - } - - if(mask & MAC_CTRL_KEY || mask & MAC_CMD_KEY) - { - out_mask |= MASK_CONTROL; - } - - if(mask & MAC_ALT_KEY) - { - out_mask |= MASK_ALT; - } - - return out_mask; + // This is handled for us in LLNSWindow on OS X. + + return mask; } BOOL LLKeyboardMacOSX::handleKeyDown(const U16 key, const U32 mask) @@ -231,12 +217,7 @@ BOOL LLKeyboardMacOSX::handleKeyDown(const U16 key, const U32 mask) { handled = handleTranslatedKeyDown(translated_key, translated_mask); } - if (!handled) - { - LL_INFOS("Keyboard") << "Unhandled key: " << mTranslateKeyMap[key] << LL_ENDL; - } else { - LL_INFOS("Keyboard") << "Handled key: " << mTranslateKeyMap[key] << LL_ENDL; - } + return handled; } @@ -272,7 +253,7 @@ MASK LLKeyboardMacOSX::currentMask(BOOL for_mouse_event) if (mask & MAC_CMD_KEY) result |= MASK_CONTROL; } - return result; + return mask; } void LLKeyboardMacOSX::scanKeyboard() diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 20589e321d..8412621392 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -40,8 +40,3 @@ } @end - -void setLLNSWindowRef(LLNSWindow* window); -void setLLOpenGLViewRef(LLOpenGLView* view); -LLNSWindow* winRef; -LLOpenGLView* glviewRef; diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index e5e198b856..d91601152b 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -132,62 +132,72 @@ - (void) mouseDragged:(NSEvent *)theEvent { - [super mouseDragged:theEvent]; + [_window mouseDragged:theEvent]; } - (void) scrollWheel:(NSEvent *)theEvent { - [super scrollWheel:theEvent]; + [_window scrollWheel:theEvent]; } - (void) mouseDown:(NSEvent *)theEvent { - [super mouseDown:theEvent]; + [_window mouseDown:theEvent]; } - (void) mouseUp:(NSEvent *)theEvent { - [super mouseUp:theEvent]; + [_window mouseUp:theEvent]; } - (void) rightMouseDown:(NSEvent *)theEvent { - [super rightMouseDown:theEvent]; + [_window rightMouseDown:theEvent]; } - (void) rightMouseUp:(NSEvent *)theEvent { - [super rightMouseUp:theEvent]; + [_window rightMouseUp:theEvent]; +} + +- (void) otherMouseDown:(NSEvent *)theEvent +{ + [_window otherMouseDown:theEvent]; +} + +- (void) otherMouseUp:(NSEvent *)theEvent +{ + [_window otherMouseUp:theEvent]; } - (void) keyUp:(NSEvent *)theEvent { - [super keyUp:theEvent]; + [_window keyUp:theEvent]; } - (void) keyDown:(NSEvent *)theEvent { - [super keyDown:theEvent]; + [_window keyDown:theEvent]; } - (void) mouseMoved:(NSEvent *)theEvent { - [super mouseMoved:theEvent]; + [_window mouseMoved:theEvent]; } - (void) flagsChanged:(NSEvent *)theEvent { - [super flagsChanged:theEvent]; + [_window flagsChanged:theEvent]; } - (BOOL) becomeFirstResponder { - return [super becomeFirstResponder]; + return [_window becomeFirstResponder]; } - (BOOL) resignFirstResponder { - return [super resignFirstResponder]; + return [_window resignFirstResponder]; } @end @@ -200,58 +210,99 @@ - (id) init { + //[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType, nil]]; return self; } - (void) keyDown:(NSEvent *)theEvent { - callKeyDown([theEvent keyCode], [theEvent modifierFlags]); - + callKeyDown([theEvent keyCode], mModifiers); NSString *chars = [theEvent characters]; for (uint i = 0; i < [chars length]; i++) { // Enter and Return are special cases. unichar returntest = [chars characterAtIndex:i]; - if ((returntest == NSCarriageReturnCharacter || returntest == NSEnterCharacter) && !([theEvent modifierFlags] & NSCommandKeyMask) && !([theEvent modifierFlags] & NSAlternateKeyMask) && !([theEvent modifierFlags] & NSControlKeyMask)) + if ((returntest == NSCarriageReturnCharacter || returntest == NSEnterCharacter) && + !([theEvent modifierFlags] & NSCommandKeyMask) && + !([theEvent modifierFlags] & NSAlternateKeyMask) && + !([theEvent modifierFlags] & NSControlKeyMask)) { - callUnicodeCallback(returntest, 0); + callUnicodeCallback(13, 0); } else { - callUnicodeCallback([chars characterAtIndex:i], [theEvent modifierFlags]); + // The command key being pressed is also a special case. + // Control + produces an ASCII control character code. + // Command + produces just the character's code. + // Check to see if the command key is pressed, then filter through the different character ranges that are relevant to control characters, and subtract the appropriate range. + if ([theEvent modifierFlags] & NSCommandKeyMask) + { + if (returntest >= 64 && returntest <= 95) + { + callUnicodeCallback(returntest - 63, mModifiers); + } else if (returntest >= 97 && returntest <= 122) + { + callUnicodeCallback(returntest - 96, mModifiers); + } + } else { + callUnicodeCallback(returntest, mModifiers); + } } } } - (void) keyUp:(NSEvent *)theEvent { - callKeyUp([theEvent keyCode], [theEvent modifierFlags]); + callKeyUp([theEvent keyCode], mModifiers); } - (void)flagsChanged:(NSEvent *)theEvent { - mModifiers = [theEvent modifierFlags]; + uint modifiers = [theEvent modifierFlags]; + + // Filter through our modifier keys, and only pick out the ones we care about. + + mModifiers = 0; + if (modifiers & NSCommandKeyMask) + { + mModifiers |= 0x0001; + } + + if (modifiers & NSAlternateKeyMask) + { + mModifiers |= 0x0002; + } + + if (modifiers & NSShiftKeyMask) + { + mModifiers |= 0x0004; + } + + if (modifiers & NSControlKeyMask) + { + mModifiers |= 0x0001; + } } - (void) mouseDown:(NSEvent *)theEvent { if ([theEvent clickCount] >= 2) { - callDoubleClick(mMousePos, [theEvent modifierFlags]); + callDoubleClick(mMousePos, mModifiers); } else if ([theEvent clickCount] == 1) { - callLeftMouseDown(mMousePos, [theEvent modifierFlags]); + callLeftMouseDown(mMousePos, mModifiers); } } - (void) mouseUp:(NSEvent *)theEvent { - callLeftMouseUp(mMousePos, [theEvent modifierFlags]); + callLeftMouseUp(mMousePos, mModifiers); } - (void) rightMouseDown:(NSEvent *)theEvent { - callRightMouseDown(mMousePos, [theEvent modifierFlags]); + callRightMouseDown(mMousePos, mModifiers); } - (void) rightMouseUp:(NSEvent *)theEvent { - callRightMouseUp(mMousePos, [theEvent modifierFlags]); + callRightMouseUp(mMousePos, mModifiers); } - (void)mouseMoved:(NSEvent *)theEvent @@ -292,12 +343,12 @@ - (void) otherMouseDown:(NSEvent *)theEvent { - callMiddleMouseDown(mMousePos, 0); + callMiddleMouseDown(mMousePos, mModifiers); } - (void) otherMouseUp:(NSEvent *)theEvent { - callMiddleMouseUp(mMousePos, 0); + callMiddleMouseUp(mMousePos, mModifiers); } - (void) otherMouseDragged:(NSEvent *)theEvent @@ -330,13 +381,3 @@ } @end - -void setLLNSWindowRef(LLNSWindow* window) -{ - winRef = window; -} - -void setLLOpenGLViewRef(LLOpenGLView* view) -{ - glviewRef = view; -} diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 414491f948..57b3d11296 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -38,8 +38,19 @@ typedef void *CursorRef; typedef void *NSWindowRef; typedef void *GLViewRef; +// These are defined in llappviewermacosx.cpp. +bool initViewer(); +void handleQuit(); +bool runMainLoop(); +void initMainLoop(); +void cleanupViewer(); + /* Defined in llwindowmacosx-objc.mm: */ +int createNSApp(int argc, const char **argv); void setupCocoa(); +bool pasteBoardAvailable(); +bool copyToPBoard(const unsigned short *str, unsigned int len); +const unsigned short *copyFromPBoard(); CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY); short releaseImageCursor(CursorRef ref); short setImageCursor(CursorRef ref); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 5a024eda46..1a64c94b2d 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -29,6 +29,7 @@ #include #include "llwindowmacosx-objc.h" #include "llopenglview-objc.h" +#include "llappdelegate-objc.h" /* * These functions are broken out into a separate file because the @@ -37,6 +38,11 @@ * linden headers with any objective-C++ source. */ +int createNSApp(int argc, const char *argv[]) +{ + return NSApplicationMain(argc, argv); +} + void setupCocoa() { static bool inited = false; @@ -49,15 +55,6 @@ void setupCocoa() // ie. running './secondlife -set Language fr' would cause a pop-up saying can't open document 'fr' // when init'ing the Cocoa App window. [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; - - // This is a bit of voodoo taken from the Apple sample code "CarbonCocoa_PictureCursor": - // http://developer.apple.com/samplecode/CarbonCocoa_PictureCursor/index.html - - // Needed for Carbon based applications which call into Cocoa - // NSApplicationLoad(); - - // Must first call [[[NSWindow alloc] init] release] to get the NSWindow machinery set up so that NSCursor can use a window to cache the cursor image - //[[[NSWindow alloc] init] release]; [pool release]; @@ -65,6 +62,38 @@ void setupCocoa() } } +bool copyToPBoard(const unsigned short *str, unsigned int len) +{ + NSPasteboard *pboard = [NSPasteboard generalPasteboard]; + [pboard clearContents]; + + NSArray *contentsToPaste = [[NSArray alloc] initWithObjects:[NSString stringWithCharacters:str length:len], nil]; + + return [pboard writeObjects:contentsToPaste]; +} + +bool pasteBoardAvailable() +{ + NSArray *classArray = [NSArray arrayWithObject:[NSString class]]; + return [[NSPasteboard generalPasteboard] canReadObjectForClasses:classArray options:[NSDictionary dictionary]]; +} + +const unsigned short *copyFromPBoard() +{ + NSPasteboard *pboard = [NSPasteboard generalPasteboard]; + NSArray *classArray = [NSArray arrayWithObject:[NSString class]]; + NSString *str = NULL; + BOOL ok = [pboard canReadObjectForClasses:classArray options:[NSDictionary dictionary]]; + if (ok) + { + NSArray *objToPaste = [pboard readObjectsForClasses:classArray options:[NSDictionary dictionary]]; + str = [objToPaste objectAtIndex:0]; + } + unichar* temp = (unichar*)calloc([str length], sizeof(unichar)); + [str getCharacters:temp]; + return temp; +} + CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @@ -287,15 +316,12 @@ void removeGLView(GLViewRef view) NSWindowRef getMainAppWindow() { - [(LLNSWindow*)winRef setAcceptsMouseMovedEvents:TRUE]; + LLNSWindow *winRef = [(LLAppDelegate*)[[NSApplication sharedApplication] delegate] window]; + + [winRef setAcceptsMouseMovedEvents:TRUE]; return winRef; } -GLViewRef getGLView() -{ - return glviewRef; -} - unsigned int getModifiers() { return [NSEvent modifierFlags]; diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 902391e170..93b9f4c484 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -1029,25 +1029,27 @@ void LLWindowMacOSX::flashIcon(F32 seconds) BOOL LLWindowMacOSX::isClipboardTextAvailable() { - BOOL result = false; - // TODO: Clipboard support. - return result; + return pasteBoardAvailable(); } BOOL LLWindowMacOSX::pasteTextFromClipboard(LLWString &dst) -{ - BOOL result = false; - - // TODO: Clipboard support. - - return result; +{ + llutf16string str(copyFromPBoard()); + dst = utf16str_to_wstring(str); + if (dst != L"") + { + return true; + } else { + return false; + } } BOOL LLWindowMacOSX::copyTextToClipboard(const LLWString &s) { BOOL result = false; + llutf16string utf16str = wstring_to_utf16str(s); - // TODO: Clipboard support. + result = copyToPBoard(utf16str.data(), utf16str.length()); return result; } diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 73f5ecc38c..c60940f93c 100755 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -1231,10 +1231,9 @@ source_group("CMake Rules" FILES ViewerInstall.cmake) if (DARWIN) LIST(APPEND viewer_SOURCE_FILES llappviewermacosx.cpp) - LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-objc.h) - LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-objc.mm) - LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-delegate.h) - LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-delegate.mm) + + # This should be compiled with the viewer. + LIST(APPEND viewer_SOURCE_FILES llappdelegate-objc.mm) find_library(AGL_LIBRARY AGL) find_library(APPKIT_LIBRARY AppKit) @@ -1532,6 +1531,7 @@ if (FMOD) if (DARWIN) set(fmodwrapper_SOURCE_FILES fmodwrapper.cpp) add_library(fmodwrapper SHARED ${fmodwrapper_SOURCE_FILES}) + find_library(CARBON_LIBRARY Carbon) set(fmodwrapper_needed_LIBRARIES ${FMOD_LIBRARY} ${CARBON_LIBRARY}) set_target_properties( fmodwrapper diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm new file mode 100644 index 0000000000..f5143d7578 --- /dev/null +++ b/indra/newview/llappdelegate-objc.mm @@ -0,0 +1,55 @@ +// +// LLAppDelegate.m +// SecondLife +// +// Created by Geenz on 12/16/12. +// +// + +#import "llappdelegate-objc.h" + +@implementation LLAppDelegate + +@synthesize window; + +- (void)dealloc +{ + [super dealloc]; +} + +- (void) applicationDidFinishLaunching:(NSNotification *)notification +{ + frameTimer = nil; + + if (initViewer()) + { + frameTimer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(mainLoop) userInfo:nil repeats:YES]; + } else { + handleQuit(); + } +} + +- (NSApplicationDelegateReply) applicationShouldTerminate:(NSApplication *)sender +{ + if (!runMainLoop()) + { + handleQuit(); + return NSTerminateCancel; + } else { + [frameTimer release]; + cleanupViewer(); + return NSTerminateNow; + } +} + +- (void) mainLoop +{ + bool appExiting = runMainLoop(); + if (appExiting) + { + [frameTimer release]; + [[NSApplication sharedApplication] terminate:self]; + } +} + +@end diff --git a/indra/newview/llappviewermacosx-delegate.h b/indra/newview/llappviewermacosx-delegate.h deleted file mode 100644 index 848ccbde62..0000000000 --- a/indra/newview/llappviewermacosx-delegate.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// LLAppDelegate.h -// SecondLife -// -// Created by Geenz on 12/16/12. -// -// - -#import -#import "llopenglview-objc.h" -#include "llappviewermacosx-objc.h" - -@interface LLAppDelegate : NSObject { - LLNSWindow *window; - NSTimer *frameTimer; -} - -@property (assign) IBOutlet LLNSWindow *window; - -- (void) mainLoop; - -@end diff --git a/indra/newview/llappviewermacosx-delegate.mm b/indra/newview/llappviewermacosx-delegate.mm deleted file mode 100644 index 7baeeb1de8..0000000000 --- a/indra/newview/llappviewermacosx-delegate.mm +++ /dev/null @@ -1,57 +0,0 @@ -// -// LLAppDelegate.m -// SecondLife -// -// Created by Geenz on 12/16/12. -// -// - -#import "llappviewermacosx-delegate.h" - -@implementation LLAppDelegate - -@synthesize window; - -- (void)dealloc -{ - [super dealloc]; -} - -- (void) applicationDidFinishLaunching:(NSNotification *)notification -{ - frameTimer = nil; - - setLLNSWindowRef([self window]); - - if (initViewer()) - { - frameTimer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(mainLoop) userInfo:nil repeats:YES]; - } else { - handleQuit(); - } -} - -- (NSApplicationDelegateReply) applicationShouldTerminate:(NSApplication *)sender -{ - if (!runMainLoop()) - { - handleQuit(); - return NSTerminateCancel; - } else { - [frameTimer release]; - cleanupViewer(); - return NSTerminateNow; - } -} - -- (void) mainLoop -{ - bool appExiting = runMainLoop(); - if (appExiting) - { - [frameTimer release]; - [[NSApplication sharedApplication] terminate:self]; - } -} - -@end diff --git a/indra/newview/llappviewermacosx-objc.h b/indra/newview/llappviewermacosx-objc.h deleted file mode 100644 index ed9017ca5d..0000000000 --- a/indra/newview/llappviewermacosx-objc.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// NSObject_llappviewermacosx_objc.h -// SecondLife -// -// Created by Geenz on 12/16/12. -// -// - -#include -typedef std::tr1::function VoidCallback; -typedef void* ViewerAppRef; - -int createNSApp(int argc, const char **argv); - -bool initViewer(); -void handleQuit(); -bool runMainLoop(); -void initMainLoop(); -void cleanupViewer(); \ No newline at end of file diff --git a/indra/newview/llappviewermacosx-objc.mm b/indra/newview/llappviewermacosx-objc.mm deleted file mode 100644 index ca2090b790..0000000000 --- a/indra/newview/llappviewermacosx-objc.mm +++ /dev/null @@ -1,20 +0,0 @@ -// -// llappviewermacosx.m -// SecondLife -// -// Created by Geenz on 12/12/12. -// -// - -#import -#import -#include "llappviewermacosx-objc.h" -#import "llappviewermacosx-delegate.h" - -int createNSApp(int argc, const char *argv[]) -{ - return NSApplicationMain(argc, argv); -} - - - diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp index 6e7b91347b..b199405a66 100644 --- a/indra/newview/llappviewermacosx.cpp +++ b/indra/newview/llappviewermacosx.cpp @@ -31,7 +31,7 @@ #endif #include "llappviewermacosx.h" -#include "llappviewermacosx-objc.h" +#include "llwindowmacosx-objc.h" #include "llcommandlineparser.h" #include "llmemtype.h" -- cgit v1.2.3 From da90fe352847d5f27358179cb4cdf88abc40a4af Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 15 Jan 2013 05:46:31 -0500 Subject: This *should* put an end to our modifier key woes. --- indra/llwindow/llkeyboardmacosx.cpp | 27 +- indra/llwindow/llopenglview-objc.mm | 31 +- indra/newview/SecondLife.nib | Bin 15670 -> 8541 bytes indra/newview/SecondLife.xib | 957 ++---------------------------------- 4 files changed, 68 insertions(+), 947 deletions(-) diff --git a/indra/llwindow/llkeyboardmacosx.cpp b/indra/llwindow/llkeyboardmacosx.cpp index 3db94e8835..59cc2acaec 100644 --- a/indra/llwindow/llkeyboardmacosx.cpp +++ b/indra/llwindow/llkeyboardmacosx.cpp @@ -200,9 +200,25 @@ static BOOL translateKeyMac(const U16 key, const U32 mask, KEY &outKey, U32 &out MASK LLKeyboardMacOSX::updateModifiers(const U32 mask) { - // This is handled for us in LLNSWindow on OS X. - - return mask; + // translate the mask + MASK out_mask = 0; + + if(mask & MAC_SHIFT_KEY) + { + out_mask |= MASK_SHIFT; + } + + if(mask & MAC_CTRL_KEY || mask & MAC_CMD_KEY) + { + out_mask |= MASK_CONTROL; + } + + if(mask & MAC_ALT_KEY) + { + out_mask |= MASK_ALT; + } + + return out_mask; } BOOL LLKeyboardMacOSX::handleKeyDown(const U16 key, const U32 mask) @@ -232,6 +248,7 @@ BOOL LLKeyboardMacOSX::handleKeyUp(const U16 key, const U32 mask) if(translateNumpadKey(key, &translated_key)) { + LL_INFOS("Keyboard") << "Handled key!" << LL_ENDL; handled = handleTranslatedKeyUp(translated_key, translated_mask); } @@ -252,8 +269,8 @@ MASK LLKeyboardMacOSX::currentMask(BOOL for_mouse_event) { if (mask & MAC_CMD_KEY) result |= MASK_CONTROL; } - - return mask; + + return result; } void LLKeyboardMacOSX::scanKeyboard() diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index d91601152b..25669b25d3 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -190,6 +190,11 @@ [_window flagsChanged:theEvent]; } +- (void) mouseExited:(NSEvent *)theEvent +{ + [_window mouseExited:theEvent]; +} + - (BOOL) becomeFirstResponder { return [_window becomeFirstResponder]; @@ -217,6 +222,7 @@ - (void) keyDown:(NSEvent *)theEvent { callKeyDown([theEvent keyCode], mModifiers); + NSLog(@"Keycode: %hu", [theEvent keyCode]); NSString *chars = [theEvent characters]; for (uint i = 0; i < [chars length]; i++) { @@ -254,30 +260,7 @@ } - (void)flagsChanged:(NSEvent *)theEvent { - uint modifiers = [theEvent modifierFlags]; - - // Filter through our modifier keys, and only pick out the ones we care about. - - mModifiers = 0; - if (modifiers & NSCommandKeyMask) - { - mModifiers |= 0x0001; - } - - if (modifiers & NSAlternateKeyMask) - { - mModifiers |= 0x0002; - } - - if (modifiers & NSShiftKeyMask) - { - mModifiers |= 0x0004; - } - - if (modifiers & NSControlKeyMask) - { - mModifiers |= 0x0001; - } + mModifiers = [theEvent modifierFlags]; } - (void) mouseDown:(NSEvent *)theEvent diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib index cd69b1b812..ca89033300 100644 Binary files a/indra/newview/SecondLife.nib and b/indra/newview/SecondLife.nib differ diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib index 212bc5830d..b4e77279fd 100644 --- a/indra/newview/SecondLife.xib +++ b/indra/newview/SecondLife.xib @@ -193,29 +193,6 @@ - - - Open Recent - - 2147483647 - - - submenuAction: - - Open Recent - - - - Clear Menu - - 2147483647 - - - - - _NSRecentDocumentsMenu - - YES @@ -235,52 +212,6 @@ - - - Save… - s - 1048576 - 2147483647 - - - - - - Revert to Saved - - 2147483647 - - - - - - YES - YES - - - 2147483647 - - - - - - Page Setup... - P - 1179648 - 2147483647 - - - - - - - Print… - p - 1048576 - 2147483647 - - - @@ -350,23 +281,6 @@ - - - Paste and Match Style - V - 1572864 - 2147483647 - - - - - - Delete - - 2147483647 - - - Select All @@ -376,303 +290,6 @@ - - - YES - YES - - - 2147483647 - - - - - - Find - - 2147483647 - - - submenuAction: - - Find - - - - Find… - f - 1048576 - 2147483647 - - - 1 - - - - Find and Replace… - f - 1572864 - 2147483647 - - - 12 - - - - Find Next - g - 1048576 - 2147483647 - - - 2 - - - - Find Previous - G - 1048576 - 2147483647 - - - 3 - - - - Use Selection for Find - e - 1048576 - 2147483647 - - - 7 - - - - Jump to Selection - j - 1048576 - 2147483647 - - - - - - - - - Spelling and Grammar - - 2147483647 - - - submenuAction: - - Spelling - - - - Show Spelling and Grammar - : - 1048576 - 2147483647 - - - - - - Check Document Now - ; - 1048576 - 2147483647 - - - - - - YES - YES - - - 2147483647 - - - - - - Check Spelling While Typing - - 2147483647 - - - - - - Check Grammar With Spelling - - 2147483647 - - - - - - Correct Spelling Automatically - - 2147483647 - - - - - - - - - Substitutions - - 2147483647 - - - submenuAction: - - Substitutions - - - - Show Substitutions - - 2147483647 - - - - - - YES - YES - - - 2147483647 - - - - - - Smart Copy/Paste - - 2147483647 - - - - - - Smart Quotes - - 2147483647 - - - - - - Smart Dashes - - 2147483647 - - - - - - Smart Links - - 2147483647 - - - - - - Data Detectors - - 2147483647 - - - - - - Text Replacement - - 2147483647 - - - - - - - - - Transformations - - 2147483647 - - - submenuAction: - - Transformations - - - - Make Upper Case - - 2147483647 - - - - - - Make Lower Case - - 2147483647 - - - - - - Capitalize - - 2147483647 - - - - - - - - - Speech - - 2147483647 - - - submenuAction: - - Speech - - - - Start Speaking - - 2147483647 - - - - - - Stop Speaking - - 2147483647 - - - - - - @@ -776,13 +393,10 @@ {1024, 768} - + 256 {1024, 768} - - - _NS:20 {{0, 0}, {1920, 1178}} @@ -834,30 +448,6 @@ 39 - - - print: - - - - 86 - - - - runPageLayout: - - - - 87 - - - - clearRecentDocuments: - - - - 127 - performClose: @@ -882,22 +472,6 @@ 360 - - - saveDocument: - - - - 362 - - - - revertDocumentToSaved: - - - - 364 - hide: @@ -938,38 +512,6 @@ 769 - - - toggleSmartInsertDelete: - - - - 770 - - - - toggleAutomaticDashSubstitution: - - - - 773 - - - - toggleContinuousSpellChecking: - - - - 774 - - - - toggleAutomaticDataDetection: - - - - 775 - undo: @@ -978,30 +520,6 @@ 776 - - - startSpeaking: - - - - 778 - - - - showGuessPanel: - - - - 779 - - - - checkSpelling: - - - - 780 - copy: @@ -1010,14 +528,6 @@ 782 - - - delete: - - - - 783 - selectAll: @@ -1026,38 +536,6 @@ 785 - - - stopSpeaking: - - - - 786 - - - - orderFrontSubstitutionsPanel: - - - - 787 - - - - toggleAutomaticTextReplacement: - - - - 788 - - - - toggleAutomaticSpellingCorrection: - - - - 790 - toggleFullScreen: @@ -1150,85 +628,18 @@ 81 - - - - - - - - 75 - - - - - 78 - - - - - 72 - - - - - 82 - - - - - 124 - - - - - - - - 77 - - - 73 - - 79 - - - - - 112 - - - - - 74 - - - - - 125 - - - - - - - - 126 - - - 106 @@ -1373,33 +784,10 @@ - - - - - - - - - - 713 - - - - - 714 - - - - - 715 - - - 716 @@ -1415,251 +803,11 @@ - - 719 - - - - - 720 - - - 721 - - 722 - - - - - 723 - - - - - - - - 724 - - - - - - - - 725 - - - - - - - - 726 - - - - - - - - 727 - - - - - - - - 738 - - - - - - - - - 739 - - - - - 740 - - - - - 741 - - - - - - - - - - 742 - - - - - 743 - - - - - 744 - - - - - 745 - - - - - - - - - - - - - - - 746 - - - - - 747 - - - - - 748 - - - - - 749 - - - - - 750 - - - - - 751 - - - - - 752 - - - - - 753 - - - - - 754 - - - - - - - - - - - - - 755 - - - - - 756 - - - - - 757 - - - - - 758 - - - - - 759 - - - - - 760 - - - - - 761 - - - - - - - - - - - - - 762 - - - - - 763 - - - - - 764 - - - - - 765 - - - - - 766 - - - - - 821 - - - 824 @@ -1684,6 +832,36 @@ + + 713 + + + + + 714 + + + + + 715 + + + + + 82 + + + + + 79 + + + + + 72 + + + @@ -1693,10 +871,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1725,54 +899,12 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1794,20 +926,17 @@ LLAppDelegate NSObject - - LLOpenGLView - LLNSWindow - - - - glview - LLOpenGLView - - + + window + LLNSWindow + + + window + window LLNSWindow - + IBProjectSource ./Classes/LLAppDelegate.h @@ -1821,14 +950,6 @@ ./Classes/LLNSWindow.h - - LLOpenGLView - NSOpenGLView - - IBProjectSource - ./Classes/LLOpenGLView.h - - 0 -- cgit v1.2.3 From 9557a26c623f01f662b8d3dd5b933285b7bfaeb1 Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 15 Jan 2013 16:34:54 -0500 Subject: OS X 10.7+'s Autosave functionality now handles window restoration. --- indra/newview/SecondLife.nib | Bin 8541 -> 8573 bytes indra/newview/SecondLife.xib | 6 +++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib index ca89033300..0d59d59bb2 100644 Binary files a/indra/newview/SecondLife.nib and b/indra/newview/SecondLife.nib differ diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib index b4e77279fd..b02d04e0d2 100644 --- a/indra/newview/SecondLife.xib +++ b/indra/newview/SecondLife.xib @@ -393,15 +393,19 @@ {1024, 768} - + 256 {1024, 768} + + + _NS:20 {{0, 0}, {1920, 1178}} {1024, 790} {10000000000000, 10000000000000} + Second Life 128 YES -- cgit v1.2.3 From 1bbbaf8dd69a08a3e7c570e6ad14f57a4f6e91cb Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 18 Jan 2013 13:16:12 -0500 Subject: Partial workaround for mouse delta issue. --- indra/llwindow/llwindowmacosx.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 93b9f4c484..95ad87d58f 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -285,8 +285,9 @@ void callMouseMoved(float *pos, MASK mask) gWindowImplementation->getMouseDeltas(deltas); outCoords.mX += deltas[0]; outCoords.mY += deltas[1]; + LL_INFOS("Mouse Movement") << "Moved coords: " << outCoords.mX << ", " << outCoords.mY << LL_ENDL; gWindowImplementation->getCallbacks()->handleMouseMove(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); - + gWindowImplementation->getCallbacks()->handleScrollWheel(gWindowImplementation, 0); } void callScrollMoved(float delta) @@ -343,7 +344,7 @@ void LLWindowMacOSX::updateMouseDeltas(float* deltas) if (mCursorDecoupled) { mCursorLastEventDeltaX = llround(deltas[0]); - mCursorLastEventDeltaY = llround(deltas[1]); + mCursorLastEventDeltaY = llround(-deltas[1]); if (mCursorIgnoreNextDelta) { @@ -351,7 +352,6 @@ void LLWindowMacOSX::updateMouseDeltas(float* deltas) mCursorLastEventDeltaY = 0; mCursorIgnoreNextDelta = FALSE; } - LL_INFOS("Delta Update") << "Last event delta: " << mCursorLastEventDeltaX << ", " << mCursorLastEventDeltaY << LL_ENDL; } else { mCursorLastEventDeltaX = 0; mCursorLastEventDeltaY = 0; @@ -738,7 +738,7 @@ void LLWindowMacOSX::swapBuffers() F32 LLWindowMacOSX::getGamma() { - F32 result = 1.8; // Default to something sane + F32 result = 2.2; // Default to something sane CGGammaValue redMin; CGGammaValue redMax; -- cgit v1.2.3 From 29e747c4f17818816c502a3aa653b828e689be4a Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 22 Jan 2013 15:37:01 -0500 Subject: And thus, the demonic mouse position conversions from view space to screen space were tamed. --- indra/llcommon/llsys.cpp | 2 +- indra/llwindow/llopenglview-objc.h | 22 +++++++++++++++ indra/llwindow/llopenglview-objc.mm | 50 +++++++++++++++++++++++++++++++++++ indra/llwindow/llwindowmacosx-objc.mm | 2 +- indra/newview/llappviewermacosx.cpp | 2 +- 5 files changed, 75 insertions(+), 3 deletions(-) diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp index c96f2191f3..2a8eea88b6 100644 --- a/indra/llcommon/llsys.cpp +++ b/indra/llcommon/llsys.cpp @@ -67,7 +67,7 @@ using namespace llsd; # include # include # include -# include +# include # include # include # include diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 8412621392..dd2f35aafc 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -39,4 +39,26 @@ unsigned int mModifiers; } +- (NSPoint)convertToScreenFromLocalPoint:(NSPoint)point relativeToView:(NSView *)view; +- (NSPoint)flipPoint:(NSPoint)aPoint; + +@end + +@interface NSScreen (PointConversion) + +/* + Returns the screen where the mouse resides + */ ++ (NSScreen *)currentScreenForMouseLocation; + +/* + Allows you to convert a point from global coordinates to the current screen coordinates. + */ +- (NSPoint)convertPointToScreenCoordinates:(NSPoint)aPoint; + +/* + Allows to flip the point coordinates, so y is 0 at the top instead of the bottom. x remains the same + */ +- (NSPoint)flipPoint:(NSPoint)aPoint; + @end diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 25669b25d3..ca66143b78 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -8,6 +8,35 @@ #import "llopenglview-objc.h" +@implementation NSScreen (PointConversion) + ++ (NSScreen *)currentScreenForMouseLocation +{ + NSPoint mouseLocation = [NSEvent mouseLocation]; + + NSEnumerator *screenEnumerator = [[NSScreen screens] objectEnumerator]; + NSScreen *screen; + while ((screen = [screenEnumerator nextObject]) && !NSMouseInRect(mouseLocation, screen.frame, NO)) + ; + + return screen; +} + +- (NSPoint)convertPointToScreenCoordinates:(NSPoint)aPoint +{ + float normalizedX = fabs(fabs(self.frame.origin.x) - fabs(aPoint.x)); + float normalizedY = aPoint.y - self.frame.origin.y; + + return NSMakePoint(normalizedX, normalizedY); +} + +- (NSPoint)flipPoint:(NSPoint)aPoint +{ + return NSMakePoint(aPoint.x, self.frame.size.height - aPoint.y); +} + +@end + @implementation LLOpenGLView - (void)viewDidMoveToWindow @@ -349,6 +378,27 @@ callMouseExit(); } +- (NSPoint)convertToScreenFromLocalPoint:(NSPoint)point relativeToView:(NSView *)view +{ + NSScreen *currentScreen = [NSScreen currentScreenForMouseLocation]; + if(currentScreen) + { + NSPoint windowPoint = [view convertPoint:point toView:nil]; + NSPoint screenPoint = [[view window] convertBaseToScreen:windowPoint]; + NSPoint flippedScreenPoint = [currentScreen flipPoint:screenPoint]; + flippedScreenPoint.y += [currentScreen frame].origin.y; + + return flippedScreenPoint; + } + + return NSZeroPoint; +} + +- (NSPoint)flipPoint:(NSPoint)aPoint +{ + return NSMakePoint(aPoint.x, self.frame.size.height - aPoint.y); +} + - (BOOL) becomeFirstResponder { NSLog(@"Window gained focus!"); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 1a64c94b2d..b6e5767203 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -298,7 +298,7 @@ void convertWindowToScreen(NSWindowRef window, float *coord) NSPoint point; point.x = coord[0]; point.y = coord[1]; - point = [(LLNSWindow*)window convertBaseToScreen:point]; + point = [(LLNSWindow*)window convertToScreenFromLocalPoint:point relativeToView:[(LLNSWindow*)window contentView]]; coord[0] = point.x; coord[1] = point.y; } diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp index b199405a66..6e0becb518 100644 --- a/indra/newview/llappviewermacosx.cpp +++ b/indra/newview/llappviewermacosx.cpp @@ -41,7 +41,7 @@ #include "llmd5.h" #include "llfloaterworldmap.h" #include "llurldispatcher.h" -#include +#include #include "lldir.h" #include #include // for systemwide mute -- cgit v1.2.3 From 461ab912a58b67579fffdf70ec7e38d682927185 Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 22 Jan 2013 19:59:49 -0500 Subject: Initial Cocoa drag and drop support. --- indra/llwindow/llopenglview-objc.h | 1 + indra/llwindow/llopenglview-objc.mm | 50 ++++++++- indra/llwindow/llwindowmacosx-objc.h | 15 ++- indra/llwindow/llwindowmacosx-objc.mm | 6 ++ indra/llwindow/llwindowmacosx.cpp | 186 +++++++++++++--------------------- indra/llwindow/llwindowmacosx.h | 16 +-- 6 files changed, 143 insertions(+), 131 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index dd2f35aafc..1592e6e01d 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -15,6 +15,7 @@ @interface LLOpenGLView : NSOpenGLView { NSPoint mousePos; + std::string mLastDraggedUrl; } - (id) initWithFrame:(NSRect)frame withSamples:(NSUInteger)samples andVsync:(BOOL)vsync; diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index ca66143b78..763cf0c981 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -61,12 +61,13 @@ - (id) init { + //[self registerForDraggedTypes:[NSArray arrayWithObjects:NSURLPboardType, NSFilenamesPboardType, nil]]; return [self initWithFrame:[self bounds] withSamples:2 andVsync:TRUE]; } - (id) initWithFrame:(NSRect)frame withSamples:(NSUInteger)samples andVsync:(BOOL)vsync { - + [self registerForDraggedTypes:[NSArray arrayWithObject:NSURLPboardType]]; [self initWithFrame:frame]; // Initialize with a default "safe" pixel format that will work with versions dating back to OS X 10.6. @@ -234,6 +235,49 @@ return [_window resignFirstResponder]; } +- (NSDragOperation) draggingEntered:(id)sender +{ + NSPasteboard *pboard; + NSDragOperation sourceDragMask; + + sourceDragMask = [sender draggingSourceOperationMask]; + + pboard = [sender draggingPasteboard]; + + if ([[pboard types] containsObject:NSURLPboardType]) + { + if (sourceDragMask & NSDragOperationLink) { + NSURL *fileUrl = [[pboard readObjectsForClasses:[NSArray arrayWithObject:[NSURL class]] options:[NSDictionary dictionary]] objectAtIndex:0]; + mLastDraggedUrl = [[fileUrl absoluteString] UTF8String]; + return NSDragOperationLink; + } + } + return NSDragOperationNone; +} + +- (NSDragOperation)draggingUpdated:(id )sender +{ + callHandleDragUpdated(mLastDraggedUrl); + + return NSDragOperationLink; +} + +- (void) draggingExited:(id)sender +{ + callHandleDragExited(mLastDraggedUrl); +} + +- (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender +{ + return YES; +} + +- (BOOL) performDragOperation:(id)sender +{ + callHandleDragDropped(mLastDraggedUrl); + return true; +} + @end // We use a custom NSWindow for our event handling. @@ -244,7 +288,7 @@ - (id) init { - //[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType, nil]]; + return self; } @@ -378,6 +422,8 @@ callMouseExit(); } + + - (NSPoint)convertToScreenFromLocalPoint:(NSPoint)point relativeToView:(NSView *)view { NSScreen *currentScreen = [NSScreen currentScreenForMouseLocation]; diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 57b3d11296..ebc1633f9d 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -24,14 +24,6 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include -typedef std::tr1::function KeyCallback; -typedef std::tr1::function ModifierCallback; -typedef std::tr1::function MouseCallback; -typedef std::tr1::function UnicodeCallback; -typedef std::tr1::function ResizeCallback; -typedef std::tr1::function ScrollWheelCallback; -typedef std::tr1::function VoidCallback; // This will actually hold an NSCursor*, but that type is only available in objective C. typedef void *CursorRef; @@ -59,6 +51,7 @@ void setIBeamCursor(); void setPointingHandCursor(); void setCopyCursor(); void setCrossCursor(); +void setNotAllowedCursor(); void hideNSCursor(); void showNSCursor(); void hideNSCursorTillMove(bool hide); @@ -103,6 +96,12 @@ void callMiddleMouseUp(float *pos, unsigned int mask); void callFocus(); void callFocusLost(); +#include +void callHandleDragEntered(std::string url); +void callHandleDragExited(std::string url); +void callHandleDragUpdated(std::string url); +void callHandleDragDropped(std::string url); + NSWindowRef getMainAppWindow(); GLViewRef getGLView(); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index b6e5767203..7867226476 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -143,6 +143,12 @@ void setCrossCursor() [cursor set]; } +void setNotAllowedCursor() +{ + NSCursor *cursor = [NSCursor operationNotAllowedCursor]; + [cursor set]; +} + void hideNSCursor() { [NSCursor hide]; diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 95ad87d58f..f25fc82896 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -248,7 +248,6 @@ void callLeftMouseDown(float *pos, MASK mask) outCoords.mX = llround(pos[0]); outCoords.mY = llround(pos[1]); gWindowImplementation->getCallbacks()->handleMouseDown(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); - LL_INFOS("Window") << outCoords.mX << ", " << outCoords.mY << LL_ENDL; } void callLeftMouseUp(float *pos, MASK mask) @@ -285,7 +284,6 @@ void callMouseMoved(float *pos, MASK mask) gWindowImplementation->getMouseDeltas(deltas); outCoords.mX += deltas[0]; outCoords.mY += deltas[1]; - LL_INFOS("Mouse Movement") << "Moved coords: " << outCoords.mX << ", " << outCoords.mY << LL_ENDL; gWindowImplementation->getCallbacks()->handleMouseMove(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); gWindowImplementation->getCallbacks()->handleScrollWheel(gWindowImplementation, 0); } @@ -339,6 +337,26 @@ void callMiddleMouseUp(float *pos, MASK mask) gWindowImplementation->getCallbacks()->handleMiddleMouseUp(gWindowImplementation, outCoords, mask); } +void callHandleDragEntered(std::string url) +{ + gWindowImplementation->handleDragNDrop(url, LLWindowCallbacks::DNDA_START_TRACKING); +} + +void callHandleDragExited(std::string url) +{ + gWindowImplementation->handleDragNDrop(url, LLWindowCallbacks::DNDA_STOP_TRACKING); +} + +void callHandleDragUpdated(std::string url) +{ + gWindowImplementation->handleDragNDrop(url, LLWindowCallbacks::DNDA_TRACK); +} + +void callHandleDragDropped(std::string url) +{ + gWindowImplementation->handleDragNDrop(url, LLWindowCallbacks::DNDA_DROPPED); +} + void LLWindowMacOSX::updateMouseDeltas(float* deltas) { if (mCursorDecoupled) @@ -1784,7 +1802,6 @@ S16 LLWindowMacOSX::dragTrackingHandler(DragTrackingMessage message, WindowRef t return result; } - OSErr LLWindowMacOSX::dragReceiveHandler(WindowRef theWindow, void * handlerRefCon, DragRef drag) { @@ -1792,126 +1809,69 @@ OSErr LLWindowMacOSX::dragReceiveHandler(WindowRef theWindow, void * handlerRefC return self->handleDragNDrop(drag, LLWindowCallbacks::DNDA_DROPPED); } - -OSErr LLWindowMacOSX::handleDragNDrop(DragRef drag, LLWindowCallbacks::DragNDropAction action) +*/ +void LLWindowMacOSX::handleDragNDrop(std::string url, LLWindowCallbacks::DragNDropAction action) { - OSErr result = dragNotAcceptedErr; // overall function result - OSErr err = noErr; // for local error handling - - // Get the mouse position and modifiers of this drag. - SInt16 modifiers, mouseDownModifiers, mouseUpModifiers; - ::GetDragModifiers(drag, &modifiers, &mouseDownModifiers, &mouseUpModifiers); - MASK mask = LLWindowMacOSX::modifiersToMask(modifiers); + MASK mask = LLWindowMacOSX::modifiersToMask(getModifiers()); - Point mouse_point; + float mouse_point[2]; // This will return the mouse point in global screen coords - ::GetDragMouse(drag, &mouse_point, NULL); - LLCoordScreen screen_coords(mouse_point.h, mouse_point.v); + getCursorPos(mWindow, mouse_point); + LLCoordScreen screen_coords(mouse_point[0], mouse_point[1]); LLCoordGL gl_pos; convertCoords(screen_coords, &gl_pos); - - // Look at the pasteboard and try to extract an URL from it - PasteboardRef pasteboard; - if(GetDragPasteboard(drag, &pasteboard) == noErr) + + if(!url.empty()) { - ItemCount num_items = 0; - // Treat an error here as an item count of 0 - (void)PasteboardGetItemCount(pasteboard, &num_items); - - // Only deal with single-item drags. - if(num_items == 1) - { - PasteboardItemID item_id = NULL; - CFArrayRef flavors = NULL; - CFDataRef data = NULL; - - err = PasteboardGetItemIdentifier(pasteboard, 1, &item_id); // Yes, this really is 1-based. - - // Try to extract an URL from the pasteboard - if(err == noErr) - { - err = PasteboardCopyItemFlavors( pasteboard, item_id, &flavors); - } - - if(err == noErr) - { - if(CFArrayContainsValue(flavors, CFRangeMake(0, CFArrayGetCount(flavors)), kUTTypeURL)) - { - // This is an URL. - err = PasteboardCopyItemFlavorData(pasteboard, item_id, kUTTypeURL, &data); - } - else if(CFArrayContainsValue(flavors, CFRangeMake(0, CFArrayGetCount(flavors)), kUTTypeUTF8PlainText)) + LLWindowCallbacks::DragNDropResult res = + mCallbacks->handleDragNDrop(this, gl_pos, mask, action, url); + + switch (res) { + case LLWindowCallbacks::DND_NONE: // No drop allowed + if (action == LLWindowCallbacks::DNDA_TRACK) { - // This is a string that might be an URL. - err = PasteboardCopyItemFlavorData(pasteboard, item_id, kUTTypeUTF8PlainText, &data); + mDragOverrideCursor = 0; } - - } - - if(flavors != NULL) - { - CFRelease(flavors); - } - - if(data != NULL) - { - std::string url; - url.assign((char*)CFDataGetBytePtr(data), CFDataGetLength(data)); - CFRelease(data); - - if(!url.empty()) - { - LLWindowCallbacks::DragNDropResult res = - mCallbacks->handleDragNDrop(this, gl_pos, mask, action, url); - - switch (res) { - case LLWindowCallbacks::DND_NONE: // No drop allowed - if (action == LLWindowCallbacks::DNDA_TRACK) - { - mDragOverrideCursor = kThemeNotAllowedCursor; - } - else { - mDragOverrideCursor = -1; - } - break; - case LLWindowCallbacks::DND_MOVE: // Drop accepted would result in a "move" operation - mDragOverrideCursor = kThemePointingHandCursor; - result = noErr; - break; - case LLWindowCallbacks::DND_COPY: // Drop accepted would result in a "copy" operation - mDragOverrideCursor = kThemeCopyArrowCursor; - result = noErr; - break; - case LLWindowCallbacks::DND_LINK: // Drop accepted would result in a "link" operation: - mDragOverrideCursor = kThemeAliasArrowCursor; - result = noErr; - break; - default: - mDragOverrideCursor = -1; - break; - } - // This overrides the cursor being set by setCursor. - // This is a bit of a hack workaround because lots of areas - // within the viewer just blindly set the cursor. - if (mDragOverrideCursor == -1) - { - // Restore the cursor - ECursorType temp_cursor = mCurrentCursor; - // get around the "setting the same cursor" code in setCursor() - mCurrentCursor = UI_CURSOR_COUNT; - setCursor(temp_cursor); - } - else { - // Override the cursor - SetThemeCursor(mDragOverrideCursor); - } - + else { + mDragOverrideCursor = -1; } - } + break; + case LLWindowCallbacks::DND_MOVE: // Drop accepted would result in a "move" operation + mDragOverrideCursor = UI_CURSOR_NO; + break; + case LLWindowCallbacks::DND_COPY: // Drop accepted would result in a "copy" operation + mDragOverrideCursor = UI_CURSOR_ARROWCOPY; + break; + default: + mDragOverrideCursor = -1; + break; + } + // This overrides the cursor being set by setCursor. + // This is a bit of a hack workaround because lots of areas + // within the viewer just blindly set the cursor. + if (mDragOverrideCursor == -1) + { + // Restore the cursor + ECursorType temp_cursor = mCurrentCursor; + // get around the "setting the same cursor" code in setCursor() + mCurrentCursor = UI_CURSOR_COUNT; + setCursor(temp_cursor); + } + else { + // Override the cursor + switch (mDragOverrideCursor) { + case 0: + setArrowCursor(); + break; + case UI_CURSOR_NO: + setNotAllowedCursor(); + case UI_CURSOR_ARROWCOPY: + setCopyCursor(); + default: + break; + }; } } - - return result; } -*/ + #endif // LL_OS_DRAGDROP_ENABLED diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h index c5e1b2290b..14d6e70fb3 100644 --- a/indra/llwindow/llwindowmacosx.h +++ b/indra/llwindow/llwindowmacosx.h @@ -123,7 +123,8 @@ public: void updateMouseDeltas(float* deltas); void getMouseDeltas(float* delta); - + + void handleDragNDrop(std::string url, LLWindowCallbacks::DragNDropAction action); protected: LLWindowMacOSX(LLWindowCallbacks* callbacks, @@ -164,12 +165,11 @@ protected: static MASK modifiersToMask(S16 modifiers); #if LL_OS_DRAGDROP_ENABLED - /* - static OSErr dragTrackingHandler(DragTrackingMessage message, WindowRef theWindow, - void * handlerRefCon, DragRef theDrag); - static OSErr dragReceiveHandler(WindowRef theWindow, void * handlerRefCon, DragRef theDrag); - OSErr handleDragNDrop(DragRef theDrag, LLWindowCallbacks::DragNDropAction action); - */ + + //static OSErr dragTrackingHandler(DragTrackingMessage message, WindowRef theWindow, void * handlerRefCon, DragRef theDrag); + //static OSErr dragReceiveHandler(WindowRef theWindow, void * handlerRefCon, DragRef theDrag); + + #endif // LL_OS_DRAGDROP_ENABLED // @@ -202,7 +202,7 @@ protected: U32 mFSAASamples; BOOL mForceRebuild; - S32 mDragOverrideCursor; + S32 mDragOverrideCursor; F32 mBounceTime; //NMRec mBounceRec; -- cgit v1.2.3 From c52e6f9c597c67637045134d808a9039f85efc5c Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 23 Jan 2013 09:29:32 -0500 Subject: Refactor the key input handling to make it easier to filter out keys we don't need unicode characters for (such as the arrow keys). --- indra/llwindow/llopenglview-objc.h | 1 - indra/llwindow/llopenglview-objc.mm | 67 ++++++++++++++++++++--------------- indra/llwindow/llwindowmacosx-objc.mm | 6 +++- indra/newview/llappdelegate-objc.mm | 10 ++++++ 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 1592e6e01d..cc1618b3bc 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -14,7 +14,6 @@ @interface LLOpenGLView : NSOpenGLView { - NSPoint mousePos; std::string mLastDraggedUrl; } diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 763cf0c981..b79b7b3fa5 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -294,37 +294,48 @@ - (void) keyDown:(NSEvent *)theEvent { - callKeyDown([theEvent keyCode], mModifiers); - NSLog(@"Keycode: %hu", [theEvent keyCode]); - NSString *chars = [theEvent characters]; - for (uint i = 0; i < [chars length]; i++) - { - // Enter and Return are special cases. - unichar returntest = [chars characterAtIndex:i]; - if ((returntest == NSCarriageReturnCharacter || returntest == NSEnterCharacter) && - !([theEvent modifierFlags] & NSCommandKeyMask) && - !([theEvent modifierFlags] & NSAlternateKeyMask) && - !([theEvent modifierFlags] & NSControlKeyMask)) - { - callUnicodeCallback(13, 0); - } else { - // The command key being pressed is also a special case. - // Control + produces an ASCII control character code. - // Command + produces just the character's code. - // Check to see if the command key is pressed, then filter through the different character ranges that are relevant to control characters, and subtract the appropriate range. - if ([theEvent modifierFlags] & NSCommandKeyMask) - { - if (returntest >= 64 && returntest <= 95) - { - callUnicodeCallback(returntest - 63, mModifiers); - } else if (returntest >= 97 && returntest <= 122) + uint keycode = [theEvent keyCode]; + + switch (keycode) { + case 0x7b: + case 0x7c: + case 0x7d: + case 0x7e: + callKeyDown(keycode, mModifiers); + break; + + default: + callKeyDown(keycode, mModifiers); + NSString *chars = [theEvent characters]; + for (uint i = 0; i < [chars length]; i++) { + // Enter and Return are special cases. + unichar returntest = [chars characterAtIndex:i]; + if ((returntest == NSCarriageReturnCharacter || returntest == NSEnterCharacter) && + !([theEvent modifierFlags] & NSCommandKeyMask) && + !([theEvent modifierFlags] & NSAlternateKeyMask) && + !([theEvent modifierFlags] & NSControlKeyMask)) { - callUnicodeCallback(returntest - 96, mModifiers); + callUnicodeCallback(13, 0); + } else { + // The command key being pressed is also a special case. + // Control + produces an ASCII control character code. + // Command + produces just the character's code. + // Check to see if the command key is pressed, then filter through the different character ranges that are relevant to control characters, and subtract the appropriate range. + if ([theEvent modifierFlags] & NSCommandKeyMask) + { + if (returntest >= 64 && returntest <= 95) + { + callUnicodeCallback(returntest - 63, mModifiers); + } else if (returntest >= 97 && returntest <= 122) + { + callUnicodeCallback(returntest - 96, mModifiers); + } + } else { + callUnicodeCallback(returntest, mModifiers); + } } - } else { - callUnicodeCallback(returntest, mModifiers); } - } + break; } } diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 7867226476..b123ba0711 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -64,11 +64,12 @@ void setupCocoa() bool copyToPBoard(const unsigned short *str, unsigned int len) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; NSPasteboard *pboard = [NSPasteboard generalPasteboard]; [pboard clearContents]; NSArray *contentsToPaste = [[NSArray alloc] initWithObjects:[NSString stringWithCharacters:str length:len], nil]; - + [pool release]; return [pboard writeObjects:contentsToPaste]; } @@ -80,6 +81,7 @@ bool pasteBoardAvailable() const unsigned short *copyFromPBoard() { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; NSPasteboard *pboard = [NSPasteboard generalPasteboard]; NSArray *classArray = [NSArray arrayWithObject:[NSString class]]; NSString *str = NULL; @@ -91,6 +93,7 @@ const unsigned short *copyFromPBoard() } unichar* temp = (unichar*)calloc([str length], sizeof(unichar)); [str getCharacters:temp]; + [pool release]; return temp; } @@ -312,6 +315,7 @@ void convertWindowToScreen(NSWindowRef window, float *coord) void closeWindow(NSWindowRef window) { [(LLNSWindow*)window close]; + [(LLNSWindow*)window release]; } void removeGLView(GLViewRef view) diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm index f5143d7578..9bb10f3204 100644 --- a/indra/newview/llappdelegate-objc.mm +++ b/indra/newview/llappdelegate-objc.mm @@ -29,6 +29,16 @@ } } +- (void) applicationDidBecomeActive:(NSNotification *)notification +{ + +} + +- (void) applicationDidResignActive:(NSNotification *)notification +{ + +} + - (NSApplicationDelegateReply) applicationShouldTerminate:(NSApplication *)sender { if (!runMainLoop()) -- cgit v1.2.3 From ab4af5d564c2e54a087967f352b09f4ebc55cab3 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 23 Jan 2013 11:01:47 -0500 Subject: Readd event handling for application focus. --- indra/newview/llappdelegate-objc.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm index 9bb10f3204..9e0e0e35c5 100644 --- a/indra/newview/llappdelegate-objc.mm +++ b/indra/newview/llappdelegate-objc.mm @@ -31,12 +31,12 @@ - (void) applicationDidBecomeActive:(NSNotification *)notification { - + callWindowFocus(); } - (void) applicationDidResignActive:(NSNotification *)notification { - + callWindowUnfocus(); } - (NSApplicationDelegateReply) applicationShouldTerminate:(NSApplication *)sender -- cgit v1.2.3 From 3f9a1da04273a2a3eb87b524541232a04545289b Mon Sep 17 00:00:00 2001 From: Aura Linden Date: Wed, 23 Jan 2013 10:41:52 -0800 Subject: Recovered changes for dirpicker and filepicker --- indra/newview/CMakeLists.txt | 2 + indra/newview/lldirpicker.cpp | 142 ++---------- indra/newview/lldirpicker.h | 13 +- indra/newview/llfilepicker.cpp | 510 ++++++++++++++--------------------------- indra/newview/llfilepicker.h | 16 +- 5 files changed, 195 insertions(+), 488 deletions(-) diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index dff2c04fbc..4c5bfbc820 100755 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -1231,6 +1231,8 @@ source_group("CMake Rules" FILES ViewerInstall.cmake) if (DARWIN) LIST(APPEND viewer_SOURCE_FILES llappviewermacosx.cpp) + LIST(APPEND viewer_SOURCE_FILES llfilepicker_mac.mm) + LIST(APPEND viewer_HEADER_FILES llfilepicker_mac.h) find_library(AGL_LIBRARY AGL) find_library(APPKIT_LIBRARY AppKit) diff --git a/indra/newview/lldirpicker.cpp b/indra/newview/lldirpicker.cpp index 1e03582a29..c068011421 100644 --- a/indra/newview/lldirpicker.cpp +++ b/indra/newview/lldirpicker.cpp @@ -37,7 +37,7 @@ #include "llwindow.h" // beforeDialog() #include "llviewercontrol.h" -#if LL_LINUX || LL_SOLARIS +#if LL_LINUX || LL_SOLARIS || LL_DARWIN # include "llfilepicker.h" #endif @@ -147,152 +147,36 @@ std::string LLDirPicker::getDirName() #elif LL_DARWIN LLDirPicker::LLDirPicker() : - mFileName(NULL), - mLocked(false) +mFileName(NULL), +mLocked(false) { + mFilePicker = new LLFilePicker(); reset(); - - memset(&mNavOptions, 0, sizeof(mNavOptions)); - OSStatus error = NavGetDefaultDialogCreationOptions(&mNavOptions); - if (error == noErr) - { - mNavOptions.modality = kWindowModalityAppModal; - } } LLDirPicker::~LLDirPicker() { - // nothing + delete mFilePicker; } -//static -pascal void LLDirPicker::doNavCallbackEvent(NavEventCallbackMessage callBackSelector, - NavCBRecPtr callBackParms, void* callBackUD) +void LLDirPicker::reset() { - switch(callBackSelector) - { - case kNavCBStart: - { - if (!sInstance.mFileName) break; - - OSStatus error = noErr; - AEDesc theLocation = {typeNull, NULL}; - FSSpec outFSSpec; - - //Convert string to a FSSpec - FSRef myFSRef; - - const char* filename=sInstance.mFileName->c_str(); - - error = FSPathMakeRef ((UInt8*)filename, &myFSRef, NULL); - - if (error != noErr) break; - - error = FSGetCatalogInfo (&myFSRef, kFSCatInfoNone, NULL, NULL, &outFSSpec, NULL); - - if (error != noErr) break; - - error = AECreateDesc(typeFSS, &outFSSpec, sizeof(FSSpec), &theLocation); - - if (error != noErr) break; - - error = NavCustomControl(callBackParms->context, - kNavCtlSetLocation, (void*)&theLocation); - - } - } + if (mFilePicker) + mFilePicker->reset(); } -OSStatus LLDirPicker::doNavChooseDialog() -{ - OSStatus error = noErr; - NavDialogRef navRef = NULL; - NavReplyRecord navReply; - - memset(&navReply, 0, sizeof(navReply)); - - // NOTE: we are passing the address of a local variable here. - // This is fine, because the object this call creates will exist for less than the lifetime of this function. - // (It is destroyed by NavDialogDispose() below.) - - error = NavCreateChooseFolderDialog(&mNavOptions, &doNavCallbackEvent, NULL, NULL, &navRef); - - gViewerWindow->getWindow()->beforeDialog(); - - if (error == noErr) - error = NavDialogRun(navRef); - - gViewerWindow->getWindow()->afterDialog(); - - if (error == noErr) - error = NavDialogGetReply(navRef, &navReply); - - if (navRef) - NavDialogDispose(navRef); - - if (error == noErr && navReply.validRecord) - { - FSRef fsRef; - AEKeyword theAEKeyword; - DescType typeCode; - Size actualSize = 0; - char path[LL_MAX_PATH]; /*Flawfinder: ignore*/ - - memset(&fsRef, 0, sizeof(fsRef)); - error = AEGetNthPtr(&navReply.selection, 1, typeFSRef, &theAEKeyword, &typeCode, &fsRef, sizeof(fsRef), &actualSize); - - if (error == noErr) - error = FSRefMakePath(&fsRef, (UInt8*) path, sizeof(path)); - - if (error == noErr) - mDir = path; - } - - return error; -} +//static BOOL LLDirPicker::getDir(std::string* filename) { - if( mLocked ) return FALSE; - BOOL success = FALSE; - OSStatus error = noErr; - - // if local file browsing is turned off, return without opening dialog - if ( check_local_file_access_enabled() == false ) - { - return FALSE; - } - - mFileName = filename; - -// mNavOptions.saveFileName - - // Modal, so pause agent - send_agent_pause(); - { - error = doNavChooseDialog(); - } - send_agent_resume(); - if (error == noErr) - { - if (mDir.length() > 0) - success = true; - } - - // Account for the fact that the app has been stalled. - LLFrameTimer::updateFrameTime(); - return success; + LLFilePicker::ELoadFilter filter=LLFilePicker::FFLOAD_DIRECTORY; + + return mFilePicker->getOpenFile(filter, true); } std::string LLDirPicker::getDirName() { - return mDir; -} - -void LLDirPicker::reset() -{ - mLocked = false; - mDir.clear(); + return mFilePicker->getFirstFile(); } #elif LL_LINUX || LL_SOLARIS diff --git a/indra/newview/lldirpicker.h b/indra/newview/lldirpicker.h index 682f9d6476..9cc62431ef 100644 --- a/indra/newview/lldirpicker.h +++ b/indra/newview/lldirpicker.h @@ -34,11 +34,10 @@ #include "stdtypes.h" #if LL_DARWIN -#include // AssertMacros.h does bad things. -#include "fix_macros.h" #undef verify +#undef check #undef require #include @@ -77,15 +76,7 @@ private: void buildDirname( void ); bool check_local_file_access_enabled(); -#if LL_DARWIN - NavDialogCreationOptions mNavOptions; - static pascal void doNavCallbackEvent(NavEventCallbackMessage callBackSelector, - NavCBRecPtr callBackParms, void* callBackUD); - OSStatus doNavChooseDialog(); - -#endif - -#if LL_LINUX || LL_SOLARIS +#if LL_LINUX || LL_SOLARIS || LL_DARWIN // On Linux we just implement LLDirPicker on top of LLFilePicker LLFilePicker *mFilePicker; #endif diff --git a/indra/newview/llfilepicker.cpp b/indra/newview/llfilepicker.cpp index 4bf5b26b3b..4e68d874c3 100644 --- a/indra/newview/llfilepicker.cpp +++ b/indra/newview/llfilepicker.cpp @@ -62,6 +62,11 @@ LLFilePicker LLFilePicker::sInstance; #define DICTIONARY_FILTER L"Dictionary files (*.dic; *.xcu)\0*.dic;*.xcu\0" #endif +#ifdef LL_DARWIN +#include "llfilepicker_mac.h" +//#include +#endif + // // Implementation // @@ -94,14 +99,6 @@ LLFilePicker::LLFilePicker() mFilesW[0] = '\0'; #endif -#if LL_DARWIN - memset(&mNavOptions, 0, sizeof(mNavOptions)); - OSStatus error = NavGetDefaultDialogCreationOptions(&mNavOptions); - if (error == noErr) - { - mNavOptions.modality = kWindowModalityAppModal; - } -#endif } LLFilePicker::~LLFilePicker() @@ -546,369 +543,197 @@ BOOL LLFilePicker::getSaveFile(ESaveFilter filter, const std::string& filename) #elif LL_DARWIN -Boolean LLFilePicker::navOpenFilterProc(AEDesc *theItem, void *info, void *callBackUD, NavFilterModes filterMode) +std::vector* LLFilePicker::navOpenFilterProc(ELoadFilter filter) //(AEDesc *theItem, void *info, void *callBackUD, NavFilterModes filterMode) { - Boolean result = true; - ELoadFilter filter = *((ELoadFilter*) callBackUD); - OSStatus error = noErr; - - if (filterMode == kNavFilteringBrowserList && filter != FFLOAD_ALL && (theItem->descriptorType == typeFSRef || theItem->descriptorType == typeFSS)) - { - // navInfo is only valid for typeFSRef and typeFSS - NavFileOrFolderInfo *navInfo = (NavFileOrFolderInfo*) info; - if (!navInfo->isFolder) - { - AEDesc desc; - error = AECoerceDesc(theItem, typeFSRef, &desc); - if (error == noErr) - { - FSRef fileRef; - error = AEGetDescData(&desc, &fileRef, sizeof(fileRef)); - if (error == noErr) - { - LSItemInfoRecord fileInfo; - error = LSCopyItemInfoForRef(&fileRef, kLSRequestExtension | kLSRequestTypeCreator, &fileInfo); - if (error == noErr) - { - if (filter == FFLOAD_IMAGE) - { - if (fileInfo.filetype != 'JPEG' && fileInfo.filetype != 'JPG ' && - fileInfo.filetype != 'BMP ' && fileInfo.filetype != 'TGA ' && - fileInfo.filetype != 'BMPf' && fileInfo.filetype != 'TPIC' && - fileInfo.filetype != 'PNG ' && - (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("jpeg"), kCFCompareCaseInsensitive) != kCFCompareEqualTo && - CFStringCompare(fileInfo.extension, CFSTR("jpg"), kCFCompareCaseInsensitive) != kCFCompareEqualTo && - CFStringCompare(fileInfo.extension, CFSTR("bmp"), kCFCompareCaseInsensitive) != kCFCompareEqualTo && - CFStringCompare(fileInfo.extension, CFSTR("tga"), kCFCompareCaseInsensitive) != kCFCompareEqualTo && - CFStringCompare(fileInfo.extension, CFSTR("png"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) - ) - { - result = false; - } - } - else if (filter == FFLOAD_WAV) - { - if (fileInfo.filetype != 'WAVE' && fileInfo.filetype != 'WAV ' && - (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("wave"), kCFCompareCaseInsensitive) != kCFCompareEqualTo && - CFStringCompare(fileInfo.extension, CFSTR("wav"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) - ) - { - result = false; - } - } - else if (filter == FFLOAD_ANIM) - { - if (fileInfo.filetype != 'BVH ' && - fileInfo.filetype != 'ANIM' && - (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("bvh"), kCFCompareCaseInsensitive) != kCFCompareEqualTo) && - fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("anim"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) - ) - { - result = false; - } - } - else if (filter == FFLOAD_COLLADA) - { - if (fileInfo.filetype != 'DAE ' && - (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("dae"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) - ) - { - result = false; - } - } + std::vector *allowedv = new std::vector< std::string >; + switch(filter) + { + case FFLOAD_ALL: + allowedv->push_back("wav"); + allowedv->push_back("bvh"); + allowedv->push_back("anim"); + allowedv->push_back("dae"); + allowedv->push_back("raw"); + allowedv->push_back("lsl"); + allowedv->push_back("dic"); + allowedv->push_back("xcu"); + case FFLOAD_IMAGE: + allowedv->push_back("jpg"); + allowedv->push_back("jpeg"); + allowedv->push_back("bmp"); + allowedv->push_back("tga"); + allowedv->push_back("bmpf"); + allowedv->push_back("tpic"); + allowedv->push_back("png"); + break; + case FFLOAD_WAV: + allowedv->push_back("wav"); + break; + case FFLOAD_ANIM: + allowedv->push_back("bvh"); + allowedv->push_back("anim"); + break; + case FFLOAD_COLLADA: + allowedv->push_back("dae"); + break; #ifdef _CORY_TESTING - else if (filter == FFLOAD_GEOMETRY) - { - if (fileInfo.filetype != 'SLG ' && - (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("slg"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) - ) - { - result = false; - } - } + case FFLOAD_GEOMETRY: + allowedv->push_back("slg"); + break; #endif - else if (filter == FFLOAD_SLOBJECT) - { - llwarns << "*** navOpenFilterProc: FFLOAD_SLOBJECT NOT IMPLEMENTED ***" << llendl; - } - else if (filter == FFLOAD_RAW) - { - if (fileInfo.filetype != '\?\?\?\?' && - (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("raw"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) - ) - { - result = false; - } - } - else if (filter == FFLOAD_SCRIPT) - { - if (fileInfo.filetype != 'LSL ' && - (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("lsl"), kCFCompareCaseInsensitive) != kCFCompareEqualTo)) ) - { - result = false; - } - } - else if (filter == FFLOAD_DICTIONARY) - { - if (fileInfo.filetype != 'DIC ' && - fileInfo.filetype != 'XCU ' && - (fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("dic"), kCFCompareCaseInsensitive) != kCFCompareEqualTo) && - fileInfo.extension && (CFStringCompare(fileInfo.extension, CFSTR("xcu"), kCFCompareCaseInsensitive) != kCFCompareEqualTo))) - { - result = false; - } - } - - if (fileInfo.extension) - { - CFRelease(fileInfo.extension); - } - } - } - AEDisposeDesc(&desc); - } - } - } - return result; + case FFLOAD_RAW: + allowedv->push_back("raw"); + break; + case FFLOAD_SCRIPT: + allowedv->push_back("lsl"); + break; + case FFLOAD_DICTIONARY: + allowedv->push_back("dic"); + allowedv->push_back("xcu"); + break; + case FFLOAD_DIRECTORY: + break; + default: + llwarns << "Unsupported format." << llendl; + } + + return allowedv; } -OSStatus LLFilePicker::doNavChooseDialog(ELoadFilter filter) +bool LLFilePicker::doNavChooseDialog(ELoadFilter filter) { - OSStatus error = noErr; - NavDialogRef navRef = NULL; - NavReplyRecord navReply; - // if local file browsing is turned off, return without opening dialog if ( check_local_file_access_enabled() == false ) { - return FALSE; + return false; } - - memset(&navReply, 0, sizeof(navReply)); - - // NOTE: we are passing the address of a local variable here. - // This is fine, because the object this call creates will exist for less than the lifetime of this function. - // (It is destroyed by NavDialogDispose() below.) - error = NavCreateChooseFileDialog(&mNavOptions, NULL, NULL, NULL, navOpenFilterProc, (void*)(&filter), &navRef); - + gViewerWindow->getWindow()->beforeDialog(); - - if (error == noErr) - error = NavDialogRun(navRef); + + std::vector *allowed_types=navOpenFilterProc(filter); + + std::vector *filev = doLoadDialog(allowed_types, + mPickOptions); gViewerWindow->getWindow()->afterDialog(); - if (error == noErr) - error = NavDialogGetReply(navRef, &navReply); - if (navRef) - NavDialogDispose(navRef); - - if (error == noErr && navReply.validRecord) - { - SInt32 count = 0; - SInt32 index; - - // AE indexes are 1 based... - error = AECountItems(&navReply.selection, &count); - for (index = 1; index <= count; index++) - { - FSRef fsRef; - AEKeyword theAEKeyword; - DescType typeCode; - Size actualSize = 0; - char path[MAX_PATH]; /*Flawfinder: ignore*/ - - memset(&fsRef, 0, sizeof(fsRef)); - error = AEGetNthPtr(&navReply.selection, index, typeFSRef, &theAEKeyword, &typeCode, &fsRef, sizeof(fsRef), &actualSize); - - if (error == noErr) - error = FSRefMakePath(&fsRef, (UInt8*) path, sizeof(path)); - - if (error == noErr) - mFiles.push_back(std::string(path)); - } - } + if (filev && filev->size() > 0) + { + mFiles.insert(mFiles.end(), filev->begin(), filev->end()); + return true; + } - return error; + return false; } -OSStatus LLFilePicker::doNavSaveDialog(ESaveFilter filter, const std::string& filename) +bool LLFilePicker::doNavSaveDialog(ESaveFilter filter, const std::string& filename) { - OSStatus error = noErr; - NavDialogRef navRef = NULL; - NavReplyRecord navReply; - - memset(&navReply, 0, sizeof(navReply)); // Setup the type, creator, and extension - OSType type, creator; - CFStringRef extension = NULL; + std::string extension, type, creator; + switch (filter) { case FFSAVE_WAV: - type = 'WAVE'; - creator = 'TVOD'; - extension = CFSTR(".wav"); + type = "WAVE"; + creator = "TVOD"; + extension = "wav"; break; case FFSAVE_TGA: - type = 'TPIC'; - creator = 'prvw'; - extension = CFSTR(".tga"); + type = "TPIC"; + creator = "prvw"; + extension = "tga"; break; case FFSAVE_BMP: - type = 'BMPf'; - creator = 'prvw'; - extension = CFSTR(".bmp"); + type = "BMPf"; + creator = "prvw"; + extension = "bmp"; break; case FFSAVE_JPEG: - type = 'JPEG'; - creator = 'prvw'; - extension = CFSTR(".jpeg"); + type = "JPEG"; + creator = "prvw"; + extension = "jpeg"; break; case FFSAVE_PNG: - type = 'PNG '; - creator = 'prvw'; - extension = CFSTR(".png"); + type = "PNG "; + creator = "prvw"; + extension = "png"; break; case FFSAVE_AVI: - type = '\?\?\?\?'; - creator = '\?\?\?\?'; - extension = CFSTR(".mov"); + type = "\?\?\?\?"; + creator = "\?\?\?\?"; + extension = "mov"; break; case FFSAVE_ANIM: - type = '\?\?\?\?'; - creator = '\?\?\?\?'; - extension = CFSTR(".xaf"); + type = "\?\?\?\?"; + creator = "\?\?\?\?"; + extension = "xaf"; break; #ifdef _CORY_TESTING case FFSAVE_GEOMETRY: - type = '\?\?\?\?'; - creator = '\?\?\?\?'; - extension = CFSTR(".slg"); + type = "\?\?\?\?"; + creator = "\?\?\?\?"; + extension = "slg"; break; #endif case FFSAVE_RAW: - type = '\?\?\?\?'; - creator = '\?\?\?\?'; - extension = CFSTR(".raw"); + type = "\?\?\?\?"; + creator = "\?\?\?\?"; + extension = "raw"; break; case FFSAVE_J2C: - type = '\?\?\?\?'; - creator = 'prvw'; - extension = CFSTR(".j2c"); + type = "\?\?\?\?"; + creator = "prvw"; + extension = "j2c"; break; case FFSAVE_SCRIPT: - type = 'LSL '; - creator = '\?\?\?\?'; - extension = CFSTR(".lsl"); + type = "LSL "; + creator = "\?\?\?\?"; + extension = "lsl"; break; case FFSAVE_ALL: default: - type = '\?\?\?\?'; - creator = '\?\?\?\?'; - extension = CFSTR(""); + type = "\?\?\?\?"; + creator = "\?\?\?\?"; + extension = ""; break; } - // Create the dialog - error = NavCreatePutFileDialog(&mNavOptions, type, creator, NULL, NULL, &navRef); - if (error == noErr) - { - CFStringRef nameString = NULL; - bool hasExtension = true; - - // Create a CFString of the initial file name - if (!filename.empty()) - nameString = CFStringCreateWithCString(NULL, filename.c_str(), kCFStringEncodingUTF8); - else - nameString = CFSTR("Untitled"); - - // Add the extension if one was not provided - if (nameString && !CFStringHasSuffix(nameString, extension)) - { - CFStringRef tempString = nameString; - hasExtension = false; - nameString = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@%@"), tempString, extension); - CFRelease(tempString); - } - - // Set the name in the dialog - if (nameString) - { - error = NavDialogSetSaveFileName(navRef, nameString); - CFRelease(nameString); - } - else - { - error = paramErr; - } - } - + std::string namestring = filename; + if (namestring.empty()) namestring="Untitled"; + +// if (! boost::algorithm::ends_with(namestring, extension) ) +// { +// namestring = namestring + "." + extension; +// +// } + gViewerWindow->getWindow()->beforeDialog(); // Run the dialog - if (error == noErr) - error = NavDialogRun(navRef); + std::string* filev = doSaveDialog(&namestring, + &type, + &creator, + &extension, + mPickOptions); gViewerWindow->getWindow()->afterDialog(); - if (error == noErr) - error = NavDialogGetReply(navRef, &navReply); - - if (navRef) - NavDialogDispose(navRef); - - if (error == noErr && navReply.validRecord) + if ( filev && !filev->empty() ) { - SInt32 count = 0; - - // AE indexes are 1 based... - error = AECountItems(&navReply.selection, &count); - if (count > 0) - { - // Get the FSRef to the containing folder - FSRef fsRef; - AEKeyword theAEKeyword; - DescType typeCode; - Size actualSize = 0; - - memset(&fsRef, 0, sizeof(fsRef)); - error = AEGetNthPtr(&navReply.selection, 1, typeFSRef, &theAEKeyword, &typeCode, &fsRef, sizeof(fsRef), &actualSize); - - if (error == noErr) - { - char path[PATH_MAX]; /*Flawfinder: ignore*/ - char newFileName[SINGLE_FILENAME_BUFFER_SIZE]; /*Flawfinder: ignore*/ - - error = FSRefMakePath(&fsRef, (UInt8*)path, PATH_MAX); - if (error == noErr) - { - if (CFStringGetCString(navReply.saveFileName, newFileName, sizeof(newFileName), kCFStringEncodingUTF8)) - { - mFiles.push_back(std::string(path) + "/" + std::string(newFileName)); - } - else - { - error = paramErr; - } - } - else - { - error = paramErr; - } - } - } - } + mFiles.push_back(*filev); + return true; + } - return error; + return false; } BOOL LLFilePicker::getOpenFile(ELoadFilter filter, bool blocking) @@ -924,16 +749,21 @@ BOOL LLFilePicker::getOpenFile(ELoadFilter filter, bool blocking) return FALSE; } - OSStatus error = noErr; - reset(); - mNavOptions.optionFlags &= ~kNavAllowMultipleFiles; + mPickOptions &= ~F_MULTIPLE; + mPickOptions |= F_FILE; + + if (filter == FFLOAD_DIRECTORY) //This should only be called from lldirpicker. + { + + mPickOptions |= ( F_NAV_SUPPORT | F_DIRECTORY ); + mPickOptions &= ~F_FILE; + } if(filter == FFLOAD_ALL) // allow application bundles etc. to be traversed; important for DEV-16869, but generally useful { - // mNavOptions.optionFlags |= kNavAllowOpenPackages; - mNavOptions.optionFlags |= kNavSupportPackages; + mPickOptions &= F_NAV_SUPPORT; } if (blocking) @@ -942,14 +772,13 @@ BOOL LLFilePicker::getOpenFile(ELoadFilter filter, bool blocking) send_agent_pause(); } + + success = doNavChooseDialog(filter); + + if (success) { - error = doNavChooseDialog(filter); - } - - if (error == noErr) - { - if (getFileCount()) - success = true; + if (!getFileCount()) + success = false; } if (blocking) @@ -975,21 +804,22 @@ BOOL LLFilePicker::getMultipleOpenFiles(ELoadFilter filter) return FALSE; } - OSStatus error = noErr; - reset(); - - mNavOptions.optionFlags |= kNavAllowMultipleFiles; + + mPickOptions |= F_FILE; + + mPickOptions |= F_MULTIPLE; // Modal, so pause agent send_agent_pause(); + + success = doNavChooseDialog(filter); + + send_agent_resume(); + + if (success) { - error = doNavChooseDialog(filter); - } - send_agent_resume(); - if (error == noErr) - { - if (getFileCount()) - success = true; + if (!getFileCount()) + success = false; if (getFileCount() > 1) mLocked = true; } @@ -1001,37 +831,37 @@ BOOL LLFilePicker::getMultipleOpenFiles(ELoadFilter filter) BOOL LLFilePicker::getSaveFile(ESaveFilter filter, const std::string& filename) { + if( mLocked ) - return FALSE; - BOOL success = FALSE; - OSStatus error = noErr; + return false; + BOOL success = false; // if local file browsing is turned off, return without opening dialog if ( check_local_file_access_enabled() == false ) { - return FALSE; + return false; } reset(); - mNavOptions.optionFlags &= ~kNavAllowMultipleFiles; + mPickOptions &= ~F_MULTIPLE; // Modal, so pause agent send_agent_pause(); + + success = doNavSaveDialog(filter, filename); + + if (success) { - error = doNavSaveDialog(filter, filename); - } - send_agent_resume(); - if (error == noErr) - { - if (getFileCount()) - success = true; + if (!getFileCount()) + success = false; } // Account for the fact that the app has been stalled. LLFrameTimer::updateFrameTime(); return success; } +//END LL_DARWIN #elif LL_LINUX || LL_SOLARIS @@ -1533,4 +1363,4 @@ BOOL LLFilePicker::getMultipleOpenFiles( ELoadFilter filter ) return FALSE; } -#endif +#endif // LL_LINUX || LL_SOLARIS diff --git a/indra/newview/llfilepicker.h b/indra/newview/llfilepicker.h index 4f602f63f1..0d279f73f3 100644 --- a/indra/newview/llfilepicker.h +++ b/indra/newview/llfilepicker.h @@ -39,8 +39,8 @@ #include // AssertMacros.h does bad things. -#include "fix_macros.h" #undef verify +#undef check #undef require #include @@ -85,7 +85,8 @@ public: FFLOAD_MODEL = 9, FFLOAD_COLLADA = 10, FFLOAD_SCRIPT = 11, - FFLOAD_DICTIONARY = 12 + FFLOAD_DICTIONARY = 12, + FFLOAD_DIRECTORY = 13 //To call from lldirpicker. }; enum ESaveFilter @@ -158,15 +159,14 @@ private: #endif #if LL_DARWIN - NavDialogCreationOptions mNavOptions; + S32 mPickOptions; std::vector mFileVector; UInt32 mFileIndex; - OSStatus doNavChooseDialog(ELoadFilter filter); - OSStatus doNavSaveDialog(ESaveFilter filter, const std::string& filename); - void getFilePath(SInt32 index); - void getFileName(SInt32 index); - static Boolean navOpenFilterProc(AEDesc *theItem, void *info, void *callBackUD, NavFilterModes filterMode); + bool doNavChooseDialog(ELoadFilter filter); + bool doNavSaveDialog(ESaveFilter filter, const std::string& filename); + //static Boolean navOpenFilterProc(AEDesc *theItem, void *info, void *callBackUD, NavFilterModes filterMode); + std::vector* navOpenFilterProc(ELoadFilter filter); #endif #if LL_GTK -- cgit v1.2.3 From 867289bf8045d6b648aa99cedea804208ba9f552 Mon Sep 17 00:00:00 2001 From: Aura Linden Date: Wed, 23 Jan 2013 12:21:31 -0800 Subject: When porting lost changes remember to re-add the new files --- indra/newview/llfilepicker_mac.h | 58 +++++++++++++++++ indra/newview/llfilepicker_mac.mm | 127 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 indra/newview/llfilepicker_mac.h create mode 100644 indra/newview/llfilepicker_mac.mm diff --git a/indra/newview/llfilepicker_mac.h b/indra/newview/llfilepicker_mac.h new file mode 100644 index 0000000000..e0b7e2e8ce --- /dev/null +++ b/indra/newview/llfilepicker_mac.h @@ -0,0 +1,58 @@ +/** + * @file llfilepicker_mac.h + * @brief OS-specific file picker + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +// OS specific file selection dialog. This is implemented as a +// singleton class, so call the instance() method to get the working +// instance. When you call getMultipleOpenFile(), it locks the picker +// until you iterate to the end of the list of selected files with +// getNextFile() or call reset(). + +#ifndef LL_LLFILEPICKER_MAC_H +#define LL_LLFILEPICKER_MAC_H + +#if LL_DARWIN + +#include +#include + +//void modelessPicker(); +std::vector* doLoadDialog(const std::vector* allowed_types, + unsigned int flags); +std::string* doSaveDialog(const std::string* file, + const std::string* type, + const std::string* creator, + const std::string* extension, + unsigned int flags); +enum { + F_FILE = 0x00000001, + F_DIRECTORY = 0x00000002, + F_MULTIPLE = 0x00000004, + F_NAV_SUPPORT=0x00000008 +}; + +#endif + +#endif diff --git a/indra/newview/llfilepicker_mac.mm b/indra/newview/llfilepicker_mac.mm new file mode 100644 index 0000000000..13d0caeb9f --- /dev/null +++ b/indra/newview/llfilepicker_mac.mm @@ -0,0 +1,127 @@ +/** + * @file llfilepicker_mac.cpp + * @brief OS-specific file picker + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifdef LL_DARWIN +#import +#include +#include "llfilepicker_mac.h" + +std::vector* doLoadDialog(const std::vector* allowed_types, + unsigned int flags) +{ + int i, result; + + //Aura TODO: We could init a small window and release it at the end of this routine + //for a modeless interface. + + NSOpenPanel *panel = [NSOpenPanel openPanel]; + //NSString *fileName = nil; + NSMutableArray *fileTypes = nil; + + + if ( allowed_types && !allowed_types->empty()) + { + fileTypes = [[NSMutableArray alloc] init]; + + for (i=0;isize();++i) + { + [fileTypes addObject: + [NSString stringWithCString:(*allowed_types)[i].c_str() + encoding:[NSString defaultCStringEncoding]]]; + } + } + + //[panel setMessage:@"Import one or more files or directories."]; + [panel setAllowsMultipleSelection: ( (flags & F_MULTIPLE)?true:false ) ]; + [panel setCanChooseDirectories: ( (flags & F_DIRECTORY)?true:false ) ]; + [panel setCanCreateDirectories: true]; + [panel setResolvesAliases: true]; + [panel setCanChooseFiles: ( (flags & F_FILE)?true:false )]; + [panel setTreatsFilePackagesAsDirectories: ( flags & F_NAV_SUPPORT ) ]; + + std::vector* outfiles = NULL; + + if (fileTypes) + { + + [panel setAllowedFileTypes:fileTypes]; + + result = [panel runModalForTypes:fileTypes]; + } + else + { + result = [panel runModalForDirectory:NSHomeDirectory() file:nil]; + } + + if (result == NSOKButton) + { + NSArray *filesToOpen = [panel filenames]; + int i, count = [filesToOpen count]; + + if (count > 0) + { + outfiles = new std::vector; + } + + for (i=0; ipush_back(*afilestr); + } + } + return outfiles; +} + + +std::string* doSaveDialog(const std::string* file, + const std::string* type, + const std::string* creator, + const std::string* extension, + unsigned int flags) +{ + NSSavePanel *panel = [NSSavePanel savePanel]; + + NSString *typens = [NSString stringWithCString:type->c_str() encoding:[NSString defaultCStringEncoding]]; + NSArray *fileType = [[NSArray alloc] initWithObjects:typens,nil]; + + //[panel setMessage:@"Save Image File"]; + [panel setTreatsFilePackagesAsDirectories: ( flags & F_NAV_SUPPORT ) ]; + [panel setCanSelectHiddenExtension:true]; + [panel setAllowedFileTypes:fileType]; + NSString *fileName = [NSString stringWithCString:file->c_str() encoding:[NSString defaultCStringEncoding]]; + + std::string *outfile = NULL; + + if([panel runModalForDirectory:nil file:fileName] == + NSFileHandlingPanelOKButton) + { + outfile= new std::string( [ [panel filename] UTF8String ] ); + // write the file + } + return outfile; +} + +#endif -- cgit v1.2.3 From bf1e9124f1530339bfa35652a3b3e329b32a3240 Mon Sep 17 00:00:00 2001 From: Geenz Date: Sat, 2 Feb 2013 12:49:39 -0500 Subject: Restore the old Carbon crash handler, and more deprecated API removal. --- indra/llwindow/llwindowmacosx.cpp | 4 +- indra/newview/llappviewermacosx.cpp | 116 +++++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 4 deletions(-) diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index f25fc82896..2e86759ec0 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -1350,7 +1350,7 @@ void LLWindowMacOSX::updateCursor() { default: case UI_CURSOR_ARROW: - InitCursor(); + setArrowCursor(); if(mCursorHidden) { // Since InitCursor resets the hide level, correct for it here. @@ -1410,7 +1410,7 @@ void LLWindowMacOSX::updateCursor() if(result != noErr) { - InitCursor(); + setArrowCursor(); } mCurrentCursor = mNextCursor; diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp index 28210d18dd..4141f16647 100644 --- a/indra/newview/llappviewermacosx.cpp +++ b/indra/newview/llappviewermacosx.cpp @@ -30,6 +30,8 @@ #error "Use only with Mac OS X" #endif +#define LL_CARBON_CRASH_HANDLER 1 + #include "llappviewermacosx.h" #include "llwindowmacosx-objc.h" #include "llcommandlineparser.h" @@ -40,6 +42,9 @@ #include "llfloaterworldmap.h" #include "llurldispatcher.h" #include +#ifdef LL_CARBON_CRASH_HANDLER +#include +#endif #include "lldir.h" #include #include // for systemwide mute @@ -51,8 +56,18 @@ namespace // They are not used immediately by the app. int gArgC; char** gArgV; - + bool sCrashReporterIsRunning = false; LLAppViewerMacOSX* gViewerAppPtr; +#ifdef LL_CARBON_CRASH_HANDLER + OSErr AEQuitHandler(const AppleEvent *messagein, AppleEvent *reply, long refIn) + { + OSErr result = noErr; + + LLAppViewer::instance()->userQuit(); + + return(result); + } +#endif } bool initViewer() @@ -263,9 +278,39 @@ bool LLAppViewerMacOSX::restoreErrorTrap() return reset_count == 0; } +#ifdef LL_CARBON_CRASH_HANDLER +static OSStatus CarbonEventHandler(EventHandlerCallRef inHandlerCallRef, + EventRef inEvent, + void* inUserData) +{ + ProcessSerialNumber psn; + + GetEventParameter(inEvent, + kEventParamProcessID, + typeProcessSerialNumber, + NULL, + sizeof(psn), + NULL, + &psn); + + if( GetEventKind(inEvent) == kEventAppTerminated ) + { + Boolean matching_psn = FALSE; + OSErr os_result = SameProcess(&psn, (ProcessSerialNumber*)inUserData, &matching_psn); + if(os_result >= 0 && matching_psn) + { + sCrashReporterIsRunning = false; + QuitApplicationEventLoop(); + } + } + return noErr; +} +#endif + void LLAppViewerMacOSX::handleCrashReporting(bool reportFreeze) { - // This used to use fork&exec, but is switched to LSOpenApplication to +#ifdef LL_CARBON_CRASH_HANDLER + // This used to use fork&exec, but is switched to LSOpenApplication to // Make sure the crash reporter launches in front of the SL window. std::string command_str; @@ -283,8 +328,75 @@ void LLAppViewerMacOSX::handleCrashReporting(bool reportFreeze) memset(&appParams, 0, sizeof(appParams)); appParams.version = 0; appParams.flags = kLSLaunchNoParams | kLSLaunchStartClassic; + appParams.application = &appRef; + + if(reportFreeze) + { + // Make sure freeze reporting launches the crash logger synchronously, lest + // Log files get changed by SL while the logger is running. + + // *NOTE:Mani A better way - make a copy of the data that the crash reporter will send + // and let SL go about its business. This way makes the mac work like windows and linux + // and is the smallest patch for the issue. + sCrashReporterIsRunning = false; + ProcessSerialNumber o_psn; + + static EventHandlerRef sCarbonEventsRef = NULL; + static const EventTypeSpec kEvents[] = + { + { kEventClassApplication, kEventAppTerminated } + }; + + // Install the handler to detect crash logger termination + InstallEventHandler(GetApplicationEventTarget(), + (EventHandlerUPP) CarbonEventHandler, + GetEventTypeCount(kEvents), + kEvents, + &o_psn, + &sCarbonEventsRef + ); + + // Remove, temporarily the quit handler - which has *crash* behavior before + // the mainloop gets running! + AERemoveEventHandler(kCoreEventClass, + kAEQuitApplication, + NewAEEventHandlerUPP(AEQuitHandler), + false); + + // Launch the crash reporter. + os_result = LSOpenApplication(&appParams, &o_psn); + + if(os_result >= 0) + { + sCrashReporterIsRunning = true; + } + + while(sCrashReporterIsRunning) + { + RunApplicationEventLoop(); + } + + // Re-install the apps quit handler. + AEInstallEventHandler(kCoreEventClass, + kAEQuitApplication, + NewAEEventHandlerUPP(AEQuitHandler), + 0, + false); + + // Remove the crash reporter quit handler. + RemoveEventHandler(sCarbonEventsRef); + } + else + { + appParams.flags |= kLSLaunchAsync; + clear_signals(); + + ProcessSerialNumber o_psn; + os_result = LSOpenApplication(&appParams, &o_psn); + } } +#endif } std::string LLAppViewerMacOSX::generateSerialNumber() -- cgit v1.2.3 From f3ef69ec19c3fb54d53aba1aa2ac49bc8140b591 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 4 Feb 2013 18:27:47 -0500 Subject: Updated the crash handler to produce a CFURL which gets converted into a FSRef due to the Files.h deprecation. --- indra/newview/llappviewermacosx.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp index 4141f16647..47c82975d8 100644 --- a/indra/newview/llappviewermacosx.cpp +++ b/indra/newview/llappviewermacosx.cpp @@ -317,12 +317,19 @@ void LLAppViewerMacOSX::handleCrashReporting(bool reportFreeze) //command_str = "open Second Life.app/Contents/Resources/mac-crash-logger.app"; command_str = "mac-crash-logger.app/Contents/MacOS/mac-crash-logger"; + CFURLRef urlRef = CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)command_str.c_str(), strlen(command_str.c_str()), FALSE); + + // FSRef apparently isn't deprecated. + // There's other funcitonality that depends on it existing as well that isn't deprecated. + // There doesn't seem to be much to directly verify what the status of FSRef is, outside of some documentation pointing at FSRef being valid, and other documentation pointing to everything in Files.h being deprecated. + // We'll assume it isn't for now, since all non-deprecated functions that use it seem to assume similar. + FSRef appRef; - Boolean isDir = 0; - OSStatus os_result = FSPathMakeRef((UInt8*)command_str.c_str(), - &appRef, - &isDir); - if(os_result >= 0) + Boolean pathstatus = CFURLGetFSRef(urlRef, &appRef); + + OSStatus os_result = noErr; + + if(pathstatus == true) { LSApplicationParameters appParams; memset(&appParams, 0, sizeof(appParams)); -- cgit v1.2.3 From e17d69d1d16c607aa304936ebf2ab151684f9c76 Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 15 Feb 2013 14:37:04 -0500 Subject: XIB file cleanup. --- indra/newview/SecondLife.nib | Bin 8573 -> 8233 bytes indra/newview/SecondLife.xib | 45 ++----------------------------------------- 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib index 0d59d59bb2..b4ad4a876d 100644 Binary files a/indra/newview/SecondLife.nib and b/indra/newview/SecondLife.nib differ diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib index b02d04e0d2..6bee322017 100644 --- a/indra/newview/SecondLife.xib +++ b/indra/newview/SecondLife.xib @@ -153,7 +153,7 @@ - Quit NewApplication + Quit Second Life q 1048576 2147483647 @@ -359,22 +359,6 @@ 2147483647 - submenuAction: - - Help - - - - NewApplication Help - ? - 1048576 - 2147483647 - - - - - _NSHelpMenu - _NSMainMenu @@ -468,14 +452,6 @@ 240 - - - showHelp: - - - - 360 - hide: @@ -615,9 +591,7 @@ 103 - - - + @@ -644,19 +618,6 @@ - - 106 - - - - - - - - 111 - - - 57 @@ -873,8 +834,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin -- cgit v1.2.3 From 4a935b68151f9d6951a1d1312a3437a8e8150f41 Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 22 Feb 2013 16:41:49 -0500 Subject: Fix inconsistent handling of Control, Alt, and Shift keys through a new modifier update callback. --- indra/llwindow/llkeyboard.h | 5 +++++ indra/llwindow/llkeyboardheadless.cpp | 7 +++++++ indra/llwindow/llkeyboardheadless.h | 3 +++ indra/llwindow/llkeyboardmacosx.cpp | 5 +++++ indra/llwindow/llkeyboardmacosx.h | 1 + indra/llwindow/llopenglview-objc.mm | 3 +-- indra/llwindow/llwindowmacosx-objc.h | 1 + indra/llwindow/llwindowmacosx.cpp | 5 +++++ 8 files changed, 28 insertions(+), 2 deletions(-) diff --git a/indra/llwindow/llkeyboard.h b/indra/llwindow/llkeyboard.h index c155c1b362..92449c123f 100644 --- a/indra/llwindow/llkeyboard.h +++ b/indra/llwindow/llkeyboard.h @@ -82,6 +82,11 @@ public: virtual BOOL handleKeyUp(const U16 key, MASK mask) = 0; virtual BOOL handleKeyDown(const U16 key, MASK mask) = 0; + +#ifdef LL_DARWIN + // We only actually use this for OS X. + virtual void handleModifier(MASK mask) = 0; +#endif // LL_DARWIN // Asynchronously poll the control, alt, and shift keys and set the // appropriate internal key masks. diff --git a/indra/llwindow/llkeyboardheadless.cpp b/indra/llwindow/llkeyboardheadless.cpp index c87617c9ff..a1b6b294e0 100644 --- a/indra/llwindow/llkeyboardheadless.cpp +++ b/indra/llwindow/llkeyboardheadless.cpp @@ -45,6 +45,13 @@ BOOL LLKeyboardHeadless::handleKeyUp(const U16 key, const U32 mask) MASK LLKeyboardHeadless::currentMask(BOOL for_mouse_event) { return MASK_NONE; } +#ifdef LL_DARWIN +void LLKeyboardHeadless::handleModifier(MASK mask) +{ + +} +#endif + void LLKeyboardHeadless::scanKeyboard() { for (S32 key = 0; key < KEY_COUNT; key++) diff --git a/indra/llwindow/llkeyboardheadless.h b/indra/llwindow/llkeyboardheadless.h index 4e666f8ce8..8ed28ace90 100644 --- a/indra/llwindow/llkeyboardheadless.h +++ b/indra/llwindow/llkeyboardheadless.h @@ -40,6 +40,9 @@ public: /*virtual*/ void resetMaskKeys(); /*virtual*/ MASK currentMask(BOOL for_mouse_event); /*virtual*/ void scanKeyboard(); +#ifdef LL_DARWIN + /*virtual*/ void handleModifier(MASK mask); +#endif }; #endif diff --git a/indra/llwindow/llkeyboardmacosx.cpp b/indra/llwindow/llkeyboardmacosx.cpp index 59cc2acaec..d4c8214461 100644 --- a/indra/llwindow/llkeyboardmacosx.cpp +++ b/indra/llwindow/llkeyboardmacosx.cpp @@ -198,6 +198,11 @@ static BOOL translateKeyMac(const U16 key, const U32 mask, KEY &outKey, U32 &out } */ +void LLKeyboardMacOSX::handleModifier(MASK mask) +{ + updateModifiers(mask); +} + MASK LLKeyboardMacOSX::updateModifiers(const U32 mask) { // translate the mask diff --git a/indra/llwindow/llkeyboardmacosx.h b/indra/llwindow/llkeyboardmacosx.h index 6e1f4d3b96..f9d014ab70 100644 --- a/indra/llwindow/llkeyboardmacosx.h +++ b/indra/llwindow/llkeyboardmacosx.h @@ -49,6 +49,7 @@ public: /*virtual*/ void resetMaskKeys(); /*virtual*/ MASK currentMask(BOOL for_mouse_event); /*virtual*/ void scanKeyboard(); + /*virtual*/ void handleModifier(MASK mask); protected: MASK updateModifiers(const U32 mask); diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index b79b7b3fa5..3a6225eab5 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -345,6 +345,7 @@ - (void)flagsChanged:(NSEvent *)theEvent { mModifiers = [theEvent modifierFlags]; + callModifier([theEvent modifierFlags]); } - (void) mouseDown:(NSEvent *)theEvent @@ -433,8 +434,6 @@ callMouseExit(); } - - - (NSPoint)convertToScreenFromLocalPoint:(NSPoint)point relativeToView:(NSView *)view { NSScreen *currentScreen = [NSScreen currentScreenForMouseLocation]; diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index ebc1633f9d..32d1a4d9a2 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -95,6 +95,7 @@ void callMiddleMouseDown(float *pos, unsigned int mask); void callMiddleMouseUp(float *pos, unsigned int mask); void callFocus(); void callFocusLost(); +void callModifier(unsigned int mask); #include void callHandleDragEntered(std::string url); diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 2e86759ec0..9ce19bd977 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -337,6 +337,11 @@ void callMiddleMouseUp(float *pos, MASK mask) gWindowImplementation->getCallbacks()->handleMiddleMouseUp(gWindowImplementation, outCoords, mask); } +void callModifier(MASK mask) +{ + gKeyboard->handleModifier(mask); +} + void callHandleDragEntered(std::string url) { gWindowImplementation->handleDragNDrop(url, LLWindowCallbacks::DNDA_START_TRACKING); -- cgit v1.2.3 From f6ad4359756268067c74f3d17049f646a2139aef Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 22 Feb 2013 17:52:22 -0500 Subject: Fix for deferred rendering no longer working when the viewer is compiled against the OS X 10.7 SDK and up. --- indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl | 1 + indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl | 1 + indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl | 1 + 6 files changed, 6 insertions(+) diff --git a/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl index 2cef8f2a5d..a2b4b3b8c8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl @@ -24,6 +24,7 @@ */ #extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_shader_texture_lod : enable #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index bff87cb6aa..9050b2c5b7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -32,6 +32,7 @@ out vec4 frag_color; //class 1 -- no shadows #extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_shader_texture_lod : enable uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 89448e2167..ae18558506 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -24,6 +24,7 @@ */ #extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_shader_texture_lod : enable #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index cca63872de..fddfe60c03 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -33,6 +33,7 @@ out vec4 frag_color; //class 1 -- no shadows #extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_shader_texture_lod : enable uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 5621e47ab7..57e17ad009 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -24,6 +24,7 @@ */ #extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_shader_texture_lod : enable #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 6d6ad6d565..57abe75c45 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -24,6 +24,7 @@ */ #extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_shader_texture_lod : enable #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -- cgit v1.2.3 From 7ea8d2f6c00334eae2418cc1749e9d0219cdb80d Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 25 Feb 2013 13:46:06 -0500 Subject: Removed the minimum 1024x768 window constraint to better suit smaller displays. --- indra/newview/SecondLife.nib | Bin 8233 -> 8146 bytes indra/newview/SecondLife.xib | 6 ++---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib index b4ad4a876d..0cffdb97dd 100644 Binary files a/indra/newview/SecondLife.nib and b/indra/newview/SecondLife.nib differ diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib index 6bee322017..6ca49b81ef 100644 --- a/indra/newview/SecondLife.xib +++ b/indra/newview/SecondLife.xib @@ -3,12 +3,12 @@ 1060 12C60 - 2844 + 3084 1187.34 625.00 com.apple.InterfaceBuilder.CocoaPlugin - 2844 + 3084 NSCustomObject @@ -375,7 +375,6 @@ LLNSWindow - {1024, 768} 256 @@ -387,7 +386,6 @@ _NS:20 {{0, 0}, {1920, 1178}} - {1024, 790} {10000000000000, 10000000000000} Second Life 128 -- cgit v1.2.3 From e19db5668853b7d3be2ed6af289a3c35bd213bca Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 25 Feb 2013 15:35:21 -0500 Subject: Fix for antialiasing and VSync not being enabled properly. --- indra/llwindow/llopenglview-objc.h | 3 ++- indra/llwindow/llopenglview-objc.mm | 11 ++++++++++- indra/llwindow/llwindowmacosx-objc.h | 2 +- indra/llwindow/llwindowmacosx-objc.mm | 4 ++-- indra/llwindow/llwindowmacosx.cpp | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index cc1618b3bc..b344bed2ef 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -16,7 +16,8 @@ { std::string mLastDraggedUrl; } - +- (id) initWithSamples:(NSUInteger)samples; +- (id) initWithSamples:(NSUInteger)samples andVsync:(BOOL)vsync; - (id) initWithFrame:(NSRect)frame withSamples:(NSUInteger)samples andVsync:(BOOL)vsync; // rebuildContext diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 3a6225eab5..e89c9267d5 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -61,10 +61,19 @@ - (id) init { - //[self registerForDraggedTypes:[NSArray arrayWithObjects:NSURLPboardType, NSFilenamesPboardType, nil]]; return [self initWithFrame:[self bounds] withSamples:2 andVsync:TRUE]; } +- (id) initWithSamples:(NSUInteger)samples +{ + return [self initWithFrame:[self bounds] withSamples:samples andVsync:TRUE]; +} + +- (id) initWithSamples:(NSUInteger)samples andVsync:(BOOL)vsync +{ + return [self initWithFrame:[self bounds] withSamples:samples andVsync:vsync]; +} + - (id) initWithFrame:(NSRect)frame withSamples:(NSUInteger)samples andVsync:(BOOL)vsync { [self registerForDraggedTypes:[NSArray arrayWithObject:NSURLPboardType]]; diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 32d1a4d9a2..a0eab61e7c 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -59,7 +59,7 @@ void hideNSCursorTillMove(bool hide); NSWindowRef createNSWindow(int x, int y, int width, int height); #include -GLViewRef createOpenGLView(NSWindowRef window); +GLViewRef createOpenGLView(NSWindowRef window, unsigned int samples, bool vsync); void glSwapBuffers(void* context); CGLContextObj getCGLContextObj(GLViewRef view); void getContentViewBounds(NSWindowRef window, float* bounds); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index b123ba0711..b288671219 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -214,9 +214,9 @@ NSWindowRef createNSWindow(int x, int y, int width, int height) return window; } -GLViewRef createOpenGLView(NSWindowRef window) +GLViewRef createOpenGLView(NSWindowRef window, unsigned int samples, bool vsync) { - LLOpenGLView *glview = [[LLOpenGLView alloc]initWithFrame:[(LLNSWindow*)window frame] withSamples:0 andVsync:FALSE]; + LLOpenGLView *glview = [[LLOpenGLView alloc]initWithFrame:[(LLNSWindow*)window frame] withSamples:samples andVsync:vsync]; [(LLNSWindow*)window setContentView:glview]; return glview; } diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 9ce19bd977..ac0fa54a68 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -404,7 +404,7 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits LL_INFOS("Window") << "Creating GL view..." << LL_ENDL; // Our OpenGL view is already defined within SecondLife.xib. // Get the view instead. - mGLView = createOpenGLView(mWindow); + mGLView = createOpenGLView(mWindow, mFSAASamples, !disable_vsync); mContext = getCGLContextObj(mGLView); // Since we just created the context, it needs to be set up. glNeedsInit = TRUE; -- cgit v1.2.3 From 21aa4b9c2494aab408fffa6c21010b6ca0a9a626 Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 26 Feb 2013 16:18:42 -0500 Subject: Setup the quit handler for when the user attempts to close the window. This restores the previous functionality of asking the user if they want to quit. --- indra/llwindow/llopenglview-objc.mm | 7 +++++-- indra/llwindow/llwindowmacosx-objc.h | 1 + indra/llwindow/llwindowmacosx.cpp | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index e89c9267d5..1d26ca5ca1 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -466,16 +466,19 @@ - (BOOL) becomeFirstResponder { - NSLog(@"Window gained focus!"); callFocus(); return true; } - (BOOL) resignFirstResponder { - NSLog(@"Window lost focus!"); callFocus(); return true; } +- (void) close +{ + callQuitHandler(); +} + @end diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index a0eab61e7c..6793666927 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -96,6 +96,7 @@ void callMiddleMouseUp(float *pos, unsigned int mask); void callFocus(); void callFocusLost(); void callModifier(unsigned int mask); +void callQuitHandler(); #include void callHandleDragEntered(std::string url); diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index ac0fa54a68..24f73c5631 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -362,6 +362,14 @@ void callHandleDragDropped(std::string url) gWindowImplementation->handleDragNDrop(url, LLWindowCallbacks::DNDA_DROPPED); } +void callQuitHandler() +{ + if(gWindowImplementation->getCallbacks()->handleCloseRequest(gWindowImplementation)) + { + gWindowImplementation->getCallbacks()->handleQuit(gWindowImplementation); + } +} + void LLWindowMacOSX::updateMouseDeltas(float* deltas) { if (mCursorDecoupled) -- cgit v1.2.3 From f5516e0fc0e6c22b25f9dca2b9b24ebd7618332a Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Wed, 27 Feb 2013 06:46:53 -0800 Subject: For MAINT-2404 Fixes detection of VRAM on OSX removed along with other AGL code. Code Review: callum --- indra/llwindow/llopenglview-objc.h | 5 +++++ indra/llwindow/llopenglview-objc.mm | 22 ++++++++++++++++++++++ indra/llwindow/llwindowmacosx-objc.h | 1 + indra/llwindow/llwindowmacosx-objc.mm | 5 +++++ indra/llwindow/llwindowmacosx.cpp | 2 ++ 5 files changed, 35 insertions(+) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index b344bed2ef..c3ae34ea50 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -7,6 +7,9 @@ // #import +#import +#import +#import #include "llwindowmacosx-objc.h" // Some nasty shovelling of LLOpenGLView from LLNativeBindings to prevent any C++ <-> Obj-C interop oddities. @@ -33,6 +36,8 @@ - (CGLContextObj) getCGLContextObj; - (CGLPixelFormatObj*)getCGLPixelFormatObj; +- (unsigned long) getVramSize; + @end @interface LLNSWindow : NSWindow { diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index e89c9267d5..a1dece54f4 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -39,6 +39,28 @@ @implementation LLOpenGLView +- (unsigned long)getVramSize +{ + unsigned long vram_bytes = 0; + + io_service_t display_port = CGDisplayIOServicePort(kCGDirectMainDisplay); + + const void* type_code = IORegistryEntryCreateCFProperty(display_port, CFSTR(kIOFBMemorySizeKey), kCFAllocatorDefault, kNilOptions); + + // Ensure we have valid data from IOKit + if(type_code && CFGetTypeID(type_code) == CFNumberGetTypeID()) + { + long val; + // Retrieve actual number...is Apple ever embarrassed by this nonsense? + // + CFNumberGetValue((const __CFNumber*)type_code, kCFNumberSInt32Type, &val); + vram_bytes = (unsigned long)val; + CFRelease(type_code); + } + + return vram_bytes; +} + - (void)viewDidMoveToWindow { [[NSNotificationCenter defaultCenter] addObserver:self diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index a0eab61e7c..1724b85724 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -62,6 +62,7 @@ NSWindowRef createNSWindow(int x, int y, int width, int height); GLViewRef createOpenGLView(NSWindowRef window, unsigned int samples, bool vsync); void glSwapBuffers(void* context); CGLContextObj getCGLContextObj(GLViewRef view); +unsigned long getVramSize(GLViewRef view); void getContentViewBounds(NSWindowRef window, float* bounds); void getWindowSize(NSWindowRef window, float* size); void setWindowSize(NSWindowRef window, int width, int height); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index b288671219..9b57cd27cd 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -237,6 +237,11 @@ CGLPixelFormatObj* getCGLPixelFormatObj(NSWindowRef window) return [glview getCGLPixelFormatObj]; } +unsigned long getVramSize(GLViewRef view) +{ + return [(LLOpenGLView *)view getVramSize]; +} + void getContentViewBounds(NSWindowRef window, float* bounds) { bounds[0] = [[(LLNSWindow*)window contentView] bounds].origin.x; diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index ac0fa54a68..abb3c1e50c 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -408,6 +408,8 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits mContext = getCGLContextObj(mGLView); // Since we just created the context, it needs to be set up. glNeedsInit = TRUE; + + gGLManager.mVRAM = getVramSize(mGLView); } // Hook up the context to a drawable -- cgit v1.2.3 From a0de7a5ca77fbbaba4cafacfce9befbdf42c47b2 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Wed, 27 Feb 2013 08:04:20 -0800 Subject: Added missing IOKit lib dep to llui_libtest integration test cmake --- indra/integration_tests/llui_libtest/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indra/integration_tests/llui_libtest/CMakeLists.txt b/indra/integration_tests/llui_libtest/CMakeLists.txt index 91c9f20c10..06389ff871 100644 --- a/indra/integration_tests/llui_libtest/CMakeLists.txt +++ b/indra/integration_tests/llui_libtest/CMakeLists.txt @@ -56,7 +56,8 @@ add_executable(llui_libtest ${llui_libtest_SOURCE_FILES}) # Link with OS-specific libraries for LLWindow dependency if (DARWIN) find_library(COCOA_LIBRARY Cocoa) - set(OS_LIBRARIES ${COCOA_LIBRARY}) + find_library(IOKIT_LIBRARY IOKit) + set(OS_LIBRARIES ${COCOA_LIBRARY} ${IOKIT_LIBRARY}) elseif (WINDOWS) #ll_stack_trace needs this now... list(APPEND WINDOWS_LIBRARIES dbghelp) -- cgit v1.2.3 From d046e606575b2c3714a88e321c88e05441cba4a8 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Wed, 27 Feb 2013 14:39:26 -0800 Subject: Fix max VRAM detection on some cards and issues with sequencing of application of mem multiplier --- indra/llwindow/llopenglview-objc.mm | 32 +++++++++++++---------------- indra/llwindow/llwindowmacosx.cpp | 5 +++-- indra/newview/llfloaterhardwaresettings.cpp | 4 +++- indra/newview/llviewertexturelist.cpp | 14 ++++++------- indra/newview/llviewertexturelist.h | 2 +- 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index a1dece54f4..735ef77cce 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -41,24 +41,20 @@ - (unsigned long)getVramSize { - unsigned long vram_bytes = 0; - - io_service_t display_port = CGDisplayIOServicePort(kCGDirectMainDisplay); - - const void* type_code = IORegistryEntryCreateCFProperty(display_port, CFSTR(kIOFBMemorySizeKey), kCFAllocatorDefault, kNilOptions); - - // Ensure we have valid data from IOKit - if(type_code && CFGetTypeID(type_code) == CFNumberGetTypeID()) - { - long val; - // Retrieve actual number...is Apple ever embarrassed by this nonsense? - // - CFNumberGetValue((const __CFNumber*)type_code, kCFNumberSInt32Type, &val); - vram_bytes = (unsigned long)val; - CFRelease(type_code); - } - - return vram_bytes; + CGLRendererInfoObj info = 0; + GLint vram_bytes = 0; + int num_renderers = 0; + CGLError the_err = CGLQueryRendererInfo (CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay), &info, &num_renderers); + if(0 == the_err) + { + CGLDescribeRenderer (info, 0, kCGLRPTextureMemory, &vram_bytes); + CGLDestroyRendererInfo (info); + } + else + { + vram_bytes = (256 << 20); + } + return (unsigned long)vram_bytes; } - (void)viewDidMoveToWindow diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index abb3c1e50c..2faebe5dd9 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -511,8 +511,9 @@ void LLWindowMacOSX::destroyContext() // Close the window if(mWindow != NULL) { - closeWindow(mWindow); - mWindow = NULL; + NSWindowRef dead_window = mWindow; + mWindow = NULL; + closeWindow(dead_window); } } diff --git a/indra/newview/llfloaterhardwaresettings.cpp b/indra/newview/llfloaterhardwaresettings.cpp index 116bd241c4..664f7d4fd6 100644 --- a/indra/newview/llfloaterhardwaresettings.cpp +++ b/indra/newview/llfloaterhardwaresettings.cpp @@ -89,8 +89,10 @@ void LLFloaterHardwareSettings::refresh() void LLFloaterHardwareSettings::refreshEnabledState() { + F32 mem_multiplier = gSavedSettings.getF32("RenderTextureMemoryMultiple"); + S32 min_tex_mem = LLViewerTextureList::getMinVideoRamSetting(); - S32 max_tex_mem = LLViewerTextureList::getMaxVideoRamSetting(); + S32 max_tex_mem = LLViewerTextureList::getMaxVideoRamSetting(false, mem_multiplier); getChild("GraphicsCardTextureMemory")->setMinValue(min_tex_mem); getChild("GraphicsCardTextureMemory")->setMaxValue(max_tex_mem); diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp index b9f5c432d0..82d990cf97 100644 --- a/indra/newview/llviewertexturelist.cpp +++ b/indra/newview/llviewertexturelist.cpp @@ -1191,7 +1191,7 @@ S32 LLViewerTextureList::getMinVideoRamSetting() //static // Returns max setting for TextureMemory (in MB) -S32 LLViewerTextureList::getMaxVideoRamSetting(bool get_recommended) +S32 LLViewerTextureList::getMaxVideoRamSetting(bool get_recommended, float mem_multiplier) { S32 max_texmem; if (gGLManager.mVRAM != 0) @@ -1235,7 +1235,10 @@ S32 LLViewerTextureList::getMaxVideoRamSetting(bool get_recommended) max_texmem = llmin(max_texmem, (S32)(system_ram/2)); else max_texmem = llmin(max_texmem, (S32)(system_ram)); - + + // limit the texture memory to a multiple of the default if we've found some cards to behave poorly otherwise + max_texmem = llmin(max_texmem, (S32) (mem_multiplier * (F32) max_texmem)); + max_texmem = llclamp(max_texmem, getMinVideoRamSetting(), MAX_VIDEO_RAM_IN_MEGA_BYTES); return max_texmem; @@ -1248,7 +1251,7 @@ void LLViewerTextureList::updateMaxResidentTexMem(S32 mem) // Initialize the image pipeline VRAM settings S32 cur_mem = gSavedSettings.getS32("TextureMemory"); F32 mem_multiplier = gSavedSettings.getF32("RenderTextureMemoryMultiple"); - S32 default_mem = getMaxVideoRamSetting(true); // recommended default + S32 default_mem = getMaxVideoRamSetting(true, mem_multiplier); // recommended default if (mem == 0) { mem = cur_mem > 0 ? cur_mem : default_mem; @@ -1258,10 +1261,7 @@ void LLViewerTextureList::updateMaxResidentTexMem(S32 mem) mem = default_mem; } - // limit the texture memory to a multiple of the default if we've found some cards to behave poorly otherwise - mem = llmin(mem, (S32) (mem_multiplier * (F32) default_mem)); - - mem = llclamp(mem, getMinVideoRamSetting(), getMaxVideoRamSetting()); + mem = llclamp(mem, getMinVideoRamSetting(), getMaxVideoRamSetting(false, mem_multiplier)); if (mem != cur_mem) { gSavedSettings.setS32("TextureMemory", mem); diff --git a/indra/newview/llviewertexturelist.h b/indra/newview/llviewertexturelist.h index 3dda973d3f..88dea4448b 100644 --- a/indra/newview/llviewertexturelist.h +++ b/indra/newview/llviewertexturelist.h @@ -114,7 +114,7 @@ public: void setDebugFetching(LLViewerFetchedTexture* tex, S32 debug_level); static S32 getMinVideoRamSetting(); - static S32 getMaxVideoRamSetting(bool get_recommended = false); + static S32 getMaxVideoRamSetting(bool get_recommended, float mem_multiplier); private: void updateImagesDecodePriorities(); -- cgit v1.2.3 From f3316f8aa2484a93a35b93a3dd4961b8bad7f751 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 4 Mar 2013 17:32:49 -0500 Subject: Fix for Command + W closing the viewer window. The old viewer didn't actually use the File menu, so we'll remove it for the time being. --- indra/newview/SecondLife.nib | Bin 8146 -> 7403 bytes indra/newview/SecondLife.xib | 107 +------------------------------------------ 2 files changed, 1 insertion(+), 106 deletions(-) diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib index 0cffdb97dd..09173cd26f 100644 Binary files a/indra/newview/SecondLife.nib and b/indra/newview/SecondLife.nib differ diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib index 6ca49b81ef..cb91eeaea2 100644 --- a/indra/newview/SecondLife.xib +++ b/indra/newview/SecondLife.xib @@ -164,57 +164,6 @@ _NSAppleMenu - - - File - - 2147483647 - - - submenuAction: - - File - - - - New - n - 1048576 - 2147483647 - - - - - - Open… - o - 1048576 - 2147483647 - - - - - - YES - YES - - - 2147483647 - - - - - - Close - w - 1048576 - 2147483647 - - - - - - Edit @@ -385,7 +334,7 @@ _NS:20 - {{0, 0}, {1920, 1178}} + {{0, 0}, {1920, 1200}} {10000000000000, 10000000000000} Second Life 128 @@ -434,14 +383,6 @@ 39 - - - performClose: - - - - 193 - performZoom: @@ -564,7 +505,6 @@ - @@ -592,30 +532,6 @@ - - 83 - - - - - - - - 81 - - - - - - - - - - - 73 - - - 57 @@ -810,21 +726,6 @@ - - 82 - - - - - 79 - - - - - 72 - - - @@ -860,19 +761,13 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin -- cgit v1.2.3 From 5caa7a465e73fc9cf70f5f2c5d147a509bd5e185 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 11 Mar 2013 10:16:22 -0400 Subject: Bug fixing and prep-work for IME support (along with refactored text input in general). --- indra/llwindow/llkeyboardmacosx.cpp | 4 ++-- indra/llwindow/llwindowmacosx-objc.h | 8 ++++++++ indra/llwindow/llwindowmacosx-objc.mm | 9 ++++++++- indra/llwindow/llwindowmacosx.cpp | 25 +++++++++++++++++++++++++ indra/llwindow/llwindowmacosx.h | 1 + indra/newview/SecondLife.nib | Bin 7403 -> 7403 bytes indra/newview/SecondLife.xib | 14 +++++++------- 7 files changed, 51 insertions(+), 10 deletions(-) diff --git a/indra/llwindow/llkeyboardmacosx.cpp b/indra/llwindow/llkeyboardmacosx.cpp index d4c8214461..274e92c225 100644 --- a/indra/llwindow/llkeyboardmacosx.cpp +++ b/indra/llwindow/llkeyboardmacosx.cpp @@ -213,7 +213,7 @@ MASK LLKeyboardMacOSX::updateModifiers(const U32 mask) out_mask |= MASK_SHIFT; } - if(mask & MAC_CTRL_KEY || mask & MAC_CMD_KEY) + if(mask & (MAC_CTRL_KEY | MAC_CMD_KEY)) { out_mask |= MASK_CONTROL; } @@ -267,7 +267,7 @@ MASK LLKeyboardMacOSX::currentMask(BOOL for_mouse_event) if (mask & MAC_SHIFT_KEY) result |= MASK_SHIFT; if (mask & MAC_CTRL_KEY) result |= MASK_CONTROL; - if (mask & MAC_ALT_KEY) result |= MASK_ALT; + if (mask & MAC_ALT_KEY) result |= MASK_ALT; // For keyboard events, consider Command equivalent to Control if (!for_mouse_event) diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 6793666927..62c5b8298f 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -78,6 +78,7 @@ void removeGLView(GLViewRef view); // This is largely for easier interop between Obj-C and C++ (at least in the viewer's case due to the BOOL vs. BOOL conflict) void callKeyUp(unsigned short key, unsigned int mask); void callKeyDown(unsigned short key, unsigned int mask); +void callResetKeys(); void callUnicodeCallback(wchar_t character, unsigned int mask); void callRightMouseDown(float *pos, unsigned int mask); void callRightMouseUp(float *pos, unsigned int mask); @@ -104,6 +105,13 @@ void callHandleDragExited(std::string url); void callHandleDragUpdated(std::string url); void callHandleDragDropped(std::string url); +// LLPreeditor C bindings. +std::basic_string getPreeditString(); +void getPreeditSelectionRange(int *position, int *length); +void getPreeditMarkedRange(int *position, int *length); +void handleUnicodeCharacter(wchar_t c); +void updatePreeditor(unsigned short *str); + NSWindowRef getMainAppWindow(); GLViewRef getGLView(); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index b288671219..e4e12f4b5c 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -332,7 +332,14 @@ NSWindowRef getMainAppWindow() return winRef; } -unsigned int getModifiers() +/* +GLViewRef getGLView() { + return [(LLAppDelegate*)[[NSApplication sharedApplication] delegate] glview]; +} +*/ + +unsigned int getModifiers() +{ return [NSEvent modifierFlags]; } diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 24f73c5631..2f6c2101ef 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -211,6 +211,11 @@ void callKeyDown(unsigned short key, unsigned int mask) gKeyboard->handleKeyDown(key, mask); } +void callResetKeys() +{ + gKeyboard->resetKeys(); +} + void callUnicodeCallback(wchar_t character, unsigned int mask) { gWindowImplementation->getCallbacks()->handleUnicodeChar(character, mask); @@ -370,6 +375,26 @@ void callQuitHandler() } } +std::basic_string getPreeditString() +{ + return gWindowImplementation->getPreeditor()->getPreeditString(); +} + +void getPreeditSelectionRange(int *position, int *length) +{ + gWindowImplementation->getPreeditor()->getSelectionRange(position, length); +} + +void getPreeditMarkedRange(int *position, int *length) +{ + gWindowImplementation->getPreeditor()->getPreeditRange(position, length); +} + +void handleUnicodeCharacter(wchar_t c) +{ + gWindowImplementation->getPreeditor()->handleUnicodeCharHere(c); +} + void LLWindowMacOSX::updateMouseDeltas(float* deltas) { if (mCursorDecoupled) diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h index 14d6e70fb3..de0340cf74 100644 --- a/indra/llwindow/llwindowmacosx.h +++ b/indra/llwindow/llwindowmacosx.h @@ -120,6 +120,7 @@ public: void* getWindow() { return mWindow; } LLWindowCallbacks* getCallbacks() { return mCallbacks; } + LLPreeditor* getPreeditor() { return mPreeditor; } void updateMouseDeltas(float* deltas); void getMouseDeltas(float* delta); diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib index 09173cd26f..ff218a21c8 100644 Binary files a/indra/newview/SecondLife.nib and b/indra/newview/SecondLife.nib differ diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib index cb91eeaea2..86e8d81ebc 100644 --- a/indra/newview/SecondLife.xib +++ b/indra/newview/SecondLife.xib @@ -2,10 +2,10 @@ 1060 - 12C60 + 12D76 3084 - 1187.34 - 625.00 + 1187.37 + 626.00 com.apple.InterfaceBuilder.CocoaPlugin 3084 @@ -318,7 +318,7 @@ 15 2 - {{196, 240}, {1024, 768}} + {{196, 240}, {1024, 600}} 74974208 Second Life LLNSWindow @@ -328,13 +328,13 @@ 256 - {1024, 768} + {1024, 600} _NS:20 - {{0, 0}, {1920, 1200}} + {{0, 0}, {2560, 1440}} {10000000000000, 10000000000000} Second Life 128 @@ -775,7 +775,7 @@ - 864 + 888 -- cgit v1.2.3 From ad26f3c39002b6043e5fc4e00f9793e0f0e4941c Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 19 Mar 2013 05:50:50 -0400 Subject: IME support (and revamped text input support) semi-working. --- indra/llwindow/llopenglview-objc.h | 3 +- indra/llwindow/llopenglview-objc.mm | 126 ++++++++++++++++++++++++++++++++---- indra/llwindow/llwindowmacosx.cpp | 12 +++- indra/newview/SecondLife.nib | Bin 7403 -> 7403 bytes indra/newview/SecondLife.xib | 31 ++++++--- 5 files changed, 146 insertions(+), 26 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index c3ae34ea50..c144831da4 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -15,9 +15,10 @@ // Some nasty shovelling of LLOpenGLView from LLNativeBindings to prevent any C++ <-> Obj-C interop oddities. // Redraw callback handling removed (for now) due to being unneeded in the patch that preceeds this addition. -@interface LLOpenGLView : NSOpenGLView +@interface LLOpenGLView : NSOpenGLView { std::string mLastDraggedUrl; + unsigned int mModifiers; } - (id) initWithSamples:(NSUInteger)samples; - (id) initWithSamples:(NSUInteger)samples andVsync:(BOOL)vsync; diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 6ea523ea05..d568ed2fe5 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -94,6 +94,7 @@ - (id) initWithFrame:(NSRect)frame withSamples:(NSUInteger)samples andVsync:(BOOL)vsync { + [[self window] makeFirstResponder:self]; [self registerForDraggedTypes:[NSArray arrayWithObject:NSURLPboardType]]; [self initWithFrame:frame]; @@ -199,6 +200,7 @@ - (void) mouseDown:(NSEvent *)theEvent { + [self becomeFirstResponder]; [_window mouseDown:theEvent]; } @@ -234,7 +236,49 @@ - (void) keyDown:(NSEvent *)theEvent { - [_window keyDown:theEvent]; + [[self inputContext] handleEvent:theEvent]; + uint keycode = [theEvent keyCode]; + + switch (keycode) { + case 0x7b: + case 0x7c: + case 0x7d: + case 0x7e: + callKeyDown(keycode, mModifiers); + break; + + default: + callKeyDown(keycode, mModifiers); + NSString *chars = [theEvent characters]; + for (uint i = 0; i < [chars length]; i++) { + // Enter and Return are special cases. + unichar returntest = [chars characterAtIndex:i]; + if ((returntest == NSCarriageReturnCharacter || returntest == NSEnterCharacter) && + !([theEvent modifierFlags] & NSCommandKeyMask) && + !([theEvent modifierFlags] & NSAlternateKeyMask) && + !([theEvent modifierFlags] & NSControlKeyMask)) + { + callUnicodeCallback(13, 0); + } else { + // The command key being pressed is also a special case. + // Control + produces an ASCII control character code. + // Command + produces just the character's code. + // Check to see if the command key is pressed, then filter through the different character ranges that are relevant to control characters, and subtract the appropriate range. + if ([theEvent modifierFlags] & NSCommandKeyMask) + { + if (returntest >= 64 && returntest <= 95) + { + callUnicodeCallback(returntest - 63, mModifiers); + } else if (returntest >= 97 && returntest <= 122) + { + callUnicodeCallback(returntest - 96, mModifiers); + } + } + } + } + break; + } + } - (void) mouseMoved:(NSEvent *)theEvent @@ -242,9 +286,9 @@ [_window mouseMoved:theEvent]; } -- (void) flagsChanged:(NSEvent *)theEvent -{ - [_window flagsChanged:theEvent]; +- (void)flagsChanged:(NSEvent *)theEvent { + mModifiers = [theEvent modifierFlags]; + callModifier([theEvent modifierFlags]); } - (void) mouseExited:(NSEvent *)theEvent @@ -252,14 +296,9 @@ [_window mouseExited:theEvent]; } -- (BOOL) becomeFirstResponder +- (BOOL) acceptsFirstResponder { - return [_window becomeFirstResponder]; -} - -- (BOOL) resignFirstResponder -{ - return [_window resignFirstResponder]; + return YES; } - (NSDragOperation) draggingEntered:(id)sender @@ -305,6 +344,67 @@ return true; } +- (BOOL)hasMarkedText +{ + return NO; +} + +- (NSRange)markedRange +{ + return NSMakeRange(NSNotFound, 0); +} + +- (NSRange)selectedRange +{ + return NSMakeRange(NSNotFound, 0); +} + +- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange +{ +} + +- (void)unmarkText +{ + +} + +- (NSArray *)validAttributesForMarkedText +{ + return [NSArray array]; +} + +- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange +{ + return nil; +} + +- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange +{ + for (NSInteger i = 0; i < [aString length]; i++) + { + callUnicodeCallback([aString characterAtIndex:i], mModifiers); + } +} + +- (NSUInteger)characterIndexForPoint:(NSPoint)aPoint +{ + return NSNotFound; +} + +- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange +{ + return NSZeroRect; +} + +- (void)doCommandBySelector:(SEL)aSelector +{ +} + +- (BOOL)drawsVerticallyForCharacterAtIndex:(NSUInteger)charIndex +{ + return NO; +} + @end // We use a custom NSWindow for our event handling. @@ -315,12 +415,13 @@ - (id) init { - + [self makeFirstResponder:[self contentView]]; return self; } - (void) keyDown:(NSEvent *)theEvent { + uint keycode = [theEvent keyCode]; switch (keycode) { @@ -364,6 +465,7 @@ } break; } + } - (void) keyUp:(NSEvent *)theEvent { diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 34cc371526..08612bace4 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -223,7 +223,10 @@ void callUnicodeCallback(wchar_t character, unsigned int mask) void callFocus() { - gWindowImplementation->getCallbacks()->handleFocus(gWindowImplementation); + if (gWindowImplementation) + { + gWindowImplementation->getCallbacks()->handleFocus(gWindowImplementation); + } } void callFocusLost() @@ -369,9 +372,12 @@ void callHandleDragDropped(std::string url) void callQuitHandler() { - if(gWindowImplementation->getCallbacks()->handleCloseRequest(gWindowImplementation)) + if (gWindowImplementation) { - gWindowImplementation->getCallbacks()->handleQuit(gWindowImplementation); + if(gWindowImplementation->getCallbacks()->handleCloseRequest(gWindowImplementation)) + { + gWindowImplementation->getCallbacks()->handleQuit(gWindowImplementation); + } } } diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib index ff218a21c8..f55ddaabcd 100644 Binary files a/indra/newview/SecondLife.nib and b/indra/newview/SecondLife.nib differ diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib index 86e8d81ebc..7d20b7fd7c 100644 --- a/indra/newview/SecondLife.xib +++ b/indra/newview/SecondLife.xib @@ -2,7 +2,7 @@ 1060 - 12D76 + 12D78 3084 1187.37 626.00 @@ -775,24 +775,27 @@ - 888 + 940 LLAppDelegate NSObject - - window - LLNSWindow - - - window - + + LLOpenGLView + LLNSWindow + + + + glview + LLOpenGLView + + window LLNSWindow - + IBProjectSource ./Classes/LLAppDelegate.h @@ -806,6 +809,14 @@ ./Classes/LLNSWindow.h + + LLOpenGLView + NSOpenGLView + + IBProjectSource + ./Classes/LLOpenGLView.h + + 0 -- cgit v1.2.3 From ebe320e7c3579241e2e034a424ade9f087523b75 Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 19 Mar 2013 06:32:56 -0400 Subject: Refactored LLNSWindow and LLOpenGLView significantly. All input goes through LLOpenGLView now. --- indra/llwindow/llopenglview-objc.h | 6 +- indra/llwindow/llopenglview-objc.mm | 290 ++++++++++-------------------------- 2 files changed, 80 insertions(+), 216 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index c144831da4..5134063193 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -19,6 +19,7 @@ { std::string mLastDraggedUrl; unsigned int mModifiers; + float mMousePos[2]; } - (id) initWithSamples:(NSUInteger)samples; - (id) initWithSamples:(NSUInteger)samples andVsync:(BOOL)vsync; @@ -41,10 +42,7 @@ @end -@interface LLNSWindow : NSWindow { - float mMousePos[2]; - unsigned int mModifiers; -} +@interface LLNSWindow : NSWindow - (NSPoint)convertToScreenFromLocalPoint:(NSPoint)point relativeToView:(NSView *)view; - (NSPoint)flipPoint:(NSPoint)aPoint; diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index d568ed2fe5..45a5f24481 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -94,7 +94,6 @@ - (id) initWithFrame:(NSRect)frame withSamples:(NSUInteger)samples andVsync:(BOOL)vsync { - [[self window] makeFirstResponder:self]; [self registerForDraggedTypes:[NSArray arrayWithObject:NSURLPboardType]]; [self initWithFrame:frame]; @@ -188,102 +187,102 @@ // Various events can be intercepted by our view, thus not reaching our window. // Intercept these events, and pass them to the window as needed. - Geenz -- (void) mouseDragged:(NSEvent *)theEvent +- (void) mouseDown:(NSEvent *)theEvent { - [_window mouseDragged:theEvent]; + if ([theEvent clickCount] >= 2) + { + callDoubleClick(mMousePos, mModifiers); + } else if ([theEvent clickCount] == 1) { + callLeftMouseDown(mMousePos, mModifiers); + } } -- (void) scrollWheel:(NSEvent *)theEvent +- (void) mouseUp:(NSEvent *)theEvent { - [_window scrollWheel:theEvent]; + callLeftMouseUp(mMousePos, mModifiers); } -- (void) mouseDown:(NSEvent *)theEvent +- (void) rightMouseDown:(NSEvent *)theEvent { - [self becomeFirstResponder]; - [_window mouseDown:theEvent]; + callRightMouseDown(mMousePos, mModifiers); } -- (void) mouseUp:(NSEvent *)theEvent +- (void) rightMouseUp:(NSEvent *)theEvent { - [_window mouseUp:theEvent]; + callRightMouseUp(mMousePos, mModifiers); } -- (void) rightMouseDown:(NSEvent *)theEvent +- (void)mouseMoved:(NSEvent *)theEvent { - [_window rightMouseDown:theEvent]; + float mouseDeltas[2] = { + [theEvent deltaX], + [theEvent deltaY] + }; + + callDeltaUpdate(mouseDeltas, 0); + + NSPoint mPoint = [theEvent locationInWindow]; + mMousePos[0] = mPoint.x; + mMousePos[1] = mPoint.y; + callMouseMoved(mMousePos, 0); } -- (void) rightMouseUp:(NSEvent *)theEvent +// NSWindow doesn't trigger mouseMoved when the mouse is being clicked and dragged. +// Use mouseDragged for situations like this to trigger our movement callback instead. + +- (void) mouseDragged:(NSEvent *)theEvent { - [_window rightMouseUp:theEvent]; + // Trust the deltas supplied by NSEvent. + // The old CoreGraphics APIs we previously relied on are now flagged as obsolete. + // NSEvent isn't obsolete, and provides us with the correct deltas. + float mouseDeltas[2] = { + [theEvent deltaX], + [theEvent deltaY] + }; + + callDeltaUpdate(mouseDeltas, 0); + + NSPoint mPoint = [theEvent locationInWindow]; + mMousePos[0] = mPoint.x; + mMousePos[1] = mPoint.y; + callMouseMoved(mMousePos, 0); } - (void) otherMouseDown:(NSEvent *)theEvent { - [_window otherMouseDown:theEvent]; + callMiddleMouseDown(mMousePos, mModifiers); } - (void) otherMouseUp:(NSEvent *)theEvent { - [_window otherMouseUp:theEvent]; + callMiddleMouseUp(mMousePos, mModifiers); +} + +- (void) otherMouseDragged:(NSEvent *)theEvent +{ + +} + +- (void) scrollWheel:(NSEvent *)theEvent +{ + callScrollMoved(-[theEvent deltaY]); +} + +- (void) mouseExited:(NSEvent *)theEvent +{ + callMouseExit(); } - (void) keyUp:(NSEvent *)theEvent { - [_window keyUp:theEvent]; + callKeyUp([theEvent keyCode], mModifiers); } - (void) keyDown:(NSEvent *)theEvent { [[self inputContext] handleEvent:theEvent]; uint keycode = [theEvent keyCode]; - - switch (keycode) { - case 0x7b: - case 0x7c: - case 0x7d: - case 0x7e: - callKeyDown(keycode, mModifiers); - break; - - default: - callKeyDown(keycode, mModifiers); - NSString *chars = [theEvent characters]; - for (uint i = 0; i < [chars length]; i++) { - // Enter and Return are special cases. - unichar returntest = [chars characterAtIndex:i]; - if ((returntest == NSCarriageReturnCharacter || returntest == NSEnterCharacter) && - !([theEvent modifierFlags] & NSCommandKeyMask) && - !([theEvent modifierFlags] & NSAlternateKeyMask) && - !([theEvent modifierFlags] & NSControlKeyMask)) - { - callUnicodeCallback(13, 0); - } else { - // The command key being pressed is also a special case. - // Control + produces an ASCII control character code. - // Command + produces just the character's code. - // Check to see if the command key is pressed, then filter through the different character ranges that are relevant to control characters, and subtract the appropriate range. - if ([theEvent modifierFlags] & NSCommandKeyMask) - { - if (returntest >= 64 && returntest <= 95) - { - callUnicodeCallback(returntest - 63, mModifiers); - } else if (returntest >= 97 && returntest <= 122) - { - callUnicodeCallback(returntest - 96, mModifiers); - } - } - } - } - break; - } - -} - -- (void) mouseMoved:(NSEvent *)theEvent -{ - [_window mouseMoved:theEvent]; + callKeyDown(keycode, mModifiers); } - (void)flagsChanged:(NSEvent *)theEvent { @@ -291,11 +290,6 @@ callModifier([theEvent modifierFlags]); } -- (void) mouseExited:(NSEvent *)theEvent -{ - [_window mouseExited:theEvent]; -} - - (BOOL) acceptsFirstResponder { return YES; @@ -386,6 +380,18 @@ } } +- (void) insertNewline:(id)sender +{ + if (!(mModifiers & NSCommandKeyMask) && + !(mModifiers & NSShiftKeyMask) && + !(mModifiers & NSAlternateKeyMask)) + { + callUnicodeCallback(13, 0); + } else { + callUnicodeCallback(13, mModifiers); + } +} + - (NSUInteger)characterIndexForPoint:(NSPoint)aPoint { return NSNotFound; @@ -398,6 +404,10 @@ - (void)doCommandBySelector:(SEL)aSelector { + if (aSelector == @selector(insertNewline:)) + { + [self insertNewline:self]; + } } - (BOOL)drawsVerticallyForCharacterAtIndex:(NSUInteger)charIndex @@ -419,150 +429,6 @@ return self; } -- (void) keyDown:(NSEvent *)theEvent -{ - - uint keycode = [theEvent keyCode]; - - switch (keycode) { - case 0x7b: - case 0x7c: - case 0x7d: - case 0x7e: - callKeyDown(keycode, mModifiers); - break; - - default: - callKeyDown(keycode, mModifiers); - NSString *chars = [theEvent characters]; - for (uint i = 0; i < [chars length]; i++) { - // Enter and Return are special cases. - unichar returntest = [chars characterAtIndex:i]; - if ((returntest == NSCarriageReturnCharacter || returntest == NSEnterCharacter) && - !([theEvent modifierFlags] & NSCommandKeyMask) && - !([theEvent modifierFlags] & NSAlternateKeyMask) && - !([theEvent modifierFlags] & NSControlKeyMask)) - { - callUnicodeCallback(13, 0); - } else { - // The command key being pressed is also a special case. - // Control + produces an ASCII control character code. - // Command + produces just the character's code. - // Check to see if the command key is pressed, then filter through the different character ranges that are relevant to control characters, and subtract the appropriate range. - if ([theEvent modifierFlags] & NSCommandKeyMask) - { - if (returntest >= 64 && returntest <= 95) - { - callUnicodeCallback(returntest - 63, mModifiers); - } else if (returntest >= 97 && returntest <= 122) - { - callUnicodeCallback(returntest - 96, mModifiers); - } - } else { - callUnicodeCallback(returntest, mModifiers); - } - } - } - break; - } - -} - -- (void) keyUp:(NSEvent *)theEvent { - callKeyUp([theEvent keyCode], mModifiers); -} - -- (void)flagsChanged:(NSEvent *)theEvent { - mModifiers = [theEvent modifierFlags]; - callModifier([theEvent modifierFlags]); -} - -- (void) mouseDown:(NSEvent *)theEvent -{ - if ([theEvent clickCount] >= 2) - { - callDoubleClick(mMousePos, mModifiers); - } else if ([theEvent clickCount] == 1) { - callLeftMouseDown(mMousePos, mModifiers); - } -} - -- (void) mouseUp:(NSEvent *)theEvent -{ - callLeftMouseUp(mMousePos, mModifiers); -} - -- (void) rightMouseDown:(NSEvent *)theEvent -{ - callRightMouseDown(mMousePos, mModifiers); -} - -- (void) rightMouseUp:(NSEvent *)theEvent -{ - callRightMouseUp(mMousePos, mModifiers); -} - -- (void)mouseMoved:(NSEvent *)theEvent -{ - float mouseDeltas[2] = { - [theEvent deltaX], - [theEvent deltaY] - }; - - callDeltaUpdate(mouseDeltas, 0); - - NSPoint mPoint = [theEvent locationInWindow]; - mMousePos[0] = mPoint.x; - mMousePos[1] = mPoint.y; - callMouseMoved(mMousePos, 0); -} - -// NSWindow doesn't trigger mouseMoved when the mouse is being clicked and dragged. -// Use mouseDragged for situations like this to trigger our movement callback instead. - -- (void) mouseDragged:(NSEvent *)theEvent -{ - // Trust the deltas supplied by NSEvent. - // The old CoreGraphics APIs we previously relied on are now flagged as obsolete. - // NSEvent isn't obsolete, and provides us with the correct deltas. - float mouseDeltas[2] = { - [theEvent deltaX], - [theEvent deltaY] - }; - - callDeltaUpdate(mouseDeltas, 0); - - NSPoint mPoint = [theEvent locationInWindow]; - mMousePos[0] = mPoint.x; - mMousePos[1] = mPoint.y; - callMouseMoved(mMousePos, 0); -} - -- (void) otherMouseDown:(NSEvent *)theEvent -{ - callMiddleMouseDown(mMousePos, mModifiers); -} - -- (void) otherMouseUp:(NSEvent *)theEvent -{ - callMiddleMouseUp(mMousePos, mModifiers); -} - -- (void) otherMouseDragged:(NSEvent *)theEvent -{ - -} - -- (void) scrollWheel:(NSEvent *)theEvent -{ - callScrollMoved(-[theEvent deltaY]); -} - -- (void) mouseExited:(NSEvent *)theEvent -{ - callMouseExit(); -} - - (NSPoint)convertToScreenFromLocalPoint:(NSPoint)point relativeToView:(NSView *)view { NSScreen *currentScreen = [NSScreen currentScreenForMouseLocation]; -- cgit v1.2.3 From 64c0455db568e6818c483785cff0fcd9cfa47aff Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 19 Mar 2013 23:02:47 -0400 Subject: More LLPreeditor work. --- indra/llwindow/llopenglview-objc.mm | 10 +++++++--- indra/llwindow/llwindowmacosx-objc.h | 1 + indra/llwindow/llwindowmacosx-objc.mm | 5 +++++ indra/llwindow/llwindowmacosx.cpp | 24 ++++++++++++++++++++---- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 45a5f24481..ca00185dff 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -345,16 +345,21 @@ - (NSRange)markedRange { - return NSMakeRange(NSNotFound, 0); + int range[2]; + getPreeditMarkedRange(&range[0], &range[1]); + return NSMakeRange(range[0], range[1]); } - (NSRange)selectedRange { - return NSMakeRange(NSNotFound, 0); + int range[2]; + getPreeditSelectionRange(&range[0], &range[1]); + return NSMakeRange(range[0], range[1]); } - (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange { + } - (void)unmarkText @@ -425,7 +430,6 @@ - (id) init { - [self makeFirstResponder:[self contentView]]; return self; } diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index f3d6d2b1f1..57bb071690 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -74,6 +74,7 @@ void convertScreenToView(NSWindowRef window, float *coord); void setWindowPos(NSWindowRef window, float* pos); void closeWindow(NSWindowRef window); void removeGLView(GLViewRef view); +void makeFirstResponder(NSWindowRef window, GLViewRef view); // These are all implemented in llwindowmacosx.cpp. // This is largely for easier interop between Obj-C and C++ (at least in the viewer's case due to the BOOL vs. BOOL conflict) diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index b859f236d4..9530785b83 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -337,6 +337,11 @@ NSWindowRef getMainAppWindow() return winRef; } +void makeFirstResponder(NSWindowRef window, GLViewRef view) +{ + [(LLNSWindow*)window makeFirstResponder:(LLOpenGLView*)view]; +} + /* GLViewRef getGLView() { diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 08612bace4..7e4b9a84a1 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -383,22 +383,37 @@ void callQuitHandler() std::basic_string getPreeditString() { - return gWindowImplementation->getPreeditor()->getPreeditString(); + std::basic_string str; + if (gWindowImplementation->getPreeditor()) + { + str = gWindowImplementation->getPreeditor()->getPreeditString(); + } + + return str; } void getPreeditSelectionRange(int *position, int *length) { - gWindowImplementation->getPreeditor()->getSelectionRange(position, length); + if (gWindowImplementation->getPreeditor()) + { + gWindowImplementation->getPreeditor()->getSelectionRange(position, length); + } } void getPreeditMarkedRange(int *position, int *length) { - gWindowImplementation->getPreeditor()->getPreeditRange(position, length); + if (gWindowImplementation->getPreeditor()) + { + gWindowImplementation->getPreeditor()->getPreeditRange(position, length); + } } void handleUnicodeCharacter(wchar_t c) { - gWindowImplementation->getPreeditor()->handleUnicodeCharHere(c); + if (gWindowImplementation->getPreeditor()) + { + gWindowImplementation->getPreeditor()->handleUnicodeCharHere(c); + } } void LLWindowMacOSX::updateMouseDeltas(float* deltas) @@ -498,6 +513,7 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits } } LL_INFOS("Window") << "Completed context creation." << LL_ENDL; + makeFirstResponder(mWindow, mGLView); // Don't need to get the current gamma, since there's a call that restores it to the system defaults. return TRUE; } -- cgit v1.2.3 From 6c200a94f705667201bcaf0753986da90a2748eb Mon Sep 17 00:00:00 2001 From: Geenz Date: Sat, 23 Mar 2013 01:05:21 -0400 Subject: Fix for command key presses + a letter not triggering keyUp. Fix by Katharine Berry. --- indra/llwindow/llopenglview-objc.mm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index ca00185dff..de159816e0 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -283,6 +283,14 @@ [[self inputContext] handleEvent:theEvent]; uint keycode = [theEvent keyCode]; callKeyDown(keycode, mModifiers); + + // OS X intentionally does not send us key-up information on cmd-key combinations. + // This behaviour is not a bug, and only applies to cmd-combinations (no others). + // Since SL assumes we receive those, we fake it here. + if (mModifiers & NSCommandKeyMask) + { + callKeyUp([theEvent keyCode], mModifiers); + } } - (void)flagsChanged:(NSEvent *)theEvent { -- cgit v1.2.3 From 258b77b64777a5ce5fef0ef066aa52b34b43ba65 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 25 Mar 2013 05:26:55 -0400 Subject: Additional IME support. LLPreeditor is largely good to go at this point, but there's still some work to do in getSegments. --- indra/llwindow/llkeyboardmacosx.cpp | 1 - indra/llwindow/llopenglview-objc.h | 4 ++ indra/llwindow/llopenglview-objc.mm | 97 ++++++++++++++++++++++---- indra/llwindow/llwindowmacosx-objc.h | 11 +++ indra/llwindow/llwindowmacosx-objc.mm | 45 ++++++++++-- indra/llwindow/llwindowmacosx.cpp | 126 ++++++++++++++++++++++++++++++---- indra/newview/Info-SecondLife.plist | 2 +- indra/newview/llviewerkeyboard.cpp | 1 - indra/newview/llviewerwindow.cpp | 1 - 9 files changed, 252 insertions(+), 36 deletions(-) diff --git a/indra/llwindow/llkeyboardmacosx.cpp b/indra/llwindow/llkeyboardmacosx.cpp index 274e92c225..85bb7b9aeb 100644 --- a/indra/llwindow/llkeyboardmacosx.cpp +++ b/indra/llwindow/llkeyboardmacosx.cpp @@ -253,7 +253,6 @@ BOOL LLKeyboardMacOSX::handleKeyUp(const U16 key, const U32 mask) if(translateNumpadKey(key, &translated_key)) { - LL_INFOS("Keyboard") << "Handled key!" << LL_ENDL; handled = handleTranslatedKeyUp(translated_key, translated_mask); } diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 5134063193..8140421e44 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -20,6 +20,8 @@ std::string mLastDraggedUrl; unsigned int mModifiers; float mMousePos[2]; + bool mHasMarkedText; + unsigned int mMarkedTextLength; } - (id) initWithSamples:(NSUInteger)samples; - (id) initWithSamples:(NSUInteger)samples andVsync:(BOOL)vsync; @@ -40,6 +42,8 @@ - (unsigned long) getVramSize; +- (segment_t) getSegments:(NSAttributedString*)str; + @end @interface LLNSWindow : NSWindow diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index de159816e0..31b0e02ad8 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -281,15 +281,18 @@ - (void) keyDown:(NSEvent *)theEvent { [[self inputContext] handleEvent:theEvent]; - uint keycode = [theEvent keyCode]; - callKeyDown(keycode, mModifiers); - - // OS X intentionally does not send us key-up information on cmd-key combinations. - // This behaviour is not a bug, and only applies to cmd-combinations (no others). - // Since SL assumes we receive those, we fake it here. - if (mModifiers & NSCommandKeyMask) + if (!mHasMarkedText) { - callKeyUp([theEvent keyCode], mModifiers); + uint keycode = [theEvent keyCode]; + callKeyDown(keycode, mModifiers); + + // OS X intentionally does not send us key-up information on cmd-key combinations. + // This behaviour is not a bug, and only applies to cmd-combinations (no others). + // Since SL assumes we receive those, we fake it here. + if (mModifiers & NSCommandKeyMask) + { + callKeyUp([theEvent keyCode], mModifiers); + } } } @@ -348,7 +351,7 @@ - (BOOL)hasMarkedText { - return NO; + return mHasMarkedText; } - (NSRange)markedRange @@ -365,21 +368,73 @@ return NSMakeRange(range[0], range[1]); } -- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange +- (segment_t) getSegments:(NSAttributedString*)str { + segment_t segments; + + int segment = 0; + + NSRange l; + NSRange r = NSMakeRange(0, [str length]); + + while (r.length > 0) + { + NSNumber *segmentAttrib = [str attribute:NSUnderlineStyleAttributeName atIndex:r.location longestEffectiveRange:&l inRange:r]; + + r = NSMakeRange(NSMaxRange(l), NSMaxRange(r) - NSMaxRange(l)); + bool standout; + if ([segmentAttrib integerValue] == 1) + { + standout = false; + } else { + standout = true; + } + segments.insert(std::pair(l.length, standout)); + + segment++; + } + return segments; +} + +- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange +{ + if ([aString class] == NSClassFromString(@"NSConcreteMutableAttributedString")) + { + unsigned int selected[2] = { + selectedRange.location, + selectedRange.length + }; + + unsigned int replacement[2] = { + replacementRange.location, + replacementRange.length + }; + + NSLog(@"Attributed string: %@", aString); + + unichar text[[aString length]]; + [[aString mutableString] getCharacters:text range:NSMakeRange(0, [aString length])]; + segment_t segments = [self getSegments:(NSAttributedString *)aString]; + setMarkedText(text, selected, replacement, [aString length], segments); + mHasMarkedText = TRUE; + mMarkedTextLength = [aString length]; + } } - (void)unmarkText { - + resetPreedit(); + mHasMarkedText = FALSE; } +// We don't support attributed strings. - (NSArray *)validAttributesForMarkedText { return [NSArray array]; } +// See above. - (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange { return nil; @@ -387,9 +442,21 @@ - (void)insertText:(id)aString replacementRange:(NSRange)replacementRange { - for (NSInteger i = 0; i < [aString length]; i++) + if (!mHasMarkedText) { - callUnicodeCallback([aString characterAtIndex:i], mModifiers); + for (NSInteger i = 0; i < [aString length]; i++) + { + callUnicodeCallback([aString characterAtIndex:i], mModifiers); + } + } else { + // We may never get this point since unmarkText may be called before insertText ever gets called once we submit our text. + // But just in case... + resetPreedit(); + for (NSInteger i = 0; i < [aString length]; i++) + { + handleUnicodeCharacter([aString characterAtIndex:i]); + } + mHasMarkedText = FALSE; } } @@ -412,7 +479,9 @@ - (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange { - return NSZeroRect; + float pos[4] = {0, 0, 0, 0}; + getPreeditLocation(pos, mMarkedTextLength); + return NSMakeRect(pos[0], pos[1], pos[2], pos[3]); } - (void)doCommandBySelector:(SEL)aSelector diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 57bb071690..2de185fed3 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -25,6 +25,10 @@ * $/LicenseInfo$ */ +#include + +typedef std::map segment_t; + // This will actually hold an NSCursor*, but that type is only available in objective C. typedef void *CursorRef; typedef void *NSWindowRef; @@ -71,6 +75,8 @@ void makeWindowOrderFront(NSWindowRef window); void convertScreenToWindow(NSWindowRef window, float *coord); void convertWindowToScreen(NSWindowRef window, float *coord); void convertScreenToView(NSWindowRef window, float *coord); +void convertRectToScreen(NSWindowRef window, float *coord); +void convertRectFromScreen(NSWindowRef window, float *coord); void setWindowPos(NSWindowRef window, float* pos); void closeWindow(NSWindowRef window); void removeGLView(GLViewRef view); @@ -113,6 +119,11 @@ void getPreeditSelectionRange(int *position, int *length); void getPreeditMarkedRange(int *position, int *length); void handleUnicodeCharacter(wchar_t c); void updatePreeditor(unsigned short *str); +void setPreeditMarkedRange(int position, int length); +void resetPreedit(); +int wstring_length(const std::basic_string & wstr, const int woffset, const int utf16_length, int *unaligned); +void setMarkedText(unsigned short *text, unsigned int *selectedRange, unsigned int *replacementRange, long text_len, segment_t segments); +void getPreeditLocation(float *location, unsigned int length); NSWindowRef getMainAppWindow(); GLViewRef getGLView(); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 9530785b83..1a0647485c 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -119,6 +119,7 @@ CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY) void setArrowCursor() { NSCursor *cursor = [NSCursor arrowCursor]; + [NSCursor unhide]; [cursor set]; } @@ -290,12 +291,44 @@ void makeWindowOrderFront(NSWindowRef window) void convertScreenToWindow(NSWindowRef window, float *coord) { - NSPoint point; - point.x = coord[0]; - point.y = coord[1]; - point = [(LLNSWindow*)window convertScreenToBase:point]; - coord[0] = point.x; - coord[1] = point.y; + NSRect point; + point.origin.x = coord[0]; + point.origin.y = coord[1]; + point = [(LLNSWindow*)window convertRectFromScreen:point]; + coord[0] = point.origin.x; + coord[1] = point.origin.y; +} + +void convertRectToScreen(NSWindowRef window, float *coord) +{ + NSRect point; + point.origin.x = coord[0]; + point.origin.y = coord[1]; + point.size.width = coord[2]; + point.size.height = coord[3]; + + point = [(LLNSWindow*)window convertRectToScreen:point]; + + coord[0] = point.origin.x; + coord[1] = point.origin.y; + coord[2] = point.size.width; + coord[3] = point.size.height; +} + +void convertRectFromScreen(NSWindowRef window, float *coord) +{ + NSRect point; + point.origin.x = coord[0]; + point.origin.y = coord[1]; + point.size.width = coord[2]; + point.size.height = coord[3]; + + point = [(LLNSWindow*)window convertRectFromScreen:point]; + + coord[0] = point.origin.x; + coord[1] = point.origin.y; + coord[2] = point.size.width; + coord[3] = point.size.height; } void convertScreenToView(NSWindowRef window, float *coord) diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 7e4b9a84a1..4e8934b149 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -381,30 +381,27 @@ void callQuitHandler() } } -std::basic_string getPreeditString() +void getPreeditSelectionRange(int *position, int *length) { - std::basic_string str; if (gWindowImplementation->getPreeditor()) { - str = gWindowImplementation->getPreeditor()->getPreeditString(); + gWindowImplementation->getPreeditor()->getSelectionRange(position, length); } - - return str; } -void getPreeditSelectionRange(int *position, int *length) +void getPreeditMarkedRange(int *position, int *length) { if (gWindowImplementation->getPreeditor()) { - gWindowImplementation->getPreeditor()->getSelectionRange(position, length); + gWindowImplementation->getPreeditor()->getPreeditRange(position, length); } } -void getPreeditMarkedRange(int *position, int *length) +void setPreeditMarkedRange(int position, int length) { if (gWindowImplementation->getPreeditor()) { - gWindowImplementation->getPreeditor()->getPreeditRange(position, length); + gWindowImplementation->getPreeditor()->markAsPreedit(position, length); } } @@ -416,6 +413,69 @@ void handleUnicodeCharacter(wchar_t c) } } +void resetPreedit() +{ + if (gWindowImplementation->getPreeditor()) + { + gWindowImplementation->getPreeditor()->resetPreedit(); + } +} + +// For reasons of convenience, handle IME updates here. +// This largely mirrors the old implementation, only sans the carbon parameters. +void setMarkedText(unsigned short *unitext, unsigned int *selectedRange, unsigned int *replacementRange, long text_len, segment_t segments) +{ + if (gWindowImplementation->getPreeditor()) + { + LLPreeditor *preeditor = gWindowImplementation->getPreeditor(); + + // This should be a viable replacement for the kEventParamTextInputSendReplaceRange parameter. + if (replacementRange[0] < replacementRange[1]) + { + const LLWString& text = preeditor->getPreeditString(); + const S32 location = wstring_wstring_length_from_utf16_length(text, 0, replacementRange[0]); + const S32 length = wstring_wstring_length_from_utf16_length(text, location, replacementRange[1]); + preeditor->markAsPreedit(location, length); + } + + preeditor->resetPreedit(); + + LLWString fix_str = utf16str_to_wstring(llutf16string(unitext, text_len)); + + LLPreeditor::segment_lengths_t preedit_segment_lengths; + LLPreeditor::standouts_t preedit_standouts; + S32 caret_position = fix_str.length(); + + for (segment_t::iterator i = segments.begin(); i != segments.end(); i++) + { + preedit_segment_lengths.push_back(i->first); + preedit_standouts.push_back(i->second); + } + + preeditor->updatePreedit(fix_str, preedit_segment_lengths, preedit_standouts, caret_position); + } +} + +void getPreeditLocation(float *location, unsigned int length) +{ + if (gWindowImplementation->getPreeditor()) + { + LLPreeditor *preeditor = gWindowImplementation->getPreeditor(); + LLCoordGL coord; + LLCoordScreen screen; + LLRect rect; + + preeditor->getPreeditLocation(length, &coord, &rect, NULL); + + float c[4] = {coord.mX, coord.mY, 0, 0}; + + convertRectToScreen(gWindowImplementation->getWindow(), c); + + location[0] = c[0]; + location[1] = c[1]; + } +} + void LLWindowMacOSX::updateMouseDeltas(float* deltas) { if (mCursorDecoupled) @@ -1295,8 +1355,22 @@ BOOL LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordGL *to) BOOL LLWindowMacOSX::convertCoords(LLCoordGL from, LLCoordScreen *to) { LLCoordWindow window_coord; + if (mFullscreen) + { + to->mX = from.mX; + to->mY = from.mY; + return TRUE; + } else if (mWindow) + { + convertCoords(from, &window_coord); + convertCoords(window_coord, to); + + LL_INFOS("Coords") << to->mX << ", " << to->mY << LL_ENDL; + + return TRUE; + } - return(convertCoords(from, &window_coord) && convertCoords(window_coord, to)); + return FALSE; } @@ -1425,7 +1499,7 @@ void LLWindowMacOSX::updateCursor() // Find out what they look like and replicate them. // These are essentially correct - case UI_CURSOR_WAIT: /* Apple purposely doesn't allow us to set the beachball cursor manually. */ break; + case UI_CURSOR_WAIT: /* Apple purposely doesn't allow us to set the beachball cursor manually. Let NSApp figure out when to do this. */ break; case UI_CURSOR_IBEAM: setIBeamCursor(); break; case UI_CURSOR_CROSS: setCrossCursor(); break; case UI_CURSOR_HAND: setPointingHandCursor(); break; @@ -1810,7 +1884,35 @@ static long getDictLong (CFDictionaryRef refDict, CFStringRef key) void LLWindowMacOSX::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) { - // TODO: IME support + if (preeditor != mPreeditor && !b) + { + // This condition may occur by a call to + // setEnabled(BOOL) against LLTextEditor or LLLineEditor + // when the control is not focused. + // We need to silently ignore the case so that + // the language input status of the focused control + // is not disturbed. + return; + } + + // Take care of old and new preeditors. + if (preeditor != mPreeditor || !b) + { + // We need to interrupt before updating mPreeditor, + // so that the fix string from input method goes to + // the old preeditor. + if (mLanguageTextInputAllowed) + { + interruptLanguageTextInput(); + } + mPreeditor = (b ? preeditor : NULL); + } + + if (b == mLanguageTextInputAllowed) + { + return; + } + mLanguageTextInputAllowed = b; } void LLWindowMacOSX::interruptLanguageTextInput() diff --git a/indra/newview/Info-SecondLife.plist b/indra/newview/Info-SecondLife.plist index 5db52f040f..8fb4e88bc3 100644 --- a/indra/newview/Info-SecondLife.plist +++ b/indra/newview/Info-SecondLife.plist @@ -13,7 +13,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleName - Second Life + SecondLife CFBundlePackageType APPL CFBundleSignature diff --git a/indra/newview/llviewerkeyboard.cpp b/indra/newview/llviewerkeyboard.cpp index 92d8f2937e..f3b7c0fad4 100644 --- a/indra/newview/llviewerkeyboard.cpp +++ b/indra/newview/llviewerkeyboard.cpp @@ -653,7 +653,6 @@ BOOL LLViewerKeyboard::modeFromString(const std::string& string, S32 *mode) BOOL LLViewerKeyboard::handleKey(KEY translated_key, MASK translated_mask, BOOL repeated) { - LL_INFOS("Keyboard Handling") << "Handling key " << translated_key << LL_ENDL; // check for re-map EKeyboardMode mode = gViewerKeyboard.getMode(); U32 keyidx = (translated_mask<<16) | translated_key; diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index ccaa9245cf..48a69129eb 100755 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -2429,7 +2429,6 @@ void LLViewerWindow::draw() // Takes a single keydown event, usually when UI is visible BOOL LLViewerWindow::handleKey(KEY key, MASK mask) { - LL_INFOS("Keyboard Handling") << "Handling key " << key << LL_ENDL; // hide tooltips on keypress LLToolTipMgr::instance().blockToolTips(); -- cgit v1.2.3 From 80a79e5d7b4f37f862b312e848b1d1e7f85b0fa9 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 27 Mar 2013 08:49:45 -0400 Subject: IME support is pretty much finished at this point. --- indra/llwindow/llappdelegate-objc.h | 1 - indra/llwindow/llopenglview-objc.h | 4 +-- indra/llwindow/llopenglview-objc.mm | 66 ++++++++++++++++++----------------- indra/llwindow/llwindowmacosx-objc.h | 13 +++++-- indra/llwindow/llwindowmacosx-objc.mm | 2 +- indra/llwindow/llwindowmacosx.cpp | 13 ++----- indra/newview/llappdelegate-objc.mm | 1 + 7 files changed, 51 insertions(+), 49 deletions(-) diff --git a/indra/llwindow/llappdelegate-objc.h b/indra/llwindow/llappdelegate-objc.h index 56b7a30797..6a4794f3c3 100644 --- a/indra/llwindow/llappdelegate-objc.h +++ b/indra/llwindow/llappdelegate-objc.h @@ -8,7 +8,6 @@ #import #import "llopenglview-objc.h" -#include "llwindowmacosx-objc.h" @interface LLAppDelegate : NSObject { LLNSWindow *window; diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 8140421e44..5f972b1a98 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -10,7 +10,7 @@ #import #import #import -#include "llwindowmacosx-objc.h" +#include // Some nasty shovelling of LLOpenGLView from LLNativeBindings to prevent any C++ <-> Obj-C interop oddities. // Redraw callback handling removed (for now) due to being unneeded in the patch that preceeds this addition. @@ -42,8 +42,6 @@ - (unsigned long) getVramSize; -- (segment_t) getSegments:(NSAttributedString*)str; - @end @interface LLNSWindow : NSWindow diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 31b0e02ad8..376d238c90 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -7,6 +7,7 @@ // #import "llopenglview-objc.h" +#include "llwindowmacosx-objc.h" @implementation NSScreen (PointConversion) @@ -37,6 +38,37 @@ @end +attributedStringInfo getSegments(NSAttributedString *str) +{ + attributedStringInfo segments; + segment_lengths seg_lengths; + segment_standouts seg_standouts; + NSRange effectiveRange; + NSRange limitRange = NSMakeRange(0, [str length]); + while (limitRange.length > 0) { + NSNumber *attr = [str attribute:NSUnderlineStyleAttributeName atIndex:limitRange.location longestEffectiveRange:&effectiveRange inRange:limitRange]; + limitRange = NSMakeRange(NSMaxRange(effectiveRange), NSMaxRange(limitRange) - NSMaxRange(effectiveRange)); + + if (effectiveRange.length <= 0) + { + effectiveRange.length = 1; + } + + if ([attr integerValue] == 2) + { + seg_lengths.push_back(effectiveRange.length); + seg_standouts.push_back(true); + } else + { + seg_lengths.push_back(effectiveRange.length); + seg_standouts.push_back(false); + } + } + segments.seg_lengths = seg_lengths; + segments.seg_standouts = seg_standouts; + return segments; +} + @implementation LLOpenGLView - (unsigned long)getVramSize @@ -368,35 +400,6 @@ return NSMakeRange(range[0], range[1]); } -- (segment_t) getSegments:(NSAttributedString*)str -{ - segment_t segments; - - int segment = 0; - - NSRange l; - NSRange r = NSMakeRange(0, [str length]); - - while (r.length > 0) - { - NSNumber *segmentAttrib = [str attribute:NSUnderlineStyleAttributeName atIndex:r.location longestEffectiveRange:&l inRange:r]; - - r = NSMakeRange(NSMaxRange(l), NSMaxRange(r) - NSMaxRange(l)); - bool standout; - if ([segmentAttrib integerValue] == 1) - { - standout = false; - } else { - standout = true; - } - segments.insert(std::pair(l.length, standout)); - - segment++; - } - - return segments; -} - - (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange { if ([aString class] == NSClassFromString(@"NSConcreteMutableAttributedString")) @@ -411,11 +414,9 @@ replacementRange.length }; - NSLog(@"Attributed string: %@", aString); - unichar text[[aString length]]; [[aString mutableString] getCharacters:text range:NSMakeRange(0, [aString length])]; - segment_t segments = [self getSegments:(NSAttributedString *)aString]; + attributedStringInfo segments = getSegments((NSAttributedString *)aString); setMarkedText(text, selected, replacement, [aString length], segments); mHasMarkedText = TRUE; mMarkedTextLength = [aString length]; @@ -452,6 +453,7 @@ // We may never get this point since unmarkText may be called before insertText ever gets called once we submit our text. // But just in case... resetPreedit(); + for (NSInteger i = 0; i < [aString length]; i++) { handleUnicodeCharacter([aString characterAtIndex:i]); diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 2de185fed3..1d05db14b2 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -26,8 +26,17 @@ */ #include +#include -typedef std::map segment_t; +typedef std::vector > segment_t; + +typedef std::vector segment_lengths; +typedef std::vector segment_standouts; + +struct attributedStringInfo { + segment_lengths seg_lengths; + segment_standouts seg_standouts; +}; // This will actually hold an NSCursor*, but that type is only available in objective C. typedef void *CursorRef; @@ -122,7 +131,7 @@ void updatePreeditor(unsigned short *str); void setPreeditMarkedRange(int position, int length); void resetPreedit(); int wstring_length(const std::basic_string & wstr, const int woffset, const int utf16_length, int *unaligned); -void setMarkedText(unsigned short *text, unsigned int *selectedRange, unsigned int *replacementRange, long text_len, segment_t segments); +void setMarkedText(unsigned short *text, unsigned int *selectedRange, unsigned int *replacementRange, long text_len, attributedStringInfo segments); void getPreeditLocation(float *location, unsigned int length); NSWindowRef getMainAppWindow(); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 1a0647485c..43f853bfd1 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -27,8 +27,8 @@ #include #include -#include "llwindowmacosx-objc.h" #include "llopenglview-objc.h" +#include "llwindowmacosx-objc.h" #include "llappdelegate-objc.h" /* diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 4e8934b149..6f66da66a4 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -39,6 +39,7 @@ #include "indra_constants.h" #include +#include extern BOOL gDebugWindowProc; @@ -423,7 +424,7 @@ void resetPreedit() // For reasons of convenience, handle IME updates here. // This largely mirrors the old implementation, only sans the carbon parameters. -void setMarkedText(unsigned short *unitext, unsigned int *selectedRange, unsigned int *replacementRange, long text_len, segment_t segments) +void setMarkedText(unsigned short *unitext, unsigned int *selectedRange, unsigned int *replacementRange, long text_len, attributedStringInfo segments) { if (gWindowImplementation->getPreeditor()) { @@ -442,17 +443,9 @@ void setMarkedText(unsigned short *unitext, unsigned int *selectedRange, unsigne LLWString fix_str = utf16str_to_wstring(llutf16string(unitext, text_len)); - LLPreeditor::segment_lengths_t preedit_segment_lengths; - LLPreeditor::standouts_t preedit_standouts; S32 caret_position = fix_str.length(); - for (segment_t::iterator i = segments.begin(); i != segments.end(); i++) - { - preedit_segment_lengths.push_back(i->first); - preedit_standouts.push_back(i->second); - } - - preeditor->updatePreedit(fix_str, preedit_segment_lengths, preedit_standouts, caret_position); + preeditor->updatePreedit(fix_str, segments.seg_lengths, segments.seg_standouts, caret_position); } } diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm index 9e0e0e35c5..5fb5087cd8 100644 --- a/indra/newview/llappdelegate-objc.mm +++ b/indra/newview/llappdelegate-objc.mm @@ -7,6 +7,7 @@ // #import "llappdelegate-objc.h" +#include "llwindowmacosx-objc.h" @implementation LLAppDelegate -- cgit v1.2.3 From 2656b1f405dcf3b67d644bf47b02a64886ef2ca4 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 1 Apr 2013 08:15:12 -0400 Subject: First pass at adding a viable replacement for TSM's old UseInputWindow method (which is now deprecated with seemingly no Cocoa replacement). --- indra/llwindow/llappdelegate-objc.h | 6 +- indra/llwindow/llopenglview-objc.h | 12 +- indra/llwindow/llopenglview-objc.mm | 22 +- indra/llwindow/llwindowmacosx-objc.h | 2 + indra/llwindow/llwindowmacosx-objc.mm | 10 + indra/llwindow/llwindowmacosx.cpp | 14 +- indra/newview/SecondLife.nib | Bin 7403 -> 12997 bytes indra/newview/SecondLife.xib | 381 +++++++++++++++++++++++++++++++++- indra/newview/llappdelegate-objc.mm | 15 ++ 9 files changed, 444 insertions(+), 18 deletions(-) diff --git a/indra/llwindow/llappdelegate-objc.h b/indra/llwindow/llappdelegate-objc.h index 6a4794f3c3..e7f6ecd5fc 100644 --- a/indra/llwindow/llappdelegate-objc.h +++ b/indra/llwindow/llappdelegate-objc.h @@ -11,11 +11,15 @@ @interface LLAppDelegate : NSObject { LLNSWindow *window; + NSWindow *inputWindow; + LLNonInlineTextView *inputView; NSTimer *frameTimer; } @property (assign) IBOutlet LLNSWindow *window; +@property (assign) IBOutlet NSWindow *inputWindow; +@property (assign) IBOutlet LLNonInlineTextView *inputView; - (void) mainLoop; - +- (void) showInputWindow:(bool)show; @end diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 5f972b1a98..6b21148bb6 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -12,9 +12,6 @@ #import #include -// Some nasty shovelling of LLOpenGLView from LLNativeBindings to prevent any C++ <-> Obj-C interop oddities. -// Redraw callback handling removed (for now) due to being unneeded in the patch that preceeds this addition. - @interface LLOpenGLView : NSOpenGLView { std::string mLastDraggedUrl; @@ -44,6 +41,15 @@ @end +@interface LLNonInlineTextView : NSTextView +{ + LLOpenGLView *glview; +} + +- (void) setGLView:(LLOpenGLView*)view; + +@end + @interface LLNSWindow : NSWindow - (NSPoint)convertToScreenFromLocalPoint:(NSPoint)point relativeToView:(NSView *)view; diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 376d238c90..a6ef35a8eb 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -501,9 +501,25 @@ attributedStringInfo getSegments(NSAttributedString *str) @end -// We use a custom NSWindow for our event handling. -// Why not an NSWindowController you may ask? -// Answer: this is easier. +@implementation LLNonInlineTextView + +- (void) setGLView:(LLOpenGLView *)view +{ + glview = view; +} + +- (void) insertText:(id)insertString +{ + [self insertText:insertString replacementRange:NSMakeRange(0, 0)]; +} + +- (void) insertText:(id)aString replacementRange:(NSRange)replacementRange +{ + [glview insertText:aString replacementRange:replacementRange]; + [_window orderOut:_window]; +} + +@end @implementation LLNSWindow diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 1d05db14b2..14a0c22d66 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -90,6 +90,8 @@ void setWindowPos(NSWindowRef window, float* pos); void closeWindow(NSWindowRef window); void removeGLView(GLViewRef view); void makeFirstResponder(NSWindowRef window, GLViewRef view); +void setupInputWindow(NSWindowRef window, GLViewRef view); +void showInputWindow(bool show); // These are all implemented in llwindowmacosx.cpp. // This is largely for easier interop between Obj-C and C++ (at least in the viewer's case due to the BOOL vs. BOOL conflict) diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 43f853bfd1..0eef8c9f83 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -362,6 +362,16 @@ void removeGLView(GLViewRef view) [(LLOpenGLView*)view release]; } +void setupInputWindow(NSWindowRef window, GLViewRef glview) +{ + [[(LLAppDelegate*)[NSApp delegate] inputView] setGLView:(LLOpenGLView*)glview]; +} + +void showInputWindow(bool show) +{ + [(LLAppDelegate*)[NSApp delegate] showInputWindow:show]; +} + NSWindowRef getMainAppWindow() { LLNSWindow *winRef = [(LLAppDelegate*)[[NSApplication sharedApplication] delegate] window]; diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 6f66da66a4..2d0f981b3e 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -191,6 +191,8 @@ LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, //start with arrow cursor initCursors(); setCursor( UI_CURSOR_ARROW ); + + allowLanguageTextInput(NULL, FALSE); } mCallbacks = callbacks; @@ -513,18 +515,22 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits // Get the view instead. mGLView = createOpenGLView(mWindow, mFSAASamples, !disable_vsync); mContext = getCGLContextObj(mGLView); + // Since we just created the context, it needs to be set up. glNeedsInit = TRUE; gGLManager.mVRAM = getVramSize(mGLView); } - + + // This sets up our view to recieve text from our non-inline text input window. + setupInputWindow(mWindow, mGLView); + // Hook up the context to a drawable if(mContext != NULL) { - LL_INFOS("Window") << "Setting CGL Context..." << LL_ENDL; - LL_DEBUGS("Window") << "createContext: setting current context" << LL_ENDL; + + U32 err = CGLSetCurrentContext(mContext); if (err != kCGLNoError) { @@ -1888,6 +1894,8 @@ void LLWindowMacOSX::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) return; } + showInputWindow(!b); + // Take care of old and new preeditors. if (preeditor != mPreeditor || !b) { diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib index f55ddaabcd..0b0ff5308b 100644 Binary files a/indra/newview/SecondLife.nib and b/indra/newview/SecondLife.nib differ diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib index 7d20b7fd7c..fdfea49c42 100644 --- a/indra/newview/SecondLife.xib +++ b/indra/newview/SecondLife.xib @@ -11,9 +11,13 @@ 3084 + IBNSLayoutConstraint NSCustomObject NSMenu NSMenuItem + NSScrollView + NSScroller + NSTextView NSView NSWindowTemplate @@ -340,6 +344,202 @@ 128 YES + + 31 + 2 + {{272, 176}, {938, 42}} + -1535638528 + Window + NSPanel + + + + + 256 + + + + 256 + + + + 2304 + + + + 2322 + + Apple HTML pasteboard type + Apple PDF pasteboard type + Apple PICT pasteboard type + Apple PNG pasteboard type + Apple URL pasteboard type + CorePasteboardFlavorType 0x6D6F6F76 + NSColor pasteboard type + NSFilenamesPboardType + NSStringPboardType + NeXT Encapsulated PostScript v1.2 pasteboard type + NeXT RTFD pasteboard type + NeXT Rich Text Format v1.0 pasteboard type + NeXT TIFF v4.0 pasteboard type + NeXT font pasteboard type + NeXT ruler pasteboard type + WebURLsWithTitlesPboardType + public.url + + {938, 42} + + + + _NS:13 + + + + + + + + + + + + 166 + + + + 938 + 1 + + + 67121127 + 0 + + + 3 + MQA + + + + 6 + System + selectedTextBackgroundColor + + 3 + MC42NjY2NjY2NjY3AA + + + + 6 + System + selectedTextColor + + 3 + MAA + + + + + + + 1 + MCAwIDEAA + + + {8, -8} + 13 + + + + + + 1 + + 6 + {939, 10000000} + + + + {{1, 1}, {938, 42}} + + + + _NS:11 + + + + {4, 5} + + 79691776 + + + + + + file://localhost/Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/DVTIbeamCursor.tiff + + + + + 3 + MCAwAA + + + + 4 + + + + 256 + {{923, 1}, {16, 42}} + + + + _NS:83 + NO + + _doScroller: + 0.96666666666666667 + + + + -2147483392 + {{-100, -100}, {87, 18}} + + + + _NS:33 + NO + 1 + + _doScroller: + 1 + 0.94565218687057495 + + + {{-1, -1}, {940, 44}} + + + + _NS:9 + 133138 + + + + 0.25 + 4 + 1 + + + {938, 42} + + + + _NS:21 + + {{0, 0}, {2560, 1440}} + {10000000000000, 10000000000000} + YES + @@ -471,6 +671,22 @@ 850 + + + inputWindow + + + + 953 + + + + inputView + + + + 954 + @@ -726,6 +942,131 @@ + + 941 + + + + + + + + 942 + + + + + + 4 + 0 + + 4 + 1 + + -1 + + 1000 + + 8 + 29 + 3 + + + + 6 + 0 + + 6 + 1 + + -1 + + 1000 + + 8 + 29 + 3 + + + + 3 + 0 + + 3 + 1 + + -1 + + 1000 + + 8 + 29 + 3 + + + + 5 + 0 + + 5 + 1 + + -1 + + 1000 + + 8 + 29 + 3 + + + + + + 943 + + + + + + + + + + 944 + + + + + 945 + + + + + 946 + + + + + 949 + + + + + 950 + + + + + 951 + + + + + 952 + + + @@ -770,12 +1111,31 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + LLNonInlineTextView + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin - 940 + 954 @@ -783,13 +1143,18 @@ LLAppDelegate NSObject - LLOpenGLView + LLNonInlineTextView + NSWindow LLNSWindow - - glview - LLOpenGLView + + inputView + LLNonInlineTextView + + + inputWindow + NSWindow window @@ -810,11 +1175,11 @@ - LLOpenGLView - NSOpenGLView + LLNonInlineTextView + NSTextView IBProjectSource - ./Classes/LLOpenGLView.h + ./Classes/LLNonInlineTextView.h diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm index 5fb5087cd8..8da44fcf33 100644 --- a/indra/newview/llappdelegate-objc.mm +++ b/indra/newview/llappdelegate-objc.mm @@ -12,6 +12,8 @@ @implementation LLAppDelegate @synthesize window; +@synthesize inputWindow; +@synthesize inputView; - (void)dealloc { @@ -63,4 +65,17 @@ } } +- (void) showInputWindow:(bool)show +{ + if (show) + { + NSLog(@"Showing input window."); + [inputWindow makeKeyAndOrderFront:inputWindow]; + } else { + NSLog(@"Hiding input window."); + [inputWindow orderOut:inputWindow]; + [window makeKeyAndOrderFront:window]; + } +} + @end -- cgit v1.2.3 From 5098d43a9be5b9638a8806918e9bb82a096c000f Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 1 Apr 2013 08:25:11 -0400 Subject: STORM-1941: Cocoa project viewer: some coordinate conversions are off (Katharine Berry) --- doc/contributions.txt | 2 ++ indra/llwindow/llwindowmacosx.cpp | 70 +++++---------------------------------- 2 files changed, 10 insertions(+), 62 deletions(-) diff --git a/doc/contributions.txt b/doc/contributions.txt index e86ef11a72..f7f528e084 100644 --- a/doc/contributions.txt +++ b/doc/contributions.txt @@ -661,6 +661,8 @@ Kagehi Kohn Kaimen Takahe Katharine Berry STORM-1900 + STORM-1940 + STORM-1941 Keklily Longfall Ken Lavender Ken March diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 2d0f981b3e..4f6ae5c799 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -1255,52 +1255,21 @@ LLWindow::LLWindowResolution* LLWindowMacOSX::getSupportedResolutions(S32 &num_r BOOL LLWindowMacOSX::convertCoords(LLCoordGL from, LLCoordWindow *to) { - S32 client_height; - float client_rect[4]; - getContentViewBounds(mWindow, client_rect); - if (!mWindow || - NULL == to) - { - return FALSE; - } - to->mX = from.mX; - client_height = client_rect[3]; - to->mY = from.mY - 1; - + to->mY = from.mY; return TRUE; } BOOL LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordGL* to) { - S32 client_height; - float client_rect[4]; - - getContentViewBounds(mWindow, client_rect); - - if (!mWindow || - NULL == to) - { - return FALSE; - } - to->mX = from.mX; - client_height = client_rect[3]; - to->mY = from.mY - 1; - + to->mY = from.mY; return TRUE; } BOOL LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordWindow* to) { - if(mFullscreen) - { - // In the fullscreen case, window and screen coordinates are the same. - to->mX = from.mX; - to->mY = from.mY; - return TRUE; - } - else if(mWindow) + if(mWindow) { float mouse_point[2]; @@ -1314,20 +1283,12 @@ BOOL LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordWindow* to) return TRUE; } - return FALSE; } BOOL LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordScreen *to) { - if(mFullscreen) - { - // In the fullscreen case, window and screen coordinates are the same. - to->mX = from.mX; - to->mY = from.mY; - return TRUE; - } - else if(mWindow) + if(mWindow) { float mouse_point[2]; @@ -1340,7 +1301,6 @@ BOOL LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordScreen *to) return TRUE; } - return FALSE; } @@ -1354,22 +1314,8 @@ BOOL LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordGL *to) BOOL LLWindowMacOSX::convertCoords(LLCoordGL from, LLCoordScreen *to) { LLCoordWindow window_coord; - if (mFullscreen) - { - to->mX = from.mX; - to->mY = from.mY; - return TRUE; - } else if (mWindow) - { - convertCoords(from, &window_coord); - convertCoords(window_coord, to); - - LL_INFOS("Coords") << to->mX << ", " << to->mY << LL_ENDL; - - return TRUE; - } - return FALSE; + return(convertCoords(from, &window_coord) && convertCoords(window_coord, to)); } @@ -1981,11 +1927,11 @@ void LLWindowMacOSX::handleDragNDrop(std::string url, LLWindowCallbacks::DragNDr MASK mask = LLWindowMacOSX::modifiersToMask(getModifiers()); float mouse_point[2]; - // This will return the mouse point in global screen coords + // This will return the mouse point in window coords getCursorPos(mWindow, mouse_point); - LLCoordScreen screen_coords(mouse_point[0], mouse_point[1]); + LLCoordWindow window_coords(mouse_point[0], mouse_point[1]); LLCoordGL gl_pos; - convertCoords(screen_coords, &gl_pos); + convertCoords(window_coords, &gl_pos); if(!url.empty()) { -- cgit v1.2.3 From aa0cb35db561004c205c7aac2570407ae88ad472 Mon Sep 17 00:00:00 2001 From: Geenz Date: Sun, 7 Apr 2013 11:33:39 -0400 Subject: Support the committing of the current pre edit string when language input is interrupted per the viewer's original pre edit functionality. --- indra/llwindow/llopenglview-objc.h | 3 +++ indra/llwindow/llopenglview-objc.mm | 11 +++++++++++ indra/llwindow/llwindowmacosx-objc.h | 1 + indra/llwindow/llwindowmacosx-objc.mm | 5 +++++ indra/llwindow/llwindowmacosx.cpp | 2 +- 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 6b21148bb6..6d0f138950 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -19,11 +19,14 @@ float mMousePos[2]; bool mHasMarkedText; unsigned int mMarkedTextLength; + NSAttributedString *mMarkedText; } - (id) initWithSamples:(NSUInteger)samples; - (id) initWithSamples:(NSUInteger)samples andVsync:(BOOL)vsync; - (id) initWithFrame:(NSRect)frame withSamples:(NSUInteger)samples andVsync:(BOOL)vsync; +- (void)commitCurrentPreedit; + // rebuildContext // Destroys and recreates a context with the view's internal format set via setPixelFormat; // Use this in event of needing to rebuild a context for whatever reason, without needing to assign a new pixel format. diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index a6ef35a8eb..9d55b2c551 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -420,11 +420,20 @@ attributedStringInfo getSegments(NSAttributedString *str) setMarkedText(text, selected, replacement, [aString length], segments); mHasMarkedText = TRUE; mMarkedTextLength = [aString length]; + mMarkedText = (NSAttributedString*)[aString mutableString]; } } +- (void)commitCurrentPreedit +{ + [self insertText:mMarkedText replacementRange:NSMakeRange(0, [mMarkedText length])]; + [[self inputContext] discardMarkedText]; +} + - (void)unmarkText { + [[self inputContext] discardMarkedText]; + [mMarkedText setValue:@""]; resetPreedit(); mHasMarkedText = FALSE; } @@ -517,6 +526,8 @@ attributedStringInfo getSegments(NSAttributedString *str) { [glview insertText:aString replacementRange:replacementRange]; [_window orderOut:_window]; + [[self textStorage] setValue:@""]; + [[self inputContext] discardMarkedText]; } @end diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 14a0c22d66..59d956d4c8 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -117,6 +117,7 @@ void callFocus(); void callFocusLost(); void callModifier(unsigned int mask); void callQuitHandler(); +void commitCurrentPreedit(GLViewRef glView); #include void callHandleDragEntered(std::string url); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 0eef8c9f83..4bd65ade82 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -372,6 +372,11 @@ void showInputWindow(bool show) [(LLAppDelegate*)[NSApp delegate] showInputWindow:show]; } +void commitCurrentPreedit(GLViewRef glView) +{ + [(LLOpenGLView*)glView commitCurrentPreedit]; +} + NSWindowRef getMainAppWindow() { LLNSWindow *winRef = [(LLAppDelegate*)[[NSApplication sharedApplication] delegate] window]; diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 4f6ae5c799..e1220c83f4 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -1864,7 +1864,7 @@ void LLWindowMacOSX::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) void LLWindowMacOSX::interruptLanguageTextInput() { - // TODO: IME support + commitCurrentPreedit(mGLView); } //static -- cgit v1.2.3 From b27899ee0e035ebd4072a5e6162678f2afe81053 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 13 May 2013 19:39:45 -0400 Subject: Added IME input window white list. --- indra/llwindow/llappdelegate-objc.h | 4 ++++ indra/newview/SecondLife.nib | Bin 12997 -> 13009 bytes indra/newview/SecondLife.xib | 25 ++++++++++++-------- indra/newview/llappdelegate-objc.mm | 45 ++++++++++++++++++++++++++++++------ 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/indra/llwindow/llappdelegate-objc.h b/indra/llwindow/llappdelegate-objc.h index e7f6ecd5fc..be9ad4d79f 100644 --- a/indra/llwindow/llappdelegate-objc.h +++ b/indra/llwindow/llappdelegate-objc.h @@ -14,12 +14,16 @@ NSWindow *inputWindow; LLNonInlineTextView *inputView; NSTimer *frameTimer; + NSString *currentInputLanguage; } @property (assign) IBOutlet LLNSWindow *window; @property (assign) IBOutlet NSWindow *inputWindow; @property (assign) IBOutlet LLNonInlineTextView *inputView; +@property (retain) NSString *currentInputLanguage; + - (void) mainLoop; - (void) showInputWindow:(bool)show; +- (void) languageUpdated; @end diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib index 0b0ff5308b..cb289ebf09 100644 Binary files a/indra/newview/SecondLife.nib and b/indra/newview/SecondLife.nib differ diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib index fdfea49c42..c6b72485a1 100644 --- a/indra/newview/SecondLife.xib +++ b/indra/newview/SecondLife.xib @@ -2,9 +2,9 @@ 1060 - 12D78 + 12E30 3084 - 1187.37 + 1187.39 626.00 com.apple.InterfaceBuilder.CocoaPlugin @@ -329,16 +329,13 @@ - + 256 {1024, 600} - - - _NS:20 - {{0, 0}, {2560, 1440}} + {{0, 0}, {2560, 1418}} {10000000000000, 10000000000000} Second Life 128 @@ -349,7 +346,7 @@ 2 {{272, 176}, {938, 42}} -1535638528 - Window + Input Window NSPanel @@ -536,7 +533,7 @@ _NS:21 - {{0, 0}, {2560, 1440}} + {{0, 0}, {2560, 1418}} {10000000000000, 10000000000000} YES @@ -1112,7 +1109,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - + @@ -1182,6 +1179,14 @@ ./Classes/LLNonInlineTextView.h + + NSLayoutConstraint + NSObject + + IBProjectSource + ./Classes/NSLayoutConstraint.h + + 0 diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm index 8da44fcf33..de77447006 100644 --- a/indra/newview/llappdelegate-objc.mm +++ b/indra/newview/llappdelegate-objc.mm @@ -8,12 +8,14 @@ #import "llappdelegate-objc.h" #include "llwindowmacosx-objc.h" +#include // Used for Text Input Services ("Safe" API - it's well supported) @implementation LLAppDelegate @synthesize window; @synthesize inputWindow; @synthesize inputView; +@synthesize currentInputLanguage; - (void)dealloc { @@ -24,12 +26,16 @@ { frameTimer = nil; + [self languageUpdated]; + if (initViewer()) { frameTimer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(mainLoop) userInfo:nil repeats:YES]; } else { handleQuit(); } + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(languageUpdated) name:@"NSTextInputContextKeyboardSelectionDidChangeNotification" object:nil]; } - (void) applicationDidBecomeActive:(NSNotification *)notification @@ -67,15 +73,40 @@ - (void) showInputWindow:(bool)show { - if (show) + // How to add support for new languages with the input window: + // Simply append this array with the language code (ja for japanese, ko for korean, zh for chinese, etc.) + NSArray *authorizedLanguages = [[NSArray alloc] initWithObjects:@"ja", @"ko", @"zh-Hant", @"zh-Hans", nil]; + + if ([authorizedLanguages containsObject:currentInputLanguage]) { - NSLog(@"Showing input window."); - [inputWindow makeKeyAndOrderFront:inputWindow]; - } else { - NSLog(@"Hiding input window."); - [inputWindow orderOut:inputWindow]; - [window makeKeyAndOrderFront:window]; + if (show) + { + NSLog(@"Showing input window."); + [inputWindow makeKeyAndOrderFront:inputWindow]; + } else { + NSLog(@"Hiding input window."); + [inputWindow orderOut:inputWindow]; + [window makeKeyAndOrderFront:window]; + } } } +// This will get called multiple times by NSNotificationCenter. +// It will be called every time that the window focus changes, and every time that the input language gets changed. +// The primary use case for this selector is to update our current input language when the user, for whatever reason, changes the input language. +// This is the more elegant way of handling input language changes instead of checking every time we want to use the input window. + +- (void) languageUpdated +{ + TISInputSourceRef currentInput = TISCopyCurrentKeyboardInputSource(); + CFArrayRef languages = (CFArrayRef)TISGetInputSourceProperty(currentInput, kTISPropertyInputSourceLanguages); + +#if 1 // In the event of ever needing to add new language sources, change this to 1 and watch the terminal for "languages:" + NSLog(@"languages: %@", TISGetInputSourceProperty(currentInput, kTISPropertyInputSourceLanguages)); +#endif + + // Typically the language we want is going to be the very first result in the array. + currentInputLanguage = (NSString*)CFArrayGetValueAtIndex(languages, 0); +} + @end -- cgit v1.2.3 From 45cd21f7e1f87da60bfe16944267371f8a518799 Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 14 May 2013 00:53:42 -0400 Subject: Fix incorrect generation of Info.plist. Use a custom Info.plist template here. --- indra/newview/CMakeLists.txt | 25 +++++++++++++++---------- indra/newview/Info-SecondLife.plist | 30 ++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index bf0913a06b..221d421f30 100755 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -1965,20 +1965,25 @@ if (LINUX) endif (LINUX) if (DARWIN) + # These all get set with PROPERTIES set(product "Second Life") - + set(MACOSX_BUNDLE_INFO_STRING "Second Life Viewer") + set(MACOSX_BUNDLE_ICON_FILE "secondlife.icns") + set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.secondlife.indra.viewer") + set(MACOSX_BUNDLE_LONG_VERSION_STRING "${VIEWER_CHANNEL} ${VIEWER_SHORT_VERSION}.${VIEWER_VERSION_REVISION}") + set(MACOSX_BUNDLE_BUNDLE_NAME "SecondLife") + set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${VIEWER_SHORT_VERSION}") + set(MACOSX_BUNDLE_BUNDLE_VERSION "${VIEWER_SHORT_VERSION}${VIEWER_MACOSX_PHASE}${VIEWER_REVISION}") + set(MACOSX_BUNDLE_COPYRIGHT "Copyright © Linden Research, Inc. 2007") + set(MACOSX_BUNDLE_NSMAIN_NIB_FILE "SecondLife.nib") + set(MACOSX_BUNDLE_NSPRINCIPAL_CLASS "NSApplication") + set_target_properties( ${VIEWER_BINARY_NAME} PROPERTIES - OUTPUT_NAME "${product}" - MACOSX_BUNDLE_INFO_STRING "Second Life Viewer" - MACOSX_BUNDLE_ICON_FILE "secondlife.icns" - MACOSX_BUNDLE_GUI_IDENTIFIER "com.secondlife.indra.viewer" - MACOSX_BUNDLE_LONG_VERSION_STRING "${VIEWER_CHANNEL} ${VIEWER_SHORT_VERSION}.${VIEWER_VERSION_REVISION}" - MACOSX_BUNDLE_BUNDLE_NAME "Second Life" - MACOSX_BUNDLE_SHORT_VERSION_STRING "${VIEWER_SHORT_VERSION}" - MACOSX_BUNDLE_BUNDLE_VERSION "${VIEWER_SHORT_VERSION}${VIEWER_MACOSX_PHASE}${VIEWER_REVISION}" - MACOSX_BUNDLE_COPYRIGHT "Copyright © Linden Research, Inc. 2007" + OUTPUT_NAME "${product}" + MACOSX_BUNDLE_INFO_PLIST + "${CMAKE_CURRENT_SOURCE_DIR}/Info-SecondLife.plist" ) configure_file( diff --git a/indra/newview/Info-SecondLife.plist b/indra/newview/Info-SecondLife.plist index c7f1090e86..f584b61768 100755 --- a/indra/newview/Info-SecondLife.plist +++ b/indra/newview/Info-SecondLife.plist @@ -5,19 +5,33 @@ CFBundleDevelopmentRegion English CFBundleExecutable - Second Life + ${MACOSX_BUNDLE_EXECUTABLE_NAME} + CFBundleGetInfoString + ${MACOSX_BUNDLE_INFO_STRING} CFBundleIconFile - secondlife.icns + ${MACOSX_BUNDLE_ICON_FILE} CFBundleIdentifier - com.secondlife.indra.viewer + ${MACOSX_BUNDLE_GUI_IDENTIFIER} CFBundleInfoDictionaryVersion 6.0 + CFBundleLongVersionString + ${MACOSX_BUNDLE_LONG_VERSION_STRING} CFBundleName - SecondLife + ${MACOSX_BUNDLE_BUNDLE_NAME} CFBundlePackageType APPL + CFBundleShortVersionString + ${MACOSX_BUNDLE_SHORT_VERSION_STRING} CFBundleSignature ???? + CFBundleVersion + ${MACOSX_BUNDLE_BUNDLE_VERSION} + CSResourcesFileMapped + + LSRequiresCarbon + + NSHumanReadableCopyright + ${MACOSX_BUNDLE_COPYRIGHT} CFBundleDocumentTypes @@ -59,13 +73,9 @@ - CFBundleVersion - ${VIEWER_VERSION_MAJOR}.${VIEWER_VERSION_MINOR}.${VIEWER_VERSION_PATCH}.${VIEWER_VERSION_REVISION} NSPrincipalClass - NSApplication + ${MACOSX_BUNDLE_NSPRINCIPAL_CLASS} NSMainNibFile - SecondLife - CSResourcesFileMapped - + ${MACOSX_BUNDLE_NSMAIN_NIB_FILE} -- cgit v1.2.3 From 5683fe2fa332244a7e1e172021663a7d22c58e0c Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 14 May 2013 01:05:09 -0400 Subject: Fix the viewer bundle version not being set appropriately. --- indra/newview/Info-SecondLife.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/Info-SecondLife.plist b/indra/newview/Info-SecondLife.plist index f584b61768..9b8136a827 100755 --- a/indra/newview/Info-SecondLife.plist +++ b/indra/newview/Info-SecondLife.plist @@ -25,7 +25,7 @@ CFBundleSignature ???? CFBundleVersion - ${MACOSX_BUNDLE_BUNDLE_VERSION} + ${VIEWER_VERSION_MAJOR}.${VIEWER_VERSION_MINOR}.${VIEWER_VERSION_PATCH}.${VIEWER_VERSION_REVISION} CSResourcesFileMapped LSRequiresCarbon -- cgit v1.2.3 From cda10266ae91e28f2ac60b8472d6b8592f877d65 Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 23 May 2013 08:50:05 -0400 Subject: Only show the input window when we attempt to add marked text, *and* we can't submit marked text directly to the viewer. --- indra/llwindow/llopenglview-objc.h | 3 ++ indra/llwindow/llopenglview-objc.mm | 68 ++++++++++++++++++++++------------- indra/llwindow/llwindowmacosx-objc.h | 9 ++--- indra/llwindow/llwindowmacosx-objc.mm | 5 +++ indra/llwindow/llwindowmacosx.cpp | 42 ++++++++++------------ 5 files changed, 75 insertions(+), 52 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 6d0f138950..e20ea533fb 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -20,6 +20,7 @@ bool mHasMarkedText; unsigned int mMarkedTextLength; NSAttributedString *mMarkedText; + bool mMarkedTextAllowed; } - (id) initWithSamples:(NSUInteger)samples; - (id) initWithSamples:(NSUInteger)samples andVsync:(BOOL)vsync; @@ -42,6 +43,8 @@ - (unsigned long) getVramSize; +- (void) allowMarkedTextInput:(bool)allowed; + @end @interface LLNonInlineTextView : NSTextView diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 9d55b2c551..8ef6d4e682 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -45,6 +45,7 @@ attributedStringInfo getSegments(NSAttributedString *str) segment_standouts seg_standouts; NSRange effectiveRange; NSRange limitRange = NSMakeRange(0, [str length]); + while (limitRange.length > 0) { NSNumber *attr = [str attribute:NSUnderlineStyleAttributeName atIndex:limitRange.location longestEffectiveRange:&effectiveRange inRange:limitRange]; limitRange = NSMakeRange(NSMaxRange(effectiveRange), NSMaxRange(limitRange) - NSMaxRange(effectiveRange)); @@ -402,32 +403,40 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange { - if ([aString class] == NSClassFromString(@"NSConcreteMutableAttributedString")) - { - unsigned int selected[2] = { - selectedRange.location, - selectedRange.length - }; - - unsigned int replacement[2] = { - replacementRange.location, - replacementRange.length - }; - - unichar text[[aString length]]; - [[aString mutableString] getCharacters:text range:NSMakeRange(0, [aString length])]; - attributedStringInfo segments = getSegments((NSAttributedString *)aString); - setMarkedText(text, selected, replacement, [aString length], segments); - mHasMarkedText = TRUE; - mMarkedTextLength = [aString length]; - mMarkedText = (NSAttributedString*)[aString mutableString]; - } + if (mMarkedTextAllowed) + { + if ([aString class] == NSClassFromString(@"NSConcreteMutableAttributedString")) + { + unsigned int selected[2] = { + selectedRange.location, + selectedRange.length + }; + + unsigned int replacement[2] = { + replacementRange.location, + replacementRange.length + }; + + unichar text[[aString length]]; + [[aString mutableString] getCharacters:text range:NSMakeRange(0, [aString length])]; + attributedStringInfo segments = getSegments((NSAttributedString *)aString); + setMarkedText(text, selected, replacement, [aString length], segments); + mHasMarkedText = TRUE; + mMarkedTextLength = [aString length]; + mMarkedText = (NSAttributedString*)[aString mutableString]; + } + } else { + showInputWindow(true); + } } - (void)commitCurrentPreedit { - [self insertText:mMarkedText replacementRange:NSMakeRange(0, [mMarkedText length])]; - [[self inputContext] discardMarkedText]; + if (mMarkedText) + { + [self insertText:mMarkedText]; + [[self inputContext] discardMarkedText]; + } } - (void)unmarkText @@ -452,11 +461,12 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void)insertText:(id)aString replacementRange:(NSRange)replacementRange { + bool success = false; if (!mHasMarkedText) { for (NSInteger i = 0; i < [aString length]; i++) { - callUnicodeCallback([aString characterAtIndex:i], mModifiers); + success = callUnicodeCallback([aString characterAtIndex:i], mModifiers); } } else { // We may never get this point since unmarkText may be called before insertText ever gets called once we submit our text. @@ -465,10 +475,12 @@ attributedStringInfo getSegments(NSAttributedString *str) for (NSInteger i = 0; i < [aString length]; i++) { - handleUnicodeCharacter([aString characterAtIndex:i]); + success = handleUnicodeCharacter([aString characterAtIndex:i]); } mHasMarkedText = FALSE; } + + NSLog(@"Successful text input: %d", success); } - (void) insertNewline:(id)sender @@ -508,6 +520,11 @@ attributedStringInfo getSegments(NSAttributedString *str) return NO; } +- (void) allowMarkedTextInput:(bool)allowed +{ + mMarkedTextAllowed = allowed; +} + @end @implementation LLNonInlineTextView @@ -525,9 +542,10 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange { [glview insertText:aString replacementRange:replacementRange]; - [_window orderOut:_window]; [[self textStorage] setValue:@""]; [[self inputContext] discardMarkedText]; + [self setString:@""]; + [_window orderOut:_window]; } @end diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 59d956d4c8..62543fa01d 100755 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -95,10 +95,10 @@ void showInputWindow(bool show); // These are all implemented in llwindowmacosx.cpp. // This is largely for easier interop between Obj-C and C++ (at least in the viewer's case due to the BOOL vs. BOOL conflict) -void callKeyUp(unsigned short key, unsigned int mask); -void callKeyDown(unsigned short key, unsigned int mask); +bool callKeyUp(unsigned short key, unsigned int mask); +bool callKeyDown(unsigned short key, unsigned int mask); void callResetKeys(); -void callUnicodeCallback(wchar_t character, unsigned int mask); +bool callUnicodeCallback(wchar_t character, unsigned int mask); void callRightMouseDown(float *pos, unsigned int mask); void callRightMouseUp(float *pos, unsigned int mask); void callLeftMouseDown(float *pos, unsigned int mask); @@ -129,13 +129,14 @@ void callHandleDragDropped(std::string url); std::basic_string getPreeditString(); void getPreeditSelectionRange(int *position, int *length); void getPreeditMarkedRange(int *position, int *length); -void handleUnicodeCharacter(wchar_t c); +bool handleUnicodeCharacter(wchar_t c); void updatePreeditor(unsigned short *str); void setPreeditMarkedRange(int position, int length); void resetPreedit(); int wstring_length(const std::basic_string & wstr, const int woffset, const int utf16_length, int *unaligned); void setMarkedText(unsigned short *text, unsigned int *selectedRange, unsigned int *replacementRange, long text_len, attributedStringInfo segments); void getPreeditLocation(float *location, unsigned int length); +void allowDirectMarkedTextInput(bool allow); NSWindowRef getMainAppWindow(); GLViewRef getGLView(); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 4bd65ade82..95b9cdb863 100755 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -377,6 +377,11 @@ void commitCurrentPreedit(GLViewRef glView) [(LLOpenGLView*)glView commitCurrentPreedit]; } +void allowDirectMarkedTextInput(bool allow) +{ + +} + NSWindowRef getMainAppWindow() { LLNSWindow *winRef = [(LLAppDelegate*)[[NSApplication sharedApplication] delegate] window]; diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index e1220c83f4..16fd7e3382 100755 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -204,14 +204,14 @@ LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, // These functions are used as wrappers for our internal event handling callbacks. // It's a good idea to wrap these to avoid reworking more code than we need to within LLWindow. -void callKeyUp(unsigned short key, unsigned int mask) +bool callKeyUp(unsigned short key, unsigned int mask) { - gKeyboard->handleKeyUp(key, mask); + return gKeyboard->handleKeyUp(key, mask); } -void callKeyDown(unsigned short key, unsigned int mask) +bool callKeyDown(unsigned short key, unsigned int mask) { - gKeyboard->handleKeyDown(key, mask); + return gKeyboard->handleKeyDown(key, mask); } void callResetKeys() @@ -219,9 +219,9 @@ void callResetKeys() gKeyboard->resetKeys(); } -void callUnicodeCallback(wchar_t character, unsigned int mask) +bool callUnicodeCallback(wchar_t character, unsigned int mask) { - gWindowImplementation->getCallbacks()->handleUnicodeChar(character, mask); + return gWindowImplementation->getCallbacks()->handleUnicodeChar(character, mask); } void callFocus() @@ -408,12 +408,15 @@ void setPreeditMarkedRange(int position, int length) } } -void handleUnicodeCharacter(wchar_t c) +bool handleUnicodeCharacter(wchar_t c) { + bool success = false; if (gWindowImplementation->getPreeditor()) { - gWindowImplementation->getPreeditor()->handleUnicodeCharHere(c); + success = gWindowImplementation->getPreeditor()->handleUnicodeCharHere(c); } + + return success; } void resetPreedit() @@ -1033,21 +1036,7 @@ BOOL LLWindowMacOSX::setCursorPosition(const LLCoordWindow position) return result; } -/* -static void fixOrigin(void) -{ - GrafPtr port; - Rect portrect; - ::GetPort(&port); - ::GetPortBounds(port, &portrect); - if((portrect.left != 0) || (portrect.top != 0)) - { - // Mozilla sometimes changes our port origin. - ::SetOrigin(0,0); - } -} -*/ BOOL LLWindowMacOSX::getCursorPosition(LLCoordWindow *position) { float cursor_point[2]; @@ -1840,7 +1829,14 @@ void LLWindowMacOSX::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) return; } - showInputWindow(!b); + if (preeditor == NULL) { + // If we don't have a pre editor, then we can't accept direct marked text input. + // We needs an input window (which is handled internally by LLOpenGLView) + allowDirectMarkedTextInput(false); + } else { + // If we have a preeditor, then accept direct marked text input. + allowDirectMarkedTextInput(true); + } // Take care of old and new preeditors. if (preeditor != mPreeditor || !b) -- cgit v1.2.3 From 7decac40e6453b2d8822d2677b9b59300bc260cf Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 23 May 2013 09:39:49 -0400 Subject: Override NSPanel's close method to hide the window instead of actually removing the window. --- indra/llwindow/llopenglview-objc.h | 4 ++++ indra/llwindow/llopenglview-objc.mm | 25 ++++++++++++++++++++++++- indra/newview/SecondLife.nib | Bin 13009 -> 13021 bytes indra/newview/SecondLife.xib | 14 +++++++------- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index e20ea533fb..5309dea664 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -47,6 +47,10 @@ @end +@interface LLUserInputWindow : NSPanel + +@end + @interface LLNonInlineTextView : NSTextView { LLOpenGLView *glview; diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 8ef6d4e682..17e8c3e3cc 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -527,6 +527,15 @@ attributedStringInfo getSegments(NSAttributedString *str) @end +@implementation LLUserInputWindow + +- (void) close +{ + [self orderOut:self]; +} + +@end + @implementation LLNonInlineTextView - (void) setGLView:(LLOpenGLView *)view @@ -536,16 +545,30 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void) insertText:(id)insertString { + [[self inputContext] discardMarkedText]; + [self setString:@""]; + [_window orderOut:_window]; [self insertText:insertString replacementRange:NSMakeRange(0, 0)]; } - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange { [glview insertText:aString replacementRange:replacementRange]; +} + +- (void) insertNewline:(id)sender +{ [[self textStorage] setValue:@""]; [[self inputContext] discardMarkedText]; [self setString:@""]; - [_window orderOut:_window]; +} + +- (void)doCommandBySelector:(SEL)aSelector +{ + if (aSelector == @selector(insertNewline:)) + { + [self insertNewline:self]; + } } @end diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib index cb289ebf09..a5f2717167 100644 Binary files a/indra/newview/SecondLife.nib and b/indra/newview/SecondLife.nib differ diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib index c6b72485a1..e5736f76a4 100644 --- a/indra/newview/SecondLife.xib +++ b/indra/newview/SecondLife.xib @@ -2,7 +2,7 @@ 1060 - 12E30 + 12E52 3084 1187.39 626.00 @@ -335,7 +335,7 @@ {1024, 600} _NS:20 - {{0, 0}, {2560, 1418}} + {{0, 0}, {2560, 1440}} {10000000000000, 10000000000000} Second Life 128 @@ -347,7 +347,7 @@ {{272, 176}, {938, 42}} -1535638528 Input Window - NSPanel + LLUserInputWindow @@ -533,7 +533,7 @@ _NS:21 - {{0, 0}, {2560, 1418}} + {{0, 0}, {2560, 1440}} {10000000000000, 10000000000000} YES @@ -1180,11 +1180,11 @@ - NSLayoutConstraint - NSObject + LLUserInputWindow + NSPanel IBProjectSource - ./Classes/NSLayoutConstraint.h + ./Classes/LLUserInputWindow.h -- cgit v1.2.3 From f782e0192009b249edcb30ca2a5418ec7c1ddfa4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sat, 15 Jun 2013 05:18:50 -0700 Subject: NORSPEC-267 fix UI feedback for materials edits not appearing for observers when obj was selected by them --- indra/llprimitive/lltextureentry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/llprimitive/lltextureentry.cpp b/indra/llprimitive/lltextureentry.cpp index 597f078490..0db75a0e82 100755 --- a/indra/llprimitive/lltextureentry.cpp +++ b/indra/llprimitive/lltextureentry.cpp @@ -545,7 +545,7 @@ S32 LLTextureEntry::setMaterialID(const LLMaterialID& pMaterialID) { mMaterialUpdatePending = true; mMaterialID = pMaterialID; - return TEM_CHANGE_NONE; + return TEM_CHANGE_TEXTURE; } mMaterialUpdatePending = false; -- cgit v1.2.3 From d75667560c35a578cc3876bde485ca2a44604992 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sat, 15 Jun 2013 07:19:23 -0700 Subject: Silence spurious asserts when pool is cleared at exactly it's limit --- indra/llcommon/llapr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index a0802c6adf..b7815b0e35 100755 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -226,7 +226,7 @@ void LLVolatileAPRPool::clearVolatileAPRPool() llassert_always(mNumActiveRef > 0) ; } - llassert(mNumTotalRef < (FULL_VOLATILE_APR_POOL << 2)) ; + llassert(mNumTotalRef <= (FULL_VOLATILE_APR_POOL << 2)) ; } BOOL LLVolatileAPRPool::isFull() -- cgit v1.2.3 From f8abfb63c32a0926a393a4359c6f387482d2448e Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 17 Jun 2013 07:52:19 -0400 Subject: This brings us to feature parity with CHUI for IME support. --- indra/llwindow/llopenglview-objc.mm | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 17e8c3e3cc..b431321da6 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -313,12 +313,13 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void) keyDown:(NSEvent *)theEvent { - [[self inputContext] handleEvent:theEvent]; if (!mHasMarkedText) { uint keycode = [theEvent keyCode]; - callKeyDown(keycode, mModifiers); - + if (callKeyDown(keycode, mModifiers)) + { + [[self inputContext] handleEvent:theEvent]; + } // OS X intentionally does not send us key-up information on cmd-key combinations. // This behaviour is not a bug, and only applies to cmd-combinations (no others). // Since SL assumes we receive those, we fake it here. @@ -461,12 +462,11 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void)insertText:(id)aString replacementRange:(NSRange)replacementRange { - bool success = false; if (!mHasMarkedText) { for (NSInteger i = 0; i < [aString length]; i++) { - success = callUnicodeCallback([aString characterAtIndex:i], mModifiers); + callUnicodeCallback([aString characterAtIndex:i], mModifiers); } } else { // We may never get this point since unmarkText may be called before insertText ever gets called once we submit our text. @@ -475,12 +475,10 @@ attributedStringInfo getSegments(NSAttributedString *str) for (NSInteger i = 0; i < [aString length]; i++) { - success = handleUnicodeCharacter([aString characterAtIndex:i]); + handleUnicodeCharacter([aString characterAtIndex:i]); } mHasMarkedText = FALSE; } - - NSLog(@"Successful text input: %d", success); } - (void) insertNewline:(id)sender -- cgit v1.2.3 From 93531f3ba85748ba5c9f1d797c4925f55fe8b92c Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 17 Jun 2013 08:59:01 -0400 Subject: Insert text into the input window when we attempt to insert text without a pre-editor. Also handle backspace as a special case when determining if the input window needs to be displayed. --- indra/llwindow/llappdelegate-objc.h | 2 +- indra/llwindow/llopenglview-objc.mm | 13 +++++++++---- indra/llwindow/llwindowmacosx-objc.h | 2 +- indra/llwindow/llwindowmacosx-objc.mm | 4 ++-- indra/newview/llappdelegate-objc.mm | 3 ++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/indra/llwindow/llappdelegate-objc.h b/indra/llwindow/llappdelegate-objc.h index be9ad4d79f..b1d78d5e3c 100644 --- a/indra/llwindow/llappdelegate-objc.h +++ b/indra/llwindow/llappdelegate-objc.h @@ -24,6 +24,6 @@ @property (retain) NSString *currentInputLanguage; - (void) mainLoop; -- (void) showInputWindow:(bool)show; +- (void) showInputWindow:(bool)show withText:(id)text; - (void) languageUpdated; @end diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index b431321da6..062577baf8 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -404,10 +404,11 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange { - if (mMarkedTextAllowed) + if ([aString class] == NSClassFromString(@"NSConcreteMutableAttributedString")) { - if ([aString class] == NSClassFromString(@"NSConcreteMutableAttributedString")) + if (mMarkedTextAllowed) { + unsigned int selected[2] = { selectedRange.location, selectedRange.length @@ -425,9 +426,13 @@ attributedStringInfo getSegments(NSAttributedString *str) mHasMarkedText = TRUE; mMarkedTextLength = [aString length]; mMarkedText = (NSAttributedString*)[aString mutableString]; + } else if ([[aString mutableString] characterAtIndex:0] != NSBackspaceCharacter) { + showInputWindow(true, aString); + if (mHasMarkedText) + { + [self unmarkText]; + } } - } else { - showInputWindow(true); } } diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 62543fa01d..daf7596cab 100755 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -91,7 +91,7 @@ void closeWindow(NSWindowRef window); void removeGLView(GLViewRef view); void makeFirstResponder(NSWindowRef window, GLViewRef view); void setupInputWindow(NSWindowRef window, GLViewRef view); -void showInputWindow(bool show); +void showInputWindow(bool show, void* text); // These are all implemented in llwindowmacosx.cpp. // This is largely for easier interop between Obj-C and C++ (at least in the viewer's case due to the BOOL vs. BOOL conflict) diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 95b9cdb863..7f1af129b4 100755 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -367,9 +367,9 @@ void setupInputWindow(NSWindowRef window, GLViewRef glview) [[(LLAppDelegate*)[NSApp delegate] inputView] setGLView:(LLOpenGLView*)glview]; } -void showInputWindow(bool show) +void showInputWindow(bool show, void* text) { - [(LLAppDelegate*)[NSApp delegate] showInputWindow:show]; + [(LLAppDelegate*)[NSApp delegate] showInputWindow:show withText:(id)text]; } void commitCurrentPreedit(GLViewRef glView) diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm index de77447006..b4f9c56b00 100644 --- a/indra/newview/llappdelegate-objc.mm +++ b/indra/newview/llappdelegate-objc.mm @@ -71,7 +71,7 @@ } } -- (void) showInputWindow:(bool)show +- (void) showInputWindow:(bool)show withText:(id)text { // How to add support for new languages with the input window: // Simply append this array with the language code (ja for japanese, ko for korean, zh for chinese, etc.) @@ -83,6 +83,7 @@ { NSLog(@"Showing input window."); [inputWindow makeKeyAndOrderFront:inputWindow]; + [inputView setMarkedText:text selectedRange:NSMakeRange(0, 1)]; } else { NSLog(@"Hiding input window."); [inputWindow orderOut:inputWindow]; -- cgit v1.2.3 From 440a1ee3bae4ea9553fa57d806f942a472923190 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 17 Jun 2013 09:26:11 -0400 Subject: Move logic involving the input window to keyDown. Pass input events to the input window from there. --- indra/llwindow/llopenglview-objc.h | 5 +++++ indra/llwindow/llopenglview-objc.mm | 9 +++++++-- indra/newview/llappdelegate-objc.mm | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 5309dea664..d4207d598a 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -6,6 +6,9 @@ // // +#ifndef LLOpenGLView_H +#define LLOpenGLView_H + #import #import #import @@ -85,3 +88,5 @@ - (NSPoint)flipPoint:(NSPoint)aPoint; @end + +#endif \ No newline at end of file diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 062577baf8..99c27e79a0 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -8,6 +8,7 @@ #import "llopenglview-objc.h" #include "llwindowmacosx-objc.h" +#import "llappdelegate-objc.h" @implementation NSScreen (PointConversion) @@ -318,6 +319,11 @@ attributedStringInfo getSegments(NSAttributedString *str) uint keycode = [theEvent keyCode]; if (callKeyDown(keycode, mModifiers)) { + if (!mMarkedTextAllowed && [[theEvent characters] characterAtIndex:0] != NSBackspaceCharacter) + { + showInputWindow(true, @""); + [[[(LLAppDelegate*)[NSApp delegate] inputView] inputContext] handleEvent:theEvent]; + } [[self inputContext] handleEvent:theEvent]; } // OS X intentionally does not send us key-up information on cmd-key combinations. @@ -426,8 +432,7 @@ attributedStringInfo getSegments(NSAttributedString *str) mHasMarkedText = TRUE; mMarkedTextLength = [aString length]; mMarkedText = (NSAttributedString*)[aString mutableString]; - } else if ([[aString mutableString] characterAtIndex:0] != NSBackspaceCharacter) { - showInputWindow(true, aString); + } else { if (mHasMarkedText) { [self unmarkText]; diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm index b4f9c56b00..403c307085 100644 --- a/indra/newview/llappdelegate-objc.mm +++ b/indra/newview/llappdelegate-objc.mm @@ -8,7 +8,7 @@ #import "llappdelegate-objc.h" #include "llwindowmacosx-objc.h" -#include // Used for Text Input Services ("Safe" API - it's well supported) +#include // Used for Text Input Services ("Safe" API - it's supported) @implementation LLAppDelegate -- cgit v1.2.3 From 2253d22eb85a6b4c5e48b9905d807d0ac48b1930 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 17 Jun 2013 10:28:32 -0400 Subject: Have showInputWindow hand off input events to the bottom line input window. --- indra/llwindow/llappdelegate-objc.h | 2 +- indra/llwindow/llopenglview-objc.mm | 9 +++++++-- indra/llwindow/llwindowmacosx-objc.h | 1 - indra/llwindow/llwindowmacosx-objc.mm | 5 ----- indra/newview/llappdelegate-objc.mm | 7 +++++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/indra/llwindow/llappdelegate-objc.h b/indra/llwindow/llappdelegate-objc.h index b1d78d5e3c..266f417c4b 100644 --- a/indra/llwindow/llappdelegate-objc.h +++ b/indra/llwindow/llappdelegate-objc.h @@ -24,6 +24,6 @@ @property (retain) NSString *currentInputLanguage; - (void) mainLoop; -- (void) showInputWindow:(bool)show withText:(id)text; +- (void) showInputWindow:(bool)show withEvent:(NSEvent*)textEvent; - (void) languageUpdated; @end diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 99c27e79a0..2afd4993c5 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -321,11 +321,16 @@ attributedStringInfo getSegments(NSAttributedString *str) { if (!mMarkedTextAllowed && [[theEvent characters] characterAtIndex:0] != NSBackspaceCharacter) { - showInputWindow(true, @""); - [[[(LLAppDelegate*)[NSApp delegate] inputView] inputContext] handleEvent:theEvent]; + [(LLAppDelegate*)[NSApp delegate] showInputWindow:true withEvent:theEvent]; } + + [[self inputContext] handleEvent:theEvent]; + } else if ([[theEvent charactersIgnoringModifiers] characterAtIndex:0] == 13 || [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == 3) + { + // callKeyDown won't return the value we expect for enter or return. Handle them as a separate case. [[self inputContext] handleEvent:theEvent]; } + // OS X intentionally does not send us key-up information on cmd-key combinations. // This behaviour is not a bug, and only applies to cmd-combinations (no others). // Since SL assumes we receive those, we fake it here. diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index daf7596cab..5b1f22046b 100755 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -91,7 +91,6 @@ void closeWindow(NSWindowRef window); void removeGLView(GLViewRef view); void makeFirstResponder(NSWindowRef window, GLViewRef view); void setupInputWindow(NSWindowRef window, GLViewRef view); -void showInputWindow(bool show, void* text); // These are all implemented in llwindowmacosx.cpp. // This is largely for easier interop between Obj-C and C++ (at least in the viewer's case due to the BOOL vs. BOOL conflict) diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 7f1af129b4..33a8cf34ce 100755 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -367,11 +367,6 @@ void setupInputWindow(NSWindowRef window, GLViewRef glview) [[(LLAppDelegate*)[NSApp delegate] inputView] setGLView:(LLOpenGLView*)glview]; } -void showInputWindow(bool show, void* text) -{ - [(LLAppDelegate*)[NSApp delegate] showInputWindow:show withText:(id)text]; -} - void commitCurrentPreedit(GLViewRef glView) { [(LLOpenGLView*)glView commitCurrentPreedit]; diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm index 403c307085..cec9c586e6 100644 --- a/indra/newview/llappdelegate-objc.mm +++ b/indra/newview/llappdelegate-objc.mm @@ -71,7 +71,7 @@ } } -- (void) showInputWindow:(bool)show withText:(id)text +- (void) showInputWindow:(bool)show withEvent:(NSEvent*)textEvent { // How to add support for new languages with the input window: // Simply append this array with the language code (ja for japanese, ko for korean, zh for chinese, etc.) @@ -83,7 +83,10 @@ { NSLog(@"Showing input window."); [inputWindow makeKeyAndOrderFront:inputWindow]; - [inputView setMarkedText:text selectedRange:NSMakeRange(0, 1)]; + if (textEvent != nil) + { + [[inputView inputContext] handleEvent:textEvent]; + } } else { NSLog(@"Hiding input window."); [inputWindow orderOut:inputWindow]; -- cgit v1.2.3 From c603eb5ece7ca2f2faa870bfd89f5f4e71e2b8f0 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 17 Jun 2013 08:03:32 -0700 Subject: MAINT-318 prevent crashes from incomplete quads and lines and prevent drivers from crashing to desktop when passed short buffers --- indra/llrender/llrender.cpp | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index c60eb8d9d9..f2f1b62be0 100755 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1849,35 +1849,36 @@ void LLRender::flush() sUIVerts += mCount; } - if (gDebugGL) + //store mCount in a local variable to avoid re-entrance (drawArrays may call flush) + U32 count = mCount; + + if (mMode == LLRender::QUADS && !sGLCoreProfile) { - if (mMode == LLRender::QUADS && !sGLCoreProfile) + if (mCount%4 != 0) { - if (mCount%4 != 0) - { - llerrs << "Incomplete quad rendered." << llendl; - } + count -= (mCount % 4); + llwarns << "Incomplete quad requested." << llendl; } - - if (mMode == LLRender::TRIANGLES) + } + + if (mMode == LLRender::TRIANGLES) + { + if (mCount%3 != 0) { - if (mCount%3 != 0) - { - llerrs << "Incomplete triangle rendered." << llendl; - } + count -= (mCount % 3); + llwarns << "Incomplete triangle requested." << llendl; } - - if (mMode == LLRender::LINES) + } + + if (mMode == LLRender::LINES) + { + if (mCount%2 != 0) { - if (mCount%2 != 0) - { - llerrs << "Incomplete line rendered." << llendl; - } + count -= (mCount % 2); + llwarns << "Incomplete line requested." << llendl; } } - - //store mCount in a local variable to avoid re-entrance (drawArrays may call flush) - U32 count = mCount; + mCount = 0; if (mBuffer->useVBOs() && !mBuffer->isLocked()) -- cgit v1.2.3 From 84f287b34e7d7edbd2e897b73008c782aabe60de Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 17 Jun 2013 12:31:25 -0400 Subject: Moved detecting if we're using a roman-script language to it's own function in the application delegate. Also consider the delete and backspace characters to be special cases. --- indra/llwindow/llappdelegate-objc.h | 1 + indra/llwindow/llopenglview-objc.mm | 22 ++++++++++++++-------- indra/newview/llappdelegate-objc.mm | 22 ++++++++++++++++------ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/indra/llwindow/llappdelegate-objc.h b/indra/llwindow/llappdelegate-objc.h index 266f417c4b..a6fb77d93f 100644 --- a/indra/llwindow/llappdelegate-objc.h +++ b/indra/llwindow/llappdelegate-objc.h @@ -26,4 +26,5 @@ - (void) mainLoop; - (void) showInputWindow:(bool)show withEvent:(NSEvent*)textEvent; - (void) languageUpdated; +- (bool) romanScript; @end diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 2afd4993c5..c3f0ef4aeb 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -317,15 +317,21 @@ attributedStringInfo getSegments(NSAttributedString *str) if (!mHasMarkedText) { uint keycode = [theEvent keyCode]; - if (callKeyDown(keycode, mModifiers)) + bool acceptsText = callKeyDown(keycode, mModifiers); + if (acceptsText && + !mMarkedTextAllowed && + ![(LLAppDelegate*)[NSApp delegate] romanScript] && + [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSDeleteCharacter && + [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSBackspaceCharacter) + { + [(LLAppDelegate*)[NSApp delegate] showInputWindow:true withEvent:theEvent]; + } else { - if (!mMarkedTextAllowed && [[theEvent characters] characterAtIndex:0] != NSBackspaceCharacter) - { - [(LLAppDelegate*)[NSApp delegate] showInputWindow:true withEvent:theEvent]; - } - [[self inputContext] handleEvent:theEvent]; - } else if ([[theEvent charactersIgnoringModifiers] characterAtIndex:0] == 13 || [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == 3) + } + + if ([[theEvent charactersIgnoringModifiers] characterAtIndex:0] == NSCarriageReturnCharacter || + [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == NSEnterCharacter) { // callKeyDown won't return the value we expect for enter or return. Handle them as a separate case. [[self inputContext] handleEvent:theEvent]; @@ -438,7 +444,7 @@ attributedStringInfo getSegments(NSAttributedString *str) mMarkedTextLength = [aString length]; mMarkedText = (NSAttributedString*)[aString mutableString]; } else { - if (mHasMarkedText) + if (mHasMarkedText || ![mMarkedText isEqual: @""]) { [self unmarkText]; } diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm index cec9c586e6..6b7e613491 100644 --- a/indra/newview/llappdelegate-objc.mm +++ b/indra/newview/llappdelegate-objc.mm @@ -73,11 +73,7 @@ - (void) showInputWindow:(bool)show withEvent:(NSEvent*)textEvent { - // How to add support for new languages with the input window: - // Simply append this array with the language code (ja for japanese, ko for korean, zh for chinese, etc.) - NSArray *authorizedLanguages = [[NSArray alloc] initWithObjects:@"ja", @"ko", @"zh-Hant", @"zh-Hans", nil]; - - if ([authorizedLanguages containsObject:currentInputLanguage]) + if (![self romanScript]) { if (show) { @@ -85,6 +81,7 @@ [inputWindow makeKeyAndOrderFront:inputWindow]; if (textEvent != nil) { + [[inputView inputContext] discardMarkedText]; [[inputView inputContext] handleEvent:textEvent]; } } else { @@ -105,7 +102,7 @@ TISInputSourceRef currentInput = TISCopyCurrentKeyboardInputSource(); CFArrayRef languages = (CFArrayRef)TISGetInputSourceProperty(currentInput, kTISPropertyInputSourceLanguages); -#if 1 // In the event of ever needing to add new language sources, change this to 1 and watch the terminal for "languages:" +#if 0 // In the event of ever needing to add new language sources, change this to 1 and watch the terminal for "languages:" NSLog(@"languages: %@", TISGetInputSourceProperty(currentInput, kTISPropertyInputSourceLanguages)); #endif @@ -113,4 +110,17 @@ currentInputLanguage = (NSString*)CFArrayGetValueAtIndex(languages, 0); } +- (bool) romanScript +{ + // How to add support for new languages with the input window: + // Simply append this array with the language code (ja for japanese, ko for korean, zh for chinese, etc.) + NSArray *nonRomanScript = [[NSArray alloc] initWithObjects:@"ja", @"ko", @"zh-Hant", @"zh-Hans", nil]; + if ([nonRomanScript containsObject:currentInputLanguage]) + { + return false; + } + + return true; +} + @end -- cgit v1.2.3 From c1b7c8cacb6f6bcb8f6b9c7f73e059a41fee8c33 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Mon, 17 Jun 2013 12:56:08 -0700 Subject: NORSPEC-246 Force light func to use GL_R32F format for more precision on older nV mobile cards with single FP hardware --- indra/newview/pipeline.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 8942092221..4a1b182fd2 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -1190,7 +1190,14 @@ void LLPipeline::releaseLUTBuffers() { if (mLightFunc) { - LLImageGL::deleteTextures(LLTexUnit::TT_TEXTURE, GL_R16F, 0, 1, &mLightFunc); + U32 pix_format = GL_R16F; +#if LL_DARWIN + if (gGLManager.mIsMobileGF) + { + pix_format = GL_R32F; + } +#endif + LLImageGL::deleteTextures(LLTexUnit::TT_TEXTURE, pix_format, 0, 1, &mLightFunc); mLightFunc = 0; } } @@ -1367,7 +1374,7 @@ void LLPipeline::createLUTBuffers() // This is fine, given we only need to create our LUT once per buffer initialization. spec *= (((n + 2) * (n + 4)) / (8 * F_PI * (powf(2, -n/2) + n))); - // Since we use R16F, we no longer have a dynamic range issue we need to work around here. + // Since we use R16/32F, we no longer have a dynamic range issue we need to work around here. // Though some older drivers may not like this, newer drivers shouldn't have this problem. ls[y*lightResX+x] = spec; @@ -1390,9 +1397,16 @@ void LLPipeline::createLUTBuffers() } } - LLImageGL::generateTextures(LLTexUnit::TT_TEXTURE, GL_R16F, 1, &mLightFunc); + U32 pix_format = GL_R16F; +#if LL_DARWIN + if (gGLManager.mIsMobileGF) + { + pix_format = GL_R32F; + } +#endif + LLImageGL::generateTextures(LLTexUnit::TT_TEXTURE, pix_format, 1, &mLightFunc); gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc); - LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_R16F, lightResX, lightResY, GL_RED, GL_FLOAT, ls, false); + LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, pix_format, lightResX, lightResY, GL_RED, GL_FLOAT, ls, false); //LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_UNSIGNED_BYTE, lightResX, lightResY, GL_RED, GL_UNSIGNED_BYTE, ls, false); gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP); gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); -- cgit v1.2.3 From 2837ca7a474f92bb363a2a31d184431b636d2809 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 17 Jun 2013 17:08:48 -0400 Subject: This seems to be on par with viewer-release at this point. --- indra/llwindow/llopenglview-objc.h | 1 - indra/llwindow/llopenglview-objc.mm | 84 ++++++++++++++++++----------------- indra/llwindow/llwindowmacosx-objc.h | 2 +- indra/llwindow/llwindowmacosx-objc.mm | 4 +- indra/llwindow/llwindowmacosx.cpp | 42 ++++++++++++------ indra/llwindow/llwindowmacosx.h | 2 + 6 files changed, 78 insertions(+), 57 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index d4207d598a..b783c41c0b 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -22,7 +22,6 @@ float mMousePos[2]; bool mHasMarkedText; unsigned int mMarkedTextLength; - NSAttributedString *mMarkedText; bool mMarkedTextAllowed; } - (id) initWithSamples:(NSUInteger)samples; diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index c3f0ef4aeb..24de5912f0 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -314,37 +314,34 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void) keyDown:(NSEvent *)theEvent { - if (!mHasMarkedText) - { - uint keycode = [theEvent keyCode]; - bool acceptsText = callKeyDown(keycode, mModifiers); - if (acceptsText && - !mMarkedTextAllowed && - ![(LLAppDelegate*)[NSApp delegate] romanScript] && - [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSDeleteCharacter && - [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSBackspaceCharacter) - { - [(LLAppDelegate*)[NSApp delegate] showInputWindow:true withEvent:theEvent]; - } else - { - [[self inputContext] handleEvent:theEvent]; - } - - if ([[theEvent charactersIgnoringModifiers] characterAtIndex:0] == NSCarriageReturnCharacter || - [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == NSEnterCharacter) - { - // callKeyDown won't return the value we expect for enter or return. Handle them as a separate case. - [[self inputContext] handleEvent:theEvent]; - } - - // OS X intentionally does not send us key-up information on cmd-key combinations. - // This behaviour is not a bug, and only applies to cmd-combinations (no others). - // Since SL assumes we receive those, we fake it here. - if (mModifiers & NSCommandKeyMask) - { - callKeyUp([theEvent keyCode], mModifiers); - } - } + uint keycode = [theEvent keyCode]; + bool acceptsText = callKeyDown(keycode, mModifiers); + if (acceptsText && + !mMarkedTextAllowed && + ![(LLAppDelegate*)[NSApp delegate] romanScript] && + [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSDeleteCharacter && + [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSBackspaceCharacter) + { + [(LLAppDelegate*)[NSApp delegate] showInputWindow:true withEvent:theEvent]; + } else + { + [[self inputContext] handleEvent:theEvent]; + } + + if ([[theEvent charactersIgnoringModifiers] characterAtIndex:0] == NSCarriageReturnCharacter || + [[theEvent charactersIgnoringModifiers] characterAtIndex:0] == NSEnterCharacter) + { + // callKeyDown won't return the value we expect for enter or return. Handle them as a separate case. + [[self inputContext] handleEvent:theEvent]; + } + + // OS X intentionally does not send us key-up information on cmd-key combinations. + // This behaviour is not a bug, and only applies to cmd-combinations (no others). + // Since SL assumes we receive those, we fake it here. + if (mModifiers & NSCommandKeyMask) + { + callKeyUp([theEvent keyCode], mModifiers); + } } - (void)flagsChanged:(NSEvent *)theEvent { @@ -425,7 +422,6 @@ attributedStringInfo getSegments(NSAttributedString *str) { if (mMarkedTextAllowed) { - unsigned int selected[2] = { selectedRange.location, selectedRange.length @@ -442,9 +438,8 @@ attributedStringInfo getSegments(NSAttributedString *str) setMarkedText(text, selected, replacement, [aString length], segments); mHasMarkedText = TRUE; mMarkedTextLength = [aString length]; - mMarkedText = (NSAttributedString*)[aString mutableString]; } else { - if (mHasMarkedText || ![mMarkedText isEqual: @""]) + if (mHasMarkedText) { [self unmarkText]; } @@ -454,17 +449,18 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void)commitCurrentPreedit { - if (mMarkedText) + if (mHasMarkedText) { - [self insertText:mMarkedText]; - [[self inputContext] discardMarkedText]; + if ([[self inputContext] respondsToSelector:@selector(commitEditing)]) + { + [[self inputContext] commitEditing]; + } } } - (void)unmarkText { [[self inputContext] discardMarkedText]; - [mMarkedText setValue:@""]; resetPreedit(); mHasMarkedText = FALSE; } @@ -481,6 +477,14 @@ attributedStringInfo getSegments(NSAttributedString *str) return nil; } +- (void)insertText:(id)insertString +{ + if (insertString != nil) + { + [self insertText:insertString replacementRange:NSMakeRange(0, [insertString length])]; + } +} + - (void)insertText:(id)aString replacementRange:(NSRange)replacementRange { if (!mHasMarkedText) @@ -490,9 +494,9 @@ attributedStringInfo getSegments(NSAttributedString *str) callUnicodeCallback([aString characterAtIndex:i], mModifiers); } } else { + resetPreedit(); // We may never get this point since unmarkText may be called before insertText ever gets called once we submit our text. // But just in case... - resetPreedit(); for (NSInteger i = 0; i < [aString length]; i++) { @@ -567,7 +571,7 @@ attributedStringInfo getSegments(NSAttributedString *str) [[self inputContext] discardMarkedText]; [self setString:@""]; [_window orderOut:_window]; - [self insertText:insertString replacementRange:NSMakeRange(0, 0)]; + [self insertText:insertString replacementRange:NSMakeRange(0, [insertString length])]; } - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 5b1f22046b..914fc534fb 100755 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -135,7 +135,7 @@ void resetPreedit(); int wstring_length(const std::basic_string & wstr, const int woffset, const int utf16_length, int *unaligned); void setMarkedText(unsigned short *text, unsigned int *selectedRange, unsigned int *replacementRange, long text_len, attributedStringInfo segments); void getPreeditLocation(float *location, unsigned int length); -void allowDirectMarkedTextInput(bool allow); +void allowDirectMarkedTextInput(bool allow, GLViewRef glView); NSWindowRef getMainAppWindow(); GLViewRef getGLView(); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 33a8cf34ce..67b5279c0b 100755 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -372,9 +372,9 @@ void commitCurrentPreedit(GLViewRef glView) [(LLOpenGLView*)glView commitCurrentPreedit]; } -void allowDirectMarkedTextInput(bool allow) +void allowDirectMarkedTextInput(bool allow, GLViewRef glView) { - + [(LLOpenGLView*)glView allowMarkedTextInput:allow]; } NSWindowRef getMainAppWindow() diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 16fd7e3382..737ecba368 100755 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -239,6 +239,11 @@ void callFocusLost() void callRightMouseDown(float *pos, MASK mask) { + if (gWindowImplementation->allowsLanguageInput()) + { + gWindowImplementation->interruptLanguageTextInput(); + } + LLCoordGL outCoords; outCoords.mX = llround(pos[0]); outCoords.mY = llround(pos[1]); @@ -247,6 +252,11 @@ void callRightMouseDown(float *pos, MASK mask) void callRightMouseUp(float *pos, MASK mask) { + if (gWindowImplementation->allowsLanguageInput()) + { + gWindowImplementation->interruptLanguageTextInput(); + } + LLCoordGL outCoords; outCoords.mX = llround(pos[0]); outCoords.mY = llround(pos[1]); @@ -255,6 +265,11 @@ void callRightMouseUp(float *pos, MASK mask) void callLeftMouseDown(float *pos, MASK mask) { + if (gWindowImplementation->allowsLanguageInput()) + { + gWindowImplementation->interruptLanguageTextInput(); + } + LLCoordGL outCoords; outCoords.mX = llround(pos[0]); outCoords.mY = llround(pos[1]); @@ -263,6 +278,11 @@ void callLeftMouseDown(float *pos, MASK mask) void callLeftMouseUp(float *pos, MASK mask) { + if (gWindowImplementation->allowsLanguageInput()) + { + gWindowImplementation->interruptLanguageTextInput(); + } + LLCoordGL outCoords; outCoords.mX = llround(pos[0]); outCoords.mY = llround(pos[1]); @@ -272,6 +292,11 @@ void callLeftMouseUp(float *pos, MASK mask) void callDoubleClick(float *pos, MASK mask) { + if (gWindowImplementation->allowsLanguageInput()) + { + gWindowImplementation->interruptLanguageTextInput(); + } + LLCoordGL outCoords; outCoords.mX = llround(pos[0]); outCoords.mY = llround(pos[1]); @@ -434,7 +459,7 @@ void setMarkedText(unsigned short *unitext, unsigned int *selectedRange, unsigne if (gWindowImplementation->getPreeditor()) { LLPreeditor *preeditor = gWindowImplementation->getPreeditor(); - + preeditor->resetPreedit(); // This should be a viable replacement for the kEventParamTextInputSendReplaceRange parameter. if (replacementRange[0] < replacementRange[1]) { @@ -444,8 +469,6 @@ void setMarkedText(unsigned short *unitext, unsigned int *selectedRange, unsigne preeditor->markAsPreedit(location, length); } - preeditor->resetPreedit(); - LLWString fix_str = utf16str_to_wstring(llutf16string(unitext, text_len)); S32 caret_position = fix_str.length(); @@ -1818,6 +1841,8 @@ static long getDictLong (CFDictionaryRef refDict, CFStringRef key) void LLWindowMacOSX::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) { + allowDirectMarkedTextInput(b, mGLView); + if (preeditor != mPreeditor && !b) { // This condition may occur by a call to @@ -1828,16 +1853,7 @@ void LLWindowMacOSX::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) // is not disturbed. return; } - - if (preeditor == NULL) { - // If we don't have a pre editor, then we can't accept direct marked text input. - // We needs an input window (which is handled internally by LLOpenGLView) - allowDirectMarkedTextInput(false); - } else { - // If we have a preeditor, then accept direct marked text input. - allowDirectMarkedTextInput(true); - } - + // Take care of old and new preeditors. if (preeditor != mPreeditor || !b) { diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h index de0340cf74..82195c2700 100755 --- a/indra/llwindow/llwindowmacosx.h +++ b/indra/llwindow/llwindowmacosx.h @@ -126,6 +126,8 @@ public: void getMouseDeltas(float* delta); void handleDragNDrop(std::string url, LLWindowCallbacks::DragNDropAction action); + + bool allowsLanguageInput() { return mLanguageTextInputAllowed; } protected: LLWindowMacOSX(LLWindowCallbacks* callbacks, -- cgit v1.2.3 From 72159fd03ea02422e3c6acfbed9221a5326a9cc0 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 17 Jun 2013 18:18:37 -0400 Subject: The viewer now requires the 10.7 SDK or above to compile. --- indra/cmake/Variables.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indra/cmake/Variables.cmake b/indra/cmake/Variables.cmake index b127045115..22d0a7f0fe 100755 --- a/indra/cmake/Variables.cmake +++ b/indra/cmake/Variables.cmake @@ -140,10 +140,10 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") else (XCODE_VERSION GREATER 4.5) if (XCODE_VERSION GREATER 4.2) set(CMAKE_OSX_DEPLOYMENT_TARGET 10.6) - set(CMAKE_OSX_SYSROOT macosx10.6) + set(CMAKE_OSX_SYSROOT macosx10.7) else (XCODE_VERSION GREATER 4.2) - set(CMAKE_OSX_DEPLOYMENT_TARGET 10.5) - set(CMAKE_OSX_SYSROOT macosx10.6) + set(CMAKE_OSX_DEPLOYMENT_TARGET 10.6) + set(CMAKE_OSX_SYSROOT macosx10.7) endif (XCODE_VERSION GREATER 4.2) endif (XCODE_VERSION GREATER 4.5) -- cgit v1.2.3 From 0dbe156e2317f8e34f2f0cfa65dc89ea30cd18f1 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 18 Jun 2013 09:10:13 -0700 Subject: NORSPEC-246 make 32F light LUT apply to all OS X machines as several non-nV cards were also failing --- indra/newview/pipeline.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 4a1b182fd2..48f29b3237 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -1192,10 +1192,9 @@ void LLPipeline::releaseLUTBuffers() { U32 pix_format = GL_R16F; #if LL_DARWIN - if (gGLManager.mIsMobileGF) - { - pix_format = GL_R32F; - } + // Need to work around limited precision with 10.6.8 and older drivers + // + pix_format = GL_R32F; #endif LLImageGL::deleteTextures(LLTexUnit::TT_TEXTURE, pix_format, 0, 1, &mLightFunc); mLightFunc = 0; @@ -1399,10 +1398,9 @@ void LLPipeline::createLUTBuffers() U32 pix_format = GL_R16F; #if LL_DARWIN - if (gGLManager.mIsMobileGF) - { - pix_format = GL_R32F; - } + // Need to work around limited precision with 10.6.8 and older drivers + // + pix_format = GL_R32F; #endif LLImageGL::generateTextures(LLTexUnit::TT_TEXTURE, pix_format, 1, &mLightFunc); gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc); -- cgit v1.2.3 From 90e511bbdf9e08059180218e47350e4d2b431b68 Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 20 Jun 2013 11:28:05 -0400 Subject: Handle VRAM in megabytes. This was previously being reported as bytes. --- indra/llwindow/llopenglview-objc.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 24de5912f0..aa7df2c985 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -88,7 +88,8 @@ attributedStringInfo getSegments(NSAttributedString *str) { vram_bytes = (256 << 20); } - return (unsigned long)vram_bytes; + + return (unsigned long)vram_bytes / 1048576; // We need this in megabytes. } - (void)viewDidMoveToWindow -- cgit v1.2.3 From 42a46595558c5d87f62c9fd8e52fdad1c6960e4d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 20 Jun 2013 09:34:30 -0700 Subject: NORSPEC-278 fix misuse of legacy bumps when rendering objects with TE bumpmap setting of 18 aka BUMPY_TEXTURE --- indra/newview/llvovolume.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 3be1f52352..685f854573 100755 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -5354,7 +5354,7 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std:: mode == LLMaterial::DIFFUSE_ALPHA_MODE_EMISSIVE; } - bool use_legacy_bump = te->getBumpmap() && (!mat || mat->getNormalID().isNull()); + bool use_legacy_bump = te->getBumpmap() && (te->getBumpmap() < 18) && (!mat || mat->getNormalID().isNull()); if (mat && LLPipeline::sRenderDeferred && !hud_group) { -- cgit v1.2.3 From 65f0972a64f77388752794610e6dedc27b9eb228 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 20 Jun 2013 12:41:46 -0700 Subject: NORSPEC-262 make drag and drop aware of editing context so that editing normal/spec textures causes application to the correct tex channel --- indra/newview/llfloatertools.h | 2 ++ indra/newview/llpanelface.cpp | 37 +++++++++++++++-------------- indra/newview/llpanelface.h | 21 +++++++++++++---- indra/newview/llselectmgr.cpp | 6 ++--- indra/newview/lltooldraganddrop.cpp | 47 ++++++++++++++++++++++++++++++++++++- indra/newview/pipeline.cpp | 4 +++- 6 files changed, 89 insertions(+), 28 deletions(-) diff --git a/indra/newview/llfloatertools.h b/indra/newview/llfloatertools.h index ecb0092a6f..189bae46c2 100755 --- a/indra/newview/llfloatertools.h +++ b/indra/newview/llfloatertools.h @@ -109,6 +109,8 @@ public: static void setGridMode(S32 mode); + LLPanelFace* getPanelFace() { return mPanelFace; } + private: void refresh(); void refreshMedia(); diff --git a/indra/newview/llpanelface.cpp b/indra/newview/llpanelface.cpp index 911af9df04..3869219da6 100755 --- a/indra/newview/llpanelface.cpp +++ b/indra/newview/llpanelface.cpp @@ -66,7 +66,7 @@ #include "llvovolume.h" #include "lluictrlfactory.h" #include "llpluginclassmedia.h" -#include "llviewertexturelist.h" +#include "llviewertexturelist.h"// Update sel manager as to which channel we're editing so it can reflect the correct overlay UI // // Constant definitions for comboboxes @@ -89,6 +89,19 @@ const S32 SHINY_TEXTURE = 4; // use supplied specular map // std::string USE_TEXTURE; +LLRender::eTexIndex LLPanelFace::getTextureChannelToEdit() +{ + LLComboBox* combobox_matmedia = getChild("combobox matmedia"); + LLComboBox* combobox_mattype = getChild("combobox mattype"); + + LLRender::eTexIndex channel_to_edit = (combobox_matmedia && combobox_matmedia->getCurrentIndex() == MATMEDIA_MATERIAL) ? + (combobox_mattype ? (LLRender::eTexIndex)combobox_mattype->getCurrentIndex() : LLRender::DIFFUSE_MAP) : LLRender::DIFFUSE_MAP; + + channel_to_edit = (channel_to_edit == LLRender::NORMAL_MAP) ? (getCurrentNormalMap().isNull() ? LLRender::DIFFUSE_MAP : channel_to_edit) : channel_to_edit; + channel_to_edit = (channel_to_edit == LLRender::SPECULAR_MAP) ? (getCurrentSpecularMap().isNull() ? LLRender::DIFFUSE_MAP : channel_to_edit) : channel_to_edit; + return channel_to_edit; +} + // Things the UI provides... // LLUUID LLPanelFace::getCurrentNormalMap() { return getChild("bumpytexture control")->getImageAssetID(); } @@ -1194,7 +1207,8 @@ void LLPanelFace::updateUI() getChildView("checkbox fullbright")->setEnabled(editable); getChild("checkbox fullbright")->setTentative(!identical_fullbright); } - + + // Repeats per meter { F32 repeats_diff = 1.f; @@ -1218,6 +1232,9 @@ void LLPanelFace::updateUI() F32 repeats = 1.0f; U32 material_type = (combobox_matmedia->getCurrentIndex() == MATMEDIA_MATERIAL) ? combobox_mattype->getCurrentIndex() : MATTYPE_DIFFUSE; + + LLSelectMgr::getInstance()->setTextureChannel(LLRender::eTexIndex(material_type)); + switch (material_type) { default: @@ -1328,18 +1345,6 @@ void LLPanelFace::updateUI() getChild("shinycolorswatch")->set(material->getSpecularLightColor(),TRUE); } - // Update sel manager as to which channel we're editing so it can reflect the correct overlay UI - // NORSPEC-103 - LLRender::eTexIndex channel_to_edit = (combobox_matmedia->getCurrentIndex() == MATMEDIA_MATERIAL) ? (LLRender::eTexIndex)combobox_mattype->getCurrentIndex() : LLRender::DIFFUSE_MAP; - - if ( ((channel_to_edit == LLRender::NORMAL_MAP) && material->getNormalID().isNull()) - ||((channel_to_edit == LLRender::SPECULAR_MAP) && material->getSpecularID().isNull())) - { - channel_to_edit = LLRender::DIFFUSE_MAP; - } - - LLSelectMgr::getInstance()->setTextureChannel(channel_to_edit); - // Bumpy (normal) texture_ctrl = getChild("bumpytexture control"); texture_ctrl->setImageAssetID(material->getNormalID()); @@ -1365,10 +1370,6 @@ void LLPanelFace::updateUI() updateBumpyControls(!material->getNormalID().isNull(), true); } } - else - { - LLSelectMgr::getInstance()->setTextureChannel(LLRender::DIFFUSE_MAP); - } } // Set variable values for numeric expressions diff --git a/indra/newview/llpanelface.h b/indra/newview/llpanelface.h index 42c1f6bd48..834ad9e14c 100755 --- a/indra/newview/llpanelface.h +++ b/indra/newview/llpanelface.h @@ -100,6 +100,19 @@ public: void setMediaURL(const std::string& url); void setMediaType(const std::string& mime_type); + LLMaterialPtr createDefaultMaterial(LLMaterialPtr current_material) + { + LLMaterialPtr new_material(!current_material.isNull() ? new LLMaterial(current_material->asLLSD()) : new LLMaterial()); + llassert_always(new_material); + + // Preserve old diffuse alpha mode or assert correct default blend mode as appropriate for the alpha channel content of the diffuse texture + // + new_material->setDiffuseAlphaMode(current_material.isNull() ? (isAlpha() ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE) : current_material->getDiffuseAlphaMode()); + return new_material; + } + + LLRender::eTexIndex getTextureChannelToEdit(); + protected: void getState(); @@ -178,6 +191,8 @@ protected: static F32 valueGlow(LLViewerObject* object, S32 face); + + private: bool isAlpha() { return mIsAlpha; } @@ -234,7 +249,7 @@ private: { if (_edit) { - LLMaterialPtr new_material(!current_material.isNull() ? new LLMaterial(current_material->asLLSD()) : new LLMaterial()); + LLMaterialPtr new_material = _panel->createDefaultMaterial(current_material); llassert_always(new_material); // Determine correct alpha mode for current diffuse texture @@ -242,10 +257,6 @@ private: // U8 default_alpha_mode = (_panel->isAlpha() ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE); - // Default to matching expected state of UI - // - new_material->setDiffuseAlphaMode(current_material.isNull() ? default_alpha_mode : current_material->getDiffuseAlphaMode()); - // Do "It"! // _edit->apply(new_material); diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index 0cbdbe16a3..7b397d46f3 100755 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -91,7 +91,7 @@ #include "llvovolume.h" #include "pipeline.h" #include "llviewershadermgr.h" - +#include "llpanelface.h" #include "llglheaders.h" LLViewerObject* getSelectedParentObject(LLViewerObject *object) ; @@ -2534,7 +2534,7 @@ void LLSelectMgr::adjustTexturesByScale(BOOL send_to_sim, BOOL stretch) if (tep && !tep->getMaterialParams().isNull()) { LLMaterialPtr orig = tep->getMaterialParams(); - LLMaterialPtr p = new LLMaterial(orig->asLLSD()); + LLMaterialPtr p = gFloaterTools->getPanelFace()->createDefaultMaterial(orig); p->setNormalRepeat(normal_scale_s, normal_scale_t); p->setSpecularRepeat(specular_scale_s, specular_scale_t); @@ -2560,8 +2560,8 @@ void LLSelectMgr::adjustTexturesByScale(BOOL send_to_sim, BOOL stretch) if (tep && !tep->getMaterialParams().isNull()) { LLMaterialPtr orig = tep->getMaterialParams(); + LLMaterialPtr p = gFloaterTools->getPanelFace()->createDefaultMaterial(orig); - LLMaterialPtr p = new LLMaterial(orig->asLLSD()); p->setNormalRepeat(normal_scale_s, normal_scale_t); p->setSpecularRepeat(specular_scale_s, specular_scale_t); diff --git a/indra/newview/lltooldraganddrop.cpp b/indra/newview/lltooldraganddrop.cpp index e085834326..ef7d0cd81b 100755 --- a/indra/newview/lltooldraganddrop.cpp +++ b/indra/newview/lltooldraganddrop.cpp @@ -58,6 +58,7 @@ #include "llviewerwindow.h" #include "llvoavatarself.h" #include "llworld.h" +#include "llpanelface.h" // syntactic sugar #define callMemberFunction(object,ptrToMember) ((object).*(ptrToMember)) @@ -1163,7 +1164,51 @@ void LLToolDragAndDrop::dropTextureOneFace(LLViewerObject* hit_obj, // update viewer side image in anticipation of update from simulator LLViewerTexture* image = LLViewerTextureManager::getFetchedTexture(asset_id); LLViewerStats::getInstance()->incStat(LLViewerStats::ST_EDIT_TEXTURE_COUNT ); - hit_obj->setTEImage(hit_face, image); + + LLTextureEntry* tep = hit_obj ? (hit_obj->getTE(hit_face)) : NULL; + + LLPanelFace* panel_face = gFloaterTools->getPanelFace(); + + if (gFloaterTools->getVisible() && panel_face) + { + switch (LLSelectMgr::getInstance()->getTextureChannel()) + { + + case 0: + default: + { + hit_obj->setTEImage(hit_face, image); + } + break; + + case 1: + { + LLMaterialPtr old_mat = tep->getMaterialParams(); + LLMaterialPtr new_mat = panel_face->createDefaultMaterial(old_mat); + new_mat->setNormalID(asset_id); + tep->setMaterialParams(new_mat); + hit_obj->setTENormalMap(hit_face, asset_id); + LLMaterialMgr::getInstance()->put(hit_obj->getID(), hit_face, *new_mat); + } + break; + + case 2: + { + LLMaterialPtr old_mat = tep->getMaterialParams(); + LLMaterialPtr new_mat = panel_face->createDefaultMaterial(old_mat); + new_mat->setSpecularID(asset_id); + tep->setMaterialParams(new_mat); + hit_obj->setTESpecularMap(hit_face, asset_id); + LLMaterialMgr::getInstance()->put(hit_obj->getID(), hit_face, *new_mat); + } + break; + } + } + else + { + hit_obj->setTEImage(hit_face, image); + } + dialog_refresh_all(); // send the update to the simulator diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 56a3ebe3a8..d37b086ae3 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -111,6 +111,8 @@ #include "llpathinglib.h" #include "llfloaterpathfindingconsole.h" #include "llfloaterpathfindingcharacters.h" +#include "llfloatertools.h" +#include "llpanelface.h" #include "llpathfindingpathtool.h" #ifdef _DEBUG @@ -3962,7 +3964,7 @@ void LLPipeline::postSort(LLCamera& camera) { mSelectedFaces.clear(); - LLPipeline::setRenderHighlightTextureChannel(LLSelectMgr::getInstance()->getTextureChannel()); + LLPipeline::setRenderHighlightTextureChannel(gFloaterTools->getPanelFace()->getTextureChannelToEdit()); // Draw face highlights for selected faces. if (LLSelectMgr::getInstance()->getTEMode()) -- cgit v1.2.3 From 3a8cdb5d46cd12a5aad001e4bcec5b26f6f748ce Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 20 Jun 2013 15:27:22 -0700 Subject: NORSPEC-277 WIP backout old-school normal permutation --- .../shaders/class1/deferred/blurLightF.glsl | 17 ----------- .../shaders/class1/deferred/materialF.glsl | 17 ----------- .../shaders/class1/deferred/multiPointLightF.glsl | 17 ----------- .../shaders/class1/deferred/multiSpotLightF.glsl | 17 ----------- .../shaders/class1/deferred/pointLightF.glsl | 17 ----------- .../shaders/class1/deferred/softenLightF.glsl | 17 ----------- .../shaders/class1/deferred/spotLightF.glsl | 17 ----------- .../shaders/class1/deferred/sunLightSSAOF.glsl | 17 ----------- .../shaders/class2/deferred/multiSpotLightF.glsl | 17 ----------- .../shaders/class2/deferred/softenLightF.glsl | 17 ----------- .../shaders/class2/deferred/spotLightF.glsl | 17 ----------- .../shaders/class2/deferred/sunLightF.glsl | 17 ----------- .../shaders/class2/deferred/sunLightSSAOF.glsl | 17 ----------- indra/newview/llviewershadermgr.cpp | 34 ---------------------- 14 files changed, 255 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index 968a5f6b3d..a4f54dff70 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -59,22 +59,6 @@ vec4 getPosition(vec2 pos_screen) return pos; } -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -91,7 +75,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 618ea747f5..6cd8caa113 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -428,22 +428,6 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -460,7 +444,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 868526d457..c95aa8bb3c 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -56,22 +56,6 @@ uniform float far_z; uniform mat4 inv_proj; -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -88,7 +72,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 97bf49a605..7d39ad7bc1 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -67,22 +67,6 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -99,7 +83,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index caf20ce707..106d48bd71 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -54,22 +54,6 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -86,7 +70,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 08583ad0f2..f0d2746700 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -78,22 +78,6 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec3 decode_normal (vec2 enc) { vec2 fenc = enc*4-2; @@ -104,7 +88,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif vec4 getPosition_d(vec2 pos_screen, float depth) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 1975b18652..045d1a00cd 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -65,22 +65,6 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -97,7 +81,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 6653f57ee1..c0a5865bef 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -49,22 +49,6 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -81,7 +65,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 780df9ed1a..0deb4fe3b6 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -68,22 +68,6 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -100,7 +84,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 67bac1f7c2..6e05091b57 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -78,22 +78,6 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -110,7 +94,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif vec4 getPosition_d(vec2 pos_screen, float depth) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index fc0e6b2388..7a4337c277 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -68,22 +68,6 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -100,7 +84,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index 7b09dd29dd..95c09d3238 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -65,22 +65,6 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -97,7 +81,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 01e34ed792..b5ff6404ea 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -66,22 +66,6 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -#ifdef SINGLE_FP_ONLY -vec2 encode_normal(vec3 n) -{ - vec2 sn; - sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - vec3 n; - n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); - n.z = sqrt(1.0f - dot(n.xy,n.xy)); - return n; -} -#else vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -98,7 +82,6 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } -#endif vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index e24237522a..fa9c2ce51f 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -42,22 +42,6 @@ #include "llvosky.h" #include "llrender.h" -#if LL_DARWIN -#include "OpenGL/OpenGL.h" - -// include spec exp clamp to fix older mac rendering artifacts -// -#define SINGLE_FP_PERMUTATION(shader) \ - if (gGLManager.mIsMobileGF) \ - { \ - shader.addPermutation("SINGLE_FP_ONLY","1"); \ - } - - -#else -#define SINGLE_FP_PERMUTATION(shader) -#endif - #ifdef LL_RELEASE_FOR_DOWNLOAD #define UNIFORM_ERRS LL_WARNS_ONCE("Shader") #else @@ -1308,8 +1292,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() bool has_skin = i & 0x10; gDeferredMaterialProgram[i].addPermutation("HAS_SKIN",has_skin ? "1" : "0"); - SINGLE_FP_PERMUTATION(gDeferredMaterialProgram[i]); - if (has_skin) { gDeferredMaterialProgram[i].mFeatures.hasObjectSkinning = true; @@ -1368,8 +1350,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; - SINGLE_FP_PERMUTATION(gDeferredLightProgram); - success = gDeferredLightProgram.createShader(NULL, NULL); } @@ -1381,8 +1361,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredMultiLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMultiLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; - SINGLE_FP_PERMUTATION(gDeferredMultiLightProgram); - success = gDeferredMultiLightProgram.createShader(NULL, NULL); } @@ -1394,8 +1372,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/spotLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; - SINGLE_FP_PERMUTATION(gDeferredSpotLightProgram); - success = gDeferredSpotLightProgram.createShader(NULL, NULL); } @@ -1407,8 +1383,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiSpotLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMultiSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; - SINGLE_FP_PERMUTATION(gDeferredMultiSpotLightProgram); - success = gDeferredMultiSpotLightProgram.createShader(NULL, NULL); } @@ -1436,8 +1410,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSunProgram.mShaderFiles.push_back(make_pair(fragment, GL_FRAGMENT_SHADER_ARB)); gDeferredSunProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; - SINGLE_FP_PERMUTATION(gDeferredSunProgram); - success = gDeferredSunProgram.createShader(NULL, NULL); } @@ -1449,8 +1421,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredBlurLightProgram.mShaderFiles.push_back(make_pair("deferred/blurLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredBlurLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; - SINGLE_FP_PERMUTATION(gDeferredBlurLightProgram); - success = gDeferredBlurLightProgram.createShader(NULL, NULL); } @@ -1482,8 +1452,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); gDeferredAlphaProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; - SINGLE_FP_PERMUTATION(gDeferredAlphaProgram); - success = gDeferredAlphaProgram.createShader(NULL, NULL); // Hack @@ -1600,8 +1568,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSoftenProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; - SINGLE_FP_PERMUTATION(gDeferredSoftenProgram); - if (gSavedSettings.getBOOL("RenderDeferredSSAO")) { //if using SSAO, take screen space light map into account as if shadows are enabled gDeferredSoftenProgram.mShaderLevel = llmax(gDeferredSoftenProgram.mShaderLevel, 2); -- cgit v1.2.3 From 559173f71196602dd85211a786af7829ab2877c4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 24 Jun 2013 06:44:14 -0700 Subject: NORSPEC-280 include fix to downsampleDepthRect shader making GL 3.3. drivers cry --- .../app_settings/shaders/class1/interface/downsampleDepthRectF.glsl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/indra/newview/app_settings/shaders/class1/interface/downsampleDepthRectF.glsl b/indra/newview/app_settings/shaders/class1/interface/downsampleDepthRectF.glsl index 2f89b8ed72..0e5dc08183 100644 --- a/indra/newview/app_settings/shaders/class1/interface/downsampleDepthRectF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/downsampleDepthRectF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +#extension GL_ARB_texture_rectangle : enable + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else -- cgit v1.2.3 From 4841eaddb9dcfe6c6290f430121a6407b4ebe322 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham)" Date: Mon, 24 Jun 2013 10:18:37 -0700 Subject: MATBUG-194 WIP investigate if light func sampling precision is causing whirly's wierdness --- indra/newview/pipeline.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index d37b086ae3..9713f963b9 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -1400,13 +1400,9 @@ void LLPipeline::createLUTBuffers() ls[y*lightResX+x] = k;*/ } } - - U32 pix_format = GL_R16F; -#if LL_DARWIN // Need to work around limited precision with 10.6.8 and older drivers // - pix_format = GL_R32F; -#endif + U32 pix_format = GL_R32F; LLImageGL::generateTextures(LLTexUnit::TT_TEXTURE, pix_format, 1, &mLightFunc); gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc); LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, pix_format, lightResX, lightResY, GL_RED, GL_FLOAT, ls, false); -- cgit v1.2.3 From c07f47dee88db5e041648b38d92b173cce65aa9f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 24 Jun 2013 19:28:02 -0700 Subject: NORSPEC-259 nerfed copyContentsToFramebuffer handling of non-FBO sources --- indra/llrender/llrendertarget.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 6e22712b94..09ef780424 100755 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -572,8 +572,10 @@ void LLRenderTarget::copyContentsToFramebuffer(LLRenderTarget& source, S32 srcX0 { if (!source.mFBO) { - llerrs << "Cannot copy framebuffer contents for non FBO render targets." << llendl; + llwarns << "Cannot copy framebuffer contents for non FBO render targets." << llendl; + return; } + { GLboolean write_depth = mask & GL_DEPTH_BUFFER_BIT ? TRUE : FALSE; -- cgit v1.2.3 From 53789008221043052360dcff2c1faeb11c64d9f6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 25 Jun 2013 10:21:59 -0700 Subject: NORSPEC-250 add setting to force higher LUT precision and made LUT cleanup match creation --- indra/newview/app_settings/settings.xml | 12 ++++++++++++ indra/newview/pipeline.cpp | 21 +++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 344079b640..ebb01fb330 100755 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -8592,6 +8592,18 @@ + RenderSpecularPrecision + + Comment + Force 32-bit floating point LUT + Persist + 1 + Type + U32 + Value + 0 + + RenderSpecularResX Comment diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 9713f963b9..442b0b6d2d 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -1201,7 +1201,15 @@ void LLPipeline::releaseLUTBuffers() { if (mLightFunc) { - LLImageGL::deleteTextures(LLTexUnit::TT_TEXTURE, GL_R16F, 0, 1, &mLightFunc); + U32 use_high_precision = gSavedSettings.getU32("RenderSpecularPrecision"); + + U32 pix_format = use_high_precision ? GL_R32F : GL_R16F; + +#if LL_DARWIN + pix_format = GL_R32F; +#endif + + LLImageGL::deleteTextures(LLTexUnit::TT_TEXTURE, pix_format, 0, 1, &mLightFunc); mLightFunc = 0; } } @@ -1402,7 +1410,16 @@ void LLPipeline::createLUTBuffers() } // Need to work around limited precision with 10.6.8 and older drivers // - U32 pix_format = GL_R32F; + U32 use_high_precision = gSavedSettings.getU32("RenderSpecularPrecision"); + + U32 pix_format = use_high_precision ? GL_R32F : GL_R16F; + +#if LL_DARWIN + // Forced to work around 10.6.8. driver bugs on most every GPU + // + pix_format = GL_R32F; +#endif + LLImageGL::generateTextures(LLTexUnit::TT_TEXTURE, pix_format, 1, &mLightFunc); gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc); LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, pix_format, lightResX, lightResY, GL_RED, GL_FLOAT, ls, false); -- cgit v1.2.3 From 705a0ab6770459d89474b3495b05214315a49c94 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 25 Jun 2013 11:16:27 -0700 Subject: NORSPEC-288 WIP fixes the issue with normal gen, but may be a bigger perf hit than we want --- indra/llmath/llvector4a.inl | 20 +++++++++++ indra/llmath/llvolume.cpp | 83 ++++++++++++++++++++++++--------------------- 2 files changed, 64 insertions(+), 39 deletions(-) diff --git a/indra/llmath/llvector4a.inl b/indra/llmath/llvector4a.inl index 7c52ffef21..558fe09323 100755 --- a/indra/llmath/llvector4a.inl +++ b/indra/llmath/llvector4a.inl @@ -409,6 +409,26 @@ inline void LLVector4a::normalize3fast() mQ = _mm_mul_ps( mQ, approxRsqrt ); } +inline void LLVector4a::normalize3fast_checked(LLVector4a* d) +{ + if (!isFinite3()) + { + *this = d ? *d : LLVector4a(0,1,0,1); + return; + } + + LLVector4a lenSqrd; lenSqrd.setAllDot3( *this, *this ); + + if (lenSqrd.getF32ptr()[0] <= FLT_EPSILON) + { + *this = d ? *d : LLVector4a(0,1,0,1); + return; + } + + const LLQuad approxRsqrt = _mm_rsqrt_ps(lenSqrd.mQ); + mQ = _mm_mul_ps( mQ, approxRsqrt ); +} + // Return true if this vector is normalized with respect to x,y,z up to tolerance inline LLBool32 LLVector4a::isNormalized3( F32 tolerance ) const { diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 14cebfe5aa..58cac57e7f 100755 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -4472,6 +4472,9 @@ void LLVolume::generateSilhouetteVertices(std::vector &vertices, continue; //skip degenerate face } + LLVector4a default_norm; + default_norm.set(0,1,0,1); + //for each edge for (S32 k = 0; k < 3; k++) { S32 index = face.mEdge[j*3+k]; @@ -4493,14 +4496,14 @@ void LLVolume::generateSilhouetteVertices(std::vector &vertices, norm_mat.rotate(n[v1], t); - t.normalize3fast(); + t.normalize3fast_checked(&default_norm); normals.push_back(LLVector3(t[0], t[1], t[2])); mat.affineTransform(v[v2], t); vertices.push_back(LLVector3(t[0], t[1], t[2])); norm_mat.rotate(n[v2], t); - t.normalize3fast(); + t.normalize3fast_checked(&default_norm); normals.push_back(LLVector3(t[0], t[1], t[2])); } } @@ -6096,6 +6099,9 @@ BOOL LLVolumeFace::createUnCutCubeCap(LLVolume* volume, BOOL partial_build) { VertexData corners[4]; VertexData baseVert; + LLVector4a default_norm; + default_norm.set(0,1,0,1); + for(S32 t = 0; t < 4; t++) { corners[t].getPosition().load3( mesh[offset + (grid_size*t)].mPos.mV); @@ -6108,8 +6114,8 @@ BOOL LLVolumeFace::createUnCutCubeCap(LLVolume* volume, BOOL partial_build) lhs.setSub(corners[1].getPosition(), corners[0].getPosition()); LLVector4a rhs; rhs.setSub(corners[2].getPosition(), corners[1].getPosition()); - baseVert.getNormal().setCross3(lhs, rhs); - baseVert.getNormal().normalize3fast(); + baseVert.getNormal().setCross3(lhs, rhs); + baseVert.getNormal().normalize3fast_checked(&default_norm); } if(!(mTypeMask & TOP_MASK)) @@ -6559,17 +6565,12 @@ BOOL LLVolumeFace::createCap(LLVolume* volume, BOOL partial_build) d1.setSub(mPositions[mIndices[2]], mPositions[mIndices[0]]); LLVector4a normal; - normal.setCross3(d0,d1); - - if (normal.dot3(normal).getF32() > F_APPROXIMATELY_ZERO) - { - normal.normalize3fast(); - } - else - { //degenerate, make up a value - normal.set(0,0,1); - } + LLVector4a default_norm; + default_norm.set(0,1,0,1); + normal.setCross3(d0,d1); + normal.normalize3fast_checked(&default_norm); + llassert(llfinite(normal.getF32ptr()[0])); llassert(llfinite(normal.getF32ptr()[1])); llassert(llfinite(normal.getF32ptr()[2])); @@ -6611,11 +6612,13 @@ void LLVolumeFace::createTangents() CalculateTangentArray(mNumVertices, mPositions, mNormals, mTexCoords, mNumIndices/3, mIndices, mTangents); //normalize tangents + LLVector4a default_norm; + default_norm.set(0,1,0,1); for (U32 i = 0; i < mNumVertices; i++) { //binorm[i].normalize3fast(); //bump map/planar projection code requires normals to be normalized - mNormals[i].normalize3fast(); + mNormals[i].normalize3fast_checked(&default_norm); } } } @@ -6793,6 +6796,9 @@ void LLVolumeFace::appendFace(const LLVolumeFace& face, LLMatrix4& mat_in, LLMat mat.loadu(mat_in); norm_mat.loadu(norm_mat_in); + LLVector4a default_norm; + default_norm.set(0,1,0,1); + for (U32 i = 0; i < face.mNumVertices; ++i) { //transform appended face position and store @@ -6800,7 +6806,7 @@ void LLVolumeFace::appendFace(const LLVolumeFace& face, LLMatrix4& mat_in, LLMat //transform appended face normal and store norm_mat.rotate(src_norm[i], dst_norm[i]); - dst_norm[i].normalize3fast(); + dst_norm[i].normalize3fast_checked(&default_norm); //copy appended face texture coordinate dst_tc[i] = src_tc[i]; @@ -7213,42 +7219,41 @@ BOOL LLVolumeFace::createSide(LLVolume* volume, BOOL partial_build) void CalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal, const LLVector2 *texcoord, U32 triangleCount, const U16* index_array, LLVector4a *tangent) { - //LLVector4a *tan1 = new LLVector4a[vertexCount * 2]; LLVector4a* tan1 = (LLVector4a*) ll_aligned_malloc_16(vertexCount*2*sizeof(LLVector4a)); - LLVector4a* tan2 = tan1 + vertexCount; + LLVector4a* tan2 = tan1 + vertexCount; memset(tan1, 0, vertexCount*2*sizeof(LLVector4a)); - for (U32 a = 0; a < triangleCount; a++) - { - U32 i1 = *index_array++; - U32 i2 = *index_array++; - U32 i3 = *index_array++; + for (U32 a = 0; a < triangleCount; a++) + { + U32 i1 = *index_array++; + U32 i2 = *index_array++; + U32 i3 = *index_array++; - const LLVector4a& v1 = vertex[i1]; - const LLVector4a& v2 = vertex[i2]; - const LLVector4a& v3 = vertex[i3]; + const LLVector4a& v1 = vertex[i1]; + const LLVector4a& v2 = vertex[i2]; + const LLVector4a& v3 = vertex[i3]; - const LLVector2& w1 = texcoord[i1]; - const LLVector2& w2 = texcoord[i2]; - const LLVector2& w3 = texcoord[i3]; + const LLVector2& w1 = texcoord[i1]; + const LLVector2& w2 = texcoord[i2]; + const LLVector2& w3 = texcoord[i3]; const F32* v1ptr = v1.getF32ptr(); const F32* v2ptr = v2.getF32ptr(); const F32* v3ptr = v3.getF32ptr(); - float x1 = v2ptr[0] - v1ptr[0]; - float x2 = v3ptr[0] - v1ptr[0]; - float y1 = v2ptr[1] - v1ptr[1]; - float y2 = v3ptr[1] - v1ptr[1]; - float z1 = v2ptr[2] - v1ptr[2]; - float z2 = v3ptr[2] - v1ptr[2]; + float x1 = v2ptr[0] - v1ptr[0]; + float x2 = v3ptr[0] - v1ptr[0]; + float y1 = v2ptr[1] - v1ptr[1]; + float y2 = v3ptr[1] - v1ptr[1]; + float z1 = v2ptr[2] - v1ptr[2]; + float z2 = v3ptr[2] - v1ptr[2]; - float s1 = w2.mV[0] - w1.mV[0]; - float s2 = w3.mV[0] - w1.mV[0]; - float t1 = w2.mV[1] - w1.mV[1]; - float t2 = w3.mV[1] - w1.mV[1]; + float s1 = w2.mV[0] - w1.mV[0]; + float s2 = w3.mV[0] - w1.mV[0]; + float t1 = w2.mV[1] - w1.mV[1]; + float t2 = w3.mV[1] - w1.mV[1]; F32 rd = s1*t2-s2*t1; -- cgit v1.2.3 From 280a9d9827e4e5e0e1408cc8f9c20ef792a6c714 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 25 Jun 2013 18:02:08 -0500 Subject: MATBUG-78 Fix for alpha lighting falloff not matching opaque lighting falloff (again). --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 0899caa2af..143af0576c 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -101,7 +101,7 @@ vec3 calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float float dist = d/la; da = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); da *= da; - da *= 1.4; + da *= 2.0; // spotlight coefficient. diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 618ea747f5..10b6385809 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -142,7 +142,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe float dist = d/la; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; - dist_atten *= 1.4; + dist_atten *= 2.0; // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); -- cgit v1.2.3 From de4892b3373ef0c4562dba43a05fd19c973e9f30 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 25 Jun 2013 16:25:22 -0700 Subject: NORSPEC-288 remove unassertable asserts from restoring code to condition normals for this fix --- indra/newview/llface.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp index f021f4ed0f..700b31f8d3 100755 --- a/indra/newview/llface.cpp +++ b/indra/newview/llface.cpp @@ -817,12 +817,6 @@ BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f, size.mul(scale); } - // Catch potential badness from normalization before it happens - // - llassert(mat_normal.mMatrix[0].isFinite3() && (mat_normal.mMatrix[0].dot3(mat_normal.mMatrix[0]).getF32() > F_APPROXIMATELY_ZERO)); - llassert(mat_normal.mMatrix[1].isFinite3() && (mat_normal.mMatrix[1].dot3(mat_normal.mMatrix[1]).getF32() > F_APPROXIMATELY_ZERO)); - llassert(mat_normal.mMatrix[2].isFinite3() && (mat_normal.mMatrix[2].dot3(mat_normal.mMatrix[2]).getF32() > F_APPROXIMATELY_ZERO)); - mat_normal.mMatrix[0].normalize3fast(); mat_normal.mMatrix[1].normalize3fast(); mat_normal.mMatrix[2].normalize3fast(); -- cgit v1.2.3 From 1c6783fdb564cb10ade2a585a874ce951fff34e6 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Wed, 26 Jun 2013 09:43:01 -0400 Subject: NORSPEC-29: use the MaxMaterialsPerTransaction simulator feature if available --- indra/newview/llmaterialmgr.cpp | 86 +++++++++++++++++++++++++--------------- indra/newview/llmaterialmgr.h | 2 + indra/newview/llviewerregion.cpp | 2 +- indra/newview/llviewerregion.h | 2 +- 4 files changed, 57 insertions(+), 35 deletions(-) diff --git a/indra/newview/llmaterialmgr.cpp b/indra/newview/llmaterialmgr.cpp index 16871adc4d..ad9958546c 100644 --- a/indra/newview/llmaterialmgr.cpp +++ b/indra/newview/llmaterialmgr.cpp @@ -50,13 +50,12 @@ #define MATERIALS_CAP_MATERIAL_FIELD "Material" #define MATERIALS_CAP_OBJECT_ID_FIELD "ID" #define MATERIALS_CAP_MATERIAL_ID_FIELD "MaterialID" +#define SIM_FEATURE_MAX_MATERIALS_PER_TRANSACTION "MaxMaterialsPerTransaction" -#define MATERIALS_GET_MAX_ENTRIES 50 +#define MATERIALS_DEFAULT_MAX_ENTRIES 50 #define MATERIALS_GET_TIMEOUT (60.f * 20) -#define MATERIALS_POST_MAX_ENTRIES 50 #define MATERIALS_POST_TIMEOUT (60.f * 5) #define MATERIALS_PUT_THROTTLE_SECS 1.f -#define MATERIALS_PUT_MAX_ENTRIES 50 /** * LLMaterialsResponder helper class @@ -595,8 +594,9 @@ void LLMaterialMgr::processGetQueue() LLSD materialsData = LLSD::emptyArray(); material_queue_t& materials = itRegionQueue->second; - material_queue_t::iterator loopMaterial = materials.begin(); - while ( (materials.end() != loopMaterial) && (materialsData.size() <= MATERIALS_GET_MAX_ENTRIES) ) + U32 max_entries = getMaxEntries(regionp); + material_queue_t::iterator loopMaterial = materials.begin(); + while ( (materials.end() != loopMaterial) && (materialsData.size() < max_entries) ) { material_queue_t::iterator itMaterial = loopMaterial++; materialsData.append((*itMaterial).asLLSD()); @@ -680,39 +680,43 @@ void LLMaterialMgr::processPutQueue() const LLUUID& object_id = itQueue->first; const LLViewerObject* objectp = gObjectList.findObject(object_id); - if ( (!objectp) || (!objectp->getRegion()) ) + if ( !objectp ) { - LL_WARNS("Materials") << "Object or object region is NULL" << LL_ENDL; - + LL_WARNS("Materials") << "Object is NULL" << LL_ENDL; mPutQueue.erase(itQueue); - continue; - } - - const LLViewerRegion* regionp = objectp->getRegion(); - if (!regionp->capabilitiesReceived()) - { - continue; } - - LLSD& facesData = requests[regionp]; - - facematerial_map_t& face_map = itQueue->second; - facematerial_map_t::iterator itFace = face_map.begin(); - while ( (face_map.end() != itFace) && (facesData.size() < MATERIALS_GET_MAX_ENTRIES) ) + else { - LLSD faceData = LLSD::emptyMap(); - faceData[MATERIALS_CAP_FACE_FIELD] = static_cast(itFace->first); - faceData[MATERIALS_CAP_OBJECT_ID_FIELD] = static_cast(objectp->getLocalID()); - if (!itFace->second.isNull()) + const LLViewerRegion* regionp = objectp->getRegion(); + if ( !regionp ) { - faceData[MATERIALS_CAP_MATERIAL_FIELD] = itFace->second.asLLSD(); + LL_WARNS("Materials") << "Object region is NULL" << LL_ENDL; + mPutQueue.erase(itQueue); + } + else if ( regionp->capabilitiesReceived()) + { + LLSD& facesData = requests[regionp]; + + facematerial_map_t& face_map = itQueue->second; + U32 max_entries = getMaxEntries(regionp); + facematerial_map_t::iterator itFace = face_map.begin(); + while ( (face_map.end() != itFace) && (facesData.size() < max_entries) ) + { + LLSD faceData = LLSD::emptyMap(); + faceData[MATERIALS_CAP_FACE_FIELD] = static_cast(itFace->first); + faceData[MATERIALS_CAP_OBJECT_ID_FIELD] = static_cast(objectp->getLocalID()); + if (!itFace->second.isNull()) + { + faceData[MATERIALS_CAP_MATERIAL_FIELD] = itFace->second.asLLSD(); + } + facesData.append(faceData); + face_map.erase(itFace++); + } + if (face_map.empty()) + { + mPutQueue.erase(itQueue); + } } - facesData.append(faceData); - face_map.erase(itFace++); - } - if (face_map.empty()) - { - mPutQueue.erase(itQueue); } } @@ -773,10 +777,26 @@ void LLMaterialMgr::clearGetQueues(const LLUUID& region_id) mGetAllPending.erase(region_id); mGetAllCallbacks.erase(region_id); } - void LLMaterialMgr::onRegionRemoved(LLViewerRegion* regionp) { clearGetQueues(regionp->getRegionID()); // Put doesn't need clearing: objects that can't be found will clean up in processPutQueue() } +U32 LLMaterialMgr::getMaxEntries(const LLViewerRegion* regionp) +{ + LLSD sim_features; + regionp->getSimulatorFeatures(sim_features); + U32 max_entries; + if ( sim_features.has( SIM_FEATURE_MAX_MATERIALS_PER_TRANSACTION ) + && sim_features[ SIM_FEATURE_MAX_MATERIALS_PER_TRANSACTION ].isInteger()) + { + max_entries = sim_features[ SIM_FEATURE_MAX_MATERIALS_PER_TRANSACTION ].asInteger(); + } + else + { + max_entries = MATERIALS_DEFAULT_MAX_ENTRIES; + } + return max_entries; +} + diff --git a/indra/newview/llmaterialmgr.h b/indra/newview/llmaterialmgr.h index e317a791ad..e83f1f4e01 100644 --- a/indra/newview/llmaterialmgr.h +++ b/indra/newview/llmaterialmgr.h @@ -124,6 +124,8 @@ protected: put_queue_t mPutQueue; material_map_t mMaterials; + + U32 getMaxEntries(const LLViewerRegion* regionp); }; #endif // LL_LLMATERIALMGR_H diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp index 8422708add..a4f6340d9e 100755 --- a/indra/newview/llviewerregion.cpp +++ b/indra/newview/llviewerregion.cpp @@ -1219,7 +1219,7 @@ void LLViewerRegion::getInfo(LLSD& info) info["Region"]["Handle"]["y"] = (LLSD::Integer)y; } -void LLViewerRegion::getSimulatorFeatures(LLSD& sim_features) +void LLViewerRegion::getSimulatorFeatures(LLSD& sim_features) const { sim_features = mSimulatorFeatures; diff --git a/indra/newview/llviewerregion.h b/indra/newview/llviewerregion.h index 56cd0c9ea1..031159183b 100755 --- a/indra/newview/llviewerregion.h +++ b/indra/newview/llviewerregion.h @@ -293,7 +293,7 @@ public: bool meshRezEnabled() const; bool meshUploadEnabled() const; - void getSimulatorFeatures(LLSD& info); + void getSimulatorFeatures(LLSD& info) const; void setSimulatorFeatures(const LLSD& info); -- cgit v1.2.3 From 5595888dd23b0ac526fc520eb20de6e11a2b62ee Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 26 Jun 2013 11:52:10 -0500 Subject: NORSPEC-290 Allow shader compiler to unroll loop in multiPointLightF --- .../shaders/class1/deferred/multiPointLightF.glsl | 91 +++++++++------------- indra/newview/featuretable_mac.txt | 4 +- indra/newview/llface.cpp | 6 -- indra/newview/llviewershadermgr.cpp | 27 ++++--- indra/newview/llviewershadermgr.h | 4 +- indra/newview/pipeline.cpp | 19 +++-- 6 files changed, 69 insertions(+), 82 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 868526d457..6612892f6e 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -45,9 +45,8 @@ uniform float sun_wash; uniform int light_count; -#define MAX_LIGHT_COUNT 16 -uniform vec4 light[MAX_LIGHT_COUNT]; -uniform vec4 light_col[MAX_LIGHT_COUNT]; +uniform vec4 light[LIGHT_COUNT]; +uniform vec4 light_col[LIGHT_COUNT]; VARYING vec4 vary_fragcoord; uniform vec2 screen_res; @@ -122,73 +121,59 @@ void main() vec3 npos = normalize(-pos); // As of OSX 10.6.7 ATI Apple's crash when using a variable size loop - for (int i = 0; i < MAX_LIGHT_COUNT; ++i) + for (int i = 0; i < LIGHT_COUNT; ++i) { - bool light_contrib = (i < light_count); - vec3 lv = light[i].xyz-pos; float dist = length(lv); dist /= light[i].w; - if (dist > 1.0) + if (dist <= 1.0) { - light_contrib = false; - } - - float da = dot(norm, lv); - if (da < 0.0) - { - light_contrib = false; - } - - if (light_contrib) - { - lv = normalize(lv); - da = dot(norm, lv); + float da = dot(norm, lv); + if (da > 0.0) + { + lv = normalize(lv); + da = dot(norm, lv); - float fa = light_col[i].a+1.0; - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0; + float fa = light_col[i].a+1.0; + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0; - dist_atten *= noise; + dist_atten *= noise; - float lit = da * dist_atten; + float lit = da * dist_atten; - vec3 col = light_col[i].rgb*lit*diff; + vec3 col = light_col[i].rgb*lit*diff; - //vec3 col = vec3(dist2, light_col[i].a, lit); + //vec3 col = vec3(dist2, light_col[i].a, lit); - if (spec.a > 0.0) - { - lit = min(da*6.0, 1.0) * dist_atten; - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) + if (spec.a > 0.0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += lit*scol*light_col[i].rgb*spec.rgb; - //col += spec.rgb; + lit = min(da*6.0, 1.0) * dist_atten; + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + col += lit*scol*light_col[i].rgb*spec.rgb; + //col += spec.rgb; + } } - } - out_col += col; + out_col += col; + } } } - if (dot(out_col, out_col) <= 0.0) - { - discard; - } - frag_color.rgb = out_col; frag_color.a = 0.0; } diff --git a/indra/newview/featuretable_mac.txt b/indra/newview/featuretable_mac.txt index 1c0d45c11b..0bdd425504 100755 --- a/indra/newview/featuretable_mac.txt +++ b/indra/newview/featuretable_mac.txt @@ -309,8 +309,8 @@ RenderVolumeLODFactor 1 2.0 VertexShaderEnable 1 1 WindLightUseAtmosShaders 1 1 WLSkyDetail 1 128 -RenderDeferred 1 0 -RenderDeferredSSAO 1 0 +RenderDeferred 1 1 +RenderDeferredSSAO 1 1 RenderShadowDetail 1 2 RenderFSAASamples 1 2 diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp index f021f4ed0f..700b31f8d3 100755 --- a/indra/newview/llface.cpp +++ b/indra/newview/llface.cpp @@ -817,12 +817,6 @@ BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f, size.mul(scale); } - // Catch potential badness from normalization before it happens - // - llassert(mat_normal.mMatrix[0].isFinite3() && (mat_normal.mMatrix[0].dot3(mat_normal.mMatrix[0]).getF32() > F_APPROXIMATELY_ZERO)); - llassert(mat_normal.mMatrix[1].isFinite3() && (mat_normal.mMatrix[1].dot3(mat_normal.mMatrix[1]).getF32() > F_APPROXIMATELY_ZERO)); - llassert(mat_normal.mMatrix[2].isFinite3() && (mat_normal.mMatrix[2].dot3(mat_normal.mMatrix[2]).getF32() > F_APPROXIMATELY_ZERO)); - mat_normal.mMatrix[0].normalize3fast(); mat_normal.mMatrix[1].normalize3fast(); mat_normal.mMatrix[2].normalize3fast(); diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index e24237522a..e4f04a414d 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -199,7 +199,7 @@ LLGLSLShader gDeferredTreeShadowProgram; LLGLSLShader gDeferredAvatarProgram; LLGLSLShader gDeferredAvatarAlphaProgram; LLGLSLShader gDeferredLightProgram; -LLGLSLShader gDeferredMultiLightProgram; +LLGLSLShader gDeferredMultiLightProgram[16]; LLGLSLShader gDeferredSpotLightProgram; LLGLSLShader gDeferredMultiSpotLightProgram; LLGLSLShader gDeferredSunProgram; @@ -1128,7 +1128,10 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredImpostorProgram.unload(); gDeferredTerrainProgram.unload(); gDeferredLightProgram.unload(); - gDeferredMultiLightProgram.unload(); + for (U32 i = 0; i < LL_DEFERRED_MULTI_LIGHT_COUNT; ++i) + { + gDeferredMultiLightProgram[i].unload(); + } gDeferredSpotLightProgram.unload(); gDeferredMultiSpotLightProgram.unload(); gDeferredSunProgram.unload(); @@ -1373,17 +1376,21 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() success = gDeferredLightProgram.createShader(NULL, NULL); } - if (success) + for (U32 i = 0; i < LL_DEFERRED_MULTI_LIGHT_COUNT; i++) { - gDeferredMultiLightProgram.mName = "Deferred MultiLight Shader"; - gDeferredMultiLightProgram.mShaderFiles.clear(); - gDeferredMultiLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER_ARB)); - gDeferredMultiLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightF.glsl", GL_FRAGMENT_SHADER_ARB)); - gDeferredMultiLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + if (success) + { + gDeferredMultiLightProgram[i].mName = llformat("Deferred MultiLight Shader %d", i); + gDeferredMultiLightProgram[i].mShaderFiles.clear(); + gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER_ARB)); + gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredMultiLightProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + gDeferredMultiLightProgram[i].addPermutation("LIGHT_COUNT", llformat("%d", i+1)); - SINGLE_FP_PERMUTATION(gDeferredMultiLightProgram); + SINGLE_FP_PERMUTATION(gDeferredMultiLightProgram[i]); - success = gDeferredMultiLightProgram.createShader(NULL, NULL); + success = gDeferredMultiLightProgram[i].createShader(NULL, NULL); + } } if (success) diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h index 438853cd6f..ed8167947d 100755 --- a/indra/newview/llviewershadermgr.h +++ b/indra/newview/llviewershadermgr.h @@ -30,6 +30,8 @@ #include "llshadermgr.h" #include "llmaterial.h" +#define LL_DEFERRED_MULTI_LIGHT_COUNT 16 + class LLViewerShaderMgr: public LLShaderMgr { public: @@ -341,7 +343,7 @@ extern LLGLSLShader gDeferredTerrainProgram; extern LLGLSLShader gDeferredTreeProgram; extern LLGLSLShader gDeferredTreeShadowProgram; extern LLGLSLShader gDeferredLightProgram; -extern LLGLSLShader gDeferredMultiLightProgram; +extern LLGLSLShader gDeferredMultiLightProgram[LL_DEFERRED_MULTI_LIGHT_COUNT]; extern LLGLSLShader gDeferredSpotLightProgram; extern LLGLSLShader gDeferredMultiSpotLightProgram; extern LLGLSLShader gDeferredSunProgram; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 4801c52209..2eeedc8214 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8672,10 +8672,6 @@ void LLPipeline::renderDeferredLighting() vert[2].set(3,1,0); { - bindDeferredShader(gDeferredMultiLightProgram); - - mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); - LLGLDepthTest depth(GL_FALSE); //full screen blit @@ -8687,7 +8683,7 @@ void LLPipeline::renderDeferredLighting() U32 count = 0; - const U32 max_count = 8; + const U32 max_count = LL_DEFERRED_MULTI_LIGHT_COUNT; LLVector4 light[max_count]; LLVector4 col[max_count]; @@ -8710,17 +8706,20 @@ void LLPipeline::renderDeferredLighting() count++; if (count == max_count || fullscreen_lights.empty()) { - gDeferredMultiLightProgram.uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT, count); - gDeferredMultiLightProgram.uniform4fv(LLShaderMgr::MULTI_LIGHT, count, (GLfloat*) light); - gDeferredMultiLightProgram.uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*) col); - gDeferredMultiLightProgram.uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z, far_z); + U32 idx = count-1; + bindDeferredShader(gDeferredMultiLightProgram[idx]); + gDeferredMultiLightProgram[idx].uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT, count); + gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT, count, (GLfloat*) light); + gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*) col); + gDeferredMultiLightProgram[idx].uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z, far_z); far_z = 0.f; count = 0; + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); } } - unbindDeferredShader(gDeferredMultiLightProgram); + unbindDeferredShader(gDeferredMultiLightProgram[0]); bindDeferredShader(gDeferredMultiSpotLightProgram); -- cgit v1.2.3 From 2b5205c74395ca67dde8c2978e26c2e2d5d41b97 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 26 Jun 2013 15:33:07 -0500 Subject: Merge cleanup. --- indra/newview/llviewershadermgr.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index d195971c03..7bce629d3e 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -1366,8 +1366,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMultiLightProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; gDeferredMultiLightProgram[i].addPermutation("LIGHT_COUNT", llformat("%d", i+1)); - - SINGLE_FP_PERMUTATION(gDeferredMultiLightProgram[i]); success = gDeferredMultiLightProgram[i].createShader(NULL, NULL); } } -- cgit v1.2.3 From 3ce387a04dfa7d1f90b3340770d236b2a168150d Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham)" Date: Wed, 26 Jun 2013 13:44:57 -0700 Subject: Remove patch file --- NORSPEC-207.patch | 164 ------------------------------------------------------ 1 file changed, 164 deletions(-) delete mode 100644 NORSPEC-207.patch diff --git a/NORSPEC-207.patch b/NORSPEC-207.patch deleted file mode 100644 index a1c1447bda..0000000000 --- a/NORSPEC-207.patch +++ /dev/null @@ -1,164 +0,0 @@ -diff -r fe4bab01522e indra/llprimitive/llrendermaterialtable.cpp ---- a/indra/llprimitive/llrendermaterialtable.cpp Wed May 15 17:57:21 2013 +0000 -+++ b/indra/llprimitive/llrendermaterialtable.cpp Wed May 22 14:23:04 2013 -0700 -@@ -184,6 +184,44 @@ - } - } - -+// 'v' is an integer value for 100ths of radians (don't ask...) -+// -+void LLRenderMaterialEntry::LLRenderMaterial::setSpecularMapRotation(S32 v) const -+{ -+ // Store the fact that we're using the new rotation rep -+ // -+ m_flags |= kNewSpecularMapRotation; -+ -+ // Store 'sign bit' in our m_flags -+ // -+ m_flags &= ~kSpecularMapRotationNegative; -+ m_flags |= (specularMapRotation < 0) ? kSpecularMapRotationNegative : 0; -+ -+ specularRotation = abs(specularRotation); -+ specularRotation = llmin(specularRotation, MAX_MATERIAL_MAP_ROTATION); -+ -+ m_specularRotation = (U16)(abs(specularMapRotation)); -+} -+ -+// 'v' is an integer value for 100ths of radians (don't ask...) -+// -+void LLRenderMaterialEntry::LLRenderMaterial::setNormalMapRotation(S32 v) const -+{ -+ -+ // Store the fact that we're using the new rep for this material -+ // -+ m_flags |= kNewNormalMapRotation; -+ -+ // Store 'sign bit' in our m_flags -+ // -+ m_flags &= ~kNormalMapRotationNegative; -+ m_flags |= (normalMapRotation < 0) ? kNormalMapRotationNegative : 0; -+ -+ normalRotation = abs(normalRotation); -+ normalRotation = llmin(normalRotation, MAX_MATERIAL_MAP_ROTATION); -+ -+ m_normalRotation = (U16)(abs(normalMapRotation)); -+} - - void LLRenderMaterialEntry::LLRenderMaterial::asLLSD( LLSD& dest ) const - { -@@ -193,20 +231,45 @@ - dest["NormOffsetY"] = (S32)m_normalOffsetY; - dest["NormRepeatX"] = m_normalRepeatX; - dest["NormRepeatY"] = m_normalRepeatY; -- dest["NormRotation"] = (S32)m_normalRotation; -+ -+ S32 value = (S32)m_normalMapRotation; -+ -+ // If we don't have the flag for new rotations set, -+ // then we need to convert it now -+ if (!(m_flags & kNewNormalMapRotation)) -+ { -+ F32 old_radians = ((F32)m_normalMapRotation / 10000.0f) -+ S32 new_val = (S32)(old_radians * 100.0f); -+ setNormalMapRotation(new_Val); -+ } -+ -+ dest["NormRotation"] = (m_flags & kNormalMapRotationNegative) ? -(S32)m_normalRotation : (S32)m_normalRotation; - - dest["SpecOffsetX"] = (S32)m_specularOffsetX; - dest["SpecOffsetY"] = (S32)m_specularOffsetY; - dest["SpecRepeatX"] = m_specularRepeatX; - dest["SpecRepeatY"] = m_specularRepeatY; -- dest["SpecRotation"] = (S32)m_specularRotation; -+ -+ -+ value = (S32)m_specularRotation; -+ -+ // If we don't have the flag for new rotations set, -+ // then we need to convert it now -+ if (!(m_flags & kNewSpecularMapRotation)) -+ { -+ F32 old_radians = ((F32)m_specularMapRotation / 10000.0f) -+ S32 new_val = (S32)(old_radians * 100.0f); -+ setSpecularMapRotation(new_Val); -+ } -+ -+ dest["SpecRotation"] = (m_flags & kSpecularMapRotationNegative) ? -(S32)m_specularRotation : (S32)m_specularRotation; - - dest["SpecMap"] = m_specularMap; - dest["SpecColor"] = m_specularLightColor.getValue(); - dest["SpecExp"] = (S32)m_specularLightExponent; - dest["EnvIntensity"] = (S32)m_environmentIntensity; - dest["AlphaMaskCutoff"] = (S32)m_alphaMaskCutoff; -- dest["DiffuseAlphaMode"] = (S32)m_diffuseAlphaMode; -+ dest["DiffuseAlphaMode"] = (S32)(m_diffuseAlphaMode & 0xF); - - } - -@@ -217,7 +280,10 @@ - m_normalOffsetY = (U16)materialDefinition["NormOffsetY"].asInteger(); - m_normalRepeatX = materialDefinition["NormRepeatX"].asInteger(); - m_normalRepeatY = materialDefinition["NormRepeatY"].asInteger(); -- m_normalRotation = (U16)materialDefinition["NormRotation"].asInteger(); -+ -+ S32 normalRotation = materialDefinition["NormRotation"].asInteger(); -+ -+ setNormalMapRotation(normalRotation); - - m_specularMap = materialDefinition["SpecMap"].asUUID(); - -@@ -225,7 +291,10 @@ - m_specularOffsetY = (U16)materialDefinition["SpecOffsetY"].asInteger(); - m_specularRepeatX = materialDefinition["SpecRepeatX"].asInteger(); - m_specularRepeatY = materialDefinition["SpecRepeatY"].asInteger(); -- m_specularRotation = (U16)materialDefinition["SpecRotation"].asInteger(); -+ -+ S32 specularRotation = materialDefinition["SpecRotation"].asInteger(); -+ -+ setSpecularMapRotation(specularRotation); - - m_specularLightColor.setValue( materialDefinition["SpecColor"] ); - m_specularLightExponent = (U8)materialDefinition["SpecExp"].asInteger(); -diff -r fe4bab01522e indra/llprimitive/llrendermaterialtable.h ---- a/indra/llprimitive/llrendermaterialtable.h Wed May 15 17:57:21 2013 +0000 -+++ b/indra/llprimitive/llrendermaterialtable.h Wed May 22 14:23:04 2013 -0700 -@@ -89,11 +89,17 @@ - - void computeID(); - -+ - struct LLRenderMaterial - { - void asLLSD( LLSD& dest ) const; - void setFromLLSD( const LLSD& materialDefinition ); - -+ void setNormalMapRotation(S32 v); -+ void setSpecularMapRotation(S32 v); -+ -+ const S32 MAX_MATERIAL_MAP_ROTATION = 62800; -+ - // 36 bytes - LLUUID m_normalMap; - LLUUID m_specularMap; -@@ -119,7 +125,20 @@ - U8 m_specularLightExponent; - U8 m_environmentIntensity; - U8 m_alphaMaskCutoff; -- U8 m_diffuseAlphaMode; -+ U8 m_diffuseAlphaMode : 4; -+ U8 m_flags : 4; -+ }; -+ -+ // Flags stored in LLRenderMaterial::m_flags to differentiate 'old' rotation format -+ // which doesn't handle negative or large rotations correctly from new format. -+ // All ancient materials will have these flags unset as the values for diffuseAlphaMode -+ // from which the bits were stolen never used more than the bottom 2 bits. -+ // -+ enum RenderMaterialFlags { -+ kNewNormalMapRotation = 0x1, -+ kNewSpecularMapRotation = 0x2, -+ kNormalMapRotationNegative = 0x4, -+ kSpecularMapRotationNegative = 0x8 - }; - - friend struct eastl::hash; -- cgit v1.2.3 From 06b024f60e6953f3b1de08523b511e0f0a777531 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 26 Jun 2013 19:16:49 -0500 Subject: MATBUG-194 Fix for crazy colors on projector shadows with NVIDIA OpenGL 3.3 implementations --- .../app_settings/shaders/class2/deferred/multiSpotLightF.glsl | 4 ++++ indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 0deb4fe3b6..14f6afc8c2 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -318,6 +318,10 @@ void main() } } + + //not sure why, but this line prevents MATBUG-194 + col = max(col, vec3(0.0)); + frag_color.rgb = col; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 7a4337c277..6e0218cb9c 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -315,7 +315,10 @@ void main() } } } - + + //not sure why, but this line prevents MATBUG-194 + col = max(col, vec3(0.0)); + frag_color.rgb = col; frag_color.a = 0.0; } -- cgit v1.2.3 From 860b86e3d1c61c18be99301ea1c5027058a8353d Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 27 Jun 2013 13:48:44 -0400 Subject: Fix for down key presses not opening up the IME character selection window, and inadvertently being handled while marked text is selected. --- indra/llwindow/llopenglview-objc.mm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index aa7df2c985..7803d78862 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -316,12 +316,16 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void) keyDown:(NSEvent *)theEvent { uint keycode = [theEvent keyCode]; - bool acceptsText = callKeyDown(keycode, mModifiers); + bool acceptsText = mHasMarkedText ? false : callKeyDown(keycode, mModifiers); if (acceptsText && !mMarkedTextAllowed && ![(LLAppDelegate*)[NSApp delegate] romanScript] && [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSDeleteCharacter && - [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSBackspaceCharacter) + [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSBackspaceCharacter && + [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSDownArrowFunctionKey && + [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSUpArrowFunctionKey && + [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSLeftArrowFunctionKey && + [[theEvent charactersIgnoringModifiers] characterAtIndex:0] != NSRightArrowFunctionKey) { [(LLAppDelegate*)[NSApp delegate] showInputWindow:true withEvent:theEvent]; } else @@ -339,7 +343,7 @@ attributedStringInfo getSegments(NSAttributedString *str) // OS X intentionally does not send us key-up information on cmd-key combinations. // This behaviour is not a bug, and only applies to cmd-combinations (no others). // Since SL assumes we receive those, we fake it here. - if (mModifiers & NSCommandKeyMask) + if (mModifiers & NSCommandKeyMask && !mHasMarkedText) { callKeyUp([theEvent keyCode], mModifiers); } -- cgit v1.2.3 From 623077e6a4eef516d445975eaa71d5f67e6767c5 Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 27 Jun 2013 15:06:03 -0400 Subject: Added license headers. --- indra/llwindow/llappdelegate-objc.h | 32 ++++++++++++++++++----- indra/llwindow/llopenglview-objc.h | 32 ++++++++++++++++++----- indra/llwindow/llopenglview-objc.mm | 32 ++++++++++++++++++----- indra/llwindow/llwindowmacosx-objc.mm | 48 +++++++++++++++++------------------ indra/newview/llappdelegate-objc.mm | 32 ++++++++++++++++++----- 5 files changed, 124 insertions(+), 52 deletions(-) diff --git a/indra/llwindow/llappdelegate-objc.h b/indra/llwindow/llappdelegate-objc.h index a6fb77d93f..faa5d3abb7 100644 --- a/indra/llwindow/llappdelegate-objc.h +++ b/indra/llwindow/llappdelegate-objc.h @@ -1,10 +1,28 @@ -// -// LLAppDelegate.h -// SecondLife -// -// Created by Geenz on 12/16/12. -// -// +/** + * @file llappdelegate-objc.h + * @brief Class interface for the Mac version's application delegate. + * + * $LicenseInfo:firstyear=2000&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ #import #import "llopenglview-objc.h" diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index b783c41c0b..f895aae577 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -1,10 +1,28 @@ -// -// LLOpenGLView.h -// SecondLife -// -// Created by Geenz on 10/2/12. -// -// +/** + * @file llopenglview-objc.h + * @brief Class interfaces for most of the Mac facing window functionality. + * + * $LicenseInfo:firstyear=2000&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ #ifndef LLOpenGLView_H #define LLOpenGLView_H diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 7803d78862..8a6984091d 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -1,10 +1,28 @@ -// -// LLOpenGLView.m -// SecondLife -// -// Created by Geenz on 10/2/12. -// -// +/** + * @file llopenglview-objc.mm + * @brief Class implementation for most of the Mac facing window functionality. + * + * $LicenseInfo:firstyear=2000&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ #import "llopenglview-objc.h" #include "llwindowmacosx-objc.h" diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 67b5279c0b..41d8e3ecd9 100755 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -1,4 +1,4 @@ -/** +/** * @file llwindowmacosx-objc.mm * @brief Definition of functions shared between llwindowmacosx.cpp * and llwindowmacosx-objc.mm. @@ -6,21 +6,21 @@ * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2010, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -52,10 +52,10 @@ void setupCocoa() NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // The following prevents the Cocoa command line parser from trying to open 'unknown' arguements as documents. - // ie. running './secondlife -set Language fr' would cause a pop-up saying can't open document 'fr' - // when init'ing the Cocoa App window. + // ie. running './secondlife -set Language fr' would cause a pop-up saying can't open document 'fr' + // when init'ing the Cocoa App window. [[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; - + [pool release]; inited = true; @@ -100,17 +100,17 @@ const unsigned short *copyFromPBoard() CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - + // extra retain on the NSCursor since we want it to live for the lifetime of the app. NSCursor *cursor = - [[[NSCursor alloc] - initWithImage: - [[[NSImage alloc] initWithContentsOfFile: - [NSString stringWithFormat:@"%s", fullpath] - ]autorelease] - hotSpot:NSMakePoint(hotspotX, hotspotY) - ]retain]; - + [[[NSCursor alloc] + initWithImage: + [[[NSImage alloc] initWithContentsOfFile: + [NSString stringWithFormat:@"%s", fullpath] + ]autorelease] + hotSpot:NSMakePoint(hotspotX, hotspotY) + ]retain]; + [pool release]; return (CursorRef)cursor; @@ -209,7 +209,7 @@ OSErr setImageCursor(CursorRef ref) NSWindowRef createNSWindow(int x, int y, int width, int height) { LLNSWindow *window = [[LLNSWindow alloc]initWithContentRect:NSMakeRect(x, y, width, height) - styleMask:NSTitledWindowMask | NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTexturedBackgroundWindowMask backing:NSBackingStoreBuffered defer:NO]; + styleMask:NSTitledWindowMask | NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTexturedBackgroundWindowMask backing:NSBackingStoreBuffered defer:NO]; [window makeKeyAndOrderFront:nil]; [window setAcceptsMouseMovedEvents:TRUE]; return window; @@ -391,13 +391,13 @@ void makeFirstResponder(NSWindowRef window, GLViewRef view) } /* -GLViewRef getGLView() -{ - return [(LLAppDelegate*)[[NSApplication sharedApplication] delegate] glview]; -} -*/ + GLViewRef getGLView() + { + return [(LLAppDelegate*)[[NSApplication sharedApplication] delegate] glview]; + } + */ unsigned int getModifiers() -{ +{ return [NSEvent modifierFlags]; } diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm index 6b7e613491..30476b3d22 100644 --- a/indra/newview/llappdelegate-objc.mm +++ b/indra/newview/llappdelegate-objc.mm @@ -1,10 +1,28 @@ -// -// LLAppDelegate.m -// SecondLife -// -// Created by Geenz on 12/16/12. -// -// +/** + * @file llappdelegate-objc.mm + * @brief Class implementation for the Mac version's application delegate. + * + * $LicenseInfo:firstyear=2000&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ #import "llappdelegate-objc.h" #include "llwindowmacosx-objc.h" -- cgit v1.2.3 From 5f397fa58352fb58d79b72148904f925416f4978 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Fri, 28 Jun 2013 13:29:11 -0400 Subject: NORSPEC-206: read RenderMaterialsCapability throttle rate per second from simulator --- indra/newview/llmaterialmgr.cpp | 24 +++++++++++++----------- indra/newview/llmaterialmgr.h | 3 +++ indra/newview/llviewerregion.cpp | 32 ++++++++++++++++++++++++++++++++ indra/newview/llviewerregion.h | 8 ++++++++ 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/indra/newview/llmaterialmgr.cpp b/indra/newview/llmaterialmgr.cpp index ad9958546c..96dd402d84 100644 --- a/indra/newview/llmaterialmgr.cpp +++ b/indra/newview/llmaterialmgr.cpp @@ -543,11 +543,9 @@ void LLMaterialMgr::onIdle(void*) instancep->processGetAllQueue(); } - static LLFrameTimer mPutTimer; - if ( (!instancep->mPutQueue.empty()) && (mPutTimer.hasExpired()) ) + if (!instancep->mPutQueue.empty()) { instancep->processPutQueue(); - mPutTimer.resetWithExpiry(MATERIALS_PUT_THROTTLE_SECS); } } @@ -564,14 +562,14 @@ void LLMaterialMgr::processGetQueue() continue; } - const LLViewerRegion* regionp = LLWorld::instance().getRegionFromID(region_id); + LLViewerRegion* regionp = LLWorld::instance().getRegionFromID(region_id); if (!regionp) { LL_WARNS("Materials") << "Unknown region with id " << region_id.asString() << LL_ENDL; mGetQueue.erase(itRegionQueue); continue; } - else if (!regionp->capabilitiesReceived()) + else if (!regionp->capabilitiesReceived() || regionp->materialsCapThrottled()) { continue; } @@ -628,6 +626,7 @@ void LLMaterialMgr::processGetQueue() LL_DEBUGS("Materials") << "POSTing to region '" << regionp->getName() << "' at '"<< capURL << " for " << materialsData.size() << " materials." << "\ndata: " << ll_pretty_print_sd(materialsData) << LL_ENDL; LLHTTPClient::post(capURL, postData, materialsResponder); + regionp->resetMaterialsCapThrottle(); } } @@ -646,7 +645,7 @@ void LLMaterialMgr::processGetAllQueue() clearGetQueues(region_id); // Invalidates region_id continue; } - else if (!regionp->capabilitiesReceived()) + else if (!regionp->capabilitiesReceived() || regionp->materialsCapThrottled()) { continue; } @@ -663,6 +662,7 @@ void LLMaterialMgr::processGetAllQueue() LL_DEBUGS("Materials") << "GET all for region " << region_id << "url " << capURL << LL_ENDL; LLHTTPClient::ResponderPtr materialsResponder = new LLMaterialsResponder("GET", capURL, boost::bind(&LLMaterialMgr::onGetAllResponse, this, _1, _2, *itRegion)); LLHTTPClient::get(capURL, materialsResponder); + regionp->resetMaterialsCapThrottle(); mGetAllPending.insert(std::pair(region_id, LLFrameTimer::getTotalSeconds())); mGetAllQueue.erase(itRegion); // Invalidates region_id } @@ -670,7 +670,7 @@ void LLMaterialMgr::processGetAllQueue() void LLMaterialMgr::processPutQueue() { - typedef std::map regionput_request_map; + typedef std::map regionput_request_map; regionput_request_map requests; put_queue_t::iterator loopQueue = mPutQueue.begin(); @@ -687,13 +687,13 @@ void LLMaterialMgr::processPutQueue() } else { - const LLViewerRegion* regionp = objectp->getRegion(); + LLViewerRegion* regionp = objectp->getRegion(); if ( !regionp ) { LL_WARNS("Materials") << "Object region is NULL" << LL_ENDL; mPutQueue.erase(itQueue); } - else if ( regionp->capabilitiesReceived()) + else if ( regionp->capabilitiesReceived() && !regionp->materialsCapThrottled()) { LLSD& facesData = requests[regionp]; @@ -722,11 +722,12 @@ void LLMaterialMgr::processPutQueue() for (regionput_request_map::const_iterator itRequest = requests.begin(); itRequest != requests.end(); ++itRequest) { - std::string capURL = itRequest->first->getCapability(MATERIALS_CAPABILITY_NAME); + LLViewerRegion* regionp = itRequest->first; + std::string capURL = regionp->getCapability(MATERIALS_CAPABILITY_NAME); if (capURL.empty()) { LL_WARNS("Materials") << "Capability '" << MATERIALS_CAPABILITY_NAME - << "' is not defined on region '" << itRequest->first->getName() << "'" << LL_ENDL; + << "' is not defined on region '" << regionp->getName() << "'" << LL_ENDL; continue; } @@ -749,6 +750,7 @@ void LLMaterialMgr::processPutQueue() LL_DEBUGS("Materials") << "put for " << itRequest->second.size() << " faces to region " << itRequest->first->getName() << LL_ENDL; LLHTTPClient::ResponderPtr materialsResponder = new LLMaterialsResponder("PUT", capURL, boost::bind(&LLMaterialMgr::onPutResponse, this, _1, _2)); LLHTTPClient::put(capURL, putData, materialsResponder); + regionp->resetMaterialsCapThrottle(); } else { diff --git a/indra/newview/llmaterialmgr.h b/indra/newview/llmaterialmgr.h index e83f1f4e01..2836019c27 100644 --- a/indra/newview/llmaterialmgr.h +++ b/indra/newview/llmaterialmgr.h @@ -126,6 +126,9 @@ protected: material_map_t mMaterials; U32 getMaxEntries(const LLViewerRegion* regionp); + + LLFrameTimer mCapThrottleTimer; + F32 getThrottleIntervalSecs(const LLUUID& region_id); }; #endif // LL_LLMATERIALMGR_H diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp index a4f6340d9e..0f8decc643 100755 --- a/indra/newview/llviewerregion.cpp +++ b/indra/newview/llviewerregion.cpp @@ -1944,3 +1944,35 @@ bool LLViewerRegion::dynamicPathfindingEnabled() const mSimulatorFeatures["DynamicPathfindingEnabled"].asBoolean()); } +void LLViewerRegion::resetMaterialsCapThrottle() +{ + F32 requests_per_sec = 1.0f; // original default; + if ( mSimulatorFeatures.has("RenderMaterialsCapability") + && mSimulatorFeatures["RenderMaterialsCapability"].isReal() ) + { + requests_per_sec = mSimulatorFeatures["RenderMaterialsCapability"].asReal(); + if ( requests_per_sec != 0.0f ) + { + requests_per_sec = 1.0f; + LL_WARNS("Materials") + << "region '" << getName() + << "' returned zero for RenderMaterialsCapability; using default " + << requests_per_sec << " per second" + << LL_ENDL; + } + LL_DEBUGS_ONCE("Materials") << "region '" << getName() + << "' RenderMaterialsCapability " << requests_per_sec + << LL_ENDL; + } + else + { + LL_DEBUGS("Materials") + << "region '" << getName() + << "' did not return RenderMaterialsCapability, using default " + << requests_per_sec << " per second" + << LL_ENDL; + } + + mMaterialsCapThrottleTimer.resetWithExpiry( 1.0f / requests_per_sec ); +} + diff --git a/indra/newview/llviewerregion.h b/indra/newview/llviewerregion.h index 031159183b..a3db7f5ac7 100755 --- a/indra/newview/llviewerregion.h +++ b/indra/newview/llviewerregion.h @@ -43,6 +43,7 @@ #include "llcapabilityprovider.h" #include "m4math.h" // LLMatrix4 #include "llhttpclient.h" +#include "llframetimer.h" // Surface id's #define LAND 1 @@ -342,6 +343,10 @@ public: void getNeighboringRegionsStatus( std::vector& regions ); const LLViewerRegionImpl * getRegionImpl() const { return mImpl; } LLViewerRegionImpl * getRegionImplNC() { return mImpl; } + + // implements the materials capability throttle + bool materialsCapThrottled() const { return !mMaterialsCapThrottleTimer.hasExpired(); } + void resetMaterialsCapThrottle(); public: struct CompareDistance @@ -434,6 +439,9 @@ private: BOOL mReleaseNotesRequested; LLSD mSimulatorFeatures; + + // the materials capability throttle + LLFrameTimer mMaterialsCapThrottleTimer; }; inline BOOL LLViewerRegion::getRegionProtocol(U64 protocol) const -- cgit v1.2.3 From 8ae792b38af42d26a0f588e9a8b778df99416fd5 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Fri, 28 Jun 2013 16:18:08 -0400 Subject: move reading of the sim features to LLViewerRegion for consistency, a couple of minor cleanups --- indra/newview/llmaterialmgr.cpp | 23 ++--------------------- indra/newview/llmaterialmgr.h | 5 ----- indra/newview/llviewerregion.cpp | 12 ++++++++++++ indra/newview/llviewerregion.h | 1 + 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/indra/newview/llmaterialmgr.cpp b/indra/newview/llmaterialmgr.cpp index 96dd402d84..658fea944d 100644 --- a/indra/newview/llmaterialmgr.cpp +++ b/indra/newview/llmaterialmgr.cpp @@ -50,9 +50,7 @@ #define MATERIALS_CAP_MATERIAL_FIELD "Material" #define MATERIALS_CAP_OBJECT_ID_FIELD "ID" #define MATERIALS_CAP_MATERIAL_ID_FIELD "MaterialID" -#define SIM_FEATURE_MAX_MATERIALS_PER_TRANSACTION "MaxMaterialsPerTransaction" -#define MATERIALS_DEFAULT_MAX_ENTRIES 50 #define MATERIALS_GET_TIMEOUT (60.f * 20) #define MATERIALS_POST_TIMEOUT (60.f * 5) #define MATERIALS_PUT_THROTTLE_SECS 1.f @@ -592,7 +590,7 @@ void LLMaterialMgr::processGetQueue() LLSD materialsData = LLSD::emptyArray(); material_queue_t& materials = itRegionQueue->second; - U32 max_entries = getMaxEntries(regionp); + U32 max_entries = regionp->getMaxMaterialsPerTransaction(); material_queue_t::iterator loopMaterial = materials.begin(); while ( (materials.end() != loopMaterial) && (materialsData.size() < max_entries) ) { @@ -698,7 +696,7 @@ void LLMaterialMgr::processPutQueue() LLSD& facesData = requests[regionp]; facematerial_map_t& face_map = itQueue->second; - U32 max_entries = getMaxEntries(regionp); + U32 max_entries = regionp->getMaxMaterialsPerTransaction(); facematerial_map_t::iterator itFace = face_map.begin(); while ( (face_map.end() != itFace) && (facesData.size() < max_entries) ) { @@ -785,20 +783,3 @@ void LLMaterialMgr::onRegionRemoved(LLViewerRegion* regionp) // Put doesn't need clearing: objects that can't be found will clean up in processPutQueue() } -U32 LLMaterialMgr::getMaxEntries(const LLViewerRegion* regionp) -{ - LLSD sim_features; - regionp->getSimulatorFeatures(sim_features); - U32 max_entries; - if ( sim_features.has( SIM_FEATURE_MAX_MATERIALS_PER_TRANSACTION ) - && sim_features[ SIM_FEATURE_MAX_MATERIALS_PER_TRANSACTION ].isInteger()) - { - max_entries = sim_features[ SIM_FEATURE_MAX_MATERIALS_PER_TRANSACTION ].asInteger(); - } - else - { - max_entries = MATERIALS_DEFAULT_MAX_ENTRIES; - } - return max_entries; -} - diff --git a/indra/newview/llmaterialmgr.h b/indra/newview/llmaterialmgr.h index 2836019c27..e317a791ad 100644 --- a/indra/newview/llmaterialmgr.h +++ b/indra/newview/llmaterialmgr.h @@ -124,11 +124,6 @@ protected: put_queue_t mPutQueue; material_map_t mMaterials; - - U32 getMaxEntries(const LLViewerRegion* regionp); - - LLFrameTimer mCapThrottleTimer; - F32 getThrottleIntervalSecs(const LLUUID& region_id); }; #endif // LL_LLMATERIALMGR_H diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp index 0f8decc643..b541a35111 100755 --- a/indra/newview/llviewerregion.cpp +++ b/indra/newview/llviewerregion.cpp @@ -1976,3 +1976,15 @@ void LLViewerRegion::resetMaterialsCapThrottle() mMaterialsCapThrottleTimer.resetWithExpiry( 1.0f / requests_per_sec ); } +U32 LLViewerRegion::getMaxMaterialsPerTransaction() const +{ + U32 max_entries = 50; // original hard coded default + if ( mSimulatorFeatures.has( "MaxMaterialsPerTransaction" ) + && mSimulatorFeatures[ "MaxMaterialsPerTransaction" ].isInteger()) + { + max_entries = mSimulatorFeatures[ "MaxMaterialsPerTransaction" ].asInteger(); + } + return max_entries; +} + + diff --git a/indra/newview/llviewerregion.h b/indra/newview/llviewerregion.h index a3db7f5ac7..109baccf9a 100755 --- a/indra/newview/llviewerregion.h +++ b/indra/newview/llviewerregion.h @@ -348,6 +348,7 @@ public: bool materialsCapThrottled() const { return !mMaterialsCapThrottleTimer.hasExpired(); } void resetMaterialsCapThrottle(); + U32 getMaxMaterialsPerTransaction() const; public: struct CompareDistance { -- cgit v1.2.3 From dd31d9941fe1bfbccdfd0428abbe803b6c495f6c Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Jul 2013 07:39:55 -0700 Subject: NORSPEC-296 make add_media button always available as long as the face is editable --- indra/newview/llfloatertools.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indra/newview/llfloatertools.cpp b/indra/newview/llfloatertools.cpp index 14923eec3c..7b25291da7 100755 --- a/indra/newview/llfloatertools.cpp +++ b/indra/newview/llfloatertools.cpp @@ -1328,7 +1328,7 @@ void LLFloaterTools::getMediaState() getChildView("media_tex")->setEnabled(bool_has_media && editable); getChildView("edit_media")->setEnabled(bool_has_media && LLFloaterMediaSettings::getInstance()->mIdenticalHasMediaInfo && editable ); getChildView("delete_media")->setEnabled(bool_has_media && editable ); - getChildView("add_media")->setEnabled(( ! bool_has_media ) && editable ); + getChildView("add_media")->setEnabled(editable); // TODO: display a list of all media on the face - use 'identical' flag } else // not all face has media but at least one does. @@ -1358,7 +1358,7 @@ void LLFloaterTools::getMediaState() getChildView("media_tex")->setEnabled(TRUE); getChildView("edit_media")->setEnabled(LLFloaterMediaSettings::getInstance()->mIdenticalHasMediaInfo); getChildView("delete_media")->setEnabled(TRUE); - getChildView("add_media")->setEnabled(FALSE ); + getChildView("add_media")->setEnabled(editable); } media_info->setText(media_title); -- cgit v1.2.3 From 418c8a72c875b30d1e0746422afa3caaa809e37b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Jul 2013 07:39:55 -0700 Subject: NORSPEC-296 make add_media button always available as long as the face is editable --- indra/newview/llfloatertools.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indra/newview/llfloatertools.cpp b/indra/newview/llfloatertools.cpp index 14923eec3c..7b25291da7 100755 --- a/indra/newview/llfloatertools.cpp +++ b/indra/newview/llfloatertools.cpp @@ -1328,7 +1328,7 @@ void LLFloaterTools::getMediaState() getChildView("media_tex")->setEnabled(bool_has_media && editable); getChildView("edit_media")->setEnabled(bool_has_media && LLFloaterMediaSettings::getInstance()->mIdenticalHasMediaInfo && editable ); getChildView("delete_media")->setEnabled(bool_has_media && editable ); - getChildView("add_media")->setEnabled(( ! bool_has_media ) && editable ); + getChildView("add_media")->setEnabled(editable); // TODO: display a list of all media on the face - use 'identical' flag } else // not all face has media but at least one does. @@ -1358,7 +1358,7 @@ void LLFloaterTools::getMediaState() getChildView("media_tex")->setEnabled(TRUE); getChildView("edit_media")->setEnabled(LLFloaterMediaSettings::getInstance()->mIdenticalHasMediaInfo); getChildView("delete_media")->setEnabled(TRUE); - getChildView("add_media")->setEnabled(FALSE ); + getChildView("add_media")->setEnabled(editable); } media_info->setText(media_title); -- cgit v1.2.3 From f1c04467f70ce7e5a048614fa7db631cd3a35a00 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Jul 2013 13:12:08 -0700 Subject: NORSPEC-292 fix issues with managing LLNetworkData::PARAMS_LIGHT_IMAGE when demoting spotlights by removing their tex --- indra/newview/llpanelvolume.cpp | 13 ++++++++++++- indra/newview/lltexturectrl.cpp | 13 +++++++++++-- indra/newview/llvovolume.cpp | 6 ++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/indra/newview/llpanelvolume.cpp b/indra/newview/llpanelvolume.cpp index 02d363d795..0b501f6a74 100755 --- a/indra/newview/llpanelvolume.cpp +++ b/indra/newview/llpanelvolume.cpp @@ -710,9 +710,20 @@ void LLPanelVolume::onLightCancelColor(const LLSD& data) void LLPanelVolume::onLightCancelTexture(const LLSD& data) { LLTextureCtrl* LightTextureCtrl = getChild("light texture control"); + if (LightTextureCtrl) { - LightTextureCtrl->setImageAssetID(mLightSavedTexture); + LightTextureCtrl->setImageAssetID(LLUUID::null); + } + + LLVOVolume *volobjp = (LLVOVolume *) mObject.get(); + if(volobjp) + { + // Cancel the light texture as requested + // NORSPEC-292 + // + volobjp->setLightTextureID(LLUUID::null); + volobjp->setIsLight(TRUE,TRUE); } } diff --git a/indra/newview/lltexturectrl.cpp b/indra/newview/lltexturectrl.cpp index 4676f7b251..2b1ed5858a 100755 --- a/indra/newview/lltexturectrl.cpp +++ b/indra/newview/lltexturectrl.cpp @@ -133,7 +133,8 @@ public: PermissionMask getFilterPermMask(); void updateFilterPermMask(); void commitIfImmediateSet(); - + void commitCancel(); + void onFilterEdit(const std::string& search_string ); void setCanApply(bool can_preview, bool can_apply); @@ -706,6 +707,14 @@ void LLFloaterTexturePicker::commitIfImmediateSet() } } +void LLFloaterTexturePicker::commitCancel() +{ + if (!mNoCopyTextureSelected && mOwner && mCanApply) + { + mOwner->onFloaterCommit(LLTextureCtrl::TEXTURE_CANCEL); + } +} + // static void LLFloaterTexturePicker::onBtnSetToDefault(void* userdata) { @@ -733,7 +742,7 @@ void LLFloaterTexturePicker::onBtnNone(void* userdata) { LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata; self->setImageID( LLUUID::null ); - self->commitIfImmediateSet(); + self->commitCancel(); } /* diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 685f854573..d890548710 100755 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -2590,6 +2590,7 @@ void LLVOVolume::setLightTextureID(LLUUID id) if (hasLightTexture()) { setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE, FALSE, true); + parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true); mLightTexture = NULL; } } @@ -2607,7 +2608,8 @@ void LLVOVolume::setSpotLightParams(LLVector3 params) void LLVOVolume::setIsLight(BOOL is_light) { - if (is_light != getIsLight()) + BOOL was_light = getIsLight(); + if (is_light != was_light) { if (is_light) { @@ -2792,7 +2794,7 @@ void LLVOVolume::updateSpotLightPriority() bool LLVOVolume::isLightSpotlight() const { LLLightImageParams* params = (LLLightImageParams*) getParameterEntry(LLNetworkData::PARAMS_LIGHT_IMAGE); - if (params) + if (params && getParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE)) { return params->isLightSpotlight(); } -- cgit v1.2.3 From c262ef58fab4dcbe8d891f9acba285ddc2c296db Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Jul 2013 13:16:23 -0700 Subject: NORSPEC-292 remove unnecessary call to setIsLight --- indra/newview/llpanelvolume.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/indra/newview/llpanelvolume.cpp b/indra/newview/llpanelvolume.cpp index 0b501f6a74..a1d60b5b16 100755 --- a/indra/newview/llpanelvolume.cpp +++ b/indra/newview/llpanelvolume.cpp @@ -723,7 +723,6 @@ void LLPanelVolume::onLightCancelTexture(const LLSD& data) // NORSPEC-292 // volobjp->setLightTextureID(LLUUID::null); - volobjp->setIsLight(TRUE,TRUE); } } -- cgit v1.2.3 From 9c8fdf5a49145f4147f50c16c4e1775386976798 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Tue, 2 Jul 2013 17:07:50 -0400 Subject: fix bug reading RenderMaterialsCapability, improve logging for NORSPEC-206 --- indra/newview/llviewerregion.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp index b541a35111..e6fc82f761 100755 --- a/indra/newview/llviewerregion.cpp +++ b/indra/newview/llviewerregion.cpp @@ -1951,7 +1951,7 @@ void LLViewerRegion::resetMaterialsCapThrottle() && mSimulatorFeatures["RenderMaterialsCapability"].isReal() ) { requests_per_sec = mSimulatorFeatures["RenderMaterialsCapability"].asReal(); - if ( requests_per_sec != 0.0f ) + if ( requests_per_sec == 0.0f ) { requests_per_sec = 1.0f; LL_WARNS("Materials") @@ -1960,9 +1960,9 @@ void LLViewerRegion::resetMaterialsCapThrottle() << requests_per_sec << " per second" << LL_ENDL; } - LL_DEBUGS_ONCE("Materials") << "region '" << getName() - << "' RenderMaterialsCapability " << requests_per_sec - << LL_ENDL; + LL_DEBUGS("Materials") << "region '" << getName() + << "' RenderMaterialsCapability " << requests_per_sec + << LL_ENDL; } else { -- cgit v1.2.3 From 930de04f51212195a2c7a877d235d4106f4d37e2 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 2 Jul 2013 18:02:28 -0500 Subject: NORSPEC-287 Make alpha sRGB correction curves match OpenGL spec. --- .../shaders/class1/deferred/alphaF.glsl | 29 ++++++++++++++++++---- .../shaders/class1/deferred/materialF.glsl | 28 ++++++++++++++++++--- .../shaders/class1/deferred/multiPointLightF.glsl | 2 ++ .../shaders/class1/deferred/multiSpotLightF.glsl | 25 +++++++++++++++---- .../class1/deferred/postDeferredGammaCorrect.glsl | 13 +++++++++- .../shaders/class1/deferred/softenLightF.glsl | 26 +++++++++++++++++-- .../shaders/class2/deferred/softenLightF.glsl | 24 ++++++++++++++++-- indra/newview/lldrawable.cpp | 2 ++ 8 files changed, 131 insertions(+), 18 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 143af0576c..e80e4b0fcf 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -135,6 +135,26 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc) } #endif +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} + void main() { @@ -217,7 +237,7 @@ void main() #endif vec4 gamma_diff = diff; - diff.rgb = pow(diff.rgb, vec3(2.2f, 2.2f, 2.2f)); + diff.rgb = srgb_to_linear(diff.rgb); #ifdef USE_VERTEX_COLOR float vertex_color_alpha = vertex_color.a; @@ -243,9 +263,8 @@ void main() color.rgb = scaleSoftClip(color.rgb); - color.rgb = pow(color.rgb, vec3(2.2)); + color.rgb = srgb_to_linear(color.rgb); col = vec4(0,0,0,0); - #define LIGHT_LOOP(i) col.rgb += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, normal, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); @@ -257,9 +276,9 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) - color.rgb += diff.rgb * pow(vary_pointlight_col, vec3(2.2)) * col.rgb; + color.rgb += diff.rgb * srgb_to_linear(vary_pointlight_col) * col.rgb; - color.rgb = pow(color.rgb, vec3(1.0/2.2)); + color.rgb = linear_to_srgb(color.rgb); frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 53ade8ea64..027c6eeadb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -30,6 +30,28 @@ uniform float emissive_brightness; + +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} + + #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #ifdef DEFINE_GL_FRAGCOLOR @@ -459,7 +481,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vec3 old_diffcol = diffcol.rgb; - diffcol.rgb = pow(diffcol.rgb, vec3(2.2)); + diffcol.rgb = srgb_to_linear(diffcol.rgb); #endif #if HAS_SPECULAR_MAP @@ -648,7 +670,7 @@ void main() col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); //convert to linear space before adding local lights - col = pow(col, vec3(2.2)); + col = srgb_to_linear(col); vec3 npos = normalize(-pos.xyz); @@ -665,7 +687,7 @@ void main() //convert to gamma space for display on screen - col.rgb = pow(col.rgb, vec3(1.0/2.2)); + col.rgb = linear_to_srgb(col.rgb); frag_color.rgb = col.rgb; glare = min(glare, 1.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index a955ef6e9d..3ba6de8b76 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -99,6 +99,7 @@ void main() norm = normalize(norm); vec4 spec = texture2DRect(specularRect, frag.xy); vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb; + float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 out_col = vec3(0,0,0); vec3 npos = normalize(-pos); @@ -157,6 +158,7 @@ void main() } } + frag_color.rgb = out_col; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 7d39ad7bc1..11220bfa47 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -84,15 +84,30 @@ vec3 decode_normal (vec2 enc) return n; } -vec4 correctWithGamma(vec4 col) +vec3 srgb_to_linear(vec3 cs) { - return vec4(pow(col.rgb, vec3(2.2)), col.a); + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; } vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = tc-vec2(0.5); @@ -108,7 +123,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -126,7 +141,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = tc-vec2(0.5); diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 6f2cfae6d2..a3610bfffa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -38,9 +38,20 @@ VARYING vec2 vary_fragcoord; uniform float texture_gamma; +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} + void main() { vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - frag_color = pow(diff, vec4(texture_gamma, texture_gamma, texture_gamma, 1.0f)); + diff.rgb = linear_to_srgb(diff.rgb); + frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index f0d2746700..dc2519bd0a 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -78,6 +78,28 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; + +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} + + vec3 decode_normal (vec2 enc) { vec2 fenc = enc*4-2; @@ -313,7 +335,7 @@ void main() vec4 diffuse = texture2DRect(diffuseRect, tc); //convert to gamma space - diffuse.rgb = pow(diffuse.rgb, vec3(1.0/2.2)); + diffuse.rgb = linear_to_srgb(diffuse.rgb); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 col; @@ -369,7 +391,7 @@ void main() col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); } - col = pow(col, vec3(2.2)); + col = srgb_to_linear(col); //col = vec3(1,0,1); //col.g = envIntensity; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 6e05091b57..06447261b4 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -78,6 +78,26 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} + vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -326,7 +346,7 @@ void main() vec4 diffuse = texture2DRect(diffuseRect, tc); //convert to gamma space - diffuse.rgb = pow(diffuse.rgb, vec3(1.0/2.2)); + diffuse.rgb = linear_to_srgb(diffuse.rgb); vec3 col; float bloom = 0.0; @@ -392,7 +412,7 @@ void main() col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); } - col = pow(col, vec3(2.2)); + col = srgb_to_linear(col); //col = vec3(1,0,1); //col.g = envIntensity; diff --git a/indra/newview/lldrawable.cpp b/indra/newview/lldrawable.cpp index 8c9fd4152a..2a333157f2 100755 --- a/indra/newview/lldrawable.cpp +++ b/indra/newview/lldrawable.cpp @@ -527,6 +527,8 @@ void LLDrawable::makeStatic(BOOL warning_enabled) } updatePartition(); } + + llassert(isAvatar() || isRoot() || mParent->isStatic()); } // Returns "distance" between target destination and resulting xfrom -- cgit v1.2.3 From ce6bb9538489b420d5f0827779912d7241dfa6c6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 2 Jul 2013 16:50:35 -0700 Subject: NORSPEC-293 nix gamma correction in fullbrightF causing this visual disparity --- .../app_settings/shaders/class1/deferred/fullbrightF.glsl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index dc1dead656..5bdb3115d9 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -45,19 +45,21 @@ vec3 fullbrightScaleSoftClip(vec3 light); void main() { #if HAS_DIFFUSE_LOOKUP - vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; + vec4 color = diffuseLookup(vary_texcoord0.xy); #else - vec4 color = texture2D(diffuseMap, vary_texcoord0.xy)*vertex_color; + vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); #endif color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); - - color.rgb = fullbrightAtmosTransport(color.rgb); + color.rgb *= vertex_color.rgb; + color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); - color.rgb = pow(color.rgb, vec3(1.0/2.2)); + // NORSPEC-293 + //color.rgb = pow(color.rgb, vec3(1.0/2.2)); - frag_color = color; + frag_color.rgb = color.rgb; + frag_color.a = color.a; } -- cgit v1.2.3 From 6c440d1b51fcd73d56e96ceb8a285282a6a242ef Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Wed, 3 Jul 2013 09:15:33 -0400 Subject: remove command line option that causes warning messages --- autobuild.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/autobuild.xml b/autobuild.xml index 628d3f6883..50c5808bb5 100755 --- a/autobuild.xml +++ b/autobuild.xml @@ -2674,7 +2674,6 @@ /build "/cfg=Release|Win32" - "/CL_ADD=/m:1" configure -- cgit v1.2.3 From ed3b5184990822162840e1e7611d338a880e67a6 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 3 Jul 2013 10:42:03 -0700 Subject: NORSPEC-295 make a deferred path version of fullbright alpha mask shader so we can included gamma ops --- .../class1/deferred/fullbrightAlphaMaskF.glsl | 70 ++++++++++++++++++++++ indra/newview/lldrawpoolsimple.cpp | 15 ++++- indra/newview/llviewershadermgr.cpp | 17 ++++++ indra/newview/llviewershadermgr.h | 1 + 4 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl new file mode 100644 index 0000000000..5aa31b96df --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl @@ -0,0 +1,70 @@ +/** + * @file fullbrightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#extension GL_ARB_texture_rectangle : enable + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +#if !HAS_DIFFUSE_LOOKUP +uniform sampler2D diffuseMap; +#endif + +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +vec3 fullbrightAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light); + +uniform float minimum_alpha; + +void main() +{ +#if HAS_DIFFUSE_LOOKUP + vec4 color = diffuseLookup(vary_texcoord0.xy); +#else + vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); +#endif + + if (color.a < minimum_alpha) + { + discard; + } + + color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); + color.rgb *= vertex_color.rgb; + + color.rgb = fullbrightAtmosTransport(color.rgb); + color.rgb = fullbrightScaleSoftClip(color.rgb); + + color.rgb = pow(color.rgb, vec3(1.0/2.2)); + + frag_color.rgb = color.rgb; + frag_color.a = color.a; +} + diff --git a/indra/newview/lldrawpoolsimple.cpp b/indra/newview/lldrawpoolsimple.cpp index 2cf9d833c6..e219769a0c 100755 --- a/indra/newview/lldrawpoolsimple.cpp +++ b/indra/newview/lldrawpoolsimple.cpp @@ -625,14 +625,16 @@ S32 LLDrawPoolFullbright::getNumPasses() void LLDrawPoolFullbrightAlphaMask::beginPostDeferredPass(S32 pass) { - gObjectFullbrightAlphaMaskProgram.bind(); + if (LLPipeline::sRenderingHUDs || !LLPipeline::sRenderDeferred) { + gObjectFullbrightAlphaMaskProgram.bind(); gObjectFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 1.0f); } else { - gObjectFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); + gDeferredFullbrightAlphaMaskProgram.bind(); + gDeferredFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); } } @@ -646,7 +648,14 @@ void LLDrawPoolFullbrightAlphaMask::renderPostDeferred(S32 pass) void LLDrawPoolFullbrightAlphaMask::endPostDeferredPass(S32 pass) { - gObjectFullbrightAlphaMaskProgram.unbind(); + if (LLPipeline::sRenderingHUDs || !LLPipeline::sRenderDeferred) + { + gObjectFullbrightAlphaMaskProgram.unbind(); + } + else + { + gDeferredFullbrightAlphaMaskProgram.unbind(); + } LLRenderPass::endRenderPass(pass); } diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 7bce629d3e..6d9a0dd261 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -197,6 +197,7 @@ LLGLSLShader gDeferredAttachmentShadowProgram; LLGLSLShader gDeferredAlphaProgram; LLGLSLShader gDeferredAvatarEyesProgram; LLGLSLShader gDeferredFullbrightProgram; +LLGLSLShader gDeferredFullbrightAlphaMaskProgram; LLGLSLShader gDeferredEmissiveProgram; LLGLSLShader gDeferredPostProgram; LLGLSLShader gDeferredCoFProgram; @@ -290,6 +291,7 @@ LLViewerShaderMgr::LLViewerShaderMgr() : mShaderList.push_back(&gDeferredAlphaProgram); mShaderList.push_back(&gDeferredSkinnedAlphaProgram); mShaderList.push_back(&gDeferredFullbrightProgram); + mShaderList.push_back(&gDeferredFullbrightAlphaMaskProgram); mShaderList.push_back(&gDeferredFullbrightShinyProgram); mShaderList.push_back(&gDeferredSkinnedFullbrightShinyProgram); mShaderList.push_back(&gDeferredSkinnedFullbrightProgram); @@ -1130,6 +1132,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAvatarAlphaProgram.unload(); gDeferredAlphaProgram.unload(); gDeferredFullbrightProgram.unload(); + gDeferredFullbrightAlphaMaskProgram.unload(); gDeferredEmissiveProgram.unload(); gDeferredAvatarEyesProgram.unload(); gDeferredPostProgram.unload(); @@ -1493,6 +1496,20 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() success = gDeferredFullbrightProgram.createShader(NULL, NULL); } + if (success) + { + gDeferredFullbrightAlphaMaskProgram.mName = "Deferred Fullbright Alpha Mask Shader"; + gDeferredFullbrightAlphaMaskProgram.mFeatures.calculatesAtmospherics = true; + gDeferredFullbrightAlphaMaskProgram.mFeatures.hasGamma = true; + gDeferredFullbrightAlphaMaskProgram.mFeatures.hasTransport = true; + gDeferredFullbrightAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; + gDeferredFullbrightAlphaMaskProgram.mShaderFiles.clear(); + gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); + gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightAlphaMaskF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredFullbrightAlphaMaskProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + success = gDeferredFullbrightAlphaMaskProgram.createShader(NULL, NULL); + } + if (success) { gDeferredFullbrightShinyProgram.mName = "Deferred FullbrightShiny Shader"; diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h index ed8167947d..f3a419b1f2 100755 --- a/indra/newview/llviewershadermgr.h +++ b/indra/newview/llviewershadermgr.h @@ -363,6 +363,7 @@ extern LLGLSLShader gDeferredAvatarShadowProgram; extern LLGLSLShader gDeferredAttachmentShadowProgram; extern LLGLSLShader gDeferredAlphaProgram; extern LLGLSLShader gDeferredFullbrightProgram; +extern LLGLSLShader gDeferredFullbrightAlphaMaskProgram; extern LLGLSLShader gDeferredEmissiveProgram; extern LLGLSLShader gDeferredAvatarEyesProgram; extern LLGLSLShader gDeferredAvatarAlphaProgram; -- cgit v1.2.3 From d2855f9eecdfb80dca6c5a8b496ef9fe1b746843 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 3 Jul 2013 10:56:10 -0700 Subject: NORSPEC-293 better fix incorporating srgb_to_linear curve and applying texture gamma corrections to spot inputs --- .../class1/deferred/fullbrightAlphaMaskF.glsl | 24 ++++++++++++++++++++-- .../shaders/class1/deferred/fullbrightF.glsl | 24 +++++++++++++++++++--- .../shaders/class1/deferred/spotLightF.glsl | 22 +++++++++++++++++++- .../shaders/class2/deferred/alphaV.glsl | 22 +++++++++++++++++++- .../shaders/class2/deferred/multiSpotLightF.glsl | 12 ++++++++++- .../shaders/class2/deferred/spotLightF.glsl | 12 ++++++++++- 6 files changed, 107 insertions(+), 9 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl index 5aa31b96df..3d93583e1e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl @@ -41,6 +41,26 @@ VARYING vec2 vary_texcoord0; vec3 fullbrightAtmosTransport(vec3 light); vec3 fullbrightScaleSoftClip(vec3 light); +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} + uniform float minimum_alpha; void main() @@ -56,13 +76,13 @@ void main() discard; } - color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); + color.rgb = srgb_to_linear(color.rgb); color.rgb *= vertex_color.rgb; color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); - color.rgb = pow(color.rgb, vec3(1.0/2.2)); + color.rgb = linear_to_srgb(color.rgb); frag_color.rgb = color.rgb; frag_color.a = color.a; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 5bdb3115d9..ec25f52ef5 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -41,6 +41,25 @@ VARYING vec2 vary_texcoord0; vec3 fullbrightAtmosTransport(vec3 light); vec3 fullbrightScaleSoftClip(vec3 light); +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} void main() { @@ -50,14 +69,13 @@ void main() vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); #endif - color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); + color.rgb = srgb_to_linear(color.rgb); color.rgb *= vertex_color.rgb; color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); - // NORSPEC-293 - //color.rgb = pow(color.rgb, vec3(1.0/2.2)); + color.rgb = linear_to_srgb(color.rgb); frag_color.rgb = color.rgb; frag_color.a = color.a; diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 045d1a00cd..61262c9eb5 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -82,9 +82,29 @@ vec3 decode_normal (vec2 enc) return n; } +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} + vec4 correctWithGamma(vec4 col) { - return vec4(pow(col.rgb, vec3(2.2)), col.a); + return vec4(srgb_to_linear(col.rgb), col.a); } vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl index 13c6ffc607..fc60998ec3 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl @@ -85,6 +85,26 @@ uniform vec3 light_diffuse[8]; uniform vec3 sun_dir; +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} + vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); @@ -183,7 +203,7 @@ void main() //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); - vec3 dff = pow(diffuse_color.rgb, vec3(2.2f,2.2f,2.2f)); + vec3 dff = srgb_to_linear(diffuse_color.rgb); vary_pointlight_col = dff; diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 14f6afc8c2..0aac9d77de 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -85,9 +85,19 @@ vec3 decode_normal (vec2 enc) return n; } +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + vec4 correctWithGamma(vec4 col) { - return vec4(pow(col.rgb, vec3(2.2)), col.a); + return vec4(srgb_to_linear(col.rgb), col.a); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 6e0218cb9c..17c0d26f6d 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -85,9 +85,19 @@ vec3 decode_normal (vec2 enc) return n; } +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + vec4 correctWithGamma(vec4 col) { - return vec4(pow(col.rgb, vec3(2.2)), col.a); + return vec4(srgb_to_linear(col.rgb), col.a); } vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) -- cgit v1.2.3 From cf3b7bbe4b932b683d0d30c95505f45d16a1d2a7 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 3 Jul 2013 12:59:29 -0500 Subject: NORSPEC-298 Fix for inconsistent alpha lighting when diffuse color is not white. --- .../shaders/class1/deferred/alphaF.glsl | 4 +- .../shaders/class1/deferred/alphaV.glsl | 15 +- .../shaders/class2/deferred/alphaV.glsl | 224 --------------------- 3 files changed, 15 insertions(+), 228 deletions(-) delete mode 100755 indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index e80e4b0fcf..640e273415 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -61,6 +61,7 @@ VARYING vec3 vary_directional; VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; +VARYING vec3 vary_pointlight_col_linear; VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; @@ -228,6 +229,7 @@ void main() { shadow = 1.0; } + #endif #ifdef USE_INDEXED_TEX @@ -276,7 +278,7 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) - color.rgb += diff.rgb * srgb_to_linear(vary_pointlight_col) * col.rgb; + color.rgb += diff.rgb * vary_pointlight_col_linear * col.rgb; color.rgb = linear_to_srgb(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 9d3ba564cd..6b5b54b863 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -68,6 +68,7 @@ VARYING vec3 vary_directional; VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; +VARYING vec3 vary_pointlight_col_linear; #ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; @@ -86,6 +87,16 @@ uniform vec3 light_diffuse[8]; uniform vec3 sun_dir; +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + vec3 calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) { //get light vector @@ -178,10 +189,8 @@ void main() vec3 diff = diffuse_color.rgb; - - vary_pointlight_col = diff; - + vary_pointlight_col_linear = srgb_to_linear(diff); col.rgb = vec3(0,0,0); diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl deleted file mode 100755 index 13c6ffc607..0000000000 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl +++ /dev/null @@ -1,224 +0,0 @@ -/** - * @file alphaV.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -uniform mat3 normal_matrix; -uniform mat4 texture_matrix0; -uniform mat4 projection_matrix; -uniform mat4 modelview_matrix; -uniform mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; - -#ifdef USE_INDEXED_TEX -void passTextureIndex(); -#endif - -ATTRIBUTE vec3 normal; - -#ifdef USE_VERTEX_COLOR -ATTRIBUTE vec4 diffuse_color; -#endif - -ATTRIBUTE vec2 texcoord0; - -#ifdef HAS_SKIN -mat4 getObjectSkinnedTransform(); -#else -#ifdef IS_AVATAR_SKIN -mat4 getSkinnedTransform(); -#endif -#endif - -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); -void calcAtmospherics(vec3 inPositionEye); - -vec3 calcDirectionalLight(vec3 n, vec3 l); - -vec3 atmosAmbient(vec3 light); -vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); -vec3 scaleUpLight(vec3 light); - -VARYING vec3 vary_ambient; -VARYING vec3 vary_directional; -VARYING vec3 vary_fragcoord; -VARYING vec3 vary_position; -VARYING vec3 vary_pointlight_col; - -#ifdef USE_VERTEX_COLOR -VARYING vec4 vertex_color; -#endif - -VARYING vec2 vary_texcoord0; -VARYING vec3 vary_norm; - -uniform float near_clip; -uniform float shadow_offset; -uniform float shadow_bias; - -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -uniform vec3 sun_dir; - -vec3 calcDirectionalLight(vec3 n, vec3 l) -{ - float a = max(dot(n,l),0.0); - return vec3(a,a,a); -} - -vec3 calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) -{ - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float d = dot(lv,lv); - - float da = 0.0; - - if (d > 0.0 && la > 0.0 && fa > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist2 = d/la; - da = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - //angular attenuation - da *= max(dot(n, lv), 0.0); - } - - return vec3(da,da,da); -} - -void main() -{ - vec4 pos; - vec3 norm; - - //transform vertex -#ifdef HAS_SKIN - mat4 trans = getObjectSkinnedTransform(); - trans = modelview_matrix * trans; - - pos = trans * vec4(position.xyz, 1.0); - - norm = position.xyz + normal.xyz; - norm = normalize((trans * vec4(norm, 1.0)).xyz - pos.xyz); - vec4 frag_pos = projection_matrix * pos; - gl_Position = frag_pos; -#else - -#ifdef IS_AVATAR_SKIN - mat4 trans = getSkinnedTransform(); - vec4 pos_in = vec4(position.xyz, 1.0); - pos.x = dot(trans[0], pos_in); - pos.y = dot(trans[1], pos_in); - pos.z = dot(trans[2], pos_in); - pos.w = 1.0; - - norm.x = dot(trans[0].xyz, normal); - norm.y = dot(trans[1].xyz, normal); - norm.z = dot(trans[2].xyz, normal); - norm = normalize(norm); - - vec4 frag_pos = projection_matrix * pos; - gl_Position = frag_pos; -#else - norm = normalize(normal_matrix * normal); - vec4 vert = vec4(position.xyz, 1.0); - pos = (modelview_matrix * vert); - gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); -#endif - -#endif - -#ifdef USE_INDEXED_TEX - passTextureIndex(); - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -#else - vary_texcoord0 = texcoord0; -#endif - - vary_norm = norm; - float dp_directional_light = max(0.0, dot(norm, light_position[0].xyz)); - vary_position = pos.xyz + light_position[0].xyz * (1.0-dp_directional_light)*shadow_offset; - - calcAtmospherics(pos.xyz); - -#ifndef USE_VERTEX_COLOR - vec4 diffuse_color = vec4(1,1,1,1); -#endif - - //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); - vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); - - vec3 dff = pow(diffuse_color.rgb, vec3(2.2f,2.2f,2.2f)); - - vary_pointlight_col = dff; - - col.rgb = vec3(0,0,0); - - // Add windlight lights - col.rgb = atmosAmbient(col.rgb); - - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb *= ambient; - - vary_directional.rgb = atmosAffectDirectionalLight(1.0f); - vary_ambient = col.rgb*dff; - - col.rgb = col.rgb*dff; - -#ifdef USE_VERTEX_COLOR - vertex_color = col; -#endif - -#ifdef HAS_SKIN - vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); -#else - -#ifdef IS_AVATAR_SKIN - vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); -#else - pos = modelview_projection_matrix * vert; - vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); -#endif - -#endif - -} -- cgit v1.2.3 From 6963c69c85144a8d20e4c67f65ec9334c8fde22d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 3 Jul 2013 11:42:52 -0700 Subject: NORSPEC-297 fix deferred fog using wrong ref point --- indra/newview/app_settings/shaders/class1/deferred/waterV.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl index ece34dcc4e..9734acf005 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl @@ -85,7 +85,7 @@ void main() pos.w = 1.0; pos = modelview_matrix*pos; - calcAtmospherics(view.xyz); + calcAtmospherics(pos.xyz); //pass wave parameters to pixel shader vec2 bigWave = (v.xy) * vec2(0.04,0.04) + d1 * time * 0.055; -- cgit v1.2.3 From 4ad86739c1b6823540fb596481621c089d3a3183 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 3 Jul 2013 15:10:54 -0500 Subject: NORSPEC-286 Make raycast code pay attention to diffuse alpha mode. --- indra/newview/llvovolume.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index d890548710..b545e99a32 100755 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -3724,8 +3724,30 @@ BOOL LLVOVolume::lineSegmentIntersect(const LLVector4a& start, const LLVector4a& { LLFace* face = mDrawable->getFace(face_hit); + bool ignore_alpha = false; + + const LLTextureEntry* te = face->getTextureEntry(); + if (te) + { + LLMaterial* mat = te->getMaterialParams(); + if (mat) + { + U8 mode = mat->getDiffuseAlphaMode(); + + if (mode == LLMaterial::DIFFUSE_ALPHA_MODE_EMISSIVE || + mode == LLMaterial::DIFFUSE_ALPHA_MODE_NONE) + { + ignore_alpha = true; + } + } + } + if (face && - (pick_transparent || !face->getTexture() || !face->getTexture()->hasGLTexture() || face->getTexture()->getMask(face->surfaceToTexture(tc, p, n)))) + (ignore_alpha || + pick_transparent || + !face->getTexture() || + !face->getTexture()->hasGLTexture() || + face->getTexture()->getMask(face->surfaceToTexture(tc, p, n)))) { local_end = p; if (face_hitp != NULL) -- cgit v1.2.3 From 5d7be3a4987c603500bbe3733870a378bd9eda92 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 8 Jul 2013 10:46:21 -0700 Subject: NORSPEC-300 stop-gap measure of clamping offsets > 0 until server-side fix to store negative values can be released --- indra/newview/skins/default/xui/en/panel_tools_texture.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indra/newview/skins/default/xui/en/panel_tools_texture.xml b/indra/newview/skins/default/xui/en/panel_tools_texture.xml index 5ac2ec2b20..426c0c4915 100644 --- a/indra/newview/skins/default/xui/en/panel_tools_texture.xml +++ b/indra/newview/skins/default/xui/en/panel_tools_texture.xml @@ -663,7 +663,7 @@ label_width="205" layout="topleft" left="10" - min_val="-1" + min_val="0" name="bumpyOffsetU" width="265" /> Date: Mon, 8 Jul 2013 12:17:41 -0700 Subject: NORSPEC-293 WIP fix black glowing fullbright, does not address deferred glow errors --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index ec25f52ef5..90518128fb 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -70,10 +70,10 @@ void main() #endif color.rgb = srgb_to_linear(color.rgb); - color.rgb *= vertex_color.rgb; color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); + color.rgb *= vertex_color.rgb; color.rgb = linear_to_srgb(color.rgb); -- cgit v1.2.3 From 167fc262734dfb72e33e57a0b309d0ce6a17ce47 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 9 Jul 2013 06:38:12 -0700 Subject: NORSPEC-291 WIP drop the no deferred underwater logic only --- indra/newview/lldrawpoolalpha.cpp | 11 +- indra/newview/llviewerdisplay.cpp | 8 +- indra/newview/pipeline.cpp | 523 ++++++++++++++++++++++++++++++++++++-- indra/newview/pipeline.h | 3 +- 4 files changed, 522 insertions(+), 23 deletions(-) diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index c832e1401d..737da2e209 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -113,6 +113,15 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) gObjectFullbrightAlphaMaskProgram.setMinimumAlpha(0.33f); } + if (LLPipeline::sUnderWaterRender) + { + emissive_shader = &gObjectEmissiveWaterProgram; + } + else + { + emissive_shader = &gObjectEmissiveProgram; + } + deferred_render = TRUE; if (mVertexShaderLevel > 0) { @@ -352,7 +361,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask) LLMaterial* mat = NULL; - if (deferred_render && !LLPipeline::sUnderWaterRender) + if (deferred_render) { mat = params.mMaterial; } diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp index f90b35a7bd..e6718ca618 100755 --- a/indra/newview/llviewerdisplay.cpp +++ b/indra/newview/llviewerdisplay.cpp @@ -890,7 +890,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot) { gGL.setColorMask(true, true); - if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender) + if (LLPipeline::sRenderDeferred) { gPipeline.mDeferredScreen.bindTarget(); glClearColor(1,0,1,1); @@ -939,7 +939,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot) gGL.setColorMask(true, false); - if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender) + if (LLPipeline::sRenderDeferred) { gPipeline.renderGeomDeferred(*LLViewerCamera::getInstance()); } @@ -976,7 +976,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot) if (to_texture) { - if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender) + if (LLPipeline::sRenderDeferred) { gPipeline.mDeferredScreen.flush(); if(LLRenderTarget::sUseFBO) @@ -1002,7 +1002,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot) } } - if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender) + if (LLPipeline::sRenderDeferred) { gPipeline.renderDeferredLighting(); } diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index c9f8a4d9ee..aed73be3c1 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -2448,7 +2448,7 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result, S32 water_cl if (to_texture) { - if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender) + if (LLPipeline::sRenderDeferred) { mOcclusionDepth.bindTarget(); } @@ -2593,7 +2593,7 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result, S32 water_cl if (to_texture) { - if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender) + if (LLPipeline::sRenderDeferred) { mOcclusionDepth.flush(); } @@ -8891,6 +8891,495 @@ void LLPipeline::renderDeferredLighting() } +void LLPipeline::renderDeferredLightingToRenderTarget(LLRenderTarget* render_target) +{ + if (!sCull) + { + return; + } + + { + LLFastTimer ftm(FTM_RENDER_DEFERRED); + + LLViewerCamera* camera = LLViewerCamera::getInstance(); + { + LLGLDepthTest depth(GL_TRUE); + mDeferredDepth.copyContents(mDeferredScreen, 0, 0, mDeferredScreen.getWidth(), mDeferredScreen.getHeight(), + 0, 0, mDeferredDepth.getWidth(), mDeferredDepth.getHeight(), GL_DEPTH_BUFFER_BIT, GL_NEAREST); + } + + LLGLEnable multisample(0); + + if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD)) + { + gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD); + } + + //ati doesn't seem to love actually using the stencil buffer on FBO's + LLGLDisable stencil(GL_STENCIL_TEST); + //glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF); + //glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + + gGL.setColorMask(true, true); + + //draw a cube around every light + LLVertexBuffer::unbind(); + + LLGLEnable cull(GL_CULL_FACE); + LLGLEnable blend(GL_BLEND); + + glh::matrix4f mat = glh_copy_matrix(gGLModelView); + + LLStrider vert; + mDeferredVB->getVertexStrider(vert); + + vert[0].set(-1,1,0); + vert[1].set(-1,-3,0); + vert[2].set(3,1,0); + + { + setupHWLights(NULL); //to set mSunDir; + LLVector4 dir(mSunDir, 0.f); + glh::vec4f tc(dir.mV); + mat.mult_matrix_vec(tc); + mTransformedSunDir.set(tc.v); + } + + gGL.pushMatrix(); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_PROJECTION); + gGL.pushMatrix(); + gGL.loadIdentity(); + + stop_glerror(); + gGL.popMatrix(); + stop_glerror(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + stop_glerror(); + gGL.popMatrix(); + stop_glerror(); + + render_target = render_target ? render_target : &mScreen; + + llassert(render_target); + + render_target->bindTarget(); + + // clear color buffer here - zeroing alpha (glow) is important or it will accumulate against sky + glClearColor(0,0,0,0); + render_target->clear(GL_COLOR_BUFFER_BIT); + + if (RenderDeferredAtmospheric) + { //apply sunlight contribution + LLFastTimer ftm(FTM_ATMOSPHERICS); + bindDeferredShader(gDeferredSoftenProgram); + { + LLGLDepthTest depth(GL_FALSE); + LLGLDisable blend(GL_BLEND); + LLGLDisable test(GL_ALPHA_TEST); + + //full screen blit + gGL.pushMatrix(); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_PROJECTION); + gGL.pushMatrix(); + gGL.loadIdentity(); + + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + + mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); + + gGL.popMatrix(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + gGL.popMatrix(); + } + + unbindDeferredShader(gDeferredSoftenProgram); + } + + { //render non-deferred geometry (fullbright, alpha, etc) + LLGLDisable blend(GL_BLEND); + LLGLDisable stencil(GL_STENCIL_TEST); + gGL.setSceneBlendType(LLRender::BT_ALPHA); + + gPipeline.pushRenderTypeMask(); + + gPipeline.andRenderTypeMask(LLPipeline::RENDER_TYPE_SKY, + LLPipeline::RENDER_TYPE_CLOUDS, + LLPipeline::RENDER_TYPE_WL_SKY, + LLPipeline::END_RENDER_TYPES); + + + renderGeomPostDeferred(*LLViewerCamera::getInstance(), false); + gPipeline.popRenderTypeMask(); + } + + BOOL render_local = RenderLocalLights; + + if (render_local) + { + gGL.setSceneBlendType(LLRender::BT_ADD); + std::list fullscreen_lights; + LLDrawable::drawable_list_t spot_lights; + LLDrawable::drawable_list_t fullscreen_spot_lights; + + for (U32 i = 0; i < 2; i++) + { + mTargetShadowSpotLight[i] = NULL; + } + + std::list light_colors; + + LLVertexBuffer::unbind(); + + { + bindDeferredShader(gDeferredLightProgram); + + if (mCubeVB.isNull()) + { + mCubeVB = ll_create_cube_vb(LLVertexBuffer::MAP_VERTEX, GL_STATIC_DRAW_ARB); + } + + mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + + LLGLDepthTest depth(GL_TRUE, GL_FALSE); + for (LLDrawable::drawable_set_t::iterator iter = mLights.begin(); iter != mLights.end(); ++iter) + { + LLDrawable* drawablep = *iter; + + LLVOVolume* volume = drawablep->getVOVolume(); + if (!volume) + { + continue; + } + + if (volume->isAttachment()) + { + if (!sRenderAttachedLights) + { + continue; + } + } + + + LLVector4a center; + center.load3(drawablep->getPositionAgent().mV); + const F32* c = center.getF32ptr(); + F32 s = volume->getLightRadius()*1.5f; + + LLColor3 col = volume->getLightColor(); + + if (col.magVecSquared() < 0.001f) + { + continue; + } + + if (s <= 0.001f) + { + continue; + } + + LLVector4a sa; + sa.splat(s); + if (camera->AABBInFrustumNoFarClip(center, sa) == 0) + { + continue; + } + + sVisibleLightCount++; + + if (camera->getOrigin().mV[0] > c[0] + s + 0.2f || + camera->getOrigin().mV[0] < c[0] - s - 0.2f || + camera->getOrigin().mV[1] > c[1] + s + 0.2f || + camera->getOrigin().mV[1] < c[1] - s - 0.2f || + camera->getOrigin().mV[2] > c[2] + s + 0.2f || + camera->getOrigin().mV[2] < c[2] - s - 0.2f) + { //draw box if camera is outside box + if (render_local) + { + if (volume->isLightSpotlight()) + { + drawablep->getVOVolume()->updateSpotLightPriority(); + spot_lights.push_back(drawablep); + continue; + } + + /*col.mV[0] = powf(col.mV[0], 2.2f); + col.mV[1] = powf(col.mV[1], 2.2f); + col.mV[2] = powf(col.mV[2], 2.2f);*/ + + LLFastTimer ftm(FTM_LOCAL_LIGHTS); + gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c); + gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); + gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); + gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); + gGL.syncMatrices(); + + mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center)); + stop_glerror(); + } + } + else + { + if (volume->isLightSpotlight()) + { + drawablep->getVOVolume()->updateSpotLightPriority(); + fullscreen_spot_lights.push_back(drawablep); + continue; + } + + glh::vec3f tc(c); + mat.mult_matrix_vec(tc); + + fullscreen_lights.push_back(LLVector4(tc.v[0], tc.v[1], tc.v[2], s)); + light_colors.push_back(LLVector4(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff()*0.5f)); + } + } + unbindDeferredShader(gDeferredLightProgram); + } + + if (!spot_lights.empty()) + { + LLGLDepthTest depth(GL_TRUE, GL_FALSE); + bindDeferredShader(gDeferredSpotLightProgram); + + mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + + gDeferredSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION); + + for (LLDrawable::drawable_list_t::iterator iter = spot_lights.begin(); iter != spot_lights.end(); ++iter) + { + LLFastTimer ftm(FTM_PROJECTORS); + LLDrawable* drawablep = *iter; + + LLVOVolume* volume = drawablep->getVOVolume(); + + LLVector4a center; + center.load3(drawablep->getPositionAgent().mV); + const F32* c = center.getF32ptr(); + F32 s = volume->getLightRadius()*1.5f; + + sVisibleLightCount++; + + setupSpotLight(gDeferredSpotLightProgram, drawablep); + + LLColor3 col = volume->getLightColor(); + /*col.mV[0] = powf(col.mV[0], 2.2f); + col.mV[1] = powf(col.mV[1], 2.2f); + col.mV[2] = powf(col.mV[2], 2.2f);*/ + + gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c); + gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); + gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); + gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); + gGL.syncMatrices(); + + mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center)); + } + gDeferredSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION); + unbindDeferredShader(gDeferredSpotLightProgram); + } + + //reset mDeferredVB to fullscreen triangle + mDeferredVB->getVertexStrider(vert); + vert[0].set(-1,1,0); + vert[1].set(-1,-3,0); + vert[2].set(3,1,0); + + { + bindDeferredShader(gDeferredMultiLightProgram); + + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + + LLGLDepthTest depth(GL_FALSE); + + //full screen blit + gGL.pushMatrix(); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_PROJECTION); + gGL.pushMatrix(); + gGL.loadIdentity(); + + U32 count = 0; + + const U32 max_count = 8; + LLVector4 light[max_count]; + LLVector4 col[max_count]; + + F32 far_z = 0.f; + + while (!fullscreen_lights.empty()) + { + LLFastTimer ftm(FTM_FULLSCREEN_LIGHTS); + light[count] = fullscreen_lights.front(); + fullscreen_lights.pop_front(); + col[count] = light_colors.front(); + light_colors.pop_front(); + + /*col[count].mV[0] = powf(col[count].mV[0], 2.2f); + col[count].mV[1] = powf(col[count].mV[1], 2.2f); + col[count].mV[2] = powf(col[count].mV[2], 2.2f);*/ + + far_z = llmin(light[count].mV[2]-light[count].mV[3], far_z); + //col[count] = pow4fsrgb(col[count], 2.2f); + count++; + if (count == max_count || fullscreen_lights.empty()) + { + gDeferredMultiLightProgram.uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT, count); + gDeferredMultiLightProgram.uniform4fv(LLShaderMgr::MULTI_LIGHT, count, (GLfloat*) light); + gDeferredMultiLightProgram.uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*) col); + gDeferredMultiLightProgram.uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z, far_z); + far_z = 0.f; + count = 0; + mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); + } + } + + unbindDeferredShader(gDeferredMultiLightProgram); + + bindDeferredShader(gDeferredMultiSpotLightProgram); + + gDeferredMultiSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION); + + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + + for (LLDrawable::drawable_list_t::iterator iter = fullscreen_spot_lights.begin(); iter != fullscreen_spot_lights.end(); ++iter) + { + LLFastTimer ftm(FTM_PROJECTORS); + LLDrawable* drawablep = *iter; + + LLVOVolume* volume = drawablep->getVOVolume(); + + LLVector3 center = drawablep->getPositionAgent(); + F32* c = center.mV; + F32 s = volume->getLightRadius()*1.5f; + + sVisibleLightCount++; + + glh::vec3f tc(c); + mat.mult_matrix_vec(tc); + + setupSpotLight(gDeferredMultiSpotLightProgram, drawablep); + + LLColor3 col = volume->getLightColor(); + + /*col.mV[0] = powf(col.mV[0], 2.2f); + col.mV[1] = powf(col.mV[1], 2.2f); + col.mV[2] = powf(col.mV[2], 2.2f);*/ + + gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v); + gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); + gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); + gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); + mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); + } + + gDeferredMultiSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION); + unbindDeferredShader(gDeferredMultiSpotLightProgram); + + gGL.popMatrix(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + gGL.popMatrix(); + } + } + + gGL.setColorMask(true, true); + } + + render_target->flush(); + + //gamma correct lighting + gGL.matrixMode(LLRender::MM_PROJECTION); + gGL.pushMatrix(); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + gGL.pushMatrix(); + gGL.loadIdentity(); + + { + LLGLDepthTest depth(GL_FALSE, GL_FALSE); + + LLVector2 tc1(0,0); + LLVector2 tc2((F32) render_target->getWidth()*2,(F32) render_target->getHeight()*2); + + render_target->bindTarget(); + // Apply gamma correction to the frame here. + gDeferredPostGammaCorrectProgram.bind(); + //mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + S32 channel = 0; + channel = gDeferredPostGammaCorrectProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, render_target->getUsage()); + if (channel > -1) + { + render_target->bindTexture(0,channel); + gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT); + } + + gDeferredPostGammaCorrectProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, mScreen.getWidth(), mScreen.getHeight()); + + F32 gamma = 1.0f/1.8f; + + gDeferredPostGammaCorrectProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, gamma); + + gGL.begin(LLRender::TRIANGLE_STRIP); + gGL.texCoord2f(tc1.mV[0], tc1.mV[1]); + gGL.vertex2f(-1,-1); + + gGL.texCoord2f(tc1.mV[0], tc2.mV[1]); + gGL.vertex2f(-1,3); + + gGL.texCoord2f(tc2.mV[0], tc1.mV[1]); + gGL.vertex2f(3,-1); + + gGL.end(); + + gGL.getTexUnit(channel)->unbind(render_target->getUsage()); + gDeferredPostGammaCorrectProgram.unbind(); + render_target->flush(); + } + + gGL.matrixMode(LLRender::MM_PROJECTION); + gGL.popMatrix(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + gGL.popMatrix(); + + render_target->bindTarget(); + + { //render non-deferred geometry (alpha, fullbright, glow) + LLGLDisable blend(GL_BLEND); + LLGLDisable stencil(GL_STENCIL_TEST); + + pushRenderTypeMask(); + andRenderTypeMask(LLPipeline::RENDER_TYPE_ALPHA, + LLPipeline::RENDER_TYPE_FULLBRIGHT, + LLPipeline::RENDER_TYPE_VOLUME, + LLPipeline::RENDER_TYPE_GLOW, + LLPipeline::RENDER_TYPE_BUMP, + LLPipeline::RENDER_TYPE_PASS_SIMPLE, + LLPipeline::RENDER_TYPE_PASS_ALPHA, + LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK, + LLPipeline::RENDER_TYPE_PASS_BUMP, + LLPipeline::RENDER_TYPE_PASS_POST_BUMP, + LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT, + LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK, + LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY, + LLPipeline::RENDER_TYPE_PASS_GLOW, + LLPipeline::RENDER_TYPE_PASS_GRASS, + LLPipeline::RENDER_TYPE_PASS_SHINY, + LLPipeline::RENDER_TYPE_PASS_INVISIBLE, + LLPipeline::RENDER_TYPE_PASS_INVISI_SHINY, + LLPipeline::RENDER_TYPE_AVATAR, + LLPipeline::RENDER_TYPE_ALPHA_MASK, + LLPipeline::RENDER_TYPE_FULLBRIGHT_ALPHA_MASK, + END_RENDER_TYPES); + + renderGeomPostDeferred(*LLViewerCamera::getInstance()); + popRenderTypeMask(); + } + + render_target->flush(); + +} + void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep) { //construct frustum @@ -9182,22 +9671,22 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) if (LLDrawPoolWater::sNeedsReflectionUpdate) { - //initial sky pass (no user clip plane) - { //mask out everything but the sky - gPipeline.pushRenderTypeMask(); - gPipeline.andRenderTypeMask(LLPipeline::RENDER_TYPE_SKY, - LLPipeline::RENDER_TYPE_WL_SKY, - LLPipeline::RENDER_TYPE_CLOUDS, - LLPipeline::END_RENDER_TYPES); + //initial sky pass (no user clip plane) + { //mask out everything but the sky + gPipeline.pushRenderTypeMask(); + gPipeline.andRenderTypeMask(LLPipeline::RENDER_TYPE_SKY, + LLPipeline::RENDER_TYPE_WL_SKY, + LLPipeline::RENDER_TYPE_CLOUDS, + LLPipeline::END_RENDER_TYPES); - static LLCullResult result; - updateCull(camera, result); - stateSort(camera, result); + static LLCullResult result; + updateCull(camera, result); + stateSort(camera, result); renderGeom(camera, TRUE); - + gPipeline.popRenderTypeMask(); - } + } gPipeline.pushRenderTypeMask(); @@ -9279,7 +9768,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) mWaterDis.bindTarget(); LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WATER1; mWaterDis.getViewport(gGLViewport); - + if (!LLPipeline::sUnderWaterRender || LLDrawPoolWater::sNeedsReflectionUpdate) { //clip out geometry on the same side of water as the camera @@ -9290,12 +9779,12 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) static LLCullResult result; updateCull(camera, result, water_clip, &plane); stateSort(camera, result); - + gGL.setColorMask(true, true); mWaterDis.clear(); gGL.setColorMask(true, false); - renderGeom(camera); + renderGeom(camera); } diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index 70dcf80407..a8ad16b8fb 100755 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -288,7 +288,8 @@ public: void unbindDeferredShader(LLGLSLShader& shader); void renderDeferredLighting(); - + void renderDeferredLightingToRenderTarget(LLRenderTarget* render_target); + void generateWaterReflection(LLCamera& camera); void generateSunShadow(LLCamera& camera); void generateHighlight(LLCamera& camera); -- cgit v1.2.3 From cb013b54c27257e25e429267fe0ea041a61bb6f8 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham)" Date: Tue, 9 Jul 2013 09:40:14 -0700 Subject: Remove failed renderDeferredLightingToRenderTarget experiment --- indra/newview/pipeline.cpp | 492 --------------------------------------------- indra/newview/pipeline.h | 2 +- 2 files changed, 1 insertion(+), 493 deletions(-) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index aed73be3c1..ace4417ee1 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8891,495 +8891,6 @@ void LLPipeline::renderDeferredLighting() } -void LLPipeline::renderDeferredLightingToRenderTarget(LLRenderTarget* render_target) -{ - if (!sCull) - { - return; - } - - { - LLFastTimer ftm(FTM_RENDER_DEFERRED); - - LLViewerCamera* camera = LLViewerCamera::getInstance(); - { - LLGLDepthTest depth(GL_TRUE); - mDeferredDepth.copyContents(mDeferredScreen, 0, 0, mDeferredScreen.getWidth(), mDeferredScreen.getHeight(), - 0, 0, mDeferredDepth.getWidth(), mDeferredDepth.getHeight(), GL_DEPTH_BUFFER_BIT, GL_NEAREST); - } - - LLGLEnable multisample(0); - - if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD)) - { - gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD); - } - - //ati doesn't seem to love actually using the stencil buffer on FBO's - LLGLDisable stencil(GL_STENCIL_TEST); - //glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF); - //glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - - gGL.setColorMask(true, true); - - //draw a cube around every light - LLVertexBuffer::unbind(); - - LLGLEnable cull(GL_CULL_FACE); - LLGLEnable blend(GL_BLEND); - - glh::matrix4f mat = glh_copy_matrix(gGLModelView); - - LLStrider vert; - mDeferredVB->getVertexStrider(vert); - - vert[0].set(-1,1,0); - vert[1].set(-1,-3,0); - vert[2].set(3,1,0); - - { - setupHWLights(NULL); //to set mSunDir; - LLVector4 dir(mSunDir, 0.f); - glh::vec4f tc(dir.mV); - mat.mult_matrix_vec(tc); - mTransformedSunDir.set(tc.v); - } - - gGL.pushMatrix(); - gGL.loadIdentity(); - gGL.matrixMode(LLRender::MM_PROJECTION); - gGL.pushMatrix(); - gGL.loadIdentity(); - - stop_glerror(); - gGL.popMatrix(); - stop_glerror(); - gGL.matrixMode(LLRender::MM_MODELVIEW); - stop_glerror(); - gGL.popMatrix(); - stop_glerror(); - - render_target = render_target ? render_target : &mScreen; - - llassert(render_target); - - render_target->bindTarget(); - - // clear color buffer here - zeroing alpha (glow) is important or it will accumulate against sky - glClearColor(0,0,0,0); - render_target->clear(GL_COLOR_BUFFER_BIT); - - if (RenderDeferredAtmospheric) - { //apply sunlight contribution - LLFastTimer ftm(FTM_ATMOSPHERICS); - bindDeferredShader(gDeferredSoftenProgram); - { - LLGLDepthTest depth(GL_FALSE); - LLGLDisable blend(GL_BLEND); - LLGLDisable test(GL_ALPHA_TEST); - - //full screen blit - gGL.pushMatrix(); - gGL.loadIdentity(); - gGL.matrixMode(LLRender::MM_PROJECTION); - gGL.pushMatrix(); - gGL.loadIdentity(); - - mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); - - mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); - - gGL.popMatrix(); - gGL.matrixMode(LLRender::MM_MODELVIEW); - gGL.popMatrix(); - } - - unbindDeferredShader(gDeferredSoftenProgram); - } - - { //render non-deferred geometry (fullbright, alpha, etc) - LLGLDisable blend(GL_BLEND); - LLGLDisable stencil(GL_STENCIL_TEST); - gGL.setSceneBlendType(LLRender::BT_ALPHA); - - gPipeline.pushRenderTypeMask(); - - gPipeline.andRenderTypeMask(LLPipeline::RENDER_TYPE_SKY, - LLPipeline::RENDER_TYPE_CLOUDS, - LLPipeline::RENDER_TYPE_WL_SKY, - LLPipeline::END_RENDER_TYPES); - - - renderGeomPostDeferred(*LLViewerCamera::getInstance(), false); - gPipeline.popRenderTypeMask(); - } - - BOOL render_local = RenderLocalLights; - - if (render_local) - { - gGL.setSceneBlendType(LLRender::BT_ADD); - std::list fullscreen_lights; - LLDrawable::drawable_list_t spot_lights; - LLDrawable::drawable_list_t fullscreen_spot_lights; - - for (U32 i = 0; i < 2; i++) - { - mTargetShadowSpotLight[i] = NULL; - } - - std::list light_colors; - - LLVertexBuffer::unbind(); - - { - bindDeferredShader(gDeferredLightProgram); - - if (mCubeVB.isNull()) - { - mCubeVB = ll_create_cube_vb(LLVertexBuffer::MAP_VERTEX, GL_STATIC_DRAW_ARB); - } - - mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX); - - LLGLDepthTest depth(GL_TRUE, GL_FALSE); - for (LLDrawable::drawable_set_t::iterator iter = mLights.begin(); iter != mLights.end(); ++iter) - { - LLDrawable* drawablep = *iter; - - LLVOVolume* volume = drawablep->getVOVolume(); - if (!volume) - { - continue; - } - - if (volume->isAttachment()) - { - if (!sRenderAttachedLights) - { - continue; - } - } - - - LLVector4a center; - center.load3(drawablep->getPositionAgent().mV); - const F32* c = center.getF32ptr(); - F32 s = volume->getLightRadius()*1.5f; - - LLColor3 col = volume->getLightColor(); - - if (col.magVecSquared() < 0.001f) - { - continue; - } - - if (s <= 0.001f) - { - continue; - } - - LLVector4a sa; - sa.splat(s); - if (camera->AABBInFrustumNoFarClip(center, sa) == 0) - { - continue; - } - - sVisibleLightCount++; - - if (camera->getOrigin().mV[0] > c[0] + s + 0.2f || - camera->getOrigin().mV[0] < c[0] - s - 0.2f || - camera->getOrigin().mV[1] > c[1] + s + 0.2f || - camera->getOrigin().mV[1] < c[1] - s - 0.2f || - camera->getOrigin().mV[2] > c[2] + s + 0.2f || - camera->getOrigin().mV[2] < c[2] - s - 0.2f) - { //draw box if camera is outside box - if (render_local) - { - if (volume->isLightSpotlight()) - { - drawablep->getVOVolume()->updateSpotLightPriority(); - spot_lights.push_back(drawablep); - continue; - } - - /*col.mV[0] = powf(col.mV[0], 2.2f); - col.mV[1] = powf(col.mV[1], 2.2f); - col.mV[2] = powf(col.mV[2], 2.2f);*/ - - LLFastTimer ftm(FTM_LOCAL_LIGHTS); - gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c); - gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); - gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); - gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); - gGL.syncMatrices(); - - mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center)); - stop_glerror(); - } - } - else - { - if (volume->isLightSpotlight()) - { - drawablep->getVOVolume()->updateSpotLightPriority(); - fullscreen_spot_lights.push_back(drawablep); - continue; - } - - glh::vec3f tc(c); - mat.mult_matrix_vec(tc); - - fullscreen_lights.push_back(LLVector4(tc.v[0], tc.v[1], tc.v[2], s)); - light_colors.push_back(LLVector4(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff()*0.5f)); - } - } - unbindDeferredShader(gDeferredLightProgram); - } - - if (!spot_lights.empty()) - { - LLGLDepthTest depth(GL_TRUE, GL_FALSE); - bindDeferredShader(gDeferredSpotLightProgram); - - mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX); - - gDeferredSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION); - - for (LLDrawable::drawable_list_t::iterator iter = spot_lights.begin(); iter != spot_lights.end(); ++iter) - { - LLFastTimer ftm(FTM_PROJECTORS); - LLDrawable* drawablep = *iter; - - LLVOVolume* volume = drawablep->getVOVolume(); - - LLVector4a center; - center.load3(drawablep->getPositionAgent().mV); - const F32* c = center.getF32ptr(); - F32 s = volume->getLightRadius()*1.5f; - - sVisibleLightCount++; - - setupSpotLight(gDeferredSpotLightProgram, drawablep); - - LLColor3 col = volume->getLightColor(); - /*col.mV[0] = powf(col.mV[0], 2.2f); - col.mV[1] = powf(col.mV[1], 2.2f); - col.mV[2] = powf(col.mV[2], 2.2f);*/ - - gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c); - gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); - gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); - gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); - gGL.syncMatrices(); - - mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center)); - } - gDeferredSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION); - unbindDeferredShader(gDeferredSpotLightProgram); - } - - //reset mDeferredVB to fullscreen triangle - mDeferredVB->getVertexStrider(vert); - vert[0].set(-1,1,0); - vert[1].set(-1,-3,0); - vert[2].set(3,1,0); - - { - bindDeferredShader(gDeferredMultiLightProgram); - - mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); - - LLGLDepthTest depth(GL_FALSE); - - //full screen blit - gGL.pushMatrix(); - gGL.loadIdentity(); - gGL.matrixMode(LLRender::MM_PROJECTION); - gGL.pushMatrix(); - gGL.loadIdentity(); - - U32 count = 0; - - const U32 max_count = 8; - LLVector4 light[max_count]; - LLVector4 col[max_count]; - - F32 far_z = 0.f; - - while (!fullscreen_lights.empty()) - { - LLFastTimer ftm(FTM_FULLSCREEN_LIGHTS); - light[count] = fullscreen_lights.front(); - fullscreen_lights.pop_front(); - col[count] = light_colors.front(); - light_colors.pop_front(); - - /*col[count].mV[0] = powf(col[count].mV[0], 2.2f); - col[count].mV[1] = powf(col[count].mV[1], 2.2f); - col[count].mV[2] = powf(col[count].mV[2], 2.2f);*/ - - far_z = llmin(light[count].mV[2]-light[count].mV[3], far_z); - //col[count] = pow4fsrgb(col[count], 2.2f); - count++; - if (count == max_count || fullscreen_lights.empty()) - { - gDeferredMultiLightProgram.uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT, count); - gDeferredMultiLightProgram.uniform4fv(LLShaderMgr::MULTI_LIGHT, count, (GLfloat*) light); - gDeferredMultiLightProgram.uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*) col); - gDeferredMultiLightProgram.uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z, far_z); - far_z = 0.f; - count = 0; - mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); - } - } - - unbindDeferredShader(gDeferredMultiLightProgram); - - bindDeferredShader(gDeferredMultiSpotLightProgram); - - gDeferredMultiSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION); - - mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); - - for (LLDrawable::drawable_list_t::iterator iter = fullscreen_spot_lights.begin(); iter != fullscreen_spot_lights.end(); ++iter) - { - LLFastTimer ftm(FTM_PROJECTORS); - LLDrawable* drawablep = *iter; - - LLVOVolume* volume = drawablep->getVOVolume(); - - LLVector3 center = drawablep->getPositionAgent(); - F32* c = center.mV; - F32 s = volume->getLightRadius()*1.5f; - - sVisibleLightCount++; - - glh::vec3f tc(c); - mat.mult_matrix_vec(tc); - - setupSpotLight(gDeferredMultiSpotLightProgram, drawablep); - - LLColor3 col = volume->getLightColor(); - - /*col.mV[0] = powf(col.mV[0], 2.2f); - col.mV[1] = powf(col.mV[1], 2.2f); - col.mV[2] = powf(col.mV[2], 2.2f);*/ - - gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v); - gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); - gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); - gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); - mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); - } - - gDeferredMultiSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION); - unbindDeferredShader(gDeferredMultiSpotLightProgram); - - gGL.popMatrix(); - gGL.matrixMode(LLRender::MM_MODELVIEW); - gGL.popMatrix(); - } - } - - gGL.setColorMask(true, true); - } - - render_target->flush(); - - //gamma correct lighting - gGL.matrixMode(LLRender::MM_PROJECTION); - gGL.pushMatrix(); - gGL.loadIdentity(); - gGL.matrixMode(LLRender::MM_MODELVIEW); - gGL.pushMatrix(); - gGL.loadIdentity(); - - { - LLGLDepthTest depth(GL_FALSE, GL_FALSE); - - LLVector2 tc1(0,0); - LLVector2 tc2((F32) render_target->getWidth()*2,(F32) render_target->getHeight()*2); - - render_target->bindTarget(); - // Apply gamma correction to the frame here. - gDeferredPostGammaCorrectProgram.bind(); - //mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); - S32 channel = 0; - channel = gDeferredPostGammaCorrectProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, render_target->getUsage()); - if (channel > -1) - { - render_target->bindTexture(0,channel); - gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT); - } - - gDeferredPostGammaCorrectProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, mScreen.getWidth(), mScreen.getHeight()); - - F32 gamma = 1.0f/1.8f; - - gDeferredPostGammaCorrectProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, gamma); - - gGL.begin(LLRender::TRIANGLE_STRIP); - gGL.texCoord2f(tc1.mV[0], tc1.mV[1]); - gGL.vertex2f(-1,-1); - - gGL.texCoord2f(tc1.mV[0], tc2.mV[1]); - gGL.vertex2f(-1,3); - - gGL.texCoord2f(tc2.mV[0], tc1.mV[1]); - gGL.vertex2f(3,-1); - - gGL.end(); - - gGL.getTexUnit(channel)->unbind(render_target->getUsage()); - gDeferredPostGammaCorrectProgram.unbind(); - render_target->flush(); - } - - gGL.matrixMode(LLRender::MM_PROJECTION); - gGL.popMatrix(); - gGL.matrixMode(LLRender::MM_MODELVIEW); - gGL.popMatrix(); - - render_target->bindTarget(); - - { //render non-deferred geometry (alpha, fullbright, glow) - LLGLDisable blend(GL_BLEND); - LLGLDisable stencil(GL_STENCIL_TEST); - - pushRenderTypeMask(); - andRenderTypeMask(LLPipeline::RENDER_TYPE_ALPHA, - LLPipeline::RENDER_TYPE_FULLBRIGHT, - LLPipeline::RENDER_TYPE_VOLUME, - LLPipeline::RENDER_TYPE_GLOW, - LLPipeline::RENDER_TYPE_BUMP, - LLPipeline::RENDER_TYPE_PASS_SIMPLE, - LLPipeline::RENDER_TYPE_PASS_ALPHA, - LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK, - LLPipeline::RENDER_TYPE_PASS_BUMP, - LLPipeline::RENDER_TYPE_PASS_POST_BUMP, - LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT, - LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK, - LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY, - LLPipeline::RENDER_TYPE_PASS_GLOW, - LLPipeline::RENDER_TYPE_PASS_GRASS, - LLPipeline::RENDER_TYPE_PASS_SHINY, - LLPipeline::RENDER_TYPE_PASS_INVISIBLE, - LLPipeline::RENDER_TYPE_PASS_INVISI_SHINY, - LLPipeline::RENDER_TYPE_AVATAR, - LLPipeline::RENDER_TYPE_ALPHA_MASK, - LLPipeline::RENDER_TYPE_FULLBRIGHT_ALPHA_MASK, - END_RENDER_TYPES); - - renderGeomPostDeferred(*LLViewerCamera::getInstance()); - popRenderTypeMask(); - } - - render_target->flush(); - -} - void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep) { //construct frustum @@ -11653,6 +11164,3 @@ void LLPipeline::restoreHiddenObject( const LLUUID& id ) } } - - - diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index a8ad16b8fb..2f0fc3491d 100755 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -288,7 +288,6 @@ public: void unbindDeferredShader(LLGLSLShader& shader); void renderDeferredLighting(); - void renderDeferredLightingToRenderTarget(LLRenderTarget* render_target); void generateWaterReflection(LLCamera& camera); void generateSunShadow(LLCamera& camera); @@ -955,3 +954,4 @@ extern BOOL gDebugPipeline; extern const LLMatrix4* gGLLastMatrix; #endif + -- cgit v1.2.3 From 326e20b0e5cd8e30d4b52c662a29aa2fc816b40d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 10 Jul 2013 09:47:46 -0700 Subject: NORSPEC-291 WIP materials underwater w and wo alpha, water fog color broken, no refl, no water dis --- .../shaders/class1/deferred/materialF.glsl | 86 ++++++++++++++++--- .../shaders/class1/deferred/materialV.glsl | 9 +- .../shaders/class1/deferred/softenLightF.glsl | 54 +++++++++++- indra/newview/lldrawpoolavatar.cpp | 18 +++- indra/newview/lldrawpoolmaterials.cpp | 10 ++- indra/newview/lldrawpoolsky.cpp | 2 +- indra/newview/lldrawpoolwater.cpp | 8 +- indra/newview/lldrawpoolwlsky.cpp | 4 +- indra/newview/llviewerdisplay.cpp | 10 ++- indra/newview/llviewershadermgr.cpp | 97 +++++++++++++++++++++- indra/newview/llviewershadermgr.h | 3 + indra/newview/pipeline.cpp | 34 +++++--- 12 files changed, 293 insertions(+), 42 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 027c6eeadb..393074344b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -51,7 +51,6 @@ vec3 linear_to_srgb(vec3 cl) return 1.055 * pow(cl, vec3(0.41666)) - 0.055; } - #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #ifdef DEFINE_GL_FRAGCOLOR @@ -136,6 +135,57 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +#ifdef WATER_FOG +vec3 getPositionEye() +{ + return vary_PositionEye; +} + +uniform vec4 waterPlane; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; + +vec4 applyWaterFogDeferred(vec4 color) +{ + //normalize view vector + vec3 view = normalize(getPositionEye()); + float es = -(dot(view, waterPlane.xyz)); + + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); + + //get object depth + float depth = length(getPositionEye() - int_v); + + //get "thickness" of water + float l = max(depth, 0.1); + + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2*l) - 1.0; + + float L = min(t1/t2*t3, 1.0); + + float D = pow(0.98, l*kd); + + color.rgb = color.rgb * D + kc.rgb * L; + color.a = kc.a + color.a; + + return color; +} +#endif + vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); @@ -221,10 +271,6 @@ vec4 getPosition_d(vec2 pos_screen, float depth) return pos; } -vec3 getPositionEye() -{ - return vary_PositionEye; -} vec3 getSunlitColor() { return vary_SunlitColor; @@ -417,6 +463,21 @@ out vec4 frag_data[3]; #else #define frag_data gl_FragData #endif + +VARYING vec3 vary_position; + +#ifdef WATER_FOG +vec3 vary_PositionEye; +vec3 getPositionEye() +{ + return vary_PositionEye; +} +void setPositionEye(vec3 e) +{ + vary_PositionEye = e; +} +#endif + #endif uniform sampler2D diffuseMap; @@ -672,7 +733,6 @@ void main() //convert to linear space before adding local lights col = srgb_to_linear(col); - vec3 npos = normalize(-pos.xyz); #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); @@ -685,17 +745,19 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) + glare = min(glare, 1.0); + float al = max(diffcol.a,glare)*vertex_color.a; - //convert to gamma space for display on screen - col.rgb = linear_to_srgb(col.rgb); - +#ifdef WATER_FOG + frag_color = applyWaterFogDeferred(vec4(col.rgb, al)); +#else frag_color.rgb = col.rgb; - glare = min(glare, 1.0); - frag_color.a = max(diffcol.a,glare)*vertex_color.a; + frag_color.a = al; +#endif #else frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. -#endif +#endif% } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index b25032866b..154db09583 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -43,10 +43,10 @@ uniform mat4 modelview_projection_matrix; uniform mat4 modelview_matrix; #endif -VARYING vec3 vary_position; - #endif +VARYING vec3 vary_position; + uniform mat4 texture_matrix0; ATTRIBUTE vec3 position; @@ -84,15 +84,14 @@ void main() mat = modelview_matrix * mat; vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vary_position = pos; -#endif + gl_Position = projection_matrix*vec4(pos,1.0); #else //transform vertex + vary_position = (modelview_projection_matrix * vec4(position.xyz, 1.0)).xyz; gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index dc2519bd0a..1706d41da0 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -175,6 +175,53 @@ void setAtmosAttenuation(vec3 v) vary_AtmosAttenuation = v; } + +#ifdef WATER_FOG +uniform vec4 waterPlane; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; + +vec4 applyWaterFogDeferred(vec4 color) +{ + //normalize view vector + vec3 view = normalize(getPositionEye()); + float es = -(dot(view, waterPlane.xyz)); + + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); + + //get object depth + float depth = length(getPositionEye() - int_v); + + //get "thickness" of water + float l = max(depth, 0.1); + + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2*l) - 1.0; + + float L = min(t1/t2*t3, 1.0); + + float D = pow(0.98, l*kd); + + color.rgb = color.rgb * D + kc.rgb * L; + color.a = kc.a + color.a; + + return color; +} +#endif + void calcAtmospherics(vec3 inPositionEye, float ambFactor) { vec3 P = inPositionEye; @@ -389,6 +436,12 @@ void main() { col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + + #ifdef WATER_FOG + vec4 fogged = applyWaterFogDeferred(vec4(col, bloom)); + col = fogged.rgb; + bloom = fogged.a; + #endif } col = srgb_to_linear(col); @@ -398,6 +451,5 @@ void main() } frag_color.rgb = col; - frag_color.a = bloom; } diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index 075299386e..45abb87bad 100755 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -297,7 +297,14 @@ void LLDrawPoolAvatar::beginDeferredRiggedMaterialAlpha(S32 pass) pass += LLMaterial::SHADER_COUNT; - sVertexProgram = &gDeferredMaterialProgram[pass]; + if (LLPipeline::sUnderWaterRender) + { + sVertexProgram = &(gDeferredMaterialWaterProgram[pass]); + } + else + { + sVertexProgram = &(gDeferredMaterialProgram[pass]); + } gPipeline.bindDeferredShader(*sVertexProgram); sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); @@ -1092,7 +1099,14 @@ void LLDrawPoolAvatar::beginDeferredRiggedMaterial(S32 pass) { //skip alpha passes return; } - sVertexProgram = &gDeferredMaterialProgram[pass+LLMaterial::SHADER_COUNT]; + if (LLPipeline::sUnderWaterRender) + { + sVertexProgram = &gDeferredMaterialWaterProgram[pass+LLMaterial::SHADER_COUNT]; + } + else + { + sVertexProgram = &gDeferredMaterialProgram[pass+LLMaterial::SHADER_COUNT]; + } sVertexProgram->bind(); normal_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::BUMP_MAP); specular_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::SPECULAR_MAP); diff --git a/indra/newview/lldrawpoolmaterials.cpp b/indra/newview/lldrawpoolmaterials.cpp index 08a36bddf1..49619e6b1d 100644 --- a/indra/newview/lldrawpoolmaterials.cpp +++ b/indra/newview/lldrawpoolmaterials.cpp @@ -71,7 +71,15 @@ void LLDrawPoolMaterials::beginDeferredPass(S32 pass) 15, //LLRenderPass::PASS_NORMSPEC_GLOW, }; - mShader = &(gDeferredMaterialProgram[shader_idx[pass]]); + if (LLPipeline::sUnderWaterRender) + { + mShader = &(gDeferredMaterialWaterProgram[shader_idx[pass]]); + } + else + { + mShader = &(gDeferredMaterialProgram[shader_idx[pass]]); + } + mShader->bind(); diffuse_channel = mShader->enableTexture(LLShaderMgr::DIFFUSE_MAP); diff --git a/indra/newview/lldrawpoolsky.cpp b/indra/newview/lldrawpoolsky.cpp index 7f7d9f65c6..d36b9ace94 100755 --- a/indra/newview/lldrawpoolsky.cpp +++ b/indra/newview/lldrawpoolsky.cpp @@ -77,7 +77,7 @@ void LLDrawPoolSky::render(S32 pass) } // don't render sky under water (background just gets cleared to fog color) - if(mVertexShaderLevel > 0 && LLPipeline::sUnderWaterRender) + if(mVertexShaderLevel > 0 /*&& !LLPipeline::sRenderDeferred*/ && LLPipeline::sUnderWaterRender) { return; } diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp index 5ddc15df42..5b0b173926 100755 --- a/indra/newview/lldrawpoolwater.cpp +++ b/indra/newview/lldrawpoolwater.cpp @@ -522,13 +522,13 @@ void LLDrawPoolWater::shade() F32 eyedepth = LLViewerCamera::getInstance()->getOrigin().mV[2] - gAgent.getRegion()->getWaterHeight(); - if (deferred_render) + if (eyedepth < 0.f && LLPipeline::sWaterReflections) { - shader = &gDeferredWaterProgram; + shader = &gUnderWaterProgram; } - else if (eyedepth < 0.f && LLPipeline::sWaterReflections) + else if (deferred_render) { - shader = &gUnderWaterProgram; + shader = &gDeferredWaterProgram; } else { diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp index b5faff7968..56b58aaeb4 100755 --- a/indra/newview/lldrawpoolwlsky.cpp +++ b/indra/newview/lldrawpoolwlsky.cpp @@ -99,12 +99,12 @@ LLViewerTexture *LLDrawPoolWLSky::getDebugTexture() void LLDrawPoolWLSky::beginRenderPass( S32 pass ) { sky_shader = - LLPipeline::sUnderWaterRender ? + (LLPipeline::sUnderWaterRender /*&& !LLPipeline::sRenderDeferred*/) ? &gObjectFullbrightNoColorWaterProgram : &gWLSkyProgram; cloud_shader = - LLPipeline::sUnderWaterRender ? + (LLPipeline::sUnderWaterRender /*&& !LLPipeline::sRenderDeferred*/) ? &gObjectFullbrightNoColorWaterProgram : &gWLCloudProgram; } diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp index e6718ca618..d9fd171b4e 100755 --- a/indra/newview/llviewerdisplay.cpp +++ b/indra/newview/llviewerdisplay.cpp @@ -893,7 +893,15 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot) if (LLPipeline::sRenderDeferred) { gPipeline.mDeferredScreen.bindTarget(); - glClearColor(1,0,1,1); + if (LLPipeline::sUnderWaterRender) + { + const LLColor4 &col = LLDrawPoolWater::sWaterFogColor; + glClearColor(col.mV[0], col.mV[1], col.mV[2], 0.f); + } + else + { + glClearColor(1,0,1,1); + } gPipeline.mDeferredScreen.clear(); } else diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 6d9a0dd261..88593346c0 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -168,6 +168,7 @@ LLGLSLShader gPostNightVisionProgram; // Deferred rendering shaders LLGLSLShader gDeferredImpostorProgram; LLGLSLShader gDeferredWaterProgram; +LLGLSLShader gDeferredUnderWaterProgram; LLGLSLShader gDeferredDiffuseProgram; LLGLSLShader gDeferredDiffuseAlphaMaskProgram; LLGLSLShader gDeferredNonIndexedDiffuseProgram; @@ -189,6 +190,7 @@ LLGLSLShader gDeferredMultiSpotLightProgram; LLGLSLShader gDeferredSunProgram; LLGLSLShader gDeferredBlurLightProgram; LLGLSLShader gDeferredSoftenProgram; +LLGLSLShader gDeferredSoftenWaterProgram; LLGLSLShader gDeferredShadowProgram; LLGLSLShader gDeferredShadowCubeProgram; LLGLSLShader gDeferredShadowAlphaMaskProgram; @@ -215,6 +217,7 @@ LLGLSLShader gNormalMapGenProgram; // Deferred materials shaders LLGLSLShader gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2]; +LLGLSLShader gDeferredMaterialWaterProgram[LLMaterial::SHADER_COUNT*2]; LLViewerShaderMgr::LLViewerShaderMgr() : mVertexShaderLevel(SHADER_COUNT, 0), @@ -280,14 +283,23 @@ LLViewerShaderMgr::LLViewerShaderMgr() : mShaderList.push_back(&gUnderWaterProgram); mShaderList.push_back(&gDeferredSunProgram); mShaderList.push_back(&gDeferredSoftenProgram); + mShaderList.push_back(&gDeferredSoftenWaterProgram); mShaderList.push_back(&gDeferredMaterialProgram[1]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[1]); mShaderList.push_back(&gDeferredMaterialProgram[5]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[5]); mShaderList.push_back(&gDeferredMaterialProgram[9]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[9]); mShaderList.push_back(&gDeferredMaterialProgram[13]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[13]); mShaderList.push_back(&gDeferredMaterialProgram[1+LLMaterial::SHADER_COUNT]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[1+LLMaterial::SHADER_COUNT]); mShaderList.push_back(&gDeferredMaterialProgram[5+LLMaterial::SHADER_COUNT]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[5+LLMaterial::SHADER_COUNT]); mShaderList.push_back(&gDeferredMaterialProgram[9+LLMaterial::SHADER_COUNT]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[9+LLMaterial::SHADER_COUNT]); mShaderList.push_back(&gDeferredMaterialProgram[13+LLMaterial::SHADER_COUNT]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[13+LLMaterial::SHADER_COUNT]); mShaderList.push_back(&gDeferredAlphaProgram); mShaderList.push_back(&gDeferredSkinnedAlphaProgram); mShaderList.push_back(&gDeferredFullbrightProgram); @@ -1123,6 +1135,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSunProgram.unload(); gDeferredBlurLightProgram.unload(); gDeferredSoftenProgram.unload(); + gDeferredSoftenWaterProgram.unload(); gDeferredShadowProgram.unload(); gDeferredShadowCubeProgram.unload(); gDeferredShadowAlphaMaskProgram.unload(); @@ -1141,6 +1154,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredPostGammaCorrectProgram.unload(); gFXAAProgram.unload(); gDeferredWaterProgram.unload(); + gDeferredUnderWaterProgram.unload(); gDeferredWLSkyProgram.unload(); gDeferredWLCloudProgram.unload(); gDeferredStarProgram.unload(); @@ -1152,6 +1166,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() for (U32 i = 0; i < LLMaterial::SHADER_COUNT*2; ++i) { gDeferredMaterialProgram[i].unload(); + gDeferredMaterialWaterProgram[i].unload(); } return TRUE; } @@ -1279,6 +1294,15 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredMaterialProgram[9+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false; gDeferredMaterialProgram[13+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false; + gDeferredMaterialWaterProgram[1].mFeatures.hasLighting = false; + gDeferredMaterialWaterProgram[5].mFeatures.hasLighting = false; + gDeferredMaterialWaterProgram[9].mFeatures.hasLighting = false; + gDeferredMaterialWaterProgram[13].mFeatures.hasLighting = false; + gDeferredMaterialWaterProgram[1+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false; + gDeferredMaterialWaterProgram[5+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false; + gDeferredMaterialWaterProgram[9+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false; + gDeferredMaterialWaterProgram[13+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false; + for (U32 i = 0; i < LLMaterial::SHADER_COUNT*2; ++i) { if (success) @@ -1305,6 +1329,35 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() success = gDeferredMaterialProgram[i].createShader(NULL, NULL); } + + if (success) + { + gDeferredMaterialProgram[i].mName = llformat("Deferred Material Shader %d", i); + + U32 alpha_mode = i & 0x3; + + gDeferredMaterialWaterProgram[i].mShaderFiles.clear(); + gDeferredMaterialWaterProgram[i].mShaderFiles.push_back(make_pair("deferred/materialV.glsl", GL_VERTEX_SHADER_ARB)); + gDeferredMaterialWaterProgram[i].mShaderFiles.push_back(make_pair("deferred/materialF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredMaterialWaterProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + gDeferredMaterialWaterProgram[i].addPermutation("HAS_NORMAL_MAP", i & 0x8? "1" : "0"); + gDeferredMaterialWaterProgram[i].addPermutation("HAS_SPECULAR_MAP", i & 0x4 ? "1" : "0"); + gDeferredMaterialWaterProgram[i].addPermutation("DIFFUSE_ALPHA_MODE", llformat("%d", alpha_mode)); + gDeferredMaterialWaterProgram[i].addPermutation("HAS_SUN_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); + bool has_skin = i & 0x10; + gDeferredMaterialWaterProgram[i].addPermutation("HAS_SKIN",has_skin ? "1" : "0"); + + gDeferredMaterialWaterProgram[i].addPermutation("WATER_FOG","1"); + gDeferredMaterialWaterProgram[i].mFeatures.hasWaterFog = true; + gDeferredMaterialWaterProgram[i].mShaderGroup = SHADER_WATER; + + if (has_skin) + { + gDeferredMaterialWaterProgram[i].mFeatures.hasObjectSkinning = true; + } + + success = gDeferredMaterialWaterProgram[i].createShader(NULL, NULL); + } } gDeferredMaterialProgram[1].mFeatures.hasLighting = true; @@ -1316,7 +1369,14 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredMaterialProgram[9+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true; gDeferredMaterialProgram[13+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true; - + gDeferredMaterialWaterProgram[1].mFeatures.hasLighting = true; + gDeferredMaterialWaterProgram[5].mFeatures.hasLighting = true; + gDeferredMaterialWaterProgram[9].mFeatures.hasLighting = true; + gDeferredMaterialWaterProgram[13].mFeatures.hasLighting = true; + gDeferredMaterialWaterProgram[1+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true; + gDeferredMaterialWaterProgram[5+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true; + gDeferredMaterialWaterProgram[9+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true; + gDeferredMaterialWaterProgram[13+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true; if (success) { @@ -1582,6 +1642,21 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() success = gDeferredWaterProgram.createShader(NULL, &mWaterUniforms); } + if (success) + { + // load water shader + /*gDeferredUnderWaterProgram.mName = "Deferred Under Water Shader"; + gDeferredUnderWaterProgram.mFeatures.calculatesAtmospherics = true; + gDeferredUnderWaterProgram.mFeatures.hasGamma = true; + gDeferredUnderWaterProgram.mShaderFiles.clear(); + gDeferredUnderWaterProgram.mShaderFiles.push_back(make_pair("deferred/waterV.glsl", GL_VERTEX_SHADER_ARB)); + gDeferredUnderWaterProgram.mShaderFiles.push_back(make_pair("deferred/underWaterF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredUnderWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_WATER]; + gDeferredUnderWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; + + success = gDeferredUnderWaterProgram.createShader(NULL, &mWaterUniforms);*/ + } + if (success) { gDeferredSoftenProgram.mName = "Deferred Soften Shader"; @@ -1599,6 +1674,26 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() success = gDeferredSoftenProgram.createShader(NULL, NULL); } + if (success) + { + gDeferredSoftenWaterProgram.mName = "Deferred Soften Underwater Shader"; + gDeferredSoftenWaterProgram.mFeatures.hasWaterFog = true; + gDeferredSoftenWaterProgram.mShaderFiles.clear(); + gDeferredSoftenWaterProgram.mShaderFiles.push_back(make_pair("deferred/softenLightV.glsl", GL_VERTEX_SHADER_ARB)); + gDeferredSoftenWaterProgram.mShaderFiles.push_back(make_pair("deferred/softenLightF.glsl", GL_FRAGMENT_SHADER_ARB)); + + gDeferredSoftenWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + gDeferredSoftenWaterProgram.addPermutation("WATER_FOG", "1"); + gDeferredSoftenWaterProgram.mShaderGroup = SHADER_WATER; + + if (gSavedSettings.getBOOL("RenderDeferredSSAO")) + { //if using SSAO, take screen space light map into account as if shadows are enabled + gDeferredSoftenWaterProgram.mShaderLevel = llmax(gDeferredSoftenWaterProgram.mShaderLevel, 2); + } + + success = gDeferredSoftenWaterProgram.createShader(NULL, NULL); + } + if (success) { gDeferredShadowProgram.mName = "Deferred Shadow Shader"; diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h index f3a419b1f2..34a0f6b89d 100755 --- a/indra/newview/llviewershadermgr.h +++ b/indra/newview/llviewershadermgr.h @@ -330,6 +330,7 @@ extern LLGLSLShader gPostNightVisionProgram; // Deferred rendering shaders extern LLGLSLShader gDeferredImpostorProgram; extern LLGLSLShader gDeferredWaterProgram; +extern LLGLSLShader gDeferredUnderWaterProgram; extern LLGLSLShader gDeferredDiffuseProgram; extern LLGLSLShader gDeferredDiffuseAlphaMaskProgram; extern LLGLSLShader gDeferredNonIndexedDiffuseAlphaMaskProgram; @@ -350,6 +351,7 @@ extern LLGLSLShader gDeferredSunProgram; extern LLGLSLShader gDeferredBlurLightProgram; extern LLGLSLShader gDeferredAvatarProgram; extern LLGLSLShader gDeferredSoftenProgram; +extern LLGLSLShader gDeferredSoftenWaterProgram; extern LLGLSLShader gDeferredShadowProgram; extern LLGLSLShader gDeferredShadowCubeProgram; extern LLGLSLShader gDeferredShadowAlphaMaskProgram; @@ -377,5 +379,6 @@ extern LLGLSLShader gNormalMapGenProgram; // Deferred materials shaders extern LLGLSLShader gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2]; +extern LLGLSLShader gDeferredMaterialWaterProgram[LLMaterial::SHADER_COUNT*2]; #endif diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index aed73be3c1..e9fb94239e 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8466,7 +8466,7 @@ void LLPipeline::renderDeferredLighting() if (RenderDeferredAtmospheric) { //apply sunlight contribution LLFastTimer ftm(FTM_ATMOSPHERICS); - bindDeferredShader(gDeferredSoftenProgram); + bindDeferredShader(LLPipeline::sUnderWaterRender ? gDeferredSoftenWaterProgram : gDeferredSoftenProgram); { LLGLDepthTest depth(GL_FALSE); LLGLDisable blend(GL_BLEND); @@ -8488,7 +8488,7 @@ void LLPipeline::renderDeferredLighting() gGL.popMatrix(); } - unbindDeferredShader(gDeferredSoftenProgram); + unbindDeferredShader(LLPipeline::sUnderWaterRender ? gDeferredSoftenWaterProgram : gDeferredSoftenProgram); } { //render non-deferred geometry (fullbright, alpha, etc) @@ -8725,9 +8725,11 @@ void LLPipeline::renderDeferredLighting() count = 0; mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); +// seems like this should be done here... + //unbindDeferredShader(gDeferredMultiLightProgram[idx]); } } - + unbindDeferredShader(gDeferredMultiLightProgram[0]); bindDeferredShader(gDeferredMultiSpotLightProgram); @@ -8972,7 +8974,7 @@ void LLPipeline::renderDeferredLightingToRenderTarget(LLRenderTarget* render_tar if (RenderDeferredAtmospheric) { //apply sunlight contribution LLFastTimer ftm(FTM_ATMOSPHERICS); - bindDeferredShader(gDeferredSoftenProgram); + bindDeferredShader(LLPipeline::sUnderWaterRender ? gDeferredSoftenWaterProgram : gDeferredSoftenProgram); { LLGLDepthTest depth(GL_FALSE); LLGLDisable blend(GL_BLEND); @@ -8994,7 +8996,7 @@ void LLPipeline::renderDeferredLightingToRenderTarget(LLRenderTarget* render_tar gGL.popMatrix(); } - unbindDeferredShader(gDeferredSoftenProgram); + unbindDeferredShader(LLPipeline::sUnderWaterRender ? gDeferredSoftenWaterProgram : gDeferredSoftenProgram); } { //render non-deferred geometry (fullbright, alpha, etc) @@ -9187,7 +9189,7 @@ void LLPipeline::renderDeferredLightingToRenderTarget(LLRenderTarget* render_tar vert[2].set(3,1,0); { - bindDeferredShader(gDeferredMultiLightProgram); + bindDeferredShader(gDeferredMultiLightProgram[0]); mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); @@ -9225,17 +9227,25 @@ void LLPipeline::renderDeferredLightingToRenderTarget(LLRenderTarget* render_tar count++; if (count == max_count || fullscreen_lights.empty()) { - gDeferredMultiLightProgram.uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT, count); - gDeferredMultiLightProgram.uniform4fv(LLShaderMgr::MULTI_LIGHT, count, (GLfloat*) light); - gDeferredMultiLightProgram.uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*) col); - gDeferredMultiLightProgram.uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z, far_z); + U32 idx = count-1; + bindDeferredShader(gDeferredMultiLightProgram[idx]); + + gDeferredMultiLightProgram[idx].uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT, count); + gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT, count, (GLfloat*) light); + gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*) col); + gDeferredMultiLightProgram[idx].uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z, far_z); far_z = 0.f; count = 0; + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); + + // This "seems necessary"...ask davep if it's automagical + // + //unbindDeferredShader(gDeferredMultiLightProgram[idx]); } } - - unbindDeferredShader(gDeferredMultiLightProgram); + + unbindDeferredShader(gDeferredMultiLightProgram[0]); bindDeferredShader(gDeferredMultiSpotLightProgram); -- cgit v1.2.3 From bb8ff8707c93604007c00a5227be35b2799bdb92 Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 11 Jul 2013 18:27:50 -0400 Subject: Fix a crash on 10.6.x due to auto layout not being supported in 10.6 nibs. --- indra/newview/SecondLife.nib | Bin 13021 -> 12348 bytes indra/newview/SecondLife.xib | 138 +++++++++++-------------------------------- 2 files changed, 34 insertions(+), 104 deletions(-) diff --git a/indra/newview/SecondLife.nib b/indra/newview/SecondLife.nib index a5f2717167..8b99b5a770 100644 Binary files a/indra/newview/SecondLife.nib and b/indra/newview/SecondLife.nib differ diff --git a/indra/newview/SecondLife.xib b/indra/newview/SecondLife.xib index e5736f76a4..370df6bf5f 100644 --- a/indra/newview/SecondLife.xib +++ b/indra/newview/SecondLife.xib @@ -2,16 +2,15 @@ 1060 - 12E52 - 3084 + 12E55 + 4457.6 1187.39 626.00 com.apple.InterfaceBuilder.CocoaPlugin - 3084 + 4457.6 - IBNSLayoutConstraint NSCustomObject NSMenu NSMenuItem @@ -329,13 +328,15 @@ - + 256 {1024, 600} + + _NS:20 - {{0, 0}, {2560, 1440}} + {{0, 0}, {2560, 1418}} {10000000000000, 10000000000000} Second Life 128 @@ -360,7 +361,7 @@ - 2304 + 2322 @@ -533,7 +534,7 @@ _NS:21 - {{0, 0}, {2560, 1440}} + {{0, 0}, {2560, 1418}} {10000000000000, 10000000000000} YES @@ -952,70 +953,6 @@ - - - 4 - 0 - - 4 - 1 - - -1 - - 1000 - - 8 - 29 - 3 - - - - 6 - 0 - - 6 - 1 - - -1 - - 1000 - - 8 - 29 - 3 - - - - 3 - 0 - - 3 - 1 - - -1 - - 1000 - - 8 - 29 - 3 - - - - 5 - 0 - - 5 - 1 - - -1 - - 1000 - - 8 - 29 - 3 - @@ -1044,26 +981,6 @@ - - 949 - - - - - 950 - - - - - 951 - - - - - 952 - - - @@ -1110,23 +1027,12 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - - - - - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin LLNonInlineTextView com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin @@ -1187,6 +1093,27 @@ ./Classes/LLUserInputWindow.h + + NSTextView + + id + id + + + + orderFrontSharingServicePicker: + id + + + toggleQuickLookPreviewPanel: + id + + + + IBProjectSource + ./Classes/NSTextView.h + + 0 @@ -1195,12 +1122,15 @@ com.apple.InterfaceBuilder.CocoaPlugin.macosx + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + YES 3 {11, 11} {10, 3} - YES -- cgit v1.2.3 From 6fbafaf056d61ab0ab49cc16a998a528f0ea22e8 Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 11 Jul 2013 18:41:16 -0400 Subject: Restore control + right click functionality. --- indra/llwindow/llopenglview-objc.mm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 8a6984091d..77c2fc7e19 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -242,12 +242,18 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void) mouseDown:(NSEvent *)theEvent { - if ([theEvent clickCount] >= 2) - { - callDoubleClick(mMousePos, mModifiers); - } else if ([theEvent clickCount] == 1) { - callLeftMouseDown(mMousePos, mModifiers); - } + // Apparently people still use this? + if ([theEvent modifierFlags] & NSControlKeyMask) + { + callRightMouseDown(mMousePos, mModifiers); + } else { + if ([theEvent clickCount] >= 2) + { + callDoubleClick(mMousePos, mModifiers); + } else if ([theEvent clickCount] == 1) { + callLeftMouseDown(mMousePos, mModifiers); + } + } } - (void) mouseUp:(NSEvent *)theEvent -- cgit v1.2.3 From 72bb473c9ed106cce6baf22ac74a13443d4630e8 Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 11 Jul 2013 18:59:28 -0400 Subject: Ensure that the correct method is called when we're simulating a right click. --- indra/llwindow/llopenglview-objc.h | 1 + indra/llwindow/llopenglview-objc.mm | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index f895aae577..71149f8561 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -41,6 +41,7 @@ bool mHasMarkedText; unsigned int mMarkedTextLength; bool mMarkedTextAllowed; + bool mSimulatedRightClick; } - (id) initWithSamples:(NSUInteger)samples; - (id) initWithSamples:(NSUInteger)samples andVsync:(BOOL)vsync; diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 77c2fc7e19..e5b7681435 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -246,6 +246,7 @@ attributedStringInfo getSegments(NSAttributedString *str) if ([theEvent modifierFlags] & NSControlKeyMask) { callRightMouseDown(mMousePos, mModifiers); + mSimulatedRightClick = true; } else { if ([theEvent clickCount] >= 2) { @@ -258,7 +259,13 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void) mouseUp:(NSEvent *)theEvent { - callLeftMouseUp(mMousePos, mModifiers); + if (mSimulatedRightClick) + { + callRightMouseUp(mMousePos, mModifiers); + mSimulatedRightClick = false; + } else { + callLeftMouseUp(mMousePos, mModifiers); + } } - (void) rightMouseDown:(NSEvent *)theEvent -- cgit v1.2.3 From fbf3d8b78137a5229ccfabd1e42a0712d92b061f Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham)" Date: Thu, 11 Jul 2013 16:21:23 -0700 Subject: NORSPEC-291 WIP materials underwater with haze, reflection broken, water dist broken --- .../shaders/class1/deferred/materialF.glsl | 37 +++++----------- .../shaders/class1/deferred/materialV.glsl | 1 + .../shaders/class1/deferred/softenLightF.glsl | 15 ++++--- .../shaders/class2/deferred/softenLightF.glsl | 9 ++++ indra/newview/lldrawpoolalpha.cpp | 6 +++ indra/newview/lldrawpoolavatar.cpp | 15 +++---- indra/newview/lldrawpoolmaterials.cpp | 9 ++-- indra/newview/lldrawpoolsky.cpp | 3 +- indra/newview/lldrawpoolwlsky.cpp | 5 ++- indra/newview/llviewerdisplay.cpp | 11 +---- indra/newview/llviewershadermgr.cpp | 50 ++++++++-------------- indra/newview/llviewershadermgr.h | 3 +- indra/newview/pipeline.cpp | 2 - 13 files changed, 70 insertions(+), 96 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 393074344b..9ce4d89df7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -136,20 +136,15 @@ uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; #ifdef WATER_FOG -vec3 getPositionEye() -{ - return vary_PositionEye; -} - uniform vec4 waterPlane; uniform vec4 waterFogColor; uniform float waterFogDensity; uniform float waterFogKS; -vec4 applyWaterFogDeferred(vec4 color) +vec4 applyWaterFogDeferred(vec3 pos, vec4 color) { //normalize view vector - vec3 view = normalize(getPositionEye()); + vec3 view = normalize(pos); float es = -(dot(view, waterPlane.xyz)); //find intersection point with water plane and eye vector @@ -160,7 +155,7 @@ vec4 applyWaterFogDeferred(vec4 color) vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); //get object depth - float depth = length(getPositionEye() - int_v); + float depth = length(pos - int_v); //get "thickness" of water float l = max(depth, 0.1); @@ -463,21 +458,6 @@ out vec4 frag_data[3]; #else #define frag_data gl_FragData #endif - -VARYING vec3 vary_position; - -#ifdef WATER_FOG -vec3 vary_PositionEye; -vec3 getPositionEye() -{ - return vary_PositionEye; -} -void setPositionEye(vec3 e) -{ - vary_PositionEye = e; -} -#endif - #endif uniform sampler2D diffuseMap; @@ -749,15 +729,18 @@ void main() float al = max(diffcol.a,glare)*vertex_color.a; #ifdef WATER_FOG - frag_color = applyWaterFogDeferred(vec4(col.rgb, al)); -#else + vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al)); + col.rgb = temp.rgb; + al = temp.a; +#endif + frag_color.rgb = col.rgb; frag_color.a = al; -#endif #else frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. -#endif% +#endif } + diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index 154db09583..e44a6fcec8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -141,3 +141,4 @@ vary_normal = n; #endif #endif } + diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 1706d41da0..953f0189f0 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -133,6 +133,7 @@ vec3 getPositionEye() { return vary_PositionEye; } + vec3 getSunlitColor() { return vary_SunlitColor; @@ -182,10 +183,10 @@ uniform vec4 waterFogColor; uniform float waterFogDensity; uniform float waterFogKS; -vec4 applyWaterFogDeferred(vec4 color) +vec4 applyWaterFogDeferred(vec3 pos, vec4 color) { //normalize view vector - vec3 view = normalize(getPositionEye()); + vec3 view = normalize(pos); float es = -(dot(view, waterPlane.xyz)); //find intersection point with water plane and eye vector @@ -196,7 +197,7 @@ vec4 applyWaterFogDeferred(vec4 color) vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); //get object depth - float depth = length(getPositionEye() - int_v); + float depth = length(pos - int_v); //get "thickness" of water float l = max(depth, 0.1); @@ -435,13 +436,14 @@ void main() if (norm.w < 0.5) { col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); #ifdef WATER_FOG - vec4 fogged = applyWaterFogDeferred(vec4(col, bloom)); + vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); col = fogged.rgb; bloom = fogged.a; #endif + + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); } col = srgb_to_linear(col); @@ -450,6 +452,7 @@ void main() //col.g = envIntensity; } - frag_color.rgb = col; + frag_color.rgb = col.rgb; frag_color.a = bloom; } + diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 06447261b4..4464358b1e 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -133,6 +133,13 @@ vec4 getPosition(vec2 pos_screen) return getPosition_d(pos_screen, depth); } +#ifdef WATER_FOG +vec3 getPositionEye(); +vec3 getSunlitColor(); +vec3 getAmblitColor(); +vec3 getAdditiveColor(); +vec3 getAtmosAttenuation(); +#else vec3 getPositionEye() { return vary_PositionEye; @@ -153,6 +160,7 @@ vec3 getAtmosAttenuation() { return vary_AtmosAttenuation; } +#endif void setPositionEye(vec3 v) { @@ -421,3 +429,4 @@ void main() frag_color.rgb = col; frag_color.a = bloom; } + diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 737da2e209..e53c783161 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -405,6 +405,11 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask) llassert(mask < LLMaterial::SHADER_COUNT); target_shader = &(gDeferredMaterialProgram[mask]); + if (LLPipeline::sUnderWaterRender) + { + target_shader = &(gDeferredMaterialWaterProgram[mask]); + } + if (current_shader != target_shader) { gPipeline.bindDeferredShader(*target_shader); @@ -554,3 +559,4 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask) gPipeline.enableLightsDynamic(); } } + diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index 45abb87bad..3815548dba 100755 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -297,14 +297,12 @@ void LLDrawPoolAvatar::beginDeferredRiggedMaterialAlpha(S32 pass) pass += LLMaterial::SHADER_COUNT; + sVertexProgram = &gDeferredMaterialProgram[pass]; + if (LLPipeline::sUnderWaterRender) { sVertexProgram = &(gDeferredMaterialWaterProgram[pass]); } - else - { - sVertexProgram = &(gDeferredMaterialProgram[pass]); - } gPipeline.bindDeferredShader(*sVertexProgram); sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); @@ -1099,14 +1097,13 @@ void LLDrawPoolAvatar::beginDeferredRiggedMaterial(S32 pass) { //skip alpha passes return; } + sVertexProgram = &gDeferredMaterialProgram[pass+LLMaterial::SHADER_COUNT]; + if (LLPipeline::sUnderWaterRender) { - sVertexProgram = &gDeferredMaterialWaterProgram[pass+LLMaterial::SHADER_COUNT]; - } - else - { - sVertexProgram = &gDeferredMaterialProgram[pass+LLMaterial::SHADER_COUNT]; + sVertexProgram = &(gDeferredMaterialWaterProgram[pass]); } + sVertexProgram->bind(); normal_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::BUMP_MAP); specular_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::SPECULAR_MAP); diff --git a/indra/newview/lldrawpoolmaterials.cpp b/indra/newview/lldrawpoolmaterials.cpp index 49619e6b1d..d1b5080650 100644 --- a/indra/newview/lldrawpoolmaterials.cpp +++ b/indra/newview/lldrawpoolmaterials.cpp @@ -71,15 +71,13 @@ void LLDrawPoolMaterials::beginDeferredPass(S32 pass) 15, //LLRenderPass::PASS_NORMSPEC_GLOW, }; + mShader = &(gDeferredMaterialProgram[shader_idx[pass]]); + if (LLPipeline::sUnderWaterRender) { mShader = &(gDeferredMaterialWaterProgram[shader_idx[pass]]); } - else - { - mShader = &(gDeferredMaterialProgram[shader_idx[pass]]); - } - + mShader->bind(); diffuse_channel = mShader->enableTexture(LLShaderMgr::DIFFUSE_MAP); @@ -223,3 +221,4 @@ void LLDrawPoolMaterials::pushBatch(LLDrawInfo& params, U32 mask, BOOL texture, gGL.matrixMode(LLRender::MM_MODELVIEW); } } + diff --git a/indra/newview/lldrawpoolsky.cpp b/indra/newview/lldrawpoolsky.cpp index d36b9ace94..ef8bdc3304 100755 --- a/indra/newview/lldrawpoolsky.cpp +++ b/indra/newview/lldrawpoolsky.cpp @@ -77,7 +77,7 @@ void LLDrawPoolSky::render(S32 pass) } // don't render sky under water (background just gets cleared to fog color) - if(mVertexShaderLevel > 0 /*&& !LLPipeline::sRenderDeferred*/ && LLPipeline::sUnderWaterRender) + if(mVertexShaderLevel > 0 && LLPipeline::sUnderWaterRender) { return; } @@ -155,3 +155,4 @@ void LLDrawPoolSky::renderSkyCubeFace(U8 side) void LLDrawPoolSky::endRenderPass( S32 pass ) { } + diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp index 56b58aaeb4..53339222eb 100755 --- a/indra/newview/lldrawpoolwlsky.cpp +++ b/indra/newview/lldrawpoolwlsky.cpp @@ -99,12 +99,12 @@ LLViewerTexture *LLDrawPoolWLSky::getDebugTexture() void LLDrawPoolWLSky::beginRenderPass( S32 pass ) { sky_shader = - (LLPipeline::sUnderWaterRender /*&& !LLPipeline::sRenderDeferred*/) ? + LLPipeline::sUnderWaterRender ? &gObjectFullbrightNoColorWaterProgram : &gWLSkyProgram; cloud_shader = - (LLPipeline::sUnderWaterRender /*&& !LLPipeline::sRenderDeferred*/) ? + LLPipeline::sUnderWaterRender ? &gObjectFullbrightNoColorWaterProgram : &gWLCloudProgram; } @@ -420,3 +420,4 @@ void LLDrawPoolWLSky::restoreGL() sCloudNoiseTexture = LLViewerTextureManager::getLocalTexture(sCloudNoiseRawImage.get(), TRUE); } } + diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp index d9fd171b4e..bbebeea3e0 100755 --- a/indra/newview/llviewerdisplay.cpp +++ b/indra/newview/llviewerdisplay.cpp @@ -893,15 +893,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot) if (LLPipeline::sRenderDeferred) { gPipeline.mDeferredScreen.bindTarget(); - if (LLPipeline::sUnderWaterRender) - { - const LLColor4 &col = LLDrawPoolWater::sWaterFogColor; - glClearColor(col.mV[0], col.mV[1], col.mV[2], 0.f); - } - else - { - glClearColor(1,0,1,1); - } + glClearColor(1,0,1,1); gPipeline.mDeferredScreen.clear(); } else @@ -1631,3 +1623,4 @@ void display_cleanup() { gDisconnectedImagep = NULL; } + diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 88593346c0..3df8115402 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -168,7 +168,6 @@ LLGLSLShader gPostNightVisionProgram; // Deferred rendering shaders LLGLSLShader gDeferredImpostorProgram; LLGLSLShader gDeferredWaterProgram; -LLGLSLShader gDeferredUnderWaterProgram; LLGLSLShader gDeferredDiffuseProgram; LLGLSLShader gDeferredDiffuseAlphaMaskProgram; LLGLSLShader gDeferredNonIndexedDiffuseProgram; @@ -285,21 +284,21 @@ LLViewerShaderMgr::LLViewerShaderMgr() : mShaderList.push_back(&gDeferredSoftenProgram); mShaderList.push_back(&gDeferredSoftenWaterProgram); mShaderList.push_back(&gDeferredMaterialProgram[1]); - mShaderList.push_back(&gDeferredMaterialWaterProgram[1]); mShaderList.push_back(&gDeferredMaterialProgram[5]); - mShaderList.push_back(&gDeferredMaterialWaterProgram[5]); mShaderList.push_back(&gDeferredMaterialProgram[9]); - mShaderList.push_back(&gDeferredMaterialWaterProgram[9]); mShaderList.push_back(&gDeferredMaterialProgram[13]); - mShaderList.push_back(&gDeferredMaterialWaterProgram[13]); mShaderList.push_back(&gDeferredMaterialProgram[1+LLMaterial::SHADER_COUNT]); - mShaderList.push_back(&gDeferredMaterialWaterProgram[1+LLMaterial::SHADER_COUNT]); mShaderList.push_back(&gDeferredMaterialProgram[5+LLMaterial::SHADER_COUNT]); - mShaderList.push_back(&gDeferredMaterialWaterProgram[5+LLMaterial::SHADER_COUNT]); mShaderList.push_back(&gDeferredMaterialProgram[9+LLMaterial::SHADER_COUNT]); - mShaderList.push_back(&gDeferredMaterialWaterProgram[9+LLMaterial::SHADER_COUNT]); mShaderList.push_back(&gDeferredMaterialProgram[13+LLMaterial::SHADER_COUNT]); - mShaderList.push_back(&gDeferredMaterialWaterProgram[13+LLMaterial::SHADER_COUNT]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[1]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[5]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[9]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[13]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[1+LLMaterial::SHADER_COUNT]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[5+LLMaterial::SHADER_COUNT]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[9+LLMaterial::SHADER_COUNT]); + mShaderList.push_back(&gDeferredMaterialWaterProgram[13+LLMaterial::SHADER_COUNT]); mShaderList.push_back(&gDeferredAlphaProgram); mShaderList.push_back(&gDeferredSkinnedAlphaProgram); mShaderList.push_back(&gDeferredFullbrightProgram); @@ -1154,7 +1153,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredPostGammaCorrectProgram.unload(); gFXAAProgram.unload(); gDeferredWaterProgram.unload(); - gDeferredUnderWaterProgram.unload(); gDeferredWLSkyProgram.unload(); gDeferredWLCloudProgram.unload(); gDeferredStarProgram.unload(); @@ -1332,7 +1330,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { - gDeferredMaterialProgram[i].mName = llformat("Deferred Material Shader %d", i); + gDeferredMaterialWaterProgram[i].mName = llformat("Deferred Underwater Material Shader %d", i); U32 alpha_mode = i & 0x3; @@ -1340,23 +1338,22 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredMaterialWaterProgram[i].mShaderFiles.push_back(make_pair("deferred/materialV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMaterialWaterProgram[i].mShaderFiles.push_back(make_pair("deferred/materialF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMaterialWaterProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + gDeferredMaterialWaterProgram[i].mShaderGroup = LLGLSLShader::SG_WATER; + gDeferredMaterialWaterProgram[i].addPermutation("HAS_NORMAL_MAP", i & 0x8? "1" : "0"); gDeferredMaterialWaterProgram[i].addPermutation("HAS_SPECULAR_MAP", i & 0x4 ? "1" : "0"); gDeferredMaterialWaterProgram[i].addPermutation("DIFFUSE_ALPHA_MODE", llformat("%d", alpha_mode)); gDeferredMaterialWaterProgram[i].addPermutation("HAS_SUN_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); bool has_skin = i & 0x10; gDeferredMaterialWaterProgram[i].addPermutation("HAS_SKIN",has_skin ? "1" : "0"); - gDeferredMaterialWaterProgram[i].addPermutation("WATER_FOG","1"); - gDeferredMaterialWaterProgram[i].mFeatures.hasWaterFog = true; - gDeferredMaterialWaterProgram[i].mShaderGroup = SHADER_WATER; if (has_skin) { gDeferredMaterialWaterProgram[i].mFeatures.hasObjectSkinning = true; } - success = gDeferredMaterialWaterProgram[i].createShader(NULL, NULL); + success = gDeferredMaterialWaterProgram[i].createShader(NULL, NULL);//&mWLUniforms); } } @@ -1377,6 +1374,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredMaterialWaterProgram[5+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true; gDeferredMaterialWaterProgram[9+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true; gDeferredMaterialWaterProgram[13+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true; + if (success) { @@ -1642,21 +1640,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() success = gDeferredWaterProgram.createShader(NULL, &mWaterUniforms); } - if (success) - { - // load water shader - /*gDeferredUnderWaterProgram.mName = "Deferred Under Water Shader"; - gDeferredUnderWaterProgram.mFeatures.calculatesAtmospherics = true; - gDeferredUnderWaterProgram.mFeatures.hasGamma = true; - gDeferredUnderWaterProgram.mShaderFiles.clear(); - gDeferredUnderWaterProgram.mShaderFiles.push_back(make_pair("deferred/waterV.glsl", GL_VERTEX_SHADER_ARB)); - gDeferredUnderWaterProgram.mShaderFiles.push_back(make_pair("deferred/underWaterF.glsl", GL_FRAGMENT_SHADER_ARB)); - gDeferredUnderWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_WATER]; - gDeferredUnderWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; - - success = gDeferredUnderWaterProgram.createShader(NULL, &mWaterUniforms);*/ - } - if (success) { gDeferredSoftenProgram.mName = "Deferred Soften Shader"; @@ -1677,21 +1660,21 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredSoftenWaterProgram.mName = "Deferred Soften Underwater Shader"; - gDeferredSoftenWaterProgram.mFeatures.hasWaterFog = true; gDeferredSoftenWaterProgram.mShaderFiles.clear(); + gDeferredSoftenWaterProgram.mShaderFiles.push_back(make_pair("deferred/softenLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSoftenWaterProgram.mShaderFiles.push_back(make_pair("deferred/softenLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredSoftenWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; gDeferredSoftenWaterProgram.addPermutation("WATER_FOG", "1"); - gDeferredSoftenWaterProgram.mShaderGroup = SHADER_WATER; + gDeferredSoftenWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; if (gSavedSettings.getBOOL("RenderDeferredSSAO")) { //if using SSAO, take screen space light map into account as if shadows are enabled gDeferredSoftenWaterProgram.mShaderLevel = llmax(gDeferredSoftenWaterProgram.mShaderLevel, 2); } - success = gDeferredSoftenWaterProgram.createShader(NULL, NULL); + success = gDeferredSoftenWaterProgram.createShader(NULL, &mWLUniforms); } if (success) @@ -3275,3 +3258,4 @@ LLViewerShaderMgr::shader_iter LLViewerShaderMgr::endShaders() const { return mShaderList.end(); } + diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h index 34a0f6b89d..5310076013 100755 --- a/indra/newview/llviewershadermgr.h +++ b/indra/newview/llviewershadermgr.h @@ -330,7 +330,6 @@ extern LLGLSLShader gPostNightVisionProgram; // Deferred rendering shaders extern LLGLSLShader gDeferredImpostorProgram; extern LLGLSLShader gDeferredWaterProgram; -extern LLGLSLShader gDeferredUnderWaterProgram; extern LLGLSLShader gDeferredDiffuseProgram; extern LLGLSLShader gDeferredDiffuseAlphaMaskProgram; extern LLGLSLShader gDeferredNonIndexedDiffuseAlphaMaskProgram; @@ -380,5 +379,5 @@ extern LLGLSLShader gNormalMapGenProgram; // Deferred materials shaders extern LLGLSLShader gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2]; extern LLGLSLShader gDeferredMaterialWaterProgram[LLMaterial::SHADER_COUNT*2]; - #endif + diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index a44cc73678..c605735170 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8725,8 +8725,6 @@ void LLPipeline::renderDeferredLighting() count = 0; mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); -// seems like this should be done here... - //unbindDeferredShader(gDeferredMultiLightProgram[idx]); } } -- cgit v1.2.3 From b2bec3f99c74d21bb1c2c68d73854f3990db26d5 Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 11 Jul 2013 19:37:08 -0400 Subject: STORM-1942: dock icon bouncing unimplemented --- indra/llwindow/llwindowmacosx-objc.h | 1 + indra/llwindow/llwindowmacosx-objc.mm | 5 +++++ indra/llwindow/llwindowmacosx.cpp | 34 +++------------------------------- indra/llwindow/llwindowmacosx.h | 5 ----- 4 files changed, 9 insertions(+), 36 deletions(-) diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 914fc534fb..020e2bff5b 100755 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -68,6 +68,7 @@ void setNotAllowedCursor(); void hideNSCursor(); void showNSCursor(); void hideNSCursorTillMove(bool hide); +void requestUserAttention(); NSWindowRef createNSWindow(int x, int y, int width, int height); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 41d8e3ecd9..ef29515403 100755 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -390,6 +390,11 @@ void makeFirstResponder(NSWindowRef window, GLViewRef view) [(LLNSWindow*)window makeFirstResponder:(LLOpenGLView*)view]; } +void requestUserAttention() +{ + [[NSApplication sharedApplication] requestUserAttention:NSInformationalRequest]; +} + /* GLViewRef getGLView() { diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 737ecba368..e5556c23d4 100755 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -149,10 +149,6 @@ LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, mFSAASamples = fsaa_samples; mForceRebuild = FALSE; - // For reasons that aren't clear to me, LLTimers seem to be created in the "started" state. - // Since the started state of this one is used to track whether the NMRec has been installed, it wants to start out in the "stopped" state. - mBounceTimer.stop(); - // Get the original aspect ratio of the main device. mOriginalAspectRatio = (double)CGDisplayPixelsWide(mDisplay) / (double)CGDisplayPixelsHigh(mDisplay); @@ -763,12 +759,6 @@ BOOL LLWindowMacOSX::getFullscreen() void LLWindowMacOSX::gatherInput() { - // stop bouncing icon after fixed period of time - if (mBounceTimer.getStarted() && mBounceTimer.getElapsedTimeF32() > mBounceTime) - { - stopDockTileBounce(); - } - updateCursor(); } @@ -1161,22 +1151,9 @@ void LLWindowMacOSX::afterDialog() void LLWindowMacOSX::flashIcon(F32 seconds) { - // Don't do this if we're already started, since this would try to install the NMRec twice. - if(!mBounceTimer.getStarted()) - { - S32 err = 0; - // TODO: Implement icon bouncing - mBounceTime = seconds; - if(err == 0) - { - mBounceTimer.start(); - } - else - { - // This is very not-fatal (only problem is the icon will not bounce), but we'd like to find out about it somehow... - llinfos << "NMInstall failed with error code " << err << llendl; - } - } + // For consistency with OS X conventions, the number of seconds given is ignored and + // left up to the OS (which will actually bounce it for one second). + requestUserAttention(); } BOOL LLWindowMacOSX::isClipboardTextAvailable() @@ -1809,11 +1786,6 @@ void *LLWindowMacOSX::getPlatformWindow() return (void*)mWindow; } -void LLWindowMacOSX::stopDockTileBounce() -{ - mBounceTimer.stop(); -} - // get a double value from a dictionary /* static double getDictDouble (CFDictionaryRef refDict, CFStringRef key) diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h index 82195c2700..6a6b39e674 100755 --- a/indra/llwindow/llwindowmacosx.h +++ b/indra/llwindow/llwindowmacosx.h @@ -164,7 +164,6 @@ protected: void destroyContext(); void setupFailure(const std::string& text, const std::string& caption, U32 type); void adjustCursorDecouple(bool warpingMouse = false); - void stopDockTileBounce(); static MASK modifiersToMask(S16 modifiers); #if LL_OS_DRAGDROP_ENABLED @@ -206,10 +205,6 @@ protected: BOOL mForceRebuild; S32 mDragOverrideCursor; - - F32 mBounceTime; - //NMRec mBounceRec; - LLTimer mBounceTimer; // Input method management through Text Service Manager. BOOL mLanguageTextInputAllowed; -- cgit v1.2.3 From e9cdd0bfe8fe7f3bec0e6db7fba43e11f729af8a Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham)" Date: Thu, 11 Jul 2013 16:39:39 -0700 Subject: NORSPEC-291 WIP fix avatar disappearing --- .../app_settings/shaders/class1/deferred/materialV.glsl | 9 +++++---- .../shaders/class2/deferred/softenLightF.glsl | 8 -------- indra/newview/lldrawpoolavatar.cpp | 16 ++++++++-------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index e44a6fcec8..393d1e69da 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -43,10 +43,10 @@ uniform mat4 modelview_projection_matrix; uniform mat4 modelview_matrix; #endif -#endif - VARYING vec3 vary_position; +#endif + uniform mat4 texture_matrix0; ATTRIBUTE vec3 position; @@ -84,14 +84,15 @@ void main() mat = modelview_matrix * mat; vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; - vary_position = pos; +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vary_position = pos; +#endif gl_Position = projection_matrix*vec4(pos,1.0); #else //transform vertex - vary_position = (modelview_projection_matrix * vec4(position.xyz, 1.0)).xyz; gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); #endif diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 4464358b1e..08aaa2237d 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -133,13 +133,6 @@ vec4 getPosition(vec2 pos_screen) return getPosition_d(pos_screen, depth); } -#ifdef WATER_FOG -vec3 getPositionEye(); -vec3 getSunlitColor(); -vec3 getAmblitColor(); -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); -#else vec3 getPositionEye() { return vary_PositionEye; @@ -160,7 +153,6 @@ vec3 getAtmosAttenuation() { return vary_AtmosAttenuation; } -#endif void setPositionEye(vec3 v) { diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index 3815548dba..86776b7e42 100755 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -299,10 +299,10 @@ void LLDrawPoolAvatar::beginDeferredRiggedMaterialAlpha(S32 pass) sVertexProgram = &gDeferredMaterialProgram[pass]; - if (LLPipeline::sUnderWaterRender) - { - sVertexProgram = &(gDeferredMaterialWaterProgram[pass]); - } + //if (LLPipeline::sUnderWaterRender) + //{ + // sVertexProgram = &(gDeferredMaterialWaterProgram[pass]); + //} gPipeline.bindDeferredShader(*sVertexProgram); sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); @@ -1099,10 +1099,10 @@ void LLDrawPoolAvatar::beginDeferredRiggedMaterial(S32 pass) } sVertexProgram = &gDeferredMaterialProgram[pass+LLMaterial::SHADER_COUNT]; - if (LLPipeline::sUnderWaterRender) - { - sVertexProgram = &(gDeferredMaterialWaterProgram[pass]); - } + //if (LLPipeline::sUnderWaterRender) + //{ + // sVertexProgram = &(gDeferredMaterialWaterProgram[pass]); + //} sVertexProgram->bind(); normal_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::BUMP_MAP); -- cgit v1.2.3 From dc7d287717ed42d1d8aa8b57cfd740ca75fe9e7b Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 11 Jul 2013 19:41:57 -0400 Subject: OPEN-170: "Set Window Size" always increases window size by specified size --- indra/llwindow/llwindowmacosx.cpp | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index e5556c23d4..d657c629b9 100755 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -863,26 +863,11 @@ BOOL LLWindowMacOSX::setSizeImpl(const LLCoordScreen size) BOOL LLWindowMacOSX::setSizeImpl(const LLCoordWindow size) { - float client_rect[4]; if (mWindow) { - S32 err = noErr; - getContentViewBounds(mWindow, client_rect); - if (err == noErr) - { - client_rect[2] += size.mX; - client_rect[3] += size.mY; - setWindowSize(mWindow, client_rect[2], client_rect[3]); - } - if (err == noErr) - { - return TRUE; - } - else - { - llinfos << "Error setting size" << err << llendl; - return FALSE; - } + LLCoordScreen screen_size; + convertCoords(size, &screen_size); + return setSizeImpl(screen_size); } return FALSE; } -- cgit v1.2.3 From d07ba61a850d926eda3e6a9abe54465c7a462676 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham)" Date: Thu, 11 Jul 2013 16:42:14 -0700 Subject: NORSPEC-291 really fix missing avatar --- indra/newview/lldrawpoolavatar.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index 86776b7e42..59c9cf5a83 100755 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -299,10 +299,10 @@ void LLDrawPoolAvatar::beginDeferredRiggedMaterialAlpha(S32 pass) sVertexProgram = &gDeferredMaterialProgram[pass]; - //if (LLPipeline::sUnderWaterRender) - //{ - // sVertexProgram = &(gDeferredMaterialWaterProgram[pass]); - //} + if (LLPipeline::sUnderWaterRender) + { + sVertexProgram = &(gDeferredMaterialWaterProgram[pass]); + } gPipeline.bindDeferredShader(*sVertexProgram); sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); @@ -1099,10 +1099,10 @@ void LLDrawPoolAvatar::beginDeferredRiggedMaterial(S32 pass) } sVertexProgram = &gDeferredMaterialProgram[pass+LLMaterial::SHADER_COUNT]; - //if (LLPipeline::sUnderWaterRender) - //{ - // sVertexProgram = &(gDeferredMaterialWaterProgram[pass]); - //} + if (LLPipeline::sUnderWaterRender) + { + sVertexProgram = &(gDeferredMaterialWaterProgram[pass+LLMaterial::SHADER_COUNT]); + } sVertexProgram->bind(); normal_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::BUMP_MAP); -- cgit v1.2.3 From d68f254c66cc2c971cda14c59f8d16e8c44586d6 Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 11 Jul 2013 19:43:02 -0400 Subject: OPEN-171: the save file dialog incorrectly uses type codes as extensions --- indra/newview/llfilepicker_mac.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indra/newview/llfilepicker_mac.mm b/indra/newview/llfilepicker_mac.mm index d8862bce57..c41639fbd5 100644 --- a/indra/newview/llfilepicker_mac.mm +++ b/indra/newview/llfilepicker_mac.mm @@ -106,8 +106,8 @@ std::string* doSaveDialog(const std::string* file, { NSSavePanel *panel = [NSSavePanel savePanel]; - NSString *typens = [NSString stringWithCString:type->c_str() encoding:[NSString defaultCStringEncoding]]; - NSArray *fileType = [[NSArray alloc] initWithObjects:typens,nil]; + NSString *extensionns = [NSString stringWithCString:extension->c_str() encoding:[NSString defaultCStringEncoding]]; + NSArray *fileType = [[NSArray alloc] initWithObjects:extensionns,nil]; //[panel setMessage:@"Save Image File"]; [panel setTreatsFilePackagesAsDirectories: ( flags & F_NAV_SUPPORT ) ]; -- cgit v1.2.3 From a787e272c31d8e535dae75e4d95365d17cec78db Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 11 Jul 2013 21:31:17 -0400 Subject: Alert box support! --- indra/llwindow/llopenglview-objc.mm | 2 +- indra/llwindow/llwindowmacosx-objc.h | 1 + indra/llwindow/llwindowmacosx-objc.mm | 35 +++++++++++++++++++++++++++++++++++ indra/llwindow/llwindowmacosx.cpp | 23 +---------------------- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index e5b7681435..42ad4f8723 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -668,7 +668,7 @@ attributedStringInfo getSegments(NSAttributedString *str) - (BOOL) resignFirstResponder { - callFocus(); + callFocusLost(); return true; } diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 020e2bff5b..32b3bfb078 100755 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -69,6 +69,7 @@ void hideNSCursor(); void showNSCursor(); void hideNSCursorTillMove(bool hide); void requestUserAttention(); +long showAlert(std::string title, std::string text, int type); NSWindowRef createNSWindow(int x, int y, int width, int height); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index ef29515403..3703dcf28d 100755 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -395,6 +395,41 @@ void requestUserAttention() [[NSApplication sharedApplication] requestUserAttention:NSInformationalRequest]; } +long showAlert(std::string text, std::string title, int type) +{ + NSAlert *alert = [[NSAlert alloc] init]; + + [alert setMessageText:[NSString stringWithCString:title.c_str() encoding:[NSString defaultCStringEncoding]]]; + [alert setInformativeText:[NSString stringWithCString:text.c_str() encoding:[NSString defaultCStringEncoding]]]; + if (type == 0) + { + [alert addButtonWithTitle:@"Okay"]; + } else if (type == 1) + { + [alert addButtonWithTitle:@"Okay"]; + [alert addButtonWithTitle:@"Cancel"]; + } else if (type == 2) + { + [alert addButtonWithTitle:@"Yes"]; + [alert addButtonWithTitle:@"No"]; + } + long ret = [alert runModal]; + [alert dealloc]; + + if (ret == NSAlertFirstButtonReturn) + { + ret = 0; + } else if (ret == NSAlertSecondButtonReturn) + { + ret = 1; + } else if (ret == NSAlertThirdButtonReturn) + { + ret = 2; + } + + return ret; +} + /* GLViewRef getGLView() { diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index d657c629b9..beb9ebe8e0 100755 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -1597,24 +1597,6 @@ LLSplashScreenMacOSX::~LLSplashScreenMacOSX() void LLSplashScreenMacOSX::showImpl() { // This code _could_ be used to display a spash screen... -#if 0 - IBNibRef nib = NULL; - S32 err; - - err = CreateNibReference(CFSTR("SecondLife"), &nib); - - if(err == noErr) - { - CreateWindowFromNib(nib, CFSTR("Splash Screen"), &mWindow); - - DisposeNibReference(nib); - } - - if(mWindow != NULL) - { - ShowWindow(mWindow); - } -#endif } void LLSplashScreenMacOSX::updateImpl(const std::string& mesg) @@ -1636,12 +1618,9 @@ void LLSplashScreenMacOSX::hideImpl() } } - - S32 OSMessageBoxMacOSX(const std::string& text, const std::string& caption, U32 type) { - // TODO: Implement a native NSAlert function that replicates all of this. - return 0; + return showAlert(text, caption, type); } // Open a URL with the user's default web browser. -- cgit v1.2.3 From 2f680eec93f1b06620c04af04116fe49d577cf8f Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 11 Jul 2013 21:46:10 -0400 Subject: A bit of cleanup and make the return of showAlert match the OSBTN return types in llwindow.h. --- indra/llwindow/llwindowmacosx-objc.mm | 19 ++++++++++++++----- indra/llwindow/llwindowmacosx.cpp | 8 +------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 3703dcf28d..0354c2b717 100755 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -418,13 +418,22 @@ long showAlert(std::string text, std::string title, int type) if (ret == NSAlertFirstButtonReturn) { - ret = 0; + if (type == 1) + { + ret = 3; + } else if (type == 2) + { + ret = 0; + } } else if (ret == NSAlertSecondButtonReturn) { - ret = 1; - } else if (ret == NSAlertThirdButtonReturn) - { - ret = 2; + if (type == 0 || type == 1) + { + ret = 2; + } else if (type == 2) + { + ret = 1; + } } return ret; diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index beb9ebe8e0..a3e88ea7dc 100755 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -164,7 +164,6 @@ LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, // Stash an object pointer for OSMessageBox() gWindowImplementation = this; // Create the GL context and set it up for windowed or fullscreen, as appropriate. - LL_INFOS("Window") << "Creating context..." << LL_ENDL; if(createContext(x, y, width, height, 32, fullscreen, disable_vsync)) { if(mWindow != NULL) @@ -526,13 +525,11 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits if (mWindow == NULL) { - LL_INFOS("Window") << "Creating window..." << LL_ENDL; mWindow = getMainAppWindow(); } if(mContext == NULL) { - LL_INFOS("Window") << "Creating GL view..." << LL_ENDL; // Our OpenGL view is already defined within SecondLife.xib. // Get the view instead. mGLView = createOpenGLView(mWindow, mFSAASamples, !disable_vsync); @@ -565,12 +562,10 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits GLint frames_per_swap = 0; if (disable_vsync) { - LL_DEBUGS("GLInit") << "Disabling vertical sync" << LL_ENDL; frames_per_swap = 0; } else { - LL_DEBUGS("GLinit") << "Keeping vertical sync" << LL_ENDL; frames_per_swap = 1; } @@ -593,9 +588,8 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits LL_DEBUGS("GLInit") << "Multi-threaded OpenGL enabled." << LL_ENDL; } } - LL_INFOS("Window") << "Completed context creation." << LL_ENDL; makeFirstResponder(mWindow, mGLView); - // Don't need to get the current gamma, since there's a call that restores it to the system defaults. + return TRUE; } -- cgit v1.2.3 From dea416fd83497d22147b3c0abab1bf1240e472dd Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 11 Jul 2013 22:07:17 -0400 Subject: Rework the command+click functionality a bit to ensure we're not mistakenly simulating a right click where we shouldn't. --- indra/llwindow/llopenglview-objc.mm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 42ad4f8723..5f34d03c35 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -243,7 +243,13 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void) mouseDown:(NSEvent *)theEvent { // Apparently people still use this? - if ([theEvent modifierFlags] & NSControlKeyMask) + if ([theEvent modifierFlags] & NSCommandKeyMask && + !([theEvent modifierFlags] & NSControlKeyMask) && + !([theEvent modifierFlags] & NSShiftKeyMask) && + !([theEvent modifierFlags] & NSAlternateKeyMask) && + !([theEvent modifierFlags] & NSAlphaShiftKeyMask) && + !([theEvent modifierFlags] & NSFunctionKeyMask) && + !([theEvent modifierFlags] & NSHelpKeyMask)) { callRightMouseDown(mMousePos, mModifiers); mSimulatedRightClick = true; -- cgit v1.2.3 From a8c9d81a376244a372de60b8c2af44c577ee51e0 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 12 Jul 2013 06:45:49 -0700 Subject: NORSPEC-291 WIP fix materials underwater with shadows on --- .../shaders/class2/deferred/softenLightF.glsl | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 08aaa2237d..9b72c5b57d 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -266,6 +266,52 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); } +#ifdef WATER_FOG +uniform vec4 waterPlane; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; + +vec4 applyWaterFogDeferred(vec3 pos, vec4 color) +{ + //normalize view vector + vec3 view = normalize(pos); + float es = -(dot(view, waterPlane.xyz)); + + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); + + //get object depth + float depth = length(pos - int_v); + + //get "thickness" of water + float l = max(depth, 0.1); + + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2*l) - 1.0; + + float L = min(t1/t2*t3, 1.0); + + float D = pow(0.98, l*kd); + + color.rgb = color.rgb * D + kc.rgb * L; + color.a = kc.a + color.a; + + return color; +} +#endif + vec3 atmosLighting(vec3 light) { light *= getAtmosAttenuation().r; @@ -409,6 +455,13 @@ void main() if (norm.w < 0.5) { col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); + + #ifdef WATER_FOG + vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); + col = fogged.rgb; + bloom = fogged.a; + #endif + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); } -- cgit v1.2.3 From b588865f3f56a338fc068b55ab1a408f89307f2b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 12 Jul 2013 08:04:40 -0700 Subject: NORSPEC-291 WIP first attempt at materials in reflection/waterdis maps --- indra/newview/pipeline.cpp | 620 ++++++++++++++++++++++++++++++++++++++++++++- indra/newview/pipeline.h | 1 + 2 files changed, 608 insertions(+), 13 deletions(-) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index c605735170..cac347b3a5 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8891,6 +8891,539 @@ void LLPipeline::renderDeferredLighting() } +void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) +{ + if (!sCull) + { + return; + } + + { + LLFastTimer ftm(FTM_RENDER_DEFERRED); + + LLViewerCamera* camera = LLViewerCamera::getInstance(); + + /*{ + LLGLDepthTest depth(GL_TRUE); + mDeferredDepth.copyContents(mDeferredScreen, 0, 0, mDeferredScreen.getWidth(), mDeferredScreen.getHeight(), + 0, 0, mDeferredDepth.getWidth(), mDeferredDepth.getHeight(), GL_DEPTH_BUFFER_BIT, GL_NEAREST); + }*/ + + LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE_ARB : 0); + + if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD)) + { + gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD); + } + + //ati doesn't seem to love actually using the stencil buffer on FBO's + LLGLDisable stencil(GL_STENCIL_TEST); + //glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF); + //glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + + gGL.setColorMask(true, true); + + //draw a cube around every light + LLVertexBuffer::unbind(); + + LLGLEnable cull(GL_CULL_FACE); + LLGLEnable blend(GL_BLEND); + + glh::matrix4f mat = glh_copy_matrix(gGLModelView); + + LLStrider vert; + mDeferredVB->getVertexStrider(vert); + + vert[0].set(-1,1,0); + vert[1].set(-1,-3,0); + vert[2].set(3,1,0); + + { + setupHWLights(NULL); //to set mSunDir; + LLVector4 dir(mSunDir, 0.f); + glh::vec4f tc(dir.mV); + mat.mult_matrix_vec(tc); + mTransformedSunDir.set(tc.v); + } + + gGL.pushMatrix(); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_PROJECTION); + gGL.pushMatrix(); + gGL.loadIdentity(); + + if (RenderDeferredSSAO || RenderShadowDetail > 0) + { + mDeferredLight.bindTarget(); + { //paint shadow/SSAO light map (direct lighting lightmap) + LLFastTimer ftm(FTM_SUN_SHADOW); + bindDeferredShader(gDeferredSunProgram, 0); + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + glClearColor(1,1,1,1); + mDeferredLight.clear(GL_COLOR_BUFFER_BIT); + glClearColor(0,0,0,0); + + glh::matrix4f inv_trans = glh_get_current_modelview().inverse().transpose(); + + const U32 slice = 32; + F32 offset[slice*3]; + for (U32 i = 0; i < 4; i++) + { + for (U32 j = 0; j < 8; j++) + { + glh::vec3f v; + v.set_value(sinf(6.284f/8*j), cosf(6.284f/8*j), -(F32) i); + v.normalize(); + inv_trans.mult_matrix_vec(v); + v.normalize(); + offset[(i*8+j)*3+0] = v.v[0]; + offset[(i*8+j)*3+1] = v.v[2]; + offset[(i*8+j)*3+2] = v.v[1]; + } + } + + gDeferredSunProgram.uniform3fv("offset", slice, offset); + gDeferredSunProgram.uniform2f("screenRes", mDeferredLight.getWidth(), mDeferredLight.getHeight()); + + { + LLGLDisable blend(GL_BLEND); + LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS); + stop_glerror(); + mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); + stop_glerror(); + } + + unbindDeferredShader(gDeferredSunProgram); + } + mDeferredLight.flush(); + } + + stop_glerror(); + gGL.popMatrix(); + stop_glerror(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + stop_glerror(); + gGL.popMatrix(); + stop_glerror(); + + // Done by callers... + // + //target->bindTarget(); + // clear color buffer here - zeroing alpha (glow) is important or it will accumulate against sky + //glClearColor(0,0,0,0); + //target->clear(GL_COLOR_BUFFER_BIT); + + if (RenderDeferredAtmospheric) + { //apply sunlight contribution + LLFastTimer ftm(FTM_ATMOSPHERICS); + bindDeferredShader(gDeferredSoftenProgram); + { + LLGLDepthTest depth(GL_FALSE); + LLGLDisable blend(GL_BLEND); + LLGLDisable test(GL_ALPHA_TEST); + + //full screen blit + gGL.pushMatrix(); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_PROJECTION); + gGL.pushMatrix(); + gGL.loadIdentity(); + + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + + mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); + + gGL.popMatrix(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + gGL.popMatrix(); + } + + unbindDeferredShader(gDeferredSoftenProgram); + } + + { //render non-deferred geometry (fullbright, alpha, etc) + LLGLDisable blend(GL_BLEND); + LLGLDisable stencil(GL_STENCIL_TEST); + gGL.setSceneBlendType(LLRender::BT_ALPHA); + + gPipeline.pushRenderTypeMask(); + + gPipeline.andRenderTypeMask(LLPipeline::RENDER_TYPE_SKY, + LLPipeline::RENDER_TYPE_CLOUDS, + LLPipeline::RENDER_TYPE_WL_SKY, + LLPipeline::END_RENDER_TYPES); + + + renderGeomPostDeferred(*LLViewerCamera::getInstance(), false); + gPipeline.popRenderTypeMask(); + } + + BOOL render_local = RenderLocalLights; + + if (render_local) + { + gGL.setSceneBlendType(LLRender::BT_ADD); + std::list fullscreen_lights; + LLDrawable::drawable_list_t spot_lights; + LLDrawable::drawable_list_t fullscreen_spot_lights; + + for (U32 i = 0; i < 2; i++) + { + mTargetShadowSpotLight[i] = NULL; + } + + std::list light_colors; + + LLVertexBuffer::unbind(); + + { + bindDeferredShader(gDeferredLightProgram); + + if (mCubeVB.isNull()) + { + mCubeVB = ll_create_cube_vb(LLVertexBuffer::MAP_VERTEX, GL_STATIC_DRAW_ARB); + } + + mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + + LLGLDepthTest depth(GL_TRUE, GL_FALSE); + for (LLDrawable::drawable_set_t::iterator iter = mLights.begin(); iter != mLights.end(); ++iter) + { + LLDrawable* drawablep = *iter; + + LLVOVolume* volume = drawablep->getVOVolume(); + if (!volume) + { + continue; + } + + if (volume->isAttachment()) + { + if (!sRenderAttachedLights) + { + continue; + } + } + + + LLVector4a center; + center.load3(drawablep->getPositionAgent().mV); + const F32* c = center.getF32ptr(); + F32 s = volume->getLightRadius()*1.5f; + + LLColor3 col = volume->getLightColor(); + + if (col.magVecSquared() < 0.001f) + { + continue; + } + + if (s <= 0.001f) + { + continue; + } + + LLVector4a sa; + sa.splat(s); + if (camera->AABBInFrustumNoFarClip(center, sa) == 0) + { + continue; + } + + sVisibleLightCount++; + + if (camera->getOrigin().mV[0] > c[0] + s + 0.2f || + camera->getOrigin().mV[0] < c[0] - s - 0.2f || + camera->getOrigin().mV[1] > c[1] + s + 0.2f || + camera->getOrigin().mV[1] < c[1] - s - 0.2f || + camera->getOrigin().mV[2] > c[2] + s + 0.2f || + camera->getOrigin().mV[2] < c[2] - s - 0.2f) + { //draw box if camera is outside box + if (render_local) + { + if (volume->isLightSpotlight()) + { + drawablep->getVOVolume()->updateSpotLightPriority(); + spot_lights.push_back(drawablep); + continue; + } + + /*col.mV[0] = powf(col.mV[0], 2.2f); + col.mV[1] = powf(col.mV[1], 2.2f); + col.mV[2] = powf(col.mV[2], 2.2f);*/ + + LLFastTimer ftm(FTM_LOCAL_LIGHTS); + gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c); + gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); + gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); + gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); + gGL.syncMatrices(); + + mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center)); + stop_glerror(); + } + } + else + { + if (volume->isLightSpotlight()) + { + drawablep->getVOVolume()->updateSpotLightPriority(); + fullscreen_spot_lights.push_back(drawablep); + continue; + } + + glh::vec3f tc(c); + mat.mult_matrix_vec(tc); + + fullscreen_lights.push_back(LLVector4(tc.v[0], tc.v[1], tc.v[2], s)); + light_colors.push_back(LLVector4(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff()*0.5f)); + } + } + unbindDeferredShader(gDeferredLightProgram); + } + + if (!spot_lights.empty()) + { + LLGLDepthTest depth(GL_TRUE, GL_FALSE); + bindDeferredShader(gDeferredSpotLightProgram); + + mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + + gDeferredSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION); + + for (LLDrawable::drawable_list_t::iterator iter = spot_lights.begin(); iter != spot_lights.end(); ++iter) + { + LLFastTimer ftm(FTM_PROJECTORS); + LLDrawable* drawablep = *iter; + + LLVOVolume* volume = drawablep->getVOVolume(); + + LLVector4a center; + center.load3(drawablep->getPositionAgent().mV); + const F32* c = center.getF32ptr(); + F32 s = volume->getLightRadius()*1.5f; + + sVisibleLightCount++; + + setupSpotLight(gDeferredSpotLightProgram, drawablep); + + LLColor3 col = volume->getLightColor(); + /*col.mV[0] = powf(col.mV[0], 2.2f); + col.mV[1] = powf(col.mV[1], 2.2f); + col.mV[2] = powf(col.mV[2], 2.2f);*/ + + gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c); + gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); + gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); + gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); + gGL.syncMatrices(); + + mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center)); + } + gDeferredSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION); + unbindDeferredShader(gDeferredSpotLightProgram); + } + + //reset mDeferredVB to fullscreen triangle + mDeferredVB->getVertexStrider(vert); + vert[0].set(-1,1,0); + vert[1].set(-1,-3,0); + vert[2].set(3,1,0); + + { + LLGLDepthTest depth(GL_FALSE); + + //full screen blit + gGL.pushMatrix(); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_PROJECTION); + gGL.pushMatrix(); + gGL.loadIdentity(); + + U32 count = 0; + + const U32 max_count = LL_DEFERRED_MULTI_LIGHT_COUNT; + LLVector4 light[max_count]; + LLVector4 col[max_count]; + + F32 far_z = 0.f; + + while (!fullscreen_lights.empty()) + { + LLFastTimer ftm(FTM_FULLSCREEN_LIGHTS); + light[count] = fullscreen_lights.front(); + fullscreen_lights.pop_front(); + col[count] = light_colors.front(); + light_colors.pop_front(); + + /*col[count].mV[0] = powf(col[count].mV[0], 2.2f); + col[count].mV[1] = powf(col[count].mV[1], 2.2f); + col[count].mV[2] = powf(col[count].mV[2], 2.2f);*/ + + far_z = llmin(light[count].mV[2]-light[count].mV[3], far_z); + //col[count] = pow4fsrgb(col[count], 2.2f); + count++; + if (count == max_count || fullscreen_lights.empty()) + { + U32 idx = count-1; + bindDeferredShader(gDeferredMultiLightProgram[idx]); + gDeferredMultiLightProgram[idx].uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT, count); + gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT, count, (GLfloat*) light); + gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*) col); + gDeferredMultiLightProgram[idx].uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z, far_z); + far_z = 0.f; + count = 0; + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); + } + } + + unbindDeferredShader(gDeferredMultiLightProgram[0]); + + bindDeferredShader(gDeferredMultiSpotLightProgram); + + gDeferredMultiSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION); + + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + + for (LLDrawable::drawable_list_t::iterator iter = fullscreen_spot_lights.begin(); iter != fullscreen_spot_lights.end(); ++iter) + { + LLFastTimer ftm(FTM_PROJECTORS); + LLDrawable* drawablep = *iter; + + LLVOVolume* volume = drawablep->getVOVolume(); + + LLVector3 center = drawablep->getPositionAgent(); + F32* c = center.mV; + F32 s = volume->getLightRadius()*1.5f; + + sVisibleLightCount++; + + glh::vec3f tc(c); + mat.mult_matrix_vec(tc); + + setupSpotLight(gDeferredMultiSpotLightProgram, drawablep); + + LLColor3 col = volume->getLightColor(); + + /*col.mV[0] = powf(col.mV[0], 2.2f); + col.mV[1] = powf(col.mV[1], 2.2f); + col.mV[2] = powf(col.mV[2], 2.2f);*/ + + gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v); + gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); + gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); + gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); + mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); + } + + gDeferredMultiSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION); + unbindDeferredShader(gDeferredMultiSpotLightProgram); + + gGL.popMatrix(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + gGL.popMatrix(); + } + } + + gGL.setColorMask(true, true); + } + + target->flush(); + + //gamma correct lighting + gGL.matrixMode(LLRender::MM_PROJECTION); + gGL.pushMatrix(); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + gGL.pushMatrix(); + gGL.loadIdentity(); + + { + LLGLDepthTest depth(GL_FALSE, GL_FALSE); + + LLVector2 tc1(0,0); + LLVector2 tc2((F32) target->getWidth()*2, + (F32) target->getHeight()*2); + + target->bindTarget(); + // Apply gamma correction to the frame here. + gDeferredPostGammaCorrectProgram.bind(); + //mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + S32 channel = 0; + channel = gDeferredPostGammaCorrectProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, target->getUsage()); + if (channel > -1) + { + target->bindTexture(0,channel); + gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT); + } + + gDeferredPostGammaCorrectProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, target->getWidth(), target->getHeight()); + + F32 gamma = 1.0/2.2; + + gDeferredPostGammaCorrectProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, gamma); + + gGL.begin(LLRender::TRIANGLE_STRIP); + gGL.texCoord2f(tc1.mV[0], tc1.mV[1]); + gGL.vertex2f(-1,-1); + + gGL.texCoord2f(tc1.mV[0], tc2.mV[1]); + gGL.vertex2f(-1,3); + + gGL.texCoord2f(tc2.mV[0], tc1.mV[1]); + gGL.vertex2f(3,-1); + + gGL.end(); + + gGL.getTexUnit(channel)->unbind(target->getUsage()); + gDeferredPostGammaCorrectProgram.unbind(); + target->flush(); + } + + gGL.matrixMode(LLRender::MM_PROJECTION); + gGL.popMatrix(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + gGL.popMatrix(); + + target->bindTarget(); + + { //render non-deferred geometry (alpha, fullbright, glow) + LLGLDisable blend(GL_BLEND); + LLGLDisable stencil(GL_STENCIL_TEST); + + pushRenderTypeMask(); + andRenderTypeMask(LLPipeline::RENDER_TYPE_ALPHA, + LLPipeline::RENDER_TYPE_FULLBRIGHT, + LLPipeline::RENDER_TYPE_VOLUME, + LLPipeline::RENDER_TYPE_GLOW, + LLPipeline::RENDER_TYPE_BUMP, + LLPipeline::RENDER_TYPE_PASS_SIMPLE, + LLPipeline::RENDER_TYPE_PASS_ALPHA, + LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK, + LLPipeline::RENDER_TYPE_PASS_BUMP, + LLPipeline::RENDER_TYPE_PASS_POST_BUMP, + LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT, + LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK, + LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY, + LLPipeline::RENDER_TYPE_PASS_GLOW, + LLPipeline::RENDER_TYPE_PASS_GRASS, + LLPipeline::RENDER_TYPE_PASS_SHINY, + LLPipeline::RENDER_TYPE_PASS_INVISIBLE, + LLPipeline::RENDER_TYPE_PASS_INVISI_SHINY, + LLPipeline::RENDER_TYPE_AVATAR, + LLPipeline::RENDER_TYPE_ALPHA_MASK, + LLPipeline::RENDER_TYPE_FULLBRIGHT_ALPHA_MASK, + END_RENDER_TYPES); + + renderGeomPostDeferred(*LLViewerCamera::getInstance()); + popRenderTypeMask(); + } + + // Done by callers for flexibility + //target->flush(); +} + void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep) { //construct frustum @@ -9145,7 +9678,9 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) LLPipeline::sUseOcclusion = 0; gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); glClearColor(0,0,0,0); + mWaterRef.bindTarget(); + LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WATER0; gGL.setColorMask(true, true); mWaterRef.clear(); @@ -9182,19 +9717,39 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) if (LLDrawPoolWater::sNeedsReflectionUpdate) { - //initial sky pass (no user clip plane) - { //mask out everything but the sky - gPipeline.pushRenderTypeMask(); - gPipeline.andRenderTypeMask(LLPipeline::RENDER_TYPE_SKY, - LLPipeline::RENDER_TYPE_WL_SKY, - LLPipeline::RENDER_TYPE_CLOUDS, - LLPipeline::END_RENDER_TYPES); + //initial sky pass (no user clip plane) + { //mask out everything but the sky + gPipeline.pushRenderTypeMask(); + gPipeline.andRenderTypeMask(LLPipeline::RENDER_TYPE_SKY, + LLPipeline::RENDER_TYPE_WL_SKY, + LLPipeline::RENDER_TYPE_CLOUDS, + LLPipeline::END_RENDER_TYPES); - static LLCullResult result; - updateCull(camera, result); - stateSort(camera, result); + static LLCullResult result; + updateCull(camera, result); + stateSort(camera, result); - renderGeom(camera, TRUE); +#if MATERIALS_IN_REFLECTIONS + if (LLPipeline::sRenderDeferred) + { + gGL.setColorMask(true, true); + renderGeomDeferred(camera); + gPipeline.mDeferredScreen.flush(); + if(LLRenderTarget::sUseFBO) + { + LLRenderTarget::copyContentsToFramebuffer(gPipeline.mDeferredScreen, 0, 0, gPipeline.mDeferredScreen.getWidth(), + gPipeline.mDeferredScreen.getHeight(), 0, 0, + gPipeline.mDeferredScreen.getWidth(), + gPipeline.mDeferredScreen.getHeight(), + GL_DEPTH_BUFFER_BIT, GL_NEAREST); + } + renderDeferredLightingToRT(&mWaterRef); + } + else +#endif + { + renderGeom(camera, TRUE); + } gPipeline.popRenderTypeMask(); } @@ -9236,7 +9791,27 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) { gPipeline.grabReferences(ref_result); LLGLUserClipPlane clip_plane(plane, mat, projection); - renderGeom(camera); + +#if MATERIALS_IN_REFLECTIONS + if (LLPipeline::sRenderDeferred) + { + renderGeomDeferred(camera); + gPipeline.mDeferredScreen.flush(); + if(LLRenderTarget::sUseFBO) + { + LLRenderTarget::copyContentsToFramebuffer(gPipeline.mDeferredScreen, 0, 0, gPipeline.mDeferredScreen.getWidth(), + gPipeline.mDeferredScreen.getHeight(), 0, 0, + gPipeline.mDeferredScreen.getWidth(), + gPipeline.mDeferredScreen.getHeight(), + GL_DEPTH_BUFFER_BIT, GL_NEAREST); + } + renderDeferredLightingToRT(&mWaterRef); + } + else +#endif + { + renderGeom(camera); + } } } @@ -9293,9 +9868,28 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) gGL.setColorMask(true, true); mWaterDis.clear(); - gGL.setColorMask(true, false); +#if MATERIALS_IN_REFLECTIONS + if (LLPipeline::sRenderDeferred) + { + renderGeomDeferred(camera); + gPipeline.mDeferredScreen.flush(); + if(LLRenderTarget::sUseFBO) + { + LLRenderTarget::copyContentsToFramebuffer(gPipeline.mDeferredScreen, 0, 0, gPipeline.mDeferredScreen.getWidth(), + gPipeline.mDeferredScreen.getHeight(), 0, 0, + gPipeline.mDeferredScreen.getWidth(), + gPipeline.mDeferredScreen.getHeight(), + GL_DEPTH_BUFFER_BIT, GL_NEAREST); + } + renderDeferredLightingToRT(&mWaterDis); + } + else +#endif + { + gGL.setColorMask(true, false); renderGeom(camera); + } } diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index 2f0fc3491d..36b293b998 100755 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -288,6 +288,7 @@ public: void unbindDeferredShader(LLGLSLShader& shader); void renderDeferredLighting(); + void renderDeferredLightingToRT(LLRenderTarget* target); void generateWaterReflection(LLCamera& camera); void generateSunShadow(LLCamera& camera); -- cgit v1.2.3 From 5efee00a835a30f09637b2459134d458a9efa6cd Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 12 Jul 2013 13:01:31 -0700 Subject: NORSPEC-291 WIP added underwater deferred program and more reflection pass work --- .../shaders/class1/deferred/underWaterF.glsl | 120 +++++++++++ indra/newview/lldrawpoolwater.cpp | 9 +- indra/newview/llviewershadermgr.cpp | 17 ++ indra/newview/llviewershadermgr.h | 1 + indra/newview/pipeline.cpp | 220 ++++++++++++++++----- indra/newview/pipeline.h | 3 +- 6 files changed, 315 insertions(+), 55 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl new file mode 100644 index 0000000000..c160b38cfe --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -0,0 +1,120 @@ +/** + * @file underWaterF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif + +uniform sampler2D diffuseMap; +uniform sampler2D bumpMap; +uniform sampler2D screenTex; +uniform sampler2D refTex; +uniform sampler2D screenDepth; + +uniform vec4 fogCol; +uniform vec3 lightDir; +uniform vec3 specular; +uniform float lightExp; +uniform vec2 fbScale; +uniform float refScale; +uniform float znear; +uniform float zfar; +uniform float kd; +uniform vec4 waterPlane; +uniform vec3 eyeVec; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; +uniform vec2 screenRes; + +//bigWave is (refCoord.w, view.w); +VARYING vec4 refCoord; +VARYING vec4 littleWave; +VARYING vec4 view; + +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec4 applyWaterFog(vec4 color, vec3 viewVec) +{ + //normalize view vector + vec3 view = normalize(viewVec); + float es = -view.z; + + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + //get object depth + float depth = length(viewVec); + + //get "thickness" of water + float l = max(depth, 0.1); + + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2*l) - 1.0; + + float L = min(t1/t2*t3, 1.0); + + float D = pow(0.98, l*kd); + //return vec4(1.0, 0.0, 1.0, 1.0); + return color * D + kc * L; + //depth /= 10.0; + //return vec4(depth,depth,depth,0.0); +} + +void main() +{ + vec4 color; + + //get detail normals + vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; + vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + vec3 wavef = normalize(wave1+wave2+wave3); + + //figure out distortion vector (ripply) + vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; + distort = distort+wavef.xy*refScale; + + vec4 fb = texture2D(screenTex, distort); + + frag_data[0] = vec4(fb.rgb, 0.5); // diffuse + frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec + frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, displace +} diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp index 5b0b173926..6774926f62 100755 --- a/indra/newview/lldrawpoolwater.cpp +++ b/indra/newview/lldrawpoolwater.cpp @@ -524,7 +524,14 @@ void LLDrawPoolWater::shade() if (eyedepth < 0.f && LLPipeline::sWaterReflections) { - shader = &gUnderWaterProgram; + if (deferred_render) + { + shader = &gDeferredUnderWaterProgram; + } + else + { + shader = &gUnderWaterProgram; + } } else if (deferred_render) { diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 3df8115402..e9c3990e9a 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -168,6 +168,7 @@ LLGLSLShader gPostNightVisionProgram; // Deferred rendering shaders LLGLSLShader gDeferredImpostorProgram; LLGLSLShader gDeferredWaterProgram; +LLGLSLShader gDeferredUnderWaterProgram; LLGLSLShader gDeferredDiffuseProgram; LLGLSLShader gDeferredDiffuseAlphaMaskProgram; LLGLSLShader gDeferredNonIndexedDiffuseProgram; @@ -309,6 +310,7 @@ LLViewerShaderMgr::LLViewerShaderMgr() : mShaderList.push_back(&gDeferredEmissiveProgram); mShaderList.push_back(&gDeferredAvatarEyesProgram); mShaderList.push_back(&gDeferredWaterProgram); + mShaderList.push_back(&gDeferredUnderWaterProgram); mShaderList.push_back(&gDeferredAvatarAlphaProgram); mShaderList.push_back(&gDeferredWLSkyProgram); mShaderList.push_back(&gDeferredWLCloudProgram); @@ -1153,6 +1155,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredPostGammaCorrectProgram.unload(); gFXAAProgram.unload(); gDeferredWaterProgram.unload(); + gDeferredUnderWaterProgram.unload(); gDeferredWLSkyProgram.unload(); gDeferredWLCloudProgram.unload(); gDeferredStarProgram.unload(); @@ -1640,6 +1643,20 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() success = gDeferredWaterProgram.createShader(NULL, &mWaterUniforms); } + if (success) + { + // load water shader + gDeferredUnderWaterProgram.mName = "Deferred Under Water Shader"; + gDeferredUnderWaterProgram.mFeatures.calculatesAtmospherics = true; + gDeferredUnderWaterProgram.mFeatures.hasGamma = true; + gDeferredUnderWaterProgram.mFeatures.hasTransport = true; + gDeferredUnderWaterProgram.mShaderFiles.clear(); + gDeferredUnderWaterProgram.mShaderFiles.push_back(make_pair("deferred/waterV.glsl", GL_VERTEX_SHADER_ARB)); + gDeferredUnderWaterProgram.mShaderFiles.push_back(make_pair("deferred/underWaterF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredUnderWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + success = gDeferredUnderWaterProgram.createShader(NULL, &mWaterUniforms); + } + if (success) { gDeferredSoftenProgram.mName = "Deferred Soften Shader"; diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h index 5310076013..f14180d957 100755 --- a/indra/newview/llviewershadermgr.h +++ b/indra/newview/llviewershadermgr.h @@ -330,6 +330,7 @@ extern LLGLSLShader gPostNightVisionProgram; // Deferred rendering shaders extern LLGLSLShader gDeferredImpostorProgram; extern LLGLSLShader gDeferredWaterProgram; +extern LLGLSLShader gDeferredUnderWaterProgram; extern LLGLSLShader gDeferredDiffuseProgram; extern LLGLSLShader gDeferredDiffuseAlphaMaskProgram; extern LLGLSLShader gDeferredNonIndexedDiffuseAlphaMaskProgram; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index cac347b3a5..4e1eb4d8ad 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -122,6 +122,10 @@ //#define DEBUG_INDICES #endif +// Expensive and currently broken... +// +#define MATERIALS_IN_REFLECTIONS 0 + bool gShiftFrame = false; //cached settings @@ -4647,6 +4651,103 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera) gGL.setColorMask(true, false); } +void LLPipeline::renderGeomDeferredToRT(LLCamera& camera) +{ + LLAppViewer::instance()->pingMainloopTimeout("Pipeline:RenderGeomDeferred"); + + LLFastTimer t(FTM_RENDER_GEOMETRY); + LLFastTimer t2(FTM_DEFERRED_POOLS); + + LLGLEnable cull(GL_CULL_FACE); + + LLGLEnable stencil(GL_STENCIL_TEST); + glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF); + stop_glerror(); + glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + stop_glerror(); + + for (pool_set_t::iterator iter = mPools.begin(); iter != mPools.end(); ++iter) + { + LLDrawPool *poolp = *iter; + if (hasRenderType(poolp->getType())) + { + poolp->prerender(); + } + } + + LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE_ARB : 0); + + LLVertexBuffer::unbind(); + + LLGLState::checkStates(); + LLGLState::checkTextureChannels(); + LLGLState::checkClientArrays(); + + U32 cur_type = 0; + + gGL.setColorMask(true, true); + + pool_set_t::iterator iter1 = mPools.begin(); + + while ( iter1 != mPools.end() ) + { + LLDrawPool *poolp = *iter1; + + cur_type = poolp->getType(); + + pool_set_t::iterator iter2 = iter1; + if (hasRenderType(poolp->getType()) && poolp->getNumDeferredPasses() > 0) + { + LLFastTimer t(FTM_DEFERRED_POOLRENDER); + + gGLLastMatrix = NULL; + gGL.loadMatrix(gGLModelView); + + for( S32 i = 0; i < poolp->getNumDeferredPasses(); i++ ) + { + LLVertexBuffer::unbind(); + poolp->beginDeferredPass(i); + for (iter2 = iter1; iter2 != mPools.end(); iter2++) + { + LLDrawPool *p = *iter2; + if (p->getType() != cur_type) + { + break; + } + + if ( !p->getSkipRenderFlag() ) { p->renderDeferred(i); } + } + poolp->endDeferredPass(i); + LLVertexBuffer::unbind(); + + if (gDebugGL || gDebugPipeline) + { + LLGLState::checkStates(); + } + } + } + else + { + // Skip all pools of this type + for (iter2 = iter1; iter2 != mPools.end(); iter2++) + { + LLDrawPool *p = *iter2; + if (p->getType() != cur_type) + { + break; + } + } + } + iter1 = iter2; + stop_glerror(); + } + + gGLLastMatrix = NULL; + gGL.loadMatrix(gGLModelView); + + gGL.setColorMask(true, false); +} + void LLPipeline::renderGeomPostDeferred(LLCamera& camera, bool do_occlusion) { LLFastTimer t(FTM_POST_DEFERRED_POOLS); @@ -8047,10 +8148,12 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield) static LLFastTimer::DeclareTimer FTM_BIND_DEFERRED("Bind Deferred"); -void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 noise_map) +void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, LLRenderTarget* alternative_target, U32 noise_map) { LLFastTimer t(FTM_BIND_DEFERRED); + LLRenderTarget* render_target = alternative_target ? alternative_target : &mScreen; + if (noise_map == 0xFFFFFFFF) { noise_map = mNoiseMap; @@ -8120,7 +8223,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 n { if (light_index > 0) { - mScreen.bindTexture(0, channel); + render_target->bindTexture(0, channel); } else { @@ -8903,11 +9006,11 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) LLViewerCamera* camera = LLViewerCamera::getInstance(); - /*{ + { LLGLDepthTest depth(GL_TRUE); mDeferredDepth.copyContents(mDeferredScreen, 0, 0, mDeferredScreen.getWidth(), mDeferredScreen.getHeight(), 0, 0, mDeferredDepth.getWidth(), mDeferredDepth.getHeight(), GL_DEPTH_BUFFER_BIT, GL_NEAREST); - }*/ + } LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE_ARB : 0); @@ -8957,7 +9060,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) mDeferredLight.bindTarget(); { //paint shadow/SSAO light map (direct lighting lightmap) LLFastTimer ftm(FTM_SUN_SHADOW); - bindDeferredShader(gDeferredSunProgram, 0); + bindDeferredShader(gDeferredSunProgram, 0, target); mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); glClearColor(1,1,1,1); mDeferredLight.clear(GL_COLOR_BUFFER_BIT); @@ -9006,17 +9109,16 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) gGL.popMatrix(); stop_glerror(); - // Done by callers... - // - //target->bindTarget(); - // clear color buffer here - zeroing alpha (glow) is important or it will accumulate against sky - //glClearColor(0,0,0,0); + target->bindTarget(); + + //clear color buffer here - zeroing alpha (glow) is important or it will accumulate against sky + //glClearColor(0,1,0,0); //target->clear(GL_COLOR_BUFFER_BIT); if (RenderDeferredAtmospheric) { //apply sunlight contribution LLFastTimer ftm(FTM_ATMOSPHERICS); - bindDeferredShader(gDeferredSoftenProgram); + bindDeferredShader(gDeferredSoftenProgram,0,target); { LLGLDepthTest depth(GL_FALSE); LLGLDisable blend(GL_BLEND); @@ -9077,7 +9179,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) LLVertexBuffer::unbind(); { - bindDeferredShader(gDeferredLightProgram); + bindDeferredShader(gDeferredLightProgram, 0, target); if (mCubeVB.isNull()) { @@ -9185,7 +9287,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) if (!spot_lights.empty()) { LLGLDepthTest depth(GL_TRUE, GL_FALSE); - bindDeferredShader(gDeferredSpotLightProgram); + bindDeferredShader(gDeferredSpotLightProgram,0, target); mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX); @@ -9266,7 +9368,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) if (count == max_count || fullscreen_lights.empty()) { U32 idx = count-1; - bindDeferredShader(gDeferredMultiLightProgram[idx]); + bindDeferredShader(gDeferredMultiLightProgram[idx],0, target); gDeferredMultiLightProgram[idx].uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT, count); gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT, count, (GLfloat*) light); gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*) col); @@ -9280,7 +9382,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) unbindDeferredShader(gDeferredMultiLightProgram[0]); - bindDeferredShader(gDeferredMultiSpotLightProgram); + bindDeferredShader(gDeferredMultiSpotLightProgram, 0, target); gDeferredMultiSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION); @@ -9420,8 +9522,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) popRenderTypeMask(); } - // Done by callers for flexibility - //target->flush(); + target->flush(); } void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep) @@ -9733,17 +9834,12 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) if (LLPipeline::sRenderDeferred) { gGL.setColorMask(true, true); - renderGeomDeferred(camera); - gPipeline.mDeferredScreen.flush(); - if(LLRenderTarget::sUseFBO) - { - LLRenderTarget::copyContentsToFramebuffer(gPipeline.mDeferredScreen, 0, 0, gPipeline.mDeferredScreen.getWidth(), - gPipeline.mDeferredScreen.getHeight(), 0, 0, - gPipeline.mDeferredScreen.getWidth(), - gPipeline.mDeferredScreen.getHeight(), - GL_DEPTH_BUFFER_BIT, GL_NEAREST); - } - renderDeferredLightingToRT(&mWaterRef); + gPipeline.mDeferredScreen.bindTarget(); + glClearColor(0,0,0,0); + gPipeline.mDeferredScreen.clear(); + + LLGLDepthTest d(GL_FALSE,GL_FALSE); + renderGeomDeferred(camera); } else #endif @@ -9754,6 +9850,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) gPipeline.popRenderTypeMask(); } + gGL.setColorMask(true, false); gPipeline.pushRenderTypeMask(); clearRenderTypeMask(LLPipeline::RENDER_TYPE_WATER, @@ -9795,26 +9892,30 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) #if MATERIALS_IN_REFLECTIONS if (LLPipeline::sRenderDeferred) { + LLGLDepthTest d(GL_FALSE,GL_FALSE); renderGeomDeferred(camera); - gPipeline.mDeferredScreen.flush(); - if(LLRenderTarget::sUseFBO) - { - LLRenderTarget::copyContentsToFramebuffer(gPipeline.mDeferredScreen, 0, 0, gPipeline.mDeferredScreen.getWidth(), - gPipeline.mDeferredScreen.getHeight(), 0, 0, - gPipeline.mDeferredScreen.getWidth(), - gPipeline.mDeferredScreen.getHeight(), - GL_DEPTH_BUFFER_BIT, GL_NEAREST); - } - renderDeferredLightingToRT(&mWaterRef); } else #endif { renderGeom(camera); - } + } } } +#if MATERIALS_IN_REFLECTIONS + if (LLPipeline::sRenderDeferred) + { + gPipeline.mDeferredScreen.flush(); + gPipeline.mWaterRef.copyContents(gPipeline.mDeferredScreen, + 0, 0, gPipeline.mDeferredScreen.getWidth(), gPipeline.mDeferredScreen.getHeight(), + 0, 0, gPipeline.mWaterRef.getWidth(), gPipeline.mWaterRef.getHeight(), + 0, GL_NEAREST); + mWaterRef.flush(); + renderDeferredLightingToRT(&mWaterRef); + } +#endif + gPipeline.popRenderTypeMask(); } glCullFace(GL_BACK); @@ -9849,10 +9950,12 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) LLViewerCamera::updateFrustumPlanes(camera); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + LLColor4& col = LLDrawPoolWater::sWaterFogColor; glClearColor(col.mV[0], col.mV[1], col.mV[2], 0.f); mWaterDis.bindTarget(); LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WATER1; + mWaterDis.getViewport(gGLViewport); if (!LLPipeline::sUnderWaterRender || LLDrawPoolWater::sNeedsReflectionUpdate) @@ -9868,33 +9971,44 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) gGL.setColorMask(true, true); mWaterDis.clear(); + gGL.setColorMask(true, false); #if MATERIALS_IN_REFLECTIONS if (LLPipeline::sRenderDeferred) - { + { + + gPipeline.mDeferredScreen.bindTarget(); + gGL.setColorMask(true, true); + glClearColor(1,0,1,0); + gPipeline.mDeferredScreen.clear(); + renderGeomDeferred(camera); + gPipeline.mDeferredScreen.flush(); - if(LLRenderTarget::sUseFBO) - { - LLRenderTarget::copyContentsToFramebuffer(gPipeline.mDeferredScreen, 0, 0, gPipeline.mDeferredScreen.getWidth(), - gPipeline.mDeferredScreen.getHeight(), 0, 0, - gPipeline.mDeferredScreen.getWidth(), - gPipeline.mDeferredScreen.getHeight(), - GL_DEPTH_BUFFER_BIT, GL_NEAREST); - } - renderDeferredLightingToRT(&mWaterDis); + + mWaterDis.copyContents(gPipeline.mDeferredScreen, + 0, 0, gPipeline.mDeferredScreen.getWidth(), gPipeline.mDeferredScreen.getHeight(), + 0, 0, gPipeline.mWaterDis.getWidth(), gPipeline.mWaterDis.getHeight(), + 0, GL_NEAREST); + mWaterDis.flush(); } else #endif { - gGL.setColorMask(true, false); - renderGeom(camera); + renderGeom(camera); } - + +#if MATERIALS_IN_REFLECTIONS + if (LLPipeline::sRenderDeferred) + { + renderDeferredLightingToRT(&mWaterDis); + } +#endif } - LLPipeline::sUnderWaterRender = FALSE; mWaterDis.flush(); + LLPipeline::sUnderWaterRender = FALSE; + } last_update = LLDrawPoolWater::sNeedsReflectionUpdate && LLDrawPoolWater::sNeedsDistortionUpdate; diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index 36b293b998..8764616fba 100755 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -281,9 +281,10 @@ public: void renderGeom(LLCamera& camera, BOOL forceVBOUpdate = FALSE); void renderGeomDeferred(LLCamera& camera); + void renderGeomDeferredToRT(LLCamera& camera); void renderGeomPostDeferred(LLCamera& camera, bool do_occlusion=true); void renderGeomShadow(LLCamera& camera); - void bindDeferredShader(LLGLSLShader& shader, U32 light_index = 0, U32 noise_map = 0xFFFFFFFF); + void bindDeferredShader(LLGLSLShader& shader, U32 light_index = 0, LLRenderTarget* alternative_target = NULL, U32 noise_map = 0xFFFFFFFF); void setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep); void unbindDeferredShader(LLGLSLShader& shader); -- cgit v1.2.3 From 7acf6fa449a1a8383f4cf1291dbebeff5f98283a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 15 Jul 2013 08:40:17 -0700 Subject: NORSPEC-291 WIP materials working underwater and in reflection and dis passes, not gamma correct, needs cleanup --- indra/newview/pipeline.cpp | 75 +++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 4e1eb4d8ad..e5ea7d0381 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -124,7 +124,7 @@ // Expensive and currently broken... // -#define MATERIALS_IN_REFLECTIONS 0 +#define MATERIALS_IN_REFLECTIONS 1 bool gShiftFrame = false; @@ -1239,8 +1239,23 @@ void LLPipeline::createGLBuffers() if (LLPipeline::sWaterReflections) { //water reflection texture U32 res = (U32) llmax(gSavedSettings.getS32("RenderWaterRefResolution"), 512); - - mWaterRef.allocate(res,res,GL_RGBA,TRUE,FALSE); + +#if MATERIALS_IN_REFLECTIONS + if (LLPipeline::sRenderDeferred) + { + mWaterRef.allocate(res,res,GL_SRGB8_ALPHA8,TRUE,FALSE); + } + else +#endif + mWaterRef.allocate(res,res,GL_RGBA,TRUE,FALSE); + +#if MATERIALS_IN_REFLECTIONS + if (LLPipeline::sRenderDeferred) + { + mWaterDis.allocate(res,res,GL_SRGB8_ALPHA8,TRUE,FALSE,LLTexUnit::TT_TEXTURE, true); + } + else +#endif //always use FBO for mWaterDis so it can be used for avatar texture bakes mWaterDis.allocate(res,res,GL_RGBA,TRUE,FALSE,LLTexUnit::TT_TEXTURE, true); } @@ -8152,7 +8167,8 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, LLRen { LLFastTimer t(FTM_BIND_DEFERRED); - LLRenderTarget* render_target = alternative_target ? alternative_target : &mScreen; + (void)alternative_target; + //LLRenderTarget* render_target = alternative_target ? alternative_target : &mScreen; if (noise_map == 0xFFFFFFFF) { @@ -8221,11 +8237,11 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, LLRen channel = shader.enableTexture(LLShaderMgr::DEFERRED_LIGHT, mDeferredLight.getUsage()); if (channel > -1) { - if (light_index > 0) + /*if (light_index > 0) { render_target->bindTexture(0, channel); } - else + else*/ { mDeferredLight.bindTexture(0, channel); } @@ -9112,8 +9128,8 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) target->bindTarget(); //clear color buffer here - zeroing alpha (glow) is important or it will accumulate against sky - //glClearColor(0,1,0,0); - //target->clear(GL_COLOR_BUFFER_BIT); + glClearColor(0,0,0,0); + target->clear(GL_COLOR_BUFFER_BIT); if (RenderDeferredAtmospheric) { //apply sunlight contribution @@ -9431,7 +9447,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) gGL.setColorMask(true, true); } - target->flush(); + /*target->flush(); //gamma correct lighting gGL.matrixMode(LLRender::MM_PROJECTION); @@ -9488,7 +9504,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.popMatrix(); - target->bindTarget(); + target->bindTarget();*/ { //render non-deferred geometry (alpha, fullbright, glow) LLGLDisable blend(GL_BLEND); @@ -9522,7 +9538,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) popRenderTypeMask(); } - target->flush(); + //target->flush(); } void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep) @@ -9833,12 +9849,14 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) #if MATERIALS_IN_REFLECTIONS if (LLPipeline::sRenderDeferred) { - gGL.setColorMask(true, true); + mWaterRef.flush(); + + gPipeline.grabReferences(result); gPipeline.mDeferredScreen.bindTarget(); + gGL.setColorMask(true, true); glClearColor(0,0,0,0); gPipeline.mDeferredScreen.clear(); - LLGLDepthTest d(GL_FALSE,GL_FALSE); renderGeomDeferred(camera); } else @@ -9891,8 +9909,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) #if MATERIALS_IN_REFLECTIONS if (LLPipeline::sRenderDeferred) - { - LLGLDepthTest d(GL_FALSE,GL_FALSE); + { renderGeomDeferred(camera); } else @@ -9907,11 +9924,6 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) if (LLPipeline::sRenderDeferred) { gPipeline.mDeferredScreen.flush(); - gPipeline.mWaterRef.copyContents(gPipeline.mDeferredScreen, - 0, 0, gPipeline.mDeferredScreen.getWidth(), gPipeline.mDeferredScreen.getHeight(), - 0, 0, gPipeline.mWaterRef.getWidth(), gPipeline.mWaterRef.getHeight(), - 0, GL_NEAREST); - mWaterRef.flush(); renderDeferredLightingToRT(&mWaterRef); } #endif @@ -9971,26 +9983,20 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) gGL.setColorMask(true, true); mWaterDis.clear(); + + gGL.setColorMask(true, false); #if MATERIALS_IN_REFLECTIONS + mWaterDis.flush(); if (LLPipeline::sRenderDeferred) - { - + { gPipeline.mDeferredScreen.bindTarget(); gGL.setColorMask(true, true); - glClearColor(1,0,1,0); + glClearColor(0,0,0,0); gPipeline.mDeferredScreen.clear(); - - renderGeomDeferred(camera); - - gPipeline.mDeferredScreen.flush(); - - mWaterDis.copyContents(gPipeline.mDeferredScreen, - 0, 0, gPipeline.mDeferredScreen.getWidth(), gPipeline.mDeferredScreen.getHeight(), - 0, 0, gPipeline.mWaterDis.getWidth(), gPipeline.mWaterDis.getHeight(), - 0, GL_NEAREST); - mWaterDis.flush(); + gPipeline.grabReferences(result); + renderGeomDeferred(camera); } else #endif @@ -10000,7 +10006,8 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) #if MATERIALS_IN_REFLECTIONS if (LLPipeline::sRenderDeferred) - { + { + gPipeline.mDeferredScreen.flush(); renderDeferredLightingToRT(&mWaterDis); } #endif -- cgit v1.2.3 From a09d1ac79ab2172de11d6a3e08965ee6e2f5537a Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 15 Jul 2013 11:49:31 -0700 Subject: NORSPEC-291 WIP clean-up and make materials rendering underwater a runtime setting --- indra/newview/app_settings/settings.xml | 11 +++ indra/newview/pipeline.cpp | 169 ++++++-------------------------- indra/newview/pipeline.h | 3 +- 3 files changed, 42 insertions(+), 141 deletions(-) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index ebb01fb330..2d3b32159a 100755 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -9621,6 +9621,17 @@ Value 1 + RenderWaterMaterials + + Comment + Water planar reflections include materials rendering. + Persist + 1 + Type + S32 + Value + 0 + RenderWaterMipNormal Comment diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index e5ea7d0381..ad082b5c74 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -122,7 +122,7 @@ //#define DEBUG_INDICES #endif -// Expensive and currently broken... +// Expensive // #define MATERIALS_IN_REFLECTIONS 1 @@ -1236,28 +1236,26 @@ void LLPipeline::createGLBuffers() updateRenderDeferred(); + bool materials_in_water = gSavedSettings.getS32("RenderWaterMaterials"); + if (LLPipeline::sWaterReflections) { //water reflection texture U32 res = (U32) llmax(gSavedSettings.getS32("RenderWaterRefResolution"), 512); -#if MATERIALS_IN_REFLECTIONS - if (LLPipeline::sRenderDeferred) + // Set up SRGB targets if we're doing deferred-path reflection rendering + // + if (LLPipeline::sRenderDeferred && materials_in_water) { mWaterRef.allocate(res,res,GL_SRGB8_ALPHA8,TRUE,FALSE); + //always use FBO for mWaterDis so it can be used for avatar texture bakes + mWaterDis.allocate(res,res,GL_SRGB8_ALPHA8,TRUE,FALSE,LLTexUnit::TT_TEXTURE, true); } else -#endif - mWaterRef.allocate(res,res,GL_RGBA,TRUE,FALSE); - -#if MATERIALS_IN_REFLECTIONS - if (LLPipeline::sRenderDeferred) { - mWaterDis.allocate(res,res,GL_SRGB8_ALPHA8,TRUE,FALSE,LLTexUnit::TT_TEXTURE, true); + mWaterRef.allocate(res,res,GL_RGBA,TRUE,FALSE); + //always use FBO for mWaterDis so it can be used for avatar texture bakes + mWaterDis.allocate(res,res,GL_RGBA,TRUE,FALSE,LLTexUnit::TT_TEXTURE, true); } - else -#endif - //always use FBO for mWaterDis so it can be used for avatar texture bakes - mWaterDis.allocate(res,res,GL_RGBA,TRUE,FALSE,LLTexUnit::TT_TEXTURE, true); } mHighlight.allocate(256,256,GL_RGBA, FALSE, FALSE); @@ -4666,103 +4664,6 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera) gGL.setColorMask(true, false); } -void LLPipeline::renderGeomDeferredToRT(LLCamera& camera) -{ - LLAppViewer::instance()->pingMainloopTimeout("Pipeline:RenderGeomDeferred"); - - LLFastTimer t(FTM_RENDER_GEOMETRY); - LLFastTimer t2(FTM_DEFERRED_POOLS); - - LLGLEnable cull(GL_CULL_FACE); - - LLGLEnable stencil(GL_STENCIL_TEST); - glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF); - stop_glerror(); - glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); - stop_glerror(); - - for (pool_set_t::iterator iter = mPools.begin(); iter != mPools.end(); ++iter) - { - LLDrawPool *poolp = *iter; - if (hasRenderType(poolp->getType())) - { - poolp->prerender(); - } - } - - LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE_ARB : 0); - - LLVertexBuffer::unbind(); - - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); - - U32 cur_type = 0; - - gGL.setColorMask(true, true); - - pool_set_t::iterator iter1 = mPools.begin(); - - while ( iter1 != mPools.end() ) - { - LLDrawPool *poolp = *iter1; - - cur_type = poolp->getType(); - - pool_set_t::iterator iter2 = iter1; - if (hasRenderType(poolp->getType()) && poolp->getNumDeferredPasses() > 0) - { - LLFastTimer t(FTM_DEFERRED_POOLRENDER); - - gGLLastMatrix = NULL; - gGL.loadMatrix(gGLModelView); - - for( S32 i = 0; i < poolp->getNumDeferredPasses(); i++ ) - { - LLVertexBuffer::unbind(); - poolp->beginDeferredPass(i); - for (iter2 = iter1; iter2 != mPools.end(); iter2++) - { - LLDrawPool *p = *iter2; - if (p->getType() != cur_type) - { - break; - } - - if ( !p->getSkipRenderFlag() ) { p->renderDeferred(i); } - } - poolp->endDeferredPass(i); - LLVertexBuffer::unbind(); - - if (gDebugGL || gDebugPipeline) - { - LLGLState::checkStates(); - } - } - } - else - { - // Skip all pools of this type - for (iter2 = iter1; iter2 != mPools.end(); iter2++) - { - LLDrawPool *p = *iter2; - if (p->getType() != cur_type) - { - break; - } - } - } - iter1 = iter2; - stop_glerror(); - } - - gGLLastMatrix = NULL; - gGL.loadMatrix(gGLModelView); - - gGL.setColorMask(true, false); -} - void LLPipeline::renderGeomPostDeferred(LLCamera& camera, bool do_occlusion) { LLFastTimer t(FTM_POST_DEFERRED_POOLS); @@ -8163,13 +8064,10 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield) static LLFastTimer::DeclareTimer FTM_BIND_DEFERRED("Bind Deferred"); -void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, LLRenderTarget* alternative_target, U32 noise_map) +void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 noise_map) { LLFastTimer t(FTM_BIND_DEFERRED); - (void)alternative_target; - //LLRenderTarget* render_target = alternative_target ? alternative_target : &mScreen; - if (noise_map == 0xFFFFFFFF) { noise_map = mNoiseMap; @@ -8237,11 +8135,11 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, LLRen channel = shader.enableTexture(LLShaderMgr::DEFERRED_LIGHT, mDeferredLight.getUsage()); if (channel > -1) { - /*if (light_index > 0) + if (light_index > 0) { - render_target->bindTexture(0, channel); + mScreen.bindTexture(0, channel); } - else*/ + else { mDeferredLight.bindTexture(0, channel); } @@ -9076,7 +8974,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) mDeferredLight.bindTarget(); { //paint shadow/SSAO light map (direct lighting lightmap) LLFastTimer ftm(FTM_SUN_SHADOW); - bindDeferredShader(gDeferredSunProgram, 0, target); + bindDeferredShader(gDeferredSunProgram); mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); glClearColor(1,1,1,1); mDeferredLight.clear(GL_COLOR_BUFFER_BIT); @@ -9134,7 +9032,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) if (RenderDeferredAtmospheric) { //apply sunlight contribution LLFastTimer ftm(FTM_ATMOSPHERICS); - bindDeferredShader(gDeferredSoftenProgram,0,target); + bindDeferredShader(gDeferredSoftenProgram); { LLGLDepthTest depth(GL_FALSE); LLGLDisable blend(GL_BLEND); @@ -9195,7 +9093,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) LLVertexBuffer::unbind(); { - bindDeferredShader(gDeferredLightProgram, 0, target); + bindDeferredShader(gDeferredLightProgram); if (mCubeVB.isNull()) { @@ -9303,7 +9201,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) if (!spot_lights.empty()) { LLGLDepthTest depth(GL_TRUE, GL_FALSE); - bindDeferredShader(gDeferredSpotLightProgram,0, target); + bindDeferredShader(gDeferredSpotLightProgram); mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX); @@ -9384,7 +9282,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) if (count == max_count || fullscreen_lights.empty()) { U32 idx = count-1; - bindDeferredShader(gDeferredMultiLightProgram[idx],0, target); + bindDeferredShader(gDeferredMultiLightProgram[idx]); gDeferredMultiLightProgram[idx].uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT, count); gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT, count, (GLfloat*) light); gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*) col); @@ -9398,7 +9296,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) unbindDeferredShader(gDeferredMultiLightProgram[0]); - bindDeferredShader(gDeferredMultiSpotLightProgram, 0, target); + bindDeferredShader(gDeferredMultiSpotLightProgram); gDeferredMultiSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION); @@ -9787,6 +9685,8 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) water_clip = 1; } + bool materials_in_water = gSavedSettings.getS32("RenderWaterMaterials"); + if (!LLViewerCamera::getInstance()->cameraUnderWater()) { //generate planar reflection map @@ -9846,8 +9746,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) updateCull(camera, result); stateSort(camera, result); -#if MATERIALS_IN_REFLECTIONS - if (LLPipeline::sRenderDeferred) + if (LLPipeline::sRenderDeferred && materials_in_water) { mWaterRef.flush(); @@ -9860,7 +9759,6 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) renderGeomDeferred(camera); } else -#endif { renderGeom(camera, TRUE); } @@ -9907,26 +9805,22 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) gPipeline.grabReferences(ref_result); LLGLUserClipPlane clip_plane(plane, mat, projection); -#if MATERIALS_IN_REFLECTIONS - if (LLPipeline::sRenderDeferred) + if (LLPipeline::sRenderDeferred && materials_in_water) { renderGeomDeferred(camera); } else -#endif { renderGeom(camera); } } } -#if MATERIALS_IN_REFLECTIONS - if (LLPipeline::sRenderDeferred) + if (LLPipeline::sRenderDeferred && materials_in_water) { gPipeline.mDeferredScreen.flush(); renderDeferredLightingToRT(&mWaterRef); } -#endif gPipeline.popRenderTypeMask(); } @@ -9987,10 +9881,10 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) gGL.setColorMask(true, false); -#if MATERIALS_IN_REFLECTIONS - mWaterDis.flush(); - if (LLPipeline::sRenderDeferred) + + if (LLPipeline::sRenderDeferred && materials_in_water) { + mWaterDis.flush(); gPipeline.mDeferredScreen.bindTarget(); gGL.setColorMask(true, true); glClearColor(0,0,0,0); @@ -9999,18 +9893,15 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) renderGeomDeferred(camera); } else -#endif { renderGeom(camera); } -#if MATERIALS_IN_REFLECTIONS - if (LLPipeline::sRenderDeferred) + if (LLPipeline::sRenderDeferred && materials_in_water) { gPipeline.mDeferredScreen.flush(); renderDeferredLightingToRT(&mWaterDis); } -#endif } mWaterDis.flush(); diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index 8764616fba..36b293b998 100755 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -281,10 +281,9 @@ public: void renderGeom(LLCamera& camera, BOOL forceVBOUpdate = FALSE); void renderGeomDeferred(LLCamera& camera); - void renderGeomDeferredToRT(LLCamera& camera); void renderGeomPostDeferred(LLCamera& camera, bool do_occlusion=true); void renderGeomShadow(LLCamera& camera); - void bindDeferredShader(LLGLSLShader& shader, U32 light_index = 0, LLRenderTarget* alternative_target = NULL, U32 noise_map = 0xFFFFFFFF); + void bindDeferredShader(LLGLSLShader& shader, U32 light_index = 0, U32 noise_map = 0xFFFFFFFF); void setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep); void unbindDeferredShader(LLGLSLShader& shader); -- cgit v1.2.3 From a540ae81c42f1c7be87bda73d060b7ba8eaa0654 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 15 Jul 2013 13:46:01 -0700 Subject: NORSPEC-291 first attempt at gamma correction of materials in reflections --- .../shaders/class1/deferred/underWaterF.glsl | 22 +++++++++++++++- .../shaders/class1/deferred/waterF.glsl | 29 +++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index c160b38cfe..938947bbce 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -56,6 +56,26 @@ VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} + vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -114,7 +134,7 @@ void main() vec4 fb = texture2D(screenTex, distort); - frag_data[0] = vec4(fb.rgb, 0.5); // diffuse + frag_data[0] = vec4(linear_to_srgb(fb.rgb), 1.0); // diffuse frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, displace } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index daa2fb390a..17288873c8 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -67,6 +67,26 @@ VARYING vec4 littleWave; VARYING vec4 view; VARYING vec4 vary_position; +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} + vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -116,6 +136,10 @@ void main() vec2 refvec3 = distort+refdistort3/dmod_scale; vec4 refcol3 = texture2D(refTex, refvec3); + refcol1.rgb = srgb_to_linear(refcol1.rgb); + refcol2.rgb = srgb_to_linear(refcol2.rgb); + refcol3.rgb = srgb_to_linear(refcol3.rgb); + vec4 refcol = refcol1 + refcol2 + refcol3; float df1 = df.x + df.y + df.z; refcol *= df1 * 0.333; @@ -131,6 +155,9 @@ void main() vec2 refvec4 = distort+refdistort4/dmod; float dweight = min(dist2*blurMultiplier, 1.0); vec4 baseCol = texture2D(refTex, refvec4); + + baseCol.rgb = srgb_to_linear(baseCol.rgb); + refcol = mix(baseCol*df2, refcol, dweight); //get specular component @@ -165,7 +192,7 @@ void main() //wavef = normalize(wavef); vec3 screenspacewavef = (norm_mat*vec4(wavef, 1.0)).xyz; - frag_data[0] = vec4(color.rgb, 0.5); // diffuse + frag_data[0] = vec4(linear_to_srgb(color.rgb), 0.5); // diffuse frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec frag_data[2] = vec4(encode_normal(screenspacewavef), 0.0, 0.0); // normalxyz, displace } -- cgit v1.2.3 From 749eef31fa7b33438e1e110faf584512d75338a4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 15 Jul 2013 17:38:38 -0700 Subject: NORSPEC-265 WIP imposters work in non-deferred and ALM but are forward-only render --- indra/newview/lldrawpoolavatar.cpp | 8 +++++++- indra/newview/pipeline.cpp | 20 +++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index 59c9cf5a83..87e9071c4d 100755 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -681,12 +681,16 @@ void LLDrawPoolAvatar::beginDeferredImpostor() LLVOAvatar::sNumVisibleAvatars = 0; } +#if DEFERRED_IMPOSTORS sVertexProgram = &gDeferredImpostorProgram; specular_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::SPECULAR_MAP); normal_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::DEFERRED_NORMAL); sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); - +#else + sVertexProgram = &gImpostorProgram; + sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); +#endif sVertexProgram->bind(); sVertexProgram->setMinimumAlpha(0.01f); } @@ -1248,6 +1252,7 @@ void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, S32 pass) if (impostor) { +#if DEFERRED_IMPOSTORS if (LLPipeline::sRenderDeferred && !LLPipeline::sReflectionRender && avatarp->mImpostor.isComplete()) { if (normal_channel > -1) @@ -1259,6 +1264,7 @@ void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, S32 pass) avatarp->mImpostor.bindTexture(1, specular_channel); } } +#endif avatarp->renderImpostor(LLColor4U(255,255,255,255), sDiffuseChannel); } return; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index ad082b5c74..fc79f1c31f 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -11254,7 +11254,7 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) S32 occlusion = sUseOcclusion; sUseOcclusion = 0; - sReflectionRender = sRenderDeferred ? FALSE : TRUE; + //sReflectionRender = sRenderDeferred ? FALSE : TRUE; sShadowRender = TRUE; sImpostorRender = TRUE; @@ -11351,25 +11351,27 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) LLFastTimer t(FTM_IMPOSTOR_ALLOCATE); avatar->mImpostor.allocate(resX,resY,GL_RGBA,TRUE,FALSE); +#if DEFERRED_IMPOSTORS if (LLPipeline::sRenderDeferred) { addDeferredAttachments(avatar->mImpostor); } - +#endif + gGL.getTexUnit(0)->bind(&avatar->mImpostor); gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); } - else if(resX != avatar->mImpostor.getWidth() || - resY != avatar->mImpostor.getHeight()) + else if(resX != avatar->mImpostor.getWidth() || resY != avatar->mImpostor.getHeight()) { LLFastTimer t(FTM_IMPOSTOR_RESIZE); avatar->mImpostor.resize(resX,resY,GL_RGBA); } - avatar->mImpostor.bindTarget(); + avatar->mImpostor.bindTarget(); } +#if DEFERRED_IMPOSTORS if (LLPipeline::sRenderDeferred) { avatar->mImpostor.clear(); @@ -11377,20 +11379,24 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) renderGeomPostDeferred(camera); } else - { +#endif + { LLGLEnable scissor(GL_SCISSOR_TEST); - glScissor(0, 0, resX, resY); + glScissor(0, 0, resX, resY); avatar->mImpostor.clear(); renderGeom(camera); } { //create alpha mask based on depth buffer (grey out if muted) LLFastTimer t(FTM_IMPOSTOR_BACKGROUND); + +#if DEFERRED_IMPOSTORS if (LLPipeline::sRenderDeferred) { GLuint buff = GL_COLOR_ATTACHMENT0; glDrawBuffersARB(1, &buff); } +#endif LLGLDisable blend(GL_BLEND); -- cgit v1.2.3 From d76e6e2337142e3e819fcf757f396b3089e97e71 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 16 Jul 2013 06:10:05 -0700 Subject: NORSPEC-240 make alpha-masked fullbright objs use fullbright alpha mask rendering --- .../shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl | 2 +- indra/newview/llvovolume.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index 59d109b886..8525e13333 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -50,7 +50,7 @@ void main() { discard; } - + frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index b545e99a32..8ed6a08aae 100755 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -4604,7 +4604,7 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group) if (mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK && te->getColor().mV[3] >= 0.999f) { - pool->addRiggedFace(facep, fullbright ? LLDrawPoolAvatar::RIGGED_FULLBRIGHT : LLDrawPoolAvatar::RIGGED_SIMPLE); + pool->addRiggedFace(facep, fullbright ? LLDrawPoolAvatar::RIGGED_FULLBRIGHT_ALPHA_MASK : LLDrawPoolAvatar::RIGGED_ALPHA_MASK); } else if (is_alpha || (te->getColor().mV[3] < 0.999f)) { @@ -5390,7 +5390,7 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std:: { if (te->getColor().mV[3] >= 0.999f) { - material_pass = true; + registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK); } else { -- cgit v1.2.3 From f0f30c976bba99842cf0451621e14c690ef3ceae Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 16 Jul 2013 06:26:02 -0700 Subject: NORSPEC-240 revert part of change causing regression in non-ALM rendering --- indra/newview/llvovolume.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 8ed6a08aae..3d6c5398d5 100755 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -4604,7 +4604,7 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group) if (mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK && te->getColor().mV[3] >= 0.999f) { - pool->addRiggedFace(facep, fullbright ? LLDrawPoolAvatar::RIGGED_FULLBRIGHT_ALPHA_MASK : LLDrawPoolAvatar::RIGGED_ALPHA_MASK); + pool->addRiggedFace(facep, fullbright ? LLDrawPoolAvatar::RIGGED_FULLBRIGHT : LLDrawPoolAvatar::RIGGED_SIMPLE); } else if (is_alpha || (te->getColor().mV[3] < 0.999f)) { -- cgit v1.2.3 From f618b7d5cc84a83739a8ac6c3eea7d0a7d4f22cd Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 16 Jul 2013 10:25:06 -0700 Subject: NORSPEC-293 WIP fix fullbrightF order of ops to match non-deferred with fullbright+glow+texcolor --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index ec25f52ef5..33c07a6e08 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -69,8 +69,8 @@ void main() vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); #endif - color.rgb = srgb_to_linear(color.rgb); color.rgb *= vertex_color.rgb; + color.rgb = srgb_to_linear(color.rgb); color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); -- cgit v1.2.3 From 1587999b0329c76d108fcd1efe2d3fb768043e9e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 16 Jul 2013 12:03:42 -0700 Subject: Add info to vert buffer warnings to track down fullbright alpha mask crasher --- indra/llrender/llvertexbuffer.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 01541026b1..b1ef6e0576 100755 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -2239,7 +2239,32 @@ void LLVertexBuffer::setBuffer(U32 data_mask) if ((data_mask & required_mask) != required_mask) { - llwarns << "Shader consumption mismatches data provision." << llendl; + + U32 unsatisfied_mask = (required_mask & ~data_mask); + U32 i = 0; + + while (i < 15) + { + switch ((unsatisfied_mask & (1 << i))) + { + case MAP_VERTEX: llinfos << "Missing vert pos" << llendl; break; + case MAP_NORMAL: llinfos << "Missing normals" << llendl; break; + case MAP_TEXCOORD0: llinfos << "Missing TC 0" << llendl; break; + case MAP_TEXCOORD1: llinfos << "Missing TC 1" << llendl; break; + case MAP_TEXCOORD2: llinfos << "Missing TC 2" << llendl; break; + case MAP_TEXCOORD3: llinfos << "Missing TC 3" << llendl; break; + case MAP_COLOR: llinfos << "Missing vert color" << llendl; break; + case MAP_EMISSIVE: llinfos << "Missing emissive" << llendl; break; + case MAP_TANGENT: llinfos << "Missing tangent" << llendl; break; + case MAP_WEIGHT: llinfos << "Missing weight" << llendl; break; + case MAP_WEIGHT4: llinfos << "Missing weightx4" << llendl; break; + case MAP_CLOTHWEIGHT: llinfos << "Missing clothweight" << llendl; break; + case MAP_TEXTURE_INDEX: llinfos << "Missing tex index" << llendl; break; + default: llinfos << "Missing who effin knows" << llendl; + } + } + + llerrs << "Shader consumption mismatches data provision." << llendl; } } } -- cgit v1.2.3 From 9aeb3b48d77ce9e22445b4bca23d36f651bb9395 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 17 Jul 2013 08:03:09 -0700 Subject: NORSPEC-291 fix materials underwater, disable attempt at materials in reflect/distort RTs --- .../app_settings/shaders/class1/deferred/waterF.glsl | 2 +- indra/newview/pipeline.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 17288873c8..46d5b9b612 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -192,7 +192,7 @@ void main() //wavef = normalize(wavef); vec3 screenspacewavef = (norm_mat*vec4(wavef, 1.0)).xyz; - frag_data[0] = vec4(linear_to_srgb(color.rgb), 0.5); // diffuse + frag_data[0] = vec4(color.rgb, 0.5); // diffuse frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec frag_data[2] = vec4(encode_normal(screenspacewavef), 0.0, 0.0); // normalxyz, displace } diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index fc79f1c31f..d88cb30887 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -122,9 +122,9 @@ //#define DEBUG_INDICES #endif -// Expensive +// Expensive and currently broken // -#define MATERIALS_IN_REFLECTIONS 1 +#define MATERIALS_IN_REFLECTIONS 0 bool gShiftFrame = false; @@ -1236,7 +1236,11 @@ void LLPipeline::createGLBuffers() updateRenderDeferred(); - bool materials_in_water = gSavedSettings.getS32("RenderWaterMaterials"); + bool materials_in_water = false; + +#if MATERIALS_IN_REFLECTIONS + materials_in_water = gSavedSettings.getS32("RenderWaterMaterials"); +#endif if (LLPipeline::sWaterReflections) { //water reflection texture @@ -9685,7 +9689,11 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) water_clip = 1; } - bool materials_in_water = gSavedSettings.getS32("RenderWaterMaterials"); + bool materials_in_water = false; + +#if MATERIALS_IN_REFLECTIONS + materials_in_water = gSavedSettings.getS32("RenderWaterMaterials"); +#endif if (!LLViewerCamera::getInstance()->cameraUnderWater()) { //generate planar reflection map -- cgit v1.2.3 From 0160491f888917d830ca3d827cc1f28f07363fed Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 17 Jul 2013 10:29:02 -0700 Subject: NORSPEC-291 put back conversion to srgb in deferred water shader --- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 46d5b9b612..17288873c8 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -192,7 +192,7 @@ void main() //wavef = normalize(wavef); vec3 screenspacewavef = (norm_mat*vec4(wavef, 1.0)).xyz; - frag_data[0] = vec4(color.rgb, 0.5); // diffuse + frag_data[0] = vec4(linear_to_srgb(color.rgb), 0.5); // diffuse frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec frag_data[2] = vec4(encode_normal(screenspacewavef), 0.0, 0.0); // normalxyz, displace } -- cgit v1.2.3 From 8712086a4bcf1f0f7527a916baafc9e65667e4e8 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Thu, 18 Jul 2013 06:37:22 -0700 Subject: NORSPEC-314 work-around mystery mac GeForce crash from new shader for nspec 295 --- indra/newview/lldrawpoolsimple.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/indra/newview/lldrawpoolsimple.cpp b/indra/newview/lldrawpoolsimple.cpp index e219769a0c..87fbeaf2c0 100755 --- a/indra/newview/lldrawpoolsimple.cpp +++ b/indra/newview/lldrawpoolsimple.cpp @@ -633,8 +633,15 @@ void LLDrawPoolFullbrightAlphaMask::beginPostDeferredPass(S32 pass) } else { +#if LL_DARWIN + // the OS X 10.6.8 GeForce driver is a real POS + // this is a work-around for NORSPEC-314 + gObjectFullbrightAlphaMaskProgram.bind(); + gObjectFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); +#else gDeferredFullbrightAlphaMaskProgram.bind(); gDeferredFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); +#endif } } @@ -654,7 +661,11 @@ void LLDrawPoolFullbrightAlphaMask::endPostDeferredPass(S32 pass) } else { +#if LL_DARWIN + gObjectFullbrightAlphaMaskProgram.unbind(); +#else gDeferredFullbrightAlphaMaskProgram.unbind(); +#endif } LLRenderPass::endRenderPass(pass); } -- cgit v1.2.3 From 94abe75dea90ee91dd044161d8587279b0bfae13 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sun, 21 Jul 2013 08:15:21 -0700 Subject: NORSPEC-315 NORSPEC-316 NORSPEC-312 fix various haze and gamma correction issues, alpha-blend objects still missing haze underwater --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- .../shaders/class1/deferred/fullbrightAlphaMaskF.glsl | 7 ++++--- .../shaders/class1/deferred/fullbrightF.glsl | 5 +++-- .../app_settings/shaders/class1/deferred/materialF.glsl | 12 ++++++++++++ .../shaders/class1/deferred/softenLightF.glsl | 13 ++++++------- .../app_settings/shaders/class1/deferred/waterF.glsl | 5 ++++- .../shaders/class2/deferred/softenLightF.glsl | 16 +++++++--------- indra/newview/llvovolume.cpp | 3 ++- indra/newview/pipeline.cpp | 4 +++- 9 files changed, 42 insertions(+), 25 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 640e273415..b64852f17b 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -281,7 +281,7 @@ void main() color.rgb += diff.rgb * vary_pointlight_col_linear * col.rgb; color.rgb = linear_to_srgb(color.rgb); - + //color.rgb = vec3(1,0,1); frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl index 3d93583e1e..a74256de81 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl @@ -71,7 +71,8 @@ void main() vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); #endif - if (color.a < minimum_alpha) + float final_alpha = color.a * vertex_color.a; + if (final_alpha < minimum_alpha) { discard; } @@ -83,8 +84,8 @@ void main() color.rgb = fullbrightScaleSoftClip(color.rgb); color.rgb = linear_to_srgb(color.rgb); - + //color.rgb = vec3(1,0,1); frag_color.rgb = color.rgb; - frag_color.a = color.a; + frag_color.a = final_alpha; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 33c07a6e08..5876efedec 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -69,14 +69,15 @@ void main() vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); #endif - color.rgb *= vertex_color.rgb; + color.rgb = srgb_to_linear(color.rgb); + color.rgb *= vertex_color.rgb; color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); color.rgb = linear_to_srgb(color.rgb); - + //color.rgb = vec3(1,0,1); frag_color.rgb = color.rgb; frag_color.a = color.a; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 9ce4d89df7..954a27b698 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -266,6 +266,13 @@ vec4 getPosition_d(vec2 pos_screen, float depth) return pos; } +#ifndef WATER_FOG +vec3 getPositionEye() +{ + return vary_PositionEye; +} +#endif + vec3 getSunlitColor() { return vary_SunlitColor; @@ -728,6 +735,10 @@ void main() glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; + + //convert to gamma space for display on screen + col.rgb = linear_to_srgb(col.rgb); + #ifdef WATER_FOG vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al)); col.rgb = temp.rgb; @@ -738,6 +749,7 @@ void main() frag_color.a = al; #else + //final_color.rgb = vec3(1,0,1); frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 953f0189f0..950512a79d 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -436,16 +436,15 @@ void main() if (norm.w < 0.5) { col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - - #ifdef WATER_FOG - vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); - col = fogged.rgb; - bloom = fogged.a; - #endif - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); } + #ifdef WATER_FOG + vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); + col = fogged.rgb; + bloom = fogged.a; + #endif + col = srgb_to_linear(col); //col = vec3(1,0,1); diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 17288873c8..7415415290 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -192,7 +192,10 @@ void main() //wavef = normalize(wavef); vec3 screenspacewavef = (norm_mat*vec4(wavef, 1.0)).xyz; - frag_data[0] = vec4(linear_to_srgb(color.rgb), 0.5); // diffuse + // this is needed for materials in reflections, but not otherwise + // + //frag_data[0] = vec4(linear_to_srgb(color.rgb), 0.5); // diffuse + frag_data[0] = vec4(color.rgb, 0.5); // diffuse frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec frag_data[2] = vec4(encode_normal(screenspacewavef), 0.0, 0.0); // normalxyz, displace } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 9b72c5b57d..0c71b4f554 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -455,23 +455,21 @@ void main() if (norm.w < 0.5) { col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - - #ifdef WATER_FOG - vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); - col = fogged.rgb; - bloom = fogged.a; - #endif - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); } + #ifdef WATER_FOG + vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); + col = fogged.rgb; + bloom = fogged.a; + #endif + col = srgb_to_linear(col); //col = vec3(1,0,1); //col.g = envIntensity; } - + frag_color.rgb = col; frag_color.a = bloom; } - diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 3d6c5398d5..c4b4c76254 100755 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -5379,6 +5379,7 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std:: } bool use_legacy_bump = te->getBumpmap() && (te->getBumpmap() < 18) && (!mat || mat->getNormalID().isNull()); + bool opaque = te->getColor().mV[3] >= 0.999f; if (mat && LLPipeline::sRenderDeferred && !hud_group) { @@ -5388,7 +5389,7 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std:: { if (mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_MASK) { - if (te->getColor().mV[3] >= 0.999f) + if (opaque) { registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK); } diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index d88cb30887..d89ad615ae 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -11262,7 +11262,9 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) S32 occlusion = sUseOcclusion; sUseOcclusion = 0; - //sReflectionRender = sRenderDeferred ? FALSE : TRUE; + + sReflectionRender = sRenderDeferred ? FALSE : TRUE; + sShadowRender = TRUE; sImpostorRender = TRUE; -- cgit v1.2.3 From caefe0e74cf553de41c6c8748dd2ea5ef4d82c06 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sun, 21 Jul 2013 14:28:54 -0700 Subject: NORSPEC-311 fix alpha / opaque lighting diffs --- indra/newview/app_settings/settings.xml | 11 +++ .../shaders/class1/deferred/alphaF.glsl | 56 +++++++++++++- .../class1/deferred/fullbrightAlphaMaskF.glsl | 55 +++++++++++++- .../shaders/class1/deferred/fullbrightF.glsl | 73 +++++++++++++++++- .../shaders/class1/deferred/fullbrightV.glsl | 9 ++- .../class1/deferred/postDeferredGammaCorrect.glsl | 2 +- indra/newview/lldrawpoolalpha.cpp | 14 +++- indra/newview/lldrawpoolsimple.cpp | 48 +++++++++--- indra/newview/llviewershadermgr.cpp | 88 +++++++++++++++++++++- indra/newview/llviewershadermgr.h | 3 + indra/newview/pipeline.cpp | 8 +- 11 files changed, 336 insertions(+), 31 deletions(-) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 2d3b32159a..6570189c5b 100755 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -8894,6 +8894,17 @@ Value 1.0 + RenderDeferredDisplayGamma + + Comment + Gamma ramp exponent for final correction before display gamma. + Persist + 1 + Type + F32 + Value + 1.8 + RenderGLCoreProfile Comment diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index b64852f17b..69b0f8f012 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -136,6 +136,52 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc) } #endif +#if WATER_FOG +uniform vec4 waterPlane; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; + +vec4 applyWaterFogDeferred(vec3 pos, vec4 color) +{ + //normalize view vector + vec3 view = normalize(pos); + float es = -(dot(view, waterPlane.xyz)); + + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); + + //get object depth + float depth = length(pos - int_v); + + //get "thickness" of water + float l = max(depth, 0.1); + + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2*l) - 1.0; + + float L = min(t1/t2*t3, 1.0); + + float D = pow(0.98, l*kd); + + color.rgb = color.rgb * D + kc.rgb * L; + color.a = kc.a + color.a; + + return color; +} +#endif + vec3 srgb_to_linear(vec3 cs) { @@ -240,8 +286,9 @@ void main() vec4 gamma_diff = diff; diff.rgb = srgb_to_linear(diff.rgb); - + #ifdef USE_VERTEX_COLOR + diff.rgb *= vertex_color.rgb; float vertex_color_alpha = vertex_color.a; #else float vertex_color_alpha = 1.0; @@ -266,6 +313,7 @@ void main() color.rgb = scaleSoftClip(color.rgb); color.rgb = srgb_to_linear(color.rgb); + col = vec4(0,0,0,0); #define LIGHT_LOOP(i) col.rgb += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, normal, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); @@ -281,7 +329,11 @@ void main() color.rgb += diff.rgb * vary_pointlight_col_linear * col.rgb; color.rgb = linear_to_srgb(color.rgb); - //color.rgb = vec3(1,0,1); + +#if WATER_FOG + color = applyWaterFogDeferred(pos.xyz, color); +#endif + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl index a74256de81..00743abe34 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl @@ -61,6 +61,52 @@ vec3 linear_to_srgb(vec3 cl) return 1.055 * pow(cl, vec3(0.41666)) - 0.055; } +#ifdef WATER_FOG +uniform vec4 waterPlane; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; + +vec4 applyWaterFogDeferred(vec3 pos, vec4 color) +{ + //normalize view vector + vec3 view = normalize(pos); + float es = -(dot(view, waterPlane.xyz)); + + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); + + //get object depth + float depth = length(pos - int_v); + + //get "thickness" of water + float l = max(depth, 0.1); + + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2*l) - 1.0; + + float L = min(t1/t2*t3, 1.0); + + float D = pow(0.98, l*kd); + + color.rgb = color.rgb * D + kc.rgb * L; + color.a = kc.a + color.a; + + return color; +} +#endif + uniform float minimum_alpha; void main() @@ -72,7 +118,7 @@ void main() #endif float final_alpha = color.a * vertex_color.a; - if (final_alpha < minimum_alpha) + if (color.a < minimum_alpha) { discard; } @@ -84,7 +130,12 @@ void main() color.rgb = fullbrightScaleSoftClip(color.rgb); color.rgb = linear_to_srgb(color.rgb); - //color.rgb = vec3(1,0,1); + + +#ifdef WATER_FOG + color = applyWaterFogDeferred(pos, vec4(color)); +#endif + frag_color.rgb = color.rgb; frag_color.a = final_alpha; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 5876efedec..1e8df68a72 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -35,12 +35,63 @@ out vec4 frag_color; uniform sampler2D diffuseMap; #endif +VARYING vec3 vary_position; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; vec3 fullbrightAtmosTransport(vec3 light); vec3 fullbrightScaleSoftClip(vec3 light); +#if HAS_ALPHA_MASK +uniform float minimum_alpha; +#endif + +#ifdef WATER_FOG +uniform vec4 waterPlane; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; + +vec4 applyWaterFogDeferred(vec3 pos, vec4 color) +{ + //normalize view vector + vec3 view = normalize(pos); + float es = -(dot(view, waterPlane.xyz)); + + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); + + //get object depth + float depth = length(pos - int_v); + + //get "thickness" of water + float l = max(depth, 0.1); + + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2*l) - 1.0; + + float L = min(t1/t2*t3, 1.0); + + float D = pow(0.98, l*kd); + + color.rgb = color.rgb * D + kc.rgb * L; + color.a = kc.a + color.a; + + return color; +} +#endif + vec3 srgb_to_linear(vec3 cs) { @@ -69,15 +120,31 @@ void main() vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); #endif + float final_alpha = color.a * vertex_color.a; + +#if HAS_ALPHA_MASK + if (color.a < minimum_alpha) + { + discard; + } +#endif - color.rgb = srgb_to_linear(color.rgb); color.rgb *= vertex_color.rgb; + color.rgb = srgb_to_linear(color.rgb); + color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); - + color.rgb = linear_to_srgb(color.rgb); - //color.rgb = vec3(1,0,1); + +#ifdef WATER_FOG + vec3 pos = vary_position; + vec4 fogged = applyWaterFogDeferred(pos, vec4(color.rgb, final_alpha)); + color.rgb = fogged.rgb; + color.a = fogged.a; +#endif + frag_color.rgb = color.rgb; frag_color.a = color.a; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl index 3f09a15375..22f47b7572 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -40,6 +40,9 @@ vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 scaleDownLight(vec3 light); vec3 scaleUpLight(vec3 light); +#if WATER_FOG +VARYING vec3 vary_position; +#endif VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; @@ -53,7 +56,11 @@ void main() passTextureIndex(); gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); - + +#if WATER_FOG + vary_position = pos.xyz; +#endif + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; calcAtmospherics(pos.xyz); diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index a3610bfffa..59b027a045 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -51,7 +51,7 @@ vec3 linear_to_srgb(vec3 cl) void main() { vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - diff.rgb = linear_to_srgb(diff.rgb); + diff.rgb = pow(diff.rgb,vec3(texture_gamma)); frag_color = diff; } diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index e53c783161..973e263572 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -93,11 +93,21 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) if (pass == 0) { - simple_shader = &gDeferredAlphaProgram; - fullbright_shader = &gObjectFullbrightProgram; + if (LLPipeline::sUnderWaterRender) + { + simple_shader = &gDeferredAlphaWaterProgram; + fullbright_shader = &gDeferredFullbrightWaterProgram; + } + else + { + simple_shader = &gDeferredAlphaProgram; + fullbright_shader = &gDeferredFullbrightProgram; + } + fullbright_shader->bind(); fullbright_shader->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); fullbright_shader->unbind(); + //prime simple shader (loads shadow relevant uniforms) gPipeline.bindDeferredShader(*simple_shader); } diff --git a/indra/newview/lldrawpoolsimple.cpp b/indra/newview/lldrawpoolsimple.cpp index 87fbeaf2c0..d51b84cfbc 100755 --- a/indra/newview/lldrawpoolsimple.cpp +++ b/indra/newview/lldrawpoolsimple.cpp @@ -111,7 +111,14 @@ void LLDrawPoolGlow::render(S32 pass) LLGLSLShader* shader = LLPipeline::sUnderWaterRender ? &gObjectEmissiveWaterProgram : &gObjectEmissiveProgram; shader->bind(); - shader->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 1.f); + if (LLPipeline::sRenderDeferred) + { + shader->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); + } + else + { + shader->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 1.f); + } LLGLDepthTest depth(GL_TRUE, GL_FALSE); gGL.setColorMask(false, true); @@ -536,7 +543,15 @@ void LLDrawPoolFullbright::prerender() void LLDrawPoolFullbright::beginPostDeferredPass(S32 pass) { - gDeferredFullbrightProgram.bind(); + if (LLPipeline::sUnderWaterRender) + { + gDeferredFullbrightWaterProgram.bind(); + } + else + { + gDeferredFullbrightProgram.bind(); + } + } void LLDrawPoolFullbright::renderPostDeferred(S32 pass) @@ -550,7 +565,14 @@ void LLDrawPoolFullbright::renderPostDeferred(S32 pass) void LLDrawPoolFullbright::endPostDeferredPass(S32 pass) { - gDeferredFullbrightProgram.unbind(); + if (LLPipeline::sUnderWaterRender) + { + gDeferredFullbrightWaterProgram.unbind(); + } + else + { + gDeferredFullbrightProgram.unbind(); + } LLRenderPass::endRenderPass(pass); } @@ -633,15 +655,17 @@ void LLDrawPoolFullbrightAlphaMask::beginPostDeferredPass(S32 pass) } else { -#if LL_DARWIN - // the OS X 10.6.8 GeForce driver is a real POS - // this is a work-around for NORSPEC-314 - gObjectFullbrightAlphaMaskProgram.bind(); - gObjectFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); -#else - gDeferredFullbrightAlphaMaskProgram.bind(); - gDeferredFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); -#endif + if (LLPipeline::sUnderWaterRender) + { + gDeferredFullbrightAlphaMaskWaterProgram.bind(); + gDeferredFullbrightAlphaMaskWaterProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); + } + else + { + gDeferredFullbrightAlphaMaskProgram.bind(); + gDeferredFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); + } + } } diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index e9c3990e9a..f0e4825279 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -197,9 +197,12 @@ LLGLSLShader gDeferredShadowAlphaMaskProgram; LLGLSLShader gDeferredAvatarShadowProgram; LLGLSLShader gDeferredAttachmentShadowProgram; LLGLSLShader gDeferredAlphaProgram; +LLGLSLShader gDeferredAlphaWaterProgram; LLGLSLShader gDeferredAvatarEyesProgram; LLGLSLShader gDeferredFullbrightProgram; LLGLSLShader gDeferredFullbrightAlphaMaskProgram; +LLGLSLShader gDeferredFullbrightWaterProgram; +LLGLSLShader gDeferredFullbrightAlphaMaskWaterProgram; LLGLSLShader gDeferredEmissiveProgram; LLGLSLShader gDeferredPostProgram; LLGLSLShader gDeferredCoFProgram; @@ -301,9 +304,12 @@ LLViewerShaderMgr::LLViewerShaderMgr() : mShaderList.push_back(&gDeferredMaterialWaterProgram[9+LLMaterial::SHADER_COUNT]); mShaderList.push_back(&gDeferredMaterialWaterProgram[13+LLMaterial::SHADER_COUNT]); mShaderList.push_back(&gDeferredAlphaProgram); + mShaderList.push_back(&gDeferredAlphaWaterProgram); mShaderList.push_back(&gDeferredSkinnedAlphaProgram); mShaderList.push_back(&gDeferredFullbrightProgram); - mShaderList.push_back(&gDeferredFullbrightAlphaMaskProgram); + mShaderList.push_back(&gDeferredFullbrightAlphaMaskProgram); + mShaderList.push_back(&gDeferredFullbrightWaterProgram); + mShaderList.push_back(&gDeferredFullbrightAlphaMaskWaterProgram); mShaderList.push_back(&gDeferredFullbrightShinyProgram); mShaderList.push_back(&gDeferredSkinnedFullbrightShinyProgram); mShaderList.push_back(&gDeferredSkinnedFullbrightProgram); @@ -1145,8 +1151,11 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAvatarProgram.unload(); gDeferredAvatarAlphaProgram.unload(); gDeferredAlphaProgram.unload(); + gDeferredAlphaWaterProgram.unload(); gDeferredFullbrightProgram.unload(); gDeferredFullbrightAlphaMaskProgram.unload(); + gDeferredFullbrightWaterProgram.unload(); + gDeferredFullbrightAlphaMaskWaterProgram.unload(); gDeferredEmissiveProgram.unload(); gDeferredAvatarEyesProgram.unload(); gDeferredPostProgram.unload(); @@ -1518,7 +1527,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredAlphaProgram.addPermutation("USE_INDEXED_TEX", "1"); - gDeferredAlphaProgram.addPermutation("USE_VERTEX_COLOR", "1"); + //gDeferredAlphaProgram.addPermutation("USE_VERTEX_COLOR", "1"); + gDeferredAlphaProgram.addPermutation("WATER_FOG", "0"); gDeferredAlphaProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); gDeferredAlphaProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1529,6 +1539,42 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaProgram.mFeatures.hasLighting = true; } + if (success) + { + gDeferredAlphaWaterProgram.mName = "Deferred Alpha Underwater Shader"; + gDeferredAlphaWaterProgram.mFeatures.atmosphericHelpers = true; + gDeferredAlphaWaterProgram.mFeatures.calculatesLighting = false; + gDeferredAlphaWaterProgram.mFeatures.calculatesAtmospherics = true; + gDeferredAlphaWaterProgram.mFeatures.hasGamma = true; + gDeferredAlphaWaterProgram.mFeatures.hasAtmospherics = true; + gDeferredAlphaWaterProgram.mFeatures.hasLighting = false; + gDeferredAlphaWaterProgram.mFeatures.isAlphaLighting = true; + gDeferredAlphaWaterProgram.mFeatures.disableTextureIndex = true; //hack to disable auto-setup of texture channels + if (mVertexShaderLevel[SHADER_DEFERRED] < 1) + { + gDeferredAlphaWaterProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; + } + else + { //shave off some texture units for shadow maps + gDeferredAlphaWaterProgram.mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels - 6, 1); + } + gDeferredAlphaWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; + gDeferredAlphaWaterProgram.mShaderFiles.clear(); + gDeferredAlphaWaterProgram.mShaderFiles.push_back(make_pair("deferred/alphaV.glsl", GL_VERTEX_SHADER_ARB)); + gDeferredAlphaWaterProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredAlphaWaterProgram.addPermutation("USE_INDEXED_TEX", "1"); + //gDeferredAlphaWaterProgram.addPermutation("USE_VERTEX_COLOR", "1"); + gDeferredAlphaWaterProgram.addPermutation("WATER_FOG", "1"); + gDeferredAlphaWaterProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); + gDeferredAlphaWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + + success = gDeferredAlphaWaterProgram.createShader(NULL, NULL); + + // Hack + gDeferredAlphaWaterProgram.mFeatures.calculatesLighting = true; + gDeferredAlphaWaterProgram.mFeatures.hasLighting = true; + } + if (success) { gDeferredAvatarEyesProgram.mName = "Deferred Avatar Eyes Shader"; @@ -1559,18 +1605,52 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { - gDeferredFullbrightAlphaMaskProgram.mName = "Deferred Fullbright Alpha Mask Shader"; + gDeferredFullbrightAlphaMaskProgram.mName = "Deferred Fullbright Alpha Masking Shader"; gDeferredFullbrightAlphaMaskProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.hasGamma = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.hasTransport = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; gDeferredFullbrightAlphaMaskProgram.mShaderFiles.clear(); gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); - gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightAlphaMaskF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredFullbrightAlphaMaskProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + gDeferredFullbrightAlphaMaskProgram.addPermutation("HAS_ALPHA_MASK","1"); success = gDeferredFullbrightAlphaMaskProgram.createShader(NULL, NULL); } + if (success) + { + gDeferredFullbrightWaterProgram.mName = "Deferred Fullbright Underwater Shader"; + gDeferredFullbrightWaterProgram.mFeatures.calculatesAtmospherics = true; + gDeferredFullbrightWaterProgram.mFeatures.hasGamma = true; + gDeferredFullbrightWaterProgram.mFeatures.hasTransport = true; + gDeferredFullbrightWaterProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; + gDeferredFullbrightWaterProgram.mShaderFiles.clear(); + gDeferredFullbrightWaterProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); + gDeferredFullbrightWaterProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredFullbrightWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + gDeferredFullbrightWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; + gDeferredFullbrightWaterProgram.addPermutation("WATER_FOG","1"); + success = gDeferredFullbrightWaterProgram.createShader(NULL, NULL); + } + + if (success) + { + gDeferredFullbrightAlphaMaskWaterProgram.mName = "Deferred Fullbright Underwater Alpha Masking Shader"; + gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.calculatesAtmospherics = true; + gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasGamma = true; + gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasTransport = true; + gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; + gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.clear(); + gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); + gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredFullbrightAlphaMaskWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + gDeferredFullbrightAlphaMaskWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; + gDeferredFullbrightAlphaMaskWaterProgram.addPermutation("HAS_ALPHA_MASK","1"); + gDeferredFullbrightAlphaMaskWaterProgram.addPermutation("WATER_FOG","1"); + success = gDeferredFullbrightAlphaMaskWaterProgram.createShader(NULL, NULL); + } + if (success) { gDeferredFullbrightShinyProgram.mName = "Deferred FullbrightShiny Shader"; diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h index f14180d957..5fa9b82170 100755 --- a/indra/newview/llviewershadermgr.h +++ b/indra/newview/llviewershadermgr.h @@ -366,6 +366,9 @@ extern LLGLSLShader gDeferredAttachmentShadowProgram; extern LLGLSLShader gDeferredAlphaProgram; extern LLGLSLShader gDeferredFullbrightProgram; extern LLGLSLShader gDeferredFullbrightAlphaMaskProgram; +extern LLGLSLShader gDeferredAlphaWaterProgram; +extern LLGLSLShader gDeferredFullbrightWaterProgram; +extern LLGLSLShader gDeferredFullbrightAlphaMaskWaterProgram; extern LLGLSLShader gDeferredEmissiveProgram; extern LLGLSLShader gDeferredAvatarEyesProgram; extern LLGLSLShader gDeferredAvatarAlphaProgram; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index d89ad615ae..c593c85ce7 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8831,9 +8831,9 @@ void LLPipeline::renderDeferredLighting() gDeferredPostGammaCorrectProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, mScreen.getWidth(), mScreen.getHeight()); - F32 gamma = 1.0/2.2; + F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); - gDeferredPostGammaCorrectProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, gamma); + gDeferredPostGammaCorrectProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); gGL.begin(LLRender::TRIANGLE_STRIP); gGL.texCoord2f(tc1.mV[0], tc1.mV[1]); @@ -9380,9 +9380,9 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) gDeferredPostGammaCorrectProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, target->getWidth(), target->getHeight()); - F32 gamma = 1.0/2.2; + F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); - gDeferredPostGammaCorrectProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, gamma); + gDeferredPostGammaCorrectProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); gGL.begin(LLRender::TRIANGLE_STRIP); gGL.texCoord2f(tc1.mV[0], tc1.mV[1]); -- cgit v1.2.3 From b8e23afe8185b69102d28acdc5905225e1a97914 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sun, 21 Jul 2013 14:33:25 -0700 Subject: NORSPEC-311 NORSPEC-312 remove unused shader and correct default for display gamma exposed in settings --- indra/newview/app_settings/settings.xml | 2 +- .../class1/deferred/fullbrightAlphaMaskF.glsl | 142 --------------------- 2 files changed, 1 insertion(+), 143 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 6570189c5b..830cd33593 100755 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -8903,7 +8903,7 @@ Type F32 Value - 1.8 + 2.2 RenderGLCoreProfile diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl deleted file mode 100644 index 00743abe34..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl +++ /dev/null @@ -1,142 +0,0 @@ -/** - * @file fullbrightF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -#if !HAS_DIFFUSE_LOOKUP -uniform sampler2D diffuseMap; -#endif - -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -vec3 fullbrightAtmosTransport(vec3 light); -vec3 fullbrightScaleSoftClip(vec3 light); - -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} - -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - float es = -(dot(view, waterPlane.xyz)); - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; -} -#endif - -uniform float minimum_alpha; - -void main() -{ -#if HAS_DIFFUSE_LOOKUP - vec4 color = diffuseLookup(vary_texcoord0.xy); -#else - vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); -#endif - - float final_alpha = color.a * vertex_color.a; - if (color.a < minimum_alpha) - { - discard; - } - - color.rgb = srgb_to_linear(color.rgb); - color.rgb *= vertex_color.rgb; - - color.rgb = fullbrightAtmosTransport(color.rgb); - color.rgb = fullbrightScaleSoftClip(color.rgb); - - color.rgb = linear_to_srgb(color.rgb); - - -#ifdef WATER_FOG - color = applyWaterFogDeferred(pos, vec4(color)); -#endif - - frag_color.rgb = color.rgb; - frag_color.a = final_alpha; -} - -- cgit v1.2.3 From 710b529372f4d7da699318c4761963ae9dde9a63 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sun, 21 Jul 2013 16:29:05 -0700 Subject: NORSPEC-311 NORSPEC-312 make mac happy with shader ifdefs for haze/masking --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl | 4 ++-- indra/newview/llviewershadermgr.cpp | 1 - 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 69b0f8f012..69b29269c7 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -136,7 +136,7 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc) } #endif -#if WATER_FOG +#ifdef WATER_FOG uniform vec4 waterPlane; uniform vec4 waterFogColor; uniform float waterFogDensity; @@ -330,7 +330,7 @@ void main() color.rgb = linear_to_srgb(color.rgb); -#if WATER_FOG +#ifdef WATER_FOG color = applyWaterFogDeferred(pos.xyz, color); #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 1e8df68a72..a6f55dfb46 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -42,7 +42,7 @@ VARYING vec2 vary_texcoord0; vec3 fullbrightAtmosTransport(vec3 light); vec3 fullbrightScaleSoftClip(vec3 light); -#if HAS_ALPHA_MASK +#ifdef HAS_ALPHA_MASK uniform float minimum_alpha; #endif @@ -122,7 +122,7 @@ void main() float final_alpha = color.a * vertex_color.a; -#if HAS_ALPHA_MASK +#ifdef HAS_ALPHA_MASK if (color.a < minimum_alpha) { discard; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl index 22f47b7572..8e899e3e0f 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -40,7 +40,7 @@ vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 scaleDownLight(vec3 light); vec3 scaleUpLight(vec3 light); -#if WATER_FOG +#ifdef WATER_FOG VARYING vec3 vary_position; #endif @@ -57,7 +57,7 @@ void main() gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); -#if WATER_FOG +#ifdef WATER_FOG vary_position = pos.xyz; #endif diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index f0e4825279..25f2fbda07 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -1528,7 +1528,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredAlphaProgram.addPermutation("USE_INDEXED_TEX", "1"); //gDeferredAlphaProgram.addPermutation("USE_VERTEX_COLOR", "1"); - gDeferredAlphaProgram.addPermutation("WATER_FOG", "0"); gDeferredAlphaProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); gDeferredAlphaProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; -- cgit v1.2.3 From 6f62251a3d29ced4193a9a80965f33fe0318d5a0 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 22 Jul 2013 10:29:49 -0700 Subject: MATBUG-306 fix alpha knock-on from underwater lightcurve matching --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 8 ++++---- indra/newview/app_settings/shaders/class1/deferred/waterF.glsl | 9 +++------ indra/newview/llviewershadermgr.cpp | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 69b29269c7..2eef99dea7 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -288,8 +288,7 @@ void main() diff.rgb = srgb_to_linear(diff.rgb); #ifdef USE_VERTEX_COLOR - diff.rgb *= vertex_color.rgb; - float vertex_color_alpha = vertex_color.a; + float vertex_color_alpha = diff.a * vertex_color.a; #else float vertex_color_alpha = 1.0; #endif @@ -306,8 +305,9 @@ void main() vec4 col = vec4(vary_ambient + dlight, vertex_color_alpha); #endif - vec4 color = gamma_diff * col; - + vec4 color = col; + color.rgb *= gamma_diff.rgb; + color.rgb = atmosLighting(color.rgb); color.rgb = scaleSoftClip(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 7415415290..34189deaad 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -186,16 +186,13 @@ void main() color.rgb = atmosTransport(color.rgb); color.rgb = scaleSoftClip(color.rgb); - //color.a = spec * sunAngle2; + color.a = sunAngle2; //wavef.z *= 0.1f; //wavef = normalize(wavef); vec3 screenspacewavef = (norm_mat*vec4(wavef, 1.0)).xyz; - // this is needed for materials in reflections, but not otherwise - // - //frag_data[0] = vec4(linear_to_srgb(color.rgb), 0.5); // diffuse - frag_data[0] = vec4(color.rgb, 0.5); // diffuse + frag_data[0] = vec4(color.rgb, color.a); // diffuse frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec - frag_data[2] = vec4(encode_normal(screenspacewavef), 0.0, 0.0); // normalxyz, displace + frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), screenspacewavef.z * 0.16, 0.0);// normalxyz, env intensity } diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 25f2fbda07..8411fd250b 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -1527,7 +1527,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredAlphaProgram.addPermutation("USE_INDEXED_TEX", "1"); - //gDeferredAlphaProgram.addPermutation("USE_VERTEX_COLOR", "1"); + gDeferredAlphaProgram.addPermutation("USE_VERTEX_COLOR", "1"); gDeferredAlphaProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); gDeferredAlphaProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1562,7 +1562,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaWaterProgram.mShaderFiles.push_back(make_pair("deferred/alphaV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredAlphaWaterProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredAlphaWaterProgram.addPermutation("USE_INDEXED_TEX", "1"); - //gDeferredAlphaWaterProgram.addPermutation("USE_VERTEX_COLOR", "1"); + gDeferredAlphaWaterProgram.addPermutation("USE_VERTEX_COLOR", "1"); gDeferredAlphaWaterProgram.addPermutation("WATER_FOG", "1"); gDeferredAlphaWaterProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); gDeferredAlphaWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; -- cgit v1.2.3 From dcee5fe14f1299f7cbfe535e696ac213e7636bb8 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 22 Jul 2013 15:00:35 -0700 Subject: NORSPEC-320 fix fullbright alpha breakage when not underwater --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index a6f55dfb46..a532b67cd9 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -143,6 +143,8 @@ void main() vec4 fogged = applyWaterFogDeferred(pos, vec4(color.rgb, final_alpha)); color.rgb = fogged.rgb; color.a = fogged.a; +#else + color.a = final_alpha; #endif frag_color.rgb = color.rgb; -- cgit v1.2.3 From 3c1b6d6dc0585e695030eefa5bc4998ba8e11683 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 22 Jul 2013 16:47:58 -0700 Subject: NORSPEC-285 NORSPEC-311 fix gamma correction of diffuse-only objects not matching the rest of the sRGB herd --- .../shaders/class1/deferred/diffuseIndexedF.glsl | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index adc361d7a2..997c8d61d3 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -39,15 +39,34 @@ vec2 encode_normal(vec3 n) return n.xy / f + 0.5; } +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} void main() { - vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; + vec3 col = vertex_color.rgb * srgb_to_linear(diffuseLookup(vary_texcoord0.xy).rgb); vec3 spec; spec.rgb = vec3(vertex_color.a); - frag_data[0] = vec4(col, 0.0); + frag_data[0] = vec4(linear_to_srgb(col), 0.0); frag_data[1] = vec4(spec, vertex_color.a); // spec vec3 nvn = normalize(vary_normal); frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0); -- cgit v1.2.3 From 920ca152c662eec12f0e6bcc4fd19feb978e88d4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 22 Jul 2013 20:48:24 -0700 Subject: NORSPEC-314 WIP see if this ruse gets past the decrepit GeForce driver --- .../class1/deferred/fullbrightAlphaMaskF.glsl | 149 +++++++++++++++++++++ .../shaders/class1/deferred/fullbrightF.glsl | 9 -- indra/newview/llviewershadermgr.cpp | 6 +- 3 files changed, 151 insertions(+), 13 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl new file mode 100644 index 0000000000..eb7a95513c --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl @@ -0,0 +1,149 @@ +/** + * @file fullbrightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#extension GL_ARB_texture_rectangle : enable + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +#if !HAS_DIFFUSE_LOOKUP +uniform sampler2D diffuseMap; +#endif + +VARYING vec3 vary_position; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +vec3 fullbrightAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light); + +uniform float minimum_alpha; + +#ifdef WATER_FOG +uniform vec4 waterPlane; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; + +vec4 applyWaterFogDeferred(vec3 pos, vec4 color) +{ + //normalize view vector + vec3 view = normalize(pos); + float es = -(dot(view, waterPlane.xyz)); + + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); + + //get object depth + float depth = length(pos - int_v); + + //get "thickness" of water + float l = max(depth, 0.1); + + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2*l) - 1.0; + + float L = min(t1/t2*t3, 1.0); + + float D = pow(0.98, l*kd); + + color.rgb = color.rgb * D + kc.rgb * L; + color.a = kc.a + color.a; + + return color; +} +#endif + +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /*{ 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; +} + +void main() +{ +#if HAS_DIFFUSE_LOOKUP + vec4 color = diffuseLookup(vary_texcoord0.xy); +#else + vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); +#endif + + float final_alpha = color.a * vertex_color.a; + + if (color.a < minimum_alpha) + { + discard; + } + + color.rgb *= vertex_color.rgb; + color.rgb = srgb_to_linear(color.rgb); + + + color.rgb = fullbrightAtmosTransport(color.rgb); + color.rgb = fullbrightScaleSoftClip(color.rgb); + + color.rgb = linear_to_srgb(color.rgb); + +#ifdef WATER_FOG + vec3 pos = vary_position; + vec4 fogged = applyWaterFogDeferred(pos, vec4(color.rgb, final_alpha)); + color.rgb = fogged.rgb; + color.a = fogged.a; +#else + color.a = final_alpha; +#endif + + frag_color.rgb = color.rgb; + frag_color.a = color.a; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index a532b67cd9..21349e8c63 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -122,17 +122,8 @@ void main() float final_alpha = color.a * vertex_color.a; -#ifdef HAS_ALPHA_MASK - if (color.a < minimum_alpha) - { - discard; - } -#endif - color.rgb *= vertex_color.rgb; color.rgb = srgb_to_linear(color.rgb); - - color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 8411fd250b..07953c38fb 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -1611,9 +1611,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredFullbrightAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; gDeferredFullbrightAlphaMaskProgram.mShaderFiles.clear(); gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); - gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightAlphaMaskF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredFullbrightAlphaMaskProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; - gDeferredFullbrightAlphaMaskProgram.addPermutation("HAS_ALPHA_MASK","1"); success = gDeferredFullbrightAlphaMaskProgram.createShader(NULL, NULL); } @@ -1642,10 +1641,9 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.clear(); gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); - gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightAlphaMaskF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredFullbrightAlphaMaskWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; gDeferredFullbrightAlphaMaskWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; - gDeferredFullbrightAlphaMaskWaterProgram.addPermutation("HAS_ALPHA_MASK","1"); gDeferredFullbrightAlphaMaskWaterProgram.addPermutation("WATER_FOG","1"); success = gDeferredFullbrightAlphaMaskWaterProgram.createShader(NULL, NULL); } -- cgit v1.2.3 From fa74313e7db1132cd76313864d72aac27902a126 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Jul 2013 04:52:59 -0700 Subject: NORSPEC-314 WIP make work-around easier to flip and add 9800M as an evil mac --- indra/llrender/llgl.cpp | 3 ++- indra/newview/lldrawpoolsimple.cpp | 40 ++++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 088ba95b75..351fd98ced 100755 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -647,7 +647,8 @@ bool LLGLManager::initGL() } #if LL_DARWIN else if ((mGLRenderer.find("9400M") != std::string::npos) - || (mGLRenderer.find("9600M") != std::string::npos)) + || (mGLRenderer.find("9600M") != std::string::npos) + || (mGLRenderer.find("9800M") != std::string::npos)) { mIsMobileGF = TRUE; } diff --git a/indra/newview/lldrawpoolsimple.cpp b/indra/newview/lldrawpoolsimple.cpp index d51b84cfbc..06e8a3537a 100755 --- a/indra/newview/lldrawpoolsimple.cpp +++ b/indra/newview/lldrawpoolsimple.cpp @@ -37,6 +37,7 @@ #include "llviewershadermgr.h" #include "llrender.h" +#define GE_FORCE_WORKAROUND LL_DARWIN static LLGLSLShader* simple_shader = NULL; static LLGLSLShader* fullbright_shader = NULL; @@ -654,7 +655,20 @@ void LLDrawPoolFullbrightAlphaMask::beginPostDeferredPass(S32 pass) gObjectFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 1.0f); } else - { + { + +#if GE_FORCE_WORKAROUND + // Work-around until we can figure out why the right shader causes + // the GeForce driver to go tango uniform on OS X 10.6.8 only + // + if (gGLManager.mIsMobileGF) + { + gObjectFullbrightAlphaMaskProgram.bind(); + gObjectFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); + return; + } +#endif + if (LLPipeline::sUnderWaterRender) { gDeferredFullbrightAlphaMaskWaterProgram.bind(); @@ -665,7 +679,6 @@ void LLDrawPoolFullbrightAlphaMask::beginPostDeferredPass(S32 pass) gDeferredFullbrightAlphaMaskProgram.bind(); gDeferredFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); } - } } @@ -685,11 +698,26 @@ void LLDrawPoolFullbrightAlphaMask::endPostDeferredPass(S32 pass) } else { -#if LL_DARWIN - gObjectFullbrightAlphaMaskProgram.unbind(); -#else - gDeferredFullbrightAlphaMaskProgram.unbind(); + +#if GE_FORCE_WORKAROUND + // Work-around until we can figure out why the right shader causes + // the GeForce driver to go tango uniform on OS X 10.6.8 only + // + if (gGLManager.mIsMobileGF) + { + gObjectFullbrightAlphaMaskProgram.unbind(); + } + else #endif + if (LLPipeline::sUnderWaterRender) + { + gDeferredFullbrightAlphaMaskWaterProgram.unbind(); + } + else + { + gDeferredFullbrightAlphaMaskProgram.unbind(); + } + } LLRenderPass::endRenderPass(pass); } -- cgit v1.2.3 From 6ca0bbe3365b3d554789915ac143a87d2d39fdfa Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 23 Jul 2013 10:39:32 -0400 Subject: Fix for BUG-3364 --- indra/llwindow/llwindowmacosx.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index a3e88ea7dc..56472e6b45 100755 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -316,7 +316,7 @@ void callMouseMoved(float *pos, MASK mask) outCoords.mX += deltas[0]; outCoords.mY += deltas[1]; gWindowImplementation->getCallbacks()->handleMouseMove(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); - gWindowImplementation->getCallbacks()->handleScrollWheel(gWindowImplementation, 0); + //gWindowImplementation->getCallbacks()->handleScrollWheel(gWindowImplementation, 0); } void callScrollMoved(float delta) @@ -849,20 +849,24 @@ BOOL LLWindowMacOSX::setSizeImpl(const LLCoordScreen size) { if(mWindow) { - setWindowSize(mWindow, size.mX, size.mY); + LLCoordWindow to; + convertCoords(size, &to); + setWindowSize(mWindow, to.mX, to.mY); + return TRUE; } - return TRUE; + return FALSE; } BOOL LLWindowMacOSX::setSizeImpl(const LLCoordWindow size) { if (mWindow) { - LLCoordScreen screen_size; - convertCoords(size, &screen_size); - return setSizeImpl(screen_size); + const int titlePadding = 22; + setWindowSize(mWindow, size.mX, size.mY + titlePadding); + return TRUE; } + return FALSE; } -- cgit v1.2.3 From 3c336c0f36966900c234a804d13421d296edccfc Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 23 Jul 2013 10:56:59 -0400 Subject: Fix for BUG-3363. We have an array of URLs, and we need the paths of those URLs. Explicitly get the path. --- indra/newview/llfilepicker_mac.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/llfilepicker_mac.mm b/indra/newview/llfilepicker_mac.mm index c41639fbd5..2a84226e0a 100644 --- a/indra/newview/llfilepicker_mac.mm +++ b/indra/newview/llfilepicker_mac.mm @@ -89,7 +89,7 @@ std::vector* doLoadDialog(const std::vector* allowed_t } for (i=0; ipush_back(*afilestr); } -- cgit v1.2.3 From d8102b2c5c0c925064356006aa7f2f6081fc6852 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Jul 2013 08:37:35 -0700 Subject: NORSPEC-293 hazy glowing fullbright begone --- .../class1/deferred/fullbrightAlphaMaskF.glsl | 149 --------------------- .../shaders/class1/deferred/fullbrightF.glsl | 23 +++- indra/newview/llviewershadermgr.cpp | 6 +- 3 files changed, 23 insertions(+), 155 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl deleted file mode 100644 index eb7a95513c..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl +++ /dev/null @@ -1,149 +0,0 @@ -/** - * @file fullbrightF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -#if !HAS_DIFFUSE_LOOKUP -uniform sampler2D diffuseMap; -#endif - -VARYING vec3 vary_position; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -vec3 fullbrightAtmosTransport(vec3 light); -vec3 fullbrightScaleSoftClip(vec3 light); - -uniform float minimum_alpha; - -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ - //normalize view vector - vec3 view = normalize(pos); - float es = -(dot(view, waterPlane.xyz)); - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); - - //get object depth - float depth = length(pos - int_v); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - float F = 0.98; - - float t1 = -kd * pow(F, ks * e0); - float t2 = kd + ks * es; - float t3 = pow(F, t2*l) - 1.0; - - float L = min(t1/t2*t3, 1.0); - - float D = pow(0.98, l*kd); - - color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; - - return color; -} -#endif - -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} - -void main() -{ -#if HAS_DIFFUSE_LOOKUP - vec4 color = diffuseLookup(vary_texcoord0.xy); -#else - vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); -#endif - - float final_alpha = color.a * vertex_color.a; - - if (color.a < minimum_alpha) - { - discard; - } - - color.rgb *= vertex_color.rgb; - color.rgb = srgb_to_linear(color.rgb); - - - color.rgb = fullbrightAtmosTransport(color.rgb); - color.rgb = fullbrightScaleSoftClip(color.rgb); - - color.rgb = linear_to_srgb(color.rgb); - -#ifdef WATER_FOG - vec3 pos = vary_position; - vec4 fogged = applyWaterFogDeferred(pos, vec4(color.rgb, final_alpha)); - color.rgb = fogged.rgb; - color.a = fogged.a; -#else - color.a = final_alpha; -#endif - - frag_color.rgb = color.rgb; - frag_color.a = color.a; -} - diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 21349e8c63..da2585f662 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -39,8 +39,16 @@ VARYING vec3 vary_position; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec3 fullbrightAtmosTransport(vec3 light); -vec3 fullbrightScaleSoftClip(vec3 light); +vec3 fullbrightAtmosTransportDeferred(vec3 light) +{ + return light; +} + +vec3 fullbrightScaleSoftClipDeferred(vec3 light) +{ + //soft clip effect: + return light; +} #ifdef HAS_ALPHA_MASK uniform float minimum_alpha; @@ -122,10 +130,17 @@ void main() float final_alpha = color.a * vertex_color.a; +#ifdef HAS_ALPHA_MASK + if (color.a < minimum_alpha) + { + discard; + } +#endif + color.rgb *= vertex_color.rgb; color.rgb = srgb_to_linear(color.rgb); - color.rgb = fullbrightAtmosTransport(color.rgb); - color.rgb = fullbrightScaleSoftClip(color.rgb); + color.rgb = fullbrightAtmosTransportDeferred(color.rgb); + color.rgb = fullbrightScaleSoftClipDeferred(color.rgb); color.rgb = linear_to_srgb(color.rgb); diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 07953c38fb..c24284fda2 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -1611,7 +1611,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredFullbrightAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; gDeferredFullbrightAlphaMaskProgram.mShaderFiles.clear(); gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); - gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightAlphaMaskF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredFullbrightAlphaMaskWaterProgram.addPermutation("HAS_ALPHA_MASK","1"); gDeferredFullbrightAlphaMaskProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; success = gDeferredFullbrightAlphaMaskProgram.createShader(NULL, NULL); } @@ -1641,9 +1642,10 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.clear(); gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); - gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightAlphaMaskF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredFullbrightAlphaMaskWaterProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredFullbrightAlphaMaskWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; gDeferredFullbrightAlphaMaskWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER; + gDeferredFullbrightAlphaMaskWaterProgram.addPermutation("HAS_ALPHA_MASK","1"); gDeferredFullbrightAlphaMaskWaterProgram.addPermutation("WATER_FOG","1"); success = gDeferredFullbrightAlphaMaskWaterProgram.createShader(NULL, NULL); } -- cgit v1.2.3 From 18c7ef32762a6c23fdb1dfe875669fd9ebab0bfe Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Jul 2013 11:36:25 -0700 Subject: Fix regression causing fullbright alpha-masked objects to be opaque --- indra/newview/llviewershadermgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index c24284fda2..ad29c413e5 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -1612,7 +1612,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredFullbrightAlphaMaskProgram.mShaderFiles.clear(); gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER_ARB)); - gDeferredFullbrightAlphaMaskWaterProgram.addPermutation("HAS_ALPHA_MASK","1"); + gDeferredFullbrightAlphaMaskProgram.addPermutation("HAS_ALPHA_MASK","1"); gDeferredFullbrightAlphaMaskProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; success = gDeferredFullbrightAlphaMaskProgram.createShader(NULL, NULL); } -- cgit v1.2.3 From b411179bd0cffdf02b3109b72c7b79e4f7a5a2e3 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Jul 2013 13:48:57 -0700 Subject: NORSPEC-314 make work-around apply to all Macs for now --- indra/newview/lldrawpoolsimple.cpp | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/indra/newview/lldrawpoolsimple.cpp b/indra/newview/lldrawpoolsimple.cpp index 06e8a3537a..aee9d19d19 100755 --- a/indra/newview/lldrawpoolsimple.cpp +++ b/indra/newview/lldrawpoolsimple.cpp @@ -657,18 +657,13 @@ void LLDrawPoolFullbrightAlphaMask::beginPostDeferredPass(S32 pass) else { +// Work-around until we can figure out why the right shader causes +// the GeForce driver to go tango uniform on OS X 10.6.8 only +// #if GE_FORCE_WORKAROUND - // Work-around until we can figure out why the right shader causes - // the GeForce driver to go tango uniform on OS X 10.6.8 only - // - if (gGLManager.mIsMobileGF) - { - gObjectFullbrightAlphaMaskProgram.bind(); - gObjectFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); - return; - } -#endif - + gObjectFullbrightAlphaMaskProgram.bind(); + gObjectFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); +#else if (LLPipeline::sUnderWaterRender) { gDeferredFullbrightAlphaMaskWaterProgram.bind(); @@ -679,7 +674,9 @@ void LLDrawPoolFullbrightAlphaMask::beginPostDeferredPass(S32 pass) gDeferredFullbrightAlphaMaskProgram.bind(); gDeferredFullbrightAlphaMaskProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); } +#endif } + } void LLDrawPoolFullbrightAlphaMask::renderPostDeferred(S32 pass) @@ -699,16 +696,12 @@ void LLDrawPoolFullbrightAlphaMask::endPostDeferredPass(S32 pass) else { -#if GE_FORCE_WORKAROUND - // Work-around until we can figure out why the right shader causes - // the GeForce driver to go tango uniform on OS X 10.6.8 only - // - if (gGLManager.mIsMobileGF) - { - gObjectFullbrightAlphaMaskProgram.unbind(); - } - else -#endif +// Work-around until we can figure out why the right shader causes +// the GeForce driver to go tango uniform on OS X 10.6.8 only +// +#if GE_FORCE_WORKAROUND + gObjectFullbrightAlphaMaskProgram.unbind(); +#else if (LLPipeline::sUnderWaterRender) { gDeferredFullbrightAlphaMaskWaterProgram.unbind(); @@ -717,6 +710,7 @@ void LLDrawPoolFullbrightAlphaMask::endPostDeferredPass(S32 pass) { gDeferredFullbrightAlphaMaskProgram.unbind(); } +#endif } LLRenderPass::endRenderPass(pass); -- cgit v1.2.3 From 96869baaefae1f322bff5114429e7fa73b6d4bf9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Jul 2013 14:28:52 -0700 Subject: NORSPEC-285 NORSPEC-298 alpha vs diff color differences --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- .../app_settings/shaders/class1/deferred/diffuseIndexedF.glsl | 4 ++-- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 8 +++----- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 2eef99dea7..c8c23c6ce4 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -79,7 +79,7 @@ uniform vec2 screen_res; vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); - a = pow(a, 1.0/1.3); + //a = pow(a, 1.0/1.3); return vec3(a,a,a); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 997c8d61d3..10b899c91d 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -61,12 +61,12 @@ vec3 linear_to_srgb(vec3 cl) void main() { - vec3 col = vertex_color.rgb * srgb_to_linear(diffuseLookup(vary_texcoord0.xy).rgb); + vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; vec3 spec; spec.rgb = vec3(vertex_color.a); - frag_data[0] = vec4(linear_to_srgb(col), 0.0); + frag_data[0] = vec4(col, 0.0); frag_data[1] = vec4(spec, vertex_color.a); // spec vec3 nvn = normalize(vary_normal); frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 954a27b698..52842c27cc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -672,7 +672,7 @@ void main() col.rgb *= ambient; - col.rgb = col.rgb + atmosAffectDirectionalLight(pow(final_da, 1.0/1.3)); + col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); //pow(final_da, 1.0/1.3)); col.rgb *= old_diffcol.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 950512a79d..1f5cab6cd5 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -378,7 +378,7 @@ void main() norm.xyz = decode_normal(norm.xy); // unpack norm float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - da = pow(da, 1.0/1.3); + //da = pow(da, 1.0/1.3); vec4 diffuse = texture2DRect(diffuseRect, tc); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 0c71b4f554..233985631b 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -385,8 +385,8 @@ void main() float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - float light_gamma = 1.0/1.3; - da = pow(da, light_gamma); + //float light_gamma = 1.0/1.3; + //da = pow(da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); @@ -400,12 +400,10 @@ void main() vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; - scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); + //scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); float scol = max(scol_ambocc.r, diffuse.a); - - float ambocc = scol_ambocc.g; calcAtmospherics(pos.xyz, ambocc); -- cgit v1.2.3 From 72a0ae58e909b017c07e543bc99adc1db5e89180 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 23 Jul 2013 16:09:58 -0700 Subject: NORSPEC-293 fix sRGB to linear conversion to not scrooge the darks --- .../shaders/class1/deferred/alphaF.glsl | 5 +++++ .../shaders/class1/deferred/diffuseIndexedF.glsl | 25 +++------------------- .../shaders/class1/deferred/materialF.glsl | 5 +++++ .../shaders/class1/deferred/softenLightF.glsl | 5 +++++ .../shaders/class2/deferred/softenLightF.glsl | 13 ++++++++--- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index c8c23c6ce4..b928761358 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -189,6 +189,11 @@ vec3 srgb_to_linear(vec3 cs) cl = { { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + vec3 low_range = cs / vec3(12.92); + + if (((cs.r + cs.g + cs.b) / 3) <= 0.04045) + return low_range; + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 10b899c91d..6fe34b887a 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -39,34 +39,15 @@ vec2 encode_normal(vec3 n) return n.xy / f + 0.5; } -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} - void main() { - vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; + vec4 diff = diffuseLookup(vary_texcoord0.xy); + vec3 col = vertex_color.rgb * diff.rgb; vec3 spec; spec.rgb = vec3(vertex_color.a); - frag_data[0] = vec4(col, 0.0); + frag_data[0] = vec4(col, 0); frag_data[1] = vec4(spec, vertex_color.a); // spec vec3 nvn = normalize(vary_normal); frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 52842c27cc..e028eef900 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -38,6 +38,11 @@ vec3 srgb_to_linear(vec3 cs) cl = { { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + vec3 low_range = cs / vec3(12.92); + + if (((cs.r + cs.g + cs.b) / 3) <= 0.04045) + return low_range; + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 1f5cab6cd5..6f11e8427c 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -86,6 +86,11 @@ vec3 srgb_to_linear(vec3 cs) cl = { { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + vec3 low_range = cs / vec3(12.92); + + if (((cs.r + cs.g + cs.b) / 3) <= 0.04045) + return low_range; + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 233985631b..dbb32c40f4 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -85,6 +85,11 @@ vec3 srgb_to_linear(vec3 cs) cl = { { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + vec3 low_range = cs / vec3(12.92); + + if (((cs.r + cs.g + cs.b) / 3) <= 0.04045) + return low_range; + return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); } @@ -420,6 +425,7 @@ void main() col *= diffuse.rgb; + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection @@ -445,11 +451,10 @@ void main() vec3 refcol = textureCube(environmentMap, env_vec).rgb; - col = mix(col.rgb, refcol, - envIntensity); + col = mix(col.rgb, refcol, envIntensity); } - + if (norm.w < 0.5) { col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); @@ -462,6 +467,8 @@ void main() bloom = fogged.a; #endif + + col = srgb_to_linear(col); //col = vec3(1,0,1); -- cgit v1.2.3 From e290dd3fa175c2a891cc4f4e0c401edb10cedfb4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 24 Jul 2013 04:03:27 -0700 Subject: NORSPEC-311 make post deferred (alpha objects) respect same gamma ramp as deferred (opaque objects) --- indra/llrender/llshadermgr.cpp | 3 ++- indra/llrender/llshadermgr.h | 3 ++- .../newview/app_settings/shaders/class1/deferred/alphaF.glsl | 11 +++++++++-- .../app_settings/shaders/class1/deferred/fullbrightF.glsl | 5 +++++ .../app_settings/shaders/class1/deferred/materialF.glsl | 9 +++++++-- .../shaders/class1/deferred/postDeferredGammaCorrect.glsl | 8 ++++++-- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 9 ++++++--- .../app_settings/shaders/class2/deferred/softenLightF.glsl | 7 +++++-- indra/newview/lldrawpoolalpha.cpp | 5 +++++ indra/newview/pipeline.cpp | 4 ++-- 10 files changed, 49 insertions(+), 15 deletions(-) diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index fea4ee2819..942f6dc86f 100755 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1138,7 +1138,8 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("global_gamma"); mReservedUniforms.push_back("texture_gamma"); - + mReservedUniforms.push_back("display_gamma"); + mReservedUniforms.push_back("specular_color"); mReservedUniforms.push_back("env_intensity"); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index c049e935b8..2cbeea5049 100755 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -168,7 +168,8 @@ public: GLOBAL_GAMMA, TEXTURE_GAMMA, - + DISPLAY_GAMMA, + SPECULAR_COLOR, ENVIRONMENT_INTENSITY, diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index b928761358..e836e9750f 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -35,6 +35,8 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif +uniform float display_gamma; + #if HAS_SHADOW uniform sampler2DShadow shadowMap0; uniform sampler2DShadow shadowMap1; @@ -204,6 +206,11 @@ vec3 linear_to_srgb(vec3 cl) cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 { 1.0, cl >= 1*/ + cl = clamp(cl, vec3(0), vec3(1)); + + if ((cl.r+cl.g+cl.b) < 0.0031308) + return 12.92 * cl; + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; } @@ -295,7 +302,7 @@ void main() #ifdef USE_VERTEX_COLOR float vertex_color_alpha = diff.a * vertex_color.a; #else - float vertex_color_alpha = 1.0; + float vertex_color_alpha = diff.a; #endif vec3 normal = vary_norm; @@ -333,7 +340,7 @@ void main() color.rgb += diff.rgb * vary_pointlight_col_linear * col.rgb; - color.rgb = linear_to_srgb(color.rgb); + color.rgb = pow(color.rgb,vec3(display_gamma)); #ifdef WATER_FOG color = applyWaterFogDeferred(pos.xyz, color); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index da2585f662..da4ebfea58 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -117,6 +117,11 @@ vec3 linear_to_srgb(vec3 cl) cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 { 1.0, cl >= 1*/ + cl = clamp(cl, vec3(0), vec3(1)); + + if ((cl.r+cl.g+cl.b) < 0.0031308) + return 12.92 * cl; + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index e028eef900..a46fbd9516 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -53,6 +53,11 @@ vec3 linear_to_srgb(vec3 cl) cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 { 1.0, cl >= 1*/ + cl = clamp(cl, vec3(0), vec3(1)); + + if ((cl.r+cl.g+cl.b) < 0.0031308) + return 12.92 * cl; + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; } @@ -701,7 +706,7 @@ void main() col += spec_contrib; } - col = mix(col.rgb, old_diffcol.rgb, diffuse.a); + col = mix(col.rgb, diffcol.rgb, diffuse.a); if (envIntensity > 0.0) { @@ -754,7 +759,7 @@ void main() frag_color.a = al; #else - //final_color.rgb = vec3(1,0,1); + //final_color.rgb = old_diffcol.rgb; frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 59b027a045..01f9d99682 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -36,7 +36,7 @@ uniform sampler2DRect diffuseRect; uniform vec2 screen_res; VARYING vec2 vary_fragcoord; -uniform float texture_gamma; +uniform float display_gamma; vec3 linear_to_srgb(vec3 cl) { @@ -45,13 +45,17 @@ vec3 linear_to_srgb(vec3 cl) cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 { 1.0, cl >= 1*/ + cl = clamp(cl, vec3(0), vec3(1)); + + if ((cl.r+cl.g+cl.b) < 0.0031308) + return 12.92 * cl; return 1.055 * pow(cl, vec3(0.41666)) - 0.055; } void main() { vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - diff.rgb = pow(diff.rgb,vec3(texture_gamma)); + diff.rgb = pow(diff.rgb,vec3(display_gamma)); frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 6f11e8427c..045b449bbf 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -101,6 +101,11 @@ vec3 linear_to_srgb(vec3 cl) cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 { 1.0, cl >= 1*/ + cl = clamp(cl, vec3(0), vec3(1)); + + if ((cl.r+cl.g+cl.b) < 0.0031308) + return 12.92 * cl; + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; } @@ -403,9 +408,7 @@ void main() ambient = (1.0-ambient); col.rgb *= ambient; - - col += atmosAffectDirectionalLight(max(min(da, 1.0), 0.0)); - + col += atmosAffectDirectionalLight(max(min(da, 1.0), 0.0)); col *= diffuse.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index dbb32c40f4..fa67c4ecea 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -100,6 +100,11 @@ vec3 linear_to_srgb(vec3 cl) cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 { 1.0, cl >= 1*/ + cl = clamp(cl, vec3(0), vec3(1)); + + if ((cl.r+cl.g+cl.b) < 0.0031308) + return 12.92 * cl; + return 1.055 * pow(cl, vec3(0.41666)) - 0.055; } @@ -467,8 +472,6 @@ void main() bloom = fogged.a; #endif - - col = srgb_to_linear(col); //col = vec3(1,0,1); diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 973e263572..6302cf6b00 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -103,13 +103,18 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) simple_shader = &gDeferredAlphaProgram; fullbright_shader = &gDeferredFullbrightProgram; } + + F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); fullbright_shader->bind(); fullbright_shader->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); + fullbright_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); fullbright_shader->unbind(); //prime simple shader (loads shadow relevant uniforms) gPipeline.bindDeferredShader(*simple_shader); + + simple_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); } else { diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index c593c85ce7..165b28beb5 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8833,7 +8833,7 @@ void LLPipeline::renderDeferredLighting() F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); - gDeferredPostGammaCorrectProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); + gDeferredPostGammaCorrectProgram.uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); gGL.begin(LLRender::TRIANGLE_STRIP); gGL.texCoord2f(tc1.mV[0], tc1.mV[1]); @@ -9382,7 +9382,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); - gDeferredPostGammaCorrectProgram.uniform1f(LLShaderMgr::TEXTURE_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); + gDeferredPostGammaCorrectProgram.uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); gGL.begin(LLRender::TRIANGLE_STRIP); gGL.texCoord2f(tc1.mV[0], tc1.mV[1]); -- cgit v1.2.3 From 4854444e24e6e6629d0db30dd107f68535fd086e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 24 Jul 2013 06:11:22 -0700 Subject: MATBUG-315 remove unused uniforms from depth downsample frag shaders as they anger some shader compilers despite not being used --- .../newview/app_settings/shaders/class1/interface/downsampleDepthF.glsl | 2 -- .../app_settings/shaders/class1/interface/downsampleDepthRectF.glsl | 2 -- 2 files changed, 4 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/interface/downsampleDepthF.glsl b/indra/newview/app_settings/shaders/class1/interface/downsampleDepthF.glsl index 6523a06d22..f8efd7cb4a 100644 --- a/indra/newview/app_settings/shaders/class1/interface/downsampleDepthF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/downsampleDepthF.glsl @@ -31,8 +31,6 @@ out vec4 frag_color; uniform sampler2D depthMap; -uniform float delta; - VARYING vec2 tc0; VARYING vec2 tc1; VARYING vec2 tc2; diff --git a/indra/newview/app_settings/shaders/class1/interface/downsampleDepthRectF.glsl b/indra/newview/app_settings/shaders/class1/interface/downsampleDepthRectF.glsl index 0e5dc08183..942c5888e7 100644 --- a/indra/newview/app_settings/shaders/class1/interface/downsampleDepthRectF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/downsampleDepthRectF.glsl @@ -33,8 +33,6 @@ out vec4 frag_color; uniform sampler2DRect depthMap; -uniform float delta; - VARYING vec2 tc0; VARYING vec2 tc1; VARYING vec2 tc2; -- cgit v1.2.3 From 7e2c4cd91df9f8d696d77e21e58ba9937977ab3d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 24 Jul 2013 08:26:28 -0700 Subject: NORSPEC-314 fix discrepancies between alpha and non-alpha deferred point/spot atten --- .../shaders/class1/deferred/alphaF.glsl | 36 +++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index e836e9750f..ea6d22d9c2 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -85,7 +85,7 @@ vec3 calcDirectionalLight(vec3 n, vec3 l) return vec3(a,a,a); } -vec3 calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) { //get light vector vec3 lv = lp.xyz-v; @@ -93,7 +93,9 @@ vec3 calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float //get distance float d = length(lv); - float da = 0.0; + float da = 1.0; + + vec3 col = vec3(0); if (d > 0.0 && la > 0.0 && fa > 0.0) { @@ -102,20 +104,25 @@ vec3 calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float //distance attenuation float dist = d/la; - da = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); - da *= da; - da *= 2.0; - + float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0; // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation - da *= max(dot(n, lv), 0.0); + da *= max(dot(n, lv), 0.0); + + float lit = max(da * dist_atten,0.0); + + col = light_col * lit * diffuse; + + // no spec for alpha shader... } - return vec3(da,da,da); + return max(col, vec3(0.0,0.0,0.0)); } #if HAS_SHADOW @@ -321,15 +328,12 @@ void main() color.rgb *= gamma_diff.rgb; color.rgb = atmosLighting(color.rgb); - color.rgb = scaleSoftClip(color.rgb); - - color.rgb = srgb_to_linear(color.rgb); col = vec4(0,0,0,0); - #define LIGHT_LOOP(i) col.rgb += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, normal, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); - + #define LIGHT_LOOP(i) col.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diff.rgb, pos.xyz, normal, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + LIGHT_LOOP(1) LIGHT_LOOP(2) LIGHT_LOOP(3) @@ -338,8 +342,12 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) - color.rgb += diff.rgb * vary_pointlight_col_linear * col.rgb; + // keep it linear + // + color.rgb = srgb_to_linear(color.rgb) + col.rgb; + // ramp directly to display gamma as we're POST-deferred + // color.rgb = pow(color.rgb,vec3(display_gamma)); #ifdef WATER_FOG -- cgit v1.2.3 From d6b4124fb96768aad8840490efa31d9b800cb3ea Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 24 Jul 2013 11:21:40 -0700 Subject: NORSPEC-311 WIP move to per-pixel alpha lighting and make spot/point calcs match more closely --- .../shaders/class1/deferred/alphaF.glsl | 285 ++++++++++++++++++--- .../shaders/class1/deferred/alphaV.glsl | 103 +------- .../shaders/class1/deferred/materialF.glsl | 9 +- .../shaders/class1/deferred/multiSpotLightF.glsl | 2 +- .../shaders/class1/deferred/pointLightF.glsl | 2 +- .../shaders/class1/deferred/spotLightF.glsl | 2 +- .../shaders/class2/deferred/multiSpotLightF.glsl | 2 +- .../shaders/class2/deferred/spotLightF.glsl | 2 +- indra/newview/llviewershadermgr.cpp | 15 -- 9 files changed, 256 insertions(+), 166 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index ea6d22d9c2..f4298d2bde 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -36,6 +36,24 @@ out vec4 frag_color; #endif uniform float display_gamma; +uniform vec4 gamma; +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; +uniform vec4 glow; +uniform float scene_light_strength; +uniform mat3 env_mat; +uniform mat3 ssao_effect_mat; + +uniform vec3 sun_dir; #if HAS_SHADOW uniform sampler2DShadow shadowMap0; @@ -55,29 +73,26 @@ uniform float shadow_bias; uniform sampler2D diffuseMap; #endif -vec3 atmosLighting(vec3 light); -vec3 scaleSoftClip(vec3 light); - -VARYING vec3 vary_ambient; -VARYING vec3 vary_directional; VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; -VARYING vec3 vary_pointlight_col; -VARYING vec3 vary_pointlight_col_linear; VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; - -#ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; -#endif + +vec3 vary_PositionEye; +vec3 vary_SunlitColor; +vec3 vary_AmblitColor; +vec3 vary_AdditiveColor; +vec3 vary_AtmosAttenuation; + +uniform mat4 inv_proj; +uniform vec2 screen_res; uniform vec4 light_position[8]; uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -uniform vec2 screen_res; - vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); @@ -191,6 +206,192 @@ vec4 applyWaterFogDeferred(vec3 pos, vec4 color) } #endif +vec3 getSunlitColor() +{ + return vary_SunlitColor; +} +vec3 getAmblitColor() +{ + return vary_AmblitColor; +} +vec3 getAdditiveColor() +{ + return vary_AdditiveColor; +} +vec3 getAtmosAttenuation() +{ + return vary_AtmosAttenuation; +} + +void setPositionEye(vec3 v) +{ + vary_PositionEye = v; +} + +void setSunlitColor(vec3 v) +{ + vary_SunlitColor = v; +} + +void setAmblitColor(vec3 v) +{ + vary_AmblitColor = v; +} + +void setAdditiveColor(vec3 v) +{ + vary_AdditiveColor = v; +} + +void setAtmosAttenuation(vec3 v) +{ + vary_AtmosAttenuation = v; +} + +void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + + vec3 P = inPositionEye; + setPositionEye(P); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + //I had thought blue_density and haze_density should have equal weighting, + //but attenuation due to haze_density tends to seem too strong + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + setAtmosAttenuation(temp1.rgb); + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + setAdditiveColor( + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient))); + + //brightness of surface both sunlight and ambient + setSunlitColor(vec3(sunlight * .5)); + setAmblitColor(vec3(tmpAmbient * .25)); + setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); +} + +vec3 atmosLighting(vec3 light) +{ + light *= getAtmosAttenuation().r; + light += getAdditiveColor(); + return (2.0 * light); +} + +vec3 atmosTransport(vec3 light) { + light *= getAtmosAttenuation().r; + light += getAdditiveColor() * 2.0; + return light; +} +vec3 atmosGetDiffuseSunlightColor() +{ + return getSunlitColor(); +} + +vec3 scaleDownLight(vec3 light) +{ + return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); +} + +vec3 scaleUpLight(vec3 light) +{ + return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); +} + +vec3 atmosAmbient(vec3 light) +{ + return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); +} + +vec3 atmosAffectDirectionalLight(float lightIntensity) +{ + return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); +} + +vec3 scaleSoftClip(vec3 light) +{ + //soft clip effect: + vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); + vec3 ones = vec3(1.0f, 1.0f, 1.0f); + + light = ones - clamp(light, zeroes, ones); + light = ones - pow(light, gamma.xxx); + + return light; +} + +vec3 fullbrightAtmosTransport(vec3 light) { + float brightness = dot(light.rgb, vec3(0.33333)); + + return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); +} + +vec3 fullbrightScaleSoftClip(vec3 light) +{ + //soft clip effect: + return light; +} + vec3 srgb_to_linear(vec3 cs) { @@ -229,13 +430,15 @@ void main() vec4 pos = vec4(vary_position, 1.0); + float shadow = 1.0; -#if HAS_SHADOW - float shadow = 0.0; +#if HAS_SHADOW vec4 spos = pos; if (spos.z > -shadow_clip.w) { + shadow = 0.0; + vec4 lpos; vec4 near_split = shadow_clip*-0.75; @@ -294,7 +497,6 @@ void main() { shadow = 1.0; } - #endif #ifdef USE_INDEXED_TEX @@ -303,36 +505,43 @@ void main() vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif vec4 gamma_diff = diff; - - diff.rgb = srgb_to_linear(diff.rgb); -#ifdef USE_VERTEX_COLOR - float vertex_color_alpha = diff.a * vertex_color.a; -#else - float vertex_color_alpha = diff.a; -#endif + diff.rgb = srgb_to_linear(diff.rgb); + diff.rgb *= vertex_color.rgb; + + float final_alpha = diff.a * vertex_color.a; - vec3 normal = vary_norm; + vec3 norm = vary_norm; + + calcAtmospherics(pos.xyz, 1.0); - vec3 l = light_position[0].xyz; - vec3 dlight = calcDirectionalLight(normal, l); - dlight = dlight * vary_directional.rgb * vary_pointlight_col; + float da =dot(norm.xyz, sun_dir.xyz); + float final_da = da; + final_da = min(final_da, shadow); + final_da = max(final_da, final_alpha); + final_da = max(final_da, 0.0f); -#if HAS_SHADOW - vec4 col = vec4(vary_ambient + dlight * shadow, vertex_color_alpha); -#else - vec4 col = vec4(vary_ambient + dlight, vertex_color_alpha); -#endif + vec4 color = vec4(0,0,0,0); - vec4 color = col; + color.rgb = atmosAmbient(color.rgb); + color.a = final_alpha; + + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); + + color.rgb *= ambient; + + color.rgb += atmosAffectDirectionalLight(final_da); color.rgb *= gamma_diff.rgb; - color.rgb = atmosLighting(color.rgb); - color.rgb = scaleSoftClip(color.rgb); - - col = vec4(0,0,0,0); + color.rgb = mix(atmosLighting(color.rgb), fullbrightAtmosTransport(color.rgb), diff.a); + color.rgb = mix(scaleSoftClip(color.rgb), fullbrightScaleSoftClip(color.rgb), diff.a); + + vec4 light = vec4(0,0,0,0); - #define LIGHT_LOOP(i) col.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diff.rgb, pos.xyz, normal, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diff.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -344,7 +553,7 @@ void main() // keep it linear // - color.rgb = srgb_to_linear(color.rgb) + col.rgb; + color.rgb = srgb_to_linear(color.rgb) + light.rgb; // ramp directly to display gamma as we're POST-deferred // diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 6b5b54b863..3696234af6 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -41,10 +41,7 @@ void passTextureIndex(); ATTRIBUTE vec3 normal; -#ifdef USE_VERTEX_COLOR ATTRIBUTE vec4 diffuse_color; -#endif - ATTRIBUTE vec2 texcoord0; #ifdef HAS_SKIN @@ -55,78 +52,14 @@ mat4 getSkinnedTransform(); #endif #endif -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); -void calcAtmospherics(vec3 inPositionEye); - -vec3 atmosAmbient(vec3 light); -vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); -vec3 scaleUpLight(vec3 light); - -VARYING vec3 vary_ambient; -VARYING vec3 vary_directional; VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; -VARYING vec3 vary_pointlight_col; -VARYING vec3 vary_pointlight_col_linear; - -#ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; -#endif - VARYING vec2 vary_texcoord0; - VARYING vec3 vary_norm; uniform float near_clip; -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -uniform vec3 sun_dir; - -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) -{ - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float d = dot(lv,lv); - - float da = 0.0; - - if (d > 0.0 && la > 0.0 && fa > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist2 = d/la; - da = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - //angular attenuation - da *= max(dot(n, lv), 0.0); - } - - return vec3(da,da,da); -} - void main() { vec4 pos; @@ -179,40 +112,7 @@ void main() vary_norm = norm; vary_position = pos.xyz; - calcAtmospherics(pos.xyz); - -#ifndef USE_VERTEX_COLOR - vec4 diffuse_color = vec4(1,1,1,1); -#endif - //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); - vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); - - vec3 diff = diffuse_color.rgb; - - vary_pointlight_col = diff; - vary_pointlight_col_linear = srgb_to_linear(diff); - - col.rgb = vec3(0,0,0); - - // Add windlight lights - col.rgb = atmosAmbient(col.rgb); - - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb *= ambient; - - vary_ambient = col.rgb*diff.rgb; - - vary_directional.rgb = atmosAffectDirectionalLight(1.0f); - - col.rgb = col.rgb*diff.rgb; - -#ifdef USE_VERTEX_COLOR - vertex_color = col; -#endif + vertex_color = diffuse_color; #ifdef HAS_SKIN vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); @@ -228,4 +128,3 @@ void main() #endif } - diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a46fbd9516..b8c5360486 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -538,7 +538,7 @@ void main() #endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 old_diffcol = diffcol.rgb; + vec3 gamma_diff = diffcol.rgb; diffcol.rgb = srgb_to_linear(diffcol.rgb); #endif @@ -558,7 +558,7 @@ void main() dot(norm.xyz,vary_mat1), dot(norm.xyz,vary_mat2)); #else - vec4 norm = vec4(0,0,0,1.0); + vec4 norm = vec4(0,1,0,1.0); vec3 tnorm = vary_normal; #endif @@ -683,8 +683,7 @@ void main() col.rgb *= ambient; col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); //pow(final_da, 1.0/1.3)); - col.rgb *= old_diffcol.rgb; - + col.rgb *= gamma_diff.rgb; float glare = 0.0; @@ -745,7 +744,6 @@ void main() glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; - //convert to gamma space for display on screen col.rgb = linear_to_srgb(col.rgb); @@ -759,7 +757,6 @@ void main() frag_color.a = al; #else - //final_color.rgb = old_diffcol.rgb; frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 11220bfa47..3b6724479c 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -198,7 +198,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff+1.0; + float fa = falloff; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 106d48bd71..4ca0c35d91 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -115,7 +115,7 @@ void main() float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; - float fa = falloff+1.0; + float fa = falloff; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 61262c9eb5..53732e961c 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -201,7 +201,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff+1.0; + float fa = falloff; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 0aac9d77de..4af0970726 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -207,7 +207,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff+1.0; + float fa = falloff; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 17c0d26f6d..544a0a6730 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -204,7 +204,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff+1.0; + float fa = falloff; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index ad29c413e5..4a43a1255a 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -1263,9 +1263,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSkinnedAlphaProgram.mName = "Deferred Skinned Alpha Shader"; gDeferredSkinnedAlphaProgram.mFeatures.atmosphericHelpers = true; gDeferredSkinnedAlphaProgram.mFeatures.hasObjectSkinning = true; - gDeferredSkinnedAlphaProgram.mFeatures.calculatesAtmospherics = true; - gDeferredSkinnedAlphaProgram.mFeatures.hasGamma = true; - gDeferredSkinnedAlphaProgram.mFeatures.hasAtmospherics = true; gDeferredSkinnedAlphaProgram.mFeatures.calculatesLighting = false; gDeferredSkinnedAlphaProgram.mFeatures.hasLighting = false; gDeferredSkinnedAlphaProgram.mFeatures.isAlphaLighting = true; @@ -1275,7 +1272,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSkinnedAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredSkinnedAlphaProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; gDeferredSkinnedAlphaProgram.addPermutation("USE_DIFFUSE_TEX", "1"); - gDeferredSkinnedAlphaProgram.addPermutation("USE_VERTEX_COLOR", "1"); gDeferredSkinnedAlphaProgram.addPermutation("HAS_SKIN", "1"); gDeferredSkinnedAlphaProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); success = gDeferredSkinnedAlphaProgram.createShader(NULL, NULL); @@ -1508,9 +1504,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaProgram.mName = "Deferred Alpha Shader"; gDeferredAlphaProgram.mFeatures.atmosphericHelpers = true; gDeferredAlphaProgram.mFeatures.calculatesLighting = false; - gDeferredAlphaProgram.mFeatures.calculatesAtmospherics = true; - gDeferredAlphaProgram.mFeatures.hasGamma = true; - gDeferredAlphaProgram.mFeatures.hasAtmospherics = true; gDeferredAlphaProgram.mFeatures.hasLighting = false; gDeferredAlphaProgram.mFeatures.isAlphaLighting = true; gDeferredAlphaProgram.mFeatures.disableTextureIndex = true; //hack to disable auto-setup of texture channels @@ -1527,7 +1520,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredAlphaProgram.addPermutation("USE_INDEXED_TEX", "1"); - gDeferredAlphaProgram.addPermutation("USE_VERTEX_COLOR", "1"); gDeferredAlphaProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); gDeferredAlphaProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1543,9 +1535,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaWaterProgram.mName = "Deferred Alpha Underwater Shader"; gDeferredAlphaWaterProgram.mFeatures.atmosphericHelpers = true; gDeferredAlphaWaterProgram.mFeatures.calculatesLighting = false; - gDeferredAlphaWaterProgram.mFeatures.calculatesAtmospherics = true; - gDeferredAlphaWaterProgram.mFeatures.hasGamma = true; - gDeferredAlphaWaterProgram.mFeatures.hasAtmospherics = true; gDeferredAlphaWaterProgram.mFeatures.hasLighting = false; gDeferredAlphaWaterProgram.mFeatures.isAlphaLighting = true; gDeferredAlphaWaterProgram.mFeatures.disableTextureIndex = true; //hack to disable auto-setup of texture channels @@ -1562,7 +1551,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaWaterProgram.mShaderFiles.push_back(make_pair("deferred/alphaV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredAlphaWaterProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredAlphaWaterProgram.addPermutation("USE_INDEXED_TEX", "1"); - gDeferredAlphaWaterProgram.addPermutation("USE_VERTEX_COLOR", "1"); gDeferredAlphaWaterProgram.addPermutation("WATER_FOG", "1"); gDeferredAlphaWaterProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); gDeferredAlphaWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1858,9 +1846,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAvatarAlphaProgram.mFeatures.atmosphericHelpers = true; gDeferredAvatarAlphaProgram.mFeatures.hasSkinning = true; gDeferredAvatarAlphaProgram.mFeatures.calculatesLighting = false; - gDeferredAvatarAlphaProgram.mFeatures.calculatesAtmospherics = true; - gDeferredAvatarAlphaProgram.mFeatures.hasGamma = true; - gDeferredAvatarAlphaProgram.mFeatures.hasAtmospherics = true; gDeferredAvatarAlphaProgram.mFeatures.hasLighting = false; gDeferredAvatarAlphaProgram.mFeatures.isAlphaLighting = true; gDeferredAvatarAlphaProgram.mFeatures.disableTextureIndex = true; -- cgit v1.2.3 From e681d19ea678ae378807b2054d33b6b1abcb8b6b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 24 Jul 2013 12:17:39 -0700 Subject: MATBUG-306 regression fix, vert color applied in wrong colorspace --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index f4298d2bde..e3be7a52ec 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -504,11 +504,11 @@ void main() #else vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif - vec4 gamma_diff = diff; - - diff.rgb = srgb_to_linear(diff.rgb); diff.rgb *= vertex_color.rgb; + vec4 gamma_diff = diff; + diff.rgb = srgb_to_linear(diff.rgb); + float final_alpha = diff.a * vertex_color.a; vec3 norm = vary_norm; -- cgit v1.2.3 From e21ab706b93229964e59fa1d4c221ead30983486 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 24 Jul 2013 15:43:38 -0700 Subject: NORSPEC-324 when using display_gamma, actually set display_gamma --- indra/newview/lldrawpoolavatar.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index 87e9071c4d..b6eee124e1 100755 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -49,6 +49,7 @@ #include "llappviewer.h" #include "llrendersphere.h" #include "llviewerpartsim.h" +#include "llviewercontrol.h" // for gSavedSettings static U32 sDataMask = LLDrawPoolAvatar::VERTEX_DATA_MASK; static U32 sBufferUsage = GL_STREAM_DRAW_ARB; @@ -281,6 +282,11 @@ void LLDrawPoolAvatar::beginDeferredRiggedAlpha() { sVertexProgram = &gDeferredSkinnedAlphaProgram; gPipeline.bindDeferredShader(*sVertexProgram); + + sVertexProgram->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); + F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); + sVertexProgram->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); + sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); gPipeline.enableLightsDynamic(); } @@ -890,6 +896,8 @@ void LLDrawPoolAvatar::beginRiggedGlow() sVertexProgram->bind(); sVertexProgram->uniform1f(LLShaderMgr::TEXTURE_GAMMA, LLPipeline::sRenderDeferred ? 2.2f : 1.1f); + F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); + sVertexProgram->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); } } @@ -942,6 +950,9 @@ void LLDrawPoolAvatar::beginRiggedFullbright() else { sVertexProgram->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); + + F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); + sVertexProgram->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); } } } @@ -1043,6 +1054,8 @@ void LLDrawPoolAvatar::beginRiggedFullbrightShiny() else { sVertexProgram->uniform1f(LLShaderMgr::TEXTURE_GAMMA, 2.2f); + F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); + sVertexProgram->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); } } } -- cgit v1.2.3 From 24cef8d36b13c02ec06c58cc66d9bce040891069 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 24 Jul 2013 17:43:56 -0700 Subject: NORSPEC-326 eliminate identity theft causing mac nV mobile shader compilation fail --- indra/newview/llviewershadermgr.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 4a43a1255a..1ea176565b 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -1261,7 +1261,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredSkinnedAlphaProgram.mName = "Deferred Skinned Alpha Shader"; - gDeferredSkinnedAlphaProgram.mFeatures.atmosphericHelpers = true; gDeferredSkinnedAlphaProgram.mFeatures.hasObjectSkinning = true; gDeferredSkinnedAlphaProgram.mFeatures.calculatesLighting = false; gDeferredSkinnedAlphaProgram.mFeatures.hasLighting = false; @@ -1502,7 +1501,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredAlphaProgram.mName = "Deferred Alpha Shader"; - gDeferredAlphaProgram.mFeatures.atmosphericHelpers = true; + gDeferredAlphaProgram.mFeatures.calculatesLighting = false; gDeferredAlphaProgram.mFeatures.hasLighting = false; gDeferredAlphaProgram.mFeatures.isAlphaLighting = true; @@ -1533,7 +1532,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredAlphaWaterProgram.mName = "Deferred Alpha Underwater Shader"; - gDeferredAlphaWaterProgram.mFeatures.atmosphericHelpers = true; gDeferredAlphaWaterProgram.mFeatures.calculatesLighting = false; gDeferredAlphaWaterProgram.mFeatures.hasLighting = false; gDeferredAlphaWaterProgram.mFeatures.isAlphaLighting = true; @@ -1843,7 +1841,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredAvatarAlphaProgram.mName = "Avatar Alpha Shader"; - gDeferredAvatarAlphaProgram.mFeatures.atmosphericHelpers = true; gDeferredAvatarAlphaProgram.mFeatures.hasSkinning = true; gDeferredAvatarAlphaProgram.mFeatures.calculatesLighting = false; gDeferredAvatarAlphaProgram.mFeatures.hasLighting = false; -- cgit v1.2.3 From f357269c38a8627aeb67c82c5ee34b49336e0d8b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 25 Jul 2013 09:36:13 -0700 Subject: NORSPEC-325 WIP restore gamma (uncorrected) attenuation and unify sRGB conversion in one place --- indra/llrender/llglslshader.cpp | 1 + indra/llrender/llglslshader.h | 1 + indra/llrender/llshadermgr.cpp | 13 +++++- indra/llrender/llshadermgr.h | 5 ++- .../shaders/class1/deferred/alphaF.glsl | 38 +++-------------- .../shaders/class1/deferred/diffuseIndexedF.glsl | 6 +-- .../shaders/class1/deferred/fullbrightF.glsl | 28 ++----------- .../shaders/class1/deferred/materialF.glsl | 45 ++++---------------- .../shaders/class1/deferred/multiSpotLightF.glsl | 23 ++-------- .../shaders/class1/deferred/pointLightF.glsl | 2 +- .../class1/deferred/postDeferredGammaCorrect.glsl | 14 +------ .../shaders/class1/deferred/softenLightF.glsl | 38 +++-------------- .../shaders/class1/deferred/spotLightF.glsl | 23 ++-------- .../app_settings/shaders/class1/deferred/srgb.glsl | 49 ++++++++++++++++++++++ .../shaders/class1/deferred/underWaterF.glsl | 21 +--------- .../shaders/class1/deferred/waterF.glsl | 21 +--------- .../shaders/class2/deferred/multiSpotLightF.glsl | 16 ++----- .../shaders/class2/deferred/softenLightF.glsl | 43 ++++--------------- .../shaders/class2/deferred/spotLightF.glsl | 13 ++---- indra/newview/llviewershadermgr.cpp | 23 +++++++++- 20 files changed, 139 insertions(+), 284 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/srgb.glsl diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index ac16e30796..b854218e3d 100755 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -87,6 +87,7 @@ LLShaderFeatures::LLShaderFeatures() , mIndexedTextureChannels(0) , disableTextureIndex(false) , hasAlphaMask(false) + , hasSRGB(false) { } diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index eabdb9fc92..dadffeb6c4 100755 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -50,6 +50,7 @@ public: S32 mIndexedTextureChannels; bool disableTextureIndex; bool hasAlphaMask; + bool hasSRGB; // char numLights; diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 942f6dc86f..c3e76f5e0e 100755 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -175,6 +175,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) // Attach Fragment Shader Features Next /////////////////////////////////////// + if (features->hasSRGB) + { + if (!shader->attachObject("deferred/srgb.glsl")) + { + return FALSE; + } + } + if(features->calculatesAtmospherics) { if (features->hasWaterFog) @@ -1137,12 +1145,13 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("projectionMap"); mReservedUniforms.push_back("global_gamma"); - mReservedUniforms.push_back("texture_gamma"); - mReservedUniforms.push_back("display_gamma"); + mReservedUniforms.push_back("texture_gamma"); mReservedUniforms.push_back("specular_color"); mReservedUniforms.push_back("env_intensity"); + mReservedUniforms.push_back("display_gamma"); + llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); std::set dupe_check; diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 2cbeea5049..3c282bf24f 100755 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -167,12 +167,13 @@ public: DEFERRED_PROJECTION, GLOBAL_GAMMA, - TEXTURE_GAMMA, - DISPLAY_GAMMA, + TEXTURE_GAMMA, SPECULAR_COLOR, ENVIRONMENT_INTENSITY, + DISPLAY_GAMMA, + END_RESERVED_UNIFORMS } eGLSLReservedUniforms; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index e3be7a52ec..075699c591 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -93,10 +93,13 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); + vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); - //a = pow(a, 1.0/1.3); + a = pow(a, 1.0/1.3); return vec3(a,a,a); } @@ -392,37 +395,6 @@ vec3 fullbrightScaleSoftClip(vec3 light) return light; } -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - vec3 low_range = cs / vec3(12.92); - - if (((cs.r + cs.g + cs.b) / 3) <= 0.04045) - return low_range; - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - cl = clamp(cl, vec3(0), vec3(1)); - - if ((cl.r+cl.g+cl.b) < 0.0031308) - return 12.92 * cl; - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} - - void main() { vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; @@ -533,7 +505,7 @@ void main() color.rgb *= ambient; - color.rgb += atmosAffectDirectionalLight(final_da); + color.rgb += atmosAffectDirectionalLight(pow(final_da, 1.0/1.3)); color.rgb *= gamma_diff.rgb; color.rgb = mix(atmosLighting(color.rgb), fullbrightAtmosTransport(color.rgb), diff.a); diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 6fe34b887a..adc361d7a2 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -39,15 +39,15 @@ vec2 encode_normal(vec3 n) return n.xy / f + 0.5; } + void main() { - vec4 diff = diffuseLookup(vary_texcoord0.xy); - vec3 col = vertex_color.rgb * diff.rgb; + vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; vec3 spec; spec.rgb = vec3(vertex_color.a); - frag_data[0] = vec4(col, 0); + frag_data[0] = vec4(col, 0.0); frag_data[1] = vec4(spec, vertex_color.a); // spec vec3 nvn = normalize(vary_normal); frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index da4ebfea58..00548ea826 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -39,6 +39,9 @@ VARYING vec3 vary_position; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); + vec3 fullbrightAtmosTransportDeferred(vec3 light) { return light; @@ -100,31 +103,6 @@ vec4 applyWaterFogDeferred(vec3 pos, vec4 color) } #endif -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - cl = clamp(cl, vec3(0), vec3(1)); - - if ((cl.r+cl.g+cl.b) < 0.0031308) - return 12.92 * cl; - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} - void main() { #if HAS_DIFFUSE_LOOKUP diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index b8c5360486..d3bd55da7a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -30,37 +30,6 @@ uniform float emissive_brightness; - -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - vec3 low_range = cs / vec3(12.92); - - if (((cs.r + cs.g + cs.b) / 3) <= 0.04045) - return low_range; - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - cl = clamp(cl, vec3(0), vec3(1)); - - if ((cl.r+cl.g+cl.b) < 0.0031308) - return 12.92 * cl; - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} - #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #ifdef DEFINE_GL_FRAGCOLOR @@ -145,6 +114,9 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); + #ifdef WATER_FOG uniform vec4 waterPlane; uniform vec4 waterFogColor; @@ -558,7 +530,7 @@ void main() dot(norm.xyz,vary_mat1), dot(norm.xyz,vary_mat2)); #else - vec4 norm = vec4(0,1,0,1.0); + vec4 norm = vec4(0,0,0,1.0); vec3 tnorm = vary_normal; #endif @@ -682,7 +654,7 @@ void main() col.rgb *= ambient; - col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); //pow(final_da, 1.0/1.3)); + col.rgb = col.rgb + atmosAffectDirectionalLight(pow(final_da, 1.0/1.3)); col.rgb *= gamma_diff.rgb; float glare = 0.0; @@ -705,7 +677,7 @@ void main() col += spec_contrib; } - col = mix(col.rgb, diffcol.rgb, diffuse.a); + col = mix(col.rgb, gamma_diff.rgb, diffuse.a); if (envIntensity > 0.0) { @@ -724,11 +696,11 @@ void main() } col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); //convert to linear space before adding local lights col = srgb_to_linear(col); - + vec3 npos = normalize(-pos.xyz); #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); @@ -747,6 +719,7 @@ void main() //convert to gamma space for display on screen col.rgb = linear_to_srgb(col.rgb); + #ifdef WATER_FOG vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al)); col.rgb = temp.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 3b6724479c..0b62c4ec09 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -84,25 +84,8 @@ vec3 decode_normal (vec2 enc) return n; } -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { @@ -198,7 +181,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff; + float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 4ca0c35d91..106d48bd71 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -115,7 +115,7 @@ void main() float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; - float fa = falloff; + float fa = falloff+1.0; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 01f9d99682..89530f4082 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -38,19 +38,7 @@ VARYING vec2 vary_fragcoord; uniform float display_gamma; -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - cl = clamp(cl, vec3(0), vec3(1)); - - if ((cl.r+cl.g+cl.b) < 0.0031308) - return 12.92 * cl; - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} +vec3 linear_to_srgb(vec3 cl); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 045b449bbf..39d613e02b 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -78,37 +78,8 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; - -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - vec3 low_range = cs / vec3(12.92); - - if (((cs.r + cs.g + cs.b) / 3) <= 0.04045) - return low_range; - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - cl = clamp(cl, vec3(0), vec3(1)); - - if ((cl.r+cl.g+cl.b) < 0.0031308) - return 12.92 * cl; - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} - +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc) { @@ -143,7 +114,6 @@ vec3 getPositionEye() { return vary_PositionEye; } - vec3 getSunlitColor() { return vary_SunlitColor; @@ -388,7 +358,7 @@ void main() norm.xyz = decode_normal(norm.xy); // unpack norm float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - //da = pow(da, 1.0/1.3); + da = pow(da, 1.0/1.3); vec4 diffuse = texture2DRect(diffuseRect, tc); @@ -408,7 +378,9 @@ void main() ambient = (1.0-ambient); col.rgb *= ambient; + col += atmosAffectDirectionalLight(max(min(da, 1.0), 0.0)); + col *= diffuse.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 53732e961c..251abfd119 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -82,25 +82,8 @@ vec3 decode_normal (vec2 enc) return n; } -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 correctWithGamma(vec4 col) { @@ -201,7 +184,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff; + float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl new file mode 100644 index 0000000000..177f6c25f8 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl @@ -0,0 +1,49 @@ +/** + * @file srgb.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + return mix(high_range, low_range, lessThanEqual(cs,vec3(0.04045))); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /* { 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + return mix(high_range, low_range, lessThan(cl,vec3(0.0031308))); +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index 938947bbce..858c3a1fe9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -56,25 +56,8 @@ VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec2 encode_normal(vec3 n) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 34189deaad..5538c41d1c 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -67,25 +67,8 @@ VARYING vec4 littleWave; VARYING vec4 view; VARYING vec4 vary_position; -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec2 encode_normal(vec3 n) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 4af0970726..6d1cedee39 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -68,6 +68,9 @@ uniform vec2 screen_res; uniform mat4 inv_proj; +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); + vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -85,22 +88,11 @@ vec3 decode_normal (vec2 enc) return n; } -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - vec4 correctWithGamma(vec4 col) { return vec4(srgb_to_linear(col.rgb), col.a); } - vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); @@ -207,7 +199,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff; + float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index fa67c4ecea..db2faa65d7 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -78,35 +78,8 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - vec3 low_range = cs / vec3(12.92); - - if (((cs.r + cs.g + cs.b) / 3) <= 0.04045) - return low_range; - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - cl = clamp(cl, vec3(0), vec3(1)); - - if ((cl.r+cl.g+cl.b) < 0.0031308) - return 12.92 * cl; - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec2 encode_normal(vec3 n) { @@ -395,8 +368,8 @@ void main() float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - //float light_gamma = 1.0/1.3; - //da = pow(da, light_gamma); + float light_gamma = 1.0/1.3; + da = pow(da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); @@ -410,10 +383,12 @@ void main() vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; - //scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); + scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); float scol = max(scol_ambocc.r, diffuse.a); + + float ambocc = scol_ambocc.g; calcAtmospherics(pos.xyz, ambocc); @@ -430,7 +405,6 @@ void main() col *= diffuse.rgb; - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection @@ -456,7 +430,8 @@ void main() vec3 refcol = textureCube(environmentMap, env_vec).rgb; - col = mix(col.rgb, refcol, envIntensity); + col = mix(col.rgb, refcol, + envIntensity); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 544a0a6730..cfb483ab54 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -85,15 +85,8 @@ vec3 decode_normal (vec2 enc) return n; } -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 correctWithGamma(vec4 col) { @@ -204,7 +197,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff; + float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 1ea176565b..aa3d2f8349 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -911,6 +911,7 @@ BOOL LLViewerShaderMgr::loadBasicShaders() index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/atmosphericsF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/transportF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "environment/waterFogF.glsl", mVertexShaderLevel[SHADER_WATER] ) ); + index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/srgb.glsl", mVertexShaderLevel[SHADER_DEFERRED] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightAlphaMaskNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightFullbrightNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); @@ -1185,7 +1186,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { - gDeferredDiffuseProgram.mName = "Deferred Diffuse Shader"; + gDeferredDiffuseProgram.mName = "Deferred Diffuse Shader"; gDeferredDiffuseProgram.mShaderFiles.clear(); gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseIndexedF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1261,6 +1262,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredSkinnedAlphaProgram.mName = "Deferred Skinned Alpha Shader"; + gDeferredSkinnedAlphaProgram.mFeatures.hasSRGB = true; gDeferredSkinnedAlphaProgram.mFeatures.hasObjectSkinning = true; gDeferredSkinnedAlphaProgram.mFeatures.calculatesLighting = false; gDeferredSkinnedAlphaProgram.mFeatures.hasLighting = false; @@ -1317,6 +1319,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() U32 alpha_mode = i & 0x3; gDeferredMaterialProgram[i].mShaderFiles.clear(); + gDeferredMaterialProgram[i].mFeatures.hasSRGB = true; gDeferredMaterialProgram[i].mShaderFiles.push_back(make_pair("deferred/materialV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMaterialProgram[i].mShaderFiles.push_back(make_pair("deferred/materialF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMaterialProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1342,6 +1345,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() U32 alpha_mode = i & 0x3; gDeferredMaterialWaterProgram[i].mShaderFiles.clear(); + gDeferredMaterialWaterProgram[i].mFeatures.hasSRGB = true; gDeferredMaterialWaterProgram[i].mShaderFiles.push_back(make_pair("deferred/materialV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMaterialWaterProgram[i].mShaderFiles.push_back(make_pair("deferred/materialF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMaterialWaterProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1430,6 +1434,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredMultiLightProgram[i].mName = llformat("Deferred MultiLight Shader %d", i); gDeferredMultiLightProgram[i].mShaderFiles.clear(); + gDeferredMultiLightProgram[i].mFeatures.hasSRGB = true; gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMultiLightProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1442,6 +1447,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSpotLightProgram.mName = "Deferred SpotLight Shader"; gDeferredSpotLightProgram.mShaderFiles.clear(); + gDeferredSpotLightProgram.mFeatures.hasSRGB = true; gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/spotLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1453,6 +1459,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredMultiSpotLightProgram.mName = "Deferred MultiSpotLight Shader"; gDeferredMultiSpotLightProgram.mShaderFiles.clear(); + gDeferredMultiSpotLightProgram.mFeatures.hasSRGB = true; gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiSpotLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMultiSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1502,6 +1509,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredAlphaProgram.mName = "Deferred Alpha Shader"; + gDeferredAlphaProgram.mFeatures.hasSRGB = true; gDeferredAlphaProgram.mFeatures.calculatesLighting = false; gDeferredAlphaProgram.mFeatures.hasLighting = false; gDeferredAlphaProgram.mFeatures.isAlphaLighting = true; @@ -1532,6 +1540,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredAlphaWaterProgram.mName = "Deferred Alpha Underwater Shader"; + gDeferredAlphaWaterProgram.mFeatures.hasSRGB = true; gDeferredAlphaWaterProgram.mFeatures.calculatesLighting = false; gDeferredAlphaWaterProgram.mFeatures.hasLighting = false; gDeferredAlphaWaterProgram.mFeatures.isAlphaLighting = true; @@ -1577,6 +1586,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredFullbrightProgram.mName = "Deferred Fullbright Shader"; + gDeferredFullbrightProgram.mFeatures.hasSRGB = true; gDeferredFullbrightProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightProgram.mFeatures.hasGamma = true; gDeferredFullbrightProgram.mFeatures.hasTransport = true; @@ -1591,6 +1601,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredFullbrightAlphaMaskProgram.mName = "Deferred Fullbright Alpha Masking Shader"; + gDeferredFullbrightAlphaMaskProgram.mFeatures.hasSRGB = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.hasGamma = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.hasTransport = true; @@ -1606,6 +1617,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredFullbrightWaterProgram.mName = "Deferred Fullbright Underwater Shader"; + gDeferredFullbrightWaterProgram.mFeatures.hasSRGB = true; gDeferredFullbrightWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightWaterProgram.mFeatures.hasGamma = true; gDeferredFullbrightWaterProgram.mFeatures.hasTransport = true; @@ -1622,6 +1634,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredFullbrightAlphaMaskWaterProgram.mName = "Deferred Fullbright Underwater Alpha Masking Shader"; + gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasSRGB = true; gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasGamma = true; gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasTransport = true; @@ -1653,6 +1666,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredSkinnedFullbrightProgram.mName = "Skinned Fullbright Shader"; + gDeferredSkinnedFullbrightProgram.mFeatures.hasSRGB = true; gDeferredSkinnedFullbrightProgram.mFeatures.calculatesAtmospherics = true; gDeferredSkinnedFullbrightProgram.mFeatures.hasGamma = true; gDeferredSkinnedFullbrightProgram.mFeatures.hasTransport = true; @@ -1698,6 +1712,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { // load water shader gDeferredWaterProgram.mName = "Deferred Water Shader"; + gDeferredWaterProgram.mFeatures.hasSRGB = true; gDeferredWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredWaterProgram.mFeatures.hasGamma = true; gDeferredWaterProgram.mFeatures.hasTransport = true; @@ -1712,6 +1727,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { // load water shader gDeferredUnderWaterProgram.mName = "Deferred Under Water Shader"; + gDeferredUnderWaterProgram.mFeatures.hasSRGB = true; gDeferredUnderWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredUnderWaterProgram.mFeatures.hasGamma = true; gDeferredUnderWaterProgram.mFeatures.hasTransport = true; @@ -1726,6 +1742,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSoftenProgram.mName = "Deferred Soften Shader"; gDeferredSoftenProgram.mShaderFiles.clear(); + gDeferredSoftenProgram.mFeatures.hasSRGB = true; gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1743,7 +1760,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSoftenWaterProgram.mName = "Deferred Soften Underwater Shader"; gDeferredSoftenWaterProgram.mShaderFiles.clear(); - + gDeferredSoftenWaterProgram.mFeatures.hasSRGB = true; gDeferredSoftenWaterProgram.mShaderFiles.push_back(make_pair("deferred/softenLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSoftenWaterProgram.mShaderFiles.push_back(make_pair("deferred/softenLightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1841,6 +1858,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredAvatarAlphaProgram.mName = "Avatar Alpha Shader"; + gDeferredAvatarAlphaProgram.mFeatures.hasSRGB = true; gDeferredAvatarAlphaProgram.mFeatures.hasSkinning = true; gDeferredAvatarAlphaProgram.mFeatures.calculatesLighting = false; gDeferredAvatarAlphaProgram.mFeatures.hasLighting = false; @@ -1864,6 +1882,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredPostGammaCorrectProgram.mName = "Deferred Gamma Correction Post Process"; gDeferredPostGammaCorrectProgram.mShaderFiles.clear(); + gDeferredPostGammaCorrectProgram.mFeatures.hasSRGB = true; gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredGammaCorrect.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredPostGammaCorrectProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; -- cgit v1.2.3 From 6d21cd2ae1e8a32ccaf750a97199407fb1cacdef Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 25 Jul 2013 11:09:45 -0700 Subject: NORSPEC-324 set gamma value for avatar alpha shader too for gamma correct eyelashes --- indra/newview/lldrawpoolavatar.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index b6eee124e1..e2a23ef56f 100755 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -273,6 +273,9 @@ void LLDrawPoolAvatar::beginPostDeferredAlpha() gPipeline.bindDeferredShader(*sVertexProgram); + F32 gamma = gSavedSettings.getF32("RenderDeferredDisplayGamma"); + sVertexProgram->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); + sVertexProgram->setMinimumAlpha(0.2f); sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); -- cgit v1.2.3 From 3045dd6c5113d03fd0b0453ce916fc2a1c27c4e0 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 25 Jul 2013 12:13:21 -0700 Subject: Make use of vertex_color selectable per shader with alphaF/alphaV again --- .../newview/app_settings/shaders/class1/deferred/alphaF.glsl | 11 +++++++++-- .../newview/app_settings/shaders/class1/deferred/alphaV.glsl | 11 ++++++++++- indra/newview/llviewershadermgr.cpp | 3 +++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 075699c591..52858f45f4 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -77,7 +77,10 @@ VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; + +#ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; +#endif vec3 vary_PositionEye; vec3 vary_SunlitColor; @@ -476,13 +479,17 @@ void main() #else vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif + +#ifdef USE_VERTEX_COLOR + float final_alpha = diff.a * vertex_color.a; diff.rgb *= vertex_color.rgb; +#else + float final_alpha = diff.a; +#endif vec4 gamma_diff = diff; diff.rgb = srgb_to_linear(diff.rgb); - float final_alpha = diff.a * vertex_color.a; - vec3 norm = vary_norm; calcAtmospherics(pos.xyz, 1.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 3696234af6..60d414f2ff 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -41,7 +41,10 @@ void passTextureIndex(); ATTRIBUTE vec3 normal; +#ifdef USE_VERTEX_COLOR ATTRIBUTE vec4 diffuse_color; +#endif + ATTRIBUTE vec2 texcoord0; #ifdef HAS_SKIN @@ -54,7 +57,11 @@ mat4 getSkinnedTransform(); VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; + +#ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; +#endif + VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; @@ -112,8 +119,10 @@ void main() vary_norm = norm; vary_position = pos.xyz; +#ifdef USE_VERTEX_COLOR vertex_color = diffuse_color; - +#endif + #ifdef HAS_SKIN vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); #else diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index aa3d2f8349..f17e88f312 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -1274,6 +1274,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSkinnedAlphaProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; gDeferredSkinnedAlphaProgram.addPermutation("USE_DIFFUSE_TEX", "1"); gDeferredSkinnedAlphaProgram.addPermutation("HAS_SKIN", "1"); + gDeferredSkinnedAlphaProgram.addPermutation("USE_VERTEX_COLOR", "1"); gDeferredSkinnedAlphaProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); success = gDeferredSkinnedAlphaProgram.createShader(NULL, NULL); @@ -1528,6 +1529,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredAlphaProgram.addPermutation("USE_INDEXED_TEX", "1"); gDeferredAlphaProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); + gDeferredAlphaProgram.addPermutation("USE_VERTEX_COLOR", "1"); gDeferredAlphaProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; success = gDeferredAlphaProgram.createShader(NULL, NULL); @@ -1559,6 +1561,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaWaterProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredAlphaWaterProgram.addPermutation("USE_INDEXED_TEX", "1"); gDeferredAlphaWaterProgram.addPermutation("WATER_FOG", "1"); + gDeferredAlphaWaterProgram.addPermutation("USE_VERTEX_COLOR", "1"); gDeferredAlphaWaterProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); gDeferredAlphaWaterProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; -- cgit v1.2.3 From 73703191e0fc91e022d01c91740c1deade8cbaf5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 26 Jul 2013 12:44:05 -0700 Subject: NORSPEC-327 modify 'select' ops in srgb shader code to mollify the doddering mac GLSL compiler --- .../app_settings/shaders/class1/deferred/srgb.glsl | 24 ++++++++++++++++++++++ indra/newview/llviewershadermgr.cpp | 9 +++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl index 177f6c25f8..d532835bf1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +// OLD_SELECT work-around missing mix(vec3,vec,bvec3) in older GLSL versions (*cough* MAC *cough*) + vec3 srgb_to_linear(vec3 cs) { @@ -32,7 +34,17 @@ vec3 srgb_to_linear(vec3 cs) vec3 low_range = cs / vec3(12.92); vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else return mix(high_range, low_range, lessThanEqual(cs,vec3(0.04045))); +#endif } vec3 linear_to_srgb(vec3 cl) @@ -45,5 +57,17 @@ vec3 linear_to_srgb(vec3 cl) cl = clamp(cl, vec3(0), vec3(1)); vec3 low_range = cl * 12.92; vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else return mix(high_range, low_range, lessThan(cl,vec3(0.0031308))); +#endif } + diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index f17e88f312..6e2139ea9e 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -911,7 +911,6 @@ BOOL LLViewerShaderMgr::loadBasicShaders() index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/atmosphericsF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/transportF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "environment/waterFogF.glsl", mVertexShaderLevel[SHADER_WATER] ) ); - index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/srgb.glsl", mVertexShaderLevel[SHADER_DEFERRED] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightAlphaMaskNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightFullbrightNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); @@ -937,6 +936,14 @@ BOOL LLViewerShaderMgr::loadBasicShaders() index_channels.push_back(ch); shaders.push_back( make_pair( "lighting/lightShinyWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(ch); shaders.push_back( make_pair( "lighting/lightFullbrightShinyWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); + index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/srgb.glsl", mVertexShaderLevel[SHADER_DEFERRED] ) ); + +// work-around for missing mix(vec3,vec3,bvec3) on decrepit GLSLs +// +#if LL_DARWIN + attribs["OLD_SELECT"] = "1"; +#endif + for (U32 i = 0; i < shaders.size(); i++) { // Note usage of GL_FRAGMENT_SHADER_ARB -- cgit v1.2.3 From 50be9d611e55340b6d54b0a891e4bdb121954217 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 26 Jul 2013 12:44:05 -0700 Subject: NORSPEC-327 modify 'select' ops in srgb shader code to mollify the doddering mac GLSL compiler --- .../app_settings/shaders/class1/deferred/srgb.glsl | 24 ++++++++++++++++++++++ indra/newview/llviewershadermgr.cpp | 9 +++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl index 177f6c25f8..d532835bf1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +// OLD_SELECT work-around missing mix(vec3,vec,bvec3) in older GLSL versions (*cough* MAC *cough*) + vec3 srgb_to_linear(vec3 cs) { @@ -32,7 +34,17 @@ vec3 srgb_to_linear(vec3 cs) vec3 low_range = cs / vec3(12.92); vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else return mix(high_range, low_range, lessThanEqual(cs,vec3(0.04045))); +#endif } vec3 linear_to_srgb(vec3 cl) @@ -45,5 +57,17 @@ vec3 linear_to_srgb(vec3 cl) cl = clamp(cl, vec3(0), vec3(1)); vec3 low_range = cl * 12.92; vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else return mix(high_range, low_range, lessThan(cl,vec3(0.0031308))); +#endif } + diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index aa3d2f8349..29d3b70389 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -911,7 +911,6 @@ BOOL LLViewerShaderMgr::loadBasicShaders() index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/atmosphericsF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/transportF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "environment/waterFogF.glsl", mVertexShaderLevel[SHADER_WATER] ) ); - index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/srgb.glsl", mVertexShaderLevel[SHADER_DEFERRED] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightAlphaMaskNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightFullbrightNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); @@ -937,6 +936,14 @@ BOOL LLViewerShaderMgr::loadBasicShaders() index_channels.push_back(ch); shaders.push_back( make_pair( "lighting/lightShinyWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(ch); shaders.push_back( make_pair( "lighting/lightFullbrightShinyWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); + index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/srgb.glsl", mVertexShaderLevel[SHADER_DEFERRED] ) ); + +// work-around for missing mix(vec3,vec3,bvec3) on decrepit GLSLs +// +#if LL_DARWIN + attribs["OLD_SELECT"] = "1"; +#endif + for (U32 i = 0; i < shaders.size(); i++) { // Note usage of GL_FRAGMENT_SHADER_ARB -- cgit v1.2.3 From 0f5dbc1935b17d41b98d26f550cf67d3faa69dce Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Sun, 28 Jul 2013 14:03:56 -0700 Subject: NORSPEC-314 fix the fullbright alpha mask logic --- indra/newview/llvovolume.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index c4b4c76254..406591046f 100755 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -5385,7 +5385,11 @@ void LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, std:: { bool material_pass = false; - if (fullbright) + // do NOT use 'fullbright' for this logic or you risk sending + // things without normals down the materials pipeline and will + // render poorly if not crash NORSPEC-240,314 + // + if (te->getFullbright()) { if (mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_MASK) { -- cgit v1.2.3 From c5fc5d9b46121bb0d44d3b35402d604514e2dd4e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sun, 28 Jul 2013 15:43:10 -0700 Subject: NORSPEC-323 fix norm/tangent gen for prim caps --- indra/llmath/llvolume.cpp | 253 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 202 insertions(+), 51 deletions(-) diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 58cac57e7f..b90830ddd8 100755 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -94,6 +94,16 @@ const S32 SCULPT_MIN_AREA_DETAIL = 1; extern BOOL gDebugGL; +void calc_tangent_from_triangle( + LLVector4a& normal, + LLVector4a& tangent_out, + const LLVector4a& v1, + const LLVector2& w1, + const LLVector4a& v2, + const LLVector2& w2, + const LLVector4a& v3, + const LLVector2& w3); + BOOL check_same_clock_dir( const LLVector3& pt1, const LLVector3& pt2, const LLVector3& pt3, const LLVector3& norm) { LLVector3 test = (pt2-pt1)%(pt3-pt2); @@ -1594,7 +1604,7 @@ BOOL LLPath::generate(const LLPathParams& params, F32 detail, S32 split, S32 sides = (S32)llfloor(llfloor((MIN_DETAIL_FACES * detail + twist_mag * 3.5f * (detail-0.5f))) * params.getRevolutions()); if (is_sculpted) - sides = llmax(sculpt_size, 1); + sides = llmax(sculpt_size,1); genNGon(params, sides); } @@ -2062,7 +2072,7 @@ LLVolume::LLVolume(const LLVolumeParams ¶ms, const F32 detail, const BOOL ge generate(); - if (mParams.getSculptID().isNull() && mParams.getSculptType() == LL_SCULPT_TYPE_NONE || mParams.getSculptType() == LL_SCULPT_TYPE_MESH) + if (mParams.getSculptID().isNull() && ((mParams.getSculptType() == LL_SCULPT_TYPE_NONE) || (mParams.getSculptType() == LL_SCULPT_TYPE_MESH))) { createVolumeFaces(); } @@ -4472,9 +4482,6 @@ void LLVolume::generateSilhouetteVertices(std::vector &vertices, continue; //skip degenerate face } - LLVector4a default_norm; - default_norm.set(0,1,0,1); - //for each edge for (S32 k = 0; k < 3; k++) { S32 index = face.mEdge[j*3+k]; @@ -4496,14 +4503,14 @@ void LLVolume::generateSilhouetteVertices(std::vector &vertices, norm_mat.rotate(n[v1], t); - t.normalize3fast_checked(&default_norm); + t.normalize3fast(); normals.push_back(LLVector3(t[0], t[1], t[2])); mat.affineTransform(v[v2], t); vertices.push_back(LLVector3(t[0], t[1], t[2])); norm_mat.rotate(n[v2], t); - t.normalize3fast_checked(&default_norm); + t.normalize3fast(); normals.push_back(LLVector3(t[0], t[1], t[2])); } } @@ -5282,6 +5289,7 @@ LLVolumeFace& LLVolumeFace::operator=(const LLVolumeFace& src) if (src.mTangents) { allocateTangents(src.mNumVertices); + llassert(mTangents); LLVector4a::memcpyNonAliased16((F32*) mTangents, (F32*) src.mTangents, vert_size); } else @@ -5293,6 +5301,7 @@ LLVolumeFace& LLVolumeFace::operator=(const LLVolumeFace& src) if (src.mWeights) { allocateWeights(src.mNumVertices); + llassert(mWeights); LLVector4a::memcpyNonAliased16((F32*) mWeights, (F32*) src.mWeights, vert_size); } else @@ -5308,14 +5317,14 @@ LLVolumeFace& LLVolumeFace::operator=(const LLVolumeFace& src) LLVector4a::memcpyNonAliased16((F32*) mIndices, (F32*) src.mIndices, idx_size); } - + //delete return *this; } LLVolumeFace::~LLVolumeFace() { - ll_aligned_free_16(mExtents); + ll_aligned_free_16(mExtents); mExtents = NULL; freeData(); @@ -5325,7 +5334,7 @@ void LLVolumeFace::freeData() { ll_aligned_free_16(mPositions); mPositions = NULL; - ll_aligned_free_16( mNormals); + ll_aligned_free_16(mNormals); mNormals = NULL; ll_aligned_free_16(mTexCoords); mTexCoords = NULL; @@ -5911,10 +5920,10 @@ void LLVolumeFace::cacheOptimize() wght = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); } - LLVector4a* binorm = NULL; + LLVector4a* tangent = NULL; if (mTangents) { - binorm = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); + tangent = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); } //allocate mapping of old indices to new indices @@ -5939,7 +5948,7 @@ void LLVolumeFace::cacheOptimize() } if (mTangents) { - binorm[cur_idx] = mTangents[idx]; + tangent[cur_idx] = mTangents[idx]; } cur_idx++; @@ -5961,7 +5970,7 @@ void LLVolumeFace::cacheOptimize() mNormals = norm; mTexCoords = tc; mWeights = wght; - mTangents = binorm; + mTangents = tangent; //std::string result = llformat("ACMR pre/post: %.3f/%.3f -- %d triangles %d breaks", pre_acmr, post_acmr, mNumIndices/3, breaks); //llinfos << result << llendl; @@ -6099,9 +6108,6 @@ BOOL LLVolumeFace::createUnCutCubeCap(LLVolume* volume, BOOL partial_build) { VertexData corners[4]; VertexData baseVert; - LLVector4a default_norm; - default_norm.set(0,1,0,1); - for(S32 t = 0; t < 4; t++) { corners[t].getPosition().load3( mesh[offset + (grid_size*t)].mPos.mV); @@ -6115,7 +6121,7 @@ BOOL LLVolumeFace::createUnCutCubeCap(LLVolume* volume, BOOL partial_build) LLVector4a rhs; rhs.setSub(corners[2].getPosition(), corners[1].getPosition()); baseVert.getNormal().setCross3(lhs, rhs); - baseVert.getNormal().normalize3fast_checked(&default_norm); + baseVert.getNormal().normalize3fast(); } if(!(mTypeMask & TOP_MASK)) @@ -6312,6 +6318,43 @@ BOOL LLVolumeFace::createCap(LLVolume* volume, BOOL partial_build) cuv = (min_uv + max_uv)*0.5f; + + LLVector4a tangent; + calc_tangent_from_triangle( + *norm, + tangent, + *mCenter, cuv, + pos[0], tc[0], + pos[1], tc[1]); + + if (tangent.getLength3() < 0.01) + { + tangent.set(1,0,0,1); + } + else + { + LLVector4a default_tangent; + default_tangent.set(1,0,0,1); + tangent.normalize3fast_checked(&default_tangent); + } + + LLVector4a normal; + LLVector4a d0, d1; + + d0.setSub(*mCenter, pos[0]); + d1.setSub(*mCenter, pos[1]); + + if (mTypeMask & TOP_MASK) + { + normal.setCross3(d0, d1); + } + else + { + normal.setCross3(d1, d0); + } + + normal.normalize3fast_checked(); + VertexData vd; vd.setPosition(*mCenter); vd.mTexCoord = cuv; @@ -6323,7 +6366,15 @@ BOOL LLVolumeFace::createCap(LLVolume* volume, BOOL partial_build) num_vertices++; } - + + allocateTangents(num_vertices); + + for (S32 i = 0; i < num_vertices; i++) + { + mTangents[i].load4a(tangent.getF32ptr()); + norm[i].load4a(normal.getF32ptr()); + } + if (partial_build) { return TRUE; @@ -6559,31 +6610,6 @@ BOOL LLVolumeFace::createCap(LLVolume* volume, BOOL partial_build) } - LLVector4a d0,d1; - - d0.setSub(mPositions[mIndices[1]], mPositions[mIndices[0]]); - d1.setSub(mPositions[mIndices[2]], mPositions[mIndices[0]]); - - LLVector4a normal; - LLVector4a default_norm; - default_norm.set(0,1,0,1); - - normal.setCross3(d0,d1); - normal.normalize3fast_checked(&default_norm); - - llassert(llfinite(normal.getF32ptr()[0])); - llassert(llfinite(normal.getF32ptr()[1])); - llassert(llfinite(normal.getF32ptr()[2])); - - llassert(!llisnan(normal.getF32ptr()[0])); - llassert(!llisnan(normal.getF32ptr()[1])); - llassert(!llisnan(normal.getF32ptr()[2])); - - for (S32 i = 0; i < num_vertices; i++) - { - norm[i].load4a(normal.getF32ptr()); - } - return TRUE; } @@ -6616,9 +6642,9 @@ void LLVolumeFace::createTangents() default_norm.set(0,1,0,1); for (U32 i = 0; i < mNumVertices; i++) { - //binorm[i].normalize3fast(); + //tangent[i].normalize3fast(); //bump map/planar projection code requires normals to be normalized - mNormals[i].normalize3fast_checked(&default_norm); + mNormals[i].normalize3fast_checked(); } } } @@ -6693,7 +6719,7 @@ void LLVolumeFace::pushVertex(const LLVector4a& pos, const LLVector4a& norm, con void LLVolumeFace::allocateTangents(S32 num_verts) { - ll_aligned_free_16(mTangents); + ll_aligned_free_16(mTangents); mTangents = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); } @@ -6796,9 +6822,6 @@ void LLVolumeFace::appendFace(const LLVolumeFace& face, LLMatrix4& mat_in, LLMat mat.loadu(mat_in); norm_mat.loadu(norm_mat_in); - LLVector4a default_norm; - default_norm.set(0,1,0,1); - for (U32 i = 0; i < face.mNumVertices; ++i) { //transform appended face position and store @@ -6806,7 +6829,7 @@ void LLVolumeFace::appendFace(const LLVolumeFace& face, LLMatrix4& mat_in, LLMat //transform appended face normal and store norm_mat.rotate(src_norm[i], dst_norm[i]); - dst_norm[i].normalize3fast_checked(&default_norm); + dst_norm[i].normalize3fast_checked(); //copy appended face texture coordinate dst_tc[i] = src_tc[i]; @@ -7215,6 +7238,134 @@ BOOL LLVolumeFace::createSide(LLVolume* volume, BOOL partial_build) return TRUE; } +// Finds binormal based on three vertices with texture coordinates. +// Fills in dummy values if the triangle has degenerate texture coordinates. +void calc_binormal_from_triangle(LLVector4a& binormal, + + const LLVector4a& pos0, + const LLVector2& tex0, + const LLVector4a& pos1, + const LLVector2& tex1, + const LLVector4a& pos2, + const LLVector2& tex2) +{ + LLVector4a rx0( pos0[VX], tex0.mV[VX], tex0.mV[VY] ); + LLVector4a rx1( pos1[VX], tex1.mV[VX], tex1.mV[VY] ); + LLVector4a rx2( pos2[VX], tex2.mV[VX], tex2.mV[VY] ); + + LLVector4a ry0( pos0[VY], tex0.mV[VX], tex0.mV[VY] ); + LLVector4a ry1( pos1[VY], tex1.mV[VX], tex1.mV[VY] ); + LLVector4a ry2( pos2[VY], tex2.mV[VX], tex2.mV[VY] ); + + LLVector4a rz0( pos0[VZ], tex0.mV[VX], tex0.mV[VY] ); + LLVector4a rz1( pos1[VZ], tex1.mV[VX], tex1.mV[VY] ); + LLVector4a rz2( pos2[VZ], tex2.mV[VX], tex2.mV[VY] ); + + LLVector4a lhs, rhs; + + LLVector4a r0; + lhs.setSub(rx0, rx1); rhs.setSub(rx0, rx2); + r0.setCross3(lhs, rhs); + + LLVector4a r1; + lhs.setSub(ry0, ry1); rhs.setSub(ry0, ry2); + r1.setCross3(lhs, rhs); + + LLVector4a r2; + lhs.setSub(rz0, rz1); rhs.setSub(rz0, rz2); + r2.setCross3(lhs, rhs); + + if( r0[VX] && r1[VX] && r2[VX] ) + { + binormal.set( + -r0[VZ] / r0[VX], + -r1[VZ] / r1[VX], + -r2[VZ] / r2[VX]); + // binormal.normVec(); + } + else + { + binormal.set( 0, 1 , 0 ); + } +} + +// Finds binormal based on three vertices with texture coordinates. +// Fills in dummy values if the triangle has degenerate texture coordinates. +void calc_tangent_from_triangle( + LLVector4a& normal, + LLVector4a& tangent_out, + const LLVector4a& v1, + const LLVector2& w1, + const LLVector4a& v2, + const LLVector2& w2, + const LLVector4a& v3, + const LLVector2& w3) +{ + const F32* v1ptr = v1.getF32ptr(); + const F32* v2ptr = v2.getF32ptr(); + const F32* v3ptr = v3.getF32ptr(); + + float x1 = v2ptr[0] - v1ptr[0]; + float x2 = v3ptr[0] - v1ptr[0]; + float y1 = v2ptr[1] - v1ptr[1]; + float y2 = v3ptr[1] - v1ptr[1]; + float z1 = v2ptr[2] - v1ptr[2]; + float z2 = v3ptr[2] - v1ptr[2]; + + float s1 = w2.mV[0] - w1.mV[0]; + float s2 = w3.mV[0] - w1.mV[0]; + float t1 = w2.mV[1] - w1.mV[1]; + float t2 = w3.mV[1] - w1.mV[1]; + + F32 rd = s1*t2-s2*t1; + + float r = ((rd*rd) > FLT_EPSILON) ? 1.0F / rd : 1024.f; //some made up large ratio for division by zero + + llassert(llfinite(r)); + llassert(!llisnan(r)); + + LLVector4a sdir( + (t2 * x1 - t1 * x2) * r, + (t2 * y1 - t1 * y2) * r, + (t2 * z1 - t1 * z2) * r); + + LLVector4a tdir( + (s1 * x2 - s2 * x1) * r, + (s1 * y2 - s2 * y1) * r, + (s1 * z2 - s2 * z1) * r); + + LLVector4a n = normal; + LLVector4a t = sdir; + + LLVector4a ncrosst; + ncrosst.setCross3(n,t); + + // Gram-Schmidt orthogonalize + n.mul(n.dot3(t).getF32()); + + LLVector4a tsubn; + tsubn.setSub(t,n); + + if (tsubn.dot3(tsubn).getF32() > F_APPROXIMATELY_ZERO) + { + tsubn.normalize3fast_checked(); + + // Calculate handedness + F32 handedness = ncrosst.dot3(tdir).getF32() < 0.f ? -1.f : 1.f; + + tsubn.getF32ptr()[3] = handedness; + + tangent_out = tsubn; + } + else + { + // degenerate, make up a value + // + tangent_out.set(0,0,1,1); + } + +} + //adapted from Lengyel, Eric. “Computing Tangent Space Basis Vectors for an Arbitrary Mesh”. Terathon Software 3D Graphics Library, 2001. http://www.terathon.com/code/tangent.html void CalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal, const LLVector2 *texcoord, U32 triangleCount, const U16* index_array, LLVector4a *tangent) -- cgit v1.2.3 From be89f2f8fb234cc8d0d511df2384422d92e134b8 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Sun, 28 Jul 2013 18:29:51 -0700 Subject: NORSPEC-314 fixed another mac-specific stupidity by splitting out a new srgb_mac version of the shader --- .../app_settings/shaders/class1/deferred/srgb.glsl | 33 ++----------- .../shaders/class1/deferred/srgb_mac.glsl | 54 ++++++++++++++++++++++ indra/newview/llviewershadermgr.cpp | 6 ++- 3 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/srgb_mac.glsl diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl index d532835bf1..587f3d5a94 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl @@ -23,51 +23,24 @@ * $/LicenseInfo$ */ -// OLD_SELECT work-around missing mix(vec3,vec,bvec3) in older GLSL versions (*cough* MAC *cough*) - vec3 srgb_to_linear(vec3 cs) { - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - vec3 low_range = cs / vec3(12.92); vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); bvec3 lte = lessThanEqual(cs,vec3(0.04045)); -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lessThanEqual(cs,vec3(0.04045))); -#endif + return mix(high_range, low_range, lte); + } vec3 linear_to_srgb(vec3 cl) { - /* { 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - cl = clamp(cl, vec3(0), vec3(1)); vec3 low_range = cl * 12.92; vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; bvec3 lt = lessThan(cl,vec3(0.0031308)); + return mix(high_range, low_range, lt); -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lessThan(cl,vec3(0.0031308))); -#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb_mac.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb_mac.glsl new file mode 100644 index 0000000000..6cc1e6e798 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/srgb_mac.glsl @@ -0,0 +1,54 @@ +/** + * @file srgb.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + + bvec3 lt = lessThan(cl,vec3(0.0031308)); + + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +} + diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 6e2139ea9e..545a236f81 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -936,12 +936,14 @@ BOOL LLViewerShaderMgr::loadBasicShaders() index_channels.push_back(ch); shaders.push_back( make_pair( "lighting/lightShinyWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(ch); shaders.push_back( make_pair( "lighting/lightFullbrightShinyWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); - index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/srgb.glsl", mVertexShaderLevel[SHADER_DEFERRED] ) ); // work-around for missing mix(vec3,vec3,bvec3) on decrepit GLSLs // #if LL_DARWIN - attribs["OLD_SELECT"] = "1"; + attribs["OLD_SELECT"] = "1"; + index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/srgb_mac.glsl", mVertexShaderLevel[SHADER_DEFERRED] ) ); +#else + index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/srgb.glsl", mVertexShaderLevel[SHADER_DEFERRED] ) ); #endif for (U32 i = 0; i < shaders.size(); i++) -- cgit v1.2.3 From b44e7303d85ffc59afe34a97342d83a04b180c48 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Mon, 29 Jul 2013 18:59:45 -0700 Subject: NORSPEC-314 WIP fix srgb_mac use and issues found with RenderDebugGL on Mac --- indra/llrender/llshadermgr.cpp | 5 ++++ indra/llrender/llvertexbuffer.cpp | 57 +++++++++++++++++++++++++++++++++---- indra/newview/lldrawpoolalpha.cpp | 3 +- indra/newview/llviewershadermgr.cpp | 1 - indra/newview/pipeline.cpp | 19 ++++++------- 5 files changed, 68 insertions(+), 17 deletions(-) diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index c3e76f5e0e..21b8322bf1 100755 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -177,7 +177,12 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) if (features->hasSRGB) { +#if LL_DARWIN + if (!shader->attachObject("deferred/srgb_mac.glsl")) + +#else if (!shader->attachObject("deferred/srgb.glsl")) +#endif { return FALSE; } diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index b1ef6e0576..f1249a842a 100755 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -753,10 +753,10 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi U16* idx = ((U16*) getIndicesPointer())+indices_offset; stop_glerror(); - LLGLSLShader::startProfile(); - glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, + LLGLSLShader::startProfile(); + glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, idx); - LLGLSLShader::stopProfile(count, mode); + LLGLSLShader::stopProfile(count, mode); stop_glerror(); @@ -2209,11 +2209,32 @@ void LLVertexBuffer::bindForFeedback(U32 channel, U32 type, U32 index, U32 count #endif } +void DumpComponents(U32 mask) +{ + llinfos << + ((mask & LLVertexBuffer::MAP_VERTEX) ? "vertex:" : " ") << + ((mask & LLVertexBuffer::MAP_NORMAL) ? "norms:" : " ") << + ((mask & LLVertexBuffer::MAP_TEXCOORD0) ? "TC0:" : " ") << + ((mask & LLVertexBuffer::MAP_TEXCOORD1) ? "TC1:" : " ") << + ((mask & LLVertexBuffer::MAP_TEXCOORD2) ? "TC2:" : " ") << + ((mask & LLVertexBuffer::MAP_TEXCOORD3) ? "TC3:" : " ") << + ((mask & LLVertexBuffer::MAP_COLOR) ? "color:" : " ") << + ((mask & LLVertexBuffer::MAP_EMISSIVE) ? "emissive:" : " ") << + ((mask & LLVertexBuffer::MAP_TANGENT) ? "tangents" : " ") << llendl; +} + // Set for rendering void LLVertexBuffer::setBuffer(U32 data_mask) { flush(); + if((getTypeMask() & data_mask) != data_mask) + { + llinfos << "Missing VB stream components." << llendl; + DumpComponents(data_mask & ~getTypeMask()); + data_mask &= getTypeMask(); + } + //set up pointers if the data mask is different ... bool setup = (sLastMask != data_mask); @@ -2237,15 +2258,36 @@ void LLVertexBuffer::setBuffer(U32 data_mask) } } + static bool done_done_it = false; + + if (!done_done_it) + { + done_done_it = true; + + llinfos << + "MAP_VERTEX: " << MAP_VERTEX << + "MAP_VERTEX: " << MAP_NORMAL << + "MAP_VERTEX: " << MAP_TEXCOORD0 << + "MAP_VERTEX: " << MAP_TEXCOORD1 << + "MAP_VERTEX: " << MAP_TEXCOORD2 << + "MAP_VERTEX: " << MAP_TEXCOORD3 << + "MAP_VERTEX: " << MAP_COLOR << + "MAP_VERTEX: " << MAP_EMISSIVE << + "MAP_VERTEX: " << MAP_TANGENT << llendl; + + + } + if ((data_mask & required_mask) != required_mask) { U32 unsatisfied_mask = (required_mask & ~data_mask); U32 i = 0; - while (i < 15) + while (i < TYPE_MAX) { - switch ((unsatisfied_mask & (1 << i))) + U32 unsatisfied_flag = unsatisfied_mask & (1 << i); + switch (unsatisfied_flag) { case MAP_VERTEX: llinfos << "Missing vert pos" << llendl; break; case MAP_NORMAL: llinfos << "Missing normals" << llendl; break; @@ -2264,6 +2306,11 @@ void LLVertexBuffer::setBuffer(U32 data_mask) } } + if (unsatisfied_mask & (1 << TYPE_INDEX)) + { + llinfos << "Missing indices" << llendl; + } + llerrs << "Shader consumption mismatches data provision." << llendl; } } diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 6302cf6b00..f4f63e1042 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -529,7 +529,8 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask) } } - params.mVertexBuffer->setBuffer(mask); + params.mVertexBuffer->setBuffer(mask & ~(params.mFullbright ? (LLVertexBuffer::MAP_TEXTURE_INDEX | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2) : 0)); + params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 545a236f81..73177d549b 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -1444,7 +1444,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredMultiLightProgram[i].mName = llformat("Deferred MultiLight Shader %d", i); gDeferredMultiLightProgram[i].mShaderFiles.clear(); - gDeferredMultiLightProgram[i].mFeatures.hasSRGB = true; gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMultiLightProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 165b28beb5..05390f64f0 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8695,12 +8695,6 @@ void LLPipeline::renderDeferredLighting() unbindDeferredShader(gDeferredSpotLightProgram); } - //reset mDeferredVB to fullscreen triangle - mDeferredVB->getVertexStrider(vert); - vert[0].set(-1,1,0); - vert[1].set(-1,-3,0); - vert[2].set(3,1,0); - { LLGLDepthTest depth(GL_FALSE); @@ -8719,6 +8713,10 @@ void LLPipeline::renderDeferredLighting() F32 far_z = 0.f; + bindDeferredShader(gDeferredMultiLightProgram[0]); + + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + while (!fullscreen_lights.empty()) { LLFastTimer ftm(FTM_FULLSCREEN_LIGHTS); @@ -8743,14 +8741,15 @@ void LLPipeline::renderDeferredLighting() gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*) col); gDeferredMultiLightProgram[idx].uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z, far_z); far_z = 0.f; - count = 0; - mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + count = 0; + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); + unbindDeferredShader(gDeferredMultiLightProgram[idx]); } } - - unbindDeferredShader(gDeferredMultiLightProgram[0]); + unbindDeferredShader(gDeferredMultiLightProgram[0]); + bindDeferredShader(gDeferredMultiSpotLightProgram); gDeferredMultiSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION); -- cgit v1.2.3 From f86a7c04d3c265f4d61d99d1d7fdb7e35c4bc3f6 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Tue, 30 Jul 2013 11:33:58 -0700 Subject: NORSPEC-314 rollback unified srgb shader code to see if we can get past Mac 10.6.8 nV driver issues --- indra/llrender/llglslshader.cpp | 6 +++- indra/llrender/llglslshader.h | 1 - indra/llrender/llshadermgr.cpp | 13 -------- .../shaders/class1/deferred/alphaF.glsl | 38 +++++++++++++++++++-- .../shaders/class1/deferred/fullbrightF.glsl | 39 ++++++++++++++++++++-- .../shaders/class1/deferred/materialF.glsl | 38 +++++++++++++++++++-- .../shaders/class1/deferred/multiSpotLightF.glsl | 38 +++++++++++++++++++-- .../shaders/class1/deferred/softenLightF.glsl | 39 ++++++++++++++++++++-- .../shaders/class1/deferred/spotLightF.glsl | 38 +++++++++++++++++++-- .../shaders/class1/deferred/underWaterF.glsl | 38 +++++++++++++++++++-- .../shaders/class1/deferred/waterF.glsl | 38 +++++++++++++++++++-- .../shaders/class2/deferred/multiSpotLightF.glsl | 38 +++++++++++++++++++-- .../shaders/class2/deferred/softenLightF.glsl | 38 +++++++++++++++++++-- .../shaders/class2/deferred/spotLightF.glsl | 38 +++++++++++++++++++-- indra/newview/llviewershadermgr.cpp | 28 ---------------- 15 files changed, 403 insertions(+), 65 deletions(-) diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index b854218e3d..40aff36dac 100755 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -87,7 +87,6 @@ LLShaderFeatures::LLShaderFeatures() , mIndexedTextureChannels(0) , disableTextureIndex(false) , hasAlphaMask(false) - , hasSRGB(false) { } @@ -375,6 +374,11 @@ BOOL LLGLSLShader::createShader(vector * attributes, // Create program mProgramObject = glCreateProgramObjectARB(); + +#if LL_DARWIN + // work-around missing mix(vec3,vec3,bvec3) + mDefines["OLD_SELECT"] = "1"; +#endif //compile new source vector< pair >::iterator fileIter = mShaderFiles.begin(); diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index dadffeb6c4..eabdb9fc92 100755 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -50,7 +50,6 @@ public: S32 mIndexedTextureChannels; bool disableTextureIndex; bool hasAlphaMask; - bool hasSRGB; // char numLights; diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 21b8322bf1..63404abeff 100755 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -175,19 +175,6 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) // Attach Fragment Shader Features Next /////////////////////////////////////// - if (features->hasSRGB) - { -#if LL_DARWIN - if (!shader->attachObject("deferred/srgb_mac.glsl")) - -#else - if (!shader->attachObject("deferred/srgb.glsl")) -#endif - { - return FALSE; - } - } - if(features->calculatesAtmospherics) { if (features->hasWaterFog) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 52858f45f4..d11f67ee58 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -96,8 +96,42 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} vec3 calcDirectionalLight(vec3 n, vec3 l) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 00548ea826..f22b16965c 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -39,8 +39,43 @@ VARYING vec3 vary_position; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); + +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} vec3 fullbrightAtmosTransportDeferred(vec3 light) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index d3bd55da7a..b3ae81d494 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -114,8 +114,42 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} #ifdef WATER_FOG uniform vec4 waterPlane; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 0b62c4ec09..ed68e38891 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -83,9 +83,43 @@ vec3 decode_normal (vec2 enc) n.z = 1-f/2; return n; } +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 39d613e02b..0febbcd6e0 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -78,8 +78,43 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} + vec3 decode_normal (vec2 enc) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 251abfd119..48c9cd363c 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -82,8 +82,42 @@ vec3 decode_normal (vec2 enc) return n; } -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index 858c3a1fe9..78f841c733 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -56,8 +56,42 @@ VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} vec2 encode_normal(vec3 n) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 5538c41d1c..d49ff72cf0 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -67,8 +67,42 @@ VARYING vec4 littleWave; VARYING vec4 view; VARYING vec4 vary_position; -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} vec2 encode_normal(vec3 n) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 6d1cedee39..df750d3cec 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -68,8 +68,42 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} vec2 encode_normal(vec3 n) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index db2faa65d7..cc34285d65 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -78,8 +78,42 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} vec2 encode_normal(vec3 n) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index cfb483ab54..bb6afbbf62 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -85,8 +85,42 @@ vec3 decode_normal (vec2 enc) return n; } -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cl); +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 73177d549b..264655029a 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -936,16 +936,6 @@ BOOL LLViewerShaderMgr::loadBasicShaders() index_channels.push_back(ch); shaders.push_back( make_pair( "lighting/lightShinyWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(ch); shaders.push_back( make_pair( "lighting/lightFullbrightShinyWaterF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); - -// work-around for missing mix(vec3,vec3,bvec3) on decrepit GLSLs -// -#if LL_DARWIN - attribs["OLD_SELECT"] = "1"; - index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/srgb_mac.glsl", mVertexShaderLevel[SHADER_DEFERRED] ) ); -#else - index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/srgb.glsl", mVertexShaderLevel[SHADER_DEFERRED] ) ); -#endif - for (U32 i = 0; i < shaders.size(); i++) { // Note usage of GL_FRAGMENT_SHADER_ARB @@ -1271,7 +1261,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredSkinnedAlphaProgram.mName = "Deferred Skinned Alpha Shader"; - gDeferredSkinnedAlphaProgram.mFeatures.hasSRGB = true; gDeferredSkinnedAlphaProgram.mFeatures.hasObjectSkinning = true; gDeferredSkinnedAlphaProgram.mFeatures.calculatesLighting = false; gDeferredSkinnedAlphaProgram.mFeatures.hasLighting = false; @@ -1329,7 +1318,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() U32 alpha_mode = i & 0x3; gDeferredMaterialProgram[i].mShaderFiles.clear(); - gDeferredMaterialProgram[i].mFeatures.hasSRGB = true; gDeferredMaterialProgram[i].mShaderFiles.push_back(make_pair("deferred/materialV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMaterialProgram[i].mShaderFiles.push_back(make_pair("deferred/materialF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMaterialProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1355,7 +1343,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() U32 alpha_mode = i & 0x3; gDeferredMaterialWaterProgram[i].mShaderFiles.clear(); - gDeferredMaterialWaterProgram[i].mFeatures.hasSRGB = true; gDeferredMaterialWaterProgram[i].mShaderFiles.push_back(make_pair("deferred/materialV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMaterialWaterProgram[i].mShaderFiles.push_back(make_pair("deferred/materialF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMaterialWaterProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1456,7 +1443,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSpotLightProgram.mName = "Deferred SpotLight Shader"; gDeferredSpotLightProgram.mShaderFiles.clear(); - gDeferredSpotLightProgram.mFeatures.hasSRGB = true; gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/spotLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1468,7 +1454,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredMultiSpotLightProgram.mName = "Deferred MultiSpotLight Shader"; gDeferredMultiSpotLightProgram.mShaderFiles.clear(); - gDeferredMultiSpotLightProgram.mFeatures.hasSRGB = true; gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiSpotLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMultiSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1518,7 +1503,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredAlphaProgram.mName = "Deferred Alpha Shader"; - gDeferredAlphaProgram.mFeatures.hasSRGB = true; gDeferredAlphaProgram.mFeatures.calculatesLighting = false; gDeferredAlphaProgram.mFeatures.hasLighting = false; gDeferredAlphaProgram.mFeatures.isAlphaLighting = true; @@ -1550,7 +1534,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredAlphaWaterProgram.mName = "Deferred Alpha Underwater Shader"; - gDeferredAlphaWaterProgram.mFeatures.hasSRGB = true; gDeferredAlphaWaterProgram.mFeatures.calculatesLighting = false; gDeferredAlphaWaterProgram.mFeatures.hasLighting = false; gDeferredAlphaWaterProgram.mFeatures.isAlphaLighting = true; @@ -1597,7 +1580,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredFullbrightProgram.mName = "Deferred Fullbright Shader"; - gDeferredFullbrightProgram.mFeatures.hasSRGB = true; gDeferredFullbrightProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightProgram.mFeatures.hasGamma = true; gDeferredFullbrightProgram.mFeatures.hasTransport = true; @@ -1612,7 +1594,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredFullbrightAlphaMaskProgram.mName = "Deferred Fullbright Alpha Masking Shader"; - gDeferredFullbrightAlphaMaskProgram.mFeatures.hasSRGB = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.hasGamma = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.hasTransport = true; @@ -1628,7 +1609,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredFullbrightWaterProgram.mName = "Deferred Fullbright Underwater Shader"; - gDeferredFullbrightWaterProgram.mFeatures.hasSRGB = true; gDeferredFullbrightWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightWaterProgram.mFeatures.hasGamma = true; gDeferredFullbrightWaterProgram.mFeatures.hasTransport = true; @@ -1645,7 +1625,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredFullbrightAlphaMaskWaterProgram.mName = "Deferred Fullbright Underwater Alpha Masking Shader"; - gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasSRGB = true; gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasGamma = true; gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasTransport = true; @@ -1677,7 +1656,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredSkinnedFullbrightProgram.mName = "Skinned Fullbright Shader"; - gDeferredSkinnedFullbrightProgram.mFeatures.hasSRGB = true; gDeferredSkinnedFullbrightProgram.mFeatures.calculatesAtmospherics = true; gDeferredSkinnedFullbrightProgram.mFeatures.hasGamma = true; gDeferredSkinnedFullbrightProgram.mFeatures.hasTransport = true; @@ -1723,7 +1701,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { // load water shader gDeferredWaterProgram.mName = "Deferred Water Shader"; - gDeferredWaterProgram.mFeatures.hasSRGB = true; gDeferredWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredWaterProgram.mFeatures.hasGamma = true; gDeferredWaterProgram.mFeatures.hasTransport = true; @@ -1738,7 +1715,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { // load water shader gDeferredUnderWaterProgram.mName = "Deferred Under Water Shader"; - gDeferredUnderWaterProgram.mFeatures.hasSRGB = true; gDeferredUnderWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredUnderWaterProgram.mFeatures.hasGamma = true; gDeferredUnderWaterProgram.mFeatures.hasTransport = true; @@ -1753,7 +1729,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSoftenProgram.mName = "Deferred Soften Shader"; gDeferredSoftenProgram.mShaderFiles.clear(); - gDeferredSoftenProgram.mFeatures.hasSRGB = true; gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1771,7 +1746,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSoftenWaterProgram.mName = "Deferred Soften Underwater Shader"; gDeferredSoftenWaterProgram.mShaderFiles.clear(); - gDeferredSoftenWaterProgram.mFeatures.hasSRGB = true; gDeferredSoftenWaterProgram.mShaderFiles.push_back(make_pair("deferred/softenLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSoftenWaterProgram.mShaderFiles.push_back(make_pair("deferred/softenLightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1869,7 +1843,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredAvatarAlphaProgram.mName = "Avatar Alpha Shader"; - gDeferredAvatarAlphaProgram.mFeatures.hasSRGB = true; gDeferredAvatarAlphaProgram.mFeatures.hasSkinning = true; gDeferredAvatarAlphaProgram.mFeatures.calculatesLighting = false; gDeferredAvatarAlphaProgram.mFeatures.hasLighting = false; @@ -1893,7 +1866,6 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredPostGammaCorrectProgram.mName = "Deferred Gamma Correction Post Process"; gDeferredPostGammaCorrectProgram.mShaderFiles.clear(); - gDeferredPostGammaCorrectProgram.mFeatures.hasSRGB = true; gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredGammaCorrect.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredPostGammaCorrectProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; -- cgit v1.2.3 From 42ce98e8bfe3fd633e15f703d5ffdad64c2965a5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 30 Jul 2013 13:44:12 -0700 Subject: NORSPEC-314 cleanup debug-only code...seems to fix NORSPEC-328 as well somehow --- indra/llrender/llvertexbuffer.cpp | 45 ++++++++++++++------------------------- indra/newview/pipeline.cpp | 14 ++++++------ 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index f1249a842a..fd7b846928 100755 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -2230,9 +2230,16 @@ void LLVertexBuffer::setBuffer(U32 data_mask) if((getTypeMask() & data_mask) != data_mask) { - llinfos << "Missing VB stream components." << llendl; - DumpComponents(data_mask & ~getTypeMask()); - data_mask &= getTypeMask(); + if (gDebugGL) + { + // Dump info about what was missing + // + DumpComponents(data_mask & ~getTypeMask()); + llwarns << "Missing VB stream components. ^^" << llendl; + } + // Make sure we don't write checks we can't cash below... + // + data_mask = (data_mask & getTypeMask()); } //set up pointers if the data mask is different ... @@ -2257,27 +2264,7 @@ void LLVertexBuffer::setBuffer(U32 data_mask) required_mask |= required; } } - - static bool done_done_it = false; - - if (!done_done_it) - { - done_done_it = true; - - llinfos << - "MAP_VERTEX: " << MAP_VERTEX << - "MAP_VERTEX: " << MAP_NORMAL << - "MAP_VERTEX: " << MAP_TEXCOORD0 << - "MAP_VERTEX: " << MAP_TEXCOORD1 << - "MAP_VERTEX: " << MAP_TEXCOORD2 << - "MAP_VERTEX: " << MAP_TEXCOORD3 << - "MAP_VERTEX: " << MAP_COLOR << - "MAP_VERTEX: " << MAP_EMISSIVE << - "MAP_VERTEX: " << MAP_TANGENT << llendl; - - - } - + if ((data_mask & required_mask) != required_mask) { @@ -2302,14 +2289,14 @@ void LLVertexBuffer::setBuffer(U32 data_mask) case MAP_WEIGHT4: llinfos << "Missing weightx4" << llendl; break; case MAP_CLOTHWEIGHT: llinfos << "Missing clothweight" << llendl; break; case MAP_TEXTURE_INDEX: llinfos << "Missing tex index" << llendl; break; - default: llinfos << "Missing who effin knows" << llendl; + default: llinfos << "Missing who effin knows: " << unsatisfied_flag << llendl; } } - if (unsatisfied_mask & (1 << TYPE_INDEX)) - { - llinfos << "Missing indices" << llendl; - } + if (unsatisfied_mask & (1 << TYPE_INDEX)) + { + llinfos << "Missing indices" << llendl; + } llerrs << "Shader consumption mismatches data provision." << llendl; } diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 05390f64f0..9aa375767b 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8695,6 +8695,12 @@ void LLPipeline::renderDeferredLighting() unbindDeferredShader(gDeferredSpotLightProgram); } + //reset mDeferredVB to fullscreen triangle + mDeferredVB->getVertexStrider(vert); + vert[0].set(-1,1,0); + vert[1].set(-1,-3,0); + vert[2].set(3,1,0); + { LLGLDepthTest depth(GL_FALSE); @@ -8713,10 +8719,6 @@ void LLPipeline::renderDeferredLighting() F32 far_z = 0.f; - bindDeferredShader(gDeferredMultiLightProgram[0]); - - mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); - while (!fullscreen_lights.empty()) { LLFastTimer ftm(FTM_FULLSCREEN_LIGHTS); @@ -8742,13 +8744,11 @@ void LLPipeline::renderDeferredLighting() gDeferredMultiLightProgram[idx].uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z, far_z); far_z = 0.f; count = 0; - mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); + mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX); mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3); unbindDeferredShader(gDeferredMultiLightProgram[idx]); } } - - unbindDeferredShader(gDeferredMultiLightProgram[0]); bindDeferredShader(gDeferredMultiSpotLightProgram); -- cgit v1.2.3 From 4a3c99beb228680b297e9a3388df3290b594cd57 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Thu, 1 Aug 2013 10:34:36 -0700 Subject: NORSPEC-304 fix glow pass rendering over alpha pass after ALM toggle --- indra/newview/lldrawpoolalpha.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index f4f63e1042..bd8ecdb166 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -545,8 +545,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask) emissive_shader->bind(); - // glow doesn't use vertex colors from the mesh data - params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); + params.mVertexBuffer->setBuffer(mask & LLVertexBuffer::MAP_EMISSIVE); // do the actual drawing, again params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); -- cgit v1.2.3 From 2d065562f1dabd090a12b75f1aa4233ce9d7ce33 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 1 Aug 2013 14:01:37 -0700 Subject: NORSPEC-336 fix glow regression from 304 fix --- indra/newview/lldrawpoolalpha.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index bd8ecdb166..1cc81fa863 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -545,7 +545,10 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask) emissive_shader->bind(); - params.mVertexBuffer->setBuffer(mask & LLVertexBuffer::MAP_EMISSIVE); + U32 final_mask = params.mFullbright ? (mask | LLVertexBuffer::MAP_EMISSIVE) + : ((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); + + params.mVertexBuffer->setBuffer(final_mask); // do the actual drawing, again params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); -- cgit v1.2.3 From 14c7108ca3f646a8f7fd0d024ca200919bbf79bf Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sat, 3 Aug 2013 06:52:56 -0700 Subject: NORSPEC-304 NORSPEC-334 NORSPEC-336 fix black glow overdraw without breaking glow --- indra/newview/lldrawpoolalpha.cpp | 5 +---- indra/newview/llvovolume.cpp | 5 ++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 1cc81fa863..237579cec5 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -545,10 +545,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask) emissive_shader->bind(); - U32 final_mask = params.mFullbright ? (mask | LLVertexBuffer::MAP_EMISSIVE) - : ((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); - - params.mVertexBuffer->setBuffer(final_mask); + params.mVertexBuffer->setBuffer((mask & ~LLVertexBuffer::MAP_COLOR) | LLVertexBuffer::MAP_EMISSIVE); // do the actual drawing, again params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 406591046f..3eb5b19de5 100755 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -4881,7 +4881,10 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group) if (emissive) { //emissive faces are present, include emissive byte to preserve batching simple_mask = simple_mask | LLVertexBuffer::MAP_EMISSIVE; - alpha_mask = alpha_mask | LLVertexBuffer::MAP_EMISSIVE; + + // doing this seems to cause NORSPEC-304 + //alpha_mask = alpha_mask | LLVertexBuffer::MAP_EMISSIVE; + bump_mask = bump_mask | LLVertexBuffer::MAP_EMISSIVE; fullbright_mask = fullbright_mask | LLVertexBuffer::MAP_EMISSIVE; norm_mask = norm_mask | LLVertexBuffer::MAP_EMISSIVE; -- cgit v1.2.3 From 9557926fff5992276811c1b1d9aa371ede9004a8 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sat, 3 Aug 2013 08:25:03 -0700 Subject: NORSPEC-332 fix fullbright tex indexing fail --- indra/newview/lldrawpoolalpha.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 237579cec5..fca4492fbb 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -529,7 +529,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask) } } - params.mVertexBuffer->setBuffer(mask & ~(params.mFullbright ? (LLVertexBuffer::MAP_TEXTURE_INDEX | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2) : 0)); + params.mVertexBuffer->setBuffer(mask & ~(params.mFullbright ? (LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2) : 0)); params.mVertexBuffer->drawRange(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); -- cgit v1.2.3 From 938ad0c640a72dc7ee8bf39ad138e6d84d1d0a1e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sun, 4 Aug 2013 05:21:34 -0700 Subject: NORSPEC-305 -NORSPEC-335 fix scale and HUD anim regression from materials changes in CL 28424 --- indra/newview/llviewerobject.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp index 6f7b2f40e6..f29a00e4c4 100755 --- a/indra/newview/llviewerobject.cpp +++ b/indra/newview/llviewerobject.cpp @@ -4410,12 +4410,10 @@ S32 LLViewerObject::setTEMaterialParams(const U8 te, const LLMaterialPtr pMateri void LLViewerObject::refreshMaterials() { - setChanged(ALL_CHANGED); + setChanged(TEXTURE); if (mDrawable.notNull()) { gPipeline.markTextured(mDrawable); - gPipeline.markRebuild(mDrawable,LLDrawable::REBUILD_ALL); - dirtySpatialGroup(TRUE); } } -- cgit v1.2.3 From 08e429e27df488cb8740eb82f3fb10d5011e6f5d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 5 Aug 2013 06:23:13 -0700 Subject: NORSPEC-285 NORSPEC-293 NORSPEC-298 fix ighting diffs between alpha/non/ALM/non-ALM --- .../shaders/class1/deferred/alphaF.glsl | 48 ++++++--- .../shaders/class1/deferred/materialF.glsl | 108 ++++++++++++--------- .../class1/deferred/postDeferredGammaCorrect.glsl | 22 ++++- .../shaders/class1/deferred/softenLightF.glsl | 10 +- 4 files changed, 125 insertions(+), 63 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index d11f67ee58..d0c7cc9dde 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -133,6 +133,23 @@ vec3 linear_to_srgb(vec3 cl) } +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); @@ -527,33 +544,42 @@ void main() vec3 norm = vary_norm; calcAtmospherics(pos.xyz, 1.0); - - float da =dot(norm.xyz, sun_dir.xyz); + + vec2 abnormal = encode_normal(norm.xyz); + norm.xyz = decode_normal(abnormal.xy); + + float da = dot(norm.xyz, sun_dir.xyz); + float final_da = da; final_da = min(final_da, shadow); - final_da = max(final_da, final_alpha); final_da = max(final_da, 0.0f); + final_da = min(final_da, 1.0f); + final_da = pow(final_da, 1.0/1.3); vec4 color = vec4(0,0,0,0); color.rgb = atmosAmbient(color.rgb); color.a = final_alpha; - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + float ambient = abs(da); ambient *= 0.5; ambient *= ambient; ambient = (1.0-ambient); color.rgb *= ambient; - color.rgb += atmosAffectDirectionalLight(pow(final_da, 1.0/1.3)); + color.rgb += atmosAffectDirectionalLight(final_da); color.rgb *= gamma_diff.rgb; - color.rgb = mix(atmosLighting(color.rgb), fullbrightAtmosTransport(color.rgb), diff.a); - color.rgb = mix(scaleSoftClip(color.rgb), fullbrightScaleSoftClip(color.rgb), diff.a); + color.rgb = mix(diff.rgb, color.rgb, final_alpha); + + color.rgb = atmosLighting(color.rgb); + color.rgb = scaleSoftClip(color.rgb); vec4 light = vec4(0,0,0,0); - + + color.rgb = srgb_to_linear(color.rgb); + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diff.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); LIGHT_LOOP(1) @@ -566,11 +592,11 @@ void main() // keep it linear // - color.rgb = srgb_to_linear(color.rgb) + light.rgb; + color.rgb += light.rgb; - // ramp directly to display gamma as we're POST-deferred + // straight to display gamma, we're post-deferred // - color.rgb = pow(color.rgb,vec3(display_gamma)); + color.rgb = linear_to_srgb(color.rgb); #ifdef WATER_FOG color = applyWaterFogDeferred(pos.xyz, color); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index b3ae81d494..8202b4978f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -29,6 +29,44 @@ #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 uniform float emissive_brightness; +uniform float display_gamma; + +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -114,43 +152,6 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -vec3 srgb_to_linear(vec3 cs) -{ - vec3 low_range = cs / vec3(12.92); - vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); - bvec3 lte = lessThanEqual(cs,vec3(0.04045)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lte.r ? low_range.r : high_range.r; - result.g = lte.g ? low_range.g : high_range.g; - result.b = lte.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lte); -#endif - -} - -vec3 linear_to_srgb(vec3 cl) -{ - cl = clamp(cl, vec3(0), vec3(1)); - vec3 low_range = cl * 12.92; - vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; - bvec3 lt = lessThan(cl,vec3(0.0031308)); - -#ifdef OLD_SELECT - vec3 result; - result.r = lt.r ? low_range.r : high_range.r; - result.g = lt.g ? low_range.g : high_range.g; - result.b = lt.b ? low_range.b : high_range.b; - return result; -#else - return mix(high_range, low_range, lt); -#endif - -} - #ifdef WATER_FOG uniform vec4 waterPlane; uniform vec4 waterFogColor; @@ -571,6 +572,9 @@ void main() norm.xyz = tnorm; norm.xyz = normalize(norm.xyz); + vec2 abnormal = encode_normal(norm.xyz); + norm.xyz = decode_normal(abnormal.xy); + vec4 final_color = diffcol; #if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) @@ -666,7 +670,7 @@ void main() vec4 diffuse = final_color; float envIntensity = final_normal.z; - vec3 col = vec3(0.0f,0.0f,0.0f); + vec3 col = vec3(0.0f,0.0f,0.0f); float bloom = 0.0; calcAtmospherics(pos.xyz, 1.0); @@ -674,23 +678,28 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); float da =dot(norm.xyz, sun_dir.xyz); + float final_da = da; final_da = min(final_da, shadow); - final_da = max(final_da, diffuse.a); + //final_da = max(final_da, diffuse.a); final_da = max(final_da, 0.0f); + final_da = min(final_da, 1.0f); + final_da = pow(final_da, 1.0/1.3); col.rgb = atmosAmbient(col); - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + float ambient = min(abs(da), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0-ambient); col.rgb *= ambient; - col.rgb = col.rgb + atmosAffectDirectionalLight(pow(final_da, 1.0/1.3)); + col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); + col.rgb *= gamma_diff.rgb; + float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -711,7 +720,8 @@ void main() col += spec_contrib; } - col = mix(col.rgb, gamma_diff.rgb, diffuse.a); + + col = mix(col.rgb, diffcol.rgb, diffuse.a); if (envIntensity > 0.0) { @@ -729,15 +739,20 @@ void main() glare += cur_glare; } - col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + //col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); + //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + + col = atmosLighting(col); + col = scaleSoftClip(col); //convert to linear space before adding local lights col = srgb_to_linear(col); vec3 npos = normalize(-pos.xyz); - #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); + vec3 light = vec3(0,0,0); + + #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -747,13 +762,14 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) + col.rgb += light.rgb; + glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; //convert to gamma space for display on screen col.rgb = linear_to_srgb(col.rgb); - #ifdef WATER_FOG vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al)); col.rgb = temp.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 89530f4082..4e2f98aa29 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -38,12 +38,30 @@ VARYING vec2 vary_fragcoord; uniform float display_gamma; -vec3 linear_to_srgb(vec3 cl); +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} + void main() { vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - diff.rgb = pow(diff.rgb,vec3(display_gamma)); + diff.rgb = linear_to_srgb(diff.rgb); frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 0febbcd6e0..ebe5e57bb7 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -98,7 +98,6 @@ vec3 srgb_to_linear(vec3 cs) vec3 linear_to_srgb(vec3 cl) { - cl = clamp(cl, vec3(0), vec3(1)); vec3 low_range = cl * 12.92; vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; bvec3 lt = lessThan(cl,vec3(0.0031308)); @@ -392,8 +391,11 @@ void main() float envIntensity = norm.z; norm.xyz = decode_normal(norm.xy); // unpack norm - float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - da = pow(da, 1.0/1.3); + float da = dot(norm.xyz, sun_dir.xyz); + + float final_da = max(0.0,da); + final_da = min(final_da, 1.0f); + final_da = pow(final_da, 1.0/1.3); vec4 diffuse = texture2DRect(diffuseRect, tc); @@ -414,7 +416,7 @@ void main() col.rgb *= ambient; - col += atmosAffectDirectionalLight(max(min(da, 1.0), 0.0)); + col += atmosAffectDirectionalLight(final_da); col *= diffuse.rgb; -- cgit v1.2.3 From 614ee255c6ed782138daecbc8aa886fb0f4e93e2 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 5 Aug 2013 09:12:41 -0700 Subject: NORSPEC-336 intentionally rebreak 304 to fix glow while we find a fix that works for both --- indra/newview/llvovolume.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 3eb5b19de5..5dc59197ca 100755 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -4880,11 +4880,8 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group) if (emissive) { //emissive faces are present, include emissive byte to preserve batching - simple_mask = simple_mask | LLVertexBuffer::MAP_EMISSIVE; - - // doing this seems to cause NORSPEC-304 - //alpha_mask = alpha_mask | LLVertexBuffer::MAP_EMISSIVE; - + simple_mask = simple_mask | LLVertexBuffer::MAP_EMISSIVE; + alpha_mask = alpha_mask | LLVertexBuffer::MAP_EMISSIVE; bump_mask = bump_mask | LLVertexBuffer::MAP_EMISSIVE; fullbright_mask = fullbright_mask | LLVertexBuffer::MAP_EMISSIVE; norm_mask = norm_mask | LLVertexBuffer::MAP_EMISSIVE; -- cgit v1.2.3 From fe69b4049bdbdf36a179ccc28a2f253af13e61c5 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Mon, 5 Aug 2013 10:16:17 -0700 Subject: NORSPEC-304 NORSPEC-336 another attempt as resolving black glow overdraw without breaking glow (even for alpha-blended) faces --- indra/newview/lldrawpoolalpha.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index fca4492fbb..b5d37ba5cc 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -128,14 +128,22 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) gObjectFullbrightAlphaMaskProgram.setMinimumAlpha(0.33f); } - if (LLPipeline::sUnderWaterRender) - { - emissive_shader = &gObjectEmissiveWaterProgram; - } - else - { - emissive_shader = &gObjectEmissiveProgram; - } + + if (LLPipeline::sRenderDeferred) + { + emissive_shader = &gDeferredEmissiveProgram; + } + else + { + if (LLPipeline::sUnderWaterRender) + { + emissive_shader = &gObjectEmissiveWaterProgram; + } + else + { + emissive_shader = &gObjectEmissiveProgram; + } + } deferred_render = TRUE; if (mVertexShaderLevel > 0) -- cgit v1.2.3 From efba897e45b5065619bbe0e1451a40b6391e503c Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Mon, 5 Aug 2013 15:38:43 -0400 Subject: correct coding standards problems --- indra/llwindow/llopenglview-objc.h | 2 +- indra/newview/CMakeLists.txt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 71149f8561..41837b1eb4 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -107,4 +107,4 @@ @end -#endif \ No newline at end of file +#endif diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index df70cd21f1..b81b4a14bd 100755 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -1990,9 +1990,9 @@ if (DARWIN) set_target_properties( ${VIEWER_BINARY_NAME} PROPERTIES - OUTPUT_NAME "${product}" - MACOSX_BUNDLE_INFO_PLIST - "${CMAKE_CURRENT_SOURCE_DIR}/Info-SecondLife.plist" + OUTPUT_NAME "${product}" + MACOSX_BUNDLE_INFO_PLIST + "${CMAKE_CURRENT_SOURCE_DIR}/Info-SecondLife.plist" ) configure_file( -- cgit v1.2.3 From 5b400d50e1f25667e2c865d85fd93546ffe7f96f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 6 Aug 2013 14:16:46 -0700 Subject: NORSPEC-322 NORSPEC-342 fix issues with black impostors and missing alpha attachments on impostors --- .../shaders/class1/deferred/impostorF.glsl | 31 +++++++++++++++++++--- indra/newview/lldrawpoolalpha.cpp | 9 +++++-- indra/newview/lldrawpoolavatar.cpp | 21 +++------------ indra/newview/pipeline.cpp | 21 +++++++-------- 4 files changed, 48 insertions(+), 34 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index bc0719cb82..d52744103f 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -38,6 +38,31 @@ uniform sampler2D specularMap; VARYING vec2 vary_texcoord0; +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 linear_to_srgb(vec3 cl) +{ + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} + void main() { vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); @@ -47,7 +72,7 @@ void main() discard; } - frag_data[0] = vec4(col.rgb, col.a * 0.005); - frag_data[1] = texture2D(specularMap, vary_texcoord0.xy); - frag_data[2] = vec4(texture2D(normalMap, vary_texcoord0.xy).xyz, 0.0); + frag_data[0] = vec4(linear_to_srgb(col.rgb), col.a); + frag_data[1] = vec4(texture2D(specularMap, vary_texcoord0.xy)); + frag_data[2] = vec4(texture2D(normalMap, vary_texcoord0.xy).xy,0,0); } diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index b5d37ba5cc..60e22c08dc 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -224,8 +224,13 @@ void LLDrawPoolAlpha::render(S32 pass) gGL.setColorMask(true, true); } - LLGLDepthTest depth(GL_TRUE, LLDrawPoolWater::sSkipScreenCopy || - (deferred_render && pass == 1) ? GL_TRUE : GL_FALSE); + bool write_depth = LLDrawPoolWater::sSkipScreenCopy + || (deferred_render && pass == 1) + // we want depth written so that rendered alpha will + // contribute to the alpha mask used for impostors + || LLPipeline::sImpostorRender; + + LLGLDepthTest depth(GL_TRUE, write_depth ? GL_TRUE : GL_FALSE); if (deferred_render && pass == 1) { diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index e2a23ef56f..9434b51685 100755 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -505,7 +505,7 @@ S32 LLDrawPoolAvatar::getNumDeferredPasses() { if (LLPipeline::sImpostorRender) { - return 3; + return 19; } else { @@ -690,28 +690,15 @@ void LLDrawPoolAvatar::beginDeferredImpostor() LLVOAvatar::sNumVisibleAvatars = 0; } -#if DEFERRED_IMPOSTORS sVertexProgram = &gDeferredImpostorProgram; - - specular_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::SPECULAR_MAP); - normal_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::DEFERRED_NORMAL); - sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); -#else - sVertexProgram = &gImpostorProgram; - sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); -#endif - sVertexProgram->bind(); + gPipeline.bindDeferredShader(*sVertexProgram); sVertexProgram->setMinimumAlpha(0.01f); } void LLDrawPoolAvatar::endDeferredImpostor() { sShaderLevel = mVertexShaderLevel; - sVertexProgram->disableTexture(LLViewerShaderMgr::DEFERRED_NORMAL); - sVertexProgram->disableTexture(LLViewerShaderMgr::SPECULAR_MAP); - sVertexProgram->disableTexture(LLViewerShaderMgr::DIFFUSE_MAP); - sVertexProgram->unbind(); - gGL.getTexUnit(0)->activate(); + gPipeline.unbindDeferredShader(*sVertexProgram); } void LLDrawPoolAvatar::beginDeferredRigid() @@ -1268,7 +1255,6 @@ void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, S32 pass) if (impostor) { -#if DEFERRED_IMPOSTORS if (LLPipeline::sRenderDeferred && !LLPipeline::sReflectionRender && avatarp->mImpostor.isComplete()) { if (normal_channel > -1) @@ -1280,7 +1266,6 @@ void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, S32 pass) avatarp->mImpostor.bindTexture(1, specular_channel); } } -#endif avatarp->renderImpostor(LLColor4U(255,255,255,255), sDiffuseChannel); } return; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 9aa375767b..29b7e30655 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -11358,15 +11358,18 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) if (!avatar->mImpostor.isComplete()) { LLFastTimer t(FTM_IMPOSTOR_ALLOCATE); - avatar->mImpostor.allocate(resX,resY,GL_RGBA,TRUE,FALSE); + -#if DEFERRED_IMPOSTORS if (LLPipeline::sRenderDeferred) { + avatar->mImpostor.allocate(resX,resY,GL_SRGB8_ALPHA8,TRUE,FALSE); addDeferredAttachments(avatar->mImpostor); } -#endif - + else + { + avatar->mImpostor.allocate(resX,resY,GL_RGBA,TRUE,FALSE); + } + gGL.getTexUnit(0)->bind(&avatar->mImpostor); gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); @@ -11374,38 +11377,34 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) else if(resX != avatar->mImpostor.getWidth() || resY != avatar->mImpostor.getHeight()) { LLFastTimer t(FTM_IMPOSTOR_RESIZE); - avatar->mImpostor.resize(resX,resY,GL_RGBA); + avatar->mImpostor.resize(resX,resY,LLPipeline::sRenderDeferred ? GL_SRGB8_ALPHA8 : GL_RGBA); } avatar->mImpostor.bindTarget(); } -#if DEFERRED_IMPOSTORS if (LLPipeline::sRenderDeferred) { - avatar->mImpostor.clear(); + avatar->mImpostor.clear(); renderGeomDeferred(camera); renderGeomPostDeferred(camera); } else -#endif { LLGLEnable scissor(GL_SCISSOR_TEST); glScissor(0, 0, resX, resY); avatar->mImpostor.clear(); renderGeom(camera); } - + { //create alpha mask based on depth buffer (grey out if muted) LLFastTimer t(FTM_IMPOSTOR_BACKGROUND); -#if DEFERRED_IMPOSTORS if (LLPipeline::sRenderDeferred) { GLuint buff = GL_COLOR_ATTACHMENT0; glDrawBuffersARB(1, &buff); } -#endif LLGLDisable blend(GL_BLEND); -- cgit v1.2.3 From 83fa549b56826f55f0f30244dbceda77a8a5dbfe Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Tue, 6 Aug 2013 18:02:26 -0700 Subject: NORSPEC-322 NORSPEC-342 WIP fix black deferred impostors, lighting bugs remain --- indra/newview/lldrawpoolavatar.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index 9434b51685..9dbc85d121 100755 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -691,6 +691,9 @@ void LLDrawPoolAvatar::beginDeferredImpostor() } sVertexProgram = &gDeferredImpostorProgram; + specular_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::SPECULAR_MAP); + normal_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::DEFERRED_NORMAL); + sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); gPipeline.bindDeferredShader(*sVertexProgram); sVertexProgram->setMinimumAlpha(0.01f); } @@ -698,7 +701,12 @@ void LLDrawPoolAvatar::beginDeferredImpostor() void LLDrawPoolAvatar::endDeferredImpostor() { sShaderLevel = mVertexShaderLevel; + sVertexProgram->disableTexture(LLViewerShaderMgr::DEFERRED_NORMAL); + sVertexProgram->disableTexture(LLViewerShaderMgr::SPECULAR_MAP); + sVertexProgram->disableTexture(LLViewerShaderMgr::DIFFUSE_MAP); gPipeline.unbindDeferredShader(*sVertexProgram); + sVertexProgram = NULL; + sDiffuseChannel = 0; } void LLDrawPoolAvatar::beginDeferredRigid() -- cgit v1.2.3 From bfe2377a9a3061094e3c1fa10bb0afed06cac709 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 7 Aug 2013 08:42:35 -0700 Subject: NORSPEC-342 WIP fix issues with skimpy clothes getting too skimpy in impostors --- .../shaders/class1/deferred/impostorF.glsl | 20 ++++++++++++--- indra/newview/lldrawpoolalpha.cpp | 2 +- indra/newview/pipeline.cpp | 29 +++++++++++++++++++++- indra/newview/pipeline.h | 1 + 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index d52744103f..d1eaabf901 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -38,6 +38,17 @@ uniform sampler2D specularMap; VARYING vec2 vary_texcoord0; +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -72,7 +83,10 @@ void main() discard; } - frag_data[0] = vec4(linear_to_srgb(col.rgb), col.a); - frag_data[1] = vec4(texture2D(specularMap, vary_texcoord0.xy)); - frag_data[2] = vec4(texture2D(normalMap, vary_texcoord0.xy).xy,0,0); + vec4 norm = texture2D(normalMap, vary_texcoord0.xy); + vec4 spec = texture2D(specularMap, vary_texcoord0.xy); + + frag_data[0] = vec4(col.rgb, col.a); + frag_data[1] = spec; + frag_data[2] = vec4(norm.xy,0,0); } diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 60e22c08dc..8b2cbb1b9d 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -228,7 +228,7 @@ void LLDrawPoolAlpha::render(S32 pass) || (deferred_render && pass == 1) // we want depth written so that rendered alpha will // contribute to the alpha mask used for impostors - || LLPipeline::sImpostorRender; + || LLPipeline::sImpostorRenderAlphaDepthPass; LLGLDepthTest depth(GL_TRUE, write_depth ? GL_TRUE : GL_FALSE); diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 29b7e30655..9378c89eb7 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -379,6 +379,7 @@ BOOL LLPipeline::sWaterReflections = FALSE; BOOL LLPipeline::sRenderGlow = FALSE; BOOL LLPipeline::sReflectionRender = FALSE; BOOL LLPipeline::sImpostorRender = FALSE; +BOOL LLPipeline::sImpostorRenderAlphaDepthPass = FALSE; BOOL LLPipeline::sUnderWaterRender = FALSE; BOOL LLPipeline::sTextureBindTest = FALSE; BOOL LLPipeline::sRenderFrameTest = FALSE; @@ -11387,14 +11388,40 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) { avatar->mImpostor.clear(); renderGeomDeferred(camera); + + renderGeomPostDeferred(camera); + + // Shameless hack time: render it all again, + // this time writing the depth + // values we need to generate the alpha mask below + // while preserving the alpha-sorted color rendering + // from the previous pass + // + sImpostorRenderAlphaDepthPass = true; + // depth-only here... + // + gGL.setColorMask(false,false); renderGeomPostDeferred(camera); + sImpostorRenderAlphaDepthPass = false; } else - { + { LLGLEnable scissor(GL_SCISSOR_TEST); glScissor(0, 0, resX, resY); avatar->mImpostor.clear(); renderGeom(camera); + + // Shameless hack time: render it all again, + // this time writing the depth + // values we need to generate the alpha mask below + // while preserving the alpha-sorted color rendering + // from the previous pass + // + sImpostorRenderAlphaDepthPass = true; + // depth-only here... + // + gGL.setColorMask(false,false); + renderGeom(camera); } { //create alpha mask based on depth buffer (grey out if muted) diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index 36b293b998..5e68524067 100755 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -588,6 +588,7 @@ public: static BOOL sPickAvatar; static BOOL sReflectionRender; static BOOL sImpostorRender; + static BOOL sImpostorRenderAlphaDepthPass; static BOOL sUnderWaterRender; static BOOL sRenderGlow; static BOOL sTextureBindTest; -- cgit v1.2.3 From f3952f9a8dc368c991d9aaac174bfee5a0dd90e9 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 7 Aug 2013 13:35:08 -0700 Subject: NORSPEC-329 fix mangling of diffuse alpha mode by material edits when only one face really has alpha --- indra/newview/llpanelface.h | 15 ++++++++++++++- indra/newview/llviewerobject.cpp | 24 ++++++++++++++++++++++++ indra/newview/llviewerobject.h | 2 ++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/indra/newview/llpanelface.h b/indra/newview/llpanelface.h index 834ad9e14c..06a45644d0 100755 --- a/indra/newview/llpanelface.h +++ b/indra/newview/llpanelface.h @@ -255,7 +255,20 @@ private: // Determine correct alpha mode for current diffuse texture // (i.e. does it have an alpha channel that makes alpha mode useful) // - U8 default_alpha_mode = (_panel->isAlpha() ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE); + // _panel->isAlpha() "lies" when one face has alpha and the rest do not (NORSPEC-329) + // need to get per-face answer to this question for sane alpha mode retention on updates. + // + U8 default_alpha_mode = object->isImageAlphaBlended(face) ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE; + + if (!current_material.isNull()) + { + default_alpha_mode = current_material->getDiffuseAlphaMode(); + } + + // Insure we don't inherit the default of blend by accident... + // this will be stomped by a legit request to change the alpha mode by the apply() below + // + new_material->setDiffuseAlphaMode(default_alpha_mode); // Do "It"! // diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp index f29a00e4c4..0070240803 100755 --- a/indra/newview/llviewerobject.cpp +++ b/indra/newview/llviewerobject.cpp @@ -4517,6 +4517,30 @@ LLViewerTexture *LLViewerObject::getTEImage(const U8 face) const } +bool LLViewerObject::isImageAlphaBlended(const U8 te) const +{ + LLViewerTexture* image = getTEImage(te); + LLGLenum format = image ? image->getPrimaryFormat() : GL_RGB; + switch (format) + { + case GL_RGBA: + case GL_ALPHA: + { + return true; + } + break; + + case GL_RGB: break; + default: + { + llwarns << "Unexpected tex format in LLViewerObject::isImageAlphaBlended...returning no alpha." << llendl; + } + break; + } + + return false; +} + LLViewerTexture *LLViewerObject::getTENormalMap(const U8 face) const { // llassert(mTEImages); diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h index ea0d55cda5..16f1f403d3 100755 --- a/indra/newview/llviewerobject.h +++ b/indra/newview/llviewerobject.h @@ -339,6 +339,8 @@ public: LLViewerTexture *getTENormalMap(const U8 te) const; LLViewerTexture *getTESpecularMap(const U8 te) const; + bool isImageAlphaBlended(const U8 te) const; + void fitFaceTexture(const U8 face); void sendTEUpdate() const; // Sends packed representation of all texture entry information -- cgit v1.2.3 From e156e3ff32469d5efdfd4fb96969b8cc4bc056b8 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 7 Aug 2013 15:37:53 -0700 Subject: NORSPEC-343 protect against edits that would set non-alpha faces to diffuse alpha mode blend --- indra/newview/llpanelface.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/indra/newview/llpanelface.h b/indra/newview/llpanelface.h index 06a45644d0..86642e5635 100755 --- a/indra/newview/llpanelface.h +++ b/indra/newview/llpanelface.h @@ -258,7 +258,8 @@ private: // _panel->isAlpha() "lies" when one face has alpha and the rest do not (NORSPEC-329) // need to get per-face answer to this question for sane alpha mode retention on updates. // - U8 default_alpha_mode = object->isImageAlphaBlended(face) ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE; + bool is_alpha_face = object->isImageAlphaBlended(face); + U8 default_alpha_mode = is_alpha_face ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE; if (!current_material.isNull()) { @@ -278,6 +279,11 @@ private: LLUUID new_normal_map_id = new_material->getNormalID(); LLUUID new_spec_map_id = new_material->getSpecularID(); + if ((new_alpha_mode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND) && !is_alpha_face) + { + new_alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_NONE; + } + bool is_default_blend_mode = (new_alpha_mode == default_alpha_mode); bool is_need_material = !is_default_blend_mode || !new_normal_map_id.isNull() || !new_spec_map_id.isNull(); -- cgit v1.2.3 From 79686b6974bb07063f2ff470d4ff0cfd38ac8847 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Wed, 7 Aug 2013 16:30:27 -0700 Subject: NORSPEC-342 fix alpha objects appearing black in impostor images --- indra/newview/lldrawpoolalpha.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 8b2cbb1b9d..ba83c95518 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -548,7 +548,8 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask) gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. - if (current_shader && + if (current_shader && + !LLPipeline::sImpostorRender && draw_glow_for_this_partition && params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) { -- cgit v1.2.3 From 9c1b45b16763d452a3c9175186217d005a9cfd2b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 7 Aug 2013 17:23:23 -0700 Subject: NORSPEC-343 fix oversight and actually apply override to new material when no alpha is present --- indra/newview/llpanelface.h | 1 + 1 file changed, 1 insertion(+) diff --git a/indra/newview/llpanelface.h b/indra/newview/llpanelface.h index 86642e5635..562d293d56 100755 --- a/indra/newview/llpanelface.h +++ b/indra/newview/llpanelface.h @@ -282,6 +282,7 @@ private: if ((new_alpha_mode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND) && !is_alpha_face) { new_alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_NONE; + new_material->setDiffuseAlphaMode(LLMaterial::DIFFUSE_ALPHA_MODE_NONE); } bool is_default_blend_mode = (new_alpha_mode == default_alpha_mode); -- cgit v1.2.3 From e34f088104af64bf4468ff0d2f525a898f531bfb Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Sun, 11 Aug 2013 08:49:05 -0700 Subject: NORSPEC-341 fix issues with water reflection coloring and abnormals --- .../shaders/class1/deferred/waterF.glsl | 33 +++++++--------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index d49ff72cf0..72c46e240d 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -153,16 +153,12 @@ void main() vec2 refvec3 = distort+refdistort3/dmod_scale; vec4 refcol3 = texture2D(refTex, refvec3); - refcol1.rgb = srgb_to_linear(refcol1.rgb); - refcol2.rgb = srgb_to_linear(refcol2.rgb); - refcol3.rgb = srgb_to_linear(refcol3.rgb); - vec4 refcol = refcol1 + refcol2 + refcol3; float df1 = df.x + df.y + df.z; refcol *= df1 * 0.333; vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; - //wavef.z *= max(-viewVec.z, 0.1); + wavef.z *= max(-viewVec.z, 0.1); wavef = normalize(wavef); float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; @@ -173,15 +169,13 @@ void main() float dweight = min(dist2*blurMultiplier, 1.0); vec4 baseCol = texture2D(refTex, refvec4); - baseCol.rgb = srgb_to_linear(baseCol.rgb); - refcol = mix(baseCol*df2, refcol, dweight); //get specular component - //float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); + float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); //harden specular - //spec = pow(spec, 128.0); + spec = pow(spec, 128.0); //figure out distortion vector (ripply) vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); @@ -192,24 +186,17 @@ void main() // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); - float shadow = 1.0; vec4 pos = vary_position; - - //vec3 nz = texture2D(noiseMap, gl_FragCoord.xy/128.0).xyz; - vec4 spos = pos; - //spec *= shadow; - //color.rgb += spec * specular; - + color.rgb += spec * specular; + color.rgb = atmosTransport(color.rgb); color.rgb = scaleSoftClip(color.rgb); - color.a = sunAngle2; + color.a = spec * sunAngle2; - //wavef.z *= 0.1f; - //wavef = normalize(wavef); - vec3 screenspacewavef = (norm_mat*vec4(wavef, 1.0)).xyz; + vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - frag_data[0] = vec4(color.rgb, color.a); // diffuse - frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec - frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), screenspacewavef.z * 0.16, 0.0);// normalxyz, env intensity + frag_data[0] = vec4(color.rgb, color); // diffuse + frag_data[1] = vec4(0); // speccolor, spec + frag_data[2] = vec4(encode_normal(screenspacewavef.xyz*0.5+0.5), 0.05, 0);// normalxy, 0, 0 } -- cgit v1.2.3 From 61129c73c97accf297943d6bc5beea3c09579084 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 12 Aug 2013 10:12:09 -0700 Subject: NORSPEC-346 fix knock-on causing alpha mask edits to cause materials to get removed and revert to alpha blend --- indra/newview/llpanelface.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/indra/newview/llpanelface.h b/indra/newview/llpanelface.h index 562d293d56..46b3375f64 100755 --- a/indra/newview/llpanelface.h +++ b/indra/newview/llpanelface.h @@ -259,8 +259,13 @@ private: // need to get per-face answer to this question for sane alpha mode retention on updates. // bool is_alpha_face = object->isImageAlphaBlended(face); - U8 default_alpha_mode = is_alpha_face ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE; + // need to keep this original answer for valid comparisons in logic below + // + U8 original_default_alpha_mode = is_alpha_face ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE; + + U8 default_alpha_mode = original_default_alpha_mode; + if (!current_material.isNull()) { default_alpha_mode = current_material->getDiffuseAlphaMode(); @@ -285,7 +290,7 @@ private: new_material->setDiffuseAlphaMode(LLMaterial::DIFFUSE_ALPHA_MODE_NONE); } - bool is_default_blend_mode = (new_alpha_mode == default_alpha_mode); + bool is_default_blend_mode = (new_alpha_mode == original_default_alpha_mode); bool is_need_material = !is_default_blend_mode || !new_normal_map_id.isNull() || !new_spec_map_id.isNull(); if (!is_need_material) -- cgit v1.2.3 From 51dfcb9c67f7c3464bf3640adfdd87a061f60390 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 12 Aug 2013 15:55:25 -0700 Subject: NORSPEC-342 WIP MATBUG-347 make impostor rendering not contribute to depth for mostly-transparent buffer pixels, aka hair in ALM only --- .../shaders/class1/deferred/alphaF.glsl | 19 +++++++++-- .../shaders/class1/deferred/impostorF.glsl | 2 ++ indra/newview/lldrawpoolalpha.cpp | 11 +++++-- indra/newview/lldrawpoolavatar.cpp | 8 ++--- indra/newview/llviewershadermgr.cpp | 37 ++++++++++++++++++++++ indra/newview/llviewershadermgr.h | 1 + indra/newview/pipeline.cpp | 5 +++ 7 files changed, 74 insertions(+), 9 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index d0c7cc9dde..f35ff25dcb 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -531,6 +531,19 @@ void main() vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif +#if FOR_IMPOSTOR + vec4 color; + color.rgb = diff.rgb; + color.a = diff.a; + + // Insure we don't pollute depth with invis pixels in impostor rendering + // + if (color.a < 0.01) + { + discard; + } +#else + #ifdef USE_VERTEX_COLOR float final_alpha = diff.a * vertex_color.a; diff.rgb *= vertex_color.rgb; @@ -538,6 +551,7 @@ void main() float final_alpha = diff.a; #endif + vec4 gamma_diff = diff; diff.rgb = srgb_to_linear(diff.rgb); @@ -567,11 +581,10 @@ void main() ambient = (1.0-ambient); color.rgb *= ambient; - color.rgb += atmosAffectDirectionalLight(final_da); color.rgb *= gamma_diff.rgb; - color.rgb = mix(diff.rgb, color.rgb, final_alpha); + //color.rgb = mix(diff.rgb, color.rgb, final_alpha); color.rgb = atmosLighting(color.rgb); color.rgb = scaleSoftClip(color.rgb); @@ -600,6 +613,8 @@ void main() #ifdef WATER_FOG color = applyWaterFogDeferred(pos.xyz, color); +#endif + #endif frag_color = color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index d1eaabf901..506323fdce 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -86,6 +86,8 @@ void main() vec4 norm = texture2D(normalMap, vary_texcoord0.xy); vec4 spec = texture2D(specularMap, vary_texcoord0.xy); + col.rgb = linear_to_srgb(col.rgb); + frag_data[0] = vec4(col.rgb, col.a); frag_data[1] = spec; frag_data[2] = vec4(norm.xy,0,0); diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index ba83c95518..a8010d17d6 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -93,7 +93,12 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) if (pass == 0) { - if (LLPipeline::sUnderWaterRender) + if (LLPipeline::sImpostorRender) + { + simple_shader = &gDeferredAlphaImpostorProgram; + fullbright_shader = &gDeferredFullbrightProgram; + } + else if (LLPipeline::sUnderWaterRender) { simple_shader = &gDeferredAlphaWaterProgram; fullbright_shader = &gDeferredFullbrightWaterProgram; @@ -116,7 +121,7 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) simple_shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f/2.2f)); } - else + else if (!LLPipeline::sImpostorRender) { //update depth buffer sampler gPipeline.mScreen.flush(); @@ -156,7 +161,7 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) void LLDrawPoolAlpha::endPostDeferredPass(S32 pass) { - if (pass == 1) + if (pass == 1 && !LLPipeline::sImpostorRender) { gPipeline.mDeferredDepth.flush(); gPipeline.mScreen.bindTarget(); diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index 9dbc85d121..8b1e934224 100755 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -691,7 +691,7 @@ void LLDrawPoolAvatar::beginDeferredImpostor() } sVertexProgram = &gDeferredImpostorProgram; - specular_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::SPECULAR_MAP); + specular_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::SPECULAR_MAP); normal_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::DEFERRED_NORMAL); sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); gPipeline.bindDeferredShader(*sVertexProgram); @@ -701,12 +701,12 @@ void LLDrawPoolAvatar::beginDeferredImpostor() void LLDrawPoolAvatar::endDeferredImpostor() { sShaderLevel = mVertexShaderLevel; - sVertexProgram->disableTexture(LLViewerShaderMgr::DEFERRED_NORMAL); + sVertexProgram->disableTexture(LLViewerShaderMgr::DEFERRED_NORMAL); sVertexProgram->disableTexture(LLViewerShaderMgr::SPECULAR_MAP); sVertexProgram->disableTexture(LLViewerShaderMgr::DIFFUSE_MAP); gPipeline.unbindDeferredShader(*sVertexProgram); - sVertexProgram = NULL; - sDiffuseChannel = 0; + sVertexProgram = NULL; + sDiffuseChannel = 0; } void LLDrawPoolAvatar::beginDeferredRigid() diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 264655029a..b2f7949388 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -197,6 +197,7 @@ LLGLSLShader gDeferredShadowAlphaMaskProgram; LLGLSLShader gDeferredAvatarShadowProgram; LLGLSLShader gDeferredAttachmentShadowProgram; LLGLSLShader gDeferredAlphaProgram; +LLGLSLShader gDeferredAlphaImpostorProgram; LLGLSLShader gDeferredAlphaWaterProgram; LLGLSLShader gDeferredAvatarEyesProgram; LLGLSLShader gDeferredFullbrightProgram; @@ -304,6 +305,8 @@ LLViewerShaderMgr::LLViewerShaderMgr() : mShaderList.push_back(&gDeferredMaterialWaterProgram[9+LLMaterial::SHADER_COUNT]); mShaderList.push_back(&gDeferredMaterialWaterProgram[13+LLMaterial::SHADER_COUNT]); mShaderList.push_back(&gDeferredAlphaProgram); + mShaderList.push_back(&gDeferredAlphaProgram); + mShaderList.push_back(&gDeferredAlphaImpostorProgram); mShaderList.push_back(&gDeferredAlphaWaterProgram); mShaderList.push_back(&gDeferredSkinnedAlphaProgram); mShaderList.push_back(&gDeferredFullbrightProgram); @@ -1531,6 +1534,40 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaProgram.mFeatures.hasLighting = true; } + if (success) + { + gDeferredAlphaImpostorProgram.mName = "Deferred Alpha Shader"; + + gDeferredAlphaImpostorProgram.mFeatures.calculatesLighting = false; + gDeferredAlphaImpostorProgram.mFeatures.hasLighting = false; + gDeferredAlphaImpostorProgram.mFeatures.isAlphaLighting = true; + gDeferredAlphaImpostorProgram.mFeatures.disableTextureIndex = true; //hack to disable auto-setup of texture channels + if (mVertexShaderLevel[SHADER_DEFERRED] < 1) + { + gDeferredAlphaImpostorProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; + } + else + { //shave off some texture units for shadow maps + gDeferredAlphaImpostorProgram.mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels - 6, 1); + } + + gDeferredAlphaImpostorProgram.mShaderFiles.clear(); + gDeferredAlphaImpostorProgram.mShaderFiles.push_back(make_pair("deferred/alphaV.glsl", GL_VERTEX_SHADER_ARB)); + gDeferredAlphaImpostorProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER_ARB)); + gDeferredAlphaImpostorProgram.addPermutation("USE_INDEXED_TEX", "1"); + gDeferredAlphaImpostorProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); + gDeferredAlphaImpostorProgram.addPermutation("USE_VERTEX_COLOR", "1"); + gDeferredAlphaImpostorProgram.addPermutation("FOR_IMPOSTOR", "1"); + + gDeferredAlphaImpostorProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + + success = gDeferredAlphaImpostorProgram.createShader(NULL, NULL); + + // Hack + gDeferredAlphaImpostorProgram.mFeatures.calculatesLighting = true; + gDeferredAlphaImpostorProgram.mFeatures.hasLighting = true; + } + if (success) { gDeferredAlphaWaterProgram.mName = "Deferred Alpha Underwater Shader"; diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h index 5fa9b82170..08c1ce6911 100755 --- a/indra/newview/llviewershadermgr.h +++ b/indra/newview/llviewershadermgr.h @@ -364,6 +364,7 @@ extern LLGLSLShader gDeferredPostGammaCorrectProgram; extern LLGLSLShader gDeferredAvatarShadowProgram; extern LLGLSLShader gDeferredAttachmentShadowProgram; extern LLGLSLShader gDeferredAlphaProgram; +extern LLGLSLShader gDeferredAlphaImpostorProgram; extern LLGLSLShader gDeferredFullbrightProgram; extern LLGLSLShader gDeferredFullbrightAlphaMaskProgram; extern LLGLSLShader gDeferredAlphaWaterProgram; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 9378c89eb7..31baf4188b 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -11402,7 +11402,9 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) // gGL.setColorMask(false,false); renderGeomPostDeferred(camera); + sImpostorRenderAlphaDepthPass = false; + } else { @@ -11418,10 +11420,13 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) // from the previous pass // sImpostorRenderAlphaDepthPass = true; + // depth-only here... // gGL.setColorMask(false,false); renderGeom(camera); + + sImpostorRenderAlphaDepthPass = false; } { //create alpha mask based on depth buffer (grey out if muted) -- cgit v1.2.3 From a43a762c0ddf3ecac2056b36d0ede1f99e71231e Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 12 Aug 2013 17:22:47 -0700 Subject: NORSPEC-342 fix blocky hair in ALM from writing depth for transparent pixels in impostor rendering --- indra/newview/lldrawpoolalpha.cpp | 8 +++++++- indra/newview/lldrawpoolsimple.cpp | 6 +++++- indra/newview/llviewershadermgr.cpp | 25 +++++++++++++++++++++++++ indra/newview/llviewershadermgr.h | 1 + 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index a8010d17d6..5ebc58fb7d 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -181,7 +181,13 @@ void LLDrawPoolAlpha::beginRenderPass(S32 pass) { LLFastTimer t(FTM_RENDER_ALPHA); - if (LLPipeline::sUnderWaterRender) + if (LLPipeline::sImpostorRender) + { + simple_shader = &gObjectSimpleImpostorProgram; + fullbright_shader = &gObjectFullbrightProgram; + emissive_shader = &gObjectEmissiveProgram; + } + else if (LLPipeline::sUnderWaterRender) { simple_shader = &gObjectSimpleWaterProgram; fullbright_shader = &gObjectFullbrightWaterProgram; diff --git a/indra/newview/lldrawpoolsimple.cpp b/indra/newview/lldrawpoolsimple.cpp index aee9d19d19..8926f64c64 100755 --- a/indra/newview/lldrawpoolsimple.cpp +++ b/indra/newview/lldrawpoolsimple.cpp @@ -156,7 +156,11 @@ void LLDrawPoolSimple::beginRenderPass(S32 pass) { LLFastTimer t(FTM_RENDER_SIMPLE); - if (LLPipeline::sUnderWaterRender) + if (LLPipeline::sImpostorRender) + { + simple_shader = &gObjectSimpleImpostorProgram; + } + else if (LLPipeline::sUnderWaterRender) { simple_shader = &gObjectSimpleWaterProgram; } diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index b2f7949388..995eb599b8 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -83,6 +83,7 @@ LLGLSLShader gAlphaMaskProgram; //object shaders LLGLSLShader gObjectSimpleProgram; +LLGLSLShader gObjectSimpleImpostorProgram; LLGLSLShader gObjectPreviewProgram; LLGLSLShader gObjectSimpleWaterProgram; LLGLSLShader gObjectSimpleAlphaMaskProgram; @@ -237,6 +238,7 @@ LLViewerShaderMgr::LLViewerShaderMgr() : mShaderList.push_back(&gWaterProgram); mShaderList.push_back(&gAvatarEyeballProgram); mShaderList.push_back(&gObjectSimpleProgram); + mShaderList.push_back(&gObjectSimpleImpostorProgram); mShaderList.push_back(&gObjectPreviewProgram); mShaderList.push_back(&gImpostorProgram); mShaderList.push_back(&gObjectFullbrightNoColorProgram); @@ -729,6 +731,7 @@ void LLViewerShaderMgr::unloadShaders() gObjectFullbrightNoColorProgram.unload(); gObjectFullbrightNoColorWaterProgram.unload(); gObjectSimpleProgram.unload(); + gObjectSimpleImpostorProgram.unload(); gObjectPreviewProgram.unload(); gImpostorProgram.unload(); gObjectSimpleAlphaMaskProgram.unload(); @@ -2020,6 +2023,7 @@ BOOL LLViewerShaderMgr::loadShadersObject() gObjectFullbrightNoColorProgram.unload(); gObjectFullbrightNoColorWaterProgram.unload(); gObjectSimpleProgram.unload(); + gObjectSimpleImpostorProgram.unload(); gObjectPreviewProgram.unload(); gImpostorProgram.unload(); gObjectSimpleAlphaMaskProgram.unload(); @@ -2440,6 +2444,27 @@ BOOL LLViewerShaderMgr::loadShadersObject() success = gObjectSimpleProgram.createShader(NULL, NULL); } + if (success) + { + gObjectSimpleImpostorProgram.mName = "Simple Impostor Shader"; + gObjectSimpleImpostorProgram.mFeatures.calculatesLighting = true; + gObjectSimpleImpostorProgram.mFeatures.calculatesAtmospherics = true; + gObjectSimpleImpostorProgram.mFeatures.hasGamma = true; + gObjectSimpleImpostorProgram.mFeatures.hasAtmospherics = true; + gObjectSimpleImpostorProgram.mFeatures.hasLighting = true; + gObjectSimpleImpostorProgram.mFeatures.mIndexedTextureChannels = 0; + // force alpha mask version of lighting so we can weed out + // transparent pixels from impostor temp buffer + // + gObjectSimpleImpostorProgram.mFeatures.hasAlphaMask = true; + gObjectSimpleImpostorProgram.mShaderFiles.clear(); + gObjectSimpleImpostorProgram.mShaderFiles.push_back(make_pair("objects/simpleV.glsl", GL_VERTEX_SHADER_ARB)); + gObjectSimpleImpostorProgram.mShaderFiles.push_back(make_pair("objects/simpleF.glsl", GL_FRAGMENT_SHADER_ARB)); + gObjectSimpleImpostorProgram.mShaderLevel = mVertexShaderLevel[SHADER_OBJECT]; + + success = gObjectSimpleImpostorProgram.createShader(NULL, NULL); + } + if (success) { gObjectSimpleWaterProgram.mName = "Simple Water Shader"; diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h index 08c1ce6911..e4684c19d5 100755 --- a/indra/newview/llviewershadermgr.h +++ b/indra/newview/llviewershadermgr.h @@ -242,6 +242,7 @@ extern LLGLSLShader gOneTextureNoColorProgram; //object shaders extern LLGLSLShader gObjectSimpleProgram; +extern LLGLSLShader gObjectSimpleImpostorProgram; extern LLGLSLShader gObjectPreviewProgram; extern LLGLSLShader gObjectSimpleAlphaMaskProgram; extern LLGLSLShader gObjectSimpleWaterProgram; -- cgit v1.2.3 From e586f0325f23363e0223162f4643c7c4c1dfe4a4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 12 Aug 2013 17:45:11 -0700 Subject: NORSPEC-342 tweak shader to work on mac og glsl --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index f35ff25dcb..d1abebf84c 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -531,7 +531,7 @@ void main() vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif -#if FOR_IMPOSTOR +#ifdef FOR_IMPOSTOR vec4 color; color.rgb = diff.rgb; color.a = diff.a; -- cgit v1.2.3 From 5fb214a37fd68cf6f9b33206a7952db3351e05b5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Tue, 13 Aug 2013 20:30:07 -0700 Subject: NORSPEC-342 fix the invisi-feet --- indra/newview/pipeline.cpp | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 31baf4188b..314a2ae295 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -11240,26 +11240,32 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) } else { - andRenderTypeMask(LLPipeline::RENDER_TYPE_VOLUME, - LLPipeline::RENDER_TYPE_AVATAR, - LLPipeline::RENDER_TYPE_BUMP, - LLPipeline::RENDER_TYPE_GRASS, - LLPipeline::RENDER_TYPE_SIMPLE, - LLPipeline::RENDER_TYPE_FULLBRIGHT, - LLPipeline::RENDER_TYPE_ALPHA, - LLPipeline::RENDER_TYPE_INVISIBLE, - LLPipeline::RENDER_TYPE_PASS_SIMPLE, - LLPipeline::RENDER_TYPE_PASS_ALPHA, - LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK, - LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT, - LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK, - LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY, - LLPipeline::RENDER_TYPE_PASS_SHINY, - LLPipeline::RENDER_TYPE_PASS_INVISIBLE, - LLPipeline::RENDER_TYPE_PASS_INVISI_SHINY, - END_RENDER_TYPES); + andRenderTypeMask(LLPipeline::RENDER_TYPE_ALPHA, + LLPipeline::RENDER_TYPE_FULLBRIGHT, + LLPipeline::RENDER_TYPE_VOLUME, + LLPipeline::RENDER_TYPE_GLOW, + LLPipeline::RENDER_TYPE_BUMP, + LLPipeline::RENDER_TYPE_PASS_SIMPLE, + LLPipeline::RENDER_TYPE_PASS_ALPHA, + LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK, + LLPipeline::RENDER_TYPE_PASS_BUMP, + LLPipeline::RENDER_TYPE_PASS_POST_BUMP, + LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT, + LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK, + LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY, + LLPipeline::RENDER_TYPE_PASS_GLOW, + LLPipeline::RENDER_TYPE_PASS_GRASS, + LLPipeline::RENDER_TYPE_PASS_SHINY, + LLPipeline::RENDER_TYPE_PASS_INVISIBLE, + LLPipeline::RENDER_TYPE_PASS_INVISI_SHINY, + LLPipeline::RENDER_TYPE_AVATAR, + LLPipeline::RENDER_TYPE_ALPHA_MASK, + LLPipeline::RENDER_TYPE_FULLBRIGHT_ALPHA_MASK, + LLPipeline::RENDER_TYPE_INVISIBLE, + LLPipeline::RENDER_TYPE_ALPHA, + END_RENDER_TYPES); } - + S32 occlusion = sUseOcclusion; sUseOcclusion = 0; -- cgit v1.2.3 From 55c36ab7dbee9463c3df72d60cdc882cdeb69b9d Mon Sep 17 00:00:00 2001 From: Arun Bapu Date: Wed, 14 Aug 2013 11:35:06 -0700 Subject: Fix for NORSPEC 271 - Transparent prims in Materials Viewer are incorrectly affecting depth of field by modifying the depth buffer --- indra/newview/lldrawpoolalpha.cpp | 27 ++++++++++++++++++++++----- indra/newview/lldrawpoolalpha.h | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index ba83c95518..9c510d360f 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -100,7 +100,7 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) } else { - simple_shader = &gDeferredAlphaProgram; + simple_shader = &gDeferredAlphaProgram; fullbright_shader = &gDeferredFullbrightProgram; } @@ -276,11 +276,11 @@ void LLDrawPoolAlpha::render(S32 pass) if (mVertexShaderLevel > 0) { - renderAlpha(getVertexDataMask() | LLVertexBuffer::MAP_TEXTURE_INDEX | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2); + renderAlpha(getVertexDataMask() | LLVertexBuffer::MAP_TEXTURE_INDEX | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2, pass); } else { - renderAlpha(getVertexDataMask()); + renderAlpha(getVertexDataMask(), pass); } gGL.setColorMask(true, false); @@ -352,7 +352,7 @@ void LLDrawPoolAlpha::renderAlphaHighlight(U32 mask) } } -void LLDrawPoolAlpha::renderAlpha(U32 mask) +void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { BOOL initialized_lighting = FALSE; BOOL light_enabled = TRUE; @@ -385,6 +385,23 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask) continue; } + // Fix for bug - NORSPEC-271 + // If the face is more than 90% transparent, then don't update the Depth buffer for Dof + // We don't want the nearly invisible objects to cause of DoF effects + if(pass == 1) + { + LLFace* face = params.mFace; + if(face) + { + const LLTextureEntry* tep = face->getTextureEntry(); + if(tep) + { + if(tep->getColor().mV[3] < 0.1f) + continue; + } + } + } + LLRenderPass::applyModelMatrix(params); LLMaterial* mat = NULL; @@ -548,7 +565,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask) gPipeline.addTrianglesDrawn(params.mCount, params.mDrawMode); // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. - if (current_shader && + if (current_shader && !LLPipeline::sImpostorRender && draw_glow_for_this_partition && params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) diff --git a/indra/newview/lldrawpoolalpha.h b/indra/newview/lldrawpoolalpha.h index 43122218ed..d064a3a324 100755 --- a/indra/newview/lldrawpoolalpha.h +++ b/indra/newview/lldrawpoolalpha.h @@ -63,7 +63,7 @@ public: /*virtual*/ void prerender(); void renderGroupAlpha(LLSpatialGroup* group, U32 type, U32 mask, BOOL texture = TRUE); - void renderAlpha(U32 mask); + void renderAlpha(U32 mask, S32 pass); void renderAlphaHighlight(U32 mask); static BOOL sShowDebugAlpha; -- cgit v1.2.3 From 8f4a481610f64fc37b00fae1c71f57ece3972d8f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 14 Aug 2013 16:31:50 -0700 Subject: NORSPEC-342 add simple pass type to things rendered for impostors to fix missing shoes/belts/handbags/cigarettecases/etc --- indra/newview/pipeline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 314a2ae295..bade7a9f52 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -11262,7 +11262,7 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) LLPipeline::RENDER_TYPE_ALPHA_MASK, LLPipeline::RENDER_TYPE_FULLBRIGHT_ALPHA_MASK, LLPipeline::RENDER_TYPE_INVISIBLE, - LLPipeline::RENDER_TYPE_ALPHA, + LLPipeline::RENDER_TYPE_SIMPLE, END_RENDER_TYPES); } -- cgit v1.2.3 From 141c34cff46a7f2be868df45aa1a8de7b95fa4a4 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 15 Aug 2013 08:00:47 -0700 Subject: NORSPEC-342 NORSPEC-352 make impostor alpha shader use vertex alpha to remedy unsightly blemishes, boxes, and the occasional extra wing. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index d1abebf84c..cd7a76db28 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -534,11 +534,17 @@ void main() #ifdef FOR_IMPOSTOR vec4 color; color.rgb = diff.rgb; - color.a = diff.a; + +#ifdef USE_VERTEX_COLOR + float final_alpha = diff.a * vertex_color.a; + diff.rgb *= vertex_color.rgb; +#else + float final_alpha = diff.a; +#endif // Insure we don't pollute depth with invis pixels in impostor rendering // - if (color.a < 0.01) + if (final_alpha < 0.01) { discard; } -- cgit v1.2.3 From dc63061714b0872a123ca769cd3683ab233c9915 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 15 Aug 2013 09:37:54 -0700 Subject: NORSPEC-352 for non-ALM rendering, make lighting shader with alpha masking obey vertex alpha --- indra/llrender/llrendertarget.cpp | 2 +- .../newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index 09ef780424..a011e81b99 100755 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -113,7 +113,7 @@ void LLRenderTarget::resize(U32 resx, U32 resy, U32 color_fmt) sBytesAllocated += pix_diff*4; } } - + bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, bool stencil, LLTexUnit::eTextureType usage, bool use_fbo, S32 samples) { diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl index eaaa7b208d..cad5b9ff04 100755 --- a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl @@ -41,13 +41,13 @@ void default_lighting() { vec4 color = diffuseLookup(vary_texcoord0.xy); + color *= vertex_color; + if (color.a < minimum_alpha) { discard; } - color.rgb *= vertex_color.rgb; - color.rgb = atmosLighting(color.rgb); color.rgb = scaleSoftClip(color.rgb); -- cgit v1.2.3 From 80256fdbf5fe444c177be793b12d0da58ce2b608 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 15 Aug 2013 10:07:41 -0700 Subject: NORSPEC-349 make render targets use original formats when resizing impostors and fix alpha for deferred impostor shader --- indra/llrender/llrendertarget.cpp | 6 ++++-- indra/llrender/llrendertarget.h | 2 +- indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl | 2 +- indra/newview/pipeline.cpp | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index a011e81b99..731e0bc2b3 100755 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -79,7 +79,7 @@ LLRenderTarget::~LLRenderTarget() release(); } -void LLRenderTarget::resize(U32 resx, U32 resy, U32 color_fmt) +void LLRenderTarget::resize(U32 resx, U32 resy) { //for accounting, get the number of pixels added/subtracted S32 pix_diff = (resx*resy)-(mResX*mResY); @@ -87,10 +87,12 @@ void LLRenderTarget::resize(U32 resx, U32 resy, U32 color_fmt) mResX = resx; mResY = resy; + llassert(mInternalFormat.size() == mTex.size()); + for (U32 i = 0; i < mTex.size(); ++i) { //resize color attachments gGL.getTexUnit(0)->bindManual(mUsage, mTex[i]); - LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage), 0, color_fmt, mResX, mResY, GL_RGBA, GL_UNSIGNED_BYTE, NULL, false); + LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage), 0, mInternalFormat[i], mResX, mResY, GL_RGBA, GL_UNSIGNED_BYTE, NULL, false); sBytesAllocated += pix_diff*4; } diff --git a/indra/llrender/llrendertarget.h b/indra/llrender/llrendertarget.h index 66a9874a6b..336441661c 100755 --- a/indra/llrender/llrendertarget.h +++ b/indra/llrender/llrendertarget.h @@ -79,7 +79,7 @@ public: // CAUTION: if the GL runs out of memory attempting to resize, this render target will be undefined // DO NOT use for screen space buffers or for scratch space for an image that might be uploaded // DO use for render targets that resize often and aren't likely to ruin someone's day if they break - void resize(U32 resx, U32 resy, U32 color_fmt); + void resize(U32 resx, U32 resy); //add color buffer attachment //limit of 4 color attachments per render target diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index 506323fdce..f8fdde43f9 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -88,7 +88,7 @@ void main() col.rgb = linear_to_srgb(col.rgb); - frag_data[0] = vec4(col.rgb, col.a); + frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = spec; frag_data[2] = vec4(norm.xy,0,0); } diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index bade7a9f52..1ca4115a5e 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -11384,7 +11384,7 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) else if(resX != avatar->mImpostor.getWidth() || resY != avatar->mImpostor.getHeight()) { LLFastTimer t(FTM_IMPOSTOR_RESIZE); - avatar->mImpostor.resize(resX,resY,LLPipeline::sRenderDeferred ? GL_SRGB8_ALPHA8 : GL_RGBA); + avatar->mImpostor.resize(resX,resY); } avatar->mImpostor.bindTarget(); -- cgit v1.2.3 From 62011c2871bdb09b92c56d2959eed64ba6ec3e1f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 19 Aug 2013 12:56:04 -0700 Subject: Fix merge issues from genBBoxes optimizations fighting with genBBoxes optimizations and missing statics --- indra/llmath/llvolume.cpp | 157 +++++++++++++++++++++---------------------- indra/newview/llface.cpp | 98 ++++++++++----------------- indra/newview/llface.h | 3 +- indra/newview/llvovolume.cpp | 2 +- indra/newview/pipeline.cpp | 2 + indra/newview/pipeline.h | 4 +- 6 files changed, 119 insertions(+), 147 deletions(-) diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index ad0ca618a0..a030d889af 100755 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -136,6 +136,82 @@ BOOL LLLineSegmentBoxIntersect(const F32* start, const F32* end, const F32* cent return true; } +// Finds tangent vec based on three vertices with texture coordinates. +// Fills in dummy values if the triangle has degenerate texture coordinates. +void calc_tangent_from_triangle( + LLVector4a& normal, + LLVector4a& tangent_out, + const LLVector4a& v1, + const LLVector2& w1, + const LLVector4a& v2, + const LLVector2& w2, + const LLVector4a& v3, + const LLVector2& w3) +{ + const F32* v1ptr = v1.getF32ptr(); + const F32* v2ptr = v2.getF32ptr(); + const F32* v3ptr = v3.getF32ptr(); + + float x1 = v2ptr[0] - v1ptr[0]; + float x2 = v3ptr[0] - v1ptr[0]; + float y1 = v2ptr[1] - v1ptr[1]; + float y2 = v3ptr[1] - v1ptr[1]; + float z1 = v2ptr[2] - v1ptr[2]; + float z2 = v3ptr[2] - v1ptr[2]; + + float s1 = w2.mV[0] - w1.mV[0]; + float s2 = w3.mV[0] - w1.mV[0]; + float t1 = w2.mV[1] - w1.mV[1]; + float t2 = w3.mV[1] - w1.mV[1]; + + F32 rd = s1*t2-s2*t1; + + float r = ((rd*rd) > FLT_EPSILON) ? 1.0F / rd : 1024.f; //some made up large ratio for division by zero + + llassert(llfinite(r)); + llassert(!llisnan(r)); + + LLVector4a sdir( + (t2 * x1 - t1 * x2) * r, + (t2 * y1 - t1 * y2) * r, + (t2 * z1 - t1 * z2) * r); + + LLVector4a tdir( + (s1 * x2 - s2 * x1) * r, + (s1 * y2 - s2 * y1) * r, + (s1 * z2 - s2 * z1) * r); + + LLVector4a n = normal; + LLVector4a t = sdir; + + LLVector4a ncrosst; + ncrosst.setCross3(n,t); + + // Gram-Schmidt orthogonalize + n.mul(n.dot3(t).getF32()); + + LLVector4a tsubn; + tsubn.setSub(t,n); + + if (tsubn.dot3(tsubn).getF32() > F_APPROXIMATELY_ZERO) + { + tsubn.normalize3fast_checked(); + + // Calculate handedness + F32 handedness = ncrosst.dot3(tdir).getF32() < 0.f ? -1.f : 1.f; + + tsubn.getF32ptr()[3] = handedness; + + tangent_out = tsubn; + } + else + { + // degenerate, make up a value + // + tangent_out.set(0,0,1,1); + } + +} // intersect test between triangle vert0, vert1, vert2 and a ray from orig in direction dir. @@ -5908,10 +5984,10 @@ void LLVolumeFace::cacheOptimize() wght = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); } - LLVector4a* binorm = NULL; + LLVector4a* tangent = NULL; if (mTangents) { - binorm = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); + tangent = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); } //allocate mapping of old indices to new indices @@ -7277,83 +7353,6 @@ void calc_binormal_from_triangle(LLVector4a& binormal, } } -// Finds binormal based on three vertices with texture coordinates. -// Fills in dummy values if the triangle has degenerate texture coordinates. -void calc_tangent_from_triangle( - LLVector4a& normal, - LLVector4a& tangent_out, - const LLVector4a& v1, - const LLVector2& w1, - const LLVector4a& v2, - const LLVector2& w2, - const LLVector4a& v3, - const LLVector2& w3) -{ - const F32* v1ptr = v1.getF32ptr(); - const F32* v2ptr = v2.getF32ptr(); - const F32* v3ptr = v3.getF32ptr(); - - float x1 = v2ptr[0] - v1ptr[0]; - float x2 = v3ptr[0] - v1ptr[0]; - float y1 = v2ptr[1] - v1ptr[1]; - float y2 = v3ptr[1] - v1ptr[1]; - float z1 = v2ptr[2] - v1ptr[2]; - float z2 = v3ptr[2] - v1ptr[2]; - - float s1 = w2.mV[0] - w1.mV[0]; - float s2 = w3.mV[0] - w1.mV[0]; - float t1 = w2.mV[1] - w1.mV[1]; - float t2 = w3.mV[1] - w1.mV[1]; - - F32 rd = s1*t2-s2*t1; - - float r = ((rd*rd) > FLT_EPSILON) ? 1.0F / rd : 1024.f; //some made up large ratio for division by zero - - llassert(llfinite(r)); - llassert(!llisnan(r)); - - LLVector4a sdir( - (t2 * x1 - t1 * x2) * r, - (t2 * y1 - t1 * y2) * r, - (t2 * z1 - t1 * z2) * r); - - LLVector4a tdir( - (s1 * x2 - s2 * x1) * r, - (s1 * y2 - s2 * y1) * r, - (s1 * z2 - s2 * z1) * r); - - LLVector4a n = normal; - LLVector4a t = sdir; - - LLVector4a ncrosst; - ncrosst.setCross3(n,t); - - // Gram-Schmidt orthogonalize - n.mul(n.dot3(t).getF32()); - - LLVector4a tsubn; - tsubn.setSub(t,n); - - if (tsubn.dot3(tsubn).getF32() > F_APPROXIMATELY_ZERO) - { - tsubn.normalize3fast_checked(); - - // Calculate handedness - F32 handedness = ncrosst.dot3(tdir).getF32() < 0.f ? -1.f : 1.f; - - tsubn.getF32ptr()[3] = handedness; - - tangent_out = tsubn; - } - else - { - // degenerate, make up a value - // - tangent_out.set(0,0,1,1); - } - -} - //adapted from Lengyel, Eric. “Computing Tangent Space Basis Vectors for an Arbitrary Mesh”. Terathon Software 3D Graphics Library, 2001. http://www.terathon.com/code/tangent.html void CalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal, const LLVector2 *texcoord, U32 triangleCount, const U16* index_array, LLVector4a *tangent) diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp index 700b31f8d3..53e5b55b89 100755 --- a/indra/newview/llface.cpp +++ b/indra/newview/llface.cpp @@ -768,7 +768,7 @@ bool less_than_max_mag(const LLVector4a& vec) } BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f, - const LLMatrix4& mat_vert_in, const LLMatrix3& mat_normal_in, BOOL global_volume) + const LLMatrix4& mat_vert_in, BOOL global_volume) { //get bounding box if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME | LLDrawable::REBUILD_POSITION | LLDrawable::REBUILD_RIGGED)) @@ -777,10 +777,6 @@ BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f, LLMatrix4a mat_vert; mat_vert.loadu(mat_vert_in); - LLMatrix4a mat_normal; - mat_normal.loadu(mat_normal_in); - - //VECTORIZE THIS LLVector4a min,max; if (f >= volume.getNumVolumeFaces()) @@ -797,95 +793,69 @@ BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f, llassert(less_than_max_mag(max)); //min, max are in volume space, convert to drawable render space - LLVector4a center; - LLVector4a t; - t.setAdd(min, max); - t.mul(0.5f); - mat_vert.affineTransform(t, center); - LLVector4a size; - size.setSub(max, min); - size.mul(0.5f); - llassert(less_than_max_mag(min)); - llassert(less_than_max_mag(max)); + //get 8 corners of bounding box + LLVector4Logical mask[6]; - if (!global_volume) + for (U32 i = 0; i < 6; ++i) { - //VECTORIZE THIS - LLVector4a scale; - scale.load3(mDrawablep->getVObj()->getScale().mV); - size.mul(scale); + mask[i].clear(); } - mat_normal.mMatrix[0].normalize3fast(); - mat_normal.mMatrix[1].normalize3fast(); - mat_normal.mMatrix[2].normalize3fast(); + mask[0].setElement<2>(); //001 + mask[1].setElement<1>(); //010 + mask[2].setElement<1>(); //011 + mask[2].setElement<2>(); + mask[3].setElement<0>(); //100 + mask[4].setElement<0>(); //101 + mask[4].setElement<2>(); + mask[5].setElement<0>(); //110 + mask[5].setElement<1>(); - LLVector4a v[4]; + LLVector4a v[8]; - //get 4 corners of bounding box - mat_normal.rotate(size,v[0]); + v[6] = min; + v[7] = max; - //VECTORIZE THIS - LLVector4a scale; - - scale.set(-1.f, -1.f, 1.f); - scale.mul(size); - mat_normal.rotate(scale, v[1]); + for (U32 i = 0; i < 6; ++i) + { + v[i].setSelectWithMask(mask[i], min, max); + } - scale.set(1.f, -1.f, -1.f); - scale.mul(size); - mat_normal.rotate(scale, v[2]); + LLVector4a tv[8]; - scale.set(-1.f, 1.f, -1.f); - scale.mul(size); - mat_normal.rotate(scale, v[3]); + //transform bounding box into drawable space + for (U32 i = 0; i < 8; ++i) + { + mat_vert.affineTransform(v[i], tv[i]); + } + //find bounding box LLVector4a& newMin = mExtents[0]; LLVector4a& newMax = mExtents[1]; - newMin = newMax = center; - - llassert(less_than_max_mag(center)); + newMin = newMax = tv[0]; - for (U32 i = 0; i < 4; i++) + for (U32 i = 1; i < 8; ++i) { - LLVector4a delta; - delta.setAbs(v[i]); - LLVector4a min; - min.setSub(center, delta); - LLVector4a max; - max.setAdd(center, delta); - - newMin.setMin(newMin,min); - newMax.setMax(newMax,max); - - llassert(less_than_max_mag(newMin)); - llassert(less_than_max_mag(newMax)); + newMin.setMin(newMin, tv[i]); + newMax.setMax(newMax, tv[i]); } if (!mDrawablep->isActive()) - { + { // Shift position for region LLVector4a offset; offset.load3(mDrawablep->getRegion()->getOriginAgent().mV); newMin.add(offset); newMax.add(offset); - - llassert(less_than_max_mag(newMin)); - llassert(less_than_max_mag(newMax)); } + LLVector4a t; t.setAdd(newMin, newMax); t.mul(0.5f); - llassert(less_than_max_mag(t)); - - //VECTORIZE THIS mCenterLocal.set(t.getF32ptr()); - llassert(less_than_max_mag(newMin)); - llassert(less_than_max_mag(newMax)); - t.setSub(newMax,newMin); mBoundingSphereRadius = t.getLength3().getF32()*0.5f; diff --git a/indra/newview/llface.h b/indra/newview/llface.h index 763634a3ab..66b5f13740 100755 --- a/indra/newview/llface.h +++ b/indra/newview/llface.h @@ -194,8 +194,7 @@ public: void setSize(S32 numVertices, S32 num_indices = 0, bool align = false); - BOOL genVolumeBBoxes(const LLVolume &volume, S32 f, - const LLMatrix4& mat, BOOL global_volume = FALSE); + BOOL genVolumeBBoxes(const LLVolume &volume, S32 f,const LLMatrix4& mat, BOOL global_volume = FALSE); void init(LLDrawable* drawablep, LLViewerObject* objp); void destroy(); diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 113bdd2ce3..33b26494de 100755 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -1458,7 +1458,7 @@ BOOL LLVOVolume::genBBoxes(BOOL force_global) continue; } res &= face->genVolumeBBoxes(*volume, i, - mRelativeXform, mRelativeXformInvTrans, + mRelativeXform, /*mRelativeXformInvTrans,*/ (mVolumeImpl && mVolumeImpl->isVolumeGlobal()) || force_global); if (rebuild) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index c4286e73eb..8be7b2ab53 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -169,6 +169,7 @@ S32 LLPipeline::RenderGlowIterations; F32 LLPipeline::RenderGlowWidth; F32 LLPipeline::RenderGlowStrength; BOOL LLPipeline::RenderDepthOfField; +BOOL LLPipeline::RenderDepthOfFieldInEditMode; F32 LLPipeline::CameraFocusTransitionTime; F32 LLPipeline::CameraFNumber; F32 LLPipeline::CameraFocalLength; @@ -379,6 +380,7 @@ BOOL LLPipeline::sWaterReflections = FALSE; BOOL LLPipeline::sRenderGlow = FALSE; BOOL LLPipeline::sReflectionRender = FALSE; BOOL LLPipeline::sImpostorRender = FALSE; +BOOL LLPipeline::sImpostorRenderAlphaDepthPass = FALSE; BOOL LLPipeline::sUnderWaterRender = FALSE; BOOL LLPipeline::sTextureBindTest = FALSE; BOOL LLPipeline::sRenderFrameTest = FALSE; diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index f0bebbe20d..fbbcf8f06d 100755 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -295,7 +295,8 @@ public: void unbindDeferredShader(LLGLSLShader& shader); void renderDeferredLighting(); - + void renderDeferredLightingToRT(LLRenderTarget* target); + void generateWaterReflection(LLCamera& camera); void generateSunShadow(LLCamera& camera); void generateHighlight(LLCamera& camera); @@ -594,6 +595,7 @@ public: static BOOL sPickAvatar; static BOOL sReflectionRender; static BOOL sImpostorRender; + static BOOL sImpostorRenderAlphaDepthPass; static BOOL sUnderWaterRender; static BOOL sRenderGlow; static BOOL sTextureBindTest; -- cgit v1.2.3 From 8675ed0491efee860ac1b2d1d5fe88d150768217 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 19 Aug 2013 16:04:28 -0700 Subject: Fix merge regressions from missed changes to LoD updates --- indra/llrender/llvertexbuffer.cpp | 28 ---------------------------- indra/newview/lldrawpoolalpha.cpp | 3 +-- indra/newview/lldrawpoolavatar.cpp | 10 ++++++++++ indra/newview/llvovolume.cpp | 7 +++++++ 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index fd7b846928..6a7cec3bad 100755 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -2209,39 +2209,11 @@ void LLVertexBuffer::bindForFeedback(U32 channel, U32 type, U32 index, U32 count #endif } -void DumpComponents(U32 mask) -{ - llinfos << - ((mask & LLVertexBuffer::MAP_VERTEX) ? "vertex:" : " ") << - ((mask & LLVertexBuffer::MAP_NORMAL) ? "norms:" : " ") << - ((mask & LLVertexBuffer::MAP_TEXCOORD0) ? "TC0:" : " ") << - ((mask & LLVertexBuffer::MAP_TEXCOORD1) ? "TC1:" : " ") << - ((mask & LLVertexBuffer::MAP_TEXCOORD2) ? "TC2:" : " ") << - ((mask & LLVertexBuffer::MAP_TEXCOORD3) ? "TC3:" : " ") << - ((mask & LLVertexBuffer::MAP_COLOR) ? "color:" : " ") << - ((mask & LLVertexBuffer::MAP_EMISSIVE) ? "emissive:" : " ") << - ((mask & LLVertexBuffer::MAP_TANGENT) ? "tangents" : " ") << llendl; -} - // Set for rendering void LLVertexBuffer::setBuffer(U32 data_mask) { flush(); - if((getTypeMask() & data_mask) != data_mask) - { - if (gDebugGL) - { - // Dump info about what was missing - // - DumpComponents(data_mask & ~getTypeMask()); - llwarns << "Missing VB stream components. ^^" << llendl; - } - // Make sure we don't write checks we can't cash below... - // - data_mask = (data_mask & getTypeMask()); - } - //set up pointers if the data mask is different ... bool setup = (sLastMask != data_mask); diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index 500fad4f78..e4ebfea665 100755 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -399,7 +399,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) // Fix for bug - NORSPEC-271 // If the face is more than 90% transparent, then don't update the Depth buffer for Dof // We don't want the nearly invisible objects to cause of DoF effects - if(pass == 1) + if(pass == 1 && !LLPipeline::sImpostorRender) { LLFace* face = params.mFace; if(face) @@ -577,7 +577,6 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow). Interleaving these state-changing calls could be expensive, but glow must be drawn Z-sorted with alpha. if (current_shader && - !LLPipeline::sImpostorRender && draw_glow_for_this_partition && params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE)) { diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index 120920a4b0..66bbc6819b 100755 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -136,6 +136,16 @@ void LLDrawPoolAvatar::prerender() { sBufferUsage = GL_STREAM_DRAW_ARB; } + + if (!mDrawFace.empty()) + { + const LLFace *facep = mDrawFace[0]; + if (facep && facep->getDrawable()) + { + LLVOAvatar* avatarp = (LLVOAvatar *)facep->getDrawable()->getVObj().get(); + updateRiggedVertexBuffers(avatarp); + } + } } LLMatrix4& LLDrawPoolAvatar::getModelView() diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 33b26494de..6b3611b796 100755 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -4863,7 +4863,14 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group) if (is_rigged) { + if (!drawablep->isState(LLDrawable::RIGGED)) + { drawablep->setState(LLDrawable::RIGGED); + + //first time this is drawable is being marked as rigged, + // do another LoD update to use avatar bounding box + vobj->updateLOD(); + } } else { -- cgit v1.2.3 From f46e07c14c11ffd26c0cf0794992d7c08d16fcd4 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Mon, 26 Aug 2013 10:16:11 -0700 Subject: MAINT-1453 ifdef around windows-only work-around to restore 8x and 16x AA modes on Mac --- indra/newview/llfloaterhardwaresettings.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/indra/newview/llfloaterhardwaresettings.cpp b/indra/newview/llfloaterhardwaresettings.cpp index 664f7d4fd6..792a2a5d25 100755 --- a/indra/newview/llfloaterhardwaresettings.cpp +++ b/indra/newview/llfloaterhardwaresettings.cpp @@ -151,12 +151,17 @@ BOOL LLFloaterHardwareSettings::postBuild() { childSetAction("OK", onBtnOK, this); +// Don't do this on Mac as their braindead GL versioning +// sets this when 8x and 16x are indeed available +// +#if !LL_DARWIN if (gGLManager.mIsIntel || gGLManager.mGLVersion < 3.f) { //remove FSAA settings above "4x" LLComboBox* combo = getChild("fsaa"); combo->remove("8x"); combo->remove("16x"); } +#endif refresh(); center(); -- cgit v1.2.3 From d8f700d6ac68388d021e923efa5d89e7d5852bd5 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 28 Aug 2013 09:14:29 -0700 Subject: NORSPEC-355 NORSPEC-356 replaced llerrs with asserts to avoid crashes from false alarms in release --- indra/newview/lldrawable.cpp | 8 +++++++- indra/newview/llviewertexturelist.cpp | 16 ++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/indra/newview/lldrawable.cpp b/indra/newview/lldrawable.cpp index 2a333157f2..9682f38227 100755 --- a/indra/newview/lldrawable.cpp +++ b/indra/newview/lldrawable.cpp @@ -132,10 +132,16 @@ void LLDrawable::destroy() sNumZombieDrawables--; } + // Attempt to catch violations of this in debug, + // knowing that some false alarms may result + // + llassert(!LLSpatialGroup::sNoDelete); + + /* cannot be guaranteed and causes crashes on false alarms if (LLSpatialGroup::sNoDelete) { llerrs << "Illegal deletion of LLDrawable!" << llendl; - } + }*/ std::for_each(mFaces.begin(), mFaces.end(), DeletePointer()); mFaces.clear(); diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp index d9f3548a29..487a06949a 100755 --- a/indra/newview/llviewertexturelist.cpp +++ b/indra/newview/llviewertexturelist.cpp @@ -562,11 +562,11 @@ void LLViewerTextureList::addImageToList(LLViewerFetchedTexture *image) llassert(image); if (image->isInImageList()) { - llerrs << "LLViewerTextureList::addImageToList - Image already in list" << llendl; + llinfos << "LLViewerTextureList::addImageToList - Image already in list" << llendl; } if((mImageList.insert(image)).second != true) { - llerrs << "Error happens when insert image to mImageList!" << llendl ; + llinfos << "Error happens when insert image to mImageList!" << llendl ; } image->setInImageList(TRUE) ; @@ -585,32 +585,32 @@ void LLViewerTextureList::removeImageFromList(LLViewerFetchedTexture *image) { llinfos << "Image is not in mUUIDMap!" << llendl ; } - llerrs << "LLViewerTextureList::removeImageFromList - Image not in list" << llendl; + llinfos << "LLViewerTextureList::removeImageFromList - Image not in list" << llendl; } S32 count = mImageList.erase(image) ; + llassert(count == 1); if(count != 1) { - llinfos << image->getID() << llendl ; - llerrs << "Error happens when remove image from mImageList: " << count << llendl ; + llinfos << image->getID() << " removed with non-one count of " << count << llendl; } image->setInImageList(FALSE) ; } void LLViewerTextureList::addImage(LLViewerFetchedTexture *new_image) -{ +{ if (!new_image) { - llwarning("No image to add to image list", 0); return; } + llassert(new_image); LLUUID image_id = new_image->getID(); LLViewerFetchedTexture *image = findImage(image_id); if (image) { - llwarns << "Image with ID " << image_id << " already in list" << llendl; + llinfos << "Image with ID " << image_id << " already in list" << llendl; } sNumImages++; -- cgit v1.2.3 From a3be9d3467c068f8ed0d4f1c98484d132b1f1a5f Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Thu, 5 Sep 2013 17:30:23 -0700 Subject: NORSPEC-360 fix issues with mip selection and TCs in projector fake env reflection --- .../app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 9 +++------ .../app_settings/shaders/class2/deferred/multiSpotLightF.glsl | 8 +++----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index ed68e38891..86f9f227d5 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -310,14 +310,11 @@ void main() vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); - + stc /= stc.w; if (stc.z > 0.0) { - stc.xy /= stc.w; - - float fatten = clamp(envIntensity*envIntensity+envIntensity*0.5, 0.25, 1.0); + float fatten = clamp(envIntensity*envIntensity+envIntensity*0.25, 0.25, 1.0); - //stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5); stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5); if (stc.x < 1.0 && @@ -325,7 +322,7 @@ void main() stc.x > 0.0 && stc.y > 0.0) { - col += color.rgb*texture2DLodSpecular(projectionMap, stc.xy, proj_lod-envIntensity*proj_lod).rgb*spec.rgb; + col += color.rgb*texture2DLodSpecular(projectionMap, stc.xy, proj_lod).rgb*spec.rgb; } } } diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index df750d3cec..ed3458963d 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -333,14 +333,12 @@ void main() vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + stc /= stc.w; if (stc.z > 0.0) { - stc.xy /= stc.w; - - float fatten = clamp(envIntensity*envIntensity+envIntensity*0.5, 0.25, 1.0); + float fatten = clamp(envIntensity*envIntensity+envIntensity*0.25, 0.25, 1.0); - //stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5); stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5); if (stc.x < 1.0 && @@ -348,7 +346,7 @@ void main() stc.x > 0.0 && stc.y > 0.0) { - col += color.rgb*texture2DLodSpecular(projectionMap, stc.xy, proj_lod-envIntensity*proj_lod).rgb*shadow*spec.rgb; + col += color.rgb*texture2DLodSpecular(projectionMap, stc.xy, proj_lod).rgb*shadow*spec.rgb; } } } -- cgit v1.2.3 From 93df4ff2fea7378ab5b5ac069c2fec808ec5027b Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Mon, 9 Sep 2013 09:24:46 -0700 Subject: NORSPEC-362 address video mem leak on windows on maximize --- indra/newview/pipeline.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 8be7b2ab53..b4e59909db 100755 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -796,14 +796,22 @@ void LLPipeline::resizeScreenTexture() GLuint resX = gViewerWindow->getWorldViewWidthRaw(); GLuint resY = gViewerWindow->getWorldViewHeightRaw(); - if (!allocateScreenBuffer(resX,resY)) - { //FAILSAFE: screen buffer allocation failed, disable deferred rendering if it's enabled - //NOTE: if the session closes successfully after this call, deferred rendering will be - // disabled on future sessions - if (LLPipeline::sRenderDeferred) + if ((resX != mScreen.getWidth()) || (resY != mScreen.getHeight())) + { + releaseScreenBuffers(); + if (!allocateScreenBuffer(resX,resY)) { - gSavedSettings.setBOOL("RenderDeferred", FALSE); - LLPipeline::refreshCachedSettings(); +#if PROBABLE_FALSE_DISABLES_OF_ALM_HERE + //FAILSAFE: screen buffer allocation failed, disable deferred rendering if it's enabled + //NOTE: if the session closes successfully after this call, deferred rendering will be + // disabled on future sessions + if (LLPipeline::sRenderDeferred) + { + gSavedSettings.setBOOL("RenderDeferred", FALSE); + LLPipeline::refreshCachedSettings(); + + } +#endif } } } @@ -1193,7 +1201,8 @@ void LLPipeline::releaseGLBuffers() mWaterRef.release(); mWaterDis.release(); - + mHighlight.release(); + for (U32 i = 0; i < 3; i++) { mGlow[i].release(); @@ -1223,12 +1232,12 @@ void LLPipeline::releaseScreenBuffers() mDeferredScreen.release(); mDeferredDepth.release(); mDeferredLight.release(); - - mHighlight.release(); + mOcclusionDepth.release(); for (U32 i = 0; i < 6; i++) { mShadow[i].release(); + mShadowOcclusion[i].release(); } } -- cgit v1.2.3 From 938e201d8f6517c7b8a39954dedb0f3c0e9bfb6d Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Mon, 9 Sep 2013 14:45:03 -0400 Subject: Added tag 3.6.5-release for changeset bf6d45304601 --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index e33fd73874..2e94290c50 100755 --- a/.hgtags +++ b/.hgtags @@ -464,3 +464,4 @@ f6741d5fe8d632651424484df0fe0cb4a01e9fbe 3.6.2-release fe4f7c5e9fd27e09d03deb1cc9ab3e5093f6309e 3.6.3-release 83357f31d8dbf048a8bfdc323f363bf4d588aca1 CHOP-951-a 91ed595b716f14f07409595b734fda891a59379e 3.6.4-release +bf6d453046011a11de2643fac610cc5258650f82 3.6.5-release -- cgit v1.2.3 From 55ae6a7962cdc9a9d7d087fbc529d30db9c37013 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Mon, 9 Sep 2013 14:47:01 -0400 Subject: increment viewer version to 3.6.6 --- indra/newview/VIEWER_VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/VIEWER_VERSION.txt b/indra/newview/VIEWER_VERSION.txt index d15b8b06fa..4f2c1d15f6 100644 --- a/indra/newview/VIEWER_VERSION.txt +++ b/indra/newview/VIEWER_VERSION.txt @@ -1 +1 @@ -3.6.5 +3.6.6 -- cgit v1.2.3 From 63757692b60362cd55919edb142d132d5b26fe12 Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Wed, 11 Sep 2013 20:40:11 -0700 Subject: NORSPEC-362 Fix leak of deferred color attachments --- indra/llrender/llrendertarget.cpp | 52 +++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index ed9134c938..c0602d79bd 100755 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -364,36 +364,56 @@ void LLRenderTarget::release() sBytesAllocated -= mResX*mResY*4; } - else if (mUseDepth && mFBO) - { //detach shared depth buffer + else if (mFBO) + { glBindFramebuffer(GL_FRAMEBUFFER, mFBO); - if (mStencil) - { //attached as a renderbuffer - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0); - mStencil = false; + + if (mUseDepth) + { //detach shared depth buffer + if (mStencil) + { //attached as a renderbuffer + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0); + mStencil = false; + } + else + { //attached as a texture + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), 0, 0); + } + mUseDepth = false; } - else - { //attached as a texture - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), 0, 0); + } + + // Detach any extra color buffers (e.g. SRGB spec buffers) + // + if (mFBO && (mTex.size() > 1)) + { + S32 z; + for (z = mTex.size() - 1; z >= 1; z--) + { + sBytesAllocated -= mResX*mResY*4; + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+z, LLTexUnit::getInternalType(mUsage), 0, 0); + stop_glerror(); + LLImageGL::deleteTextures(mUsage, mInternalFormat[z], 0, 1, &mTex[z], true); } - mUseDepth = false; } if (mFBO) { glDeleteFramebuffers(1, (GLuint *) &mFBO); + stop_glerror(); mFBO = 0; } if (mTex.size() > 0) { - sBytesAllocated -= mResX*mResY*4*mTex.size(); - LLImageGL::deleteTextures(mUsage, mInternalFormat[0], 0, mTex.size(), &mTex[0], true); - mTex.clear(); - mInternalFormat.clear(); + sBytesAllocated -= mResX*mResY*4; + LLImageGL::deleteTextures(mUsage, mInternalFormat[0], 0, 1, &mTex[0], true); } - + + mTex.clear(); + mInternalFormat.clear(); + mResX = mResY = 0; sBoundTarget = NULL; -- cgit v1.2.3 From f0f727c07d75b7a988edfe7c07e4f6b43df92f93 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Wed, 18 Sep 2013 14:31:33 -0700 Subject: Added tag 3.6.6-release for changeset b62e417982d9 --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index 2e94290c50..5cdeede2ea 100755 --- a/.hgtags +++ b/.hgtags @@ -465,3 +465,4 @@ fe4f7c5e9fd27e09d03deb1cc9ab3e5093f6309e 3.6.3-release 83357f31d8dbf048a8bfdc323f363bf4d588aca1 CHOP-951-a 91ed595b716f14f07409595b734fda891a59379e 3.6.4-release bf6d453046011a11de2643fac610cc5258650f82 3.6.5-release +b62e417982d9d4f3ec49d0de3b3c2e37c6d394c1 3.6.6-release -- cgit v1.2.3 From ad777b46d0fe5d790e43efb1771e9f64f3ad3dfb Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Wed, 18 Sep 2013 14:32:18 -0700 Subject: increment viewer version to 3.6.7 --- indra/newview/VIEWER_VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/VIEWER_VERSION.txt b/indra/newview/VIEWER_VERSION.txt index 4f2c1d15f6..5b3413147c 100644 --- a/indra/newview/VIEWER_VERSION.txt +++ b/indra/newview/VIEWER_VERSION.txt @@ -1 +1 @@ -3.6.6 +3.6.7 -- cgit v1.2.3