Dump shader programs on compile errors
authorRealBadAngel <maciej.kasatkin@o2.pl>
Wed, 10 Feb 2016 03:27:45 +0000 (04:27 +0100)
committerKahrl <kahrl@gmx.net>
Thu, 11 Feb 2016 06:13:07 +0000 (07:13 +0100)
src/shader.cpp
src/shader.h

index d39a8307c632e11a1f3098f329c3f0e33daf05c3..1d990eafe315cbb0076a4c5fbc3aefa54dcf42de 100644 (file)
@@ -808,6 +808,9 @@ ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
                                        "failed to generate \""<<name<<"\", "
                                        "addHighLevelShaderMaterial failed."
                                        <<std::endl;
+                       dumpShaderProgram(warningstream, "Vertex", vertex_program);
+                       dumpShaderProgram(warningstream, "Pixel", pixel_program);
+                       dumpShaderProgram(warningstream, "Geometry", geometry_program);
                        return shaderinfo;
                }
        }
@@ -826,6 +829,8 @@ ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
                                        "failed to generate \""<<name<<"\", "
                                        "addShaderMaterial failed."
                                        <<std::endl;
+                       dumpShaderProgram(warningstream, "Vertex", vertex_program);
+                       dumpShaderProgram(warningstream,"Pixel", pixel_program);
                        return shaderinfo;
                }
        }
@@ -871,3 +876,21 @@ void load_shaders(std::string name, SourceShaderCache *sourcecache,
        }
 
 }
+
+void dumpShaderProgram(std::ostream &output_stream,
+               const std::string &program_type, const std::string &program)
+{
+       output_stream << program_type << " shader program:" << std::endl <<
+               "----------------------------------" << std::endl;
+       size_t pos = 0;
+       size_t prev = 0;
+       s16 line = 1;
+       while ((pos = program.find("\n", prev)) != std::string::npos) {
+               output_stream << line++ << ": "<< program.substr(prev, pos - prev) <<
+                       std::endl;
+               prev = pos + 1;
+       }
+       output_stream << line << ": " << program.substr(prev) << std::endl <<
+               "End of " << program_type << " shader program." << std::endl <<
+               " " << std::endl;
+}
index 811f33080d8453091da09889f1e8831730d813fc..b8aa88bce17f92db0c8f66fccb914bff89cfafb7 100644 (file)
@@ -110,4 +110,7 @@ public:
 
 IWritableShaderSource* createShaderSource(IrrlichtDevice *device);
 
+void dumpShaderProgram(std::ostream &output_stream,
+       const std::string &program_type, const std::string &program);
+
 #endif