Panda3D
Loading...
Searching...
No Matches
callbackGraphicsWindow.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file callbackGraphicsWindow.h
10 * @author drose
11 * @date 2011-01-06
12 */
13
14#ifndef CALLBACKGRAPHICSWINDOW_H
15#define CALLBACKGRAPHICSWINDOW_H
16
17#include "pandabase.h"
18#include "graphicsWindow.h"
19
20/**
21 * This special window object doesn't represent a window in its own right, but
22 * instead hooks into some third-party API for creating and rendering to
23 * windows via callbacks. This can be used to allow Panda to render into an
24 * already-created OpenGL context, for instance.
25 */
26class EXPCL_PANDA_DISPLAY CallbackGraphicsWindow : public GraphicsWindow {
27protected:
29 GraphicsPipe *pipe,
30 const std::string &name,
31 const FrameBufferProperties &fb_prop,
32 const WindowProperties &win_prop,
33 int flags,
35
36PUBLISHED:
38
39 class EXPCL_PANDA_DISPLAY WindowCallbackData : public CallbackData {
40 public:
42
43 PUBLISHED:
44 INLINE CallbackGraphicsWindow *get_window() const;
45 MAKE_PROPERTY(window, get_window);
46
47 protected:
48 PT(CallbackGraphicsWindow) _window;
49
50 public:
51 static TypeHandle get_class_type() {
52 return _type_handle;
53 }
54 static void init_type() {
55 CallbackData::init_type();
56 register_type(_type_handle, "CallbackGraphicsWindow::WindowCallbackData",
57 CallbackData::get_class_type());
58 }
59 virtual TypeHandle get_type() const {
60 return get_class_type();
61 }
62 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
63
64 private:
65 static TypeHandle _type_handle;
66 };
67
68 class EXPCL_PANDA_DISPLAY EventsCallbackData : public WindowCallbackData {
69 public:
71
72 PUBLISHED:
73 virtual void upcall();
74
75 public:
76 static TypeHandle get_class_type() {
77 return _type_handle;
78 }
79 static void init_type() {
80 WindowCallbackData::init_type();
81 register_type(_type_handle, "CallbackGraphicsWindow::EventsCallbackData",
82 WindowCallbackData::get_class_type());
83 }
84 virtual TypeHandle get_type() const {
85 return get_class_type();
86 }
87 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
88
89 private:
90 static TypeHandle _type_handle;
91 };
92
93 class EXPCL_PANDA_DISPLAY PropertiesCallbackData : public WindowCallbackData {
94 public:
96
97 PUBLISHED:
98 INLINE WindowProperties &get_properties() const;
99
100 virtual void upcall();
101
102 private:
103 WindowProperties &_properties;
104
105 public:
106 static TypeHandle get_class_type() {
107 return _type_handle;
108 }
109 static void init_type() {
110 WindowCallbackData::init_type();
111 register_type(_type_handle, "CallbackGraphicsWindow::PropertiesCallbackData",
112 WindowCallbackData::get_class_type());
113 }
114 virtual TypeHandle get_type() const {
115 return get_class_type();
116 }
117 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
118
119 private:
120 static TypeHandle _type_handle;
121 };
122
123 enum RenderCallbackType {
124 RCT_begin_frame,
125 RCT_end_frame,
126 RCT_begin_flip,
127 RCT_end_flip,
128 };
129
130 class EXPCL_PANDA_DISPLAY RenderCallbackData : public WindowCallbackData {
131 public:
132 INLINE RenderCallbackData(CallbackGraphicsWindow *window, RenderCallbackType callback_type, FrameMode frame_mode);
133
134 PUBLISHED:
135 INLINE CallbackGraphicsWindow::RenderCallbackType get_callback_type() const;
136 INLINE GraphicsOutput::FrameMode get_frame_mode() const;
137 MAKE_PROPERTY(callback_type, get_callback_type);
138 MAKE_PROPERTY(frame_mode, get_frame_mode);
139
140 INLINE void set_render_flag(bool render_flag);
141 INLINE bool get_render_flag() const;
142 MAKE_PROPERTY(render_flag, get_render_flag, set_render_flag);
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
181 int create_input_device(const std::string &name);
182
183public:
184 virtual bool begin_frame(FrameMode mode, Thread *current_thread);
185 virtual void end_frame(FrameMode mode, Thread *current_thread);
186
187 virtual void begin_flip();
188 virtual void end_flip();
189
190 virtual void process_events();
191 virtual void set_properties_now(WindowProperties &properties);
192
193protected:
194 virtual bool open_window();
195 virtual bool do_reshape_request(int x_origin, int y_origin, bool has_origin,
196 int x_size, int y_size);
197
198private:
199 PT(CallbackObject) _events_callback;
200 PT(CallbackObject) _properties_callback;
201 PT(CallbackObject) _render_callback;
202
203public:
204 static TypeHandle get_class_type() {
205 return _type_handle;
206 }
207 static void init_type() {
208 GraphicsWindow::init_type();
209 register_type(_type_handle, "CallbackGraphicsWindow",
210 GraphicsWindow::get_class_type());
211 WindowCallbackData::init_type();
212 EventsCallbackData::init_type();
213 PropertiesCallbackData::init_type();
214 RenderCallbackData::init_type();
215 }
216 virtual TypeHandle get_type() const {
217 return get_class_type();
218 }
219 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
220
221private:
222 static TypeHandle _type_handle;
223
224 friend class GraphicsEngine;
225};
226
228
229#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a generic data block that is passed along to a CallbackObject when a callback is made.
This special window object doesn't represent a window in its own right, but instead hooks into some t...
This is a generic object that can be assigned to a callback at various points in the rendering proces...
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
This class is the main interface to controlling the render process.
virtual void begin_flip()
This function will be called within the draw thread after end_frame() has been called on all windows,...
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.
virtual void end_flip()
This function will be called within the draw thread after begin_flip() has been called on all windows...
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.
An object to create GraphicsOutputs that share a particular 3-D API.
Encapsulates all the communication with a particular instance of a given rendering backend.
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
get_properties
Returns the current properties of the window.
virtual void process_events()
Do whatever processing is necessary to ensure that the window responds to user events.
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:46
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
A container for the various kinds of properties we might ask to have on a graphics window before we o...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...