| | 33 | /** Simple class for wrapping up the data used in OpenGL ES 2's glShaderBinary calls. |
| | 34 | * ShaderBinary is set up with the binary data then assigned to one or more osg::Shader. */ |
| | 35 | class OSG_EXPORT ShaderBinary : public osg::Object |
| | 36 | { |
| | 37 | public: |
| | 38 | |
| | 39 | ShaderBinary(); |
| | 40 | |
| | 41 | /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ |
| | 42 | ShaderBinary(const ShaderBinary& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); |
| | 43 | |
| | 44 | META_Object(osg, ShaderBinary); |
| | 45 | |
| | 46 | /** Allocated a data buffer of specified size/*/ |
| | 47 | void allocate(unsigned int size); |
| | 48 | |
| | 49 | /** Assign shader binary data, copying the specified data into locally stored data buffer, the original data can then be deleted.*/ |
| | 50 | void assign(unsigned int size, const unsigned char* data); |
| | 51 | |
| | 52 | /** Get the size of the shader binary data.*/ |
| | 53 | unsigned int getSize() const { return _data.size(); } |
| | 54 | |
| | 55 | /** Get a ptr to the shader binary data.*/ |
| | 56 | unsigned char* getData() { return _data.empty() ? 0 : &(_data.front()); } |
| | 57 | |
| | 58 | /** Get a const ptr to the shader binary data.*/ |
| | 59 | const unsigned char* getData() const { return _data.empty() ? 0 : &(_data.front()); } |
| | 60 | |
| | 61 | protected: |
| | 62 | |
| | 63 | typedef std::vector<unsigned char> Data; |
| | 64 | Data _data; |
| | 65 | }; |
| | 66 | |
| | 67 | |
| 64 | | bool setType( Type t ); |
| 65 | | |
| 66 | | |
| 67 | | /** Load the Shader's source code text from a string. */ |
| 68 | | void setShaderSource( const std::string& sourceText ); |
| | 100 | /** Set the Shader type as an enum. */ |
| | 101 | bool setType(Type t); |
| | 102 | |
| | 103 | /** Get the Shader type as an enum. */ |
| | 104 | inline Type getType() const { return _type; } |
| | 105 | |
| | 106 | /** Get the Shader type as a descriptive string. */ |
| | 107 | const char* getTypename() const; |
| | 108 | |
| | 109 | |
| | 110 | /** Set file name for the shader source code. */ |
| | 111 | inline void setFileName(const std::string& fileName) { _shaderFileName = fileName; } |
| | 112 | |
| | 113 | /** Get filename to which the shader source code belongs. */ |
| | 114 | inline const std::string& getFileName() const { return _shaderFileName; } |
| | 115 | |
| | 116 | |
| | 117 | /** Set the Shader's source code text from a string. */ |
| | 118 | void setShaderSource(const std::string& sourceText); |
| | 119 | |
| | 120 | /** Query the shader's source code text */ |
| | 121 | inline const std::string& getShaderSource() const { return _shaderSource; } |
| | 122 | |
| | 123 | |
| | 124 | /** Set the Shader using a ShaderBinary. */ |
| | 125 | void setShaderBinary(ShaderBinary* shaderBinary) { _shaderBinary = shaderBinary; } |
| | 126 | |
| | 127 | /** Get the Shader's ShaderBinary, return NULL if none is assigned. */ |
| | 128 | ShaderBinary* getShaderBinary() { return _shaderBinary.get(); } |
| | 129 | |
| | 130 | /** Get the const Shader's ShaderBinary, return NULL if none is assigned. */ |
| | 131 | const ShaderBinary* getShaderBinary() const { return _shaderBinary.get(); } |
| | 132 | |
| 77 | | /** Query the shader's source code text */ |
| 78 | | inline const std::string& getShaderSource() const { return _shaderSource; } |
| 79 | | |
| 80 | | /** Get the Shader type as an enum. */ |
| 81 | | inline Type getType() const { return _type; } |
| 82 | | |
| 83 | | /** Get the Shader type as a descriptive string. */ |
| 84 | | const char* getTypename() const; |
| 85 | | |
| 86 | | /** Set file name for the shader source code. */ |
| 87 | | inline void setFileName(const std::string& fileName) { _shaderFileName = fileName; } |
| 88 | | |
| 89 | | /** Get filename to which the shader source code belongs. */ |
| 90 | | inline const std::string& getFileName() const { return _shaderFileName; } |
| | 141 | |