GLSL中的二阶函数? [英] Second order functions in GLSL?

查看:83
本文介绍了GLSL中的二阶函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种将函数用作GLSL中另一个函数的参数的方法.在常规C中,可以通过将函数指针作为函数参数传递来模拟它.似乎其他语言(例如HLSL)现在也提供了处理诸如高阶函数之类的高级构造的方法,或者可以使用

I'm looking for a way to use a function as an argument to another function in GLSL. In regular C, it can be simulated by passing a function pointer as a function argument. It also seems that other languages (like HLSL) now provide ways to deal with high-level constructs like higher-order functions, or can simulate them with clever use of HLSL structures. unfortunately I'm stuck with GLSL for now, and I can't find any way to simulate higher-order functions. Is it really impossible in current (4.2) GLSL ? Or am I missing some clever trick ?

我想要实现的常见示例:

common example of what I'm trying to achieve :

int f(someType f2, int i) {
    return f2(i);
}

推荐答案

我正在寻找一种将函数用作GLSL中另一个函数的参数的方法.

I'm looking for a way to use a function as an argument to another function in GLSL.

简短的回答:您不能.

您在GLSL中获得的与这种功能最接近的是 shader子例程.而且,这仅允许外部OpenGL API选择要使用的子例程,而不是着色器本身.

The closest thing to this kind of functionality you'll get in GLSL is shader subroutines. And that only allows the external OpenGL API to select which subroutine to use, not the shader itself.

所以只需执行switch/case语句并获得它即可.

So just do the switch/case statement and get it over with.

这篇关于GLSL中的二阶函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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