Shark.cpp
branchv_0
changeset 12 076e3b2d97ac
parent 11 0aeedc35ebed
child 15 1eb7cfefbeea
equal deleted inserted replaced
11:0aeedc35ebed 12:076e3b2d97ac
   191 	Window getRootWindow(Window defaultValue);
   191 	Window getRootWindow(Window defaultValue);
   192 	void log(LogLevel level, std::string message);
   192 	void log(LogLevel level, std::string message);
   193 	int setNonBlocking(int fd);
   193 	int setNonBlocking(int fd);
   194 	void loadVertices();
   194 	void loadVertices();
   195 	Texture loadTexture(const std::string& fileName);
   195 	Texture loadTexture(const std::string& fileName);
       
   196 	void updateTexture(Texture& tex, const Buffer& file);
   196 	bool reloadTexture(const std::string& fileName);
   197 	bool reloadTexture(const std::string& fileName);
   197 	void loadTextures();
   198 	void loadTextures();
   198 	std::shared_ptr<Program> loadShaders();
   199 	std::shared_ptr<Program> loadShaders();
   199 	bool reloadShader(const std::string& fileName);
   200 	bool reloadShader(const std::string& fileName);
   200 	void setTitle(const std::string& suffix = "");
   201 	void setTitle(const std::string& suffix = "");
   552 
   553 
   553 Shark::Impl::Texture Shark::Impl::loadTexture(const std::string& fileName) {
   554 Shark::Impl::Texture Shark::Impl::loadTexture(const std::string& fileName) {
   554 	Texture tex;
   555 	Texture tex;
   555 	tex.fileName = fileName;
   556 	tex.fileName = fileName;
   556 	MappedFile file(tex.fileName);
   557 	MappedFile file(tex.fileName);
   557 
   558 	updateTexture(tex, file);
       
   559 	return tex;
       
   560 }
       
   561 
       
   562 void Shark::Impl::updateTexture(Texture& tex, const Buffer& file) {
   558 	std::shared_ptr<ImageLoader::ImageBuffer> img(imageLoader.loadImage(file));
   563 	std::shared_ptr<ImageLoader::ImageBuffer> img(imageLoader.loadImage(file));
   559 
   564 
   560 	tex.width = img->width;
   565 	tex.width = img->width;
   561 	tex.height = img->height;
   566 	tex.height = img->height;
   562 
   567 
   570 	glTexParameteri(GLT2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   575 	glTexParameteri(GLT2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   571 	glTexParameteri(GLT2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
   576 	glTexParameteri(GLT2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
   572 	glTexParameteri(GLT2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   577 	glTexParameteri(GLT2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   573 	glTexParameteri(GLT2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
   578 	glTexParameteri(GLT2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
   574 	glGenerateMipmap(GLT2D);
   579 	glGenerateMipmap(GLT2D);
   575 	std::cerr << "loadTexture(\"" << fileName.c_str() << "\", "
   580 	std::cerr << "loadTexture(\"" << tex.fileName.c_str() << "\", "
   576 			<< tex.width << ", " << tex.height << ") = " << tex.id << std::endl;
   581 			<< tex.width << ", " << tex.height << ") = " << tex.id << std::endl;
   577 	checkError(&std::cerr);
   582 	checkError(&std::cerr);
   578 	return tex;
       
   579 }
   583 }
   580 
   584 
   581 void Shark::Impl::loadTextures() {
   585 void Shark::Impl::loadTextures() {
   582 	// Load default texture if there is no configured:
   586 	// Load default texture if there is no configured:
   583 	if (cfg.textures.empty())
   587 	if (cfg.textures.empty())
   592 		// checkError(&std::cerr);
   596 		// checkError(&std::cerr);
   593 	}
   597 	}
   594 }
   598 }
   595 
   599 
   596 bool Shark::Impl::reloadTexture(const std::string& fileName) {
   600 bool Shark::Impl::reloadTexture(const std::string& fileName) {
   597 	for (const Configuration::Texture& tex : cfg.textures) {
   601 	for (Texture& tex : textures) {
   598 		if (tex.fileName == fileName) {
   602 		if (tex.fileName == fileName) {
   599 			logOutput << "TODO: reload texture: " << fileName.c_str() << "\n";
   603 			updateTexture(tex, MappedFile(fileName));
       
   604 			loadVertices();
   600 			return true;
   605 			return true;
   601 		}
   606 		}
   602 	}
   607 	}
   603 	return false;
   608 	return false;
   604 }
   609 }