2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include "main/glheader.h"
27 #include "main/context.h"
28 #include "main/macros.h"
29 #include "main/multisample.h"
30 #include "main/mtypes.h"
31 #include "main/fbobject.h"
32 #include "main/glformats.h"
36 * Called via glSampleCoverageARB
39 _mesa_SampleCoverage(GLclampf value
, GLboolean invert
)
41 GET_CURRENT_CONTEXT(ctx
);
43 FLUSH_VERTICES(ctx
, 0);
45 ctx
->Multisample
.SampleCoverageValue
= (GLfloat
) CLAMP(value
, 0.0, 1.0);
46 ctx
->Multisample
.SampleCoverageInvert
= invert
;
47 ctx
->NewState
|= _NEW_MULTISAMPLE
;
52 * Initialize the context's multisample state.
53 * \param ctx the GL context.
56 _mesa_init_multisample(struct gl_context
*ctx
)
58 ctx
->Multisample
.Enabled
= GL_TRUE
;
59 ctx
->Multisample
.SampleAlphaToCoverage
= GL_FALSE
;
60 ctx
->Multisample
.SampleAlphaToOne
= GL_FALSE
;
61 ctx
->Multisample
.SampleCoverage
= GL_FALSE
;
62 ctx
->Multisample
.SampleCoverageValue
= 1.0;
63 ctx
->Multisample
.SampleCoverageInvert
= GL_FALSE
;
65 /* ARB_texture_multisample / GL3.2 additions */
66 ctx
->Multisample
.SampleMask
= GL_FALSE
;
67 ctx
->Multisample
.SampleMaskValue
= ~(GLbitfield
)0;
72 _mesa_GetMultisamplefv(GLenum pname
, GLuint index
, GLfloat
* val
)
74 GET_CURRENT_CONTEXT(ctx
);
77 case GL_SAMPLE_POSITION
: {
78 if (index
>= ctx
->DrawBuffer
->Visual
.samples
) {
79 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetMultisamplefv(index)" );
83 ctx
->Driver
.GetSamplePosition(ctx
, ctx
->DrawBuffer
, index
, val
);
85 /* winsys FBOs are upside down */
86 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
))
93 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMultisamplefv(pname)" );
99 _mesa_SampleMaski(GLuint index
, GLbitfield mask
)
101 GET_CURRENT_CONTEXT(ctx
);
103 if (!ctx
->Extensions
.ARB_texture_multisample
) {
104 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glSampleMaski");
109 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSampleMaski(index)");
113 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
114 ctx
->Multisample
.SampleMaskValue
= mask
;
118 /* Helper for checking a requested sample count against the limit
119 * for a particular (target, internalFormat) pair. The limit imposed,
120 * and the error generated, both depend on which extensions are supported.
122 * Returns a GL error enum, or GL_NO_ERROR if the requested sample count is
126 _mesa_check_sample_count(struct gl_context
*ctx
, GLenum target
,
127 GLenum internalFormat
, GLsizei samples
)
129 /* If ARB_internalformat_query is supported, then treat its highest returned sample
130 * count as the absolute maximum for this format; it is allowed to exceed MAX_SAMPLES.
132 * From the ARB_internalformat_query spec:
134 * "If <samples is greater than the maximum number of samples supported
135 * for <internalformat> then the error INVALID_OPERATION is generated."
137 if (ctx
->Extensions
.ARB_internalformat_query
) {
139 int count
= ctx
->Driver
.QuerySamplesForFormat(ctx
, target
, internalFormat
, buffer
);
140 int limit
= count
? buffer
[0] : -1;
142 return samples
> limit
? GL_INVALID_OPERATION
: GL_NO_ERROR
;
145 /* If ARB_texture_multisample is supported, we have separate limits for
148 * From the ARB_texture_multisample spec:
150 * "If <internalformat> is a signed or unsigned integer format and
151 * <samples> is greater than the value of MAX_INTEGER_SAMPLES, then the
152 * error INVALID_OPERATION is generated"
155 if (ctx
->Extensions
.ARB_texture_multisample
) {
156 if (_mesa_is_enum_format_integer(internalFormat
))
157 return samples
> ctx
->Const
.MaxIntegerSamples
? GL_INVALID_OPERATION
: GL_NO_ERROR
;
160 /* No more specific limit is available, so just use MAX_SAMPLES:
162 * On p205 of the GL3.1 spec:
164 * "... or if samples is greater than MAX_SAMPLES, then the error
165 * INVALID_VALUE is generated"
167 return samples
> ctx
->Const
.MaxSamples
? GL_INVALID_VALUE
: GL_NO_ERROR
;