TensorArray.hpp

00001 #ifndef TENSOR_ARRAY_HPP
00002 #define TENSOR_ARRAY_HPP
00003 
00004 #include <ocean/plankton/VCreator.hpp>
00005 #include <ocean/shrimp/VEnum.hpp>
00006 
00007 #include <GL/fieldGL.hpp>
00008 #include <eye/retina/SplatRenderObject.hpp>
00009 #include <ocean/GLvish/BufferArray.hpp>
00010 
00011 namespace Wizt
00012 {
00013 
00014 using namespace Fiber;
00015 using namespace Eagle;
00016 
00017 
00019 struct  TensorIDs
00020 {
00021         int     xx_xy_yy,
00022                 xz_yz_zz;
00023 };
00024 
00031 template <class Type>
00032 class   TensorArray : public BufferArray
00033 {
00034 public: 
00035         typedef Type                            value_type;
00036         typedef typename Type::value_type       etype;
00037         typedef BufferArray                     Base_t;
00038 
00039         TensorIDs       index;
00040 
00041         TensorArray(const TensorIDs&IDs)
00042         : index(IDs)
00043         {}
00044 
00045         override bool enable() const
00046         {
00047         GLboolean       normalized = false;
00048                 GLVERIFY( glVertexAttribPointer( index.xx_xy_yy, 3, glType<etype>::type, normalized, sizeof(Type), 0) ); 
00049                 GLVERIFY( glVertexAttribPointer( index.xz_yz_zz, 3, glType<etype>::type, normalized, sizeof(Type), (char*)(0) + 3*sizeof(etype) ) ); 
00050                 GLVERIFY( glEnableVertexAttribArray( index.xx_xy_yy ) );
00051                 GLVERIFY( glEnableVertexAttribArray( index.xz_yz_zz ) );
00052                 return true;
00053         }
00054 
00055         override bool disable() const
00056         {
00057                 glDisableVertexAttribArray( index.xx_xy_yy ); 
00058                 glDisableVertexAttribArray( index.xz_yz_zz );
00059                 return true;
00060         }
00061 };
00062 
00063 
00067 class   VBOTensorField : public VertexField
00068 {
00069 public:
00070         typedef TensorArray<Eagle::metric33>    VBOArrayType;
00071         typedef VBOArrayType::value_type        value_type;
00072 
00073         VBOTensorField(VObject*that, const string&fieldname);
00074 
00075         ~VBOTensorField();
00076 
00077         override RefPtr<BufferArray> createVBOArray(const RefPtr<Fiber::MemBase>&MB,
00078                                                     const string&arrayname,
00079                                                     const RefPtr<GLProgram>&Shader,
00080                                                     const Fiber::MemBase::Creator_t&theCreator) const;
00081 };
00082 
00083 } // namespace Wizt
00084 
00085 #endif // TENSOR_ARRAY_HPP
00086 
00087 
00088 
00089