1 {
2 * CVOpenGLTextureCache.h
3 * CoreVideo
4 *
5 * Copyright 2004 Apple Computer, Inc. All rights reserved.
6 *
7 }
8 { Pascal Translation: Gorazd Krosl, <gorazd_1957@yahoo.ca>, 2009 }
9 { Pascal Translation Update: Jonas Maebe <jonas@freepascal.org>, October 2012 }
10 { Pascal Translation Update: Jonas Maebe <jonas@freepascal.org>, August 2015 }
11
12 {
13 Modified for use with Free Pascal
14 Version 308
15 Please report any bugs to <gpc@microbizz.nl>
16 }
17
18 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
19 {$mode macpas}
20 {$modeswitch cblocks}
21 {$packenum 1}
22 {$macro on}
23 {$inline on}
24 {$calling mwpascal}
25
26 unit CVOpenGLTextureCache;
27 interface
28 {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
29 {$setc GAP_INTERFACES_VERSION := $0308}
30
31 {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
32 {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
33 {$endc}
34
35 {$ifc defined CPUPOWERPC and defined CPUI386}
36 {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
37 {$endc}
38 {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
39 {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
40 {$endc}
41
42 {$ifc not defined __ppc__ and defined CPUPOWERPC32}
43 {$setc __ppc__ := 1}
44 {$elsec}
45 {$setc __ppc__ := 0}
46 {$endc}
47 {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
48 {$setc __ppc64__ := 1}
49 {$elsec}
50 {$setc __ppc64__ := 0}
51 {$endc}
52 {$ifc not defined __i386__ and defined CPUI386}
53 {$setc __i386__ := 1}
54 {$elsec}
55 {$setc __i386__ := 0}
56 {$endc}
57 {$ifc not defined __x86_64__ and defined CPUX86_64}
58 {$setc __x86_64__ := 1}
59 {$elsec}
60 {$setc __x86_64__ := 0}
61 {$endc}
62 {$ifc not defined __arm__ and defined CPUARM}
63 {$setc __arm__ := 1}
64 {$elsec}
65 {$setc __arm__ := 0}
66 {$endc}
67 {$ifc not defined __arm64__ and defined CPUAARCH64}
68 {$setc __arm64__ := 1}
69 {$elsec}
70 {$setc __arm64__ := 0}
71 {$endc}
72
73 {$ifc defined cpu64}
74 {$setc __LP64__ := 1}
75 {$elsec}
76 {$setc __LP64__ := 0}
77 {$endc}
78
79
80 {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
81 {$error Conflicting definitions for __ppc__ and __i386__}
82 {$endc}
83
84 {$ifc defined __ppc__ and __ppc__}
85 {$setc TARGET_CPU_PPC := TRUE}
86 {$setc TARGET_CPU_PPC64 := FALSE}
87 {$setc TARGET_CPU_X86 := FALSE}
88 {$setc TARGET_CPU_X86_64 := FALSE}
89 {$setc TARGET_CPU_ARM := FALSE}
90 {$setc TARGET_CPU_ARM64 := FALSE}
91 {$setc TARGET_OS_MAC := TRUE}
92 {$setc TARGET_OS_IPHONE := FALSE}
93 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
94 {$setc TARGET_OS_EMBEDDED := FALSE}
95 {$elifc defined __ppc64__ and __ppc64__}
96 {$setc TARGET_CPU_PPC := FALSE}
97 {$setc TARGET_CPU_PPC64 := TRUE}
98 {$setc TARGET_CPU_X86 := FALSE}
99 {$setc TARGET_CPU_X86_64 := FALSE}
100 {$setc TARGET_CPU_ARM := FALSE}
101 {$setc TARGET_CPU_ARM64 := FALSE}
102 {$setc TARGET_OS_MAC := TRUE}
103 {$setc TARGET_OS_IPHONE := FALSE}
104 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
105 {$setc TARGET_OS_EMBEDDED := FALSE}
106 {$elifc defined __i386__ and __i386__}
107 {$setc TARGET_CPU_PPC := FALSE}
108 {$setc TARGET_CPU_PPC64 := FALSE}
109 {$setc TARGET_CPU_X86 := TRUE}
110 {$setc TARGET_CPU_X86_64 := FALSE}
111 {$setc TARGET_CPU_ARM := FALSE}
112 {$setc TARGET_CPU_ARM64 := FALSE}
113 {$ifc defined iphonesim}
114 {$setc TARGET_OS_MAC := FALSE}
115 {$setc TARGET_OS_IPHONE := TRUE}
116 {$setc TARGET_IPHONE_SIMULATOR := TRUE}
117 {$elsec}
118 {$setc TARGET_OS_MAC := TRUE}
119 {$setc TARGET_OS_IPHONE := FALSE}
120 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
121 {$endc}
122 {$setc TARGET_OS_EMBEDDED := FALSE}
123 {$elifc defined __x86_64__ and __x86_64__}
124 {$setc TARGET_CPU_PPC := FALSE}
125 {$setc TARGET_CPU_PPC64 := FALSE}
126 {$setc TARGET_CPU_X86 := FALSE}
127 {$setc TARGET_CPU_X86_64 := TRUE}
128 {$setc TARGET_CPU_ARM := FALSE}
129 {$setc TARGET_CPU_ARM64 := FALSE}
130 {$ifc defined iphonesim}
131 {$setc TARGET_OS_MAC := FALSE}
132 {$setc TARGET_OS_IPHONE := TRUE}
133 {$setc TARGET_IPHONE_SIMULATOR := TRUE}
134 {$elsec}
135 {$setc TARGET_OS_MAC := TRUE}
136 {$setc TARGET_OS_IPHONE := FALSE}
137 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
138 {$endc}
139 {$setc TARGET_OS_EMBEDDED := FALSE}
140 {$elifc defined __arm__ and __arm__}
141 {$setc TARGET_CPU_PPC := FALSE}
142 {$setc TARGET_CPU_PPC64 := FALSE}
143 {$setc TARGET_CPU_X86 := FALSE}
144 {$setc TARGET_CPU_X86_64 := FALSE}
145 {$setc TARGET_CPU_ARM := TRUE}
146 {$setc TARGET_CPU_ARM64 := FALSE}
147 {$setc TARGET_OS_MAC := FALSE}
148 {$setc TARGET_OS_IPHONE := TRUE}
149 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
150 {$setc TARGET_OS_EMBEDDED := TRUE}
151 {$elifc defined __arm64__ and __arm64__}
152 {$setc TARGET_CPU_PPC := FALSE}
153 {$setc TARGET_CPU_PPC64 := FALSE}
154 {$setc TARGET_CPU_X86 := FALSE}
155 {$setc TARGET_CPU_X86_64 := FALSE}
156 {$setc TARGET_CPU_ARM := FALSE}
157 {$setc TARGET_CPU_ARM64 := TRUE}
158 {$ifc defined ios}
159 {$setc TARGET_OS_MAC := FALSE}
160 {$setc TARGET_OS_IPHONE := TRUE}
161 {$setc TARGET_OS_EMBEDDED := TRUE}
162 {$elsec}
163 {$setc TARGET_OS_MAC := TRUE}
164 {$setc TARGET_OS_IPHONE := FALSE}
165 {$setc TARGET_OS_EMBEDDED := FALSE}
166 {$endc}
167 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
168 {$elsec}
169 {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
170 {$endc}
171
172 {$ifc defined __LP64__ and __LP64__ }
173 {$setc TARGET_CPU_64 := TRUE}
174 {$elsec}
175 {$setc TARGET_CPU_64 := FALSE}
176 {$endc}
177
178 {$ifc defined FPC_BIG_ENDIAN}
179 {$setc TARGET_RT_BIG_ENDIAN := TRUE}
180 {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
181 {$elifc defined FPC_LITTLE_ENDIAN}
182 {$setc TARGET_RT_BIG_ENDIAN := FALSE}
183 {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
184 {$elsec}
185 {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
186 {$endc}
187 {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
188 {$setc CALL_NOT_IN_CARBON := FALSE}
189 {$setc OLDROUTINENAMES := FALSE}
190 {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
191 {$setc OPAQUE_UPP_TYPES := TRUE}
192 {$setc OTCARBONAPPLICATION := TRUE}
193 {$setc OTKERNEL := FALSE}
194 {$setc PM_USE_SESSION_APIS := TRUE}
195 {$setc TARGET_API_MAC_CARBON := TRUE}
196 {$setc TARGET_API_MAC_OS8 := FALSE}
197 {$setc TARGET_API_MAC_OSX := TRUE}
198 {$setc TARGET_CARBON := TRUE}
199 {$setc TARGET_CPU_68K := FALSE}
200 {$setc TARGET_CPU_MIPS := FALSE}
201 {$setc TARGET_CPU_SPARC := FALSE}
202 {$setc TARGET_OS_UNIX := FALSE}
203 {$setc TARGET_OS_WIN32 := FALSE}
204 {$setc TARGET_RT_MAC_68881 := FALSE}
205 {$setc TARGET_RT_MAC_CFM := FALSE}
206 {$setc TARGET_RT_MAC_MACHO := TRUE}
207 {$setc TYPED_FUNCTION_POINTERS := TRUE}
208 {$setc TYPE_BOOL := FALSE}
209 {$setc TYPE_EXTENDED := FALSE}
210 {$setc TYPE_LONGLONG := TRUE}
211 uses MacTypes,CFBase,CFString,CFDictionary,CVBase,CVReturns,CVBuffer,CVImageBuffer,CVOpenGLTexture,CGLTypes;
212 {$endc} {not MACOSALLINCLUDE}
213
214
215 {$ifc TARGET_OS_MAC}
216
217 {$ALIGN POWER}
218
219 {!
220 @typedef CVOpenGLTextureCacheRef
221 @abstract CoreVideo OpenGL Texture Cache
222
223 }
224 type
225 CVOpenGLTextureCacheRef = ^__CVOpenGLTextureCache; { an opaque type }
226 __CVOpenGLTextureCache = record end;
227
228 { Dictionary keys and values for use with the 'cacheAttributes' parameter of CVOpenGLTextureCacheCreate }
229
230 { CVOpenGLTextureCache can (in some cases) do higher quality chroma upsampling on GPUs that support ARB_fragment_program. By
231 default it will be enabled automatically if the texture cache determines that the GPU has the needed support and the image
232 size is something reasonable for the GPU being used. The automatic behaviour can be overridden below. Note that setting
233 kCVOpenGLTextureCacheChromaSamplingModeHighQuality is only a request. GPUs that don't support ARB_fragment_program will still
234 resort back to the native hardware support for YCbCr textures. }
235 var kCVOpenGLTextureCacheChromaSamplingModeKey: CFStringRef; external name '_kCVOpenGLTextureCacheChromaSamplingModeKey'; (* attribute const *)
236 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
237 var kCVOpenGLTextureCacheChromaSamplingModeAutomatic: CFStringRef; external name '_kCVOpenGLTextureCacheChromaSamplingModeAutomatic'; (* attribute const *)
238 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *) // Defaut if the key is not present
239 var kCVOpenGLTextureCacheChromaSamplingModeHighestQuality: CFStringRef; external name '_kCVOpenGLTextureCacheChromaSamplingModeHighestQuality'; (* attribute const *)
240 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *) // Force highest quality regardless of performance impact
241 var kCVOpenGLTextureCacheChromaSamplingModeBestPerformance: CFStringRef; external name '_kCVOpenGLTextureCacheChromaSamplingModeBestPerformance'; (* attribute const *)
242 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *) // Do it the quickest way possible
243
CVOpenGLTextureCacheGetTypeIDnull244 function CVOpenGLTextureCacheGetTypeID: CFTypeID; external name '_CVOpenGLTextureCacheGetTypeID';
245 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
246
247 {!
248 @function CVOpenGLTextureCacheRetain
249 @abstract Retains a CVOpenGLTextureCache object
250 @discussion Equivalent to CFRetain, but NULL safe
251 @param buffer A CVOpenGLTextureCache object that you want to retain.
252 @result A CVOpenGLTextureCache object that is the same as the passed in buffer.
253 }
CVOpenGLTextureCacheRetainnull254 function CVOpenGLTextureCacheRetain( textureCache: CVOpenGLTextureCacheRef ): CVOpenGLTextureCacheRef; external name '_CVOpenGLTextureCacheRetain';
255 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *) // NULL-safe
256
257 {!
258 @function CVOpenGLTextureCacheRelease
259 @abstract Releases a CVOpenGLTextureCache object
260 @discussion Equivalent to CFRelease, but NULL safe
261 @param buffer A CVOpenGLTextureCache object that you want to release.
262 }
263 procedure CVOpenGLTextureCacheRelease( textureCache: CVOpenGLTextureCacheRef ); external name '_CVOpenGLTextureCacheRelease';
264 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *) // NULL-safe
265
266 {!
267 @function CVOpenGLTextureCacheCreate
268 @abstract Creates a new Texture Cache.
269 @param allocator The CFAllocatorRef to use for allocating the cache. May be NULL.
270 @param cacheAttributes A CFDictionaryRef containing the attributes of the cache itself. May be NULL.
271 @param cglContext The OpenGL context into which the texture objects will be created
272 @param cglPixelFormat The OpenGL pixel format object used to create the passed in OpenGL context
273 @param textureAttributes A CFDictionaryRef containing the attributes to be used for creating the CVOpenGLTexture objects. May be NULL.
274 @param cacheOut The newly created texture cache will be placed here
275 @result Returns kCVReturnSuccess on success
276 }
CVOpenGLTextureCacheCreatenull277 function CVOpenGLTextureCacheCreate( allocator: CFAllocatorRef; cacheAttributes: CFDictionaryRef; cglContext: CGLContextObj; cglPixelFormat: CGLPixelFormatObj; textureAttributes: CFDictionaryRef; var cacheOut: CVOpenGLTextureCacheRef ): CVReturn; external name '_CVOpenGLTextureCacheCreate';
278 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
279
280 {!
281 @function CVOpenGLTextureCacheCreateTextureFromImage
282 @abstract Creates a CVOpenGLTexture object from an existing CVImageBuffer
283 @param allocator The CFAllocatorRef to use for allocating the CVOpenGLTexture object. May be NULL.
284 @param textureCache The texture cache object that will manage the texture
285 @param sourceImage The CVImageBuffer that you want to create a CVOpenGLTexture from.
286 @param attributes For Future use only! - The desired buffer attributes for the CVOpenGLTexture.
287 @param textureOut The newly created texture object will be placed here.
288 @result Returns kCVReturnSuccess on success
289 }
CVOpenGLTextureCacheCreateTextureFromImagenull290 function CVOpenGLTextureCacheCreateTextureFromImage( allocator: CFAllocatorRef; textureCache: CVOpenGLTextureCacheRef; sourceImage: CVImageBufferRef; attributes: CFDictionaryRef; var textureOut: CVOpenGLTextureRef ): CVReturn; external name '_CVOpenGLTextureCacheCreateTextureFromImage';
291 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
292
293 {!
294 @function CVOpenGLTextureCacheFlush
295 @abstract Performs internal housekeeping/recycling operations
296 @discussion This call must be made periodically to give the texture cache a chance to make OpenGL calls
297 on the OpenGL context used to create it in order to do housekeeping operations.
298 @param textureCache The texture cache object to flush
299 @param options Currently unused, set to 0.
300 @result Returns kCVReturnSuccess on success
301 }
302 procedure CVOpenGLTextureCacheFlush( textureCache: CVOpenGLTextureCacheRef; options: CVOptionFlags ); external name '_CVOpenGLTextureCacheFlush';
303 (* AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER *)
304
305 {$endc} // TARGET_OS_MAC
306 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
307
308 end.
309 {$endc} {not MACOSALLINCLUDE}
310