|
@@ -5,9 +5,9 @@ return {
|
|
defined in its source code. This can be a tedious process, so you can call this function to
|
|
defined in its source code. This can be a tedious process, so you can call this function to
|
|
return a GLSL string that contains this definition. Roughly, it will look something like this:
|
|
return a GLSL string that contains this definition. Roughly, it will look something like this:
|
|
|
|
|
|
- uniform <label> {
|
|
|
|
|
|
+ layout(std140) uniform <label> {
|
|
<type> <name>[<count>];
|
|
<type> <name>[<count>];
|
|
- };
|
|
|
|
|
|
+ } <namespace>;
|
|
]],
|
|
]],
|
|
arguments = {
|
|
arguments = {
|
|
{
|
|
{
|
|
@@ -15,7 +15,17 @@ return {
|
|
type = 'string',
|
|
type = 'string',
|
|
description = [[
|
|
description = [[
|
|
The label of the block in the shader code. This will be used to identify it when using
|
|
The label of the block in the shader code. This will be used to identify it when using
|
|
- Shader:sendBlock.
|
|
|
|
|
|
+ `Shader:sendBlock`.
|
|
|
|
+ ]]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ name = 'namespace',
|
|
|
|
+ type = 'string',
|
|
|
|
+ default = 'nil',
|
|
|
|
+ description = [[
|
|
|
|
+ The namespace to use when accessing the block's variables in the shader code. This can be
|
|
|
|
+ used to prevent naming conflicts if two blocks have variables with the same name. If the
|
|
|
|
+ namespace is nil, the block's variables will be available in the global scope.
|
|
]]
|
|
]]
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -23,15 +33,31 @@ return {
|
|
{
|
|
{
|
|
name = 'code',
|
|
name = 'code',
|
|
type = 'string',
|
|
type = 'string',
|
|
- description = 'The code that can be prepended to a Shader.'
|
|
|
|
|
|
+ description = 'The code that can be prepended to `Shader` code.'
|
|
}
|
|
}
|
|
},
|
|
},
|
|
example = [=[
|
|
example = [=[
|
|
- lovr.graphics.newShader(
|
|
|
|
- block:getShaderCode() .. [[
|
|
|
|
- // The rest of the shader here
|
|
|
|
- ]]
|
|
|
|
- )
|
|
|
|
|
|
+ block = lovr.graphics.newShaderBlock('uniform', {
|
|
|
|
+ sizes = { 'float', 10 }
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ code = [[
|
|
|
|
+ #ifdef VERTEX
|
|
|
|
+ ]] .. block:getShaderCode('MyBlock', 'sizeBlock') .. [[
|
|
|
|
+
|
|
|
|
+ // vertex shader goes here,
|
|
|
|
+ // it can access sizeBlock.sizes
|
|
|
|
+
|
|
|
|
+ ]]
|
|
|
|
+ #endif
|
|
|
|
+
|
|
|
|
+ #ifdef PIXEL
|
|
|
|
+ // fragment shader goes here
|
|
|
|
+ #endif
|
|
|
|
+ ]]
|
|
|
|
+
|
|
|
|
+ shader = lovr.graphics.newShader(code, code)
|
|
|
|
+ shader:sendBlock('MyBlock', block)
|
|
]=],
|
|
]=],
|
|
related = {
|
|
related = {
|
|
'lovr.graphics.newShader',
|
|
'lovr.graphics.newShader',
|