本文整理汇总了C++中Func::glsl方法的典型用法代码示例。如果您正苦于以下问题:C++ Func::glsl方法的具体用法?C++ Func::glsl怎么用?C++ Func::glsl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Func
的用法示例。
在下文中一共展示了Func::glsl方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
// This test must be run with an OpenGL target
const Target &target = get_jit_target_from_environment();
if (!target.has_feature(Target::OpenGL)) {
fprintf(stderr,"ERROR: This test must be run with an OpenGL target, e.g. by setting HL_JIT_TARGET=host-opengl.\n");
return 1;
}
Image<float> input(255, 255, 3);
for (int y=0; y<input.height(); y++) {
for (int x=0; x<input.width(); x++) {
for (int c=0; c<3; c++) {
// Note: the following values can be >1.0f to test whether
// OpenGL performs clamping operations as part of the copy
// operation. (It may do so if something other than floats
// are stored in the actual texture.)
float v = (10 * x + y + c);
input(x, y, c) = v;
}
}
}
Var x, y, c;
Func g;
g(x, y, c) = input(x, y, c);
Image<float> out(255, 255, 3);
g.bound(c, 0, 3);
g.glsl(x, y, c);
g.realize(out);
out.copy_to_host();
for (int y=0; y<out.height(); y++) {
for (int x=0; x<out.width(); x++) {
if (!(out(x, y, 0) == input(x, y, 0) &&
out(x, y, 1) == input(x, y, 1) &&
out(x, y, 2) == input(x, y, 2))) {
fprintf(stderr, "Incorrect pixel (%g,%g,%g) != (%g,%g,%g) at x=%d y=%d.\n",
out(x, y, 0), out(x, y, 1), out(x, y, 2),
input(x, y, 0), input(x, y, 1), input(x, y, 2),
x, y);
return 1;
}
}
}
printf("Success!\n");
return 0;
}
示例2: main
int main() {
// This test must be run with an OpenGL target
const Target &target = get_jit_target_from_environment();
if (!(target.features & Target::OpenGL)) {
fprintf(stderr,"ERROR: This test must be run with an OpenGL target, e.g. by setting HL_JIT_TARGET=host-opengl.\n");
return 1;
}
Image<uint8_t> input(255, 10, 3);
for (int y=0; y<input.height(); y++) {
for (int x=0; x<input.width(); x++) {
for (int c=0; c<3; c++) {
input(x, y, c) = 10*x + y + c;
}
}
}
Var x, y, c;
Func g;
g(x, y, c) = input(x, y, c);
Image<uint8_t> out(255, 10, 3);
g.bound(c, 0, 3);
g.glsl(x, y, c);
g.realize(out);
out.copy_to_host();
for (int y=0; y<out.height(); y++) {
for (int x=0; x<out.width(); x++) {
if (!(out(x, y, 0) == input(x, y, 0) &&
out(x, y, 1) == input(x, y, 1) &&
out(x, y, 2) == input(x, y, 2))) {
fprintf(stderr, "Incorrect pixel (%d,%d,%d) != (%d,%d,%d) at x=%d y=%d.\n",
out(x, y, 0), out(x, y, 1), out(x, y, 2),
input(x, y, 0), input(x, y, 1), input(x, y, 2),
x, y);
return 1;
}
}
}
printf("Success!\n");
return 0;
}
示例3: main
int main(int argc, char **argv) {
Param<float> time;
const float pi = 3.1415926536;
Var x, y, c;
Func result;
Expr kx, ky;
Expr xx, yy;
kx = x / 150.0f;
ky = y / 150.0f;
xx = kx + sin(time/3.0f);
yy = ky + sin(time/2.0f);
Expr angle;
angle = 2 * pi * sin(time/20.0f);
kx = kx * cos(angle) - ky * sin(angle);
ky = kx * sin(angle) + ky * cos(angle);
Expr v = 0.0f;
v += sin((ky + time) / 2.0f);
v += sin((kx + ky + time) / 2.0f);
v += sin(sqrt(xx * xx + yy * yy + 1.0f) + time);
result(x, y, c) = cast<uint8_t>(
select(c == 0, 32,
select(c == 1, cos(pi * v),
sin(pi * v)) * 80 + (255 - 80)));
result.output_buffer().set_stride(0, 4);
result.bound(c, 0, 4);
result.glsl(x, y, c);
result.compile_to_file("halide_gl_filter", {time}, "halide_gl_filter");
return 0;
}
示例4: main
int main() {
Func f;
Var x, y, c;
Expr e = 0;
// Max with integer arguments requires Halide to introduce an implicit
// cast to float.
e = select(x == 0, max(y, 5), e);
// But using float directly should also work.
e = select(x == 1, cast<int>(min(cast<float>(y), 5.0f)), e);
e = select(x == 2, y % 3, e);
e = select(x == 3, cast<int>(127*sin(y) + 128), e);
e = select(x == 4, y / 2, e);
f(x, y, c) = cast<uint8_t>(e);
Image<uint8_t> out(10, 10, 1);
f.bound(c, 0, 1);
f.glsl(x, y, c);
f.realize(out);
out.copy_to_host();
for (int y = 0; y < out.height(); y++) {
CHECK_EQ(out(0, y, 0), std::max(y, 5));
CHECK_EQ(out(1, y, 0), std::min(y, 5));
CHECK_EQ(out(2, y, 0), y % 3);
CHECK_EQ(out(3, y, 0), static_cast<int>(127*std::sin(y) + 128));
CHECK_EQ(out(4, y, 0), y / 2);
}
printf("Success!\n");
return 0;
}