Пример #1
0
void ProfilerUIImpl::saveResourceList()
{
	Lumix::FS::OsFile file;
	if (file.open("resources.csv", Lumix::FS::Mode::CREATE | Lumix::FS::Mode::WRITE, m_allocator))
	{
		auto& managers = m_resource_manager.getAll();
		for (auto* i : managers)
		{
			auto& resources = i->getResourceTable();
			for (auto& res : resources)
			{
				file.write(res->getPath().c_str(), res->getPath().length());
				file.write(", ", 2);
				char tmp[50];
				Lumix::toCString(res->size() / 1024.0f, tmp, Lumix::lengthOf(tmp), 3);
				file.write(tmp, Lumix::stringLength(tmp));
				file.write("KB, ", 4);
				
				const char* state = getResourceStateString(res->getState());
				file.write(state, Lumix::stringLength(state));
				
				file.write(", ", 4);
				Lumix::toCString(res->getRefCount(), tmp, Lumix::lengthOf(tmp));
				file.write(tmp, Lumix::stringLength(tmp));
				file.write("\n", 4);
			}
		}
		file.close();
	}
}
Пример #2
0
		void screenShot(const char* filePath,
			uint32_t width,
			uint32_t height,
			uint32_t pitch,
			const void* data,
			uint32_t size,
			bool yflip) override
		{
			#pragma pack(1)
				struct TGAHeader
				{
					char idLength;
					char colourMapType;
					char dataType;
					short int colourMapOrigin;
					short int colourMapLength;
					char colourMapDepth;
					short int xOrigin;
					short int yOrigin;
					short int width;
					short int height;
					char bitsPerPixel;
					char imageDescriptor;
				};
			#pragma pack()

			TGAHeader header;
			setMemory(&header, 0, sizeof(header));
			int bytes_per_pixel = 4;
			header.bitsPerPixel = (char)(bytes_per_pixel * 8);
			header.height = (short)height;
			header.width = (short)width;
			header.dataType = 2;

			Lumix::FS::OsFile file;
			if(!file.open(filePath, Lumix::FS::Mode::CREATE | Lumix::FS::Mode::WRITE, m_renderer.m_allocator))
			{
				g_log_error.log("renderer") << "Failed to save screenshot to " << filePath;
				return;
			}
			file.write(&header, sizeof(header));

			file.write(data, size);
			file.close();
		}
Пример #3
0
void ShaderEditor::generate(const char* path, ShaderType shader_type)
{
	char sc_path[Lumix::MAX_PATH_LENGTH];
	Lumix::PathUtils::FileInfo info(path);
	Lumix::copyString(sc_path, info.m_dir);
	Lumix::catString(sc_path, info.m_basename);
	if(shader_type == ShaderType::FRAGMENT)
	{
		Lumix::catString(sc_path, "_fs.sc");
	}
	else
	{
		Lumix::catString(sc_path, "_vs.sc");
	}

	Lumix::FS::OsFile file;
	if(!file.open(sc_path, Lumix::FS::Mode::WRITE | Lumix::FS::Mode::CREATE, m_allocator))
	{
		Lumix::g_log_error.log("Editor") << "Could not create file " << sc_path;
		return;
	}

	Lumix::OutputBlob blob(m_allocator);
	blob.reserve(4096);

	if(shader_type == ShaderType::FRAGMENT)
	{
		blob << "$input ";
		bool first = true;
		bool inputs[(int)VertexOutput::COUNT];
		memset(inputs, 0, sizeof(inputs));
		for (auto* node : m_fragment_nodes)
		{
			if (node->m_type != (int)NodeType::FRAGMENT_INPUT) continue;

			auto* input_node = static_cast<FragmentInputNode*>(node);
			inputs[(int)input_node->m_vertex_output] = true;
		}

		for (int i = 0; i < (int)VertexOutput::COUNT; ++i)
		{
			if(!inputs[i]) continue;
			
			if(!first) blob << ", ";
			blob << getVertexOutputBGFXName((VertexOutput)i);
			first = false;
		}
		blob << "\n";
	}
	else
	{
		writeVertexShaderHeader(blob, m_vertex_nodes);
	}

	blob << "#include \"common.sh\"\n";

	for (int i = 0; i < Lumix::lengthOf(m_textures); ++i)
	{
		if (!m_textures[i][0]) continue;

		blob << "SAMPLER2D(" << m_textures[i] << ", " << i << ");\n";
	}

	auto& nodes = shader_type == ShaderType::FRAGMENT ? m_fragment_nodes : m_vertex_nodes;
	for (auto* node : nodes)
	{
		node->generateBeforeMain(blob);
	}

	blob << "void main() {\n";
	for(auto& node : nodes)
	{
		if (node->m_type == (int)NodeType::FRAGMENT_OUTPUT ||
			node->m_type == (int)NodeType::VERTEX_OUTPUT ||
			node->m_type == (int)NodeType::POSITION_OUTPUT)
		{
			node->generate(blob);
		}
	}
	blob << "}\n";

	file.write(blob.getData(), blob.getSize());
	file.close();
}