代码之家  ›  专栏  ›  技术社区  ›  Seppo

OpenGL ES 3.0和APPLE_clip_distance扩展

  •  0
  • Seppo  · 技术社区  · 11 年前

    根据 this document OpenGL ES 3.0和iPhone 6+硬件上存在APPLE_clip_distance扩展。我试图通过首先在代码中启用它,然后在着色器中使用来使用它。

    我可以通过

    GLint i;
    glGetIntegerv(GL_MAX_CLIP_DISTANCES_APPLE, &i);
    printf("i: %d\n", i);
    

    这个打印出8。

    尝试在着色器中使用此选项时,请执行以下操作:

    const mediump int gl_MaxClipDistances = 8;
    out highp float gl_ClipDistance[gl_MaxClipDistances];
    

    我收到以下错误:

    ERROR: 0:24: Identifier name 'gl_MaxClipDistances' cannot start with 'gl_'
    ERROR: 0:25: Use of undeclared identifier 'gl_MaxClipDistances'
    ERROR: 0:33: Use of undeclared identifier 'gl_ClipDistance'
    

    This document 描述了扩展,据我所知,我应该重新声明剪辑距离数组,因为我使用的是ES 3.0:

    (1) GLSL 300 doesn't support unsized arrays, how should gl_ClipDistance
    be sized?
    
      RESOLVED: For maximal compatibility, it works like ES2/desktop,
      remaining unsized until sized by direct access or explicitly
      redeclared.  Language describing this behavior must be added to the
      extension specification since it's gone from the base language
      specification.
    

    同时声明如下:

    out highp float gl_ClipDistance[];
    

    给出此错误:

    ERROR: 0:25: Unsized array 'gl_ClipDistance' requires sized initializer under GLSL 300
    ERROR: 0:33: Use of undeclared identifier 'gl_ClipDistance'
    

    有人有这个扩展的工作示例吗?

    1 回复  |  直到 11 年前
        1
  •  1
  •   Reto Koradi    11 年前

    您需要做的一件事是在着色器代码中指定它依赖于此扩展。接近顶点着色器的开始,在 #version ,添加相应的 #extension 指令:

    #version 300 es
    #extension GL_APPLE_clip_distance : require
    

    然后,按照我阅读扩展规范的方式,使用如下声明 gl_ClipDistance :

    out highp float gl_ClipDistance[4];
    

    其中常数与要使用的剪辑平面的数量相匹配。注意,与问题中发布的代码不同 不 重新定义 gl_MaxClipDistances 。一旦您需要扩展名,就应该已经定义了常量。

    你可以 使用 如果要使用最大支持的剪裁平面数,请使用常量:

    out highp float gl_ClipDistance[gl_MaxClipDistances];