mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 20:58:07 +03:00
l/glrage: replace std::ifstream with FILE*
This commit is contained in:
parent
ac3f4d5029
commit
5150a19cb7
1 changed files with 10 additions and 12 deletions
|
@ -4,8 +4,6 @@
|
||||||
#include <glrage_util/ErrorUtils.hpp>
|
#include <glrage_util/ErrorUtils.hpp>
|
||||||
#include <glrage_util/StringUtils.hpp>
|
#include <glrage_util/StringUtils.hpp>
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace glrage {
|
namespace glrage {
|
||||||
|
@ -31,21 +29,21 @@ void Shader::bind()
|
||||||
|
|
||||||
Shader& Shader::fromFile(const std::string& path)
|
Shader& Shader::fromFile(const std::string& path)
|
||||||
{
|
{
|
||||||
// open and check shader file
|
FILE* fp = fopen(path.c_str(), "rb");
|
||||||
std::ifstream file;
|
if (!fp) {
|
||||||
file.open(path.c_str());
|
|
||||||
if (!file.good()) {
|
|
||||||
throw std::runtime_error("Can't open shader file '" + path +
|
throw std::runtime_error("Can't open shader file '" + path +
|
||||||
"': " + ErrorUtils::getSystemErrorString());
|
"': " + ErrorUtils::getSystemErrorString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// read file to a string stream
|
fseek(fp, 0, SEEK_END);
|
||||||
std::stringstream stream;
|
const auto size = ftell(fp);
|
||||||
stream << file.rdbuf();
|
fseek(fp, 0, SEEK_SET);
|
||||||
file.close();
|
|
||||||
|
|
||||||
// convert stream to string
|
std::string content(size + 1, '\0');
|
||||||
fromString(stream.str());
|
fread(&content[0], 1, size, fp);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
fromString(content.c_str());
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue