forked from KhronosGroup/OpenGL-Registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GLSLExtensionRules.txt
409 lines (311 loc) · 13.2 KB
/
GLSLExtensionRules.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
OpenGL(R) Shading Language Extension Conventions
Last Modified Date: 2006/12/18
Author Revision: 11
Document Source: the OpenGL Extension Registry at
http://www.opengl.org/registry/
Contributors:
Pat Brown, NVIDIA
John Kessenich, 3Dlabs
Jon Leech
Barthold Lichtenbelt, 3Dlabs
Bill Licea-Kane, ATI
Kent Lin, Intel
Jeremy Sandmel, ATI
Folker Schamel, Spinor
The ARB OpenGL Shading Language working group has defined the following
conventions for writing OpenGL extension specifications that extend the
Shading Language syntax or semantics.
=======================================================================
Section #1: Conventions to avoid name-space collision
We expect the Shading Language to continue to evolve through the
use of vendor, EXT, and ARB extensions, as well as through
revisions to the core language specification itself. As a result,
we'd like to establish some name conventions to avoid name-space
collisions between vendors and between the extensions and the core
language.
We have the same kinds of concerns that resulted in the need for
naming and syntax rules document for the non-shader parts of
OpenGL:
http://www.opengl.org/registry/doc/rules.html#spec_naming
We expect that we will need to affix new names with vendor tags
where appropriate, and change and/or remove these tags as
extensions are promoted, in the same fashion as for core GL
function and token names.
The fact that the Shading Language is modeled after C/C++ means
that we have some additional requirements for what the language
should "look" like.
Consequently, vendors must use the following naming conventions
when creating new OpenGL extensions that affect the syntax of the
Shading Language.
General principles:
- New syntax defined by an extension should be suffixed with a
vendor specific extension (EXT, ARB, SGI, etc),
except as noted below where the constraints of
being "C-like" make it unpalatble.
- Vendors should make a good faith effort to ensure that new
shading language extensions do not conflict in syntax or
semantics with the extensions of other vendors
or the ARB.
Rules for adding or modifying specific Shading Language
constructs defined by extensions follow.
Note: VEN stands for any vendor tag, e.g. ARB, EXT, SGI, etc.
Summary:
--------
1a) variables: gl_<Name>VEN
1b) keywords: __<name>VEN
1c) data types:
1c1) keywords: __<name>VEN
1c2) derived types: gl_<Name>VEN
1d) operators: use new data types as operands or ask ARB
1e) functions: <name>VEN
Details:
--------
1a) Variables
STATUS: RESOLVED
New variables defined by an extension should use:
prefix: "gl_" (lower case, single underscore)
suffix: "VEN" (no underscore)
Form:
gl_<Name>VEN
<Name> is subject to these constraints:
- Each word in <Name> must start with a capital letter.
- Words should be concatenated, not separated with
underscores.
- Don't use an underscore to separate the
final VEN suffix.
Notes:
All of the variables defined in the core
shading language specification already follow this
convention.
New variables added by shading language extensions should
match the naming style of the core specification
where possible.
Examples:
uniform float gl_SomeNewBuiltinScalarARB;
varying vec4 gl_YetAnotherVaryingEXT;
attribute vec4 gl_OneMoreAttributeATI
1b) keywords:
STATUS: RESOLVED
New keywords defined by an extension should use:
prefix: "__" (double underscore)
suffix: VEN (no underscore)
Form:
__<name>VEN
Notes:
New keywords should be prefixed with "__" because this is
how C/C++ handle keyword extensions. The core language
specification reserves the use of "__" anywhere within a
keyword so that future language revisions from the ARB will
not conflict with user level names.
To avoid name collisions between OpenGL implementations from
different IHV's, extended keywords should also use a vendor
suffix.
The working group considered requiring a "gl_" for the
prefix instead of "__", but felt this diverged too far from
the conventions of C/C++
Examples:
__float4EXT
__sampler4DSGI
__elifARB
__some_new_kind_of_while_loopARB
1c) New data types:
STATUS: RESOLVED
Naming conventions for new data types defined by an extension
differ depending on whether the data type is a new fundamental
type defined as a keyword (case 1c1), or a new derived type
defined by Shading Language constructs (case 1c2). Currently the
only derived types are "struct"s.
1c1) For new data type keywords defined by an extension:
prefix: "__" (double underscore)
suffix: VEN
Form:
__<name>VEN
Examples:
__float4SGI
__half2NV
__triplefloatARB
__mat5EXT
1c2) For new derived types defined by an extension:
prefix: "gl_" (gl and single underscore)
suffix: VEN
Form:
gl_<name>VEN
Examples:
gl_skinningParametersEXT
gl_newDerivedStateStructARB
Notes:
If new data types are defined as keywords, then they
should follow the rules for keywords. If new data types
are derived types, then they should follow a different
naming convention, like the one for variables.
New data types should not be added as keywords unless
absolutely necessary.
1d) New operators:
STATUS: RESOLVED
To avoid name space collisions for new operators
defined by an extension, or existing operators whose
behavior is re-defined by an extensions, extensions should
either:
1d1) Add a new data type along with the operator and use at
least one of these new data types for the operands of the
(re)defined operator. The new data type name should follow
the rules given in (1c) above for new data types.
or
1d2) For IHVs who want to define a new operator to work on
existing data types or to redefine an existing operator to
work on existing data types, the IHV should come to the ARB
and request the new operator to avoid colliding with any
upcoming uses for the operator by the ARB.
Examples:
An extension which overloads the "+" operator to add an int
and a "triple" should define a new gl_tripleEXT type, then
define the behavior of the + operator when one operand is an
int and the other is a gl_tripleEXT.
An extension needing to overload the "+" operator to add an
int and a float must obtain permission from the ARB. If it
approves, the ARB would revise the shading language grammar
to define the behavior of the + operator when one operand is
an int and the other is a float.
An extension needing to define an entirely new operator for
exponentiation must obtain permission from the ARB. If it
approves, the ARB would agree to reserve an appropriate new
operator, such as "**", and the extension would define the
behavior of that operator with respect to some data types.
Notes:
On the surface, operators by themselves need no additional
name-space syntax. No one wants "+" redefined as gl_+ARB, for
instance.
However, the ARB still wants to avoid name space and semantic
collisions as extensions are promoted. The ARB reserves the
use of operators with existing types.
Therefore we've adopted the two-pronged approach listed above.
(A) is borrowed from C++ operator overloading conventions.
(B) is a fall-back position in the event that (A) is
inconvenient.
1e) functions:
STATUS: RESOLVED
New functions defined by an extension should use:
prefix: none (note, no "gl_" or "__")
suffix: VEN
Form:
<name>VEN
Examples:
newfunctionEXT()
SomeOtherFuncARB()
Yet_Another_FunctionSGI()
Notes:
Since none of the standard core Shading Language functions
start with the "gl_" prefix, new functions do not need this
prefix either. There is no need to avoid collisions between
implementation-defined and user-defined functions, because
the Shading Language specifically allows user overloading of
built-in functions. In other words, name collisions are
expected and intentional. Further, when a name collision
occurs between a user function and an implementation-defined
function, the user function takes precedence.
However, we still must avoid name collisions between IHV's
and to allow for promotion of new functions into EXT, ARB
and core status. So, new functions should use a VENDOR
suffix.
=============================================================
Section #2: Protocol for accessing extension features in the
shading language
2a) Extension #defines?
STATUS: RESOLVED
Every extension which affects shading language semantics or
syntax must create a Shading Language preprocessor #define that
matches the GL extension name string. This #define would be
available in the shading language if and only if the extension
were supported on a given Shading Language implementation.
Further, extensions which do not affect shading language
semantics or syntax *must not* create this Shading Language
preprocessor #define.
The extension-writing template in the OpenGL Extension Registry
will be updated to include a placeholder for shading language
extensions showing the corresponding #define.
Example:
An extension which adds the extension string
"GL_ARB_shading_extension_1"
should also add a Shading Language preprocessor #define called
GL_ARB_shading_extension_1
Doing so means that a shader can do something like:
#ifdef GL_ARB_shading_extension_1
// do something using the extension
#else
// do something else or #error!
#endif
Notes:
If an application wishes to emulate this behavior for any
other extensions which do not directly affect the shading
language syntax or behavior, they can simply query the
extension string for the presence of these extensions and
create their own #defines to be prepended to their shader
strings.
Pseudo-code example:
char* prefixStr;
if (glIsExtensionSupported("GL_ARB_texture_mirrored_repeat"))
{
ConcatString(prefixStr, "#define GL_ARB_texture_mirrored_repeat 1\n");
}
// use prefixStr as the first string given to glShaderSource()
2b) Should we allow and/or require a shader author to declare
their intended use of a given extension prior to use?
STATUS: RESOLVED - YES
The ARB has received developer feedback requesting we strive
towards portability in the shading language. The concern is
shaders written on one implementation with an extension will not
run on an implementation without the extension and that without
an explicit "enable", the shader author may not realize that
he/she was using any extended features.
After much discussion, the resolution is as follows:
For any extension which can affect shaders written without
knowledge of the extension (i.e. no change in syntax to the
shading language), the extension must introduce an API which
explicitly "enables" the extended behavior. New extensions
should not be allowed to change the behavior of old shaders
without an explicit request to do so from the application.
Further, for any extension which affects the syntax or semantics
of the shading language, the shader author must explicitly make
a request allow the use of the extension, by inserting this
request within the shader text itself.
This request is made using the following syntax:
#extension <name> : <behavior>
where
<name> = the GL extension name string (as defined in section 2a,
starting with "GL_").
and
<behavior> can be one of the following:
require, enable, warn, or disable
Example:
To use an extension which adds the extension string
"GL_ARB_shading_extension_1", a shader should include a line like:
#extension GL_ARB_shading_extension_1: enable
See section 3.3 of the OpenGL Shading Language specification
(Language Version 1.20) for details about using this mechanism.
-----------------------------------
Revision history:
#11 - 12/18/2006 - Jon Leech
- Clarify that #extension name must be the extension name string
starting with "GL_", give an example, fix an old URL.
#10 - 10/09/2006 - Jon Leech
- Move registry URL to www.opengl.org.
#9 - 05/12/2004 - js
- no changes from rev #8, whitespace cleanup only
#8 - 05/11/2004 - js
- minor typos fixed
- cleaned up language about when to use 1c1 or 1c2
#7 - 05/07/2004 - Jon Leech
- language cleanups including removing use of "built in"
#6 - 04/29/04 - js
- cleaned up psuedo code example in section 2a
- change language about "decorate"ing names to "affix"
#5 - 04/29/04 - js
- added to contributors list
#4 - 04/29/04 - js
- cleaned up section 2 to reflect #extension resolution
#3 - 03/15/04 - js
- summarized section 1 conventions on name decorations
#2 - 03/24/04 - js
- reorganized doc to reflect recent working group discussions
#1 - 03/19/04 - js
- initial revision