UniShader  1.0.0a
Interface for GPGPU and working with shader programs
 All Classes Functions Typedefs Enumerations Enumerator
D:/Visual Studio 2010/Projects/Unishader project/Unishader/include/UniShader/Attribute.h
00001 #pragma once
00002 #ifndef ATTRIBUTE_H
00003 #define ATTRIBUTE_H
00004 
00005 #include <UniShader/Config.h>
00006 #include <UniShader/Utility.h>
00007 #include <UniShader/ObjectBase.h>
00008 #include <UniShader/SafePtr.h>
00009 #include <UniShader/Signal.h>
00010 #include <UniShader/Buffer.h>
00011 #include <UniShader/GLSLType.h>
00012 
00013 #include <string>
00014 
00015 UNISHADER_BEGIN
00016 
00017 class ShaderProgram;
00018 
00020 
00029 class UniShader_API Attribute : public SignalSender, public SignalReceiver, public ObjectBase{
00030 public:
00031         Attribute(ShaderProgram& program, std::string name);
00032         typedef SafePtr<Attribute> Ptr; 
00033         typedef SafePtr<const Attribute> PtrConst; 
00034         virtual const std::string& getClassName() const; 
00035         ~Attribute();
00036 
00038 
00041         class ReadingMode{
00042         public:
00043                 enum myEnum{NONE, 
00044                                         CHAR, 
00045                                         UNSIGNED_CHAR, 
00046                                         SHORT, 
00047                                         UNSIGNED_SHORT, 
00048                                         INT, 
00049                                         UNSIGNED_INT, 
00050                                         FLOAT, 
00051                                         DOUBLE 
00052                 };
00053         private:
00054                 myEnum m_en;
00055         public:
00056                 ReadingMode(){}
00057                 ReadingMode(const ReadingMode& ref):m_en(ref.m_en){}
00058                 ReadingMode(myEnum en){ m_en = en; }
00059                 ReadingMode& operator =(myEnum en){ m_en = en; return *this; }
00060                 operator myEnum(){ return m_en; }
00061         };
00062 
00064 
00067         class SignalID{
00068         public:
00069                 enum Types{CHANGED 
00070                 }; 
00071         };
00072 
00074 
00080         void connectBuffer(BufferBase::Ptr buffer, unsigned int offset = 0, unsigned int stride = 0);
00081 
00083 
00086         void disconnectBuffer();
00087 
00089 
00093         void normalize(bool norm);
00094 
00096 
00099         unsigned int getBufferOffset() const;
00100 
00102 
00105         unsigned int getBufferStride() const;
00106 
00108 
00111         const GLSLType& getGLSLType() const;
00112 
00114 
00117         ReadingMode getReadingMode() const;
00118 
00120 
00123         std::string getName() const;
00124         
00126 
00129         void setBufferOffset(unsigned int offset);
00130 
00132 
00135         void setBufferStride(unsigned int stride);
00136 
00138 
00141         void setReadingMode(ReadingMode readingMode);
00142         
00144 
00148         bool prepare();
00149 
00151 
00154         void apply();
00155 
00157 
00162         virtual bool handleSignal(unsigned int signalID, const ObjectBase* callerPtr);
00163 private:
00164         ShaderProgram& m_program;
00165         BufferBase::Ptr m_buffer;
00166         GLSLType m_type;
00167         std::string m_name;
00168         int m_location;
00169         unsigned int m_offset;
00170         unsigned int m_stride;
00171         ReadingMode m_readingMode;
00172         bool m_normalize;
00173         bool m_prepared;
00174 };
00175 
00176 UNISHADER_END
00177 
00178 #endif