Split Mesh:attachAttribute(name, nil) out into Mesh:detachAttribute. Fix attachAttribute.

Don’t let me push commits on a friday night…

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-11-26 01:50:36 -04:00
parent 100404c917
commit cbba8c40a6
4 changed files with 40 additions and 26 deletions
+25 -18
View File
@@ -311,24 +311,7 @@ bool Mesh::isAttributeEnabled(const std::string &name) const
void Mesh::attachAttribute(const std::string &name, Mesh *mesh, const std::string &attachname)
{
AttachedAttribute oldattrib = {};
auto it = attachedAttributes.find(name);
if (it != attachedAttributes.end())
oldattrib = it->second;
if (mesh == nullptr)
{
if (it != attachedAttributes.end() && oldattrib.mesh != this)
{
oldattrib.mesh->release();
attachedAttributes.erase(it);
if (getAttributeIndex(name) != -1)
attachAttribute(name, this, name);
return;
}
}
else if (mesh != this)
if (mesh != this)
{
for (const auto &it : mesh->attachedAttributes)
{
@@ -339,7 +322,13 @@ void Mesh::attachAttribute(const std::string &name, Mesh *mesh, const std::strin
}
}
AttachedAttribute oldattrib = {};
AttachedAttribute newattrib = {};
auto it = attachedAttributes.find(name);
if (it != attachedAttributes.end())
oldattrib = it->second;
newattrib.mesh = mesh;
newattrib.enabled = oldattrib.mesh ? oldattrib.enabled : true;
newattrib.index = mesh->getAttributeIndex(attachname);
@@ -356,6 +345,24 @@ void Mesh::attachAttribute(const std::string &name, Mesh *mesh, const std::strin
oldattrib.mesh->release();
}
bool Mesh::detachAttribute(const std::string &name)
{
auto it = attachedAttributes.find(name);
if (it != attachedAttributes.end() && it->second.mesh != this)
{
it->second.mesh->release();
attachedAttributes.erase(it);
if (getAttributeIndex(name) != -1)
attachAttribute(name, this, name);
return true;
}
return false;
}
void *Mesh::mapVertexData()
{
return vbo->map();
+1
View File
@@ -139,6 +139,7 @@ public:
* will be used when drawing this Mesh.
**/
void attachAttribute(const std::string &name, Mesh *mesh, const std::string &attachname);
bool detachAttribute(const std::string &name);
void *mapVertexData();
void unmapVertexData(size_t modifiedoffset = 0, size_t modifiedsize = -1);
+1 -1
View File
@@ -679,7 +679,7 @@ void Shader::sendTextures(const UniformInfo *info, Texture **textures, int count
return;
count = std::min(count, info->count);
bool updateuniform = internalUpdate;
bool updateuniform = false;
// Make sure the shader's samplers are associated with texture units.
for (int i = 0; i < count; i++)
+13 -7
View File
@@ -337,17 +337,22 @@ int w_Mesh_attachAttribute(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
const char *name = luaL_checkstring(L, 2);
const char *attachname = name;
Mesh *mesh = nullptr;
if (lua_isnoneornil(L, 3))
{
mesh = luax_checkmesh(L, 3);
attachname = luaL_optstring(L, 4, attachname);
}
Mesh *mesh = luax_checkmesh(L, 3);
const char *attachname = luaL_optstring(L, 4, name);
luax_catchexcept(L, [&](){ t->attachAttribute(name, mesh, attachname); });
return 0;
}
int w_Mesh_detachAttribute(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
const char *name = luaL_checkstring(L, 2);
bool success = false;
luax_catchexcept(L, [&](){ success = t->detachAttribute(name); });
luax_pushboolean(L, success);
return 1;
}
int w_Mesh_flush(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
@@ -520,6 +525,7 @@ static const luaL_Reg w_Mesh_functions[] =
{ "setAttributeEnabled", w_Mesh_setAttributeEnabled },
{ "isAttributeEnabled", w_Mesh_isAttributeEnabled },
{ "attachAttribute", w_Mesh_attachAttribute },
{ "detachAttribute", w_Mesh_detachAttribute },
{ "flush", w_Mesh_flush },
{ "setVertexMap", w_Mesh_setVertexMap },
{ "getVertexMap", w_Mesh_getVertexMap },