当前位置: 首页>>代码示例>>C++>>正文


C++ IFile::read方法代码示例

本文整理汇总了C++中fs::IFile::read方法的典型用法代码示例。如果您正苦于以下问题:C++ IFile::read方法的具体用法?C++ IFile::read怎么用?C++ IFile::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fs::IFile的用法示例。


在下文中一共展示了IFile::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parseVertexDef

bool Model::parseVertexDef(FS::IFile& file, bgfx::VertexDecl* vertex_definition)
{
	vertex_definition->begin();

	uint32 attribute_count;
	file.read(&attribute_count, sizeof(attribute_count));

	for (uint32 i = 0; i < attribute_count; ++i)
	{
		char tmp[50];
		uint32 len;
		file.read(&len, sizeof(len));
		if (len > sizeof(tmp) - 1)
		{
			return false;
		}
		file.read(tmp, len);
		tmp[len] = '\0';

		if (compareString(tmp, "in_position") == 0)
		{
			vertex_definition->add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
		}
		else if (compareString(tmp, "in_colors") == 0)
		{
			vertex_definition->add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true, false);
		}
		else if (compareString(tmp, "in_tex_coords") == 0)
		{
			vertex_definition->add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float);
		}
		else if (compareString(tmp, "in_normal") == 0)
		{
			vertex_definition->add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true);
		}
		else if (compareString(tmp, "in_tangents") == 0)
		{
			vertex_definition->add(bgfx::Attrib::Tangent, 4, bgfx::AttribType::Uint8, true, true);
		}
		else if (compareString(tmp, "in_weights") == 0)
		{
			vertex_definition->add(bgfx::Attrib::Weight, 4, bgfx::AttribType::Float);
		}
		else if (compareString(tmp, "in_indices") == 0)
		{
			vertex_definition->add(bgfx::Attrib::Indices, 4, bgfx::AttribType::Int16, false, true);
		}
		else
		{
			ASSERT(false);
			return false;
		}

		uint32 type;
		file.read(&type, sizeof(type));
	}

	vertex_definition->end();
	return true;
}
开发者ID:badkangaroo,项目名称:LumixEngine,代码行数:60,代码来源:model.cpp

示例2: parseVertexDeclEx

bool Model::parseVertexDeclEx(FS::IFile& file, bgfx::VertexDecl* vertex_decl)
{
	vertex_decl->begin();

	u32 attribute_count;
	file.read(&attribute_count, sizeof(attribute_count));

	for (u32 i = 0; i < attribute_count; ++i)
	{
		i32 attr;
		file.read(&attr, sizeof(attr));

		if (attr == (i32)Attrs::Position)
		{
			vertex_decl->add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
		}
		else if (attr == (i32)Attrs::Color0)
		{
			vertex_decl->add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true, false);
		}
		else if (attr == (i32)Attrs::TexCoord0)
		{
			vertex_decl->add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float);
		}
		else if (attr == (i32)Attrs::Normal)
		{
			vertex_decl->add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true);
		}
		else if (attr == (i32)Attrs::Tangent)
		{
			vertex_decl->add(bgfx::Attrib::Tangent, 4, bgfx::AttribType::Uint8, true, true);
		}
		else if (attr == (i32)Attrs::Weight)
		{
			vertex_decl->add(bgfx::Attrib::Weight, 4, bgfx::AttribType::Float);
		}
		else if (attr == (i32)Attrs::Indices)
		{
			vertex_decl->add(bgfx::Attrib::Indices, 4, bgfx::AttribType::Int16, false, true);
		}
		else
		{
			ASSERT(false);
			return false;
		}
	}

	vertex_decl->end();
	return true;
}
开发者ID:nem0,项目名称:LumixEngine,代码行数:50,代码来源:model.cpp

示例3: loadRaw

bool Texture::loadRaw(FS::IFile& file)
{
	PROFILE_FUNCTION();
	size_t size = file.size();
	m_BPP = 2;
	m_width = (int)sqrt(size / m_BPP);
	m_height = m_width;

	if (m_data_reference)
	{
		m_data.resize(size);
		file.read(&m_data[0], size);
	}

	const uint16_t* src_mem = (const uint16_t*)file.getBuffer();
	const bgfx::Memory* mem = bgfx::alloc(m_width * m_height * sizeof(float));
	float* dst_mem = (float*)mem->data;

	for (int i = 0; i < m_width * m_height; ++i)
	{
		dst_mem[i] = src_mem[i] / 65535.0f;
	}

	m_texture_handle = bgfx::createTexture2D(
		m_width, m_height, 1, bgfx::TextureFormat::R32F, 0, nullptr);
	bgfx::updateTexture2D(
		m_texture_handle,
		0,
		0,
		0,
		m_width,
		m_height,
		mem);
	return bgfx::isValid(m_texture_handle);
}
开发者ID:zhouxh1023,项目名称:LumixEngine,代码行数:35,代码来源:texture.cpp

示例4: parseLODs

bool Model::parseLODs(FS::IFile& file)
{
	i32 lod_count;
	file.read(&lod_count, sizeof(lod_count));
	if (lod_count <= 0 || lod_count > lengthOf(m_lods))
	{
		return false;
	}
	for (int i = 0; i < lod_count; ++i)
	{
		file.read(&m_lods[i].to_mesh, sizeof(m_lods[i].to_mesh));
		file.read(&m_lods[i].distance, sizeof(m_lods[i].distance));
		m_lods[i].from_mesh = i > 0 ? m_lods[i - 1].to_mesh + 1 : 0;
	}
	return true;
}
开发者ID:nem0,项目名称:LumixEngine,代码行数:16,代码来源:model.cpp

示例5: loaded

void Model::loaded(FS::IFile& file, bool success, FS::FileSystem& fs)
{
	PROFILE_FUNCTION();
	if (success)
	{
		FileHeader header;
		file.read(&header, sizeof(header));
		if (header.m_magic == FILE_MAGIC &&
			header.m_version <= (uint32_t)FileVersion::LATEST &&
			parseMeshes(file) && parseGeometry(file) && parseBones(file) &&
			parseLODs(file))
		{
			m_size = file.size();
			decrementDepCount();
		}
		else
		{
			g_log_warning.log("renderer") << "Error loading model "
										  << m_path.c_str();
			onFailure();
			return;
		}
	}
	else
	{
		g_log_warning.log("renderer") << "Error loading model "
									  << m_path.c_str();
		onFailure();
	}
}
开发者ID:gamedevforks,项目名称:LumixEngine,代码行数:30,代码来源:model.cpp

示例6:

JsonSerializer::JsonSerializer(FS::IFile& file,
	AccessMode access_mode,
	const Path& path,
	IAllocator& allocator)
	: m_file(file)
	, m_access_mode(access_mode)
	, m_allocator(allocator)
{
	m_is_error = false;
	copyString(m_path, path.c_str());
	m_is_first_in_block = true;
	m_data = nullptr;
	m_is_string_token = false;
	if (m_access_mode == READ)
	{
		m_data_size = (int)file.size();
		if (file.getBuffer() != nullptr)
		{
			m_data = (const char*)file.getBuffer();
			m_own_data = false;
		}
		else
		{
			int size = (int)m_file.size();
			char* data = (char*)m_allocator.allocate(size);
			m_own_data = true;
			file.read(data, m_data_size);
			m_data = data;
		}
		m_token = m_data;
		m_token_size = 0;
		deserializeToken();
	}
}
开发者ID:Ghost-yc,项目名称:LumixEngine,代码行数:34,代码来源:json_serializer.cpp

示例7: parseLODs

bool Model::parseLODs(FS::IFile& file)
{
	int32 lod_count;
	file.read(&lod_count, sizeof(lod_count));
	if (lod_count <= 0)
	{
		return false;
	}
	m_lods.resize(lod_count);
	for (int i = 0; i < lod_count; ++i)
	{
		file.read(&m_lods[i].m_to_mesh, sizeof(m_lods[i].m_to_mesh));
		file.read(&m_lods[i].m_distance, sizeof(m_lods[i].m_distance));
		m_lods[i].m_from_mesh = i > 0 ? m_lods[i - 1].m_to_mesh + 1 : 0;
	}
	return true;
}
开发者ID:badkangaroo,项目名称:LumixEngine,代码行数:17,代码来源:model.cpp

示例8: loaded

