【问题标题】:OpenGL ES 3.0 and APPLE_clip_distance extensionOpenGL ES 3.0 和 APPLE_clip_distance 扩展
【发布时间】:2015-11-08 01:40:29
【问题描述】:

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

我可以通过做查询最大裁剪平面数

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'

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

【问题讨论】:

    标签: ios opengl-es


    【解决方案1】:

    您需要做的一件事是在着色器代码中指定它依赖于此扩展。靠近顶点着色器的开头,在#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];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多