opengl-es - 没有属性的顶点着色器

我们可以拥有没有属性的垂直着色器吗?

#version 300 es
out mediump vec4 basecolor;

uniform ivec2 x1;

void main(void)
{
        if(x1 == ivec2(10,20))
                basecolor = vec4(0.0, 1.0, 0.0, 1.0);
        else
              basecolor = vec4(1.0, 0.0, 1.0, 1.0);

        gl_PointSize = 64.0;
        gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
}



#version 300 es
in mediump vec4 basecolor;

out vec4 FragColor;
void main(void)
{
        FragColor =  basecolor;
}

最佳答案

从技术上讲,规范中没有任何内容实际要求您具有顶点属性。但出于同样的原因,在 OpenGL ES 3.0 中,无论您是否需要,您都有两个内在定义的 in 属性:

The built-in vertex shader variables for communicating with fixed functionality are intrinsically declared as follows in the vertex language:

in highp int gl_VertexID;
in highp int gl_InstanceID;

这真的是唯一一次没有任何属性才真正有意义。您可以根据 gl_VertexIDgl_InstanceID 或两者的某种组合动态计算位置,这是 OpenGL ES 2.0 的重大变化。

https://stackoverflow.com/questions/18866538/

相关文章:

image - 使用 gnuplot pm3d 和 pdf 输出生成的图像中有问题的莫尔图案

integer - 有符号和无符号整数?

c# - ComboBox 向上/向下箭头键在项目重新填充后发出

python - 将 matplotlib 图导出到 HTML 文件

emacs - 如何使用预定义窗口启动 Emacs?

regex - 如何将 1100 行中的每 5 行合并为 1 行

JavaFX - 使用 CSS 为文本字段设置焦点边框

gcc - 编译外部内核模块时如何手动包含.config?

animation - SVG 元素上的多个动画

php - 为什么 PHP-FPM 需要 5 分钟才能在我的服务器上重新启动?