Panda3D
callbackGraphicsWindow.h
1 // Filename: callbackGraphicsWindow.h
2 // Created by: drose (06Jan11)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef CALLBACKGRAPHICSWINDOW_H
16 #define CALLBACKGRAPHICSWINDOW_H
17 
18 #include "pandabase.h"
19 #include "graphicsWindow.h"
20 
21 ////////////////////////////////////////////////////////////////////
22 // Class : CallbackGraphicsWindow
23 // Description : This special window object doesn't represent a window
24 // in its own right, but instead hooks into some
25 // third-party API for creating and rendering to windows
26 // via callbacks. This can be used to allow Panda to
27 // render into an already-created OpenGL context, for
28 // instance.
29 ////////////////////////////////////////////////////////////////////
30 class EXPCL_PANDA_DISPLAY CallbackGraphicsWindow : public GraphicsWindow {
31 protected:
33  GraphicsPipe *pipe,
34  const string &name,
35  const FrameBufferProperties &fb_prop,
36  const WindowProperties &win_prop,
37  int flags,
39 
40 PUBLISHED:
41  virtual ~CallbackGraphicsWindow();
42 
43  class EXPCL_PANDA_DISPLAY WindowCallbackData : public CallbackData {
44  public:
46 
47  PUBLISHED:
48  INLINE CallbackGraphicsWindow *get_window() const;
49 
50  protected:
51  PT(CallbackGraphicsWindow) _window;
52 
53  public:
54  static TypeHandle get_class_type() {
55  return _type_handle;
56  }
57  static void init_type() {
58  CallbackData::init_type();
59  register_type(_type_handle, "CallbackGraphicsWindow::WindowCallbackData",
60  CallbackData::get_class_type());
61  }
62  virtual TypeHandle get_type() const {
63  return get_class_type();
64  }
65  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
66 
67  private:
68  static TypeHandle _type_handle;
69  };
70 
71  class EXPCL_PANDA_DISPLAY EventsCallbackData : public WindowCallbackData {
72  public:
74 
75  PUBLISHED:
76  virtual void upcall();
77 
78  public:
79  static TypeHandle get_class_type() {
80  return _type_handle;
81  }
82  static void init_type() {
83  WindowCallbackData::init_type();
84  register_type(_type_handle, "CallbackGraphicsWindow::EventsCallbackData",
85  WindowCallbackData::get_class_type());
86  }
87  virtual TypeHandle get_type() const {
88  return get_class_type();
89  }
90  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
91 
92  private:
93  static TypeHandle _type_handle;
94  };
95 
96  class EXPCL_PANDA_DISPLAY PropertiesCallbackData : public WindowCallbackData {
97  public:
99 
100  PUBLISHED:
101  INLINE WindowProperties &get_properties() const;
102 
103  virtual void upcall();
104 
105  private:
106  WindowProperties &_properties;
107 
108  public:
109  static TypeHandle get_class_type() {
110  return _type_handle;
111  }
112  static void init_type() {
113  WindowCallbackData::init_type();
114  register_type(_type_handle, "CallbackGraphicsWindow::PropertiesCallbackData",
115  WindowCallbackData::get_class_type());
116  }
117  virtual TypeHandle get_type() const {
118  return get_class_type();
119  }
120  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
121 
122  private:
123  static TypeHandle _type_handle;
124  };
125 
126  enum RenderCallbackType {
127  RCT_begin_frame,
128  RCT_end_frame,
129  RCT_begin_flip,
130  RCT_end_flip,
131  };
132 
133  class EXPCL_PANDA_DISPLAY RenderCallbackData : public WindowCallbackData {
134  public:
135  INLINE RenderCallbackData(CallbackGraphicsWindow *window, RenderCallbackType callback_type, FrameMode frame_mode);
136 
137  PUBLISHED:
138  INLINE CallbackGraphicsWindow::RenderCallbackType get_callback_type() const;
139  INLINE GraphicsOutput::FrameMode get_frame_mode() const;
140 
141  INLINE void set_render_flag(bool render_flag);
142  INLINE bool get_render_flag() const;
143 
144  virtual void upcall();
145 
146  private:
147  RenderCallbackType _callback_type;
148  FrameMode _frame_mode;
149  bool _render_flag;
150 
151  public:
152  static TypeHandle get_class_type() {
153  return _type_handle;
154  }
155  static void init_type() {
156  WindowCallbackData::init_type();
157  register_type(_type_handle, "CallbackGraphicsWindow::RenderCallbackData",
158  WindowCallbackData::get_class_type());
159  }
160  virtual TypeHandle get_type() const {
161  return get_class_type();
162  }
163  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
164 
165  private:
166  static TypeHandle _type_handle;
167  };
168 
169  INLINE void set_events_callback(CallbackObject *object);
170  INLINE void clear_events_callback();
171  INLINE CallbackObject *get_events_callback() const;
172 
173  INLINE void set_properties_callback(CallbackObject *object);
174  INLINE void clear_properties_callback();
175  INLINE CallbackObject *get_properties_callback() const;
176 
177  INLINE void set_render_callback(CallbackObject *object);
178  INLINE void clear_render_callback();
179  INLINE CallbackObject *get_render_callback() const;
180 
182  int create_input_device(const string &name);
183 
184 public:
185  virtual bool begin_frame(FrameMode mode, Thread *current_thread);
186  virtual void end_frame(FrameMode mode, Thread *current_thread);
187 
188  virtual void begin_flip();
189  virtual void end_flip();
190 
191  virtual void process_events();
192  virtual void set_properties_now(WindowProperties &properties);
193 
194 protected:
195  virtual bool open_window();
196  virtual bool do_reshape_request(int x_origin, int y_origin, bool has_origin,
197  int x_size, int y_size);
198 
199 private:
200  PT(CallbackObject) _events_callback;
201  PT(CallbackObject) _properties_callback;
202  PT(CallbackObject) _render_callback;
203 
204 public:
205  static TypeHandle get_class_type() {
206  return _type_handle;
207  }
208  static void init_type() {
209  GraphicsWindow::init_type();
210  register_type(_type_handle, "CallbackGraphicsWindow",
211  GraphicsWindow::get_class_type());
212  WindowCallbackData::init_type();
213  EventsCallbackData::init_type();
214  PropertiesCallbackData::init_type();
215  RenderCallbackData::init_type();
216  }
217  virtual TypeHandle get_type() const {
218  return get_class_type();
219  }
220  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
221 
222 private:
223  static TypeHandle _type_handle;
224 
225  friend class GraphicsEngine;
226 };
227 
228 #include "callbackGraphicsWindow.I"
229 
230 #endif
void set_events_callback(CallbackObject *object)
Sets the CallbackObject that will be notified when this window is polled for window events...
GraphicsWindowInputDevice & get_input_device(int device)
Returns a writable reference to the nth input device (mouse).
void set_properties_callback(CallbackObject *object)
Sets the CallbackObject that will be notified when this window receives a property change request fro...
virtual void upcall()
You should make this call during the callback if you want to continue the normal function that would ...
virtual void begin_flip()
This function will be called within the draw thread after end_frame() has been called on all windows...
CallbackObject * get_render_callback() const
Returns the CallbackObject set by set_render_callback().
This is a generic data block that is passed along to a CallbackObject when a callback is made...
Definition: callbackData.h:32
CallbackObject * get_properties_callback() const
Returns the CallbackObject set by set_properties_callback().
const WindowProperties get_properties() const
Returns the current properties of the window.
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
void clear_render_callback()
Removes the callback set by an earlier call to set_render_callback().
CallbackObject * get_events_callback() const
Returns the CallbackObject set by set_events_callback().
void clear_events_callback()
Removes the callback set by an earlier call to set_events_callback().
A container for the various kinds of properties we might ask to have on a graphics window before we o...
This special window object doesn't represent a window in its own right, but instead hooks into some t...
virtual void process_events()
Do whatever processing is necessary to ensure that the window responds to user events.
int create_input_device(const string &name)
Adds a new input device (mouse) to the window with the indicated name.
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
This is a structure representing a single input device that may be associated with a window...
This is a generic object that can be assigned to a callback at various points in the rendering proces...
virtual void set_properties_now(WindowProperties &properties)
Applies the requested set of properties to the window, if possible, for instance to request a change ...
A thread; that is, a lightweight process.
Definition: thread.h:51
void set_render_callback(CallbackObject *object)
Sets the CallbackObject that will be notified when this window is invoked (in the draw thread) to ren...
Encapsulates all the communication with a particular instance of a given rendering backend...
virtual bool begin_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread before beginning rendering for a given frame...
virtual void end_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread after rendering is completed for a given frame...
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual void end_flip()
This function will be called within the draw thread after begin_flip() has been called on all windows...
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
void clear_properties_callback()
Removes the callback set by an earlier call to set_properties_callback().