15bd8deadSopenharmony_ciName 25bd8deadSopenharmony_ci 35bd8deadSopenharmony_ci ARB_occlusion_query 45bd8deadSopenharmony_ci 55bd8deadSopenharmony_ciName Strings 65bd8deadSopenharmony_ci 75bd8deadSopenharmony_ci GL_ARB_occlusion_query 85bd8deadSopenharmony_ci 95bd8deadSopenharmony_ciContributors 105bd8deadSopenharmony_ci 115bd8deadSopenharmony_ci Ross Cunniff 125bd8deadSopenharmony_ci Matt Craighead 135bd8deadSopenharmony_ci Daniel Ginsburg 145bd8deadSopenharmony_ci Kevin Lefebvre 155bd8deadSopenharmony_ci Bill Licea-Kane 165bd8deadSopenharmony_ci Nick Triantos 175bd8deadSopenharmony_ci 185bd8deadSopenharmony_ciContact 195bd8deadSopenharmony_ci 205bd8deadSopenharmony_ci Matt Craighead, NVIDIA Corporation (mcraighead 'at' nvidia.com) 215bd8deadSopenharmony_ci Daniel Ginsburg, AMD (dan.ginsburg 'at' amd.com) 225bd8deadSopenharmony_ci 235bd8deadSopenharmony_ciNotice 245bd8deadSopenharmony_ci 255bd8deadSopenharmony_ci Copyright (c) 2003-2013 The Khronos Group Inc. Copyright terms at 265bd8deadSopenharmony_ci http://www.khronos.org/registry/speccopyright.html 275bd8deadSopenharmony_ci 285bd8deadSopenharmony_ciSpecification Update Policy 295bd8deadSopenharmony_ci 305bd8deadSopenharmony_ci Khronos-approved extension specifications are updated in response to 315bd8deadSopenharmony_ci issues and bugs prioritized by the Khronos OpenGL Working Group. For 325bd8deadSopenharmony_ci extensions which have been promoted to a core Specification, fixes will 335bd8deadSopenharmony_ci first appear in the latest version of that core Specification, and will 345bd8deadSopenharmony_ci eventually be backported to the extension document. This policy is 355bd8deadSopenharmony_ci described in more detail at 365bd8deadSopenharmony_ci https://www.khronos.org/registry/OpenGL/docs/update_policy.php 375bd8deadSopenharmony_ci 385bd8deadSopenharmony_ciIP Status 395bd8deadSopenharmony_ci 405bd8deadSopenharmony_ci HP has claimed that they hold IP around use of this extension. HP 415bd8deadSopenharmony_ci has committed to releasing rights to this IP to the ARB if the 425bd8deadSopenharmony_ci functionality is included in OpenGL (April 10, 2003). 435bd8deadSopenharmony_ci 445bd8deadSopenharmony_ciStatus 455bd8deadSopenharmony_ci 465bd8deadSopenharmony_ci Approved by the ARB (version 1.0), June 10, 2003, pending further minor 475bd8deadSopenharmony_ci revisions 485bd8deadSopenharmony_ci 495bd8deadSopenharmony_ciVersion 505bd8deadSopenharmony_ci 515bd8deadSopenharmony_ci Date: April 21, 2007 525bd8deadSopenharmony_ci Revision: 7 535bd8deadSopenharmony_ci $Id$ 545bd8deadSopenharmony_ci 555bd8deadSopenharmony_ciNumber 565bd8deadSopenharmony_ci 575bd8deadSopenharmony_ci ARB Extension #29 585bd8deadSopenharmony_ci 595bd8deadSopenharmony_ciDependencies 605bd8deadSopenharmony_ci 615bd8deadSopenharmony_ci Written based on the wording of the OpenGL 1.4 specification. 625bd8deadSopenharmony_ci 635bd8deadSopenharmony_ci HP_occlusion_test affects the definition of this extension. 645bd8deadSopenharmony_ci 655bd8deadSopenharmony_ciOverview 665bd8deadSopenharmony_ci 675bd8deadSopenharmony_ci This extension defines a mechanism whereby an application can query 685bd8deadSopenharmony_ci the number of pixels (or, more precisely, samples) drawn by a 695bd8deadSopenharmony_ci primitive or group of primitives. 705bd8deadSopenharmony_ci 715bd8deadSopenharmony_ci The primary purpose of such a query (hereafter referred to as an 725bd8deadSopenharmony_ci "occlusion query") is to determine the visibility of an object. 735bd8deadSopenharmony_ci Typically, the application will render the major occluders in the 745bd8deadSopenharmony_ci scene, then perform an occlusion query for the bounding box of each 755bd8deadSopenharmony_ci detail object in the scene. Only if said bounding box is visible, 765bd8deadSopenharmony_ci i.e., if at least one sample is drawn, should the corresponding object 775bd8deadSopenharmony_ci be drawn. 785bd8deadSopenharmony_ci 795bd8deadSopenharmony_ci The earlier HP_occlusion_test extension defined a similar mechanism, 805bd8deadSopenharmony_ci but it had two major shortcomings. 815bd8deadSopenharmony_ci 825bd8deadSopenharmony_ci - It returned the result as a simple GL_TRUE/GL_FALSE result, when in 835bd8deadSopenharmony_ci fact it is often useful to know exactly how many samples were 845bd8deadSopenharmony_ci drawn. 855bd8deadSopenharmony_ci - It provided only a simple "stop-and-wait" model for using multiple 865bd8deadSopenharmony_ci queries. The application begins an occlusion test and ends it; 875bd8deadSopenharmony_ci then, at some later point, it asks for the result, at which point 885bd8deadSopenharmony_ci the driver must stop and wait until the result from the previous 895bd8deadSopenharmony_ci test is back before the application can even begin the next one. 905bd8deadSopenharmony_ci This is a very simple model, but its performance is mediocre when 915bd8deadSopenharmony_ci an application wishes to perform many queries, and it eliminates 925bd8deadSopenharmony_ci most of the opportunities for parallelism between the CPU and GPU. 935bd8deadSopenharmony_ci 945bd8deadSopenharmony_ci This extension solves both of those problems. It returns as its 955bd8deadSopenharmony_ci result the number of samples that pass the depth and stencil tests, 965bd8deadSopenharmony_ci and it encapsulates occlusion queries in "query objects" that allow 975bd8deadSopenharmony_ci applications to issue many queries before asking for the result of 985bd8deadSopenharmony_ci any one. As a result, they can overlap the time it takes for the 995bd8deadSopenharmony_ci occlusion query results to be returned with other, more useful work, 1005bd8deadSopenharmony_ci such as rendering other parts of the scene or performing other 1015bd8deadSopenharmony_ci computations on the CPU. 1025bd8deadSopenharmony_ci 1035bd8deadSopenharmony_ci There are many situations where a pixel/sample count, rather than a 1045bd8deadSopenharmony_ci boolean result, is useful. 1055bd8deadSopenharmony_ci 1065bd8deadSopenharmony_ci - Objects that are visible but cover only a very small number of 1075bd8deadSopenharmony_ci pixels can be skipped at a minimal reduction of image quality. 1085bd8deadSopenharmony_ci - Knowing exactly how many pixels an object might cover may help the 1095bd8deadSopenharmony_ci application decide which level-of-detail model should be used. If 1105bd8deadSopenharmony_ci only a few pixels are visible, a low-detail model may be 1115bd8deadSopenharmony_ci acceptable. 1125bd8deadSopenharmony_ci - "Depth peeling" techniques, such as order-independent transparency, 1135bd8deadSopenharmony_ci need to know when to stop rendering more layers; it is difficult to 1145bd8deadSopenharmony_ci determine a priori how many layers are needed. A boolean result 1155bd8deadSopenharmony_ci allows applications to stop when more layers will not affect the 1165bd8deadSopenharmony_ci image at all, but this will likely result in unacceptable 1175bd8deadSopenharmony_ci performance. Instead, it makes more sense to stop rendering when 1185bd8deadSopenharmony_ci the number of pixels in each layer falls below a given threshold. 1195bd8deadSopenharmony_ci - Occlusion queries can replace glReadPixels of the depth buffer to 1205bd8deadSopenharmony_ci determine whether (for example) a light source is visible for the 1215bd8deadSopenharmony_ci purposes of a lens flare effect or a halo to simulate glare. Pixel 1225bd8deadSopenharmony_ci counts allow you to compute the percentage of the light source that 1235bd8deadSopenharmony_ci is visible, and the brightness of these effects can be modulated 1245bd8deadSopenharmony_ci accordingly. 1255bd8deadSopenharmony_ci 1265bd8deadSopenharmony_ciIssues 1275bd8deadSopenharmony_ci 1285bd8deadSopenharmony_ci How is this extension different from NV_occlusion_query? 1295bd8deadSopenharmony_ci 1305bd8deadSopenharmony_ci The following changes have been made. 1315bd8deadSopenharmony_ci - A "target" parameter has been added. Only one target exists at 1325bd8deadSopenharmony_ci present, SAMPLES_PASSED_ARB, but future extensions could add 1335bd8deadSopenharmony_ci additional types of queries. 1345bd8deadSopenharmony_ci - Terminology changed slightly. "Pixel" was being used 1355bd8deadSopenharmony_ci incorrectly, where "fragment" or "sample" would be more 1365bd8deadSopenharmony_ci accurate. 1375bd8deadSopenharmony_ci - Various NVIDIA-specific references have been removed. 1385bd8deadSopenharmony_ci - Interactions with multisample have been changed slightly to 1395bd8deadSopenharmony_ci allow implementations based on either a sample count or a 1405bd8deadSopenharmony_ci fragment count. The result is returned in units of samples. 1415bd8deadSopenharmony_ci - Clarified that using an id of zero is illegal. 1425bd8deadSopenharmony_ci - Added missing spec language for IsQuery entry point. 1435bd8deadSopenharmony_ci - General language, issues, etc. cleanup. 1445bd8deadSopenharmony_ci - HP_occlusion_test is no longer required. 1455bd8deadSopenharmony_ci - Modified the minimum required counter bits to be dependent on 1465bd8deadSopenharmony_ci the implementation's maximum viewport or the value 0 1475bd8deadSopenharmony_ci - Clarified that active query state is per target server state. 1485bd8deadSopenharmony_ci This implies that a loop of QUERY_RESULT_AVAILABLE_ARB will 1495bd8deadSopenharmony_ci return TRUE in finite time. NV_occlusion_query asked 1505bd8deadSopenharmony_ci that the application flush to prevent an infinite loop. 1515bd8deadSopenharmony_ci - Clarified the behavior of the async QUERY_RESULT_AVAILABLE_ARB 1525bd8deadSopenharmony_ci command. 1535bd8deadSopenharmony_ci - When the count of samples that pass the occlusion query overflows, 1545bd8deadSopenharmony_ci the value should saturate. 1555bd8deadSopenharmony_ci 1565bd8deadSopenharmony_ci Should we use an object-based interface? 1575bd8deadSopenharmony_ci 1585bd8deadSopenharmony_ci RESOLVED: Yes, this makes the interface much simpler, and it is 1595bd8deadSopenharmony_ci friendly for indirect rendering. 1605bd8deadSopenharmony_ci 1615bd8deadSopenharmony_ci What is the difference between a "query object" and an "occlusion 1625bd8deadSopenharmony_ci query"? 1635bd8deadSopenharmony_ci 1645bd8deadSopenharmony_ci "Occlusion query" is a synonym for "query object used with target 1655bd8deadSopenharmony_ci SAMPLES_PASSED". 1665bd8deadSopenharmony_ci 1675bd8deadSopenharmony_ci Should we offer a way to poll whether an occlusion query has 1685bd8deadSopenharmony_ci completed and its result is available? 1695bd8deadSopenharmony_ci 1705bd8deadSopenharmony_ci RESOLVED. Yes, this allows applications to use CPU time that might 1715bd8deadSopenharmony_ci have been spent spinning more usefully. However, the polling 1725bd8deadSopenharmony_ci method introduced in the NV_occlusion_query spec allowed for a 1735bd8deadSopenharmony_ci potential infinite loop if the application does not do a flush. 1745bd8deadSopenharmony_ci This version of the spec clarifies the behavior which now makes such 1755bd8deadSopenharmony_ci a flush unnecessary. 1765bd8deadSopenharmony_ci 1775bd8deadSopenharmony_ci Is GetQueryObjectuivARB necessary? 1785bd8deadSopenharmony_ci 1795bd8deadSopenharmony_ci RESOLVED: Yes, it makes using a 32-bit count less painful. 1805bd8deadSopenharmony_ci 1815bd8deadSopenharmony_ci Should there be a limit on how many queries can be outstanding? 1825bd8deadSopenharmony_ci 1835bd8deadSopenharmony_ci RESOLVED: No. This would make the extension much more 1845bd8deadSopenharmony_ci difficult to spec and use. Allowing this does not add any 1855bd8deadSopenharmony_ci significant implementation burden; and even if drivers have some 1865bd8deadSopenharmony_ci internal limit on the number of outstanding queries, it is not 1875bd8deadSopenharmony_ci expected that applications will need to know this to achieve 1885bd8deadSopenharmony_ci optimal or near-optimal performance. 1895bd8deadSopenharmony_ci 1905bd8deadSopenharmony_ci What happens if BeginQueryARB is called when a query is already 1915bd8deadSopenharmony_ci outstanding for a different object on the same target? 1925bd8deadSopenharmony_ci 1935bd8deadSopenharmony_ci RESOLVED: This is an INVALID_OPERATION error. 1945bd8deadSopenharmony_ci 1955bd8deadSopenharmony_ci What happens if BeginQueryARB is called with an ID of a query that is 1965bd8deadSopenharmony_ci already in progress? 1975bd8deadSopenharmony_ci 1985bd8deadSopenharmony_ci RESOLVED: This is also an INVALID_OPERATION error. 1995bd8deadSopenharmony_ci 2005bd8deadSopenharmony_ci What parameters should EndQueryARB have? 2015bd8deadSopenharmony_ci 2025bd8deadSopenharmony_ci RESOLVED: Just a target. It doesn't need to take an "id" 2035bd8deadSopenharmony_ci argument, since this would be redundant -- only one query can be 2045bd8deadSopenharmony_ci active for any given target at a given time. 2055bd8deadSopenharmony_ci 2065bd8deadSopenharmony_ci How many bits should we require the samples-passed count to be, at 2075bd8deadSopenharmony_ci minimum? 2085bd8deadSopenharmony_ci 2095bd8deadSopenharmony_ci RESOLVED. The largest minimum that can be required of a GL 2105bd8deadSopenharmony_ci implementation is 32, the minimum bit width of an int or uint. 2115bd8deadSopenharmony_ci 2125bd8deadSopenharmony_ci The minimum number of bits required for the samples-passed 2135bd8deadSopenharmony_ci count will be dependent on the implementation's maximum viewport size. 2145bd8deadSopenharmony_ci In order to allow for two overdraws in the case of only one sample 2155bd8deadSopenharmony_ci buffer, the minimum counter precision (n) will be determined by: 2165bd8deadSopenharmony_ci 2175bd8deadSopenharmony_ci n = min (32 , ceil (log2 (maxViewportWidth x maxViewportHeight x 2185bd8deadSopenharmony_ci 1 sample x 2 overdraws) ) ) 2195bd8deadSopenharmony_ci 2205bd8deadSopenharmony_ci An implementation can either set QUERY_COUNTER_BITS_ARB to the 2215bd8deadSopenharmony_ci value 0, or to some number greater than or equal to n. If an 2225bd8deadSopenharmony_ci implementation returns 0 for QUERY_COUNTER_BITS_ARB, then the 2235bd8deadSopenharmony_ci occlusion queries will always return that zero samples passed the 2245bd8deadSopenharmony_ci occlusion test, and so an application should not use occlusion queries 2255bd8deadSopenharmony_ci on that implementation. 2265bd8deadSopenharmony_ci 2275bd8deadSopenharmony_ci Note that other targets may come along in the future that require more 2285bd8deadSopenharmony_ci or fewer bits. 2295bd8deadSopenharmony_ci 2305bd8deadSopenharmony_ci What should we do about overflows? 2315bd8deadSopenharmony_ci 2325bd8deadSopenharmony_ci RESOLVED: Overflows are required to saturate, though it is expected 2335bd8deadSopenharmony_ci that several current implementations will not conform to this 2345bd8deadSopenharmony_ci requirement. 2355bd8deadSopenharmony_ci 2365bd8deadSopenharmony_ci The ideal behavior is to saturate. This ensures that you always 2375bd8deadSopenharmony_ci get a "large" result when you render many samples. It also 2385bd8deadSopenharmony_ci ensures that apps which want a boolean test can do this without 2395bd8deadSopenharmony_ci worrying about the rare case where the result ends up exactly at 2405bd8deadSopenharmony_ci zero after wrapping. 2415bd8deadSopenharmony_ci 2425bd8deadSopenharmony_ci Either way, it's unlikely that this matters much as long as a 2435bd8deadSopenharmony_ci sufficient number of bits are required. 2445bd8deadSopenharmony_ci 2455bd8deadSopenharmony_ci What is the interaction with multisample? 2465bd8deadSopenharmony_ci 2475bd8deadSopenharmony_ci RESOLVED: We count samples, not pixels -- even if MULTISAMPLE is 2485bd8deadSopenharmony_ci disabled but SAMPLE_BUFFERS is 1. 2495bd8deadSopenharmony_ci 2505bd8deadSopenharmony_ci A given fragment may have anywhere between zero and SAMPLES of 2515bd8deadSopenharmony_ci its samples covered. Ideally, the samples-passed count would be 2525bd8deadSopenharmony_ci incremented by the precise number of samples, but we permit 2535bd8deadSopenharmony_ci implementations to instead increment the samples-passed count by 2545bd8deadSopenharmony_ci SAMPLES if at least one sample in a given fragment is covered. 2555bd8deadSopenharmony_ci 2565bd8deadSopenharmony_ci Note that the depth/stencil test optimization whereby 2575bd8deadSopenharmony_ci implementations may choose to depth test at only one of the 2585bd8deadSopenharmony_ci samples when MULTISAMPLE is disabled does not cause this to 2595bd8deadSopenharmony_ci become ill-specified, because we are counting the number of 2605bd8deadSopenharmony_ci samples that are still alive _after_ the depth test stage. The 2615bd8deadSopenharmony_ci particular mechanism used to decide whether to kill or keep those 2625bd8deadSopenharmony_ci samples is not relevant. 2635bd8deadSopenharmony_ci 2645bd8deadSopenharmony_ci Exactly what stage in the pipeline are we counting samples at? 2655bd8deadSopenharmony_ci 2665bd8deadSopenharmony_ci RESOLVED: We are counting immediately after _both_ the depth and 2675bd8deadSopenharmony_ci stencil tests, i.e., samples that pass both. Note that the depth 2685bd8deadSopenharmony_ci test comes after the stencil test, so to say that it is the 2695bd8deadSopenharmony_ci number that pass the depth test is sufficient; though it is often 2705bd8deadSopenharmony_ci conceptually helpful to think of the depth and stencil tests as 2715bd8deadSopenharmony_ci being combined, because the depth test's result impacts the 2725bd8deadSopenharmony_ci stencil operation used. 2735bd8deadSopenharmony_ci 2745bd8deadSopenharmony_ci Is it guaranteed that occlusion queries return in order? 2755bd8deadSopenharmony_ci 2765bd8deadSopenharmony_ci RESOLVED: Yes. It makes sense to do this. If occlusion test X 2775bd8deadSopenharmony_ci occurred before occlusion query Y, and the driver informs the app 2785bd8deadSopenharmony_ci that occlusion query Y is done, the app can infer that occlusion 2795bd8deadSopenharmony_ci query X is also done. For applications that do poll, this allows 2805bd8deadSopenharmony_ci them to do so with less effort. 2815bd8deadSopenharmony_ci 2825bd8deadSopenharmony_ci Will polling a query without a Flush possibly cause an infinite loop? 2835bd8deadSopenharmony_ci 2845bd8deadSopenharmony_ci RESOLVED: No. An infinite loop was possible in the original 2855bd8deadSopenharmony_ci NV_occlusion_query spec if an application did not perform a 2865bd8deadSopenharmony_ci flush prior to polling. This behavior was removed in this version 2875bd8deadSopenharmony_ci of the spec as it violated language in the core GL spec. 2885bd8deadSopenharmony_ci 2895bd8deadSopenharmony_ci Instead of allowing for an infinite loop, performing a 2905bd8deadSopenharmony_ci QUERY_RESULT_AVAILABLE_ARB will perform a flush if the result 2915bd8deadSopenharmony_ci is not ready yet on the first time it is queried. This ensures 2925bd8deadSopenharmony_ci that the async query will return true in finite time. 2935bd8deadSopenharmony_ci 2945bd8deadSopenharmony_ci This behavior is not a significant performance loss over the original 2955bd8deadSopenharmony_ci version of the spec. A flush would need to be performed at some 2965bd8deadSopenharmony_ci point anyway and the flush performed when QUERY_RESULT_AVAILABLE_ARB 2975bd8deadSopenharmony_ci is requested will only occur *if the result is not back yet*. 2985bd8deadSopenharmony_ci 2995bd8deadSopenharmony_ci What should be the interaction between this spec and 3005bd8deadSopenharmony_ci HP_occlusion_test? 3015bd8deadSopenharmony_ci 3025bd8deadSopenharmony_ci RESOLVED: Whereas NV_occlusion_query required that you implement 3035bd8deadSopenharmony_ci HP_occlusion_test, and even went so far as to specify the precise 3045bd8deadSopenharmony_ci behavior of HP_occlusion_test (since the HP_occlusion_test spec 3055bd8deadSopenharmony_ci did not contain those details), this spec does not. This spec 3065bd8deadSopenharmony_ci explains the interaction with HP_occlusion_test, but does not 3075bd8deadSopenharmony_ci attempt to double as a spec for that extension. 3085bd8deadSopenharmony_ci 3095bd8deadSopenharmony_ci What happens if HP_occlusion_test and ARB_occlusion_query usage is 3105bd8deadSopenharmony_ci overlapped? 3115bd8deadSopenharmony_ci 3125bd8deadSopenharmony_ci RESOLVED: The two can be overlapped safely. Counting is enabled 3135bd8deadSopenharmony_ci if either an occlusion query is active *or* OCCLUSION_TEST_HP is 3145bd8deadSopenharmony_ci enabled. The alternative (producing an error) does not work -- 3155bd8deadSopenharmony_ci it would require that PopAttrib be capable of producing an error, 3165bd8deadSopenharmony_ci which would be rather problematic. 3175bd8deadSopenharmony_ci 3185bd8deadSopenharmony_ci Note that BeginQueryARB, not EndQueryARB, resets the sample 3195bd8deadSopenharmony_ci count (and therefore the occlusion test result). This can avoid 3205bd8deadSopenharmony_ci certain types of strange behavior where an occlusion query's 3215bd8deadSopenharmony_ci samples-passed count does not always correspond to the samples 3225bd8deadSopenharmony_ci rendered during the occlusion query. The spec would make sense 3235bd8deadSopenharmony_ci the other way, but the behavior would be strange. 3245bd8deadSopenharmony_ci 3255bd8deadSopenharmony_ci Should there be a "target" parameter to BeginQueryARB? 3265bd8deadSopenharmony_ci 3275bd8deadSopenharmony_ci RESOLVED: Yes. Whereas NV_occlusion_query wasn't trying to solve 3285bd8deadSopenharmony_ci a problem beyond simple occlusion queries, this extension creates 3295bd8deadSopenharmony_ci a framework useful for future queries. 3305bd8deadSopenharmony_ci 3315bd8deadSopenharmony_ci Does GenQueriesARB need a "target" parameter? 3325bd8deadSopenharmony_ci 3335bd8deadSopenharmony_ci RESOLVED: No. A query can be reused any number of times with any 3345bd8deadSopenharmony_ci targets. 3355bd8deadSopenharmony_ci 3365bd8deadSopenharmony_ci How can one ask for the currently active query? 3375bd8deadSopenharmony_ci 3385bd8deadSopenharmony_ci RESOLVED: A new entry point has been added to query information 3395bd8deadSopenharmony_ci about a given query target. This makes it unnecessary to add two 3405bd8deadSopenharmony_ci new enumerants (# of bits and current query ID) for each new 3415bd8deadSopenharmony_ci target that is introduced. 3425bd8deadSopenharmony_ci 3435bd8deadSopenharmony_ci Are query objects shareable between multiple contexts? 3445bd8deadSopenharmony_ci 3455bd8deadSopenharmony_ci RESOLVED: No. Query objects are lightweight and we normally share 3465bd8deadSopenharmony_ci large data across contexts. Also, being able to share query objects 3475bd8deadSopenharmony_ci across contexts is not particularly useful. In order to do the async 3485bd8deadSopenharmony_ci query across contexts, a query on one context would have to be finished 3495bd8deadSopenharmony_ci before the other context could query it. 3505bd8deadSopenharmony_ci 3515bd8deadSopenharmony_ci What happens when an app begins a query on a target, ends it, begins 3525bd8deadSopenharmony_ci a query on the same target with the same id, ends it, and then tries 3535bd8deadSopenharmony_ci to retrieve data about the query using GetQueryObjecti[u]vARB? Which 3545bd8deadSopenharmony_ci query does the GetQueryObjecti[u]vARB return results for? 3555bd8deadSopenharmony_ci 3565bd8deadSopenharmony_ci RESOLVED. In this case, the result retrieved from 3575bd8deadSopenharmony_ci GetQueryObjecti[u]vARB will be from the last query on that target and 3585bd8deadSopenharmony_ci id. The result returned from GetQueryObjecti[u]vARB will always be from 3595bd8deadSopenharmony_ci the last BeginQueryARB/EndQueryARB pair on that target and id. 3605bd8deadSopenharmony_ci 3615bd8deadSopenharmony_ci Is this extension useful for saving geometry, fill rate, or both? 3625bd8deadSopenharmony_ci 3635bd8deadSopenharmony_ci The answer to this question is to some extent implementation- 3645bd8deadSopenharmony_ci dependent, but it is expected that it is most useful for reducing 3655bd8deadSopenharmony_ci geometry workload, and less so for fill rate. 3665bd8deadSopenharmony_ci 3675bd8deadSopenharmony_ci For the cost of rendering a bounding box, you can potentially 3685bd8deadSopenharmony_ci save rendering a normal object. A bounding box consists of only 3695bd8deadSopenharmony_ci 12 triangles, whereas the original object might have contained 3705bd8deadSopenharmony_ci thousands or even millions of triangles. 3715bd8deadSopenharmony_ci 3725bd8deadSopenharmony_ci Using bounding box occlusion queries may either help or hurt in 3735bd8deadSopenharmony_ci fill-limited situations, because rendering the pixels of a 3745bd8deadSopenharmony_ci bounding box is not free. In most situations, a bounding box 3755bd8deadSopenharmony_ci will probably have more pixels than the original object. Those 3765bd8deadSopenharmony_ci pixels can probably be rendered more quickly, though, since they 3775bd8deadSopenharmony_ci involve only Z reads (no Z writes or color traffic), and they 3785bd8deadSopenharmony_ci need not be textured or otherwise shaded. 3795bd8deadSopenharmony_ci 3805bd8deadSopenharmony_ci In multipass rendering situations, however, occlusion queries can 3815bd8deadSopenharmony_ci almost always save fill rate, because wrapping an object with an 3825bd8deadSopenharmony_ci occlusion query is generally cheap. See "Usage Examples" for an 3835bd8deadSopenharmony_ci illustration. 3845bd8deadSopenharmony_ci 3855bd8deadSopenharmony_ci What can be said about guaranteeing correctness when using 3865bd8deadSopenharmony_ci occlusion queries, especially as it relates to invariance? 3875bd8deadSopenharmony_ci 3885bd8deadSopenharmony_ci Invariance is critical to guarantee the correctness of occlusion 3895bd8deadSopenharmony_ci queries. If occlusion queries go through a different code path 3905bd8deadSopenharmony_ci than standard rendering, the fragments rendered may be different. 3915bd8deadSopenharmony_ci 3925bd8deadSopenharmony_ci However, the invariance issues are difficult at best to solve. 3935bd8deadSopenharmony_ci Because of the vagaries of floating-point precision, it is 3945bd8deadSopenharmony_ci difficult to guarantee that rendering a bounding box will render 3955bd8deadSopenharmony_ci at least as many pixels with equal or smaller Z values than the 3965bd8deadSopenharmony_ci object itself would have rendered. 3975bd8deadSopenharmony_ci 3985bd8deadSopenharmony_ci Likewise, many other aspects of rendering state tend to be 3995bd8deadSopenharmony_ci different when performing an occlusion query. Color and depth 4005bd8deadSopenharmony_ci writes are typically disabled, as are texturing, vertex programs, 4015bd8deadSopenharmony_ci and any fancy per-fragment math. So unless all these features 4025bd8deadSopenharmony_ci have guarantees of invariance themselves (unlikely at best), 4035bd8deadSopenharmony_ci requiring invariance for ARB_occlusion_query would be futile. 4045bd8deadSopenharmony_ci 4055bd8deadSopenharmony_ci In general, implementations are recommended to be fully invariant 4065bd8deadSopenharmony_ci with respect to whether any given type of query is active, 4075bd8deadSopenharmony_ci insofar as it is possible. That is, having an occlusion query 4085bd8deadSopenharmony_ci active should not affect the operation of any other stage of the 4095bd8deadSopenharmony_ci pipeline. Following this rule is essential to numerous occlusion 4105bd8deadSopenharmony_ci query algorithms working correctly. However, to permit 4115bd8deadSopenharmony_ci implementations where this feature is implemented in software, 4125bd8deadSopenharmony_ci this rule is only a recommendation, not a requirement. 4135bd8deadSopenharmony_ci 4145bd8deadSopenharmony_ci Another unrelated problem that can threaten correctness is near 4155bd8deadSopenharmony_ci and far clipping. The bounding box of an object may penetrate 4165bd8deadSopenharmony_ci the near clip plane, even though the original object may not 4175bd8deadSopenharmony_ci have. In such a circumstance, a bounding box occlusion query may 4185bd8deadSopenharmony_ci produce an incorrect result. Whenever you design an algorithm 4195bd8deadSopenharmony_ci using occlusion queries, it is best to be careful about the near 4205bd8deadSopenharmony_ci and far clip planes. 4215bd8deadSopenharmony_ci 4225bd8deadSopenharmony_ci How can frame-to-frame coherency help applications using this 4235bd8deadSopenharmony_ci extension get even higher performance? 4245bd8deadSopenharmony_ci 4255bd8deadSopenharmony_ci Usually, if an object is visible one frame, it will be visible 4265bd8deadSopenharmony_ci the next frame, and if it is not visible, it will not be visible 4275bd8deadSopenharmony_ci the next frame. 4285bd8deadSopenharmony_ci 4295bd8deadSopenharmony_ci Of course, for most applications, "usually" isn't good enough. 4305bd8deadSopenharmony_ci It is undesirable, but acceptable, to render an object that 4315bd8deadSopenharmony_ci *isn't* visible, because that only costs performance. It is 4325bd8deadSopenharmony_ci generally unacceptable to *not* render an object that *is* 4335bd8deadSopenharmony_ci visible. 4345bd8deadSopenharmony_ci 4355bd8deadSopenharmony_ci The simplest approach is that visible objects should be checked 4365bd8deadSopenharmony_ci every N frames (where, say, N=5) to see if they have become 4375bd8deadSopenharmony_ci occluded, while objects that were occluded last frame must be 4385bd8deadSopenharmony_ci rechecked again in the current frame to guarantee that they are 4395bd8deadSopenharmony_ci still occluded. This will reduce the number of wasteful 4405bd8deadSopenharmony_ci occlusion queries by almost a factor of N. 4415bd8deadSopenharmony_ci 4425bd8deadSopenharmony_ci Other, more complicated techniques exist but are beyond the scope 4435bd8deadSopenharmony_ci of this extension document. 4445bd8deadSopenharmony_ci 4455bd8deadSopenharmony_ci Do occlusion queries make other visibility algorithms obsolete? 4465bd8deadSopenharmony_ci 4475bd8deadSopenharmony_ci No. 4485bd8deadSopenharmony_ci 4495bd8deadSopenharmony_ci Occlusion queries are helpful, but they are not a cure-all. They 4505bd8deadSopenharmony_ci should be only one of many items in your bag of tricks to decide 4515bd8deadSopenharmony_ci whether objects are visible or invisible. They are not an excuse 4525bd8deadSopenharmony_ci to skip frustum culling, or precomputing visibility using portals 4535bd8deadSopenharmony_ci for static environments, or other standard visibility techniques. 4545bd8deadSopenharmony_ci 4555bd8deadSopenharmony_ciNew Procedures and Functions 4565bd8deadSopenharmony_ci 4575bd8deadSopenharmony_ci void GenQueriesARB(sizei n, uint *ids); 4585bd8deadSopenharmony_ci void DeleteQueriesARB(sizei n, const uint *ids); 4595bd8deadSopenharmony_ci boolean IsQueryARB(uint id); 4605bd8deadSopenharmony_ci void BeginQueryARB(enum target, uint id); 4615bd8deadSopenharmony_ci void EndQueryARB(enum target); 4625bd8deadSopenharmony_ci void GetQueryivARB(enum target, enum pname, int *params); 4635bd8deadSopenharmony_ci void GetQueryObjectivARB(uint id, enum pname, int *params); 4645bd8deadSopenharmony_ci void GetQueryObjectuivARB(uint id, enum pname, uint *params); 4655bd8deadSopenharmony_ci 4665bd8deadSopenharmony_ciNew Tokens 4675bd8deadSopenharmony_ci 4685bd8deadSopenharmony_ci Accepted by the <target> parameter of BeginQueryARB, EndQueryARB, 4695bd8deadSopenharmony_ci and GetQueryivARB: 4705bd8deadSopenharmony_ci 4715bd8deadSopenharmony_ci SAMPLES_PASSED_ARB 0x8914 4725bd8deadSopenharmony_ci 4735bd8deadSopenharmony_ci Accepted by the <pname> parameter of GetQueryivARB: 4745bd8deadSopenharmony_ci 4755bd8deadSopenharmony_ci QUERY_COUNTER_BITS_ARB 0x8864 4765bd8deadSopenharmony_ci CURRENT_QUERY_ARB 0x8865 4775bd8deadSopenharmony_ci 4785bd8deadSopenharmony_ci Accepted by the <pname> parameter of GetQueryObjectivARB and 4795bd8deadSopenharmony_ci GetQueryObjectuivARB: 4805bd8deadSopenharmony_ci 4815bd8deadSopenharmony_ci QUERY_RESULT_ARB 0x8866 4825bd8deadSopenharmony_ci QUERY_RESULT_AVAILABLE_ARB 0x8867 4835bd8deadSopenharmony_ci 4845bd8deadSopenharmony_ciAdditions to Chapter 2 of the OpenGL 1.4 Specification (OpenGL Operation) 4855bd8deadSopenharmony_ci 4865bd8deadSopenharmony_ci Modify Section 2.1, OpenGL Fundamentals (p. 4) 4875bd8deadSopenharmony_ci 4885bd8deadSopenharmony_ci (modify fourth paragraph, p. 4) It also means that queries and 4895bd8deadSopenharmony_ci pixel read operations return state consistent with complete 4905bd8deadSopenharmony_ci execution of all previously invoked GL commands, except where 4915bd8deadSopenharmony_ci explicitly specified otherwise 4925bd8deadSopenharmony_ci 4935bd8deadSopenharmony_ciAdditions to Chapter 3 of the OpenGL 1.4 Specification (Rasterization) 4945bd8deadSopenharmony_ci 4955bd8deadSopenharmony_ci None. 4965bd8deadSopenharmony_ci 4975bd8deadSopenharmony_ciAdditions to Chapter 4 of the OpenGL 1.4 Specification (Per-Fragment 4985bd8deadSopenharmony_ciOperations and the Frame Buffer) 4995bd8deadSopenharmony_ci 5005bd8deadSopenharmony_ci Add a new section "Occlusion Queries" between sections 4.1.6 and 5015bd8deadSopenharmony_ci 4.1.7: 5025bd8deadSopenharmony_ci 5035bd8deadSopenharmony_ci "4.1.6A Occlusion Queries 5045bd8deadSopenharmony_ci 5055bd8deadSopenharmony_ci Occlusion queries can be used to track the number of fragments or 5065bd8deadSopenharmony_ci samples that pass the depth test. 5075bd8deadSopenharmony_ci 5085bd8deadSopenharmony_ci Occlusion queries are associated with query objects. The command 5095bd8deadSopenharmony_ci 5105bd8deadSopenharmony_ci void GenQueriesARB(sizei n, uint *ids); 5115bd8deadSopenharmony_ci 5125bd8deadSopenharmony_ci returns <n> previously unused query object names in <ids>. These 5135bd8deadSopenharmony_ci names are marked as used, but no object is associated with them until 5145bd8deadSopenharmony_ci the first time they are used by BeginQueryARB. Query objects contain 5155bd8deadSopenharmony_ci one piece of state, an integer result value. This result value is 5165bd8deadSopenharmony_ci initialized to zero when the object is created. Any positive integer 5175bd8deadSopenharmony_ci except for zero (which is reserved for the GL) is a valid query 5185bd8deadSopenharmony_ci object name. 5195bd8deadSopenharmony_ci 5205bd8deadSopenharmony_ci Query objects are deleted by calling 5215bd8deadSopenharmony_ci 5225bd8deadSopenharmony_ci void DeleteQueriesARB(sizei n, const uint *ids); 5235bd8deadSopenharmony_ci 5245bd8deadSopenharmony_ci <ids> contains <n> names of query objects to be deleted. After a 5255bd8deadSopenharmony_ci query object is deleted, its name is again unused. Unused names in 5265bd8deadSopenharmony_ci <ids> are silently ignored. 5275bd8deadSopenharmony_ci 5285bd8deadSopenharmony_ci An occlusion query can be started and finished by calling 5295bd8deadSopenharmony_ci 5305bd8deadSopenharmony_ci void BeginQueryARB(enum target, uint id); 5315bd8deadSopenharmony_ci void EndQueryARB(enum target); 5325bd8deadSopenharmony_ci 5335bd8deadSopenharmony_ci where <target> is SAMPLES_PASSED_ARB. If BeginQueryARB is called 5345bd8deadSopenharmony_ci with an unused <id>, that name is marked as used and associated with 5355bd8deadSopenharmony_ci a new query object. If BeginQueryARB is called while another query 5365bd8deadSopenharmony_ci is already in progress with the same target, an INVALID_OPERATION 5375bd8deadSopenharmony_ci error is generated. If EndQueryARB is called while no query with the 5385bd8deadSopenharmony_ci same target is in progress, an INVALID_OPERATION error is generated. 5395bd8deadSopenharmony_ci Calling either GenQueriesARB or DeleteQueriesARB while any query of 5405bd8deadSopenharmony_ci any target is active causes an INVALID_OPERATION error to be 5415bd8deadSopenharmony_ci generated. 5425bd8deadSopenharmony_ci 5435bd8deadSopenharmony_ci BeginQueryARB with a <target> of SAMPLES_PASSED_ARB resets the 5445bd8deadSopenharmony_ci current samples-passed count to zero and sets the query active 5455bd8deadSopenharmony_ci state to TRUE and the active query id to <id>. EndQueryARB with 5465bd8deadSopenharmony_ci a target of SAMPLES_PASSED_ARB initializes a copy of the current 5475bd8deadSopenharmony_ci samples-passed count into the active occlusion query object's results 5485bd8deadSopenharmony_ci value, sets the active occlusion query object's result available to 5495bd8deadSopenharmony_ci FALSE, sets the query active state to FALSE, and the active query 5505bd8deadSopenharmony_ci id to 0. 5515bd8deadSopenharmony_ci 5525bd8deadSopenharmony_ci If BeginQueryARB is called with an <id> of zero, or where <id> is the 5535bd8deadSopenharmony_ci name of a query currently in progress, an INVALID_OPERATION error is 5545bd8deadSopenharmony_ci generated. 5555bd8deadSopenharmony_ci 5565bd8deadSopenharmony_ci When an occlusion query is active, the samples-passed count increases 5575bd8deadSopenharmony_ci by a certain quantity for each fragment that passes the depth test. 5585bd8deadSopenharmony_ci If the value of SAMPLE_BUFFERS is 0, then the samples-passed count 5595bd8deadSopenharmony_ci increases by 1 for each fragment. If the value of SAMPLE_BUFFERS is 5605bd8deadSopenharmony_ci 1, then the samples-passed count increases by the number of samples 5615bd8deadSopenharmony_ci whose coverage bit is set. However, implementations, at their 5625bd8deadSopenharmony_ci discretion, are allowed to instead increase the samples-passed count 5635bd8deadSopenharmony_ci by the value of SAMPLES if any sample in the fragment is covered. 5645bd8deadSopenharmony_ci 5655bd8deadSopenharmony_ci If the samples-passed count overflows, i.e., exceeds the value 2^n-1 5665bd8deadSopenharmony_ci (where n is the number of bits in the samples-passed count), its 5675bd8deadSopenharmony_ci value becomes undefined. It is recommended, but not required, that 5685bd8deadSopenharmony_ci implementations handle this overflow case by saturating at 2^n-1 and 5695bd8deadSopenharmony_ci incrementing no further. 5705bd8deadSopenharmony_ci 5715bd8deadSopenharmony_ci The necessary state is a single bit indicating whether an occlusion 5725bd8deadSopenharmony_ci query is active, the identifier of the currently active occlusion 5735bd8deadSopenharmony_ci query, and a counter keeping track of the number of samples that 5745bd8deadSopenharmony_ci have passed." 5755bd8deadSopenharmony_ci 5765bd8deadSopenharmony_ciAdditions to Chapter 5 of the OpenGL 1.4 Specification (Special Functions) 5775bd8deadSopenharmony_ci 5785bd8deadSopenharmony_ci Add to the end of Section 5.4 "Display Lists": 5795bd8deadSopenharmony_ci 5805bd8deadSopenharmony_ci "DeleteQueriesARB, GenQueriesARB, IsQueryARB, GetQueryivARB, 5815bd8deadSopenharmony_ci GetQueryObjectivARB, and GetQueryObjectuivARB are not compiled into 5825bd8deadSopenharmony_ci display lists but are executed immediately." 5835bd8deadSopenharmony_ci 5845bd8deadSopenharmony_ciAdditions to Chapter 6 of the OpenGL 1.4 Specification (State and 5855bd8deadSopenharmony_ciState Requests) 5865bd8deadSopenharmony_ci 5875bd8deadSopenharmony_ci Add a new section 6.1.13 "Occlusion Queries": 5885bd8deadSopenharmony_ci 5895bd8deadSopenharmony_ci "The command 5905bd8deadSopenharmony_ci 5915bd8deadSopenharmony_ci boolean IsQueryARB(uint id); 5925bd8deadSopenharmony_ci 5935bd8deadSopenharmony_ci returns TRUE if <id> is the name of a query object. If <id> is zero, 5945bd8deadSopenharmony_ci or if <id> is a non-zero value that is not the name of a query 5955bd8deadSopenharmony_ci object, IsQueryARB returns FALSE. 5965bd8deadSopenharmony_ci 5975bd8deadSopenharmony_ci Information about a query target can be queried with the command 5985bd8deadSopenharmony_ci 5995bd8deadSopenharmony_ci void GetQueryivARB(enum target, enum pname, int *params); 6005bd8deadSopenharmony_ci 6015bd8deadSopenharmony_ci If <pname> is CURRENT_QUERY_ARB, the name of the currently active 6025bd8deadSopenharmony_ci query for <target>, or zero if no query is active, will be placed in 6035bd8deadSopenharmony_ci <params>. 6045bd8deadSopenharmony_ci 6055bd8deadSopenharmony_ci If <pname> is QUERY_COUNTER_BITS_ARB, the number of bits in the counter for 6065bd8deadSopenharmony_ci <target> will be placed in <params>. The minimum number of query counter 6075bd8deadSopenharmony_ci bits allowed is a function of the implementation's maximum viewport 6085bd8deadSopenharmony_ci dimensions (MAX_VIEWPORT_DIMS). If the counter is non-zero, then the 6095bd8deadSopenharmony_ci counter must be able to represent at least two overdraws for every pixel 6105bd8deadSopenharmony_ci in the viewport using only one sample buffer. The formula to compute the 6115bd8deadSopenharmony_ci allowable minimum value is below (where n is the minimum number of bits): 6125bd8deadSopenharmony_ci 6135bd8deadSopenharmony_ci n = (min (32, ceil (log2 (maxViewportWidth x maxViewportHeight x 2) ) ) ) or 6145bd8deadSopenharmony_ci 0 6155bd8deadSopenharmony_ci 6165bd8deadSopenharmony_ci If the value of n is 0, then the result from GetQueryiv(SAMPLES_PASSED_ARB) 6175bd8deadSopenharmony_ci will always return 0, 6185bd8deadSopenharmony_ci 6195bd8deadSopenharmony_ci The state of a query object can be queried with the commands 6205bd8deadSopenharmony_ci 6215bd8deadSopenharmony_ci void GetQueryObjectivARB(uint id, enum pname, int *params); 6225bd8deadSopenharmony_ci void GetQueryObjectuivARB(uint id, enum pname, uint *params); 6235bd8deadSopenharmony_ci 6245bd8deadSopenharmony_ci If <id> is not the name of a query object, or if the query object 6255bd8deadSopenharmony_ci named by <id> is currently active, then an INVALID_OPERATION error is 6265bd8deadSopenharmony_ci generated. 6275bd8deadSopenharmony_ci 6285bd8deadSopenharmony_ci If <pname> is QUERY_RESULT_ARB, then the query object's result value 6295bd8deadSopenharmony_ci is placed in <params>. 6305bd8deadSopenharmony_ci 6315bd8deadSopenharmony_ci Often, query object results will be returned asynchronously with 6325bd8deadSopenharmony_ci respect to the host processor's operation. As a result, sometimes, 6335bd8deadSopenharmony_ci if a result is queried, the host must wait until the result is back. 6345bd8deadSopenharmony_ci If <pname> is QUERY_RESULT_AVAILABLE_ARB, the value placed in 6355bd8deadSopenharmony_ci <params> indicates whether or not such a wait would occur if the 6365bd8deadSopenharmony_ci result of that query object were to be queried presently. A result 6375bd8deadSopenharmony_ci of TRUE means no wait would be required; a result of FALSE means that 6385bd8deadSopenharmony_ci some wait would occur. It must always be true that if the result for one 6395bd8deadSopenharmony_ci query is available, the result for all previous queries must also be 6405bd8deadSopenharmony_ci available at that point in time. 6415bd8deadSopenharmony_ci 6425bd8deadSopenharmony_ci Querying the state for a given occlusion query forces that occlusion 6435bd8deadSopenharmony_ci query to complete within a finite amount of time. 6445bd8deadSopenharmony_ci 6455bd8deadSopenharmony_ci If multiple queries are issued on the same target and id prior to 6465bd8deadSopenharmony_ci calling GetQueryObject[u]iVARB, the result returned will always be 6475bd8deadSopenharmony_ci from the last query issued. The results from any queries before the 6485bd8deadSopenharmony_ci last one will be lost if the results are not retrieved before starting 6495bd8deadSopenharmony_ci a new query on the same target and id." 6505bd8deadSopenharmony_ci 6515bd8deadSopenharmony_ciDependencies on HP_occlusion_test 6525bd8deadSopenharmony_ci 6535bd8deadSopenharmony_ci When GetIntegerv is called with <pname> of OCCLUSION_TEST_RESULT_HP, 6545bd8deadSopenharmony_ci the current samples-passed count is reset to zero. The occlusion 6555bd8deadSopenharmony_ci test result is TRUE when the samples-passed count is nonzero, and 6565bd8deadSopenharmony_ci FALSE when it is zero. Sample counting is active (i.e. the samples- 6575bd8deadSopenharmony_ci passed count increases as fragments are drawn) whenever either an 6585bd8deadSopenharmony_ci occlusion query is active *or* OCCLUSION_TEST_HP is enabled. 6595bd8deadSopenharmony_ci 6605bd8deadSopenharmony_ciGLX Protocol 6615bd8deadSopenharmony_ci 6625bd8deadSopenharmony_ci Seven new GL commands are added. 6635bd8deadSopenharmony_ci 6645bd8deadSopenharmony_ci The following two rendering commands are sent to the server as part 6655bd8deadSopenharmony_ci of a glXRender request: 6665bd8deadSopenharmony_ci 6675bd8deadSopenharmony_ci BeginQueryARB 6685bd8deadSopenharmony_ci 2 12 rendering command length 6695bd8deadSopenharmony_ci 2 231 rendering command opcode 6705bd8deadSopenharmony_ci 4 ENUM target 6715bd8deadSopenharmony_ci 4 CARD32 id 6725bd8deadSopenharmony_ci 6735bd8deadSopenharmony_ci EndQueryARB 6745bd8deadSopenharmony_ci 2 8 rendering command length 6755bd8deadSopenharmony_ci 2 232 rendering command opcode 6765bd8deadSopenharmony_ci 4 ENUM target 6775bd8deadSopenharmony_ci 6785bd8deadSopenharmony_ci The remaining fivecommands are non-rendering commands. These 6795bd8deadSopenharmony_ci commands are sent separately (i.e., not as part of a glXRender or 6805bd8deadSopenharmony_ci glXRenderLarge request), using glx single requests: 6815bd8deadSopenharmony_ci 6825bd8deadSopenharmony_ci DeleteQueriesARB 6835bd8deadSopenharmony_ci 1 CARD8 opcode (X assigned) 6845bd8deadSopenharmony_ci 1 161 GLX opcode 6855bd8deadSopenharmony_ci 2 3+n request length 6865bd8deadSopenharmony_ci 4 GLX_CONTEXT_TAG context tag 6875bd8deadSopenharmony_ci 4 INT32 n 6885bd8deadSopenharmony_ci n*4 LISTofCARD32 ids 6895bd8deadSopenharmony_ci 6905bd8deadSopenharmony_ci GenQueriesARB 6915bd8deadSopenharmony_ci 1 CARD8 opcode (X assigned) 6925bd8deadSopenharmony_ci 1 162 GLX opcode 6935bd8deadSopenharmony_ci 2 3 request length 6945bd8deadSopenharmony_ci 4 GLX_CONTEXT_TAG context tag 6955bd8deadSopenharmony_ci 4 INT32 n 6965bd8deadSopenharmony_ci => 6975bd8deadSopenharmony_ci 1 1 reply 6985bd8deadSopenharmony_ci 1 unused 6995bd8deadSopenharmony_ci 2 CARD16 sequence number 7005bd8deadSopenharmony_ci 4 n reply length 7015bd8deadSopenharmony_ci 24 unused 7025bd8deadSopenharmony_ci n*4 LISTofCARD32 queries 7035bd8deadSopenharmony_ci 7045bd8deadSopenharmony_ci IsQueryARB 7055bd8deadSopenharmony_ci 1 CARD8 opcode (X assigned) 7065bd8deadSopenharmony_ci 1 163 GLX opcode 7075bd8deadSopenharmony_ci 2 3 request length 7085bd8deadSopenharmony_ci 4 GLX_CONTEXT_TAG context tag 7095bd8deadSopenharmony_ci 4 CARD32 id 7105bd8deadSopenharmony_ci => 7115bd8deadSopenharmony_ci 1 1 reply 7125bd8deadSopenharmony_ci 1 unused 7135bd8deadSopenharmony_ci 2 CARD16 sequence number 7145bd8deadSopenharmony_ci 4 0 reply length 7155bd8deadSopenharmony_ci 4 BOOL32 return value 7165bd8deadSopenharmony_ci 20 unused 7175bd8deadSopenharmony_ci 7185bd8deadSopenharmony_ci GetQueryivARB 7195bd8deadSopenharmony_ci 1 CARD8 opcode (X assigned) 7205bd8deadSopenharmony_ci 1 164 GLX opcode 7215bd8deadSopenharmony_ci 2 4 request length 7225bd8deadSopenharmony_ci 4 GLX_CONTEXT_TAG context tag 7235bd8deadSopenharmony_ci 4 ENUM target 7245bd8deadSopenharmony_ci 4 ENUM pname 7255bd8deadSopenharmony_ci => 7265bd8deadSopenharmony_ci 1 1 reply 7275bd8deadSopenharmony_ci 1 unused 7285bd8deadSopenharmony_ci 2 CARD16 sequence number 7295bd8deadSopenharmony_ci 4 m reply length, m=(n==1?0:n) 7305bd8deadSopenharmony_ci 4 unused 7315bd8deadSopenharmony_ci 4 CARD32 n 7325bd8deadSopenharmony_ci 7335bd8deadSopenharmony_ci if (n=1) this follows: 7345bd8deadSopenharmony_ci 7355bd8deadSopenharmony_ci 4 INT32 params 7365bd8deadSopenharmony_ci 12 unused 7375bd8deadSopenharmony_ci 7385bd8deadSopenharmony_ci otherwise this follows: 7395bd8deadSopenharmony_ci 7405bd8deadSopenharmony_ci 16 unused 7415bd8deadSopenharmony_ci n*4 LISTofINT32 params 7425bd8deadSopenharmony_ci 7435bd8deadSopenharmony_ci GetQueryObjectivARB 7445bd8deadSopenharmony_ci 1 CARD8 opcode (X assigned) 7455bd8deadSopenharmony_ci 1 165 GLX opcode 7465bd8deadSopenharmony_ci 2 4 request length 7475bd8deadSopenharmony_ci 4 GLX_CONTEXT_TAG context tag 7485bd8deadSopenharmony_ci 4 CARD32 id 7495bd8deadSopenharmony_ci 4 ENUM pname 7505bd8deadSopenharmony_ci => 7515bd8deadSopenharmony_ci 1 1 reply 7525bd8deadSopenharmony_ci 1 unused 7535bd8deadSopenharmony_ci 2 CARD16 sequence number 7545bd8deadSopenharmony_ci 4 m reply length, m=(n==1?0:n) 7555bd8deadSopenharmony_ci 4 unused 7565bd8deadSopenharmony_ci 4 CARD32 n 7575bd8deadSopenharmony_ci 7585bd8deadSopenharmony_ci if (n=1) this follows: 7595bd8deadSopenharmony_ci 7605bd8deadSopenharmony_ci 4 INT32 params 7615bd8deadSopenharmony_ci 12 unused 7625bd8deadSopenharmony_ci 7635bd8deadSopenharmony_ci otherwise this follows: 7645bd8deadSopenharmony_ci 7655bd8deadSopenharmony_ci 16 unused 7665bd8deadSopenharmony_ci n*4 LISTofINT32 params 7675bd8deadSopenharmony_ci 7685bd8deadSopenharmony_ci GetQueryObjectuivARB 7695bd8deadSopenharmony_ci 1 CARD8 opcode (X assigned) 7705bd8deadSopenharmony_ci 1 166 GLX opcode 7715bd8deadSopenharmony_ci 2 4 request length 7725bd8deadSopenharmony_ci 4 GLX_CONTEXT_TAG context tag 7735bd8deadSopenharmony_ci 4 CARD32 id 7745bd8deadSopenharmony_ci 4 ENUM pname 7755bd8deadSopenharmony_ci => 7765bd8deadSopenharmony_ci 1 1 reply 7775bd8deadSopenharmony_ci 1 unused 7785bd8deadSopenharmony_ci 2 CARD16 sequence number 7795bd8deadSopenharmony_ci 4 m reply length, m=(n==1?0:n) 7805bd8deadSopenharmony_ci 4 unused 7815bd8deadSopenharmony_ci 4 CARD32 n 7825bd8deadSopenharmony_ci 7835bd8deadSopenharmony_ci if (n=1) this follows: 7845bd8deadSopenharmony_ci 7855bd8deadSopenharmony_ci 4 CARD32 params 7865bd8deadSopenharmony_ci 12 unused 7875bd8deadSopenharmony_ci 7885bd8deadSopenharmony_ci otherwise this follows: 7895bd8deadSopenharmony_ci 7905bd8deadSopenharmony_ci 16 unused 7915bd8deadSopenharmony_ci n*4 LISTofCARD32 params 7925bd8deadSopenharmony_ci 7935bd8deadSopenharmony_ciErrors 7945bd8deadSopenharmony_ci 7955bd8deadSopenharmony_ci The error INVALID_VALUE is generated if GenQueriesARB is called where 7965bd8deadSopenharmony_ci <n> is negative. 7975bd8deadSopenharmony_ci 7985bd8deadSopenharmony_ci The error INVALID_VALUE is generated if DeleteQueriesARB is called 7995bd8deadSopenharmony_ci where <n> is negative. 8005bd8deadSopenharmony_ci 8015bd8deadSopenharmony_ci The error INVALID_OPERATION is generated if GenQueriesARB or 8025bd8deadSopenharmony_ci DeleteQueriesARB is called when a query of any target is active. 8035bd8deadSopenharmony_ci 8045bd8deadSopenharmony_ci The error INVALID_ENUM is generated if BeginQueryARB, EndQueryARB, or 8055bd8deadSopenharmony_ci GetQueryivARB is called where <target> is not SAMPLES_PASSED_ARB. 8065bd8deadSopenharmony_ci 8075bd8deadSopenharmony_ci The error INVALID_OPERATION is generated if BeginQueryARB is called 8085bd8deadSopenharmony_ci when a query of the given <target> is already active. 8095bd8deadSopenharmony_ci 8105bd8deadSopenharmony_ci The error INVALID_OPERATION is generated if EndQueryARB is called 8115bd8deadSopenharmony_ci when a query of the given <target> is not active. 8125bd8deadSopenharmony_ci 8135bd8deadSopenharmony_ci The error INVALID_OPERATION is generated if BeginQueryARB is called 8145bd8deadSopenharmony_ci where <id> is zero. 8155bd8deadSopenharmony_ci 8165bd8deadSopenharmony_ci The error INVALID_OPERATION is generated if BeginQueryARB is called 8175bd8deadSopenharmony_ci where <id> is is the name of a query currently in progress. 8185bd8deadSopenharmony_ci 8195bd8deadSopenharmony_ci The error INVALID_ENUM is generated if GetQueryivARB is called where 8205bd8deadSopenharmony_ci <pname> is not QUERY_COUNTER_BITS_ARB or CURRENT_QUERY_ARB. 8215bd8deadSopenharmony_ci 8225bd8deadSopenharmony_ci The error INVALID_OPERATION is generated if GetQueryObjectivARB or 8235bd8deadSopenharmony_ci GetQueryObjectuivARB is called where <id> is not the name of a query 8245bd8deadSopenharmony_ci object. 8255bd8deadSopenharmony_ci 8265bd8deadSopenharmony_ci The error INVALID_OPERATION is generated if GetQueryObjectivARB or 8275bd8deadSopenharmony_ci GetQueryObjectuivARB is called where <id> is the name of a currently 8285bd8deadSopenharmony_ci active query object. 8295bd8deadSopenharmony_ci 8305bd8deadSopenharmony_ci The error INVALID_ENUM is generated if GetQueryObjectivARB or 8315bd8deadSopenharmony_ci GetQueryObjectuivARB is called where <pname> is not QUERY_RESULT_ARB 8325bd8deadSopenharmony_ci or QUERY_RESULT_AVAILABLE_ARB. 8335bd8deadSopenharmony_ci 8345bd8deadSopenharmony_ci The error INVALID_OPERATION is generated if any of the commands 8355bd8deadSopenharmony_ci defined in this extension is executed between the execution of Begin 8365bd8deadSopenharmony_ci and the corresponding execution of End. 8375bd8deadSopenharmony_ci 8385bd8deadSopenharmony_ciNew State 8395bd8deadSopenharmony_ci 8405bd8deadSopenharmony_ci(table 6.18, p. 233) 8415bd8deadSopenharmony_ci 8425bd8deadSopenharmony_ci Get Value Type Get Command Initial Value Description Sec Attribute 8435bd8deadSopenharmony_ci --------- ---- ----------- ------------- ----------- ------ --------- 8445bd8deadSopenharmony_ci - B - FALSE query active 4.1.6A - 8455bd8deadSopenharmony_ci CURRENT_QUERY_ARB Z+ GetQueryiv 0 active query ID 4.1.6A - 8465bd8deadSopenharmony_ci QUERY_RESULT_ARB Z+ GetQueryObjectuivARB 0 samples-passed count 4.1.6A - 8475bd8deadSopenharmony_ci QUERY_RESULT_AVAILABLE_ARB B GetQueryObjectivARB FALSE query result available 4.1.6A - 8485bd8deadSopenharmony_ci 8495bd8deadSopenharmony_ciNew Implementation Dependent State 8505bd8deadSopenharmony_ci 8515bd8deadSopenharmony_ci(table 6.29, p. 224) Add the following entry: 8525bd8deadSopenharmony_ci 8535bd8deadSopenharmony_ci Get Value Type Get Command Minimum Value Description Sec Attribute 8545bd8deadSopenharmony_ci -------------------------- ---- ----------- ------------- ---------------- ------ -------------- 8555bd8deadSopenharmony_ci QUERY_COUNTER_BITS_ARB Z+ GetQueryiv see 6.1.13 Number of bits in 6.1.13 - 8565bd8deadSopenharmony_ci query counter 8575bd8deadSopenharmony_ci 8585bd8deadSopenharmony_ciRevision History 8595bd8deadSopenharmony_ci 8605bd8deadSopenharmony_ci Date: 4/21/2007 8615bd8deadSopenharmony_ci Revision: 7 (Jon Leech) 8625bd8deadSopenharmony_ci - Added QUERY_RESULT_ARB and QUERY_RESULT_AVAILABLE to state table 8635bd8deadSopenharmony_ci 6.18 (also fixed in OpenGL 2.1 spec). 8645bd8deadSopenharmony_ci 8655bd8deadSopenharmony_ci Date: 11/4/2006 8665bd8deadSopenharmony_ci Revision: 6 (Benj Lipchak, AMD) 8675bd8deadSopenharmony_ci - Updated contact info after ATI/AMD merger. 8685bd8deadSopenharmony_ci 8695bd8deadSopenharmony_ci Date: 10/27/2004 8705bd8deadSopenharmony_ci Revision: 5? (James Jones, NVIDIA) 8715bd8deadSopenharmony_ci - Added GLX protocol. 8725bd8deadSopenharmony_ci 8735bd8deadSopenharmony_ciUsage Examples 8745bd8deadSopenharmony_ci 8755bd8deadSopenharmony_ci Here is some rough sample code that illustrates how this extension 8765bd8deadSopenharmony_ci can be used. 8775bd8deadSopenharmony_ci 8785bd8deadSopenharmony_ci GLuint queries[N]; 8795bd8deadSopenharmony_ci GLuint sampleCount; 8805bd8deadSopenharmony_ci GLint available; 8815bd8deadSopenharmony_ci GLuint bitsSupported; 8825bd8deadSopenharmony_ci 8835bd8deadSopenharmony_ci // check to make sure functionality is supported 8845bd8deadSopenharmony_ci glGetQueryiv(GL_QUERY_COUNTER_BITS_ARB, &bitsSupported); 8855bd8deadSopenharmony_ci if (bitsSupported == 0) { 8865bd8deadSopenharmony_ci // render scene without using occlusion queries 8875bd8deadSopenharmony_ci } 8885bd8deadSopenharmony_ci 8895bd8deadSopenharmony_ci glGenQueriesARB(N, queries); 8905bd8deadSopenharmony_ci ... 8915bd8deadSopenharmony_ci // before this point, render major occluders 8925bd8deadSopenharmony_ci glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 8935bd8deadSopenharmony_ci glDepthMask(GL_FALSE); 8945bd8deadSopenharmony_ci // also disable texturing and any fancy shaders 8955bd8deadSopenharmony_ci for (i = 0; i < N; i++) { 8965bd8deadSopenharmony_ci glBeginQueryARB(GL_SAMPLES_PASSED_ARB, queries[i]); 8975bd8deadSopenharmony_ci // render bounding box for object i 8985bd8deadSopenharmony_ci glEndQueryARB(GL_SAMPLES_PASSED_ARB); 8995bd8deadSopenharmony_ci } 9005bd8deadSopenharmony_ci 9015bd8deadSopenharmony_ci glFlush(); 9025bd8deadSopenharmony_ci 9035bd8deadSopenharmony_ci // Do other work until "most" of the queries are back, to avoid 9045bd8deadSopenharmony_ci // wasting time spinning 9055bd8deadSopenharmony_ci i = N*3/4; // instead of N-1, to prevent the GPU from going idle 9065bd8deadSopenharmony_ci do { 9075bd8deadSopenharmony_ci DoSomeStuff(); 9085bd8deadSopenharmony_ci glGetQueryObjectivARB(queries[i], 9095bd8deadSopenharmony_ci GL_QUERY_RESULT_AVAILABLE_ARB, 9105bd8deadSopenharmony_ci &available); 9115bd8deadSopenharmony_ci } while (!available); 9125bd8deadSopenharmony_ci 9135bd8deadSopenharmony_ci glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 9145bd8deadSopenharmony_ci glDepthMask(GL_TRUE); 9155bd8deadSopenharmony_ci // reenable other state, such as texturing 9165bd8deadSopenharmony_ci for (i = 0; i < N; i++) { 9175bd8deadSopenharmony_ci glGetQueryObjectuivARB(queries[i], GL_QUERY_RESULT_ARB, 9185bd8deadSopenharmony_ci &sampleCount); 9195bd8deadSopenharmony_ci if (sampleCount > 0) { 9205bd8deadSopenharmony_ci // render object i 9215bd8deadSopenharmony_ci } 9225bd8deadSopenharmony_ci } 9235bd8deadSopenharmony_ci 9245bd8deadSopenharmony_ci Here is some rough sample code for a simple multipass rendering 9255bd8deadSopenharmony_ci application that does not use occlusion queries. 9265bd8deadSopenharmony_ci 9275bd8deadSopenharmony_ci for (i = 0; i < N; i++) { 9285bd8deadSopenharmony_ci // First rendering pass 9295bd8deadSopenharmony_ci glDisable(GL_BLEND); 9305bd8deadSopenharmony_ci glDepthFunc(GL_LESS); 9315bd8deadSopenharmony_ci glDepthMask(GL_TRUE); 9325bd8deadSopenharmony_ci // configure shader 0 9335bd8deadSopenharmony_ci // render object i 9345bd8deadSopenharmony_ci 9355bd8deadSopenharmony_ci // Second rendering pass 9365bd8deadSopenharmony_ci glEnable(GL_BLEND); 9375bd8deadSopenharmony_ci glBlendFunc(...); 9385bd8deadSopenharmony_ci glDepthFunc(GL_EQUAL); 9395bd8deadSopenharmony_ci glDepthMask(GL_FALSE); 9405bd8deadSopenharmony_ci // configure shader 1 9415bd8deadSopenharmony_ci // render object i 9425bd8deadSopenharmony_ci } 9435bd8deadSopenharmony_ci 9445bd8deadSopenharmony_ci Here is the previous example, enhanced using occlusion queries. 9455bd8deadSopenharmony_ci 9465bd8deadSopenharmony_ci GLuint queries[N]; 9475bd8deadSopenharmony_ci GLuint sampleCount; 9485bd8deadSopenharmony_ci 9495bd8deadSopenharmony_ci glGenQueriesARB(N, queries); 9505bd8deadSopenharmony_ci ... 9515bd8deadSopenharmony_ci // First rendering pass plus almost-free visibility checks 9525bd8deadSopenharmony_ci glDisable(GL_BLEND); 9535bd8deadSopenharmony_ci glDepthFunc(GL_LESS); 9545bd8deadSopenharmony_ci glDepthMask(GL_TRUE); 9555bd8deadSopenharmony_ci // configure shader 0 9565bd8deadSopenharmony_ci for (i = 0; i < N; i++) { 9575bd8deadSopenharmony_ci glBeginQueryARB(GL_SAMPLES_PASSED_ARB, queries[i]); 9585bd8deadSopenharmony_ci // render object i 9595bd8deadSopenharmony_ci glEndQueryARB(GL_SAMPLES_PASSED_ARB); 9605bd8deadSopenharmony_ci } 9615bd8deadSopenharmony_ci 9625bd8deadSopenharmony_ci // Second pass only on objects that were visible 9635bd8deadSopenharmony_ci glEnable(GL_BLEND); 9645bd8deadSopenharmony_ci glBlendFunc(...); 9655bd8deadSopenharmony_ci glDepthFunc(GL_EQUAL); 9665bd8deadSopenharmony_ci glDepthMask(GL_FALSE); 9675bd8deadSopenharmony_ci // configure shader 1 9685bd8deadSopenharmony_ci for (i = 0; i < N; i++) { 9695bd8deadSopenharmony_ci glGetQueryObjectuivARB(queries[i], GL_QUERY_RESULT_ARB, 9705bd8deadSopenharmony_ci &sampleCount); 9715bd8deadSopenharmony_ci if (sampleCount > 0) { 9725bd8deadSopenharmony_ci // render object i 9735bd8deadSopenharmony_ci } 9745bd8deadSopenharmony_ci } 975