小编Pup*_*lam的帖子

glUniform4fv给出了GL_INVALID_OPERATION

我试图在iOS和OpenGL ES中开发一个基本游戏,但是我在制服上遇到了这个问题,这里是将值传递给我的制服的代码:

glBindVertexArrayOES(_vertexArray);

// Render the object with ES2
glUseProgram(self.shaderProgram);

glUniformMatrix4fv(uniformModelViewProjection, 1, 0, modelViewProjectionMatrix.m);

// Get uniform center position
glUniform4fv(uniformCenterPosition, 1, centerPosition.v);
// Get uniform time position
glUniform1f(uniformTime, time);

// Set the sampler texture unit to 0
glUniform1i(uniformTexture, 0);
glDrawArrays(GL_POINTS, 0, numVertices);
Run Code Online (Sandbox Code Playgroud)

请注意,在glDseProgram之前和glDrawArrays调用之前,已经注意定位glUniform函数.通过追踪确认均匀位置也很好.以下是我在XCode中运行OpenGL ES Analyzer工具时得到的结果:

在此输入图像描述

它为glUniform4fv返回GL_INVALID_OPERATION,注意表示的值似乎是正确的.

以下是我从文档中找到的GL_INVALID_OPERATION错误的可能原因:

  • 没有当前的程序对象.
  • 着色器中声明的统一变量的大小与glUniform命令指示的大小不匹配.
  • 此函数的有符号或无符号整数变量之一用于加载float,vec2,vec3,vec4或其数组的统一变量,或者如果使用此函数的某个浮点变量加载int,ivec2,ivec3,ivec4,unsigned int,uvec2,uvec3,uvec4或其数组的统一变量.
  • 此函数的一个有符号整数变体用于加载unsigned int,uvec2,uvec3,uvec4或其数组的统一变量.
  • 此函数的一个无符号整数变体用于加载int,ivec2,ivec3,ivec4或其数组的统一变量.
  • location是当前程序对象的无效统一位置,位置不等于-1.
  • count大于1且指示的统一变量不是数组变量.
  • 使用除glUniform1i和glUniform1iv之外的命令加载采样器.

他们似乎没有解释为什么我收到这个错误.它让我发疯,请帮忙!

iphone shader opengl-es ios

18
推荐指数
1
解决办法
4180
查看次数

记录顶点着色器内的变量值

我是OpenGL ES编程的新手,我正在尝试调试我的着色器编程,我想知道是否有任何方法可以记录特定变量的值.例如,在下面的顶点着色器程序中,我想测试正常返回的值,基本上,我正在寻找类似于NSLog的东西......

attribute vec4 position;
attribute vec3 normal;
attribute vec2 texture;
varying vec2 v_texCoord;
varying float LightIntensity;

uniform mat4 modelViewProjectionMatrix;
uniform mat3 normalMatrix;

void main()
{
    vec3 eyeNormal = normalize(normalMatrix * normal);
    vec3 lightPosition = vec3(-1.0, 0.0, 3.0);

    float nDotVP = max(0.0, dot(eyeNormal, normalize(lightPosition)));
    LightIntensity = nDotVP;

    v_texCoord = texture;

    gl_Position = modelViewProjectionMatrix * position;
}
Run Code Online (Sandbox Code Playgroud)

shader opengl-es ios opengl-es-2.0

5
推荐指数
1
解决办法
2583
查看次数

如何使用CABasicAnimation进行缩放以保持不变

我正在我的应用程序上创建一些动画,下面的代码缩小了一个对象,直到它消失.我无法弄清楚如何使对象消失并保持这种方式,即.如何使动画在完成后保持不变.有什么问题吗?干杯!

        CABasicAnimation* zoomOut = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        zoomOut.duration = 1;
        zoomOut.toValue = [NSNumber numberWithFloat:0];
        [draggedObject addAnimation:zoomOut forKey:nil];
Run Code Online (Sandbox Code Playgroud)

ipad ios

3
推荐指数
1
解决办法
1269
查看次数

将参数传递给选择器

我在自定义单元格中有一个UIButton,我想在用户按下该按钮时触发一个动作但是我需要知道按下UIButton的哪一行.

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    [self configureCell:cell atIndexPath:indexPath];
    return cell;

    ...

    [button addTarget:self action:@selector(buttonPressedAction:)forControlEvents:UIControlEventTouchUpInside];

}

- (void)buttonPressedAction:(UIButton *)button
{
    //int row = indexPath.row;
    //NSLog(@"ROW: %i",row);
}
Run Code Online (Sandbox Code Playgroud)

如何将indexPath作为参数传递给我的选择器?

iphone cocoa-touch objective-c ipad ios

3
推荐指数
1
解决办法
1185
查看次数

无法在Java中匹配正则表达式

我在Java中实现了下面的测试正则表达式,但我看不到任何匹配.我是正则表达式的新手,但它看起来应该找到匹配.我在这里做错了什么?

 public static void main(String[] args) {
    // TODO Auto-generated method stub
    String process= "SSHD is running: PID:12506, Wrapper:STARTED, Java:STOPPPED";
    Pattern patternFileToScan = Pattern.compile("SSHD is running: PID:[d]{1,5}, Wrapper:STARTED, Java:STARTED");
      Matcher matcherFileToScan = patternFileToScan.matcher(process);
      System.out.println("TEST");
      if(matcherFileToScan.matches()) {
          System.out.println(matcherFileToScan.group());
      }

}
Run Code Online (Sandbox Code Playgroud)

java regex

1
推荐指数
1
解决办法
91
查看次数

如何获取线程内分配的变量值?

我有以下示例代码.变量alpha在线程内定义.如何在线程外获取该变量的变量?

    ...


    new Thread() {
        public void run() {
        ...
        String alpha = "new value";
        ...
        ...
        }   
    }.start();
    ...
    System.out.println(alpha); // <- how to make this work?
Run Code Online (Sandbox Code Playgroud)

java multithreading

0
推荐指数
1
解决办法
874
查看次数