1'''OpenGL extension APPLE.fence
2
3This module customises the behaviour of the
4OpenGL.raw.GL.APPLE.fence to provide a more
5Python-friendly API
6
7Overview (from the spec)
8
9	This extension is provided a finer granularity of synchronizing GL command
10	completion than offered by standard OpenGL, which currently offers only two
11	mechanisms for synchronization: Flush and Finish. Since Flush merely assures
12	the user that the commands complete in a finite (though undetermined) amount
13	of time, it is, thus, of only modest utility.  Finish, on the other hand,
14	stalls CPU execution until all pending GL commands have completed forcing
15	completely synchronous operation, which most often not the desired result.
16	This extension offers a middle ground - the ability to "finish" a subset of
17	the command stream, and the ability to determine whether a given command has
18	completed or not.
19
20	This extension introduces the concept of a "fence" to the OpenGL command
21	stream with SetFenceAPPLE.  Once the fence is inserted into the command
22	stream, it can be tested for its completion with TestFenceAPPLE. Moreover,
23	the application may also request a partial Finish up to a particular "fence"
24	using the FinishFenceAPPLE command -- that is, all commands prior to the
25	fence will be forced to complete until control is returned to the calling
26	process.  These new mechanisms allow for synchronization between the host
27	CPU and the GPU, which may be accessing the same resources (typically
28	memory).
29
30	Fences are created and deleted, as are other objects in OpenGL, specifically
31	with GenFencesAPPLE and DeleteFencesAPPLE.  The former returns a list of
32	unused fence names and the later deletes the provided list of fence names.
33
34	In addition to being able to test or finish a fence this extension allows
35	testing for other types of completion, including texture objects, vertex
36	array objects, and draw pixels. This allows the client to use
37	TestObjectAPPLE or FinishObjectAPPLE with FENCE_APPLE, TEXTURE,
38	VERTEX_ARRAY, or DRAW_PIXELS_APPLE with the same type of results as
39	TestFenceAPPLE and FinishFenceAPPLE.  Specifically, using the FENCE_APPLE
40	type is equivalent to calling TestFenceAPPLE or FinishFenceAPPLE with the
41	particular fence name.  Using TEXTURE as the object type tests or waits for
42	completion of a specific texture, meaning when there are no pending
43	rendering commands which use that texture object. Using the VERTEX_ARRAY
44	type will test or wait for drawing commands using that particular vertex
45	array object name.  Finally, DRAW_PIXELS_APPLE will wait or test for
46	completion of all pending DrawPixels commands.  These tests and finishes
47	operate with the same limitations and results as test and finish fence.
48
49	One use of this extension is in conjunction with APPLE_vertex_array_range to
50	determine when graphics hardware has completed accessing vertex data from a
51	vertex array range.  Once a fence has been tested TRUE or finished, all
52	vertex indices issued before the fence must have completed being accessed.
53	This ensures that the vertex data memory corresponding to the issued vertex
54	indices can be safely modified (assuming no other outstanding vertex indices
55	are issued subsequent to the fence).
56
57The official definition of this extension is available here:
58http://www.opengl.org/registry/specs/APPLE/fence.txt
59'''
60from OpenGL import platform, constant, arrays
61from OpenGL import extensions, wrapper
62import ctypes
63from OpenGL.raw.GL import _types, _glgets
64from OpenGL.raw.GL.APPLE.fence import *
65from OpenGL.raw.GL.APPLE.fence import _EXTENSION_NAME
66
67def glInitFenceAPPLE():
68    '''Return boolean indicating whether this extension is available'''
69    from OpenGL import extensions
70    return extensions.hasGLExtension( _EXTENSION_NAME )
71
72glGenFencesAPPLE=wrapper.wrapper(glGenFencesAPPLE).setOutput(
73    'fences',size=lambda x:(x,),pnameArg='n',orPassIn=True
74)
75# INPUT glDeleteFencesAPPLE.fences size not checked against n
76glDeleteFencesAPPLE=wrapper.wrapper(glDeleteFencesAPPLE).setInputArraySize(
77    'fences', None
78)
79### END AUTOGENERATED SECTION