OpenGL ES 3.0 和 APPLE_clip_distance 扩展 [英] OpenGL ES 3.0 and APPLE_clip_distance extension
问题描述
根据本文档APPLE_clip_distance 扩展存在于 OpenGL ES 3.0 和 iPhone 6+ 硬件上.我试图通过首先在代码中启用它然后在着色器中使用来使用它.
According to this document APPLE_clip_distance extension is present on OpenGL ES 3.0 and iPhone 6+ hardware. I'm trying to use this by first enabling it in code and then using in the shader.
我可以通过执行查询最大数量的裁剪平面
I can query the maximum number of clipping planes by doing
GLint i;
glGetIntegerv(GL_MAX_CLIP_DISTANCES_APPLE, &i);
printf("i: %d\n", i);
这会打印出 8.
当尝试在着色器中使用它时:
When trying to use this in the shader like this:
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'
本文档 描述了扩展,就我而言理解它,由于我使用的是 ES 3.0,我应该重新声明剪辑距离数组:
This document describes the extension and as far as I understand it I'm supposed to redeclare the clip distance array due to the fact that I'm using 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'
有人有这个扩展的工作示例吗?
Does somebody have a working example of this extension?
推荐答案
你需要做的一件事是在你的着色器代码中指定它依赖于这个扩展.靠近顶点着色器的开头,在#version
之后,添加对应的#extension
指令:
One thing you need to do is specify in your shader code that it relies on this extension. Close to the start of the vertex shader, after the #version
, add the corresponding #extension
directive:
#version 300 es
#extension GL_APPLE_clip_distance : require
然后,按照我阅读扩展规范的方式,您使用如下所示的声明来调整 gl_ClipDistance
的大小:
Then, the way I read the extension spec, you use a declaration looking like this to size gl_ClipDistance
:
out highp float gl_ClipDistance[4];
其中常量与您要使用的裁剪平面的数量相匹配.请注意,与问题中发布的代码不同,您不重新定义gl_MaxClipDistances
.一旦您需要扩展,就应该已经定义了常量.
where the constant matches the number of clip planes you want to use. Note that, unlike the code posted in the question, you do not redefine gl_MaxClipDistances
. Once you require the extension, the constant should already be defined.
如果您想使用最大支持数量的剪裁平面,您可以使用常量:
You can use the constant if you want to use the maximum supported number of clip planes:
out highp float gl_ClipDistance[gl_MaxClipDistances];
这篇关于OpenGL ES 3.0 和 APPLE_clip_distance 扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!