bool CombinerInfo::_loadShadersStorage() { wchar_t fileName[PLUGIN_PATH_SIZE]; getStorageFileName(fileName); m_configOptionsBitSet = _getConfigOptionsBitSet(); #ifdef OS_WINDOWS std::ifstream fin(fileName, std::ofstream::binary); #else char fileName_c[PATH_MAX]; wcstombs(fileName_c, fileName, PATH_MAX); std::ifstream fin(fileName_c, std::ofstream::binary); #endif if (!fin) return false; try { u32 version; fin.read((char*)&version, sizeof(version)); if (version != ShaderStorageFormatVersion) return false; u32 optionsSet; fin.read((char*)&optionsSet, sizeof(optionsSet)); if (optionsSet != m_configOptionsBitSet) return false; const char * strRenderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER)); u32 len; fin.read((char*)&len, sizeof(len)); std::vector<char> strBuf(len); fin.read(strBuf.data(), len); if (strncmp(strRenderer, strBuf.data(), len) != 0) return false; const char * strGLVersion = reinterpret_cast<const char *>(glGetString(GL_VERSION)); fin.read((char*)&len, sizeof(len)); strBuf.resize(len); fin.read(strBuf.data(), len); if (strncmp(strGLVersion, strBuf.data(), len) != 0) return false; fin.read((char*)&len, sizeof(len)); for (u32 i = 0; i < len; ++i) { m_pCurrent = new ShaderCombiner(); fin >> *m_pCurrent; m_pCurrent->update(true); m_pUniformCollection->bindWithShaderCombiner(m_pCurrent); m_combiners[m_pCurrent->getKey()] = m_pCurrent; } } catch (...) { m_shadersLoaded = 0; return false; } m_shadersLoaded = m_combiners.size(); fin.close(); return !isGLError(); }
void CombinerInfo::_saveShadersStorage() const { if (m_shadersLoaded >= m_combiners.size()) return; wchar_t fileName[PLUGIN_PATH_SIZE]; getStorageFileName(fileName); #ifdef OS_WINDOWS std::ofstream fout(fileName, std::ofstream::binary | std::ofstream::trunc); #else char fileName_c[PATH_MAX]; wcstombs(fileName_c, fileName, PATH_MAX); std::ofstream fout(fileName_c, std::ofstream::binary | std::ofstream::trunc); #endif if (!fout) return; fout.write((char*)&ShaderStorageFormatVersion, sizeof(ShaderStorageFormatVersion)); const u32 optionsSet = _getConfigOptionsBitSet(); fout.write((char*)&optionsSet, sizeof(optionsSet)); const char * strRenderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER)); u32 len = strlen(strRenderer); fout.write((char*)&len, sizeof(len)); fout.write(strRenderer, len); const char * strGLVersion = reinterpret_cast<const char *>(glGetString(GL_VERSION)); len = strlen(strGLVersion); fout.write((char*)&len, sizeof(len)); fout.write(strGLVersion, len); len = m_combiners.size(); fout.write((char*)&len, sizeof(len)); for (Combiners::const_iterator cur = m_combiners.begin(); cur != m_combiners.end(); ++cur) fout << *(cur->second); fout.flush(); fout.close(); }