LightWrap++
AC++wrapperfortheLightWave3DSDK
texture_handler.h
Go to the documentation of this file.
1 
7 #ifndef LWPP_PROCEDURAL_TEXTURE_HANDLER
8 #define LWPP_PROCEDURAL_TEXTURE_HANDLER
9 #include "lwpp/plugin_handler.h"
10 #include <lwtexture.h>
11 
12 namespace lwpp
13 {
15 
20 {
21  protected:
22  LWTLayerID Context;
23  public:
24  TextureHandler(void *g, void *context, LWError *err) : InstanceHandler(g, context, err, LWTEXTURE_HCLASS)
25  {
26  Context = static_cast<LWTLayerID>(context) ;
27  }
28  virtual ~TextureHandler() {;}
29  virtual double Evaluate(LWTextureAccess *ta) {UNUSED(ta); return 0;}
30  virtual unsigned int Flags() {return 0;}
31 };
32 
34 
37  template <class T, int maxVersion, int minVersion>
38  class TextureAdaptor : public InstanceAdaptor <T>, public ItemAdaptor <T>, public RenderAdaptor <T>
39  {
40  public:
41  TextureAdaptor(const char *name, ServerTagInfo *tags)
42  {
43  LWServer::AddPlugin(LWTEXTURE_HCLASS, name, Activate, tags);
44  }
46  static int Activate (int version, GlobalFunc *global, LWInstance inst, void *serverData)
47  {
48  UNUSED(serverData);
49  if ( version > maxVersion ) return AFUNC_BADVERSION;
50  if ( version < minVersion ) return AFUNC_BADVERSION;
51  lwpp::SetSuperGlobal(global);
52  LWTextureHandler *plugin = static_cast<LWTextureHandler *>(inst);
53 
54  InstanceAdaptor<T>::Activate(plugin->inst);
55  ItemAdaptor<T>::Activate(plugin->item);
56  RenderAdaptor<T>::Activate(plugin->rend);
57  plugin->evaluate = TextureAdaptor::Evaluate;
58  plugin->flags = TextureAdaptor::Flags;
59  return AFUNC_OK;
60  }
61  private:
62  static double Evaluate (LWInstance instance, LWTextureAccess *ta)
63  {
64  try
65  {
66  T *plugin = (T *) instance;
67  return plugin->Evaluate(ta);
68  }
69  catch (std::exception &e)
70  {
71  lwpp::LWMessage::Error("An exception occured in TextureHandler::Evaluate():", e.what());
72  return 0.0;
73  }
74  }
75 
76  static unsigned int Flags (LWInstance instance)
77  {
78  try
79  {
80  T *plugin = (T *) instance;
81  return plugin->Flags();
82  }
83  catch (std::exception &e)
84  {
85  lwpp::LWMessage::Error("An exception occured in TextureHandler::Flags():", e.what());
86  return 0;
87  }
88  }
89  };
90 
96 }
97 
98 #endif // LWPP_PROCEDURAL_TEXTURE_HANDLER