Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2010-01-13 10:26:11 +0300
committerJoseph Eagar <joeedh@gmail.com>2010-01-13 10:26:11 +0300
commit219b472920998d763916c165816191bd8ae1f4a1 (patch)
treed942c83359abf7cb1f0362afbbd543e3f72e38ee /intern/ghost
parented12e1978fec2eed33439f5e342cd84ef443d04e (diff)
parent3b1585b1722efcf06ef9aa8f9d673047e68a7b9d (diff)
merge with trunk/2.5 at r25907
Diffstat (limited to 'intern/ghost')
-rw-r--r--intern/ghost/GHOST_C-api.h5
-rw-r--r--intern/ghost/GHOST_ISystem.h18
-rw-r--r--intern/ghost/GHOST_Types.h23
-rw-r--r--intern/ghost/intern/GHOST_C-api.cpp5
-rw-r--r--intern/ghost/intern/GHOST_SystemCarbon.cpp1
-rw-r--r--intern/ghost/intern/GHOST_SystemCarbon.h1
-rw-r--r--intern/ghost/intern/GHOST_SystemCocoa.h19
-rw-r--r--intern/ghost/intern/GHOST_SystemCocoa.mm108
-rw-r--r--intern/ghost/intern/GHOST_SystemWin32.cpp2
-rw-r--r--intern/ghost/intern/GHOST_SystemWin32.h6
-rw-r--r--intern/ghost/intern/GHOST_SystemX11.cpp3
-rw-r--r--intern/ghost/intern/GHOST_SystemX11.h1
-rw-r--r--intern/ghost/intern/GHOST_Window.cpp6
-rw-r--r--intern/ghost/intern/GHOST_Window.h23
-rw-r--r--intern/ghost/intern/GHOST_WindowCarbon.cpp3
-rw-r--r--intern/ghost/intern/GHOST_WindowCarbon.h3
-rw-r--r--intern/ghost/intern/GHOST_WindowCocoa.h22
-rw-r--r--intern/ghost/intern/GHOST_WindowCocoa.mm68
-rw-r--r--intern/ghost/intern/GHOST_WindowWin32.cpp5
-rw-r--r--intern/ghost/intern/GHOST_WindowWin32.h4
-rw-r--r--intern/ghost/intern/GHOST_WindowX11.cpp73
-rw-r--r--intern/ghost/intern/GHOST_WindowX11.h4
-rw-r--r--intern/ghost/intern/Makefile2
23 files changed, 298 insertions, 107 deletions
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index d4788ae9e86..7e7b24721eb 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -162,6 +162,8 @@ extern void GHOST_GetMainDisplayDimensions(GHOST_SystemHandle systemhandle,
* @param height The height the window.
* @param state The state of the window when opened.
* @param type The type of drawing context installed in this window.
+ * @param stereoVisual Stereo visual for quad buffered stereo.
+ * @param numOfAASamples Number of samples used for AA (zero if no AA)
* @return A handle to the new window ( == NULL if creation failed).
*/
extern GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
@@ -172,7 +174,8 @@ extern GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
- const int stereoVisual);
+ const int stereoVisual,
+ const GHOST_TUns16 numOfAASamples);
/**
* Returns the window user data.
diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h
index 305caa70ae4..d1449aaef59 100644
--- a/intern/ghost/GHOST_ISystem.h
+++ b/intern/ghost/GHOST_ISystem.h
@@ -216,14 +216,15 @@ public:
* Create a new window.
* The new window is added to the list of windows managed.
* Never explicitly delete the window, use disposeWindow() instead.
- * @param title The name of the window (displayed in the title bar of the window if the OS supports it).
- * @param left The coordinate of the left edge of the window.
- * @param top The coordinate of the top edge of the window.
- * @param width The width the window.
- * @param height The height the window.
- * @param state The state of the window when opened.
- * @param type The type of drawing context installed in this window.
+ * @param title The name of the window (displayed in the title bar of the window if the OS supports it).
+ * @param left The coordinate of the left edge of the window.
+ * @param top The coordinate of the top edge of the window.
+ * @param width The width the window.
+ * @param height The height the window.
+ * @param state The state of the window when opened.
+ * @param type The type of drawing context installed in this window.
* @param stereoVisual Create a stereo visual for quad buffered stereo.
+ * @param numOfAASamples Number of samples used for AA (zero if no AA)
* @param parentWindow Parent (embedder) window
* @return The new window (or 0 if creation failed).
*/
@@ -231,7 +232,8 @@ public:
const STR_String& title,
GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
GHOST_TWindowState state, GHOST_TDrawingContextType type,
- const bool stereoVisual,
+ const bool stereoVisual = false,
+ const GHOST_TUns16 numOfAASamples = 0,
const GHOST_TEmbedderWindowID parentWindow = 0) = 0;
/**
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 5c888e218d8..e26013c1ecd 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -151,6 +151,7 @@ typedef enum {
GHOST_kEventButtonDown, /// Mouse button event
GHOST_kEventButtonUp, /// Mouse button event
GHOST_kEventWheel, /// Mouse wheel event
+ GHOST_kEventTrackpad, /// Trackpad event
GHOST_kEventNDOFMotion, /// N degree of freedom device motion event
GHOST_kEventNDOFButton, /// N degree of freedom device button event
@@ -373,6 +374,28 @@ typedef struct {
GHOST_TInt32 z;
} GHOST_TEventWheelData;
+typedef enum {
+ GHOST_kTrackpadEventUnknown =0,
+ GHOST_kTrackpadEventScroll,
+ GHOST_kTrackpadEventRotate,
+ GHOST_kTrackpadEventSwipe, /* Reserved, not used for now */
+ GHOST_kTrackpadEventMagnify
+} GHOST_TTrackpadEventSubTypes;
+
+
+typedef struct {
+ /** The event subtype */
+ GHOST_TTrackpadEventSubTypes subtype;
+ /** The x-location of the trackpad event */
+ GHOST_TInt32 x;
+ /** The y-location of the trackpad event */
+ GHOST_TInt32 y;
+ /** The x-delta or value of the trackpad event */
+ GHOST_TInt32 deltaX;
+ /** The y-delta (currently only for scroll subtype) of the trackpad event */
+ GHOST_TInt32 deltaY;
+} GHOST_TEventTrackpadData;
+
typedef enum {
GHOST_kDragnDropTypeUnknown =0,
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 556176809f4..be726282d80 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -140,7 +140,8 @@ GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
- const int stereoVisual)
+ const int stereoVisual,
+ const GHOST_TUns16 numOfAASamples)
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
bool bstereoVisual;
@@ -151,7 +152,7 @@ GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
bstereoVisual = false;
return (GHOST_WindowHandle) system->createWindow(title, left, top, width, height,
- state, type, bstereoVisual);
+ state, type, bstereoVisual, numOfAASamples);
}
GHOST_TUserDataPtr GHOST_GetWindowUserData(GHOST_WindowHandle windowhandle)
diff --git a/intern/ghost/intern/GHOST_SystemCarbon.cpp b/intern/ghost/intern/GHOST_SystemCarbon.cpp
index 57d6f6c06cc..3813a5ee450 100644
--- a/intern/ghost/intern/GHOST_SystemCarbon.cpp
+++ b/intern/ghost/intern/GHOST_SystemCarbon.cpp
@@ -402,6 +402,7 @@ GHOST_IWindow* GHOST_SystemCarbon::createWindow(
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
bool stereoVisual,
+ const GHOST_TUns16 numOfAASamples,
const GHOST_TEmbedderWindowID parentWindow
)
{
diff --git a/intern/ghost/intern/GHOST_SystemCarbon.h b/intern/ghost/intern/GHOST_SystemCarbon.h
index 5b3b786a5ac..7ebbbd8e97b 100644
--- a/intern/ghost/intern/GHOST_SystemCarbon.h
+++ b/intern/ghost/intern/GHOST_SystemCarbon.h
@@ -115,6 +115,7 @@ public:
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
const bool stereoVisual,
+ const GHOST_TUns16 numOfAASamples = 0,
const GHOST_TEmbedderWindowID parentWindow = 0
);
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.h b/intern/ghost/intern/GHOST_SystemCocoa.h
index 8a93e9559ba..62bb1733bca 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.h
+++ b/intern/ghost/intern/GHOST_SystemCocoa.h
@@ -93,13 +93,15 @@ public:
* Create a new window.
* The new window is added to the list of windows managed.
* Never explicitly delete the window, use disposeWindow() instead.
- * @param title The name of the window (displayed in the title bar of the window if the OS supports it).
- * @param left The coordinate of the left edge of the window.
- * @param top The coordinate of the top edge of the window.
- * @param width The width the window.
- * @param height The height the window.
- * @param state The state of the window when opened.
- * @param type The type of drawing context installed in this window.
+ * @param title The name of the window (displayed in the title bar of the window if the OS supports it).
+ * @param left The coordinate of the left edge of the window.
+ * @param top The coordinate of the top edge of the window.
+ * @param width The width the window.
+ * @param height The height the window.
+ * @param state The state of the window when opened.
+ * @param type The type of drawing context installed in this window.
+ * @param stereoVisual Stereo visual for quad buffered stereo.
+ * @param numOfAASamples Number of samples used for AA (zero if no AA)
* @param parentWindow Parent (embedder) window
* @return The new window (or 0 if creation failed).
*/
@@ -111,7 +113,8 @@ public:
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
- const bool stereoVisual,
+ const bool stereoVisual = false,
+ const GHOST_TUns16 numOfAASamples = 0,
const GHOST_TEmbedderWindowID parentWindow = 0
);
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm
index cacacd368bb..c2d3b56ce59 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemCocoa.mm
@@ -41,6 +41,7 @@
#include "GHOST_EventCursor.h"
#include "GHOST_EventWheel.h"
#include "GHOST_EventNDOF.h"
+#include "GHOST_EventTrackpad.h"
#include "GHOST_EventDragnDrop.h"
#include "GHOST_TimerManager.h"
@@ -374,6 +375,43 @@ static GHOST_TKey convertKey(int rawCode, unichar recvChar)
}
+#pragma mark defines for 10.6 api not documented in 10.5
+#ifndef MAC_OS_X_VERSION_10_6
+enum {
+ /* The following event types are available on some hardware on 10.5.2 and later */
+ NSEventTypeGesture = 29,
+ NSEventTypeMagnify = 30,
+ NSEventTypeSwipe = 31,
+ NSEventTypeRotate = 18,
+ NSEventTypeBeginGesture = 19,
+ NSEventTypeEndGesture = 20
+};
+
+@interface NSEvent(GestureEvents)
+/* This message is valid for events of type NSEventTypeMagnify, on 10.5.2 or later */
+#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
+- (float)magnification; // change in magnification.
+#else
+- (CGFloat)magnification; // change in magnification.
+#endif
+@end
+
+@interface NSEvent(SnowLeopardEvents)
+/* modifier keys currently down. This returns the state of devices combined
+ with synthesized events at the moment, independent of which events
+ have been delivered via the event stream. */
+#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
++ (unsigned int)modifierFlags; //NSUInteger is defined only from 10.5
+#else
++ (NSUInteger)modifierFlags;
+#endif
+@end
+
+#endif
+
+
+#pragma mark Utility functions
+
#define FIRSTFILEBUFLG 512
static bool g_hasFirstFile = false;
static char g_firstFileBuf[512];
@@ -577,7 +615,7 @@ GHOST_TSuccess GHOST_SystemCocoa::init()
}
[NSApp finishLaunching];
-
+
[pool drain];
}
return success;
@@ -638,6 +676,7 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow(
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
bool stereoVisual,
+ const GHOST_TUns16 numOfAASamples,
const GHOST_TEmbedderWindowID parentWindow
)
{
@@ -653,7 +692,7 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow(
left = left > contentRect.origin.x ? left : contentRect.origin.x;
top = top > contentRect.origin.y ? top : contentRect.origin.y;
- window = new GHOST_WindowCocoa (this, title, left, top, width, height, state, type);
+ window = new GHOST_WindowCocoa (this, title, left, top, width, height, state, type, stereoVisual, numOfAASamples);
if (window) {
if (window->getValid()) {
@@ -826,7 +865,9 @@ bool GHOST_SystemCocoa::processEvents(bool waitForEvent)
case NSScrollWheel:
case NSOtherMouseDown:
case NSOtherMouseUp:
- case NSOtherMouseDragged:
+ case NSOtherMouseDragged:
+ case NSEventTypeMagnify:
+ case NSEventTypeRotate:
handleMouseEvent(event);
break;
@@ -835,11 +876,9 @@ bool GHOST_SystemCocoa::processEvents(bool waitForEvent)
handleTabletEvent(event,[event type]);
break;
- /* Trackpad features, will need OS X 10.6 for implementation
+ /* Trackpad features, fired only from OS X 10.5.2
case NSEventTypeGesture:
- case NSEventTypeMagnify:
case NSEventTypeSwipe:
- case NSEventTypeRotate:
case NSEventTypeBeginGesture:
case NSEventTypeEndGesture:
break; */
@@ -883,11 +922,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleApplicationBecomeActiveEvent()
#else
//If build against an older SDK, check if running on 10.6 to use the correct function
if ([NSEvent respondsToSelector:@selector(modifierFlags)]) {
-#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
- modifiers = (unsigned int)[NSEvent modifierFlags];
-#else
- modifiers = (NSUInteger)[NSEvent modifierFlags];
-#endif
+ modifiers = [NSEvent modifierFlags];
}
else {
//TODO: need to find a better workaround for the missing cocoa "getModifierFlag" function in 10.4/10.5
@@ -1300,16 +1335,53 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
case NSScrollWheel:
{
- GHOST_TInt32 delta;
-
- double deltaF = [event deltaY];
- if (deltaF == 0.0) break; //discard trackpad delta=0 events
-
- delta = deltaF > 0.0 ? 1 : -1;
- pushEvent(new GHOST_EventWheel([event timestamp]*1000, window, delta));
+ /* Send Wheel event if sent from the mouse, trackpad event otherwise */
+ if ([event subtype] == NSMouseEventSubtype) {
+ GHOST_TInt32 delta;
+
+ double deltaF = [event deltaY];
+ if (deltaF == 0.0) break; //discard trackpad delta=0 events
+
+ delta = deltaF > 0.0 ? 1 : -1;
+ pushEvent(new GHOST_EventWheel([event timestamp]*1000, window, delta));
+ }
+ else {
+ NSPoint mousePos = [event locationInWindow];
+ double dx = [event deltaX];
+ double dy = -[event deltaY];
+
+ const double deltaMax = 50.0;
+
+ if ((dx == 0) && (dy == 0)) break;
+
+ /* Quadratic acceleration */
+ dx = dx*(fabs(dx)+0.5);
+ if (dx<0.0) dx-=0.5; else dx+=0.5;
+ if (dx< -deltaMax) dx= -deltaMax; else if (dx>deltaMax) dx=deltaMax;
+
+ dy = dy*(fabs(dy)+0.5);
+ if (dy<0.0) dy-=0.5; else dy+=0.5;
+ if (dy< -deltaMax) dy= -deltaMax; else if (dy>deltaMax) dy=deltaMax;
+
+ pushEvent(new GHOST_EventTrackpad([event timestamp]*1000, window, GHOST_kTrackpadEventScroll, mousePos.x, mousePos.y, dx, dy));
+ }
}
break;
+ case NSEventTypeMagnify:
+ {
+ NSPoint mousePos = [event locationInWindow];
+ pushEvent(new GHOST_EventTrackpad([event timestamp]*1000, window, GHOST_kTrackpadEventMagnify, mousePos.x, mousePos.y,
+ [event magnification]*250.0 + 0.1, 0));
+ }
+ break;
+
+ case NSEventTypeRotate:
+ {
+ NSPoint mousePos = [event locationInWindow];
+ pushEvent(new GHOST_EventTrackpad([event timestamp]*1000, window, GHOST_kTrackpadEventRotate, mousePos.x, mousePos.y,
+ -[event rotation] * 5.0, 0));
+ }
default:
return GHOST_kFailure;
break;
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 15914a5bf43..d7d657fb496 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -190,7 +190,7 @@ GHOST_IWindow* GHOST_SystemWin32::createWindow(
const STR_String& title,
GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
GHOST_TWindowState state, GHOST_TDrawingContextType type,
- bool stereoVisual, const GHOST_TEmbedderWindowID parentWindow )
+ bool stereoVisual, const GHOST_TUns16 numOfAASamples, const GHOST_TEmbedderWindowID parentWindow )
{
GHOST_Window* window = 0;
window = new GHOST_WindowWin32 (this, title, left, top, width, height, state, type, stereoVisual);
diff --git a/intern/ghost/intern/GHOST_SystemWin32.h b/intern/ghost/intern/GHOST_SystemWin32.h
index 517f7ddbeea..65d6a57ede3 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.h
+++ b/intern/ghost/intern/GHOST_SystemWin32.h
@@ -110,6 +110,8 @@ public:
* @param height The height the window.
* @param state The state of the window when opened.
* @param type The type of drawing context installed in this window.
+ * @param stereoVisual Stereo visual for quad buffered stereo.
+ * @param numOfAASamples Number of samples used for AA (zero if no AA)
* @param parentWindow Parent (embedder) window
* @return The new window (or 0 if creation failed).
*/
@@ -117,7 +119,9 @@ public:
const STR_String& title,
GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height,
GHOST_TWindowState state, GHOST_TDrawingContextType type,
- const bool stereoVisual, const GHOST_TEmbedderWindowID parentWindow = 0 );
+ const bool stereoVisual = false,
+ const GHOST_TUns16 numOfAASamples = 0,
+ const GHOST_TEmbedderWindowID parentWindow = 0 );
/***************************************************************************************
** Event management functionality
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index ad8647d2246..3ee3c1a29f3 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -228,6 +228,8 @@ getMainDisplayDimensions(
* @param height The height the window.
* @param state The state of the window when opened.
* @param type The type of drawing context installed in this window.
+ * @param stereoVisual Stereo visual for quad buffered stereo.
+ * @param numOfAASamples Number of samples used for AA (zero if no AA)
* @param parentWindow Parent (embedder) window
* @return The new window (or 0 if creation failed).
*/
@@ -242,6 +244,7 @@ createWindow(
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
bool stereoVisual,
+ const GHOST_TUns16 numOfAASamples,
const GHOST_TEmbedderWindowID parentWindow
){
GHOST_WindowX11 * window = 0;
diff --git a/intern/ghost/intern/GHOST_SystemX11.h b/intern/ghost/intern/GHOST_SystemX11.h
index d76c3991beb..361db783102 100644
--- a/intern/ghost/intern/GHOST_SystemX11.h
+++ b/intern/ghost/intern/GHOST_SystemX11.h
@@ -127,6 +127,7 @@ public:
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
const bool stereoVisual,
+ const GHOST_TUns16 numOfAASamples = 0,
const GHOST_TEmbedderWindowID parentWindow = 0
);
diff --git a/intern/ghost/intern/GHOST_Window.cpp b/intern/ghost/intern/GHOST_Window.cpp
index 14a255e2e5e..939a911dfac 100644
--- a/intern/ghost/intern/GHOST_Window.cpp
+++ b/intern/ghost/intern/GHOST_Window.cpp
@@ -44,13 +44,15 @@ GHOST_Window::GHOST_Window(
GHOST_TInt32 /*left*/, GHOST_TInt32 /*top*/, GHOST_TUns32 width, GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
- const bool stereoVisual)
+ const bool stereoVisual,
+ const GHOST_TUns16 numOfAASamples)
:
m_drawingContextType(type),
m_cursorVisible(true),
m_cursorGrab(GHOST_kGrabDisable),
m_cursorShape(GHOST_kStandardCursorDefault),
- m_stereoVisual(stereoVisual)
+ m_stereoVisual(stereoVisual),
+ m_numOfAASamples(numOfAASamples)
{
m_isUnsavedChanges = false;
m_canAcceptDragOperation = false;
diff --git a/intern/ghost/intern/GHOST_Window.h b/intern/ghost/intern/GHOST_Window.h
index 1b5681dc41c..8aab9125130 100644
--- a/intern/ghost/intern/GHOST_Window.h
+++ b/intern/ghost/intern/GHOST_Window.h
@@ -75,14 +75,15 @@ public:
* Constructor.
* Creates a new window and opens it.
* To check if the window was created properly, use the getValid() method.
- * @param title The text shown in the title bar of the window.
- * @param left The coordinate of the left edge of the window.
- * @param top The coordinate of the top edge of the window.
- * @param width The width the window.
- * @param heigh The height the window.
- * @param state The state the window is initially opened with.
- * @param type The type of drawing context installed in this window.
- * @param stereoVisual Stereo visual for quad buffered stereo.
+ * @param title The text shown in the title bar of the window.
+ * @param left The coordinate of the left edge of the window.
+ * @param top The coordinate of the top edge of the window.
+ * @param width The width the window.
+ * @param heigh The height the window.
+ * @param state The state the window is initially opened with.
+ * @param type The type of drawing context installed in this window.
+ * @param stereoVisual Stereo visual for quad buffered stereo.
+ * @param numOfAASamples Number of samples used for AA (zero if no AA)
*/
GHOST_Window(
const STR_String& title,
@@ -92,7 +93,8 @@ public:
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
- const bool stereoVisual = false);
+ const bool stereoVisual = false,
+ const GHOST_TUns16 numOfAASamples = 0);
/**
* @section Interface inherited from GHOST_IWindow left for derived class
@@ -319,6 +321,9 @@ protected:
* the graphics h/w
*/
bool m_stereoVisual;
+
+ /** Number of samples used in anti-aliasing, set to 0 if no AA **/
+ GHOST_TUns16 m_numOfAASamples;
/** Full-screen width */
GHOST_TUns32 m_fullScreenWidth;
diff --git a/intern/ghost/intern/GHOST_WindowCarbon.cpp b/intern/ghost/intern/GHOST_WindowCarbon.cpp
index 362e949a0a4..3e53a052146 100644
--- a/intern/ghost/intern/GHOST_WindowCarbon.cpp
+++ b/intern/ghost/intern/GHOST_WindowCarbon.cpp
@@ -98,7 +98,8 @@ GHOST_WindowCarbon::GHOST_WindowCarbon(
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
- const bool stereoVisual
+ const bool stereoVisual,
+ const GHOST_TUns16 numOfAASamples
) :
GHOST_Window(title, left, top, width, height, state, GHOST_kDrawingContextTypeNone),
m_windowRef(0),
diff --git a/intern/ghost/intern/GHOST_WindowCarbon.h b/intern/ghost/intern/GHOST_WindowCarbon.h
index dd00add7fb1..b91e5410ddd 100644
--- a/intern/ghost/intern/GHOST_WindowCarbon.h
+++ b/intern/ghost/intern/GHOST_WindowCarbon.h
@@ -80,7 +80,8 @@ public:
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
- const bool stereoVisual = false
+ const bool stereoVisual = false,
+ const GHOST_TUns16 numOfAASamples = 0
);
/**
diff --git a/intern/ghost/intern/GHOST_WindowCocoa.h b/intern/ghost/intern/GHOST_WindowCocoa.h
index 0987250e4d2..9bc7f084727 100644
--- a/intern/ghost/intern/GHOST_WindowCocoa.h
+++ b/intern/ghost/intern/GHOST_WindowCocoa.h
@@ -61,15 +61,16 @@ public:
* Constructor.
* Creates a new window and opens it.
* To check if the window was created properly, use the getValid() method.
- * @param systemCocoa The associated system class to forward events to
- * @param title The text shown in the title bar of the window.
- * @param left The coordinate of the left edge of the window.
- * @param top The coordinate of the top edge of the window.
- * @param width The width the window.
- * @param height The height the window.
- * @param state The state the window is initially opened with.
- * @param type The type of drawing context installed in this window.
- * @param stereoVisual Stereo visual for quad buffered stereo.
+ * @param systemCocoa The associated system class to forward events to
+ * @param title The text shown in the title bar of the window.
+ * @param left The coordinate of the left edge of the window.
+ * @param top The coordinate of the top edge of the window.
+ * @param width The width the window.
+ * @param height The height the window.
+ * @param state The state the window is initially opened with.
+ * @param type The type of drawing context installed in this window.
+ * @param stereoVisual Stereo visual for quad buffered stereo.
+ * @param numOfAASamples Number of samples used for AA (zero if no AA)
*/
GHOST_WindowCocoa(
GHOST_SystemCocoa *systemCocoa,
@@ -80,7 +81,8 @@ public:
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
- const bool stereoVisual = false
+ const bool stereoVisual = false,
+ const GHOST_TUns16 numOfAASamples = 0
);
/**
diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm
index 3f52ea535bd..873a5925102 100644
--- a/intern/ghost/intern/GHOST_WindowCocoa.mm
+++ b/intern/ghost/intern/GHOST_WindowCocoa.mm
@@ -34,9 +34,11 @@
#include <Carbon/Carbon.h>
#endif
+#include <OpenGL/gl.h>
/***** Multithreaded opengl code : uncomment for enabling
#include <OpenGL/OpenGL.h>
*/
+
#include "GHOST_WindowCocoa.h"
#include "GHOST_SystemCocoa.h"
@@ -277,14 +279,15 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
- const bool stereoVisual
+ const bool stereoVisual, const GHOST_TUns16 numOfAASamples
) :
- GHOST_Window(title, left, top, width, height, state, GHOST_kDrawingContextTypeNone, stereoVisual),
+ GHOST_Window(title, left, top, width, height, state, GHOST_kDrawingContextTypeNone, stereoVisual, numOfAASamples),
m_customCursor(0)
{
NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[40];
+ NSOpenGLPixelFormat *pixelFormat = nil;
int i;
-
+
m_systemCocoa = systemCocoa;
m_fullScreen = false;
@@ -329,13 +332,52 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
if (stereoVisual) pixelFormatAttrsWindow[i++] = NSOpenGLPFAStereo;
+ if (numOfAASamples>0) {
+ // Multisample anti-aliasing
+ pixelFormatAttrsWindow[i++] = NSOpenGLPFAMultisample;
+
+ pixelFormatAttrsWindow[i++] = NSOpenGLPFASampleBuffers;
+ pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 1;
+
+ pixelFormatAttrsWindow[i++] = NSOpenGLPFASamples;
+ pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) numOfAASamples;
+
+ pixelFormatAttrsWindow[i++] = NSOpenGLPFANoRecovery;
+ }
+
pixelFormatAttrsWindow[i] = (NSOpenGLPixelFormatAttribute) 0;
-
+ pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttrsWindow];
+
+
+ //Fall back to no multisampling if Antialiasing init failed
+ if (pixelFormat == nil) {
+ i=0;
+ pixelFormatAttrsWindow[i++] = NSOpenGLPFADoubleBuffer;
+ pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccelerated;
+ //pixelFormatAttrsWindow[i++] = NSOpenGLPFAAllowOfflineRenderers,; // Removed to allow 10.4 builds, and 2 GPUs rendering is not used anyway
+
+ pixelFormatAttrsWindow[i++] = NSOpenGLPFADepthSize;
+ pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 32;
+
+ if (stereoVisual) pixelFormatAttrsWindow[i++] = NSOpenGLPFAStereo;
+
+ pixelFormatAttrsWindow[i] = (NSOpenGLPixelFormatAttribute) 0;
+
+ pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttrsWindow];
+
+ }
+
+ if (numOfAASamples>0) { //Set m_numOfAASamples to the actual value
+ GLint gli;
+ [pixelFormat getValues:&gli forAttribute:NSOpenGLPFASamples forVirtualScreen:0];
+ if (m_numOfAASamples != (GHOST_TUns16)gli) {
+ m_numOfAASamples = (GHOST_TUns16)gli;
+ printf("GHOST_Window could be created with anti-aliasing of only %i samples\n",m_numOfAASamples);
+ }
+ }
+
//Creates the OpenGL View inside the window
- NSOpenGLPixelFormat *pixelFormat =
- [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttrsWindow];
-
m_openGLView = [[CocoaOpenGLView alloc] initWithFrame:rect
pixelFormat:pixelFormat];
@@ -398,14 +440,7 @@ GHOST_WindowCocoa::~GHOST_WindowCocoa()
bool GHOST_WindowCocoa::getValid() const
{
- bool valid;
- if (!m_fullScreen) {
- valid = (m_window != 0); //&& ::IsValidWindowPtr(m_windowRef);
- }
- else {
- valid = true;
- }
- return valid;
+ return (m_window != 0);
}
@@ -842,6 +877,9 @@ GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()
if (m_openGLContext != nil) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[m_openGLContext makeCurrentContext];
+
+ // Disable AA by default
+ if (m_numOfAASamples > 0) glDisable(GL_MULTISAMPLE_ARB);
[pool drain];
return GHOST_kSuccess;
}
diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp
index ea14f1dfc1b..e276f216fb7 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.cpp
+++ b/intern/ghost/intern/GHOST_WindowWin32.cpp
@@ -105,10 +105,11 @@ GHOST_WindowWin32::GHOST_WindowWin32(
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type,
- const bool stereoVisual)
+ const bool stereoVisual,
+ const GHOST_TUns16 numOfAASamples)
:
GHOST_Window(title, left, top, width, height, state, GHOST_kDrawingContextTypeNone,
- stereoVisual),
+ stereoVisual,numOfAASamples),
m_system(system),
m_hDC(0),
m_hGlRc(0),
diff --git a/intern/ghost/intern/GHOST_WindowWin32.h b/intern/ghost/intern/GHOST_WindowWin32.h
index 07a31911a5e..954546f3d82 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.h
+++ b/intern/ghost/intern/GHOST_WindowWin32.h
@@ -75,6 +75,7 @@ public:
* @param state The state the window is initially opened with.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
+ * @param numOfAASamples Number of samples used for AA (zero if no AA)
*/
GHOST_WindowWin32(
GHOST_SystemWin32 * system,
@@ -85,7 +86,8 @@ public:
GHOST_TUns32 height,
GHOST_TWindowState state,
GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
- const bool stereoVisual = false
+ const bool stereoVisual = false,
+ const GHOST_TUns16 numOfAASamples = 0
);
/**
diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp
index d9c2654f446..efde9005fe4 100644
--- a/intern/ghost/intern/GHOST_WindowX11.cpp
+++ b/intern/ghost/intern/GHOST_WindowX11.cpp
@@ -153,9 +153,10 @@ GHOST_WindowX11(
GHOST_TWindowState state,
const GHOST_TEmbedderWindowID parentWindow,
GHOST_TDrawingContextType type,
- const bool stereoVisual
+ const bool stereoVisual,
+ const GHOST_TUns16 numOfAASamples
) :
- GHOST_Window(title,left,top,width,height,state,type,stereoVisual),
+ GHOST_Window(title,left,top,width,height,state,type,stereoVisual,numOfAASamples),
m_context(NULL),
m_display(display),
m_system (system),
@@ -168,29 +169,54 @@ GHOST_WindowX11(
// Set up the minimum atrributes that we require and see if
// X can find us a visual matching those requirements.
- int attributes[40], i = 0;
+ int attributes[40], i, samples;
Atom atoms[2];
- int natom;
-
- if(m_stereoVisual)
- attributes[i++] = GLX_STEREO;
-
- attributes[i++] = GLX_RGBA;
- attributes[i++] = GLX_DOUBLEBUFFER;
- attributes[i++] = GLX_RED_SIZE; attributes[i++] = 1;
- attributes[i++] = GLX_BLUE_SIZE; attributes[i++] = 1;
- attributes[i++] = GLX_GREEN_SIZE; attributes[i++] = 1;
- attributes[i++] = GLX_DEPTH_SIZE; attributes[i++] = 1;
- attributes[i] = None;
-
- m_visual = glXChooseVisual(m_display, DefaultScreen(m_display), attributes);
+ int natom;
+ int glxVersionMajor, glxVersionMinor; // As in GLX major.minor
- if (m_visual == NULL) {
- // barf : no visual meeting these requirements could be found.
- printf("%s:%d: X11 glxChooseVisual() failed for OpenGL, verify working openGL system!\n", __FILE__, __LINE__);
+ if (!glXQueryVersion(m_display, &glxVersionMajor, &glxVersionMinor)) {
+ printf("%s:%d: X11 glXQueryVersion() failed, verify working openGL system!\n", __FILE__, __LINE__);
return;
}
-
+
+ /* Find the display with highest samples, starting at level requested */
+ for (samples = m_numOfAASamples; samples >= 0; samples--) {
+ i = 0; /* Reusing attributes array, so reset counter */
+
+ if(m_stereoVisual)
+ attributes[i++] = GLX_STEREO;
+
+ attributes[i++] = GLX_RGBA;
+ attributes[i++] = GLX_DOUBLEBUFFER;
+ attributes[i++] = GLX_RED_SIZE; attributes[i++] = 1;
+ attributes[i++] = GLX_BLUE_SIZE; attributes[i++] = 1;
+ attributes[i++] = GLX_GREEN_SIZE; attributes[i++] = 1;
+ attributes[i++] = GLX_DEPTH_SIZE; attributes[i++] = 1;
+ /* GLX >= 1.4 required for multi-sample */
+ if(samples && (glxVersionMajor >= 1) && (glxVersionMinor >= 4)) {
+ attributes[i++] = GLX_SAMPLE_BUFFERS; attributes[i++] = 1;
+ attributes[i++] = GLX_SAMPLES; attributes[i++] = samples;
+ }
+ attributes[i] = None;
+
+ m_visual = glXChooseVisual(m_display, DefaultScreen(m_display), attributes);
+
+ /* Any sample level or even zero, which means oversampling disabled, is good
+ but we need a valid visual to continue */
+ if (m_visual == NULL) {
+ if (samples == 0) {
+ /* All options exhausted, cannot continue */
+ printf("%s:%d: X11 glXChooseVisual() failed, verify working openGL system!\n", __FILE__, __LINE__);
+ return;
+ }
+ } else {
+ if (m_numOfAASamples && (m_numOfAASamples > samples)) {
+ printf("%s:%d: oversampling requested %i but using %i samples\n", __FILE__, __LINE__, m_numOfAASamples, samples);
+ }
+ break;
+ }
+ }
+
memset(&m_xtablet, 0, sizeof(m_xtablet));
// Create a bunch of attributes needed to create an X window.
@@ -1226,10 +1252,7 @@ GHOST_WindowX11::
if(m_xtablet.EraserDevice)
XCloseDevice(m_display, m_xtablet.EraserDevice);
- if (m_context) {
- if (m_context == s_firstContext) {
- s_firstContext = NULL;
- }
+ if (m_context != s_firstContext) {
glXDestroyContext(m_display, m_context);
}
diff --git a/intern/ghost/intern/GHOST_WindowX11.h b/intern/ghost/intern/GHOST_WindowX11.h
index 0dba1776553..9a299e16eb4 100644
--- a/intern/ghost/intern/GHOST_WindowX11.h
+++ b/intern/ghost/intern/GHOST_WindowX11.h
@@ -67,6 +67,7 @@ public:
* @param parentWindow Parent (embedder) window
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
+ * @param numOfAASamples Number of samples used for AA (zero if no AA)
*/
GHOST_WindowX11(
GHOST_SystemX11 *system,
@@ -79,7 +80,8 @@ public:
GHOST_TWindowState state,
const GHOST_TEmbedderWindowID parentWindow,
GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
- const bool stereoVisual = false
+ const bool stereoVisual = false,
+ const GHOST_TUns16 numOfAASamples = 0
);
bool
diff --git a/intern/ghost/intern/Makefile b/intern/ghost/intern/Makefile
index a6392662c30..d9f2bfe7cde 100644
--- a/intern/ghost/intern/Makefile
+++ b/intern/ghost/intern/Makefile
@@ -42,7 +42,7 @@ CCSRCS += GHOST_NDOFManager.cpp
ifeq ($(OS),$(findstring $(OS), "darwin"))
ifeq ($(WITH_COCOA), true)
- OCSRCS += $(wildcard *Cocoa.mm)
+ OCCSRCS += $(wildcard *Cocoa.mm)
CPPFLAGS += -DGHOST_COCOA
ifeq ($(WITH_QUICKTIME), true)
CPPFLAGS += -DWITH_QUICKTIME