示例#1
0
Shader::IShaderObject* CShaderHandler::CreateShaderObject(const std::string& soName, const std::string& soDefs, int soType) {
	assert(!soName.empty());

	bool arbShader = false;

	std::string soPath = "shaders/" + soName;
	std::string soSource = "";

	CFileHandler soFile(soPath);

	if (soFile.FileExists()) {
		std::vector<char> soFileBuffer(soFile.FileSize() + 1, 0);
		soFile.Read(&soFileBuffer[0], soFile.FileSize());

		arbShader =
			soName.find(".glsl") == std::string::npos &&
			soName.find(".vert") == std::string::npos &&
			soName.find(".frag") == std::string::npos;
		soSource = std::string(&soFileBuffer[0]);
	} else {
		LOG_L(L_WARNING, "[%s]\n\tfile \"%s\" does not exist, interpreting"
				" \"%s\" as literal shader source-string",
				__FUNCTION__, soPath.c_str(), soName.c_str());

		arbShader =
			(soName.find("!!ARBvp") != std::string::npos) ||
			(soName.find("!!ARBfp") != std::string::npos);
		soSource = soName;
	}

	if (!arbShader) {
		soSource = soDefs + soSource;
	}

	Shader::IShaderObject* so = NULL;

	switch (soType) {
		case GL_VERTEX_PROGRAM_ARB:
		case GL_FRAGMENT_PROGRAM_ARB: {
			assert(arbShader);
			so = new Shader::ARBShaderObject(soType, soSource);
		} break;

		case GL_VERTEX_SHADER:
		case GL_FRAGMENT_SHADER: {
			assert(!arbShader);
			so = new Shader::GLSLShaderObject(soType, soSource);
		} break;
	}

	assert(so != NULL);
	so->Compile();

	if (!so->IsValid()) {
		LOG_L(L_WARNING, "[%s]\n\tshader-object name: %s, compile-log:\n%s",
				__FUNCTION__, soName.c_str(), (so->GetLog()).c_str());
	}
	return so;
}
示例#2
0
Shader::IShaderObject* CShaderHandler::CreateShaderObject(const std::string& soName, int soType) {
	assert(!soName.empty());

	bool arbShader = false;

	std::string soSource("");
	CFileHandler soFile("shaders/" + soName);

	if (soFile.FileExists()) {
		arbShader =
			soName.find(".glsl") == std::string::npos &&
			soName.find(".vert") == std::string::npos &&
			soName.find(".frag") == std::string::npos;

		std::vector<char> soFileBuffer(soFile.FileSize() + 1, 0);
		soFile.Read(&soFileBuffer[0], soFile.FileSize());

		soSource = std::string(&soFileBuffer[0]);
	} else {
		arbShader =
			(soName.find("!!ARBvp") != std::string::npos) ||
			(soName.find("!!ARBfp") != std::string::npos);
		soSource = soName;
	}

	Shader::IShaderObject* so = NULL;

	switch (soType) {
		case GL_VERTEX_PROGRAM_ARB:
		case GL_FRAGMENT_PROGRAM_ARB: {
			assert(arbShader);
			so = new Shader::ARBShaderObject(soType, soSource);
		} break;

		case GL_VERTEX_SHADER:
		case GL_FRAGMENT_SHADER: {
			assert(!arbShader);
			so = new Shader::GLSLShaderObject(soType, soSource);
		} break;
	}

	assert(so != NULL);
	so->Compile();

	if (!so->IsValid()) {
		logOutput.Print("[CShaderHandler::CreateShaderObject]\n");
		logOutput.Print("\tshader-object name: %s, compile-log:\n%s\n", soName.c_str(), (so->GetLog()).c_str());
	}
	return so;
}