Shark.cpp
branchv_0
changeset 6 fd93a46db15b
parent 5 ee4ba9f5a053
child 7 e6065118326f
equal deleted inserted replaced
5:ee4ba9f5a053 6:fd93a46db15b
   374 		// Vertex Buffer Object (VBO):
   374 		// Vertex Buffer Object (VBO):
   375 		GLuint vbo;
   375 		GLuint vbo;
   376 		glGenBuffers(1, &vbo);
   376 		glGenBuffers(1, &vbo);
   377 		glBindBuffer(GL_ARRAY_BUFFER, vbo);
   377 		glBindBuffer(GL_ARRAY_BUFFER, vbo);
   378 
   378 
   379 		std::vector<std::string> fileNames = {
   379 		if (cfg.shaders.empty()) {
   380 			"shaders/first.vert",
   380 			// TODO: configurable absolute path or embedded defaults
   381 			"shaders/first.frag",
   381 			cfg.shaders.push_back({"shaders/first.vert", "vertex"});
   382 		};
   382 			cfg.shaders.push_back({"shaders/first.frag", "fragment"});
       
   383 		}
   383 
   384 
   384 		std::shared_ptr<Program> program = std::make_shared<Program>();
   385 		std::shared_ptr<Program> program = std::make_shared<Program>();
   385 
   386 
   386 		// glBindFragDataLocation(program, 0, "outColor");
   387 		// glBindFragDataLocation(program, 0, "outColor");
   387 		// glBindAttribLocation(program, LOC.input, "vertices");
   388 		// glBindAttribLocation(program, LOC.input, "vertices");
   388 
   389 
   389 		for (const std::string& fileName : fileNames) {
   390 		for (const Configuration::Shader definition : cfg.shaders) {
       
   391 			Shader::Type type;
       
   392 			std::string fileName = definition.fileName;
       
   393 			if (definition.type == "fragment") type = Shader::Type::FRAGMENT;
       
   394 			else if (definition.type == "vertex") type = Shader::Type::VERTEX;
       
   395 			else throw std::invalid_argument("unsupported shader type");
       
   396 
   390 			MappedFile file(fileName);
   397 			MappedFile file(fileName);
   391 			std::shared_ptr<Shader> shader = std::make_shared<Shader>(
   398 			std::shared_ptr<Shader> shader = std::make_shared<Shader>(
   392 					toShaderType(fileName), file, fileName);
   399 					type, file, fileName);
   393 
   400 
   394 			program->attachShader(*shader.get());
   401 			program->attachShader(*shader.get());
   395 			shaders.push_back(shader);
   402 			shaders.push_back(shader);
   396 			std::cerr << "GLSL loaded: " << fileName.c_str() << std::endl;
   403 			std::cerr << "GLSL loaded: " << fileName.c_str() << std::endl;
   397 		}
   404 		}