Kha icon indicating copy to clipboard operation
Kha copied to clipboard

WebGL: INVALID_OPERATION: uniform1f: location not for current program

Open OlegAntipov opened this issue 6 years ago • 6 comments

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

OlegAntipov avatar Feb 05 '19 05:02 OlegAntipov

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.

sh-dave avatar Feb 05 '19 07:02 sh-dave

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.

RobDangerous avatar Feb 05 '19 08:02 RobDangerous

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.

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.

OlegAntipov avatar Feb 05 '19 09:02 OlegAntipov

It seems that calling g4.setPipeline(_shaderPipeline); works, so somewhere in the g2 implementation it goes wrong.

Disar avatar Feb 28 '19 17:02 Disar

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.

RobDangerous avatar Feb 28 '19 18:02 RobDangerous

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();

Vadinci avatar May 22 '19 09:05 Vadinci