void Animation::loaded(FS::IFile& file, bool success, FS::FileSystem& fs)
{
	if (success)
	{
		IAllocator& allocator = getAllocator();
		allocator.deallocate(m_positions);
		allocator.deallocate(m_rotations);
		allocator.deallocate(m_bones);
		m_positions = nullptr;
		m_rotations = nullptr;
		m_bones = 0;
		m_frame_count = m_bone_count = 0;
		Header header;
		file.read(&header, sizeof(header));
		if (header.magic != HEADER_MAGIC)
		{
			onFailure();
			g_log_error.log("animation") << m_path.c_str() << " is not an animation file";
			return;
		}
		if (header.version > 1)
		{
			onFailure();
			g_log_error.log("animation") << "Unsupported animation version " << header.version << " (" << m_path.c_str() << ")";
			return;
		}
		m_fps = header.fps;
		file.read(&m_frame_count, sizeof(m_frame_count));
		file.read(&m_bone_count, sizeof(m_bone_count));

		m_positions = static_cast<Vec3*>(allocator.allocate(sizeof(Vec3) * m_frame_count * m_bone_count));
		m_rotations = static_cast<Quat*>(allocator.allocate(sizeof(Quat) * m_frame_count * m_bone_count));
		m_bones = static_cast<uint32_t*>(allocator.allocate(sizeof(uint32_t) * m_bone_count));
		file.read(&m_positions[0], sizeof(Vec3)* m_bone_count * m_frame_count);
		file.read(&m_rotations[0], sizeof(Quat)* m_bone_count * m_frame_count);
		file.read(m_bones, sizeof(m_bones[0]) * m_bone_count);
		
		m_size = file.size();
		decrementDepCount();
	}
	else
	{
		onFailure();
	}
}
开发者ID:gamedevforks,项目名称:LumixEngine,代码行数:45,代码来源:animation.cpp

示例9: load

bool ShaderBinary::load(FS::IFile& file)
{
	auto* mem = bgfx::alloc((uint32)file.size() + 1);
	file.read(mem->data, file.size());
	mem->data[file.size()] = '\0';
	m_handle = bgfx::createShader(mem);
	m_size = file.size();
	return bgfx::isValid(m_handle);
}
开发者ID:Fergus1986,项目名称:LumixEngine,代码行数:9,代码来源:shader.cpp

示例10: load

bool Model::load(FS::IFile& file)
{
	PROFILE_FUNCTION();
	FileHeader header;
	file.read(&header, sizeof(header));

	if (header.magic != FILE_MAGIC)
	{
		g_log_warning.log("Renderer") << "Corrupted model " << getPath().c_str();
		return false;
	}

	if(header.version > (u32)FileVersion::LATEST)
	{
		g_log_warning.log("Renderer") << "Unsupported version of model " << getPath().c_str();
		return false;
	}

	u32 global_flags = 0; // backward compatibility
	if(header.version > (u32)FileVersion::WITH_FLAGS)
	{
		file.read(&global_flags, sizeof(global_flags));
	}

	bgfx::VertexDecl global_vertex_decl;
	if (header.version > (u32)FileVersion::SINGLE_VERTEX_DECL && header.version <= (u32)FileVersion::MULTIPLE_VERTEX_DECLS)
	{
		parseVertexDeclEx(file, &global_vertex_decl);
	}

	if (parseMeshes(global_vertex_decl, file, (FileVersion)header.version, global_flags)
		&& parseBones(file)
		&& parseLODs(file))
	{
		m_size = file.size();
		return true;
	}

	g_log_error.log("Renderer") << "Error loading model " << getPath().c_str();
	return false;
}
开发者ID:nem0,项目名称:LumixEngine,代码行数:41,代码来源:model.cpp

示例11: parseGeometry

bool Model::parseGeometry(FS::IFile& file)
{
	int32_t indices_count = 0;
	file.read(&indices_count, sizeof(indices_count));
	if (indices_count <= 0)
	{
		return false;
	}
	m_indices.resize(indices_count);
	file.read(&m_indices[0], sizeof(m_indices[0]) * indices_count);

	int32_t vertices_size = 0;
	file.read(&vertices_size, sizeof(vertices_size));
	if (vertices_size <= 0)
	{
		return false;
	}

	Array<uint8_t> vertices(m_allocator);
	vertices.resize(vertices_size);
	file.read(&vertices[0], sizeof(vertices[0]) * vertices.size());

	m_geometry_buffer_object.setAttributesData(
		&vertices[0], vertices.size(), m_meshes[0].getVertexDefinition());
	m_geometry_buffer_object.setIndicesData(
		&m_indices[0], m_indices.size() * sizeof(m_indices[0]));

	int vertex_count = 0;
	for (int i = 0; i < m_meshes.size(); ++i)
	{
		vertex_count += m_meshes[i].getAttributeArraySize() /
						m_meshes[i].getVertexDefinition().getStride();
	}
	m_vertices.resize(vertex_count);

	computeRuntimeData(&vertices[0]);

	return true;
}
开发者ID:gamedevforks,项目名称:LumixEngine,代码行数:39,代码来源:model.cpp

