Ejemplo n.º 1
0
CL_ShaderObject CL_ShaderObject::load(CL_GraphicContext &gc, const CL_StringRef &resource_id, CL_ResourceManager *resources)
{
	CL_Resource resource = resources->get_resource(resource_id);
	CL_String filename = resource.get_element().get_attribute("file");
	CL_String type = resource.get_element().get_tag_name();
	
	CL_ShaderType shader_type;
	if (type == "fragment-shader")
		shader_type = cl_shadertype_fragment;
	else if (type == "vertex-shader")
		shader_type = cl_shadertype_vertex;
	else
		throw CL_Exception("CL_ShaderObject: Unknown shader type: " + type);

	CL_VirtualDirectory directory = resources->get_directory(resource);

	CL_IODevice file = directory.open_file(filename, CL_File::open_existing, CL_File::access_read, CL_File::share_read);
	int size = file.get_size();
	CL_String8 source(size, 0);
	file.read(&source[0], size);

	CL_ShaderObject shader_object(gc, shader_type, CL_StringHelp::local8_to_text(source));

	if (resource.get_element().get_attribute("compile", "true") == "true")
		if(!shader_object.compile())
			throw CL_Exception(cl_format("Unable to compiler shader program %1: %2", resource_id, shader_object.get_info_log()));

	return shader_object;
}
Ejemplo n.º 2
0
CL_XMLTokenizer::CL_XMLTokenizer(CL_IODevice &input) : impl(new CL_XMLTokenizer_Generic)
{
	impl->input = input;
	impl->size = input.get_size();
	impl->pos = 0;

	CL_DataBuffer buffer(impl->size);
	input.receive(buffer.get_data(), buffer.get_size(), true);

	CL_StringHelp::BOMType bom_type = CL_StringHelp::detect_bom(buffer.get_data(), buffer.get_size());
	switch (bom_type)
	{
	default:
	case CL_StringHelp::bom_none:
		impl->data = CL_StringHelp::utf8_to_text(CL_StringRef8(buffer.get_data(), buffer.get_size(), false));
		break;
	case CL_StringHelp::bom_utf32_be:
	case CL_StringHelp::bom_utf32_le:
		throw CL_Exception("UTF-16 XML files not supported yet");
		break;
	case CL_StringHelp::bom_utf16_be:
	case CL_StringHelp::bom_utf16_le:
		throw CL_Exception("UTF-32 XML files not supported yet");
		break;
	case CL_StringHelp::bom_utf8:
		impl->data = CL_StringHelp::utf8_to_text(CL_StringRef8(buffer.get_data()+3, buffer.get_size()-3, false));
		break;
	}

}
Ejemplo n.º 3
0
CL_ShaderObject CL_ShaderObject::load(CL_GraphicContext &gc, CL_ShaderType shader_type, CL_IODevice &file)
{
	int size = file.get_size();
	CL_String8 source(size, 0);
	file.read(&source[0], size);

	return CL_ShaderObject(gc, shader_type, CL_StringHelp::local8_to_text(source));
}
Ejemplo n.º 4
0
void CL_CSSDocument_Impl::load(const CL_String &filename, const CL_VirtualDirectory &directory)
{
	CL_String path = CL_PathHelp::get_fullpath(filename, CL_PathHelp::path_type_file);

	// Load document into a buffer:

	CL_IODevice input = directory.open_file_read(filename);

	int size = input.get_size();
	if (size < 0)
		throw CL_Exception("IODevice does not support get_size()");
	CL_DataBuffer data(size);
	int bytes_read = input.read(data.get_data(), data.get_size());
	data.set_size(bytes_read);

	// Start parsing:

	unsigned char *data_ptr = (unsigned char *) data.get_data();
	whitespace_comments(data_ptr, bytes_read);

	int pos = 0;
	while (pos < bytes_read)
	{
		unsigned char ch = data_ptr[pos];
		switch (ch)
		{
		case ' ':
		case '\t':
		case '\r':
		case '\n':
			pos++;
			break;

		case '@': // import
			pos = load_import(data_ptr, pos, bytes_read, directory, path);
			break;

		default: // ruleset
			pos = load_ruleset(data_ptr, pos, bytes_read);
			break;
		}
	}
}
Ejemplo n.º 5
0
void CL_CSSDocument_Impl::load(const CL_StringRef &path, CL_IODevice &input)
{
	// Load document into a buffer:

	int size = input.get_size();
	if (size < 0)
		throw CL_Exception("IODevice does not support get_size()");
	CL_DataBuffer data(size);
	int bytes_read = input.read(data.get_data(), data.get_size());
	data.set_size(bytes_read);

	// Start parsing:

	unsigned char *data_ptr = (unsigned char *) data.get_data();
	whitespace_comments(data_ptr, bytes_read);

	int pos = 0;
	while (pos < bytes_read)
	{
		unsigned char ch = data_ptr[pos];
		switch (ch)
		{
		case ' ':
		case '\t':
		case '\r':
		case '\n':
			pos++;
			break;

		case '@': // import
			pos = load_import(data_ptr, pos, bytes_read, path);
			break;

		default: // ruleset
			pos = load_ruleset(data_ptr, pos, bytes_read);
			break;
		}
	}
}