LightWrap++
AC++wrapperfortheLightWave3DSDK
framebuffer_handler.h
Go to the documentation of this file.
1 #ifndef LWPP_FRAMEBUFFER_HANDLER_H
2 #define LWPP_FRAMEBUFFER_HANDLER_H
3 
4 #include "lwpp/plugin_handler.h"
5 #include <lwframbuf.h>
6 
7 namespace lwpp
8 {
11  {
12  public:
13  FrameBufferHandler(void* g, void* context, LWError* err)
14  : InstanceHandler(g,context,err, LWFRAMEBUFFER_HCLASS)
15  {
16  ;
17  }
18  virtual ~FrameBufferHandler() {;}
19 
20  virtual LWError Open (int w, int h)
21  {
22  return 0;
23  }
24 
25  virtual void Close ()
26  {
27  ;
28  }
29 
30  virtual LWError Begin ()
31  {
32  return 0;
33  }
34 
35  virtual LWError Write (const void *R, const void *G, const void *B, const void *alpha)
36  {
37  return 0;
38  }
39 
40  virtual void Pause ()
41  {
42  ;
43  }
44  };
45 
47  template <class T, int FBType=LWFBT_FLOAT>
48  class FrameBufferAdaptor : public InstanceAdaptor <T>, public ItemAdaptor <T>
49  {
50  public:
51  FrameBufferAdaptor(const char *name, ServerTagInfo *tags)
52  {
53  LWServer::AddPlugin(LWFRAMEBUFFER_HCLASS, name, Activate, tags);
54  }
55  static int Activate (int version , GlobalFunc* global, LWInstance inst, void* serverData)
56  {
57  if(version!=LWFRAMEBUFFER_VERSION) return AFUNC_BADVERSION;
58  lwpp::SetSuperGlobal(global);
59 
60  LWFrameBufferHandler* plugin = static_cast<LWFrameBufferHandler*>(inst);
61  InstanceAdaptor<T>::Activate(plugin->inst);
62  ItemAdaptor<T>::Activate(plugin->item);
63 
64  plugin->type = FBType;
65  plugin->open = FrameBufferAdaptor::Open;
66  plugin->close = FrameBufferAdaptor::Close;
67  plugin->begin = FrameBufferAdaptor::Begin;
68  plugin->write = FrameBufferAdaptor::Write;
69  plugin->pause = FrameBufferAdaptor::Pause;
70 
71 
72  UNUSED(serverData);
73  return AFUNC_OK;
74  }
75 
76  private:
77  static LWError Open (LWInstance inst, int w, int h)
78  {
79  T* plugin = static_cast<T*>(inst);
80  return plugin->Open(w,h);
81  }
82 
83  static void Close (LWInstance inst)
84  {
85  T* plugin = static_cast<T*>(inst);
86  plugin->Close();
87  }
88 
89  static LWError Begin (LWInstance inst)
90  {
91  T* plugin = static_cast<T*>(inst);
92  return plugin->Begin();
93  }
94  static LWError Write (LWInstance inst, const void *R, const void *G, const void *B, const void *alpha)
95  {
96  T* plugin = static_cast<T*>(inst);
97  return plugin->Write(R,G,B,alpha);
98  }
99  static void Pause (LWInstance inst)
100  {
101  T* plugin = static_cast<T*>(inst);
102  plugin->Pause();
103  }
104  };
105 
106 }
107 #endif //LWPP_FRAMEBUFFER_HANDLER_H