mirror of https://github.com/bjornbytes/lovr.git
Shader:hasBlock; Shader:sendBlock errors on missing block;
This commit is contained in:
parent
a1a53b4bed
commit
c9c5d43829
|
@ -197,6 +197,13 @@ static int l_lovrShaderHasUniform(lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_lovrShaderHasBlock(lua_State* L) {
|
||||||
|
Shader* shader = luax_checktype(L, 1, Shader);
|
||||||
|
const char* name = luaL_checkstring(L, 2);
|
||||||
|
lua_pushboolean(L, lovrShaderHasBlock(shader, name));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_lovrShaderSend(lua_State* L) {
|
static int l_lovrShaderSend(lua_State* L) {
|
||||||
Shader* shader = luax_checktype(L, 1, Shader);
|
Shader* shader = luax_checktype(L, 1, Shader);
|
||||||
const char* name = luaL_checkstring(L, 2);
|
const char* name = luaL_checkstring(L, 2);
|
||||||
|
@ -222,6 +229,7 @@ static int l_lovrShaderSend(lua_State* L) {
|
||||||
static int l_lovrShaderSendBlock(lua_State* L) {
|
static int l_lovrShaderSendBlock(lua_State* L) {
|
||||||
Shader* shader = luax_checktype(L, 1, Shader);
|
Shader* shader = luax_checktype(L, 1, Shader);
|
||||||
const char* name = luaL_checkstring(L, 2);
|
const char* name = luaL_checkstring(L, 2);
|
||||||
|
lovrAssert(lovrShaderHasBlock(shader, name), "Unknown shader block '%s'", name);
|
||||||
ShaderBlock* block = luax_checktype(L, 3, ShaderBlock);
|
ShaderBlock* block = luax_checktype(L, 3, ShaderBlock);
|
||||||
UniformAccess access = luaL_checkoption(L, 4, "readwrite", UniformAccesses);
|
UniformAccess access = luaL_checkoption(L, 4, "readwrite", UniformAccesses);
|
||||||
Buffer* buffer = lovrShaderBlockGetBuffer(block);
|
Buffer* buffer = lovrShaderBlockGetBuffer(block);
|
||||||
|
@ -251,6 +259,7 @@ static int l_lovrShaderSendImage(lua_State* L) {
|
||||||
const luaL_Reg lovrShader[] = {
|
const luaL_Reg lovrShader[] = {
|
||||||
{ "getType", l_lovrShaderGetType },
|
{ "getType", l_lovrShaderGetType },
|
||||||
{ "hasUniform", l_lovrShaderHasUniform },
|
{ "hasUniform", l_lovrShaderHasUniform },
|
||||||
|
{ "hasBlock", l_lovrShaderHasBlock },
|
||||||
{ "send", l_lovrShaderSend },
|
{ "send", l_lovrShaderSend },
|
||||||
{ "sendBlock", l_lovrShaderSendBlock },
|
{ "sendBlock", l_lovrShaderSendBlock },
|
||||||
{ "sendImage", l_lovrShaderSendImage },
|
{ "sendImage", l_lovrShaderSendImage },
|
||||||
|
|
|
@ -86,6 +86,10 @@ bool lovrShaderHasUniform(Shader* shader, const char* name) {
|
||||||
return map_get(&shader->uniformMap, hash64(name, strlen(name))) != MAP_NIL;
|
return map_get(&shader->uniformMap, hash64(name, strlen(name))) != MAP_NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool lovrShaderHasBlock(Shader* shader, const char* name) {
|
||||||
|
return map_get(&shader->blockMap, hash64(name, strlen(name))) != MAP_NIL;
|
||||||
|
}
|
||||||
|
|
||||||
const Uniform* lovrShaderGetUniform(Shader* shader, const char* name) {
|
const Uniform* lovrShaderGetUniform(Shader* shader, const char* name) {
|
||||||
uint64_t index = map_get(&shader->uniformMap, hash64(name, strlen(name)));
|
uint64_t index = map_get(&shader->uniformMap, hash64(name, strlen(name)));
|
||||||
return index == MAP_NIL ? NULL : &shader->uniforms.data[index];
|
return index == MAP_NIL ? NULL : &shader->uniforms.data[index];
|
||||||
|
|
|
@ -133,6 +133,7 @@ void lovrShaderDestroy(void* ref);
|
||||||
ShaderType lovrShaderGetType(Shader* shader);
|
ShaderType lovrShaderGetType(Shader* shader);
|
||||||
int lovrShaderGetAttributeLocation(Shader* shader, const char* name);
|
int lovrShaderGetAttributeLocation(Shader* shader, const char* name);
|
||||||
bool lovrShaderHasUniform(Shader* shader, const char* name);
|
bool lovrShaderHasUniform(Shader* shader, const char* name);
|
||||||
|
bool lovrShaderHasBlock(Shader* shader, const char* name);
|
||||||
const Uniform* lovrShaderGetUniform(Shader* shader, const char* name);
|
const Uniform* lovrShaderGetUniform(Shader* shader, const char* name);
|
||||||
void lovrShaderSetFloats(Shader* shader, const char* name, float* data, int start, int count);
|
void lovrShaderSetFloats(Shader* shader, const char* name, float* data, int start, int count);
|
||||||
void lovrShaderSetInts(Shader* shader, const char* name, int* data, int start, int count);
|
void lovrShaderSetInts(Shader* shader, const char* name, int* data, int start, int count);
|
||||||
|
|
Loading…
Reference in New Issue