示例12: load

bool Animation::load(FS::IFile& file)
{
	IAllocator& allocator = getAllocator();
	allocator.deallocate(m_positions);
	allocator.deallocate(m_rotations);
	allocator.deallocate(m_bones);
	m_positions = nullptr;
	m_rotations = nullptr;
	m_bones = nullptr;
	m_frame_count = m_bone_count = 0;
	Header header;
	file.read(&header, sizeof(header));
	if (header.magic != HEADER_MAGIC)
	{
		g_log_error.log("Animation") << getPath() << " is not an animation file";
		return false;
	}
	if (header.version > 1)
	{
		g_log_error.log("Animation") << "Unsupported animation version " << header.version << " ("
									 << getPath() << ")";
		return false;
	}
	m_fps = header.fps;
	file.read(&m_frame_count, sizeof(m_frame_count));
	file.read(&m_bone_count, sizeof(m_bone_count));

	m_positions = static_cast<Vec3*>(allocator.allocate(sizeof(Vec3) * m_frame_count * m_bone_count));
	m_rotations = static_cast<Quat*>(allocator.allocate(sizeof(Quat) * m_frame_count * m_bone_count));
	m_bones = static_cast<uint32*>(allocator.allocate(sizeof(uint32) * m_bone_count));
	file.read(&m_positions[0], sizeof(Vec3)* m_bone_count * m_frame_count);
	file.read(&m_rotations[0], sizeof(Quat)* m_bone_count * m_frame_count);
	file.read(m_bones, sizeof(m_bones[0]) * m_bone_count);
		
	m_size = file.size();
	return true;
}
开发者ID:Fergus1986,项目名称:LumixEngine,代码行数:37,代码来源:animation.cpp

示例13: parseGeometry

bool Model::parseGeometry(FS::IFile& file)
{
	int32 indices_count = 0;
	file.read(&indices_count, sizeof(indices_count));
	if (indices_count <= 0) return false;

	m_indices.resize(indices_count);
	file.read(&m_indices[0], sizeof(m_indices[0]) * indices_count);

	int32 vertices_size = 0;
	file.read(&vertices_size, sizeof(vertices_size));
	if (vertices_size <= 0) return false;

	ASSERT(!bgfx::isValid(m_vertices_handle));
	const bgfx::Memory* vertices_mem = bgfx::alloc(vertices_size);
	file.read(vertices_mem->data, vertices_size);
	m_vertices_handle = bgfx::createVertexBuffer(vertices_mem, m_meshes[0].getVertexDefinition());
	m_vertices_size = vertices_size;

	ASSERT(!bgfx::isValid(m_indices_handle));
	m_indices_size = sizeof(m_indices[0]) * indices_count;
	const bgfx::Memory* mem = bgfx::copy(&m_indices[0], m_indices_size);
	m_indices_handle = bgfx::createIndexBuffer(mem, BGFX_BUFFER_INDEX32);

	int vertex_count = 0;
	for (int i = 0; i < m_meshes.size(); ++i)
	{
		vertex_count += m_meshes[i].getAttributeArraySize() /
						m_meshes[i].getVertexDefinition().getStride();
	}
	m_vertices.resize(vertex_count);

	computeRuntimeData(vertices_mem->data);

	return true;
}
开发者ID:badkangaroo,项目名称:LumixEngine,代码行数:36,代码来源:model.cpp

示例14: load

bool Model::load(FS::IFile& file)
{
	PROFILE_FUNCTION();
	FileHeader header;
	file.read(&header, sizeof(header));
	if (header.m_magic == FILE_MAGIC 
		&& header.m_version <= (uint32)FileVersion::LATEST 
		&& parseMeshes(file) 
		&& parseGeometry(file) 
		&& parseBones(file) 
		&& parseLODs(file))
	{
		m_size = file.size();
		return true;
	}

	g_log_warning.log("renderer") << "Error loading model " << getPath().c_str();
	return false;
}
开发者ID:badkangaroo,项目名称:LumixEngine,代码行数:19,代码来源:model.cpp

