Add computeshaders to lovr.graphics.getSupported;

This commit is contained in:
bjorn 2018-08-08 18:03:46 -07:00
parent 3b51056870
commit 98e518683a
3 changed files with 11 additions and 4 deletions

View File

@ -336,8 +336,10 @@ int l_lovrGraphicsGetDimensions(lua_State* L) {
int l_lovrGraphicsGetSupported(lua_State* L) {
GraphicsFeatures features = lovrGraphicsGetSupported();
lua_newtable(L);
lua_pushboolean(L, features.computeShaders);
lua_setfield(L, -2, "computeshaders");
lua_pushboolean(L, features.writableBlocks);
lua_setfield(L, -2, "writableBlocks");
lua_setfield(L, -2, "writableblocks");
return 1;
}
@ -859,9 +861,9 @@ int l_lovrGraphicsFill(lua_State* L) {
int l_lovrGraphicsCompute(lua_State* L) {
Shader* shader = luax_checktype(L, 1, Shader);
int x = luaL_optinteger(L, 1, 1);
int y = luaL_optinteger(L, 2, 1);
int z = luaL_optinteger(L, 3, 1);
int x = luaL_optinteger(L, 2, 1);
int y = luaL_optinteger(L, 3, 1);
int z = luaL_optinteger(L, 4, 1);
lovrGraphicsCompute(shader, x, y, z);
return 0;
}

View File

@ -68,6 +68,7 @@ typedef enum {
} Winding;
typedef struct {
bool computeShaders;
bool writableBlocks;
} GraphicsFeatures;

View File

@ -854,6 +854,7 @@ void lovrGpuDraw(DrawCommand* command) {
}
void lovrGpuCompute(Shader* shader, int x, int y, int z) {
lovrAssert(GLAD_GL_ARB_compute_shader, "Compute shaders are not supported on this system");
lovrAssert(shader->type == SHADER_COMPUTE, "Attempt to use a non-compute shader for a compute operation");
lovrGpuUseProgram(shader->program);
glDispatchCompute(x, y, z);
@ -870,8 +871,10 @@ void lovrGpuPresent() {
GraphicsFeatures lovrGraphicsGetSupported() {
return (GraphicsFeatures) {
#ifdef EMSCRIPTEN
.computeShaders = false,
.writableBlocks = false
#else
.computeShaders = GLAD_GL_ARB_compute_shader,
.writableBlocks = GLAD_GL_ARB_shader_storage_buffer_object
#endif
};
@ -1517,6 +1520,7 @@ Shader* lovrShaderCreateCompute(const char* source) {
Shader* shader = lovrAlloc(Shader, lovrShaderDestroy);
if (!shader) return NULL;
lovrAssert(GLAD_GL_ARB_compute_shader, "Compute shaders are not supported on this system");
const char* sources[] = { source, lovrShaderComputeSuffix };
GLuint computeShader = compileShader(GL_COMPUTE_SHADER, sources, sizeof(sources) / sizeof(sources[0]));
GLuint program = glCreateProgram();