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(); }
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(); }
bool Settings::save() { auto& actions = m_app.getActions(); Lumix::FS::OsFile file; auto& allocator = m_app.getWorldEditor()->getAllocator(); if (!file.open(SETTINGS_PATH, Lumix::FS::Mode::CREATE_AND_WRITE, allocator)) return false; file << "window = { x = " << m_window.x << ", y = " << m_window.y << ", w = " << m_window.w << ", h = " << m_window.h << " }\n"; file << "maximized = " << (m_is_maximized ? "true" : "false") << "\n"; auto writeBool = [&file](const char* name, bool value) { file << name << " = " << (value ? "true\n" : "false\n"); }; writeBool("settings_opened", m_is_opened); writeBool("asset_browser_opened", m_is_asset_browser_opened); writeBool("entity_list_opened", m_is_entity_list_opened); writeBool("entity_template_list_opened", m_is_entity_template_list_opened); writeBool("log_opened", m_is_log_opened); writeBool("profiler_opened", m_is_profiler_opened); writeBool("properties_opened", m_is_properties_opened); writeBool("error_reporting_enabled", m_is_crash_reporting_enabled); file << "mouse_sensitivity_x = " << m_mouse_sensitivity_x << "\n"; file << "mouse_sensitivity_y = " << m_mouse_sensitivity_y << "\n"; saveStyle(file); file << "data_dir = \""; const char* c = m_data_dir; while (*c) { if (*c == '\\') file << "\\\\"; else file << *c; ++c; } file << "\"\n"; file << "custom = {\n"; lua_getglobal(m_state, "custom"); lua_pushnil(m_state); bool first = true; while (lua_next(m_state, -2)) { if (!first) file << ",\n"; const char* name = lua_tostring(m_state, -2); switch (lua_type(m_state, -1)) { case LUA_TBOOLEAN: file << name << " = " << (lua_toboolean(m_state, -1) != 0 ? "true" : "false"); break; case LUA_TNUMBER: file << name << " = " << (int)lua_tonumber(m_state, -1); break; default: ASSERT(false); break; } lua_pop(m_state, 1); first = false; } lua_pop(m_state, 1); file << "}\n"; file << "actions = {\n"; for (int i = 0; i < actions.size(); ++i) { file << "\t" << actions[i]->name << " = {" << actions[i]->shortcut[0] << ", " << actions[i]->shortcut[1] << ", " << actions[i]->shortcut[2] << "},\n"; } file << "}\n"; file << "toolbar = {\n"; for (auto* action : m_app.getToolbarActions()) { file << "\t\"" << action->name << "\",\n"; } file << "}\n"; ImGui::SaveDock(file); file.close(); return true; }
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(); } }