mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
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:
@@ -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)
|
void Mesh::attachAttribute(const std::string &name, Mesh *mesh, const std::string &attachname)
|
||||||
{
|
{
|
||||||
AttachedAttribute oldattrib = {};
|
if (mesh != this)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
for (const auto &it : mesh->attachedAttributes)
|
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 = {};
|
AttachedAttribute newattrib = {};
|
||||||
|
|
||||||
|
auto it = attachedAttributes.find(name);
|
||||||
|
if (it != attachedAttributes.end())
|
||||||
|
oldattrib = it->second;
|
||||||
|
|
||||||
newattrib.mesh = mesh;
|
newattrib.mesh = mesh;
|
||||||
newattrib.enabled = oldattrib.mesh ? oldattrib.enabled : true;
|
newattrib.enabled = oldattrib.mesh ? oldattrib.enabled : true;
|
||||||
newattrib.index = mesh->getAttributeIndex(attachname);
|
newattrib.index = mesh->getAttributeIndex(attachname);
|
||||||
@@ -356,6 +345,24 @@ void Mesh::attachAttribute(const std::string &name, Mesh *mesh, const std::strin
|
|||||||
oldattrib.mesh->release();
|
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()
|
void *Mesh::mapVertexData()
|
||||||
{
|
{
|
||||||
return vbo->map();
|
return vbo->map();
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ public:
|
|||||||
* will be used when drawing this Mesh.
|
* will be used when drawing this Mesh.
|
||||||
**/
|
**/
|
||||||
void attachAttribute(const std::string &name, Mesh *mesh, const std::string &attachname);
|
void attachAttribute(const std::string &name, Mesh *mesh, const std::string &attachname);
|
||||||
|
bool detachAttribute(const std::string &name);
|
||||||
|
|
||||||
void *mapVertexData();
|
void *mapVertexData();
|
||||||
void unmapVertexData(size_t modifiedoffset = 0, size_t modifiedsize = -1);
|
void unmapVertexData(size_t modifiedoffset = 0, size_t modifiedsize = -1);
|
||||||
|
|||||||
@@ -679,7 +679,7 @@ void Shader::sendTextures(const UniformInfo *info, Texture **textures, int count
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
count = std::min(count, info->count);
|
count = std::min(count, info->count);
|
||||||
bool updateuniform = internalUpdate;
|
bool updateuniform = false;
|
||||||
|
|
||||||
// Make sure the shader's samplers are associated with texture units.
|
// Make sure the shader's samplers are associated with texture units.
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
|
|||||||
@@ -337,17 +337,22 @@ int w_Mesh_attachAttribute(lua_State *L)
|
|||||||
{
|
{
|
||||||
Mesh *t = luax_checkmesh(L, 1);
|
Mesh *t = luax_checkmesh(L, 1);
|
||||||
const char *name = luaL_checkstring(L, 2);
|
const char *name = luaL_checkstring(L, 2);
|
||||||
const char *attachname = name;
|
Mesh *mesh = luax_checkmesh(L, 3);
|
||||||
Mesh *mesh = nullptr;
|
const char *attachname = luaL_optstring(L, 4, name);
|
||||||
if (lua_isnoneornil(L, 3))
|
|
||||||
{
|
|
||||||
mesh = luax_checkmesh(L, 3);
|
|
||||||
attachname = luaL_optstring(L, 4, attachname);
|
|
||||||
}
|
|
||||||
luax_catchexcept(L, [&](){ t->attachAttribute(name, mesh, attachname); });
|
luax_catchexcept(L, [&](){ t->attachAttribute(name, mesh, attachname); });
|
||||||
return 0;
|
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)
|
int w_Mesh_flush(lua_State *L)
|
||||||
{
|
{
|
||||||
Mesh *t = luax_checkmesh(L, 1);
|
Mesh *t = luax_checkmesh(L, 1);
|
||||||
@@ -520,6 +525,7 @@ static const luaL_Reg w_Mesh_functions[] =
|
|||||||
{ "setAttributeEnabled", w_Mesh_setAttributeEnabled },
|
{ "setAttributeEnabled", w_Mesh_setAttributeEnabled },
|
||||||
{ "isAttributeEnabled", w_Mesh_isAttributeEnabled },
|
{ "isAttributeEnabled", w_Mesh_isAttributeEnabled },
|
||||||
{ "attachAttribute", w_Mesh_attachAttribute },
|
{ "attachAttribute", w_Mesh_attachAttribute },
|
||||||
|
{ "detachAttribute", w_Mesh_detachAttribute },
|
||||||
{ "flush", w_Mesh_flush },
|
{ "flush", w_Mesh_flush },
|
||||||
{ "setVertexMap", w_Mesh_setVertexMap },
|
{ "setVertexMap", w_Mesh_setVertexMap },
|
||||||
{ "getVertexMap", w_Mesh_getVertexMap },
|
{ "getVertexMap", w_Mesh_getVertexMap },
|
||||||
|
|||||||
Reference in New Issue
Block a user