Skip to content

Commit 040cf83

Browse files
committed
Avoid reading shaders line by line
1 parent 616da60 commit 040cf83

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

common/shader.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <iostream>
55
#include <fstream>
66
#include <algorithm>
7+
#include <sstream>
78
using namespace std;
89

910
#include <stdlib.h>
@@ -23,9 +24,9 @@ GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path
2324
std::string VertexShaderCode;
2425
std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
2526
if(VertexShaderStream.is_open()){
26-
std::string Line = "";
27-
while(getline(VertexShaderStream, Line))
28-
VertexShaderCode += "\n" + Line;
27+
std::stringstream sstr;
28+
sstr << VertexShaderStream.rdbuf();
29+
VertexShaderCode = sstr.str();
2930
VertexShaderStream.close();
3031
}else{
3132
printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", vertex_file_path);
@@ -37,9 +38,9 @@ GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path
3738
std::string FragmentShaderCode;
3839
std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
3940
if(FragmentShaderStream.is_open()){
40-
std::string Line = "";
41-
while(getline(FragmentShaderStream, Line))
42-
FragmentShaderCode += "\n" + Line;
41+
std::stringstream sstr;
42+
sstr << FragmentShaderStream.rdbuf();
43+
FragmentShaderCode = sstr.str();
4344
FragmentShaderStream.close();
4445
}
4546

0 commit comments

Comments
 (0)