Path: blob/master/servers/rendering/dummy/storage/mesh_storage.cpp
10279 views
/**************************************************************************/1/* mesh_storage.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "mesh_storage.h"3132using namespace RendererDummy;3334MeshStorage *MeshStorage::singleton = nullptr;3536MeshStorage::MeshStorage() {37singleton = this;38}3940MeshStorage::~MeshStorage() {41singleton = nullptr;42}4344RID MeshStorage::mesh_allocate() {45return mesh_owner.allocate_rid();46}4748void MeshStorage::mesh_initialize(RID p_rid) {49mesh_owner.initialize_rid(p_rid, DummyMesh());50}5152void MeshStorage::mesh_free(RID p_rid) {53DummyMesh *mesh = mesh_owner.get_or_null(p_rid);54ERR_FAIL_NULL(mesh);55mesh->dependency.deleted_notify(p_rid);56mesh_owner.free(p_rid);57}5859void MeshStorage::mesh_surface_remove(RID p_mesh, int p_surface) {60DummyMesh *m = mesh_owner.get_or_null(p_mesh);61ERR_FAIL_NULL(m);62m->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_MESH);63m->surfaces.remove_at(p_surface);64}6566void MeshStorage::mesh_clear(RID p_mesh) {67DummyMesh *m = mesh_owner.get_or_null(p_mesh);68ERR_FAIL_NULL(m);6970m->surfaces.clear();71}7273RID MeshStorage::_multimesh_allocate() {74return multimesh_owner.allocate_rid();75}7677void MeshStorage::_multimesh_initialize(RID p_rid) {78multimesh_owner.initialize_rid(p_rid, DummyMultiMesh());79}8081void MeshStorage::_multimesh_free(RID p_rid) {82DummyMultiMesh *multimesh = multimesh_owner.get_or_null(p_rid);83ERR_FAIL_NULL(multimesh);8485multimesh_owner.free(p_rid);86}8788void MeshStorage::_multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) {89DummyMultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);90ERR_FAIL_NULL(multimesh);91multimesh->buffer.resize(p_buffer.size());92float *cache_data = multimesh->buffer.ptrw();93memcpy(cache_data, p_buffer.ptr(), p_buffer.size() * sizeof(float));94}9596Vector<float> MeshStorage::_multimesh_get_buffer(RID p_multimesh) const {97DummyMultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);98ERR_FAIL_NULL_V(multimesh, Vector<float>());99100return multimesh->buffer;101}102103104