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 * THE AUTHORS 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"
33 #include "main/state.h"
37 * Called via glSampleCoverageARB
40 _mesa_SampleCoverage(GLclampf value
, GLboolean invert
)
42 GET_CURRENT_CONTEXT(ctx
);
44 FLUSH_VERTICES(ctx
, 0);
46 ctx
->Multisample
.SampleCoverageValue
= (GLfloat
) CLAMP(value
, 0.0, 1.0);
47 ctx
->Multisample
.SampleCoverageInvert
= invert
;
48 ctx
->NewState
|= _NEW_MULTISAMPLE
;
53 * Initialize the context's multisample state.
54 * \param ctx the GL context.
57 _mesa_init_multisample(struct gl_context
*ctx
)
59 ctx
->Multisample
.Enabled
= GL_TRUE
;
60 ctx
->Multisample
.SampleAlphaToCoverage
= GL_FALSE
;
61 ctx
->Multisample
.SampleAlphaToOne
= GL_FALSE
;
62 ctx
->Multisample
.SampleCoverage
= GL_FALSE
;
63 ctx
->Multisample
.SampleCoverageValue
= 1.0;
64 ctx
->Multisample
.SampleCoverageInvert
= GL_FALSE
;
66 /* ARB_texture_multisample / GL3.2 additions */
67 ctx
->Multisample
.SampleMask
= GL_FALSE
;
68 ctx
->Multisample
.SampleMaskValue
= ~(GLbitfield
)0;
73 _mesa_GetMultisamplefv(GLenum pname
, GLuint index
, GLfloat
* val
)
75 GET_CURRENT_CONTEXT(ctx
);
77 if (ctx
->NewState
& _NEW_BUFFERS
) {
78 _mesa_update_state(ctx
);
82 case GL_SAMPLE_POSITION
: {
83 if (index
>= ctx
->DrawBuffer
->Visual
.samples
) {
84 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetMultisamplefv(index)" );
88 ctx
->Driver
.GetSamplePosition(ctx
, ctx
->DrawBuffer
, index
, val
);
90 /* winsys FBOs are upside down */
91 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
))
98 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMultisamplefv(pname)" );
104 _mesa_SampleMaski(GLuint index
, GLbitfield mask
)
106 GET_CURRENT_CONTEXT(ctx
);
108 if (!ctx
->Extensions
.ARB_texture_multisample
) {
109 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glSampleMaski");
114 _mesa_error(ctx
, GL_INVALID_VALUE
, "glSampleMaski(index)");
118 FLUSH_VERTICES(ctx
, _NEW_MULTISAMPLE
);
119 ctx
->Multisample
.SampleMaskValue
= mask
;
123 /* Helper for checking a requested sample count against the limit
124 * for a particular (target, internalFormat) pair. The limit imposed,
125 * and the error generated, both depend on which extensions are supported.
127 * Returns a GL error enum, or GL_NO_ERROR if the requested sample count is
131 _mesa_check_sample_count(struct gl_context
*ctx
, GLenum target
,
132 GLenum internalFormat
, GLsizei samples
)
134 /* If ARB_internalformat_query is supported, then treat its highest returned sample
135 * count as the absolute maximum for this format; it is allowed to exceed MAX_SAMPLES.
137 * From the ARB_internalformat_query spec:
139 * "If <samples is greater than the maximum number of samples supported
140 * for <internalformat> then the error INVALID_OPERATION is generated."
142 if (ctx
->Extensions
.ARB_internalformat_query
) {
144 int count
= ctx
->Driver
.QuerySamplesForFormat(ctx
, target
, internalFormat
, buffer
);
145 int limit
= count
? buffer
[0] : -1;
147 return samples
> limit
? GL_INVALID_OPERATION
: GL_NO_ERROR
;
150 /* If ARB_texture_multisample is supported, we have separate limits,
151 * which may be lower than MAX_SAMPLES:
153 * From the ARB_texture_multisample spec, when describing the operation
154 * of RenderbufferStorageMultisample:
156 * "If <internalformat> is a signed or unsigned integer format and
157 * <samples> is greater than the value of MAX_INTEGER_SAMPLES, then the
158 * error INVALID_OPERATION is generated"
160 * And when describing the operation of TexImage*Multisample:
162 * "The error INVALID_OPERATION may be generated if any of the following are true:
164 * * <internalformat> is a depth/stencil-renderable format and <samples>
165 * is greater than the value of MAX_DEPTH_TEXTURE_SAMPLES
166 * * <internalformat> is a color-renderable format and <samples> is
167 * grater than the value of MAX_COLOR_TEXTURE_SAMPLES
168 * * <internalformat> is a signed or unsigned integer format and
169 * <samples> is greater than the value of MAX_INTEGER_SAMPLES
172 if (ctx
->Extensions
.ARB_texture_multisample
) {
173 if (_mesa_is_enum_format_integer(internalFormat
))
174 return samples
> ctx
->Const
.MaxIntegerSamples
? GL_INVALID_OPERATION
: GL_NO_ERROR
;
176 if (target
== GL_TEXTURE_2D_MULTISAMPLE
||
177 target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) {
179 if (_mesa_is_depth_or_stencil_format(internalFormat
))
180 return samples
> ctx
->Const
.MaxDepthTextureSamples
181 ? GL_INVALID_OPERATION
: GL_NO_ERROR
;
183 return samples
> ctx
->Const
.MaxColorTextureSamples
184 ? GL_INVALID_OPERATION
: GL_NO_ERROR
;
188 /* No more specific limit is available, so just use MAX_SAMPLES:
190 * On p205 of the GL3.1 spec:
192 * "... or if samples is greater than MAX_SAMPLES, then the error
193 * INVALID_VALUE is generated"
195 return samples
> ctx
->Const
.MaxSamples
? GL_INVALID_VALUE
: GL_NO_ERROR
;