LightWrap++
AC++wrapperfortheLightWave3DSDK
pixelfilter_handler.h
Go to the documentation of this file.
1 #ifndef LWPP_PIXELFILTER_HANDLER_H
2 #define LWPP_PIXELFILTER_HANDLER_H
3 
5 
6 namespace lwpp
7 {
8  namespace lw10
9  {
10  typedef struct st_LWPixelFilterHandler {
11  LWInstanceFuncs *inst;
12  LWItemFuncs *item;
13  LWRenderFuncs *rend;
14  void (*evaluate) (LWInstance, const LWPixelAccess *);
15  int * (*flags) (LWInstance);
16  unsigned int (*renderFlags) (LWInstance);
18  }
19 
20  enum {
25  };
28  {
29  protected:
32  public:
33  PixelFilterHandler(void* g, void* context, LWError* err)
34  : InstanceHandler(g,context,err, LWPIXELFILTER_HCLASS),
36  {;}
38  {
39  ;
40  }
41 
42  virtual void Evaluate(const LWPixelAccess *pfa)
43  {
44  float rgba[4];
45  pfa->getVal(LWBUF::RED,4,rgba);
46  pfa->setRGBA(rgba);
47  }
48  virtual unsigned int Flags9()
49  {
50  m_bufferSet.clear(); // clear the set of used buffers
51  UpdateFlags(); // update the set of used buffers
52  unsigned int flag = 0;
53  for (BufferSet::iterator iter = m_bufferSet.begin(); iter != m_bufferSet.end(); ++iter)
54  {
55  if (*iter < LWBUF_BACKDROP_GREEN) flag |= 1 << (*iter);
56  }
57  return flag | Flags();
58  }
59  virtual unsigned int Flags()
60  {
61  return 0;
62  }
63 
64  virtual void UpdateFlags() {;} // Used by LW 10 and higher, update m_bufferSet
65  int *Flags10()
66  {
67  m_bufferSet.clear(); // clear the set of used buffers
68  //m_bufferSet.insert(LWBUF::RED);
69  //m_bufferSet.insert(LWBUF::GREEN);
70  //m_bufferSet.insert(LWBUF::BLUE);
71  //m_bufferSet.insert(LWBUF::ALPHA);
72  UpdateFlags(); // update the set of used buffers
73  if (m_bufferReturn) delete[] m_bufferReturn;
74  m_bufferReturn = new int[m_bufferSet.size()+1];
75  int *idx = m_bufferReturn;
76  *idx++ = static_cast<int>(m_bufferSet.size()); // store the number of buffers
77  for (BufferSet::iterator iter = m_bufferSet.begin(); iter != m_bufferSet.end(); ++iter)
78  {
79  *idx++ = *iter;
80  }
81  return m_bufferReturn;
82  }
83  };
84 
86  template <class T, int maxVersion, int minVersion>
87  class PixelFilterAdaptor : public InstanceAdaptor <T>, public ItemAdaptor <T> , public RenderAdaptor<T>
88  {
89  public:
90  public:
91  PixelFilterAdaptor(const char *name, ServerTagInfo *tags)
92  {
93  LWServer::AddPlugin(LWPIXELFILTER_HCLASS, name, Activate, tags);
94  }
95  static int Activate (int version , GlobalFunc* global, LWInstance inst, void* serverData)
96  {
97  if ( version > maxVersion ) return AFUNC_BADVERSION;
98  if ( version < minVersion ) return AFUNC_BADVERSION;
99  try
100  {
101  lwpp::SetSuperGlobal(global);
102  if (version < 7)
103  {
104  LWPixelFilterHandler* plugin = static_cast<LWPixelFilterHandler*>(inst);
105  InstanceAdaptor<T>::Activate(plugin->inst);
106  ItemAdaptor<T>::Activate(plugin->item);
107  RenderAdaptor<T>::Activate(plugin->rend);
108 
109  plugin->evaluate = PixelFilterAdaptor::Evaluate;
110  plugin->flags = PixelFilterAdaptor::Flags9;
111  }
112  else
113  {
114  lw10::LWPixelFilterHandler* plugin = static_cast<lw10::LWPixelFilterHandler*>(inst);
118 
119  plugin->evaluate = PixelFilterAdaptor::Evaluate;
120  plugin->renderFlags = PixelFilterAdaptor::Flags;
121  plugin->flags = PixelFilterAdaptor::Flags10;
122  }
123 
124  UNUSED(serverData);
125  return AFUNC_OK;
126  }
127  catch (std::exception &e)
128  {
129  lwpp::LWMessage::Error("An exception occured in PixelFilter::Activate():", e.what());
130  return AFUNC_BADAPP;
131  }
132  }
133  private:
134  static void Evaluate (LWInstance inst, const LWPixelAccess* ma)
135  {
136  T* plugin = static_cast<T*>(inst);
137  plugin->Evaluate(ma);
138  }
139  static unsigned int Flags (LWInstance inst)
140  {
141  T* plugin = static_cast<T*>(inst);
142  return plugin->Flags();
143  }
144  static unsigned int Flags9 (LWInstance inst)
145  {
146  T* plugin = static_cast<T*>(inst);
147  return plugin->Flags9();
148  }
149  static int *Flags10 (LWInstance inst)
150  {
151  T* plugin = static_cast<T*>(inst);
152  return plugin->Flags10();
153  }
154  };
155 
156  /* GUI Classes */
161 
166 }
167 #endif // LWPP_PIXELFILTER_HANDLER_H