Skip to content

Commit f253ff9

Browse files
RealBadAngelkahrl
authored andcommittedFeb 11, 2016
Dump shader programs on compile errors
1 parent 7e5eea9 commit f253ff9

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎src/shader.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,9 @@ ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
808808
"failed to generate \""<<name<<"\", "
809809
"addHighLevelShaderMaterial failed."
810810
<<std::endl;
811+
dumpShaderProgram(warningstream, "Vertex", vertex_program);
812+
dumpShaderProgram(warningstream, "Pixel", pixel_program);
813+
dumpShaderProgram(warningstream, "Geometry", geometry_program);
811814
return shaderinfo;
812815
}
813816
}
@@ -826,6 +829,8 @@ ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
826829
"failed to generate \""<<name<<"\", "
827830
"addShaderMaterial failed."
828831
<<std::endl;
832+
dumpShaderProgram(warningstream, "Vertex", vertex_program);
833+
dumpShaderProgram(warningstream,"Pixel", pixel_program);
829834
return shaderinfo;
830835
}
831836
}
@@ -871,3 +876,21 @@ void load_shaders(std::string name, SourceShaderCache *sourcecache,
871876
}
872877

873878
}
879+
880+
void dumpShaderProgram(std::ostream &output_stream,
881+
const std::string &program_type, const std::string &program)
882+
{
883+
output_stream << program_type << " shader program:" << std::endl <<
884+
"----------------------------------" << std::endl;
885+
size_t pos = 0;
886+
size_t prev = 0;
887+
s16 line = 1;
888+
while ((pos = program.find("\n", prev)) != std::string::npos) {
889+
output_stream << line++ << ": "<< program.substr(prev, pos - prev) <<
890+
std::endl;
891+
prev = pos + 1;
892+
}
893+
output_stream << line << ": " << program.substr(prev) << std::endl <<
894+
"End of " << program_type << " shader program." << std::endl <<
895+
" " << std::endl;
896+
}

‎src/shader.h

+3
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,7 @@ class IWritableShaderSource : public IShaderSource
110110

111111
IWritableShaderSource* createShaderSource(IrrlichtDevice *device);
112112

113+
void dumpShaderProgram(std::ostream &output_stream,
114+
const std::string &program_type, const std::string &program);
115+
113116
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.