Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nsgldevice.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #if !defined(__MITSUBA_HW_NSGLDEVICE_H_)
20 #define __MITSUBA_HW_NSGLDEVICE_H_
21 
22 #include <mitsuba/hw/device.h>
23 #include <mitsuba/hw/nsglsession.h>
24 
26 class NSGLDevice;
28 
29 #ifdef __OBJC__
30 #include <Cocoa/Cocoa.h>
31 
32 @interface CustomView : NSView < NSWindowDelegate > {
33  mitsuba::NSGLDevice *m_device;
34  unsigned int m_keymap[0xFF];
35  unsigned int m_modifiers;
36  unsigned int m_buttonMask;
37  bool m_mouseInWindow;
38  bool m_firstMouseMotion;
39  bool m_focused;
40  bool m_ignoreNextMouseEvent;
41 }
42 
43 - (BOOL) focused;
44 - (unsigned int) extractModifiers: (unsigned int) modifiers;
45 - (void) setDevice: (mitsuba::NSGLDevice *) device;
46 - (void) ignoreNextMouseEvent;
47 - (void) ignoreFirstMouseMotion;
48 @end
49 
50 #endif
51 
53 
54 /** \brief A MacOS X (NSGL) device
55  */
57 public:
58  /// Create a new device
59  NSGLDevice(NSGLSession *session);
60 
61  /// Initialize the device
62  void init(Device *other = NULL);
63 
64  /// Shut the device down
65  void shutdown();
66 
67  /// Flip the buffers
68  void flip();
69 
70  /// Only applies in windowed mode
71  void setVisible(bool enabled);
72 
73  /// Only applies in windowed mode
74  void setPosition(const Point2i &position);
75 
76  /// Set the window title
77  void setTitle(const std::string &title);
78 
79  /// Display the NSGL cursor?
80  void showCursor(bool enabled);
81 
82  /// Move the mouse to another position
83  void warpMouse(const Point2i &position);
84 
85  /// Associate a renderer with this device
86  void makeCurrent(Renderer *renderer);
87 
88  /// Set the cursor grab state
89  void setGrab(bool grab);
90 
91  // *************************************
92  // ************* INTERNAL **************
93  // *************************************
94 
95  /// Is the NSGL cursor shown?
96  inline bool getCursor() const { return m_cursor; }
97 
98  /// Is the mouse inside the window?
99  bool isMouseInWindow();
100 
101  /// Push a device event onto the stack
102  void pushEvent(const DeviceEvent &event);
103 
104  /**
105  * Deliver all events which have been
106  * received asynchronously
107  */
108  void processEvents();
109 
110  /// Return the NSWindow
111  inline void *getWindow() { return m_window; }
112 
113  /// Return the pixel format
114  inline void *getPixelFormat() { return m_fmt; }
115 
117 protected:
118  /// Virtual destructor
119  virtual ~NSGLDevice();
120 private:
121 #ifdef __OBJC__
122  NSWindow *m_window;
123  CustomView *m_view;
124  NSOpenGLPixelFormat *m_fmt;
125  NSOpenGLContext *m_currentContext;
126 #else
127  void *m_window;
128  void *m_view;
129  void *m_fmt;
130  void *m_currentContext;
131 #endif
132  bool m_visible;
133  bool m_cursor;
134  std::vector<DeviceEvent> m_deviceEvents;
135  ref<Mutex> m_mutex;
136 };
137 
139 
140 #endif /* __MITSUBA_HW_NSGLDEVICE_H_ */
The device event structure encapsulates event information such as mouse movement or key presses...
Definition: device.h:34
A MacOS X (NSGL) device.
Definition: nsgldevice.h:56
virtual void setPosition(const Point2i &position)
Set the position of the device.
#define MTS_EXPORT_HW
Definition: platform.h:114
virtual void flip()
Flip the buffers (when using double buffering)
A MacOS X (NSGL) windowing environment session.
Definition: nsglsession.h:29
virtual void shutdown()
Shut the device down.
virtual void makeCurrent(Renderer *renderer)=0
Associate the renderer with this device.
virtual void setVisible(bool visible)=0
Only applies to devices, which are UI windows.
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
void * getWindow()
Return the NSWindow.
Definition: nsgldevice.h:111
virtual void init(Device *other=NULL)
An abstract drawing device.
Definition: device.h:136
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Definition: fwd.h:99
Reference counting helper.
Definition: ref.h:40
Abstract renderer implementation.
Definition: renderer.h:79
virtual void setTitle(const std::string &title)
Set the window title.
void * getPixelFormat()
Return the pixel format.
Definition: nsgldevice.h:114
#define MTS_NAMESPACE_END
Definition: platform.h:138
bool getCursor() const
Is the NSGL cursor shown?
Definition: nsgldevice.h:96