next up previous contents index
Next: 5.4 Display Lists Up: 5 Special Functions Previous: 5.2 Selection

5.3 Feedback

 

Feedback, like selection, is a GL mode. The mode is selected by calling RenderMode  with FEEDBACK. When the GL is in feedback mode, no fragments are written to the framebuffer. Instead, information about primitives that would have been rasterized is fed back to the application using the GL.

Feedback is controlled using

void FeedbackBuffer ( sizei n, enum type, float *buffer ) ;

*buffer is a pointer to an array of floating-point values into which feedback information will be placed, and n is a number indicating the maximum number of values that can be written to that array. type is a symbolic constant describing the information to be fed back for each vertex (see Figure 5.2). The error INVALID_OPERATION results if the GL is placed in feedback mode before a call to FeedbackBuffer  has been made, or if a call to FeedbackBuffer  is made while in feedback mode.

While in feedback mode, each primitive that would be rasterized (or bitmap or call to DrawPixels  or CopyPixels , if the raster position is valid) generates a block of values that get copied into the feedback array. If doing so would cause the number of entries to exceed the maximum, the block is partially written so as to fill the array (if there is any room left at all). The first block of values generated after the GL enters feedback mode is placed at the beginning of the feedback array, with subsequent blocks following. Each block begins with a code indicating the primitive type, followed by values that describe the primitive's vertices and associated data. Entries are also written for bitmaps and pixel rectangles. Feedback occurs after polygon culling (section 3.5.1) and PolygonMode  interpretation of polygons (section 3.5.4) has taken place. It may also occur after polygons with more than three edges are broken up into triangles (if the GL implementation renders polygons by performing this decomposition). x, y, and z coordinates returned by feedback are window coordinates; if w is returned, it is in clip coordinates. No depth offset arithmetic (section 3.5.5) is performed on the z values. In the case of bitmaps and pixel rectangles, the coordinates returned are those of the current raster position. The texture coordinates and colors returned are those resulting from the clipping operations as described in (section 2.13.8).

The ordering rules for GL command interpretation also apply in feedback mode. Each command must be fully interpreted and its effects on both GL state and the values to be written to the feedback buffer completed before a subsequent command may be executed.

The GL is taken out of feedback mode by calling RenderMode  with an argument value other than FEEDBACK. When called while in feedback mode, RenderMode  returns the number of values placed in the feedback array and resets the feedback array pointer to be buffer. The return value never exceeds the maximum number of values passed to FeedbackBuffer .

If writing a value to the feedback buffer would cause more values to be written than the specified maximum number of values, then the value is not written and an overflow flag is set. In this case, RenderMode  returns -1 when it is called, after which the overflow flag is reset. While in feedback mode, values are not guaranteed to be written into the feedback buffer before RenderMode  is called.

Figure 5.2 gives a grammar for the array produced by feedback. Each primitive is indicated with a unique identifying value followed by some number of vertices. A vertex is fed back as some number of floating-point values determined by the feedback type. Table 5.2 gives the correspondence between feedback *buffer and the number of values returned for each vertex.

  
Table 5.2: Correspondence of feedback type to number of values per vertex. k is 1 in color index mode and 4 in RGBA mode.

The command

void PassThrough ( float token ) ;

may be used as a marker in feedback mode. token is returned as if it were a primitive; it is indicated with its own unique identifying value. The ordering of any PassThrough  commands with respect to primitive specification is maintained by feedback. PassThrough  may not occur between Begin  and End . It has no effect when the GL is not in feedback mode.

The state required for feedback is the pointer to the feedback array, the maximum number of values that may be placed there, and the feedback type. An overflow flag is required to indicate whether the maximum allowable number of feedback values has been written; initially this flag is cleared. These state variables are GL client state. Feedback also relies on the same mode flag as selection to indicate whether the GL is in feedback, selection, or normal rendering mode.

  
Figure 5.2: Feedback syntax. f is a floating-point number. n is a floating-point integer giving the number of vertices in a polygon. The symbols ending with _TOKEN are symbolic floating-point constants. The labels under the ``vertex'' rule show the different data returned for vertices depending on the feedback type. LINE_TOKEN and LINE_RESET_TOKEN are identical except that the latter is returned only when the line stipple is reset for that line segment.



next up previous contents index
Next: 5.4 Display Lists Up: 5 Special Functions Previous: 5.2 Selection



David Blythe
Sat Mar 29 02:23:21 PST 1997