• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Name
2
3    ARB_map_buffer_range
4
5Name Strings
6
7    GL_ARB_map_buffer_range
8
9Contributors
10
11    Chris Niederauer, Apple (ccn 'at' apple.com)
12    Rob Barris (rbarris 'at' gmail.com)
13    Michael Gold, NVIDIA
14
15Notice
16
17    Copyright (c) 2008-2013 The Khronos Group Inc. Copyright terms at
18        http://www.khronos.org/registry/speccopyright.html
19
20Specification Update Policy
21
22    Khronos-approved extension specifications are updated in response to
23    issues and bugs prioritized by the Khronos OpenGL Working Group. For
24    extensions which have been promoted to a core Specification, fixes will
25    first appear in the latest version of that core Specification, and will
26    eventually be backported to the extension document. This policy is
27    described in more detail at
28        https://www.khronos.org/registry/OpenGL/docs/update_policy.php
29
30Status
31
32    Approved by the ARB on July 11, 2008
33
34Version
35
36    Last Modified Date: June 22, 2012
37    Author Revision: 5
38
39Number
40
41    ARB Extension #50
42
43Dependencies
44
45    OpenGL 2.1 is required.
46
47    If ARB_pixel_buffer_object is NOT supported and the OpenGL version is less
48    than 2.1, ignore references to PIXEL_UNPACK_BUFFER and PIXEL_PACK_BUFFER.
49
50    If EXT_texture_buffer_object is NOT supported, ignore references to
51    TEXTURE_BUFFER_EXT.
52
53    If GL_EXT_bindable_uniform is NOT supported, ignore references to
54    UNIFORM_BUFFER_EXT.
55
56    Written based on the wording of the OpenGL 2.1 specification.
57
58
59Overview
60
61    ARB_map_buffer_range expands the buffer object API to allow greater
62    performance when a client application only needs to write to a sub-range
63    of a buffer object. To that end, this extension introduces two new buffer
64    object features: non-serialized buffer modification and explicit sub-range
65    flushing for mapped buffer objects.
66
67    OpenGL requires that commands occur in a FIFO manner meaning that any
68    changes to buffer objects either block until the data has been processed by
69    the OpenGL pipeline or else create extra copies to avoid such a block.  By
70    providing a method to asynchronously modify buffer object data, an
71    application is then able to manage the synchronization points themselves
72    and modify ranges of data contained by a buffer object even though OpenGL
73    might still be using other parts of it.
74
75    This extension also provides a method for explicitly flushing ranges of a
76    mapped buffer object so OpenGL does not have to assume that the entire
77    range may have been modified.  Further, it allows the application to more
78    precisely specify its intent with respect to reading, writing, and whether
79    the previous contents of a mapped range of interest need be preserved
80    prior to modification.
81
82    Affects ARB_vertex_buffer_object, ARB_pixel_buffer_object and OpenGL 1.5
83    Buffer Objects.
84
85
86Issues
87
88    (1) Why don't the new tokens and entry points in this extension have
89       "ARB" suffixes like other ARB extensions?
90
91        RESOLVED: Unlike a normal ARB extension, this is a strict subset
92        of functionality already approved in OpenGL 3.0. This extension
93        exists only to support that functionality on older hardware that
94        cannot implement a full OpenGL 3.0 driver. Since there are no
95        possible behavior changes between the ARB extension and core
96        features, source code compatibility is improved by not using
97        suffixes on the extension.
98
99
100New Procedures and Functions
101
102    void *MapBufferRange( enum target, intptr offset, sizeiptr length,
103        bitfield access );
104
105    void FlushMappedBufferRange( enum target, intptr offset, sizeiptr length );
106
107
108New Tokens
109
110    Accepted by the <access> parameter of MapBufferRange:
111
112        MAP_READ_BIT                0x0001
113        MAP_WRITE_BIT               0x0002
114        MAP_INVALIDATE_RANGE_BIT    0x0004
115        MAP_INVALIDATE_BUFFER_BIT   0x0008
116        MAP_FLUSH_EXPLICIT_BIT      0x0010
117        MAP_UNSYNCHRONIZED_BIT      0x0020
118
119
120Additions to Chapter 2 of the OpenGL 2.1 Specification (Buffer Objects)
121
122    Add to the end of Section 2.9 (p. 38):
123
124    All or part of the data store of a buffer object may be mapped into the
125    client's address space by calling
126
127        void *MapBufferRange( enum target, intptr offset, sizeiptr length,
128            bitfield access );
129
130    with <target> set to one of ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER,
131    PIXEL_UNPACK_BUFFER, PIXEL_PACK_BUFFER, TEXTURE_BUFFER_EXT, or
132    UNIFORM_BUFFER_EXT. <offset> and <length> indicate the range of data in the
133    buffer object that is to be mapped, in terms of basic machine units.
134    <access> is a bitfield containing flags which describe the requested
135    mapping.  These flags are described below.
136
137    If no error occurs, a pointer to the beginning of the mapped range is
138    returned and may be used to modify and/or query the corresponding range of
139    the buffer, according to the access flags.
140
141    MAP_READ_BIT indicates that the returned pointer may be used to read buffer
142    object data. No GL error is generated if the pointer is used to query a
143    mapping which excludes this flag, but the result is undefined and system
144    errors (possibly including program termination) may occur.
145
146    MAP_WRITE_BIT indicates that the returned pointer may be used to modify
147    buffer object data. No GL error is generated if the pointer is used to
148    modify a mapping which excludes this flag, but the result is undefined and
149    system errors (possibly including program termination) may occur.
150
151    The following optional flags in <access> may be used to modify the mapping:
152
153    MAP_INVALIDATE_RANGE_BIT indicates that the previous contents of the
154    specified range may be discarded. Data within this range is undefined with
155    the exception of subsequently written data. No GL error is generated if
156    subsequent GL operations access unwritten data, but the result is undefined
157    and system errors (possibly including program termination) may occur. This
158    flag may not be used in combination with MAP_READ_BIT.
159
160    MAP_INVALIDATE_BUFFER_BIT indicates that the previous contents of the entire
161    buffer may be discarded. Data within the entire buffer is undefined with the
162    exception of subsequently written data. No GL error is generated if
163    subsequent GL operations access unwritten data, but the result is undefined
164    and system errors (possibly including program termination) may occur. This
165    flag may not be used in combination with MAP_READ_BIT.
166
167    MAP_FLUSH_EXPLICIT_BIT indicates that one or more discrete subranges of the
168    mapping may be modified. When this flag is set, modifications to each
169    subrange must be explicitly flushed by calling FlushMappedBufferRange.  No
170    GL error is set if a subrange of the mapping is modified and not flushed,
171    but data within the corresponding subrange of the buffer is undefined. This
172    flag may only be used in conjunction with MAP_WRITE_BIT.  When this option
173    is selected, flushing is strictly limited to regions that are explicitly
174    indicated with calls to FlushMappedBufferRange prior to unmap; if this
175    option is not selected UnmapBuffer will automatically flush the entire
176    mapped range when called.
177
178    MAP_UNSYNCHRONIZED_BIT indicates that the GL should not attempt to
179    synchronize pending operations on the buffer prior to returning from
180    MapBufferRange. No GL error is generated if pending operations which source
181    or modify the buffer overlap the mapped region, but the result of such
182    previous and any subsequent operations is undefined. This flag may not be
183    used in combination with MAP_READ_BIT.
184
185    MapBufferRange sets buffer object state values as shown in table 2.mbr.
186
187    Name                Value
188    ----                -----
189    BUFFER_ACCESS       Depends on <access>[1]
190    BUFFER_MAPPED       TRUE
191    BUFFER_MAP_POINTER  pointer to the data store
192    BUFFER_MAP_OFFSET   <offset>
193    BUFFER_MAP_LENGTH   <length>
194    ---------------------------------------------
195    Table 2.mbr: Buffer object state set by MapBufferRange.
196        [1] BUFFER_ACCESS is set to READ_ONLY, WRITE_ONLY, or READ_WRITE if
197        <access> & (MAP_READ_BIT|MAP_WRITE_BIT) is respectively
198        MAP_READ_BIT, MAP_WRITE_BIT, or MAP_READ_BIT|MAP_WRITE_BIT.
199
200
201    Errors
202
203    If an error occurs, MapBufferRange returns a NULL pointer.
204
205    INVALID_VALUE is generated if <offset> or <length> is negative, or if
206    offset+length is greater than the value of BUFFER_SIZE.
207
208    INVALID_OPERATION is generated for any of the following conditions:
209
210    - The buffer is already in a mapped state.
211    - Neither MAP_READ_BIT nor MAP_WRITE_BIT is set.
212    - MAP_READ_BIT is set and any of MAP_INVALIDATE_RANGE_BIT,
213      MAP_INVALIDATE_BUFFER_BIT, or MAP_UNSYNCHRONIZED_BIT is set.
214    - MAP_FLUSH_EXPLICIT_BIT is set and MAP_WRITE_BIT is not set.
215
216    No GL error is generated if memory outside the mapped range is modified or
217    queried, but the result is undefined and system errors (possibly including
218    program termination) may occur.
219
220
221    If a buffer is mapped with the MAP_FLUSH_EXPLICIT_BIT flag, modifications
222    to the mapped range may be indicated by calling
223
224        void FlushMappedBufferRange( enum target, intptr offset, sizeiptr length );
225
226    with <target> set to one of ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER,
227    PIXEL_UNPACK_BUFFER, PIXEL_PACK_BUFFER, TEXTURE_BUFFER_EXT, or
228    UNIFORM_BUFFER_EXT, <offset> and <length> indicate a modified subrange of
229    the mapping, in basic machine units.  The specified subrange to flush is
230    relative to the start of the currently mapped range of buffer.
231    FlushMappedBufferRange may be called multiple times to indicate distinct
232    subranges of the mapping which require flushing.
233
234    Errors
235
236    INVALID_VALUE is generated if <offset> or <length> is negative, or if
237    <offset>+<length> exceeds the size of the mapping.
238
239    INVALID_OPERATION is generated if buffer is not mapped, or is mapped without
240    the MAP_FLUSH_EXPLICIT_BIT flag.
241
242Additions to Chapter 2 of the OpenGL 2.0 Specification (Buffer Objects)
243
244Errors
245
246    INVALID_ENUM is generated if the <target> parameter of
247    MapBufferRange and FlushMappedBufferRange is not ARRAY_BUFFER,
248    ELEMENT_ARRAY_BUFFER, PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER,
249    TEXTURE_BUFFER_EXT, or UNIFORM_BUFFER_EXT.
250
251    INVALID_OPERATION is generated if FlushMappedBufferRange is executed
252    while zero is bound to the <target> parameter.
253
254    INVALID_OPERATION is generated if FlushMappedBufferRange is called
255    outside the execution of a MapBufferRange and the corresponding execution of
256    UnmapBuffer.
257
258    INVALID_OPERATION may be generated if any of the commands defined in this
259    extension is executed between the execution of Begin and the corresponding
260    execution of End.
261
262New Implementation Dependent State
263
264    None
265
266GLX Protocol
267
268    FlushMappedBufferRange is an entirely client-side command.
269
270    The following new non-rendering command is added:
271
272    MapBufferRange
273
274        1      CARD8           opcode (X assigned)
275        1      205             GLX opcode
276        2      8               request length
277        4      GLX_CONTEXT_TAG context tag
278        8      CARD64          offset
279        8      CARD64          length
280        4      ENUM            target
281        4      BITFIELD        access
282    =>
283        1      1               reply
284        1                      unused
285        2      CARD16          sequence number
286        4      0               reply length
287        4                      unused
288        4      CARD32          0 on error, otherwise 1.
289        8      CARD64          mapping address
290        8                      unused
291
292Usage Examples
293
294        /* bind and initialize a buffer object */
295    int             size = 65536;
296    glBindBufferARB ( 1, GL_ARRAY_BUFFER_ARB );
297    glBufferDataARB ( GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB );
298
299/* the following are not meant to be executed as a group, since there are no
300 * unmap calls shown here - they are meant to show different combinations of
301 * map options in conjunction with MapBufferRange and FlushMappedBufferRange.
302 */
303
304    /* Map the entire buffer with read and write
305     * (identical semantics to MapBufferARB)
306     */
307    void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, size, MAP_READ_BIT | MAP_WRITE_BIT );
308
309    /* Map the entire buffer as write only
310     */
311    void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, size, MAP_WRITE_BIT );
312
313
314    /* Map the last 1K bytes of the buffer as write only.
315     */
316    void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, size-1024, 1024, MAP_WRITE_BIT );
317
318
319    /* Map the last 1K bytes of the buffer as write only, and invalidate the range.
320     * locations within that range can assume undefined values.
321     * locations written while mapped take on new values as expected.
322     * no changes occur outside the range mapped.
323     */
324    void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, size-1024, 1024, MAP_WRITE_BIT | MAP_INVALIDATE_RANGE_BIT );
325
326
327    /* Map the first 1K bytes of the buffer as write only, and invalidate the entire buffer.
328     * all locations within the buffer can assume undefined values.
329     * locations written while mapped take on new values as expected.
330     */
331    void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, 1024, MAP_WRITE_BIT | MAP_INVALIDATE_BUFFER_BIT );
332
333
334    /* Map the first 32K bytes of the buffer as write only, and invalidate that range.
335     * Indicate that we will explicitly inform GL which ranges are actually written.
336     * Locations within that range can assume undefined values.
337     * Only the locations which are written and subsequently flushed are guaranteed
338     * to take on defined values.
339     * Write data to the first 8KB of the range, then flush it.
340     * Write data to the last 8KB of the range, then flush it.
341     */
342    void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, 32768, MAP_WRITE_BIT | MAP_INVALIDATE_RANGE_BIT | MAP_FLUSH_EXPLICIT_BIT );
343
344    memset( ptr, 0x00, 8192 );                  /* write zeroes to first 8KB of range */
345    FlushMappedBufferRange( GL_ARRAY_BUFFER_ARB, 0, 8192 );
346
347    memset( ((char*)ptr)+24576, 0xFF, 8192 );   /* write FF's to last 8KB of range */
348    FlushMappedBufferRange( GL_ARRAY_BUFFER_ARB, 24576, 8192 );
349
350
351    /* Map the entire buffer for write - unsynchronized.
352     * GL will not block for prior operations to complete.  Application must
353     * use other synchronization techniques to ensure correct operation.
354     */
355    void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, size, MAP_WRITE_BIT | MAP_UNSYNCHRONIZED_BIT);
356
357
358Revision History
359
360    Rev.     Date      Author   Changes
361    ----  ----------  --------  ----------------------------------------------
362      1   06/03/2008     rcb    Initial version with sample code.
363      2   07/07/2008     rcb    Various edits to match GL3 core spec.
364      3   08/07/2008   jleech   Remove ARB suffixes.
365      4   01/24/2011   srahman  Add GLX protocol.
366      5   06/22/2012   jleech   Define how buffer object state is affected
367                                by MapBufferRange.
368