15bd8deadSopenharmony_ciName 25bd8deadSopenharmony_ci 35bd8deadSopenharmony_ci ARB_map_buffer_range 45bd8deadSopenharmony_ci 55bd8deadSopenharmony_ciName Strings 65bd8deadSopenharmony_ci 75bd8deadSopenharmony_ci GL_ARB_map_buffer_range 85bd8deadSopenharmony_ci 95bd8deadSopenharmony_ciContributors 105bd8deadSopenharmony_ci 115bd8deadSopenharmony_ci Chris Niederauer, Apple (ccn 'at' apple.com) 125bd8deadSopenharmony_ci Rob Barris (rbarris 'at' gmail.com) 135bd8deadSopenharmony_ci Michael Gold, NVIDIA 145bd8deadSopenharmony_ci 155bd8deadSopenharmony_ciNotice 165bd8deadSopenharmony_ci 175bd8deadSopenharmony_ci Copyright (c) 2008-2013 The Khronos Group Inc. Copyright terms at 185bd8deadSopenharmony_ci http://www.khronos.org/registry/speccopyright.html 195bd8deadSopenharmony_ci 205bd8deadSopenharmony_ciSpecification Update Policy 215bd8deadSopenharmony_ci 225bd8deadSopenharmony_ci Khronos-approved extension specifications are updated in response to 235bd8deadSopenharmony_ci issues and bugs prioritized by the Khronos OpenGL Working Group. For 245bd8deadSopenharmony_ci extensions which have been promoted to a core Specification, fixes will 255bd8deadSopenharmony_ci first appear in the latest version of that core Specification, and will 265bd8deadSopenharmony_ci eventually be backported to the extension document. This policy is 275bd8deadSopenharmony_ci described in more detail at 285bd8deadSopenharmony_ci https://www.khronos.org/registry/OpenGL/docs/update_policy.php 295bd8deadSopenharmony_ci 305bd8deadSopenharmony_ciStatus 315bd8deadSopenharmony_ci 325bd8deadSopenharmony_ci Approved by the ARB on July 11, 2008 335bd8deadSopenharmony_ci 345bd8deadSopenharmony_ciVersion 355bd8deadSopenharmony_ci 365bd8deadSopenharmony_ci Last Modified Date: June 22, 2012 375bd8deadSopenharmony_ci Author Revision: 5 385bd8deadSopenharmony_ci 395bd8deadSopenharmony_ciNumber 405bd8deadSopenharmony_ci 415bd8deadSopenharmony_ci ARB Extension #50 425bd8deadSopenharmony_ci 435bd8deadSopenharmony_ciDependencies 445bd8deadSopenharmony_ci 455bd8deadSopenharmony_ci OpenGL 2.1 is required. 465bd8deadSopenharmony_ci 475bd8deadSopenharmony_ci If ARB_pixel_buffer_object is NOT supported and the OpenGL version is less 485bd8deadSopenharmony_ci than 2.1, ignore references to PIXEL_UNPACK_BUFFER and PIXEL_PACK_BUFFER. 495bd8deadSopenharmony_ci 505bd8deadSopenharmony_ci If EXT_texture_buffer_object is NOT supported, ignore references to 515bd8deadSopenharmony_ci TEXTURE_BUFFER_EXT. 525bd8deadSopenharmony_ci 535bd8deadSopenharmony_ci If GL_EXT_bindable_uniform is NOT supported, ignore references to 545bd8deadSopenharmony_ci UNIFORM_BUFFER_EXT. 555bd8deadSopenharmony_ci 565bd8deadSopenharmony_ci Written based on the wording of the OpenGL 2.1 specification. 575bd8deadSopenharmony_ci 585bd8deadSopenharmony_ci 595bd8deadSopenharmony_ciOverview 605bd8deadSopenharmony_ci 615bd8deadSopenharmony_ci ARB_map_buffer_range expands the buffer object API to allow greater 625bd8deadSopenharmony_ci performance when a client application only needs to write to a sub-range 635bd8deadSopenharmony_ci of a buffer object. To that end, this extension introduces two new buffer 645bd8deadSopenharmony_ci object features: non-serialized buffer modification and explicit sub-range 655bd8deadSopenharmony_ci flushing for mapped buffer objects. 665bd8deadSopenharmony_ci 675bd8deadSopenharmony_ci OpenGL requires that commands occur in a FIFO manner meaning that any 685bd8deadSopenharmony_ci changes to buffer objects either block until the data has been processed by 695bd8deadSopenharmony_ci the OpenGL pipeline or else create extra copies to avoid such a block. By 705bd8deadSopenharmony_ci providing a method to asynchronously modify buffer object data, an 715bd8deadSopenharmony_ci application is then able to manage the synchronization points themselves 725bd8deadSopenharmony_ci and modify ranges of data contained by a buffer object even though OpenGL 735bd8deadSopenharmony_ci might still be using other parts of it. 745bd8deadSopenharmony_ci 755bd8deadSopenharmony_ci This extension also provides a method for explicitly flushing ranges of a 765bd8deadSopenharmony_ci mapped buffer object so OpenGL does not have to assume that the entire 775bd8deadSopenharmony_ci range may have been modified. Further, it allows the application to more 785bd8deadSopenharmony_ci precisely specify its intent with respect to reading, writing, and whether 795bd8deadSopenharmony_ci the previous contents of a mapped range of interest need be preserved 805bd8deadSopenharmony_ci prior to modification. 815bd8deadSopenharmony_ci 825bd8deadSopenharmony_ci Affects ARB_vertex_buffer_object, ARB_pixel_buffer_object and OpenGL 1.5 835bd8deadSopenharmony_ci Buffer Objects. 845bd8deadSopenharmony_ci 855bd8deadSopenharmony_ci 865bd8deadSopenharmony_ciIssues 875bd8deadSopenharmony_ci 885bd8deadSopenharmony_ci (1) Why don't the new tokens and entry points in this extension have 895bd8deadSopenharmony_ci "ARB" suffixes like other ARB extensions? 905bd8deadSopenharmony_ci 915bd8deadSopenharmony_ci RESOLVED: Unlike a normal ARB extension, this is a strict subset 925bd8deadSopenharmony_ci of functionality already approved in OpenGL 3.0. This extension 935bd8deadSopenharmony_ci exists only to support that functionality on older hardware that 945bd8deadSopenharmony_ci cannot implement a full OpenGL 3.0 driver. Since there are no 955bd8deadSopenharmony_ci possible behavior changes between the ARB extension and core 965bd8deadSopenharmony_ci features, source code compatibility is improved by not using 975bd8deadSopenharmony_ci suffixes on the extension. 985bd8deadSopenharmony_ci 995bd8deadSopenharmony_ci 1005bd8deadSopenharmony_ciNew Procedures and Functions 1015bd8deadSopenharmony_ci 1025bd8deadSopenharmony_ci void *MapBufferRange( enum target, intptr offset, sizeiptr length, 1035bd8deadSopenharmony_ci bitfield access ); 1045bd8deadSopenharmony_ci 1055bd8deadSopenharmony_ci void FlushMappedBufferRange( enum target, intptr offset, sizeiptr length ); 1065bd8deadSopenharmony_ci 1075bd8deadSopenharmony_ci 1085bd8deadSopenharmony_ciNew Tokens 1095bd8deadSopenharmony_ci 1105bd8deadSopenharmony_ci Accepted by the <access> parameter of MapBufferRange: 1115bd8deadSopenharmony_ci 1125bd8deadSopenharmony_ci MAP_READ_BIT 0x0001 1135bd8deadSopenharmony_ci MAP_WRITE_BIT 0x0002 1145bd8deadSopenharmony_ci MAP_INVALIDATE_RANGE_BIT 0x0004 1155bd8deadSopenharmony_ci MAP_INVALIDATE_BUFFER_BIT 0x0008 1165bd8deadSopenharmony_ci MAP_FLUSH_EXPLICIT_BIT 0x0010 1175bd8deadSopenharmony_ci MAP_UNSYNCHRONIZED_BIT 0x0020 1185bd8deadSopenharmony_ci 1195bd8deadSopenharmony_ci 1205bd8deadSopenharmony_ciAdditions to Chapter 2 of the OpenGL 2.1 Specification (Buffer Objects) 1215bd8deadSopenharmony_ci 1225bd8deadSopenharmony_ci Add to the end of Section 2.9 (p. 38): 1235bd8deadSopenharmony_ci 1245bd8deadSopenharmony_ci All or part of the data store of a buffer object may be mapped into the 1255bd8deadSopenharmony_ci client's address space by calling 1265bd8deadSopenharmony_ci 1275bd8deadSopenharmony_ci void *MapBufferRange( enum target, intptr offset, sizeiptr length, 1285bd8deadSopenharmony_ci bitfield access ); 1295bd8deadSopenharmony_ci 1305bd8deadSopenharmony_ci with <target> set to one of ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER, 1315bd8deadSopenharmony_ci PIXEL_UNPACK_BUFFER, PIXEL_PACK_BUFFER, TEXTURE_BUFFER_EXT, or 1325bd8deadSopenharmony_ci UNIFORM_BUFFER_EXT. <offset> and <length> indicate the range of data in the 1335bd8deadSopenharmony_ci buffer object that is to be mapped, in terms of basic machine units. 1345bd8deadSopenharmony_ci <access> is a bitfield containing flags which describe the requested 1355bd8deadSopenharmony_ci mapping. These flags are described below. 1365bd8deadSopenharmony_ci 1375bd8deadSopenharmony_ci If no error occurs, a pointer to the beginning of the mapped range is 1385bd8deadSopenharmony_ci returned and may be used to modify and/or query the corresponding range of 1395bd8deadSopenharmony_ci the buffer, according to the access flags. 1405bd8deadSopenharmony_ci 1415bd8deadSopenharmony_ci MAP_READ_BIT indicates that the returned pointer may be used to read buffer 1425bd8deadSopenharmony_ci object data. No GL error is generated if the pointer is used to query a 1435bd8deadSopenharmony_ci mapping which excludes this flag, but the result is undefined and system 1445bd8deadSopenharmony_ci errors (possibly including program termination) may occur. 1455bd8deadSopenharmony_ci 1465bd8deadSopenharmony_ci MAP_WRITE_BIT indicates that the returned pointer may be used to modify 1475bd8deadSopenharmony_ci buffer object data. No GL error is generated if the pointer is used to 1485bd8deadSopenharmony_ci modify a mapping which excludes this flag, but the result is undefined and 1495bd8deadSopenharmony_ci system errors (possibly including program termination) may occur. 1505bd8deadSopenharmony_ci 1515bd8deadSopenharmony_ci The following optional flags in <access> may be used to modify the mapping: 1525bd8deadSopenharmony_ci 1535bd8deadSopenharmony_ci MAP_INVALIDATE_RANGE_BIT indicates that the previous contents of the 1545bd8deadSopenharmony_ci specified range may be discarded. Data within this range is undefined with 1555bd8deadSopenharmony_ci the exception of subsequently written data. No GL error is generated if 1565bd8deadSopenharmony_ci subsequent GL operations access unwritten data, but the result is undefined 1575bd8deadSopenharmony_ci and system errors (possibly including program termination) may occur. This 1585bd8deadSopenharmony_ci flag may not be used in combination with MAP_READ_BIT. 1595bd8deadSopenharmony_ci 1605bd8deadSopenharmony_ci MAP_INVALIDATE_BUFFER_BIT indicates that the previous contents of the entire 1615bd8deadSopenharmony_ci buffer may be discarded. Data within the entire buffer is undefined with the 1625bd8deadSopenharmony_ci exception of subsequently written data. No GL error is generated if 1635bd8deadSopenharmony_ci subsequent GL operations access unwritten data, but the result is undefined 1645bd8deadSopenharmony_ci and system errors (possibly including program termination) may occur. This 1655bd8deadSopenharmony_ci flag may not be used in combination with MAP_READ_BIT. 1665bd8deadSopenharmony_ci 1675bd8deadSopenharmony_ci MAP_FLUSH_EXPLICIT_BIT indicates that one or more discrete subranges of the 1685bd8deadSopenharmony_ci mapping may be modified. When this flag is set, modifications to each 1695bd8deadSopenharmony_ci subrange must be explicitly flushed by calling FlushMappedBufferRange. No 1705bd8deadSopenharmony_ci GL error is set if a subrange of the mapping is modified and not flushed, 1715bd8deadSopenharmony_ci but data within the corresponding subrange of the buffer is undefined. This 1725bd8deadSopenharmony_ci flag may only be used in conjunction with MAP_WRITE_BIT. When this option 1735bd8deadSopenharmony_ci is selected, flushing is strictly limited to regions that are explicitly 1745bd8deadSopenharmony_ci indicated with calls to FlushMappedBufferRange prior to unmap; if this 1755bd8deadSopenharmony_ci option is not selected UnmapBuffer will automatically flush the entire 1765bd8deadSopenharmony_ci mapped range when called. 1775bd8deadSopenharmony_ci 1785bd8deadSopenharmony_ci MAP_UNSYNCHRONIZED_BIT indicates that the GL should not attempt to 1795bd8deadSopenharmony_ci synchronize pending operations on the buffer prior to returning from 1805bd8deadSopenharmony_ci MapBufferRange. No GL error is generated if pending operations which source 1815bd8deadSopenharmony_ci or modify the buffer overlap the mapped region, but the result of such 1825bd8deadSopenharmony_ci previous and any subsequent operations is undefined. This flag may not be 1835bd8deadSopenharmony_ci used in combination with MAP_READ_BIT. 1845bd8deadSopenharmony_ci 1855bd8deadSopenharmony_ci MapBufferRange sets buffer object state values as shown in table 2.mbr. 1865bd8deadSopenharmony_ci 1875bd8deadSopenharmony_ci Name Value 1885bd8deadSopenharmony_ci ---- ----- 1895bd8deadSopenharmony_ci BUFFER_ACCESS Depends on <access>[1] 1905bd8deadSopenharmony_ci BUFFER_MAPPED TRUE 1915bd8deadSopenharmony_ci BUFFER_MAP_POINTER pointer to the data store 1925bd8deadSopenharmony_ci BUFFER_MAP_OFFSET <offset> 1935bd8deadSopenharmony_ci BUFFER_MAP_LENGTH <length> 1945bd8deadSopenharmony_ci --------------------------------------------- 1955bd8deadSopenharmony_ci Table 2.mbr: Buffer object state set by MapBufferRange. 1965bd8deadSopenharmony_ci [1] BUFFER_ACCESS is set to READ_ONLY, WRITE_ONLY, or READ_WRITE if 1975bd8deadSopenharmony_ci <access> & (MAP_READ_BIT|MAP_WRITE_BIT) is respectively 1985bd8deadSopenharmony_ci MAP_READ_BIT, MAP_WRITE_BIT, or MAP_READ_BIT|MAP_WRITE_BIT. 1995bd8deadSopenharmony_ci 2005bd8deadSopenharmony_ci 2015bd8deadSopenharmony_ci Errors 2025bd8deadSopenharmony_ci 2035bd8deadSopenharmony_ci If an error occurs, MapBufferRange returns a NULL pointer. 2045bd8deadSopenharmony_ci 2055bd8deadSopenharmony_ci INVALID_VALUE is generated if <offset> or <length> is negative, or if 2065bd8deadSopenharmony_ci offset+length is greater than the value of BUFFER_SIZE. 2075bd8deadSopenharmony_ci 2085bd8deadSopenharmony_ci INVALID_OPERATION is generated for any of the following conditions: 2095bd8deadSopenharmony_ci 2105bd8deadSopenharmony_ci - The buffer is already in a mapped state. 2115bd8deadSopenharmony_ci - Neither MAP_READ_BIT nor MAP_WRITE_BIT is set. 2125bd8deadSopenharmony_ci - MAP_READ_BIT is set and any of MAP_INVALIDATE_RANGE_BIT, 2135bd8deadSopenharmony_ci MAP_INVALIDATE_BUFFER_BIT, or MAP_UNSYNCHRONIZED_BIT is set. 2145bd8deadSopenharmony_ci - MAP_FLUSH_EXPLICIT_BIT is set and MAP_WRITE_BIT is not set. 2155bd8deadSopenharmony_ci 2165bd8deadSopenharmony_ci No GL error is generated if memory outside the mapped range is modified or 2175bd8deadSopenharmony_ci queried, but the result is undefined and system errors (possibly including 2185bd8deadSopenharmony_ci program termination) may occur. 2195bd8deadSopenharmony_ci 2205bd8deadSopenharmony_ci 2215bd8deadSopenharmony_ci If a buffer is mapped with the MAP_FLUSH_EXPLICIT_BIT flag, modifications 2225bd8deadSopenharmony_ci to the mapped range may be indicated by calling 2235bd8deadSopenharmony_ci 2245bd8deadSopenharmony_ci void FlushMappedBufferRange( enum target, intptr offset, sizeiptr length ); 2255bd8deadSopenharmony_ci 2265bd8deadSopenharmony_ci with <target> set to one of ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER, 2275bd8deadSopenharmony_ci PIXEL_UNPACK_BUFFER, PIXEL_PACK_BUFFER, TEXTURE_BUFFER_EXT, or 2285bd8deadSopenharmony_ci UNIFORM_BUFFER_EXT, <offset> and <length> indicate a modified subrange of 2295bd8deadSopenharmony_ci the mapping, in basic machine units. The specified subrange to flush is 2305bd8deadSopenharmony_ci relative to the start of the currently mapped range of buffer. 2315bd8deadSopenharmony_ci FlushMappedBufferRange may be called multiple times to indicate distinct 2325bd8deadSopenharmony_ci subranges of the mapping which require flushing. 2335bd8deadSopenharmony_ci 2345bd8deadSopenharmony_ci Errors 2355bd8deadSopenharmony_ci 2365bd8deadSopenharmony_ci INVALID_VALUE is generated if <offset> or <length> is negative, or if 2375bd8deadSopenharmony_ci <offset>+<length> exceeds the size of the mapping. 2385bd8deadSopenharmony_ci 2395bd8deadSopenharmony_ci INVALID_OPERATION is generated if buffer is not mapped, or is mapped without 2405bd8deadSopenharmony_ci the MAP_FLUSH_EXPLICIT_BIT flag. 2415bd8deadSopenharmony_ci 2425bd8deadSopenharmony_ciAdditions to Chapter 2 of the OpenGL 2.0 Specification (Buffer Objects) 2435bd8deadSopenharmony_ci 2445bd8deadSopenharmony_ciErrors 2455bd8deadSopenharmony_ci 2465bd8deadSopenharmony_ci INVALID_ENUM is generated if the <target> parameter of 2475bd8deadSopenharmony_ci MapBufferRange and FlushMappedBufferRange is not ARRAY_BUFFER, 2485bd8deadSopenharmony_ci ELEMENT_ARRAY_BUFFER, PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER, 2495bd8deadSopenharmony_ci TEXTURE_BUFFER_EXT, or UNIFORM_BUFFER_EXT. 2505bd8deadSopenharmony_ci 2515bd8deadSopenharmony_ci INVALID_OPERATION is generated if FlushMappedBufferRange is executed 2525bd8deadSopenharmony_ci while zero is bound to the <target> parameter. 2535bd8deadSopenharmony_ci 2545bd8deadSopenharmony_ci INVALID_OPERATION is generated if FlushMappedBufferRange is called 2555bd8deadSopenharmony_ci outside the execution of a MapBufferRange and the corresponding execution of 2565bd8deadSopenharmony_ci UnmapBuffer. 2575bd8deadSopenharmony_ci 2585bd8deadSopenharmony_ci INVALID_OPERATION may be generated if any of the commands defined in this 2595bd8deadSopenharmony_ci extension is executed between the execution of Begin and the corresponding 2605bd8deadSopenharmony_ci execution of End. 2615bd8deadSopenharmony_ci 2625bd8deadSopenharmony_ciNew Implementation Dependent State 2635bd8deadSopenharmony_ci 2645bd8deadSopenharmony_ci None 2655bd8deadSopenharmony_ci 2665bd8deadSopenharmony_ciGLX Protocol 2675bd8deadSopenharmony_ci 2685bd8deadSopenharmony_ci FlushMappedBufferRange is an entirely client-side command. 2695bd8deadSopenharmony_ci 2705bd8deadSopenharmony_ci The following new non-rendering command is added: 2715bd8deadSopenharmony_ci 2725bd8deadSopenharmony_ci MapBufferRange 2735bd8deadSopenharmony_ci 2745bd8deadSopenharmony_ci 1 CARD8 opcode (X assigned) 2755bd8deadSopenharmony_ci 1 205 GLX opcode 2765bd8deadSopenharmony_ci 2 8 request length 2775bd8deadSopenharmony_ci 4 GLX_CONTEXT_TAG context tag 2785bd8deadSopenharmony_ci 8 CARD64 offset 2795bd8deadSopenharmony_ci 8 CARD64 length 2805bd8deadSopenharmony_ci 4 ENUM target 2815bd8deadSopenharmony_ci 4 BITFIELD access 2825bd8deadSopenharmony_ci => 2835bd8deadSopenharmony_ci 1 1 reply 2845bd8deadSopenharmony_ci 1 unused 2855bd8deadSopenharmony_ci 2 CARD16 sequence number 2865bd8deadSopenharmony_ci 4 0 reply length 2875bd8deadSopenharmony_ci 4 unused 2885bd8deadSopenharmony_ci 4 CARD32 0 on error, otherwise 1. 2895bd8deadSopenharmony_ci 8 CARD64 mapping address 2905bd8deadSopenharmony_ci 8 unused 2915bd8deadSopenharmony_ci 2925bd8deadSopenharmony_ciUsage Examples 2935bd8deadSopenharmony_ci 2945bd8deadSopenharmony_ci /* bind and initialize a buffer object */ 2955bd8deadSopenharmony_ci int size = 65536; 2965bd8deadSopenharmony_ci glBindBufferARB ( 1, GL_ARRAY_BUFFER_ARB ); 2975bd8deadSopenharmony_ci glBufferDataARB ( GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB ); 2985bd8deadSopenharmony_ci 2995bd8deadSopenharmony_ci/* the following are not meant to be executed as a group, since there are no 3005bd8deadSopenharmony_ci * unmap calls shown here - they are meant to show different combinations of 3015bd8deadSopenharmony_ci * map options in conjunction with MapBufferRange and FlushMappedBufferRange. 3025bd8deadSopenharmony_ci */ 3035bd8deadSopenharmony_ci 3045bd8deadSopenharmony_ci /* Map the entire buffer with read and write 3055bd8deadSopenharmony_ci * (identical semantics to MapBufferARB) 3065bd8deadSopenharmony_ci */ 3075bd8deadSopenharmony_ci void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, size, MAP_READ_BIT | MAP_WRITE_BIT ); 3085bd8deadSopenharmony_ci 3095bd8deadSopenharmony_ci /* Map the entire buffer as write only 3105bd8deadSopenharmony_ci */ 3115bd8deadSopenharmony_ci void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, size, MAP_WRITE_BIT ); 3125bd8deadSopenharmony_ci 3135bd8deadSopenharmony_ci 3145bd8deadSopenharmony_ci /* Map the last 1K bytes of the buffer as write only. 3155bd8deadSopenharmony_ci */ 3165bd8deadSopenharmony_ci void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, size-1024, 1024, MAP_WRITE_BIT ); 3175bd8deadSopenharmony_ci 3185bd8deadSopenharmony_ci 3195bd8deadSopenharmony_ci /* Map the last 1K bytes of the buffer as write only, and invalidate the range. 3205bd8deadSopenharmony_ci * locations within that range can assume undefined values. 3215bd8deadSopenharmony_ci * locations written while mapped take on new values as expected. 3225bd8deadSopenharmony_ci * no changes occur outside the range mapped. 3235bd8deadSopenharmony_ci */ 3245bd8deadSopenharmony_ci void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, size-1024, 1024, MAP_WRITE_BIT | MAP_INVALIDATE_RANGE_BIT ); 3255bd8deadSopenharmony_ci 3265bd8deadSopenharmony_ci 3275bd8deadSopenharmony_ci /* Map the first 1K bytes of the buffer as write only, and invalidate the entire buffer. 3285bd8deadSopenharmony_ci * all locations within the buffer can assume undefined values. 3295bd8deadSopenharmony_ci * locations written while mapped take on new values as expected. 3305bd8deadSopenharmony_ci */ 3315bd8deadSopenharmony_ci void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, 1024, MAP_WRITE_BIT | MAP_INVALIDATE_BUFFER_BIT ); 3325bd8deadSopenharmony_ci 3335bd8deadSopenharmony_ci 3345bd8deadSopenharmony_ci /* Map the first 32K bytes of the buffer as write only, and invalidate that range. 3355bd8deadSopenharmony_ci * Indicate that we will explicitly inform GL which ranges are actually written. 3365bd8deadSopenharmony_ci * Locations within that range can assume undefined values. 3375bd8deadSopenharmony_ci * Only the locations which are written and subsequently flushed are guaranteed 3385bd8deadSopenharmony_ci * to take on defined values. 3395bd8deadSopenharmony_ci * Write data to the first 8KB of the range, then flush it. 3405bd8deadSopenharmony_ci * Write data to the last 8KB of the range, then flush it. 3415bd8deadSopenharmony_ci */ 3425bd8deadSopenharmony_ci void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, 32768, MAP_WRITE_BIT | MAP_INVALIDATE_RANGE_BIT | MAP_FLUSH_EXPLICIT_BIT ); 3435bd8deadSopenharmony_ci 3445bd8deadSopenharmony_ci memset( ptr, 0x00, 8192 ); /* write zeroes to first 8KB of range */ 3455bd8deadSopenharmony_ci FlushMappedBufferRange( GL_ARRAY_BUFFER_ARB, 0, 8192 ); 3465bd8deadSopenharmony_ci 3475bd8deadSopenharmony_ci memset( ((char*)ptr)+24576, 0xFF, 8192 ); /* write FF's to last 8KB of range */ 3485bd8deadSopenharmony_ci FlushMappedBufferRange( GL_ARRAY_BUFFER_ARB, 24576, 8192 ); 3495bd8deadSopenharmony_ci 3505bd8deadSopenharmony_ci 3515bd8deadSopenharmony_ci /* Map the entire buffer for write - unsynchronized. 3525bd8deadSopenharmony_ci * GL will not block for prior operations to complete. Application must 3535bd8deadSopenharmony_ci * use other synchronization techniques to ensure correct operation. 3545bd8deadSopenharmony_ci */ 3555bd8deadSopenharmony_ci void *ptr = glMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, size, MAP_WRITE_BIT | MAP_UNSYNCHRONIZED_BIT); 3565bd8deadSopenharmony_ci 3575bd8deadSopenharmony_ci 3585bd8deadSopenharmony_ciRevision History 3595bd8deadSopenharmony_ci 3605bd8deadSopenharmony_ci Rev. Date Author Changes 3615bd8deadSopenharmony_ci ---- ---------- -------- ---------------------------------------------- 3625bd8deadSopenharmony_ci 1 06/03/2008 rcb Initial version with sample code. 3635bd8deadSopenharmony_ci 2 07/07/2008 rcb Various edits to match GL3 core spec. 3645bd8deadSopenharmony_ci 3 08/07/2008 jleech Remove ARB suffixes. 3655bd8deadSopenharmony_ci 4 01/24/2011 srahman Add GLX protocol. 3665bd8deadSopenharmony_ci 5 06/22/2012 jleech Define how buffer object state is affected 3675bd8deadSopenharmony_ci by MapBufferRange. 368