Changeset 10766
- Timestamp:
- 11/18/09 12:25:28 (4 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 2 modified
-
include/osg/Shader (modified) (4 diffs)
-
src/osg/Shader.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osg/Shader
r10754 r10766 36 36 { 37 37 public: 38 38 39 39 ShaderBinary(); 40 40 … … 46 46 /** Allocated a data buffer of specified size/*/ 47 47 void allocate(unsigned int size); 48 48 49 49 /** Assign shader binary data, copying the specified data into locally stored data buffer, the original data can then be deleted.*/ 50 50 void assign(unsigned int size, const unsigned char* data); 51 51 52 52 /** Get the size of the shader binary data.*/ 53 53 unsigned int getSize() const { return _data.size(); } … … 58 58 /** Get a const ptr to the shader binary data.*/ 59 59 const unsigned char* getData() const { return _data.empty() ? 0 : &(_data.front()); } 60 60 61 /** Read shader binary from file. 62 * Return the resulting Shader or 0 if no valid shader binary could be read.*/ 63 static ShaderBinary* readShaderBinaryFile(const std::string& fileName); 64 61 65 protected: 62 66 63 67 typedef std::vector<unsigned char> Data; 64 68 Data _data; … … 133 137 134 138 /** Read shader source from file and then constructor shader of specified type. 135 * Return the resulting Shader or 0 if no valid shader source co debe read.*/139 * Return the resulting Shader or 0 if no valid shader source could be read.*/ 136 140 static Shader* readShaderFile( Type type, const std::string& fileName ); 137 141 -
OpenSceneGraph/trunk/src/osg/Shader.cpp
r10760 r10766 64 64 } 65 65 66 /////////////////////////////////////////////////////////////////////////// 66 ShaderBinary* ShaderBinary::readShaderBinaryFile(const std::string& fileName) 67 { 68 std::ifstream fin; 69 fin.open(fileName.c_str(), std::ios::binary); 70 if (!fin) return 0; 71 72 fin.seekg(0, std::ios::end); 73 int length = fin.tellg(); 74 if (length==0) return 0; 75 76 osg::ref_ptr<ShaderBinary> shaderBinary = new osg::ShaderBinary; 77 shaderBinary->allocate(length); 78 fin.seekg(0, std::ios::beg); 79 fin.read(reinterpret_cast<char*>(shaderBinary->getData()), length); 80 fin.close(); 81 82 return shaderBinary.release(); 83 } 84 85 /////////////////////////////////////////////////////////////////////////// 67 86 // static cache of glShaders flagged for deletion, which will actually 68 87 // be deleted in the correct GL context.
