1
votes

I'm working on an iOS project, using GPUImage framework. I cannot get my shader complied.


There's a function in my fragment shader:

const vec2 boundMin = vec2(0.0, 0.0);
const vec2 boundMax = vec2(1.0, 1.0);

bool inBounds (vec2 p) {
   return all(lessThan(boundMin, p)) && all(lessThan(p, boundMax));
}

Shader compile log:

ERROR: 0:1: '_Bool' : syntax error syntax error

When I replace all the calls to function

inBounds(vec2 p)

with

all(lessThan(boundMin, p)) && all(lessThan(p, boundMax))

it works great!


Questions:

Is bool function supported in OpenGL ES 2.0 Fragment Shader? If so, where did I go wrong? If not, why there're functions like all(), lessThan(), etc.

Environment: iPad mini, iOS 7, OpenGL ES 2.0, Xcode 5.0.2

1
Can you show the entire shader? If I am reading that compile log correctly, it is complaining about the first line.Andon M. Coleman
@AndonM.Coleman I don't think it's the first line, because when I delete the inBounds function, it works fine. I believe it's the function itself that causes the problem. Do you use GPUImage? I don't think GPUImage's shader compile log can give the exact location of an error.YuAo
0:1 usually means something to the effect of the first character on line 1. Each vendor is different, but that tends to be the convention.Andon M. Coleman
@AndonM.Coleman my first line is precision highp float; ...YuAo
@AndonM.Coleman iOS does support highp, I know that, and I'm using highp in other fragment shaders, it's fine.YuAo

1 Answers

6
votes

I finally figure it out!

GPUImage uses SHADER_STRING() to parse shaders.

When I write bool, the LLVM Objective-C compiler did not know this pice of code will be converted to shader string. When the compiler sees bool it will replace bool with _Bool, because in Objective-C bool is defined to be _Bool!