mirror of https://github.com/bjornbytes/lovr.git
Shader:hasAttribute;
This commit is contained in:
parent
2c339dd944
commit
8aa14ba42b
|
@ -48,9 +48,26 @@ static int l_lovrShaderHasStage(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrShaderHasAttribute(lua_State* L) {
|
||||
Shader* shader = luax_checktype(L, 1, Shader);
|
||||
const char* name;
|
||||
uint32_t location;
|
||||
if (lua_type(L, 2) == LUA_TNUMBER) {
|
||||
location = luax_checku32(L, 2);
|
||||
name = NULL;
|
||||
} else {
|
||||
name = lua_tostring(L, 2);
|
||||
location = 0;
|
||||
}
|
||||
bool present = lovrShaderHasAttribute(shader, name, location);
|
||||
lua_pushboolean(L, present);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg lovrShader[] = {
|
||||
{ "clone", l_lovrShaderClone },
|
||||
{ "getType", l_lovrShaderGetType },
|
||||
{ "hasStage", l_lovrShaderHasStage },
|
||||
{ "hasAttribute", l_lovrShaderHasAttribute },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
|
@ -1722,6 +1722,17 @@ bool lovrShaderHasStage(Shader* shader, ShaderStage stage) {
|
|||
}
|
||||
}
|
||||
|
||||
bool lovrShaderHasAttribute(Shader* shader, const char* name, uint32_t location) {
|
||||
uint32_t hash = name ? (uint32_t) hash64(name, strlen(name)) : 0;
|
||||
for (uint32_t i = 0; i < shader->attributeCount; i++) {
|
||||
ShaderAttribute* attribute = &shader->attributes[i];
|
||||
if (name ? (attribute->hash == hash) : (attribute->location == location)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Material
|
||||
|
||||
Material* lovrMaterialCreate(MaterialInfo* info) {
|
||||
|
|
|
@ -290,6 +290,7 @@ Shader* lovrShaderClone(Shader* parent, ShaderFlag* flags, uint32_t count);
|
|||
void lovrShaderDestroy(void* ref);
|
||||
const ShaderInfo* lovrShaderGetInfo(Shader* shader);
|
||||
bool lovrShaderHasStage(Shader* shader, ShaderStage stage);
|
||||
bool lovrShaderHasAttribute(Shader* shader, const char* name, uint32_t location);
|
||||
|
||||
// Material
|
||||
|
||||
|
|
Loading…
Reference in New Issue