随机的“位置不是当前节目".错误 [英] Random "location not for current program" error

查看:69
本文介绍了随机的“位置不是当前节目".错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用WebGL时遇到问题.

I have an issue with WebGL.

有时候,当我向应用程序中添加新的着色器时,当我设置统一的图像时,每帧都会出现 uniform4f:不适用于当前程序的位置错误(在Chrome控制台中显示)我的2D绘图功能中的绘图着色器.

Sometimes, when I add a new shader to my application, I start to get uniform4f: location not for current program error (displayed in Chrome console) every frame when I set an uniform of my image drawing shader in my 2D drawing functions.

虽然我之前几次遇到相同的错误,但通过进行一些未知的随机操作来修复它们并不是很困难.但是,当我添加屏幕变形着色器时,我尝试了所有可能的方法,甚至是 glFinish (我认为该错误是由于不同步而发生的),但没有任何帮助.

While I got the same error a few times before, it was not very hard to fix them by doing something random unknown manipulations. However, when I added a screen warping shader, I tried everything I could, even glFinish (I think the error occurs because of desynchronization), but nothing helped.

当我尝试在控制台绘图功能中设置2D图像 shader 的vec4制服时,发生错误.如果我交换控制台绘图功能和菜单绘图功能,则不会绘制菜单.

The error occurs when I try to set a vec4 uniform of my 2D image shader in the console drawing function. If I swap the console drawing function and the menu drawing function, the menu is not drawn.

这是我的程序创建和切换功能的源代码: http://pastebin.com/zDEWWgKV

Here's the source code of my program creation and switching functions: http://pastebin.com/zDEWWgKV

如果我从以下列表中进行任何操作,错误就会停止:

The error stops if I do anything from the following list:

  • 关闭菜单.
  • 加载地图并进行一些3D渲染(导致程序切换至少4次).
  • 启用屏幕变形(导致程序切换1次).

有人可以告诉我,什么原因会导致该错误,以及如何解决该错误?

Could anybody tell me, what may cause the error and how do I fix it?

推荐答案

这表示您使用的位置来自另一个程序.程序即使使用相同的着色器也不共享位置.示例:

It means the location you are using came from another program. Programs do not share locations, even if they are using the same shaders. Example:

// make a vertex and a fragment shader
var vs = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vs, vSource);
gl.compileShader(vs);

var fs = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fs, fSource);
gl.compileShader(fs);

// now make 2 identical programs from those shaders
var p1 = gl.createProgram();
gl.attachShader(p1, vs);
gl.attachShader(p1, fs);
gl.linkProgram(p1);

var p2 = gl.createProgram();
gl.attachShader(p2, vs);
gl.attachShader(p2, fs);
gl.linkProgram(p2);

// Get a uniform location from program1
var location1 = gl.getUniformLocation(p1, "someUniform");

// Try to use that location on program2
gl.useProgram(p2);
gl.uniform4fv(location1, [1, 2, 3, 4]);  // ERROR!!!

不允许在程序2上尝试使用程序1中的位置.您必须找到程序2的位置,才能在程序2上设置制服.

Trying to use a location from program 1 on program 2 is not allowed. You must get locations for program 2 to set uniforms on program 2.

这篇关于随机的“位置不是当前节目".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