Graphics Reference
In-Depth Information
void
glSampleCoverage
(GLfloat
value
, GLboolean
invert
)
value
specifies a value in the range [0, 1] that is converted into a
sample mask; the resulting mask should have a proportional
number of bits set corresponding to the value
invert
specifies that after determining the mask's value, all of the bits
in the mask should be inverted
When rendering with multisampling, the fragment data is picked from a
sample that is closest to a pixel center. This can lead to rendering artifacts
near triangle edges, as the pixel center may sometimes fall outside of the
triangle. In such case, the fragment data can be extrapolated to a point
outside of the triangle. Centroid sampling solves this problem by ensuring
that the fragment data is picked from a sample that falls inside the triangle.
To enable centroid sampling, you can declare the output variables of
the vertex shader (and input variables to the fragment shader) with the
centroid
qualifier as follows:
smooth centroid out vec3 v_color;
Note that using centroid sampling can lead to less accurate derivatives for
pixels near the triangle edges.
If you want to preserve your rendered image for posterity's sake, you can read
the pixel values back from the color buffer, but not from the depth or stencil
buffers. When you call
glReadPixels
, the pixels in the color buffer are
returned to your application in an array that has been previously allocated.
void
glReadPixels
(GLint
x
, GLint
y
, GLsizei
width
,
GLsizei
height
, GLenum
format
,
GLenum
type,
GLvoid
*pixels
)
x, y
specify the viewport coordinates of the lower-left corner of the
pixel rectangle read from the color buffer.
width
specify the dimensions of the pixel rectangle read from the
height
color buffer.