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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
/*
Software License :
Copyright (c) 2010-15, The Open Effects Association Ltd. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name The Foundry Visionmongers Ltd, nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
extern "C" kOfxBitDepthHalf
/** @brief String used to label the OpenGL half float (16 bit floating
point) sample format */
/** @brief Indicates whether a host or plugin can support OpenGL accelerated
rendering
- Type - C string X 1
- Property Set - plugin descriptor (read/write), host descriptor (read
only) - plugin instance change (read/write)
- Default - "false" for a plugin
- Valid Values - This must be one of
- "false" - in which case the host or plugin does not support OpenGL
accelerated rendering
- "true" - which means a host or plugin can support OpenGL accelerated
rendering, in the case of plug-ins this also means that it
is capable of CPU based rendering in the absence of a GPU
- "needed" - only for plug-ins, this means that an effect has to have
OpenGL support, without which it cannot work.
V1.4: It is now expected from host reporting v1.4 that the plugin can during instance change switch from true to false and false to true.
*/
/** @brief Indicates the bit depths supported by a plug-in during OpenGL renders.
This is analogous to ::kOfxImageEffectPropSupportedPixelDepths. When a
plug-in sets this property, the host will try to provide buffers/textures
in one of the supported formats. Additionally, the target buffers where
the plug-in renders to will be set to one of the supported formats.
Unlike ::kOfxImageEffectPropSupportedPixelDepths, this property is
optional. Shader-based effects might not really care about any
format specifics when using OpenGL textures, so they can leave this unset
and allow the host the decide the format.
- Type - string X N
- Property Set - plugin descriptor (read only)
- Default - none set
- Valid Values - This must be one of
- ::kOfxBitDepthNone (implying a clip is unconnected, not valid for an
image)
- ::kOfxBitDepthByte
- ::kOfxBitDepthShort
- ::kOfxBitDepthHalf
- ::kOfxBitDepthFloat
*/
/** @brief Indicates that an image effect SHOULD use OpenGL acceleration in
the current action
When a plugin and host have established they can both use OpenGL renders
then when this property has been set the host expects the plugin to render
its result into the buffer it has setup before calling the render. The
plugin can then also safely use the 'OfxImageEffectOpenGLRenderSuite'
- Type - int X 1
- Property Set - inArgs property set of the following actions...
- ::kOfxImageEffectActionRender
- ::kOfxImageEffectActionBeginSequenceRender
- ::kOfxImageEffectActionEndSequenceRender
- Valid Values
- 0 indicates that the effect cannot use the OpenGL suite
- 1 indicates that the effect should render into the texture,
and may use the OpenGL suite functions.
\note Once this property is set, the host and plug-in have agreed to
use OpenGL, so the effect SHOULD access all its images through the
OpenGL suite.
v1.4: kOfxImageEffectPropOpenGLEnabled should probably be checked in Instance Changed prior to try to read image via clipLoadTexture
*/
/** @brief Indicates the texture index of an image turned into an OpenGL
texture by the host
- Type - int X 1
- Property Set - texture handle returned by
` OfxImageEffectOpenGLRenderSuiteV1::clipLoadTexture (read only)
This value should be cast to a GLuint and used as the texture index when
performing OpenGL texture operations.
The property set of the following actions should contain this property:
- ::kOfxImageEffectActionRender
- ::kOfxImageEffectActionBeginSequenceRender
- ::kOfxImageEffectActionEndSequenceRender
*/
/** @brief Indicates the texture target enumerator of an image turned into
an OpenGL texture by the host
- Type - int X 1
- Property Set - texture handle returned by
OfxImageEffectOpenGLRenderSuiteV1::clipLoadTexture (read only)
This value should be cast to a GLenum and used as the texture target
when performing OpenGL texture operations.
The property set of the following actions should contain this property:
- ::kOfxImageEffectActionRender
- ::kOfxImageEffectActionBeginSequenceRender
- ::kOfxImageEffectActionEndSequenceRender
*/
/** @name StatusReturnValues
OfxStatus returns indicating that a OpenGL render error has occurred:
- If a plug-in returns ::kOfxStatGLRenderFailed, the host should retry the
render with OpenGL rendering disabled.
- If a plug-in returns ::kOfxStatGLOutOfMemory, the host may choose to free
resources on the GPU and retry the OpenGL render, rather than immediately
falling back to CPU rendering.
*/
/** @{ */
/** @brief render ran out of memory */
/** @brief render failed in a non-memory-related way */
/** @} */
/** @brief OFX suite that provides image to texture conversion for OpenGL
processing
*/
typedef struct OfxImageEffectOpenGLRenderSuiteV1
OfxImageEffectOpenGLRenderSuiteV1;
/** @brief Action called when an effect has just been attached to an OpenGL
context.
The purpose of this action is to allow a plugin to set up any data it may need
to do OpenGL rendering in an instance. For example...
- allocate a lookup table on a GPU,
- create an openCL or CUDA context that is bound to the host's OpenGL
context so it can share buffers.
The plugin will be responsible for deallocating any such shared resource in the
\ref ::kOfxActionOpenGLContextDetached action.
A host cannot call ::kOfxActionOpenGLContextAttached on the same instance
without an intervening ::kOfxActionOpenGLContextDetached. A host can have a
plugin swap OpenGL contexts by issuing a attach/detach for the first context
then another attach for the next context.
The arguments to the action are...
\arg handle - handle to the plug-in instance, cast to an
\ref OfxImageEffectHandle
\arg inArgs - is redundant and set to null
\arg outArgs - is redundant and set to null
A plugin can return...
- ::kOfxStatOK, the action was trapped and all was well
- ::kOfxStatReplyDefault, the action was ignored, but all was well anyway
- ::kOfxStatErrMemory, in which case this may be called again after a memory
purge
- ::kOfxStatFailed, something went wrong, but no error code appropriate,
the plugin should to post a message if possible and the host should not
attempt to run the plugin in OpenGL render mode.
*/
/** @brief Action called when an effect is about to be detached from an
OpenGL context
The purpose of this action is to allow a plugin to deallocate any resource
allocated in \ref ::kOfxActionOpenGLContextAttached just before the host
decouples a plugin from an OpenGL context.
The host must call this with the same OpenGL context active as it
called with the corresponding ::kOfxActionOpenGLContextAttached.
The arguments to the action are...
\arg handle - handle to the plug-in instance, cast to an
\ref OfxImageEffectHandle
\arg inArgs - is redundant and set to null
\arg outArgs - is redundant and set to null
A plugin can return...
- ::kOfxStatOK, the action was trapped and all was well
- ::kOfxStatReplyDefault, the action was ignored, but all was well anyway
- ::kOfxStatErrMemory, in which case this may be called again after a memory
purge
- ::kOfxStatFailed, something went wrong, but no error code appropriate,
the plugin should to post a message if possible and the host should not
attempt to run the plugin in OpenGL render mode.
*/
/** @page ofxOpenGLRender OpenGL Acceleration of Rendering
@section ofxOpenGLRenderIntro Introduction
The OfxOpenGLRenderSuite allows image effects to use OpenGL commands
(hopefully backed by a GPU) to accelerate rendering
of their outputs. The basic scheme is simple....
- An effect indicates it wants to use OpenGL acceleration by setting the
::kOfxImageEffectPropOpenGLRenderSupported flag on its descriptor
- A host indicates it supports OpenGL acceleration by setting
::kOfxImageEffectPropOpenGLRenderSupported on its descriptor
- In an effect's ::kOfxImageEffectActionGetClipPreferences action, an
effect indicates what clips it will be loading images from onto the GPU's
memory during an effect's ::kOfxImageEffectActionRender action.
@section ofxOpenGLRenderHouseKeeping OpenGL House Keeping
If a host supports OpenGL rendering then it flags this with the string
property ::kOfxImageEffectPropOpenGLRenderSupported on its descriptor property
set. Effects that cannot run without OpenGL support should examine this in
::kOfxActionDescribe action and return a ::kOfxStatErrMissingHostFeature
status flag if it is not set to "true".
Effects flag to a host that they support OpenGL rendering by setting the
string property ::kOfxImageEffectPropOpenGLRenderSupported on their effect
descriptor during the ::kOfxActionDescribe action. Effects can work in three
ways....
- purely on CPUs without any OpenGL support at all, in which case they
should set ::kOfxImageEffectPropOpenGLRenderSupported to be "false" (the
default),
- on CPUs but with optional OpenGL support, in which case they should set
::kOfxImageEffectPropOpenGLRenderSupported to be "true",
- only with OpenGL support, in which case they should set
::kOfxImageEffectPropOpenGLRenderSupported to be "needed".
Hosts can examine this flag and respond to it appropriately.
Effects can use OpenGL accelerated rendering during the following
action...
- ::kOfxImageEffectActionRender
If an effect has indicated that it optionally supports OpenGL acceleration,
it should check the property ::kOfxImageEffectPropOpenGLEnabled
passed as an in argument to the following actions,
- ::kOfxImageEffectActionRender
- ::kOfxImageEffectActionBeginSequenceRender
- ::kOfxImageEffectActionEndSequenceRender
If this property is set to 0, then it should not attempt to use any calls to
the OpenGL suite or OpenGL calls whilst rendering.
@section ofxOpenGLRenderGettingTextures Getting Images as Textures
An effect could fetch an image into memory from a host via the standard
Image Effect suite "clipGetImage" call, then create an OpenGL
texture from that. However as several buffer copies and various other bits
of house keeping may need to happen to do this, it is more
efficient for a host to create the texture directly.
The OfxOpenGLRenderSuiteV1::clipLoadTexture function does this. The
arguments and semantics are similar to the
OfxImageEffectSuiteV2::clipGetImage function, with a few minor changes.
The effect is passed back a property handle describing the texture. Once the
texture is finished with, this should be disposed
of via the OfxOpenGLRenderSuiteV1::clipFreeTexture function, which will also
delete the associated OpenGL texture (for source clips).
The returned handle has a set of properties on it, analogous to the
properties returned on the image handle by
OfxImageEffectSuiteV2::clipGetImage. These are:
- ::kOfxImageEffectPropOpenGLTextureIndex
- ::kOfxImageEffectPropOpenGLTextureTarget
- ::kOfxImageEffectPropPixelDepth
- ::kOfxImageEffectPropComponents
- ::kOfxImageEffectPropPreMultiplication
- ::kOfxImageEffectPropRenderScale
- ::kOfxImagePropPixelAspectRatio
- ::kOfxImagePropBounds
- ::kOfxImagePropRegionOfDefinition
- ::kOfxImagePropRowBytes
- ::kOfxImagePropField
- ::kOfxImagePropUniqueIdentifier
The main difference between this and an image handle is that the
::kOfxImagePropData property is replaced by the
kOfxImageEffectPropOpenGLTextureIndex property.
This integer property should be cast to a GLuint and is the index to use for
the OpenGL texture.
Next to texture handle the texture target enumerator is given in
kOfxImageEffectPropOpenGLTextureTarget
Note, because the image is being directly loaded into a texture by the host
it need not obey the Clip Preferences action to remap the image to the pixel
depth the effect requested.
@section ofxOpenGLRenderOutput Render Output Directly with OpenGL
Effects can use the graphics context as they see fit. They may be doing
several render passes with fetch back from the card to main memory
via 'render to texture' mechanisms interleaved with passes performed on the
CPU. The effect must leave output on the graphics card in the provided output
image texture buffer.
The host will create a default OpenGL viewport that is the size of the
render window passed to the render action. The following
code snippet shows how the viewport should be rooted at the bottom left of
the output texture.
\verbatim
// set up the OpenGL context for the render to texture
...
// figure the size of the render window
int dx = renderWindow.x2 - renderWindow.x1;
int dy = renderWindow.y2 - renderWindow.y2;
// setup the output viewport
glViewport(0, 0, dx, dy);
\endverbatim
Prior to calling the render action the host may also choose to
bind the output texture as the current color buffer (render target), or they
may defer doing this until clipLoadTexture is called for the output clip.
After this, it is completely up to the effect to choose what OpenGL
operations to render with, including projections and so on.
@section ofxOpenGLRenderContext OpenGL Current Context
The host is only required to make the OpenGL context current (e.g.,
using wglMakeCurrent, for Windows) during the following actions:
- ::kOfxImageEffectActionRender
- ::kOfxImageEffectActionBeginSequenceRender
- ::kOfxImageEffectActionEndSequenceRender
- ::kOfxActionOpenGLContextAttached
- ::kOfxActionOpenGLContextDetached
For the first 3 actions, Render through EndSequenceRender, the host is only
required to set the OpenGL context if ::kOfxImageEffectPropOpenGLEnabled is
set. In other words, a plug-in should not expect the OpenGL context to be
current for other OFX calls, such as ::kOfxImageEffectActionDescribeInContext.
*/
}