gpt4 book ai didi

opengl - 是否可以将着色器变量声明为输入和输出?

转载 作者:行者123 更新时间:2023-12-01 09:20:40 26 4
gpt4 key购买 nike

我同时使用顶点着色器和几何着色器。我的顶点着色器只不过将其输入转发到几何着色器。

#version 330 core
layout (location = 0) in uint xy;
layout (location = 1) in uint znt;

out uint out_xy;
out uint out_znt;

void main()
{
out_xy = xy;
out_znt = znt;
}

是否可以将 xyznt 声明为输入和输出,这样我就不需要重命名它们?

最佳答案

Is it possible to declare a shader variable as both input and output?

没有。变量的名称是标识符,两个不同的变量必须具有不同的标识符。


请参阅GLSL - The OpenGL Shading Language 4.6; 3.7 Identifiers; page 18

Identifiers are used for variable names, function names, structure names, and field selectors ...

... More generally, it is a compile-time error to redeclare a variable, ...


但是当然可以使用实例名称声明接口(interface) block 。正如尼可波拉斯的回答所述。在这种情况下,可以通过接口(interface) block 的实例名称和变量名称来访问变量。

但是仍然无法使用没有实例名称的接口(interface) block 并在实例 block 内重用变量名称。

参见GLSL - The OpenGL Shading Language 4.6; 4.3.9 Interface Blocks; page 54

If an instance name (instance-name) is not used, the names declared inside the block are scoped at the global level and accessed as if they were declared outside the block. If an instance name (instance-name) is used, then it puts all the members inside a scope within its own name space, accessed with the field selector ( . ) operator (analogously to structures).

关于opengl - 是否可以将着色器变量声明为输入和输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48244561/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com