4aiman wrote: ↑Thu Feb 04, 2021 9:15 am
The question implied I'd like to know why the thing isn't defined when it clearly (to me anyway) is.
The error doesn't say that it isn't defined. It says that it doesn't exist. The help text says that a common error is to
define (hence it
is defined) but then not
use the variable.
While it doesn't seem to be the case of your driver (because it worked, at the end), for some drivers it happens that when a variable is defined but then not used, the GLSL compiler optimizes out that variable, and when trying to send values to it, the variable no longer exists. It's a fairly common gotcha: a program works just fine in your system, but when sending it to someone who has a driver that optimizes the variable out, it suddenly crashes with that error.
For example, this main.lua crashes with my graphics driver, but not with some others:
Code: Select all
love.graphics.newShader[[
uniform float x; // defined, but not used anywhere
vec4 effect(vec4 col, Image tex, vec2 texpos, vec2 scrpos) { return col * Texel(tex, texpos); }
]]:send('x', 1) -- 'x' is optimized out and this causes an error because it doesn't exist
4aiman wrote: ↑Thu Feb 04, 2021 9:15 am
In the original it is separated into two lines, but I have no idea why.
I don't know much GLSL, but by analogy with C, lines starting with # are preprocessor directives, and they consist of a single line (except when the last character in the line is a \ symbol, which means that it continues on the next line). In the case of #define, it defines a macro with the name that appears immediately after #define, to be everything between the next non-blank character after the name, and the end of the line. In this case, the idea was to define the macro 'LIGHTS' to be '16', but the way you wrote it, it was defining the macro 'LIGHTS' to be '16 uniform PointLight pointLights[LIGHTS];'. These macros are text replacement macros; if 'LIGHTS' was used anywhere else, it would be replaced by '16 uniform PointLight pointLights[LIGHTS];', most likely causing a syntax error.
Apologies to Groverburger for diverting his thread even more.