Line data Source code
1 : /** 2 : Copyright (c) 2023 Stappler LLC <admin@stappler.dev> 3 : 4 : Permission is hereby granted, free of charge, to any person obtaining a copy 5 : of this software and associated documentation files (the "Software"), to deal 6 : in the Software without restriction, including without limitation the rights 7 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 : copies of the Software, and to permit persons to whom the Software is 9 : furnished to do so, subject to the following conditions: 10 : 11 : The above copyright notice and this permission notice shall be included in 12 : all copies or substantial portions of the Software. 13 : 14 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 : THE SOFTWARE. 21 : **/ 22 : 23 : #include "XLCoreMesh.h" 24 : #include "XLCoreObject.h" 25 : 26 : namespace STAPPLER_VERSIONIZED stappler::xenolith::core { 27 : 28 0 : MeshSet::~MeshSet() { } 29 : 30 0 : bool MeshSet::init(Vector<Index> &&idx, BufferObject *index, BufferObject *vertex) { 31 0 : _indexes = move(idx); 32 0 : _indexBuffer = index; 33 0 : _vertexBuffer = vertex; 34 0 : return true; 35 : } 36 : 37 0 : void MeshSet::clear() { 38 0 : _indexes.clear(); 39 0 : _vertexBuffer = nullptr; 40 0 : _indexBuffer = nullptr; 41 0 : } 42 : 43 0 : MeshIndex::~MeshIndex() { } 44 : 45 0 : bool MeshIndex::init(StringView name, Rc<DataAtlas> &&atlas, MeshBufferInfo &&bufferInfo) { 46 0 : Resource::Builder builder(name); 47 : 48 0 : _atlas = move(atlas); 49 0 : _indexBuffer = builder.addBuffer(toString(name, ":index"), 50 0 : BufferInfo(bufferInfo.indexBufferSize, ForceBufferUsage(BufferUsage::TransferSrc)), 51 0 : bufferInfo.indexBufferCallback); 52 : 53 0 : _vertexBuffer = builder.addBuffer(toString(name, ":vertex"), 54 0 : BufferInfo(bufferInfo.vertexBufferSize, ForceBufferUsage(BufferUsage::TransferSrc)), 55 0 : bufferInfo.vertexBufferCallback); 56 : 57 0 : return Resource::init(move(builder)); 58 0 : } 59 : 60 0 : MeshAttachment::~MeshAttachment() { } 61 : 62 0 : bool MeshAttachment::init(AttachmentBuilder &builder, const BufferInfo &info, Vector<Rc<MeshIndex>> &&initials) { 63 0 : if (!BufferAttachment::init(builder, info)) { 64 0 : return false; 65 : } 66 : 67 0 : _initials = move(initials); 68 0 : return true; 69 : } 70 : 71 0 : const Rc<MeshSet> &MeshAttachment::getMeshes() const { 72 0 : return _data; 73 : } 74 : 75 0 : void MeshAttachment::setMeshes(const Rc<MeshSet> &data) const { 76 0 : auto tmp = _data; 77 0 : _data = data; 78 0 : if (tmp) { 79 0 : tmp->clear(); 80 : } 81 0 : } 82 : 83 : }