1
0
Fork 0

source/Graphics/Shader.cpp: use the new File API

This commit is contained in:
Henrik Hautakoski 2020-01-18 21:38:10 +01:00
parent 624a979356
commit 59a4f1347a
No known key found for this signature in database
GPG key ID: 96765B12FEAC4745

View file

@ -1,6 +1,6 @@
#include <fstream>
#include <Spectre/System/Path.h> #include <Spectre/System/Path.h>
#include <Spectre/System/File.h>
#include <Spectre/Graphics/Shader.h> #include <Spectre/Graphics/Shader.h>
#include <Graphics/GL/gl.h> #include <Graphics/GL/gl.h>
@ -30,26 +30,26 @@ const std::string& Shader::getName() const
return m_name; return m_name;
} }
bool Shader::loadFromFile(const std::string& file) bool Shader::loadFromFile(const std::string& filename)
{ {
std::string src; std::string src;
std::ifstream strm; File file;
// If this shader does not have a name, pick the filename. // If this shader does not have a name, pick the filename.
if (m_name.length() < 1) { if (m_name.length() < 1) {
m_name = Path::getBasename(file); m_name = Path::getBasename(filename);
} }
// Load file into memory. if (!file.open(filename)) {
strm.open(file.c_str(), std::fstream::in); m_error = "Can't open file: " + filename;
if (!strm.is_open()) {
m_error = "Can't open file: " + file;
return false; return false;
} }
src.assign(std::istreambuf_iterator<char>(strm), std::istreambuf_iterator<char>()); // Load file into memory.
if (!file.read(src)) {
strm.close(); m_error = "Could not read file: " + filename;
return false;
}
return loadFromMemory(src); return loadFromMemory(src);
} }