Changeset 9836
- Timestamp:
- 03/02/09 15:53:04 (4 years ago)
- Location:
- OpenSceneGraph/branches/osg-cocoa-dev
- Files:
-
- 4 modified
-
include/osgViewer/api/Cocoa/GraphicsWindowCocoa (modified) (2 diffs)
-
src/osgViewer/DarwinUtils.mm (modified) (1 diff)
-
src/osgViewer/GraphicsWindowCocoa.mm (modified) (30 diffs)
-
src/osgViewer/PixelBufferCocoa.mm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/branches/osg-cocoa-dev/include/osgViewer/api/Cocoa/GraphicsWindowCocoa
r9831 r9836 99 99 virtual void checkEvents(); 100 100 101 /** Set the window's position and size.*/102 virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);103 104 101 /** Set Window decoration.*/ 105 102 virtual bool setWindowDecorationImplementation(bool flag); … … 114 111 115 112 virtual void resizedImplementation(int x, int y, int width, int height); 113 114 virtual bool setWindowRectangleImplementation(int x, int y, int width, int height); 116 115 117 116 virtual void setWindowName (const std::string & name); -
OpenSceneGraph/branches/osg-cocoa-dev/src/osgViewer/DarwinUtils.mm
r9831 r9836 98 98 { 99 99 ++windowsIntersectingMainScreen; 100 osg::notify(osg::WARN) << "testintrect " << windowBounds.origin.x << "/" << windowBounds.origin.y << " " << windowBounds.size.width << "x" << windowBounds.size.height << std::endl;101 osg::notify(osg::WARN) << "agains" << _availRect.origin.x << "/" << _availRect.origin.y << " " << _availRect.size.width << "x" << _availRect.size.height << std::endl;100 // osg::notify(osg::ALWAYS) << "testing rect " << windowBounds.origin.x << "/" << windowBounds.origin.y << " " << windowBounds.size.width << "x" << windowBounds.size.height << std::endl; 101 // osg::notify(osg::ALWAYS) << "against " << _availRect.origin.x << "/" << _availRect.origin.y << " " << _availRect.size.width << "x" << _availRect.size.height << std::endl; 102 102 // the window intersects the main-screen, does it intersect with the menubar/dock? 103 103 if (((_availRect.origin.y > _mainScreenBounds.origin.y) && (_availRect.origin.y > windowBounds.origin.y)) || -
OpenSceneGraph/branches/osg-cocoa-dev/src/osgViewer/GraphicsWindowCocoa.mm
r9831 r9836 131 131 132 132 133 /** remaps a native os x keycode to a GUIEventAdapter-keycode */ 133 // ---------------------------------------------------------------------------------------------------------- 134 // remapCocoaKey 135 // ---------------------------------------------------------------------------------------------------------- 134 136 static unsigned int remapCocoaKey(unsigned int key, bool pressedOnKeypad = false) 135 137 { … … 140 142 141 143 // ---------------------------------------------------------------------------------------------------------- 144 // Cocoa uses a coordinate system where its origin is in the bottom left corner, 145 // osg and quartz uses top left for the origin 146 // 147 // these 2 methods convets rects between the different coordinate systems 148 // ---------------------------------------------------------------------------------------------------------- 149 150 static NSRect convertFromQuartzCoordinates(osgViewer::GraphicsWindowCocoa* win,const NSRect& rect) 151 { 152 NSRect frame = [[win->getWindow() screen] frame]; 153 154 float y = frame.size.height - rect.origin.y - rect.size.height; 155 return NSMakeRect(rect.origin.x, y, rect.size.width, rect.size.height); 156 } 157 158 static NSRect convertToQuartzCoordinates(osgViewer::GraphicsWindowCocoa* win,const NSRect& rect) 159 { 160 NSRect frame = [[win->getWindow() screen] frame]; 161 162 float y = frame.size.height - (rect.origin.y + rect.size.height); 163 return NSMakeRect(rect.origin.x, y, rect.size.width, rect.size.height); 164 } 165 166 #pragma mark CocoaAppDelegate 167 168 // ---------------------------------------------------------------------------------------------------------- 142 169 // the app-delegate, handling quit-requests 143 170 // ---------------------------------------------------------------------------------------------------------- … … 154 181 { 155 182 s_quit_requested = true; 156 std::cout << "quit requested " << std::endl;183 // std::cout << "quit requested " << std::endl; 157 184 return NSTerminateNow; 158 185 } … … 160 187 @end 161 188 162 163 164 // ---------------------------------------------------------------------------------------------------------- 165 // GraphicsWindowCocoaWindow 189 #pragma mark GraphicsWindowCocoaWindow 190 191 // ---------------------------------------------------------------------------------------------------------- 192 // GraphicsWindowCocoaWindow, implements canBecomeKeyWindow + canBecomeMainWindow 166 193 // ---------------------------------------------------------------------------------------------------------- 167 194 … … 190 217 @end 191 218 219 #pragma mark GraphicsWindowCocoaGLView 220 221 192 222 // ---------------------------------------------------------------------------------------------------------- 193 223 // GraphicsWindowCocoaGLView 194 // ---------------------------------------------------------------------------------------------------------- 195 224 // custom NSOpenGLView-class handling mouse- and keyboard-events, forwarding them to the EventQueue 225 // some code borrowed from the example osgCocoaViewer from E.Wing 226 // ---------------------------------------------------------------------------------------------------------- 196 227 197 228 @interface GraphicsWindowCocoaGLView : NSOpenGLView … … 587 618 588 619 620 589 621 @end 590 622 … … 606 638 - (id)initWith: (osgViewer::GraphicsWindowCocoa*) win; 607 639 - (void)windowDidMove:(NSNotification *)notification; 640 - (void)windowDidResize:(NSNotification *)notification; 608 641 - (BOOL)windowShouldClose:(id)window; 642 - (void)updateWindowBounds; 609 643 610 644 @end 645 611 646 612 647 @implementation GraphicsWindowCocoaDelegate … … 619 654 } 620 655 656 621 657 - (void)windowDidMove:(NSNotification *)notification 658 { 659 [self updateWindowBounds]; 660 } 661 662 - (void)windowDidResize:(NSNotification *)notification 663 { 664 [self updateWindowBounds]; 665 } 666 667 -(void)updateWindowBounds 622 668 { 623 669 if (_inDidMove) return; 624 670 _inDidMove = true; 671 625 672 GraphicsWindowCocoaWindow* nswin = _win->getWindow(); 626 673 NSRect bounds = [nswin contentRectForFrameRect: [nswin frame] ]; 627 std::cout << "windowdidmove: " << bounds.origin.x << " " << bounds.origin.y << " " << bounds.size.width << " " << bounds.size.height << std::endl; 674 675 // convert to quartz-coordinate-system 676 bounds = convertToQuartzCoordinates(_win, bounds); 677 678 // std::cout << "windowdidmove: " << bounds.origin.x << " " << bounds.origin.y << " " << bounds.size.width << " " << bounds.size.height << std::endl; 628 679 629 680 _win->resized(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height); … … 641 692 642 693 643 #pragma mark GraphicsWindowCocoa694 #pragma mark CocoaWindowAdapter 644 695 645 696 … … 662 713 { 663 714 NSRect nsrect = [_win->getWindow() frame]; 664 715 nsrect = convertToQuartzCoordinates(_win.get(), nsrect); 716 665 717 rect.origin.x = nsrect.origin.x; 666 718 rect.origin.y = nsrect.origin.y; … … 674 726 }; 675 727 728 #pragma mark GraphicsWindowCocoa 729 730 731 732 // ---------------------------------------------------------------------------------------------------------- 733 // init 734 // ---------------------------------------------------------------------------------------------------------- 676 735 677 736 void GraphicsWindowCocoa::init() … … 687 746 688 747 748 // ---------------------------------------------------------------------------------------------------------- 749 // setupNSWindow 750 // sets up the NSWindow, adds delegates, etc 751 // ---------------------------------------------------------------------------------------------------------- 689 752 690 753 void GraphicsWindowCocoa::setupNSWindow(NSWindow* win) … … 693 756 [win setReleasedWhenClosed:NO]; 694 757 [win setDisplaysWhenScreenProfileChanges:YES]; 695 [win setDelegate: [[GraphicsWindowCocoaDelegate alloc] initWith: this] ]; 696 758 GraphicsWindowCocoaDelegate* delegate = [[GraphicsWindowCocoaDelegate alloc] initWith: this]; 759 [win setDelegate: delegate ]; 760 //[delegate autorelease]; 761 697 762 [win makeKeyAndOrderFront:nil]; 698 763 [win setAcceptsMouseMovedEvents: YES]; … … 701 766 702 767 768 // ---------------------------------------------------------------------------------------------------------- 769 // realizeImplementation, creates the window + context 770 // ---------------------------------------------------------------------------------------------------------- 703 771 704 772 bool GraphicsWindowCocoa::realizeImplementation() … … 716 784 } 717 785 786 DarwinWindowingSystemInterface* wsi = dynamic_cast<DarwinWindowingSystemInterface*>(osg::GraphicsContext::getWindowingSystemInterface()); 787 int screenLeft(0), screenTop(0); 788 if (wsi) { 789 790 wsi->getScreenTopLeft((*_traits), screenLeft, screenTop); 791 _traits->y += screenTop; 792 _traits->x += screenLeft; 793 } 718 794 719 795 NSRect rect = NSMakeRect(_traits->x, _traits->y, _traits->width, _traits->height); 796 720 797 _window = [[GraphicsWindowCocoaWindow alloc] initWithContentRect: rect styleMask: style backing: NSBackingStoreBuffered defer: NO]; 721 798 722 799 if (!_window) { 723 osg::notify(osg::WARN) << "GraphicsWindowC arbon::realizeImplementation :: could not create window" << std::endl;800 osg::notify(osg::WARN) << "GraphicsWindowCocoa::realizeImplementation :: could not create window" << std::endl; 724 801 return false; 725 802 } 726 803 804 rect = convertFromQuartzCoordinates(this, rect); 805 [_window setFrameOrigin: rect.origin]; 727 806 728 807 NSOpenGLPixelFormatAttribute attr[32]; … … 778 857 779 858 if (!_context) { 780 osg::notify(osg::WARN) << "GraphicsWindowC arbon::realizeImplementation :: could not create context" << std::endl;859 osg::notify(osg::WARN) << "GraphicsWindowCocoa::realizeImplementation :: could not create context" << std::endl; 781 860 return false; 782 861 } … … 810 889 811 890 812 813 814 / ** Close the graphics context. */891 // ---------------------------------------------------------------------------------------------------------- 892 // closeImplementation 893 // ---------------------------------------------------------------------------------------------------------- 815 894 void GraphicsWindowCocoa::closeImplementation() 816 895 { … … 826 905 } 827 906 828 /** Make this graphics context current.*/ 907 908 // ---------------------------------------------------------------------------------------------------------- 909 // makeCurrentImplementation 910 // ---------------------------------------------------------------------------------------------------------- 911 829 912 bool GraphicsWindowCocoa:: makeCurrentImplementation() 830 913 { … … 834 917 835 918 836 /** Release the graphics context.*/ 919 // ---------------------------------------------------------------------------------------------------------- 920 // releaseContextImplementation 921 // ---------------------------------------------------------------------------------------------------------- 922 837 923 bool GraphicsWindowCocoa::releaseContextImplementation() 838 924 { … … 842 928 843 929 844 /** Swap the front and back buffers.*/ 930 // ---------------------------------------------------------------------------------------------------------- 931 // swapBuffersImplementation 932 // ---------------------------------------------------------------------------------------------------------- 933 845 934 void GraphicsWindowCocoa::swapBuffersImplementation() 846 935 { … … 849 938 850 939 851 /** Check to see if any events have been generated.*/ 940 // ---------------------------------------------------------------------------------------------------------- 941 // checkEvents 942 // process all pending events 943 // ---------------------------------------------------------------------------------------------------------- 852 944 void GraphicsWindowCocoa::checkEvents() 853 945 { … … 885 977 886 978 887 /** Set the window's position and size.*/ 888 bool GraphicsWindowCocoa::setWindowRectangleImplementation(int x, int y, int width, int height) 889 { 890 std::cout << "GraphicsWindowCocoa :: realizeImplementation not implemented yet " << std::endl; 891 892 MenubarController::instance()->update(); 893 894 return true; 895 } 896 897 898 /** Set Window decoration.*/ 979 980 // ---------------------------------------------------------------------------------------------------------- 981 // setWindowDecorationImplementation 982 // 983 // unfortunately there's no way to change the decoration of a window, so we create an new one 984 // and swap the content 985 // ---------------------------------------------------------------------------------------------------------- 986 899 987 bool GraphicsWindowCocoa::setWindowDecorationImplementation(bool flag) 900 988 { 901 989 if (!_realized) return false; 902 990 903 // unfortunately there's no way to change the decoration of a window, so we create an new one and swap the content904 991 unsigned int style(NSBorderlessWindowMask); 905 992 … … 924 1011 [_window makeKeyAndOrderFront: nil]; 925 1012 } 926 927 1013 928 1014 return true; … … 930 1016 931 1017 932 /** Get focus.*/ 1018 // ---------------------------------------------------------------------------------------------------------- 1019 // grabFocus 1020 // ---------------------------------------------------------------------------------------------------------- 933 1021 void GraphicsWindowCocoa::grabFocus() 934 1022 { … … 937 1025 938 1026 939 /** Get focus on if the pointer is in this window.*/ 1027 // ---------------------------------------------------------------------------------------------------------- 1028 // grabFocusIfPointerInWindow 1029 // ---------------------------------------------------------------------------------------------------------- 940 1030 void GraphicsWindowCocoa::grabFocusIfPointerInWindow() 941 1031 { 942 std::cout << "GraphicsWindowCocoa :: grabFocusIfPointerInWindow not implemented yet " << std::endl; 943 } 944 1032 osg::notify(osg::INFO) << "GraphicsWindowCocoa :: grabFocusIfPointerInWindow not implemented yet " << std::endl; 1033 } 1034 1035 1036 // ---------------------------------------------------------------------------------------------------------- 1037 // resizedImplementation 1038 // ---------------------------------------------------------------------------------------------------------- 945 1039 946 1040 void GraphicsWindowCocoa::resizedImplementation(int x, int y, int width, int height) … … 948 1042 GraphicsContext::resizedImplementation(x, y, width, height); 949 1043 950 [_window setContentSize: NSMakeSize(width, height)];951 1044 [_context update]; 952 //[_window setFrameTopLeftPoint: NSMakePoint(x,y)];953 1045 MenubarController::instance()->update(); 954 std::cout << "GraphicsWindowCocoa :: resizedImplementation not implemented yet " << std::endl; 955 } 956 1046 } 1047 1048 1049 // ---------------------------------------------------------------------------------------------------------- 1050 // setWindowRectangleImplementation 1051 // ---------------------------------------------------------------------------------------------------------- 1052 bool GraphicsWindowCocoa::setWindowRectangleImplementation(int x, int y, int width, int height) 1053 { 1054 1055 NSRect rect = NSMakeRect(x,y,width, height); 1056 rect = convertFromQuartzCoordinates(this, rect); 1057 1058 [_window setFrame: [NSWindow frameRectForContentRect: rect styleMask: [_window styleMask]] display: YES]; 1059 [_context update]; 1060 MenubarController::instance()->update(); 1061 1062 return true; 1063 } 1064 1065 1066 1067 // ---------------------------------------------------------------------------------------------------------- 1068 // setWindowName 1069 // ---------------------------------------------------------------------------------------------------------- 957 1070 958 1071 void GraphicsWindowCocoa::setWindowName (const std::string & name) … … 966 1079 } 967 1080 1081 1082 // ---------------------------------------------------------------------------------------------------------- 1083 // useCursor 1084 // ---------------------------------------------------------------------------------------------------------- 968 1085 969 1086 void GraphicsWindowCocoa::useCursor(bool cursorOn) … … 994 1111 995 1112 1113 // ---------------------------------------------------------------------------------------------------------- 1114 // setCursor 1115 // ---------------------------------------------------------------------------------------------------------- 1116 996 1117 void GraphicsWindowCocoa::setCursor(MouseCursor mouseCursor) 997 1118 { 998 std::cout << "GraphicsWindowCocoa :: setCursor not implemented yet " << std::endl; 999 } 1119 switch (mouseCursor) 1120 { 1121 1122 case NoCursor: 1123 [NSCursor hide]; 1124 break; 1125 1126 case LeftArrowCursor: 1127 [[NSCursor arrowCursor] set]; 1128 break; 1129 1130 case TextCursor: 1131 [[NSCursor IBeamCursor] set]; 1132 break; 1133 1134 case CrosshairCursor: 1135 [[NSCursor crosshairCursor] set]; 1136 break; 1137 1138 default: 1139 osg::notify(osg::INFO) << "GraphicsWindowCocoa::setCursor :: unsupported MouseCursor: " << mouseCursor << std::endl; 1140 } 1141 } 1142 1143 1144 // ---------------------------------------------------------------------------------------------------------- 1145 // setVSync 1146 // ---------------------------------------------------------------------------------------------------------- 1000 1147 1001 1148 void GraphicsWindowCocoa::setVSync(bool f) … … 1006 1153 1007 1154 1155 // ---------------------------------------------------------------------------------------------------------- 1156 // d'tor 1157 // ---------------------------------------------------------------------------------------------------------- 1158 1008 1159 GraphicsWindowCocoa::~GraphicsWindowCocoa() 1009 1160 { … … 1012 1163 1013 1164 1014 1165 #pragma mark CocoaWindowingSystemInterface 1166 1167 // ---------------------------------------------------------------------------------------------------------- 1168 // CocoaWindowingSystemInterface 1169 // ---------------------------------------------------------------------------------------------------------- 1015 1170 1016 1171 struct CocoaWindowingSystemInterface : public DarwinWindowingSystemInterface { -
OpenSceneGraph/branches/osg-cocoa-dev/src/osgViewer/PixelBufferCocoa.mm
r9831 r9836 10 10 #include <iostream> 11 11 #include <osgViewer/api/Cocoa/PixelBufferCocoa> 12 12 #include <osgViewer/api/Cocoa/GraphicsWindowCocoa> 13 #include <Cocoa/Cocoa.h> 13 14 14 15 namespace osgViewer { … … 17 18 void PixelBufferCocoa::init() 18 19 { 19 std::cout << "PixelBufferCocoa :: init not implemented yet " << std::endl;20 //std::cout << "PixelBufferCocoa :: init not implemented yet " << std::endl; 20 21 21 _valid = _initialized = _realized =true;22 _valid = _initialized = true; 22 23 23 24 … … 27 28 { 28 29 std::cout << "PixelBufferCocoa :: realizeImplementation not implemented yet " << std::endl; 29 return true; 30 31 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 32 33 NSOpenGLPixelFormatAttribute attr[32]; 34 int i = 0; 35 36 attr[i++] = NSOpenGLPFADepthSize; 37 attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->depth); 38 39 if (_traits->doubleBuffer) { 40 attr[i++] = NSOpenGLPFADoubleBuffer; 41 } 42 43 if (_traits->alpha) { 44 attr[i++] = NSOpenGLPFAAlphaSize; 45 attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->alpha); 46 } 47 48 if (_traits->stencil) { 49 attr[i++] = NSOpenGLPFAStencilSize; 50 attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->stencil); 51 } 52 53 54 if (_traits->sampleBuffers) { 55 attr[i++] = NSOpenGLPFASampleBuffers; 56 attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->sampleBuffers); 57 attr[i++] = NSOpenGLPFASamples; 58 attr[i++] = static_cast<NSOpenGLPixelFormatAttribute>(_traits->samples); 59 } 60 61 attr[i++] = NSOpenGLPFAPixelBuffer; // for pbuffer usage 62 attr[i++] = NSOpenGLPFAAccelerated; 63 attr[i] = static_cast<NSOpenGLPixelFormatAttribute>(0); 64 65 // create the context 66 NSOpenGLContext* sharedContext = NULL; 67 68 GraphicsWindowCocoa* graphicsWindowCocoa = dynamic_cast<GraphicsWindowCocoa*>(_traits->sharedContext); 69 if (graphicsWindowCocoa) 70 { 71 sharedContext = graphicsWindowCocoa->getContext(); 72 } 73 else 74 { 75 PixelBufferCocoa* pixelbuffer = dynamic_cast<PixelBufferCocoa*>(_traits->sharedContext); 76 if (pixelbuffer) { 77 sharedContext = pixelbuffer->getContext(); 78 } 79 } 80 81 NSOpenGLPixelFormat* pixelformat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr ]; 82 _context = [[NSOpenGLContext alloc] initWithFormat: pixelformat shareContext: sharedContext]; 83 NSOpenGLPixelBuffer* pbuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget: _traits->target textureInternalFormat: _traits->format textureMaxMipMapLevel: _traits->level pixelsWide: _traits->width pixelsHigh: _traits->height]; 84 85 [_context setPixelBuffer: pbuffer cubeMapFace: _traits->face mipMapLevel:_traits->level currentVirtualScreen: nil]; 86 87 [pool release]; 88 89 _realized = (_context != nil); 90 return _realized; 30 91 } 92 31 93 32 94 void PixelBufferCocoa::closeImplementation() 33 95 { 34 std::cout << "PixelBufferCocoa :: closeImplementation not implemented yet " << std::endl; 96 _realized = false; 97 98 35 99 } 100 36 101 37 102 … … 39 104 bool PixelBufferCocoa::makeCurrentImplementation() 40 105 { 41 std::cout << "PixelBufferCocoa :: makeCurrentImplementation not implemented yet " << std::endl; 106 // osg::notify(osg::INFO) << "PixelBufferCocoa::makeCurrentImplementation" << std::endl; 107 108 [_context makeCurrentContext]; 42 109 return true; 43 110 } … … 47 114 bool PixelBufferCocoa::makeContextCurrentImplementation(osg::GraphicsContext* readContext) 48 115 { 49 std::cout << "PixelBufferCocoa :: makeContextCurrentImplementation not implemented yet " << std::endl; 50 return true; 116 return makeCurrentImplementation(); 51 117 } 52 118 … … 54 120 bool PixelBufferCocoa::releaseContextImplementation() 55 121 { 56 std::cout << "PixelBufferCocoa :: releaseContextImplementation not implemented yet " << std::endl; 57 return true; 122 // osg::notify(osg::INFO) << "PixelBufferCocoa::releaseContextImplementation" << std::endl; 123 124 [NSOpenGLContext clearCurrentContext]; 125 return true; 58 126 } 59 127 … … 67 135 void PixelBufferCocoa::swapBuffersImplementation() 68 136 { 69 std::cout << "PixelBufferCocoa :: swapBuffersImplementation not implemented yet " << std::endl; 137 osg::notify(osg::INFO) << "PixelBufferCocoa::swapBuffersImplementation" << std::endl; 138 [_context flushBuffer]; 70 139 } 71 140 72 141 PixelBufferCocoa::~PixelBufferCocoa() 73 142 { 143 [_context release]; 74 144 } 75 145
