bool RocketRenderingInterface::LoadTexture(TextureHandle& texture_handle, Vector2i& texture_dimensions,
                                           const String& source)
{
	GR_DEBUG_SCOPE("libRocket::LoadTexture");
	SCP_string filename;
	int dir_type;
	if (!RocketFileInterface::getCFilePath(source, filename, dir_type)) {
		return false;
	}

	auto period_pos = filename.rfind('.');
	if (period_pos != SCP_string::npos) {
		filename = filename.substr(0, period_pos);
	}

	auto id = bm_load_either(filename.c_str(), nullptr, nullptr, nullptr, false, dir_type);
	if (id < 0) {
		return false;
	}

	int w, h;
	bm_get_info(id, &w, &h);

	texture_dimensions.x = w;
	texture_dimensions.y = h;

	auto* tex   = new Texture();
	tex->handle = id;

	texture_handle = get_texture_handle(tex);

	return true;
}
Example #2
0
bool
TextureSystemImpl::environment(ustring filename, TextureOptBatch& options,
                               Tex::RunMask mask, const float* R,
                               const float* dRdx, const float* dRdy,
                               int nchannels, float* result, float* dresultds,
                               float* dresultdt)
{
    Perthread* thread_info        = get_perthread_info();
    TextureHandle* texture_handle = get_texture_handle(filename, thread_info);
    return environment(texture_handle, thread_info, options, mask, R, dRdx,
                       dRdy, nchannels, result, dresultds, dresultdt);
}
Example #3
0
bool
TextureSystemImpl::environment(ustring filename, TextureOptions& options,
                               Runflag* runflags, int beginactive,
                               int endactive, VaryingRef<Imath::V3f> R,
                               VaryingRef<Imath::V3f> dRdx,
                               VaryingRef<Imath::V3f> dRdy, int nchannels,
                               float* result, float* dresultds,
                               float* dresultdt)
{
    Perthread* thread_info        = get_perthread_info();
    TextureHandle* texture_handle = get_texture_handle(filename, thread_info);
    return environment(texture_handle, thread_info, options, runflags,
                       beginactive, endactive, R, dRdx, dRdy, nchannels, result,
                       dresultds, dresultdt);
}
bool RocketRenderingInterface::GenerateTexture(TextureHandle& texture_handle, const Rocket::Core::byte* source,
                                               const Vector2i& source_dimensions)
{
	GR_DEBUG_SCOPE("libRocket::GenerateTexture");
	auto size = (size_t)(source_dimensions.x * source_dimensions.y * 4); // RGBA format

	std::unique_ptr<uint8_t[]> buffer(new uint8_t[size]);
	memcpy(buffer.get(), source, size);

	auto id = bm_create(32, source_dimensions.x, source_dimensions.y, buffer.get());
	if (id < 0) {
		return false;
	}

	auto* tex   = new Texture();
	tex->handle = id;
	tex->data   = std::move(buffer);

	texture_handle = get_texture_handle(tex);

	return true;
}