示例15: parseMeshesOld

bool Model::parseMeshesOld(bgfx::VertexDecl global_vertex_decl, FS::IFile& file, FileVersion version, u32 global_flags)
{
	int object_count = 0;
	file.read(&object_count, sizeof(object_count));
	if (object_count <= 0) return false;

	m_meshes.reserve(object_count);
	char model_dir[MAX_PATH_LENGTH];
	PathUtils::getDir(model_dir, MAX_PATH_LENGTH, getPath().c_str());
	struct Offsets
	{
		i32 attribute_array_offset;
		i32 attribute_array_size;
		i32 indices_offset;
		i32 mesh_tri_count;
	};
	Array<Offsets> mesh_offsets(m_allocator);
	for (int i = 0; i < object_count; ++i)
	{
		i32 str_size;
		file.read(&str_size, sizeof(str_size));
		char material_name[MAX_PATH_LENGTH];
		file.read(material_name, str_size);
		if (str_size >= MAX_PATH_LENGTH) return false;

		material_name[str_size] = 0;

		char material_path[MAX_PATH_LENGTH];
		copyString(material_path, model_dir);
		catString(material_path, material_name);
		catString(material_path, ".mat");

		auto* material_manager = m_resource_manager.getOwner().get(Material::TYPE);
		Material* material = static_cast<Material*>(material_manager->load(Path(material_path)));

		Offsets& offsets = mesh_offsets.emplace();
		file.read(&offsets.attribute_array_offset, sizeof(offsets.attribute_array_offset));
		file.read(&offsets.attribute_array_size, sizeof(offsets.attribute_array_size));
		file.read(&offsets.indices_offset, sizeof(offsets.indices_offset));
		file.read(&offsets.mesh_tri_count, sizeof(offsets.mesh_tri_count));

		file.read(&str_size, sizeof(str_size));
		if (str_size >= MAX_PATH_LENGTH)
		{
			material_manager->unload(*material);
			return false;
		}

		char mesh_name[MAX_PATH_LENGTH];
		mesh_name[str_size] = 0;
		file.read(mesh_name, str_size);

		bgfx::VertexDecl vertex_decl = global_vertex_decl;
		if (version <= FileVersion::SINGLE_VERTEX_DECL)
		{
			parseVertexDecl(file, &vertex_decl);
			if (i != 0 && global_vertex_decl.m_hash != vertex_decl.m_hash)
			{
				g_log_error.log("Renderer") << "Model " << getPath().c_str()
					<< " contains meshes with different vertex declarations.";
			}
			if(i == 0) global_vertex_decl = vertex_decl;
		}


		m_meshes.emplace(material,
			vertex_decl,
			mesh_name,
			m_allocator);
		addDependency(*material);
	}

	i32 indices_count = 0;
	file.read(&indices_count, sizeof(indices_count));
	if (indices_count <= 0) return false;

	u32 INDICES_16BIT_FLAG = 1;
	int index_size = global_flags & INDICES_16BIT_FLAG ? 2 : 4;
	Array<u8> indices(m_allocator);
	indices.resize(indices_count * index_size);
	file.read(&indices[0], indices.size());

	i32 vertices_size = 0;
	file.read(&vertices_size, sizeof(vertices_size));
	if (vertices_size <= 0) return false;

	Array<u8> vertices(m_allocator);
	vertices.resize(vertices_size);
	file.read(&vertices[0], vertices.size());

	int vertex_count = 0;
	for (const Offsets& offsets : mesh_offsets)
	{
		vertex_count += offsets.attribute_array_size / global_vertex_decl.getStride();
	}

	if (version > FileVersion::BOUNDING_SHAPES_PRECOMPUTED)
	{
		file.read(&m_bounding_radius, sizeof(m_bounding_radius));
		file.read(&m_aabb, sizeof(m_aabb));
//.........这里部分代码省略.........
开发者ID:nem0,项目名称:LumixEngine,代码行数:101,代码来源:model.cpp


注:本文中的fs::IFile::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。