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/ShaderObject.h
00001 #pragma once
00002 #ifndef SHADER_OBJECT_H
00003 #define SHADER_OBJECT_H
00004 
00005 #include <UniShader/Config.h>
00006 #include <UniShader/Utility.h>
00007 #include <UniShader/ObjectBase.h>
00008 #include <UniShader/Signal.h>
00009 
00010 #include <memory>
00011 #include <string>
00012 
00013 UNISHADER_BEGIN
00014 
00016 
00026 class UniShader_API ShaderObject : public SignalSender, public ObjectBase{
00027 private:
00028         ShaderObject();
00029 
00030 public:
00031         typedef std::shared_ptr<ShaderObject> Ptr; 
00032         typedef std::shared_ptr<const ShaderObject> PtrConst; 
00033         virtual const std::string& getClassName() const; 
00034         ~ShaderObject();
00035 
00037         class Type{
00038         public:
00039                 enum myEnum{NONE, 
00040                                         VERTEX, 
00041                                         GEOMETRY, 
00042                                         FRAGMENT, 
00043                                         UNRECOGNIZED 
00044                 };
00045         private:
00046                 myEnum m_en;
00047         public:
00048                 Type(){}
00049                 Type(const Type& ref):m_en(ref.m_en){}
00050                 Type(myEnum en){ m_en = en; }
00051                 Type& operator =(myEnum en){ m_en = en; return *this; }
00052                 operator myEnum(){ return m_en; }
00053         };
00054 
00056         class CompilationStatus{
00057         public:
00058                 enum myEnum{PENDING_COMPILATION, 
00059                                         SUCCESSFUL_COMPILATION, 
00060                                         FAILED_COMPILATION 
00061                 };
00062         private:
00063                 myEnum m_en;
00064         public:
00065                 CompilationStatus(){}
00066                 CompilationStatus(const CompilationStatus& ref):m_en(ref.m_en){}
00067                 CompilationStatus(myEnum en){ m_en = en; }
00068                 CompilationStatus& operator =(myEnum en){ m_en = en; return *this; }
00069                 operator myEnum(){ return m_en; }
00070         };
00071         
00073 
00076         class SignalID{
00077         public:
00078                 enum Types{     CHANGED, 
00079                                         RECOMPILED 
00080                 }; 
00081         };
00082 
00084 
00087         static Ptr create();
00088 
00090 
00095         bool loadFile(const std::string fileName, Type shaderType = Type::NONE);
00096 
00098 
00103         bool loadCode(const std::string code, Type shaderType);
00104 
00106         /*
00107                 Compile shader object if needed.
00108                 \return True if shader object is successfully compiled.
00109         */
00110         bool ensureCompilation();
00111         
00113 
00116         unsigned int getGlID() const;
00117 
00119 
00122         Type getType() const;
00123 
00125 
00128         CompilationStatus getCompilationStatus() const;
00129 
00130 private:
00131         bool compile();
00132         bool printShaderInfoLog() const;
00133         int getShaderSize(const std::string &shaderName) const;
00134         bool readShaderSource(const std::string& fileName, std::string& shaderText);
00135         bool translateLiterals(std::string &shaderText);
00136 
00137         unsigned int m_shaderObjectID;
00138         Type m_type;
00139         CompilationStatus m_compilationStatus;
00140 };
00141 
00142 UNISHADER_END
00143 
00144 #endif