function with bool return type in OpenGL ES shader using GPUImage

房东的猫 提交于 2019-12-11 14:33:35

问题


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:


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!



来源:https://stackoverflow.com/questions/21206752/function-with-bool-return-type-in-opengl-es-shader-using-gpuimage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!