mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-22 21:53:35 +00:00
Shader:hasVariable;
This commit is contained in:
parent
e109306048
commit
659222cfaa
|
@ -71,6 +71,14 @@ static int l_lovrShaderHasAttribute(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrShaderHasVariable(lua_State* L) {
|
||||
Shader* shader = luax_checktype(L, 1, Shader);
|
||||
const char* variable = luaL_checkstring(L, 2);
|
||||
bool present = lovrShaderHasVariable(shader, variable);
|
||||
lua_pushboolean(L, present);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrShaderGetWorkgroupSize(lua_State* L) {
|
||||
Shader* shader = luax_checktype(L, 1, Shader);
|
||||
|
||||
|
@ -133,6 +141,7 @@ const luaL_Reg lovrShader[] = {
|
|||
{ "getType", l_lovrShaderGetType },
|
||||
{ "hasStage", l_lovrShaderHasStage },
|
||||
{ "hasAttribute", l_lovrShaderHasAttribute },
|
||||
{ "hasVariable", l_lovrShaderHasVariable },
|
||||
{ "getWorkgroupSize", l_lovrShaderGetWorkgroupSize },
|
||||
{ "getBufferFormat", l_lovrShaderGetBufferFormat },
|
||||
{ NULL, NULL }
|
||||
|
|
|
@ -3341,6 +3341,24 @@ bool lovrShaderHasAttribute(Shader* shader, const char* name, uint32_t location)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool lovrShaderHasVariable(Shader* shader, const char* name) {
|
||||
uint32_t hash = (uint32_t) hash64(name, strlen(name));
|
||||
|
||||
for (uint32_t i = 0; i < shader->uniformCount; i++) {
|
||||
if (shader->uniforms[i].hash == hash) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < shader->resourceCount; i++) {
|
||||
if (shader->resources[i].hash == hash) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void lovrShaderGetWorkgroupSize(Shader* shader, uint32_t size[3]) {
|
||||
memcpy(size, shader->workgroupSize, 3 * sizeof(uint32_t));
|
||||
}
|
||||
|
|
|
@ -333,6 +333,7 @@ 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);
|
||||
bool lovrShaderHasVariable(Shader* shader, const char* name);
|
||||
void lovrShaderGetWorkgroupSize(Shader* shader, uint32_t size[3]);
|
||||
const DataField* lovrShaderGetBufferFormat(Shader* shader, const char* name, uint32_t* fieldCount);
|
||||
|
||||
|
|
|
@ -446,4 +446,22 @@ group('graphics', function()
|
|||
expect({ image:getPixel(0, 0) }).to.equal({ 0, 0, 1, 1 })
|
||||
end)
|
||||
end)
|
||||
|
||||
group('Shader', function()
|
||||
test(':hasVariable', function()
|
||||
shader = lovr.graphics.newShader([[
|
||||
uniform vec3 position;
|
||||
vec4 lovrmain() { return vec4(position, 1.); }
|
||||
]], [[
|
||||
buffer Params { vec4 color; };
|
||||
uniform texture2D image;
|
||||
vec4 lovrmain() { return color; }
|
||||
]])
|
||||
|
||||
expect(shader:hasVariable('position')).to.equal(true)
|
||||
expect(shader:hasVariable('unknown')).to.equal(false)
|
||||
expect(shader:hasVariable('Params')).to.equal(true)
|
||||
expect(shader:hasVariable('image')).to.equal(true)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
Loading…
Reference in a new issue