love.graphics.newComputeShader;

This commit is contained in:
bjorn
2021-07-07 18:40:16 -07:00
parent b28e61d00d
commit 13a10ac482
3 changed files with 42 additions and 0 deletions
+12
View File
@@ -294,6 +294,18 @@ Shader *Graphics::newShader(const std::vector<std::string> &stagessource)
return newShaderInternal(stages);
}
Shader *Graphics::newComputeShader(const std::string &source)
{
Shader::SourceInfo info = Shader::getSourceInfo(source);
if (info.stages[SHADERSTAGE_COMPUTE] == Shader::ENTRYPOINT_NONE)
throw love::Exception("Could not parse compute shader code (missing 'computemain' function?)");
StrongRef<ShaderStage> stages[SHADERSTAGE_MAX_ENUM];
stages[SHADERSTAGE_COMPUTE].set(newShaderStage(SHADERSTAGE_COMPUTE, source, info));
return newShaderInternal(stages);
}
Buffer *Graphics::newBuffer(const Buffer::Settings &settings, DataFormat format, const void *data, size_t size, size_t arraylength)
{
std::vector<Buffer::DataDeclaration> dataformat = {{"", format, 0}};
+1
View File
@@ -439,6 +439,7 @@ public:
ParticleSystem *newParticleSystem(Texture *texture, int size);
Shader *newShader(const std::vector<std::string> &stagessource);
Shader *newComputeShader(const std::string &source);
virtual Buffer *newBuffer(const Buffer::Settings &settings, const std::vector<Buffer::DataDeclaration> &format, const void *data, size_t size, size_t arraylength) = 0;
virtual Buffer *newBuffer(const Buffer::Settings &settings, DataFormat format, const void *data, size_t size, size_t arraylength);
+29
View File
@@ -1458,6 +1458,34 @@ int w_newShader(lua_State *L)
return 1;
}
int w_newComputeShader(lua_State* L)
{
std::vector<std::string> stages;
w_getShaderSource(L, 1, stages);
bool should_error = false;
try
{
Shader *shader = instance()->newComputeShader(stages[0]);
luax_pushtype(L, shader);
shader->release();
}
catch (love::Exception &e)
{
luax_getfunction(L, "graphics", "_transformGLSLErrorMessages");
lua_pushstring(L, e.what());
// Function pushes the new error string onto the stack.
lua_pcall(L, 1, 1, 0);
should_error = true;
}
if (should_error)
return lua_error(L);
return 1;
}
int w_validateShader(lua_State *L)
{
bool gles = luax_checkboolean(L, 1);
@@ -3415,6 +3443,7 @@ static const luaL_Reg functions[] =
{ "newSpriteBatch", w_newSpriteBatch },
{ "newParticleSystem", w_newParticleSystem },
{ "newShader", w_newShader },
{ "newComputeShader", w_newComputeShader },
{ "newBuffer", w_newBuffer },
{ "newVertexBuffer", w_newVertexBuffer },
{ "newIndexBuffer", w_newIndexBuffer },