Panda3D

callbackGraphicsWindow.h

00001 // Filename: callbackGraphicsWindow.h
00002 // Created by:  drose (06Jan11)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef CALLBACKGRAPHICSWINDOW_H
00016 #define CALLBACKGRAPHICSWINDOW_H
00017 
00018 #include "pandabase.h"
00019 #include "graphicsWindow.h"
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //       Class : CallbackGraphicsWindow
00023 // Description : This special window object doesn't represent a window
00024 //               in its own right, but instead hooks into some
00025 //               third-party API for creating and rendering to windows
00026 //               via callbacks.  This can be used to allow Panda to
00027 //               render into an already-created OpenGL context, for
00028 //               instance.
00029 ////////////////////////////////////////////////////////////////////
00030 class EXPCL_PANDA_DISPLAY CallbackGraphicsWindow : public GraphicsWindow {
00031 protected:
00032   CallbackGraphicsWindow(GraphicsEngine *engine,
00033                          GraphicsPipe *pipe, 
00034                          const string &name,
00035                          const FrameBufferProperties &fb_prop,
00036                          const WindowProperties &win_prop,
00037                          int flags,
00038                          GraphicsStateGuardian *gsg);
00039 
00040 PUBLISHED:
00041   virtual ~CallbackGraphicsWindow();
00042 
00043   class WindowCallbackData : public CallbackData {
00044   public:
00045     INLINE WindowCallbackData(CallbackGraphicsWindow *window);
00046 
00047   PUBLISHED:
00048     INLINE CallbackGraphicsWindow *get_window() const;
00049     
00050   protected:
00051     PT(CallbackGraphicsWindow) _window;
00052     
00053   public:
00054     static TypeHandle get_class_type() {
00055       return _type_handle;
00056     }
00057     static void init_type() {
00058       CallbackData::init_type();
00059       register_type(_type_handle, "CallbackGraphicsWindow::WindowCallbackData",
00060                     CallbackData::get_class_type());
00061     }
00062     virtual TypeHandle get_type() const {
00063       return get_class_type();
00064     }
00065     virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00066     
00067   private:
00068     static TypeHandle _type_handle;
00069   };
00070 
00071 
00072   class EventsCallbackData : public WindowCallbackData {
00073   public:
00074     INLINE EventsCallbackData(CallbackGraphicsWindow *window);
00075 
00076   PUBLISHED:
00077     virtual void upcall();
00078     
00079   public:
00080     static TypeHandle get_class_type() {
00081       return _type_handle;
00082     }
00083     static void init_type() {
00084       WindowCallbackData::init_type();
00085       register_type(_type_handle, "CallbackGraphicsWindow::EventsCallbackData",
00086                     WindowCallbackData::get_class_type());
00087     }
00088     virtual TypeHandle get_type() const {
00089       return get_class_type();
00090     }
00091     virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00092     
00093   private:
00094     static TypeHandle _type_handle;
00095   };
00096 
00097   class PropertiesCallbackData : public WindowCallbackData {
00098   public:
00099     INLINE PropertiesCallbackData(CallbackGraphicsWindow *window, WindowProperties &properties);
00100 
00101   PUBLISHED:
00102     INLINE WindowProperties &get_properties() const;
00103 
00104     virtual void upcall();
00105 
00106   private:
00107     WindowProperties &_properties;
00108     
00109   public:
00110     static TypeHandle get_class_type() {
00111       return _type_handle;
00112     }
00113     static void init_type() {
00114       WindowCallbackData::init_type();
00115       register_type(_type_handle, "CallbackGraphicsWindow::PropertiesCallbackData",
00116                     WindowCallbackData::get_class_type());
00117     }
00118     virtual TypeHandle get_type() const {
00119       return get_class_type();
00120     }
00121     virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00122     
00123   private:
00124     static TypeHandle _type_handle;
00125   };
00126 
00127   enum RenderCallbackType {
00128     RCT_begin_frame,
00129     RCT_end_frame,
00130     RCT_begin_flip,
00131     RCT_end_flip,
00132   };
00133 
00134   class RenderCallbackData : public WindowCallbackData {
00135   public:
00136     INLINE RenderCallbackData(CallbackGraphicsWindow *window, RenderCallbackType callback_type, FrameMode frame_mode);
00137 
00138   PUBLISHED:
00139     INLINE CallbackGraphicsWindow::RenderCallbackType get_callback_type() const;
00140     INLINE GraphicsOutput::FrameMode get_frame_mode() const;
00141 
00142     INLINE void set_render_flag(bool render_flag);
00143     INLINE bool get_render_flag() const;
00144 
00145     virtual void upcall();
00146 
00147   private:
00148     RenderCallbackType _callback_type;
00149     FrameMode _frame_mode;
00150     bool _render_flag;
00151     
00152   public:
00153     static TypeHandle get_class_type() {
00154       return _type_handle;
00155     }
00156     static void init_type() {
00157       WindowCallbackData::init_type();
00158       register_type(_type_handle, "CallbackGraphicsWindow::RenderCallbackData",
00159                     WindowCallbackData::get_class_type());
00160     }
00161     virtual TypeHandle get_type() const {
00162       return get_class_type();
00163     }
00164     virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00165     
00166   private:
00167     static TypeHandle _type_handle;
00168   };
00169   
00170   INLINE void set_events_callback(CallbackObject *object);
00171   INLINE void clear_events_callback();
00172   INLINE CallbackObject *get_events_callback() const;
00173 
00174   INLINE void set_properties_callback(CallbackObject *object);
00175   INLINE void clear_properties_callback();
00176   INLINE CallbackObject *get_properties_callback() const;
00177 
00178   INLINE void set_render_callback(CallbackObject *object);
00179   INLINE void clear_render_callback();
00180   INLINE CallbackObject *get_render_callback() const;
00181 
00182   GraphicsWindowInputDevice &get_input_device(int device);
00183   int create_input_device(const string &name);
00184 
00185 public:
00186   virtual bool begin_frame(FrameMode mode, Thread *current_thread);
00187   virtual void end_frame(FrameMode mode, Thread *current_thread);
00188 
00189   virtual void begin_flip();
00190   virtual void end_flip();
00191 
00192   virtual void process_events();
00193   virtual void set_properties_now(WindowProperties &properties);
00194 
00195 protected:
00196   virtual bool open_window();
00197   virtual bool do_reshape_request(int x_origin, int y_origin, bool has_origin,
00198                                   int x_size, int y_size);
00199 
00200 private:
00201   PT(CallbackObject) _events_callback;
00202   PT(CallbackObject) _properties_callback;
00203   PT(CallbackObject) _render_callback;
00204 
00205 public:
00206   static TypeHandle get_class_type() {
00207     return _type_handle;
00208   }
00209   static void init_type() {
00210     GraphicsWindow::init_type();
00211     register_type(_type_handle, "CallbackGraphicsWindow",
00212                   GraphicsWindow::get_class_type());
00213     WindowCallbackData::init_type();
00214     EventsCallbackData::init_type();
00215     PropertiesCallbackData::init_type();
00216     RenderCallbackData::init_type();
00217   }
00218   virtual TypeHandle get_type() const {
00219     return get_class_type();
00220   }
00221   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00222 
00223 private:
00224   static TypeHandle _type_handle;
00225 
00226   friend class GraphicsEngine;
00227 };
00228 
00229 #include "callbackGraphicsWindow.I"
00230 
00231 #endif
 All Classes Functions Variables Enumerations