Shader::Shader(const std::string &filepath, glm::vec2 viewport, GLenum culling, GLboolean colormask0, GLboolean colormask1, GLboolean colormask2, GLboolean colormask3, GLboolean depthmask, GLbitfield clear) { registred.push_back(this); this->culling = culling; this->colormask[0] = colormask0; this->colormask[1] = colormask1; this->colormask[2] = colormask2; this->colormask[3] = colormask3; this->depthmask = depthmask; this->clear = clear; this->viewport = viewport; std::string firstpath = g_System()->GetDataFile(filepath); std::string vertexsource, fragmentsource, geometrysource, libraries = "\n"; GLuint vertexshader, fragmentshader, geometryshader; int IsCompiled_VS, IsCompiled_FS, IsCompiled_GS; int IsLinked; vertexsource = filetobuf(firstpath + ".vert"); fragmentsource = filetobuf(firstpath + ".frag"); geometrysource = filetobuf(firstpath + ".geom"); std::vector<std::string> libs; g_System()->GetFilesInDirectory(libs, g_System()->GetDataFile("shaders")); for (auto &s : libs) { s = "shaders/" + s; if (endsWith(s, ".slib")) { std::string libsource = filetobuf(g_System()->GetDataFile(s)); if (libsource.length() == 0) continue; g_Console()->Info("Shader library loaded " + s); libraries += libsource + "\n"; } } vertexsource = libraries + vertexsource; fragmentsource = libraries + fragmentsource; if (geometrysource.length() > 0) geometrysource = libraries + geometrysource; vertexshader = glCreateShader(GL_VERTEX_SHADER); const GLchar* ptr = vertexsource.c_str(); glShaderSource(vertexshader, 1, (const GLchar **)&ptr, 0); glCompileShader(vertexshader); glGetShaderiv(vertexshader, GL_COMPILE_STATUS, &IsCompiled_VS); if (IsCompiled_VS == GL_FALSE) { logShader(vertexshader); return; } fragmentshader = glCreateShader(GL_FRAGMENT_SHADER); ptr = fragmentsource.c_str(); glShaderSource(fragmentshader, 1, (const GLchar **)&ptr, 0); glCompileShader(fragmentshader); glGetShaderiv(fragmentshader, GL_COMPILE_STATUS, &IsCompiled_FS); if (IsCompiled_FS == GL_FALSE) { logShader(fragmentshader); return; } if (geometrysource.length() > 0) { geometryshader = glCreateShader(GL_GEOMETRY_SHADER); ptr = geometrysource.c_str(); glShaderSource(geometryshader, 1, (const GLchar **)&ptr, 0); glCompileShader(geometryshader); glGetShaderiv(geometryshader, GL_COMPILE_STATUS, &IsCompiled_GS); if (IsCompiled_GS == GL_FALSE) { logShader(geometryshader); return; } } id = glCreateProgram(); glAttachShader(id, vertexshader); glAttachShader(id, fragmentshader); if (geometrysource.length() > 0) glAttachShader(id, geometryshader); glLinkProgram(id); glGetProgramiv(id, GL_LINK_STATUS, (int *)&IsLinked); if (IsLinked == GL_FALSE) { logProgram(id); id = 0; return; } g_Console()->Info("Shader loaded " + filepath); }
tcu::TestLog& operator<< (tcu::TestLog& log, const HlslSource& shaderSource) { return logShader(log, shaderSource.sources); }