GLProgram *GLProgramManager::CreateProgram(const std::string &name) {
			SPADES_MARK_FUNCTION();

			SPLog("Loading GLSL program '%s'", name.c_str());
			std::string text = FileManager::ReadAllBytes(name.c_str());
			std::vector<std::string> lines = SplitIntoLines(text);

			GLProgram *p = new GLProgram(device, name);

			for (size_t i = 0; i < lines.size(); i++) {
				std::string text = TrimSpaces(lines[i]);
				if (text.empty())
					break;

				if (text == "*shadow*") {
					std::vector<GLShader *> shaders =
					  GLShadowShader::RegisterShader(this, settings, false);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text == "*shadow-lite*") {
					std::vector<GLShader *> shaders =
					  GLShadowShader::RegisterShader(this, settings, false, true);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text == "*shadow-variance*") {
					std::vector<GLShader *> shaders =
					  GLShadowShader::RegisterShader(this, settings, true);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text == "*dlight*") {
					std::vector<GLShader *> shaders = GLDynamicLightShader::RegisterShader(this);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text == "*shadowmap*") {
					std::vector<GLShader *> shaders = GLShadowMapShader::RegisterShader(this);
					for (size_t i = 0; i < shaders.size(); i++)
						p->Attach(shaders[i]);
					continue;
				} else if (text[0] == '*') {
					SPRaise("Unknown special shader: %s", text.c_str());
				} else if (text[0] == '#') {
					continue;
				}
				GLShader *s = CreateShader(text);

				p->Attach(s);
			}

			Stopwatch sw;
			p->Link();
			SPLog("Successfully linked GLSL program '%s' in %.3fms", name.c_str(),
			      sw.GetTime() * 1000.);
			// p->Validate();
			return p;
		}
Exemple #2
0
static void
LinkProgram(GLProgram &program)
{
  program.Link();

  if (program.GetLinkStatus() != GL_TRUE) {
    char log[4096];
    program.GetInfoLog(log, sizeof(log));
    fprintf(stderr, "Shader linker failed: %s\n", log);
  }
}
Exemple #3
0
static GLProgram *
CompileProgram(const char *vertex_shader, const char *fragment_shader)
{
  GLProgram *program = new GLProgram();
  CompileAttachShader(*program, GL_VERTEX_SHADER, vertex_shader);
  CompileAttachShader(*program, GL_FRAGMENT_SHADER, fragment_shader);
  program->Link();

  if (program->GetLinkStatus() != GL_TRUE) {
    char log[4096];
    program->GetInfoLog(log, sizeof(log));
    fprintf(stderr, "Shader linker failed: %s\n", log);
  }

  return program;
}