예제 #1
0
void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int slot, Progress *progress)
{
	if(progress->get_cancel())
		return;
	if(osl_texture_system)
		return;

	Image *img;
	bool is_float;

	if(slot < TEX_IMAGE_FLOAT_START) {
		img = images[slot];
		is_float = false;
	}
	else {
		img = float_images[slot - TEX_IMAGE_FLOAT_START];
		is_float = true;
	}

	if(is_float) {
		string filename = path_filename(float_images[slot - TEX_IMAGE_FLOAT_START]->filename);
		progress->set_status("Updating Images", "Loading " + filename);

		device_vector<float4>& tex_img = dscene->tex_float_image[slot - TEX_IMAGE_FLOAT_START];

		if(tex_img.device_pointer)
			device->tex_free(tex_img);

		if(!file_load_float_image(img, tex_img)) {
			/* on failure to load, we set a 1x1 pixels pink image */
			float *pixels = (float*)tex_img.resize(1, 1);

			pixels[0] = TEX_IMAGE_MISSING_R;
			pixels[1] = TEX_IMAGE_MISSING_G;
			pixels[2] = TEX_IMAGE_MISSING_B;
			pixels[3] = TEX_IMAGE_MISSING_A;
		}

		string name;

		if(slot >= 10) name = string_printf("__tex_image_float_0%d", slot);
		else name = string_printf("__tex_image_float_00%d", slot);

		if(!pack_images)
			device->tex_alloc(name.c_str(), tex_img, true, true);
	}
	else {
		string filename = path_filename(images[slot]->filename);
		progress->set_status("Updating Images", "Loading " + filename);

		device_vector<uchar4>& tex_img = dscene->tex_image[slot];

		if(tex_img.device_pointer)
			device->tex_free(tex_img);

		if(!file_load_image(img, tex_img)) {
			/* on failure to load, we set a 1x1 pixels pink image */
			uchar *pixels = (uchar*)tex_img.resize(1, 1);

			pixels[0] = (TEX_IMAGE_MISSING_R * 255);
			pixels[1] = (TEX_IMAGE_MISSING_G * 255);
			pixels[2] = (TEX_IMAGE_MISSING_B * 255);
			pixels[3] = (TEX_IMAGE_MISSING_A * 255);
		}

		string name;

		if(slot >= 10) name = string_printf("__tex_image_0%d", slot);
		else name = string_printf("__tex_image_00%d", slot);

		if(!pack_images)
			device->tex_alloc(name.c_str(), tex_img, true, true);
	}

	img->need_load = false;
}
예제 #2
0
void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int slot)
{
	if(osl_texture_system)
		return;

	Image *img;
	bool is_float;

	if(slot < TEX_IMAGE_FLOAT_START) {
		img = images[slot];
		is_float = false;
	}
	else {
		img = float_images[slot - TEX_IMAGE_FLOAT_START];
		is_float = true;
	}

	if(is_float) {
		device_vector<float4>& tex_img = dscene->tex_float_image[slot - TEX_IMAGE_FLOAT_START];

		if(tex_img.device_pointer)
			device->tex_free(tex_img);

		if(!file_load_float_image(img, tex_img)) {
			/* on failure to load, we set a 1x1 pixels black image */
			float *pixels = (float*)tex_img.resize(1, 1);

			pixels[0] = 0.0f;
			pixels[1] = 0.0f;
			pixels[2] = 0.0f;
			pixels[3] = 0.0f;
		}

		string name = "__tex_image_float_0";
		name += string_0d(slot,2);

		device->tex_alloc(name.c_str(), tex_img, true, true);
	}
	else {
		device_vector<uchar4>& tex_img = dscene->tex_image[slot];

		if(tex_img.device_pointer)
			device->tex_free(tex_img);

		if(!file_load_image(img, tex_img)) {
			/* on failure to load, we set a 1x1 pixels black image */
			uchar *pixels = (uchar*)tex_img.resize(1, 1);

			pixels[0] = 0;
			pixels[1] = 0;
			pixels[2] = 0;
			pixels[3] = 0;
		}

		string name = "__tex_image_0";
		name += string_0d(slot,2);

		//if(slot >= 10) name = string_printf("__tex_image_0%d", slot);
		//else name = string_printf("__tex_image_00%d", slot);

		device->tex_alloc(name.c_str(), tex_img, true, true);
	}
}