gpt4 book ai didi

ios - OpenGL ES 3.0 和 APPLE_clip_distance 扩展

转载 作者:行者123 更新时间:2023-11-29 01:45:10 25 4
gpt4 key购买 nike

根据 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'

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

最佳答案

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

关于ios - OpenGL ES 3.0 和 APPLE_clip_distance 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32016161/

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