Kha
Kha copied to clipboard
WebGL: INVALID_OPERATION: uniform1f: location not for current program
When I call g4.setFloat to pass the value to my shader I got this error (for all targets): "WebGL: INVALID_OPERATION: uniform1f: location not for current program"
but I am sure that I gave the correct location. This is a minimal example causing an error: https://drive.google.com/file/d/1fISYMHDRkUmGjCvoI56jLZ6EqvDcdNXB/view
You're mixing g2 and g4 calls in Main.render()
, that's pretty much undefined behavior. End g2
and begin g4
before you try to access anything, or from the looks of it just use g4
in the first place.
The same goes for every access to a graphics api. First begin, then do stuff, then end. In the Assets.loadEverything callback you have: _backbuffer.g2.imageScaleQuality=ImageScaleQuality.High;
This might work without begin/end, but don't rely on it, as you never know how it's implemented for different targets.
But... but... I told him to report this as a bug. In this special instance mixing them should work because g2 doesn't provide an alternative. Or maybe I'll do the latter, don't know yet.
You're mixing g2 and g4 calls in
Main.render()
, that's pretty much undefined behavior. Endg2
and beging4
before you try to access anything, or from the looks of it just useg4
in the first place.
I found this solution here https://bitbucket.org/stalei/khapunk/wiki/Renderingshaders.md
"Let's say our custom fragment shader has a uniform vec2 resolution. If we want to change the values of this uniform we can use Graphics4. Although it was mentioned we are only using g2, for now the only quick way to set a uniform is trough g4. In future Kha releases g2 might have these functions as well."
probably really better in the future to prohibit at the API level to use calls g4 inside g2.begin\g2.end and vice versa. And add to g2 methods for setting shader variables.
It seems that calling g4.setPipeline(_shaderPipeline);
works, so somewhere in the g2 implementation it goes wrong.
Oh, I already figured out what goes wrong, 3f121b4 removed a forced flush when setting a pipeline. But I think I'll add the setXYZ functions instead of reverting that change because that'll be more efficient in some situations.
As per instructions in the discord I'm here to say I've ran into the same issue ;)
the following workaround as mentioned by Disar, calling g4.setPipeline(...)
first and setting g2.pipeline = ...
after, works:
framebuffer.g2.begin();
framebuffer.g4.setPipeline(pipeline);
framebuffer.g4.setFloat(pipeline.getConstantLocation('time'), time);
framebuffer.g2.pipeline = pipeline;
framebuffer.g2.drawSubImage(img, x, y, 0, 0, 48, 48);
framebuffer.g2.end();