Esempio n. 1
0
int ImageManager::add_image(const string& filename, bool& is_float)
{
	Image *img;
	size_t slot;

	/* load image info and find out if we need a float texture */
	is_float = (pack_images)? false: is_float_image(filename);

	if(is_float) {
		/* find existing image */
		for(slot = 0; slot < float_images.size(); slot++) {
			if(float_images[slot] && float_images[slot]->filename == filename) {
				float_images[slot]->users++;
				return slot+TEX_IMAGE_FLOAT_START;
			}
		}

		/* find free slot */
		for(slot = 0; slot < float_images.size(); slot++) {
			if(!float_images[slot])
				break;
		}

		if(slot == float_images.size()) {
			/* max images limit reached */
			if(float_images.size() == TEX_NUM_FLOAT_IMAGES) {
				printf("ImageManager::add_image: byte image limit reached %d, skipping '%s'\n",
				       TEX_NUM_IMAGES, filename.c_str());
				return -1;
			}

			float_images.resize(float_images.size() + 1);
		}

		/* add new image */
		img = new Image();
		img->filename = filename;
		img->need_load = true;
		img->users = 1;

		float_images[slot] = img;
		/* report slot out of total set of textures */
		slot += TEX_IMAGE_FLOAT_START;
	}
	else {
		for(slot = 0; slot < images.size(); slot++) {
			if(images[slot] && images[slot]->filename == filename) {
				images[slot]->users++;
				return slot;
			}
		}

		/* find free slot */
		for(slot = 0; slot < images.size(); slot++) {
			if(!images[slot])
				break;
		}

		if(slot == images.size()) {
			/* max images limit reached */
			if(images.size() == TEX_NUM_IMAGES) {
				printf("ImageManager::add_image: byte image limit reached %d, skipping '%s'\n",
				       TEX_NUM_IMAGES, filename.c_str());
				return -1;
			}

			images.resize(images.size() + 1);
		}

		/* add new image */
		img = new Image();
		img->filename = filename;
		img->need_load = true;
		img->users = 1;

		images[slot] = img;
	}
	need_update = true;

	return slot;
}
Esempio n. 2
0
int ImageManager::add_image(const string& filename, bool& is_float)
{
  fprintf(stderr, "image input disabled\n");
#if 0
	Image *img;
	size_t slot;

	/* load image info and find out if we need a float texture */
	is_float = is_float_image(filename);

	if(is_float) {
		/* find existing image */
		for(slot = 0; slot < float_images.size(); slot++) {
			if(float_images[slot] && float_images[slot]->filename == filename) {
				float_images[slot]->users++;
				return slot+TEX_IMAGE_FLOAT_START;
			}
		}

		/* find free slot */
		for(slot = 0; slot < float_images.size(); slot++) {
			if(!float_images[slot])
				break;
		}

		if(slot == float_images.size()) {
			/* max images limit reached */
			if(float_images.size() == TEX_NUM_FLOAT_IMAGES)
				return -1;

			float_images.resize(float_images.size() + 1);
		}

		/* add new image */
		img = new Image();
		img->filename = filename;
		img->need_load = true;
		img->users = 1;

		float_images[slot] = img;
		/* report slot out of total set of textures */
		slot += TEX_IMAGE_FLOAT_START;
	}
	else {
		for(slot = 0; slot < images.size(); slot++) {
			if(images[slot] && images[slot]->filename == filename) {
				images[slot]->users++;
				return slot;
			}
		}

		/* find free slot */
		for(slot = 0; slot < images.size(); slot++) {
			if(!images[slot])
				break;
		}

		if(slot == images.size()) {
			/* max images limit reached */
			if(images.size() == TEX_NUM_IMAGES)
				return -1;

			images.resize(images.size() + 1);
		}

		/* add new image */
		img = new Image();
		img->filename = filename;
		img->need_load = true;
		img->users = 1;

		images[slot] = img;
	}
	need_update = true;

	return slot;
#endif
	return 0;
}