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(); } }
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); }
bool Shader::load(FS::IFile& file) { lua_State* L = luaL_newstate(); luaL_openlibs(L); registerFunctions(this, &m_combintions, &getRenderer(), L); m_render_states = BGFX_STATE_DEPTH_TEST_LEQUAL; bool errors = luaL_loadbuffer(L, (const char*)file.getBuffer(), file.size(), "") != LUA_OK; errors = errors || lua_pcall(L, 0, 0, 0) != LUA_OK; if (errors) { g_log_error.log("Renderer") << getPath().c_str() << ": " << lua_tostring(L, -1); lua_pop(L, 1); return false; } if (!generateInstances()) { g_log_error.log("Renderer") << "Could not load instances of shader " << getPath().c_str(); return false; } m_size = file.size(); lua_close(L); return true; }
bool LuaScript::load(FS::IFile& file) { m_properties.clear(); m_source_code.set((const char*)file.getBuffer(), (int)file.size()); parseProperties(); m_size = file.size(); return true; }
bool Texture::loadDDS(FS::IFile& file) { bgfx::TextureInfo info; m_texture_handle = bgfx::createTexture( bgfx::copy(file.getBuffer(), file.size()), 0, 0, &info); m_BPP = -1; m_width = info.width; m_height = info.height; return bgfx::isValid(m_texture_handle); }
bool Clip::load(FS::IFile& file) { short* output = nullptr; auto res = stb_vorbis_decode_memory( (unsigned char*)file.getBuffer(), (int)file.size(), &m_channels, &m_sample_rate, &output); if (res <= 0) return false; m_data.resize(res * m_channels); copyMemory(&m_data[0], output, res * m_channels * sizeof(m_data[0])); free(output); return true; }
void LuaScript::loaded(FS::IFile& file, bool success, FS::FileSystem& fs) { if (success) { m_source_code.set((const char*)file.getBuffer(), file.size()); parseProperties(); m_size = file.size(); decrementDepCount(); } else { g_log_error.log("lua_script") << "Could not load script " << m_path.c_str(); onFailure(); } }