Copy material schema buffers as new ref

This commit is contained in:
Zach Pomerantz 2016-03-25 11:46:24 -07:00
parent 864def31ea
commit af55547766

View file

@ -18,26 +18,34 @@ using namespace gpu;
Material::Material() : Material::Material() :
_key(0), _key(0),
_schemaBuffer(), _schemaBuffer(),
_textureMaps() { _textureMaps()
{
// only if created from nothing shall we create the Buffer to store the properties // created from nothing: create the Buffer to store the properties
Schema schema; Schema schema;
_schemaBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Schema), (const gpu::Byte*) &schema)); _schemaBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Schema), (const gpu::Byte*) &schema));
} }
Material::Material(const Material& material) : Material::Material(const Material& material) :
_key(material._key), _key(material._key),
_schemaBuffer(material._schemaBuffer), _textureMaps(material._textureMaps)
_textureMaps(material._textureMaps) { {
// copied: create the Buffer to store the properties, avoid holding a ref to the old Buffer
Schema schema;
_schemaBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Schema), (const gpu::Byte*) &schema));
_schemaBuffer.edit<Schema>() = material._schemaBuffer.get<Schema>();
} }
Material& Material::operator= (const Material& material) { Material& Material::operator= (const Material& material) {
_key = (material._key); _key = (material._key);
_schemaBuffer = (material._schemaBuffer);
_textureMaps = (material._textureMaps); _textureMaps = (material._textureMaps);
// copied: create the Buffer to store the properties, avoid holding a ref to the old Buffer
Schema schema;
_schemaBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Schema), (const gpu::Byte*) &schema));
_schemaBuffer.edit<Schema>() = material._schemaBuffer.get<Schema>();
return (*this); return (*this);
} }