00001 #ifndef GLW_RENDERABLE_H 00002 #define GLW_RENDERABLE_H 00003 00004 #include <string> 00005 00006 #include "./object.h" 00007 00008 namespace glw 00009 { 00010 00011 class RenderableArguments : public ObjectArguments 00012 { 00013 public: 00014 00015 typedef ObjectArguments BaseType; 00016 typedef RenderableArguments ThisType; 00017 00018 GLenum format; 00019 00020 RenderableArguments(void) 00021 : BaseType () 00022 , format (GL_RGBA8) 00023 { 00024 ; 00025 } 00026 00027 RenderableArguments(GLenum aFormat) 00028 : BaseType () 00029 , format (aFormat) 00030 { 00031 ; 00032 } 00033 00034 void clear(void) 00035 { 00036 BaseType::clear(); 00037 this->format = GL_RGBA8; 00038 } 00039 }; 00040 00041 class Renderable : public Object 00042 { 00043 friend class Context; 00044 00045 public: 00046 00047 typedef Object BaseType; 00048 typedef Renderable ThisType; 00049 00050 GLenum format(void) const 00051 { 00052 return this->m_format; 00053 } 00054 00055 virtual int imageDimensions (void) const = 0; 00056 virtual bool isArray (void) const = 0; 00057 00058 protected: 00059 00060 GLenum m_format; 00061 00062 Renderable(Context * ctx) 00063 : BaseType (ctx) 00064 , m_format (GL_NONE) 00065 { 00066 ; 00067 } 00068 }; 00069 00070 namespace detail { template <> struct BaseOf <Renderable> { typedef Object Type; }; }; 00071 typedef detail::ObjectSharedPointerTraits <Renderable> ::Type RenderablePtr; 00072 00073 class SafeRenderable : public SafeObject 00074 { 00075 friend class Context; 00076 friend class BoundRenderable; 00077 00078 public: 00079 00080 typedef SafeObject BaseType; 00081 typedef SafeRenderable ThisType; 00082 00083 SafeRenderable(void) 00084 : BaseType() 00085 { 00086 ; 00087 } 00088 00089 GLenum format(void) const 00090 { 00091 return this->object()->format(); 00092 } 00093 00094 int imageDimensions(void) const 00095 { 00096 return this->object()->imageDimensions(); 00097 } 00098 00099 bool isArray(void) const 00100 { 00101 return this->object()->isArray(); 00102 } 00103 00104 protected: 00105 00106 SafeRenderable(const RenderablePtr & renderable) 00107 : BaseType(renderable) 00108 { 00109 ; 00110 } 00111 00112 const RenderablePtr & object(void) const 00113 { 00114 return static_cast<const RenderablePtr &>(BaseType::object()); 00115 } 00116 00117 RenderablePtr & object(void) 00118 { 00119 return static_cast<RenderablePtr &>(BaseType::object()); 00120 } 00121 }; 00122 00123 namespace detail { template <> struct BaseOf <SafeRenderable> { typedef SafeObject Type; }; }; 00124 namespace detail { template <> struct ObjectBase <SafeRenderable> { typedef Renderable Type; }; }; 00125 namespace detail { template <> struct ObjectSafe <Renderable > { typedef SafeRenderable Type; }; }; 00126 typedef detail::ObjectSharedPointerTraits <SafeRenderable> ::Type RenderableHandle; 00127 00128 class RenderableBindingParams : public ObjectBindingParams 00129 { 00130 public: 00131 00132 typedef ObjectBindingParams BaseType; 00133 typedef RenderableBindingParams ThisType; 00134 00135 RenderableBindingParams(void) 00136 : BaseType() 00137 { 00138 ; 00139 } 00140 00141 RenderableBindingParams(GLenum aTarget, GLenum aUnit) 00142 : BaseType(aTarget, aUnit) 00143 { 00144 ; 00145 } 00146 }; 00147 00148 class BoundRenderable : public BoundObject 00149 { 00150 friend class Context; 00151 00152 public: 00153 00154 typedef BoundObject BaseType; 00155 typedef BoundRenderable ThisType; 00156 00157 BoundRenderable(void) 00158 : BaseType() 00159 { 00160 ; 00161 } 00162 00163 const RenderableHandle & handle(void) const 00164 { 00165 return static_cast<const RenderableHandle &>(BaseType::handle()); 00166 } 00167 00168 RenderableHandle & handle(void) 00169 { 00170 return static_cast<RenderableHandle &>(BaseType::handle()); 00171 } 00172 00173 protected: 00174 00175 BoundRenderable(const RenderableHandle & handle, const RenderableBindingParams & params) 00176 : BaseType(handle, params) 00177 { 00178 ; 00179 } 00180 00181 const RenderablePtr & object(void) const 00182 { 00183 return this->handle()->object(); 00184 } 00185 00186 RenderablePtr & object(void) 00187 { 00188 return this->handle()->object(); 00189 } 00190 }; 00191 00192 namespace detail { template <> struct ParamsOf <BoundRenderable> { typedef RenderableBindingParams Type; }; }; 00193 namespace detail { template <> struct BaseOf <BoundRenderable> { typedef BoundObject Type; }; }; 00194 namespace detail { template <> struct ObjectBase <BoundRenderable> { typedef Renderable Type; }; }; 00195 namespace detail { template <> struct ObjectBound <Renderable > { typedef BoundRenderable Type; }; }; 00196 typedef detail::ObjectSharedPointerTraits <BoundRenderable> ::Type BoundRenderableHandle; 00197 00198 }; 00199 00200 #endif // GLW_RENDERABLE_H