1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Mesa 3-D graphics library
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
12bf215546Sopenharmony_ci *
13bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
14bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#include "main/glheader.h"
27bf215546Sopenharmony_ci#include "main/context.h"
28bf215546Sopenharmony_ci#include "main/macros.h"
29bf215546Sopenharmony_ci#include "main/multisample.h"
30bf215546Sopenharmony_ci#include "main/mtypes.h"
31bf215546Sopenharmony_ci#include "main/fbobject.h"
32bf215546Sopenharmony_ci#include "main/glformats.h"
33bf215546Sopenharmony_ci#include "main/state.h"
34bf215546Sopenharmony_ci#include "api_exec_decl.h"
35bf215546Sopenharmony_ci#include "main/framebuffer.h"
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "state_tracker/st_context.h"
38bf215546Sopenharmony_ci#include "state_tracker/st_format.h"
39bf215546Sopenharmony_ci#include "state_tracker/st_context.h"
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci/**
42bf215546Sopenharmony_ci * Called via glSampleCoverageARB
43bf215546Sopenharmony_ci */
44bf215546Sopenharmony_civoid GLAPIENTRY
45bf215546Sopenharmony_ci_mesa_SampleCoverage(GLclampf value, GLboolean invert)
46bf215546Sopenharmony_ci{
47bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci   value = SATURATE(value);
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci   if (ctx->Multisample.SampleCoverageInvert == invert &&
52bf215546Sopenharmony_ci       ctx->Multisample.SampleCoverageValue == value)
53bf215546Sopenharmony_ci      return;
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci   FLUSH_VERTICES(ctx, 0, GL_MULTISAMPLE_BIT);
56bf215546Sopenharmony_ci   ctx->NewDriverState |= ST_NEW_SAMPLE_STATE;
57bf215546Sopenharmony_ci   ctx->Multisample.SampleCoverageValue = value;
58bf215546Sopenharmony_ci   ctx->Multisample.SampleCoverageInvert = invert;
59bf215546Sopenharmony_ci}
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci/**
63bf215546Sopenharmony_ci * Initialize the context's multisample state.
64bf215546Sopenharmony_ci * \param ctx  the GL context.
65bf215546Sopenharmony_ci */
66bf215546Sopenharmony_civoid
67bf215546Sopenharmony_ci_mesa_init_multisample(struct gl_context *ctx)
68bf215546Sopenharmony_ci{
69bf215546Sopenharmony_ci   ctx->Multisample.Enabled = GL_TRUE;
70bf215546Sopenharmony_ci   ctx->Multisample.SampleAlphaToCoverage = GL_FALSE;
71bf215546Sopenharmony_ci   ctx->Multisample.SampleAlphaToCoverageDitherControl = GL_ALPHA_TO_COVERAGE_DITHER_DEFAULT_NV;
72bf215546Sopenharmony_ci   ctx->Multisample.SampleAlphaToOne = GL_FALSE;
73bf215546Sopenharmony_ci   ctx->Multisample.SampleCoverage = GL_FALSE;
74bf215546Sopenharmony_ci   ctx->Multisample.SampleCoverageValue = 1.0;
75bf215546Sopenharmony_ci   ctx->Multisample.SampleCoverageInvert = GL_FALSE;
76bf215546Sopenharmony_ci   ctx->Multisample.SampleShading = GL_FALSE;
77bf215546Sopenharmony_ci   ctx->Multisample.MinSampleShadingValue = 0.0f;
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci   /* ARB_texture_multisample / GL3.2 additions */
80bf215546Sopenharmony_ci   ctx->Multisample.SampleMask = GL_FALSE;
81bf215546Sopenharmony_ci   ctx->Multisample.SampleMaskValue = ~(GLbitfield)0;
82bf215546Sopenharmony_ci}
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_cistatic void
85bf215546Sopenharmony_ciget_sample_position(struct gl_context *ctx,
86bf215546Sopenharmony_ci                    struct gl_framebuffer *fb,
87bf215546Sopenharmony_ci                    GLuint index,
88bf215546Sopenharmony_ci                    GLfloat *outPos)
89bf215546Sopenharmony_ci{
90bf215546Sopenharmony_ci   struct st_context *st = st_context(ctx);
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci   st_validate_state(st, ST_PIPELINE_UPDATE_FRAMEBUFFER);
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci   if (ctx->pipe->get_sample_position)
95bf215546Sopenharmony_ci      ctx->pipe->get_sample_position(ctx->pipe,
96bf215546Sopenharmony_ci                                     _mesa_geometric_samples(fb),
97bf215546Sopenharmony_ci                                     index, outPos);
98bf215546Sopenharmony_ci   else
99bf215546Sopenharmony_ci      outPos[0] = outPos[1] = 0.5f;
100bf215546Sopenharmony_ci}
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_civoid GLAPIENTRY
103bf215546Sopenharmony_ci_mesa_GetMultisamplefv(GLenum pname, GLuint index, GLfloat * val)
104bf215546Sopenharmony_ci{
105bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci   if (ctx->NewState & _NEW_BUFFERS) {
108bf215546Sopenharmony_ci      _mesa_update_state(ctx);
109bf215546Sopenharmony_ci   }
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci   switch (pname) {
112bf215546Sopenharmony_ci   case GL_SAMPLE_POSITION: {
113bf215546Sopenharmony_ci      if (index >= ctx->DrawBuffer->Visual.samples) {
114bf215546Sopenharmony_ci         _mesa_error( ctx, GL_INVALID_VALUE, "glGetMultisamplefv(index)" );
115bf215546Sopenharmony_ci         return;
116bf215546Sopenharmony_ci      }
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_ci      get_sample_position(ctx, ctx->DrawBuffer, index, val);
119bf215546Sopenharmony_ci
120bf215546Sopenharmony_ci      /* FBOs can be upside down (winsys always are)*/
121bf215546Sopenharmony_ci      if (ctx->DrawBuffer->FlipY)
122bf215546Sopenharmony_ci         val[1] = 1.0f - val[1];
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ci      return;
125bf215546Sopenharmony_ci   }
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci   case GL_PROGRAMMABLE_SAMPLE_LOCATION_ARB:
128bf215546Sopenharmony_ci      if (!ctx->Extensions.ARB_sample_locations) {
129bf215546Sopenharmony_ci         _mesa_error( ctx, GL_INVALID_ENUM, "glGetMultisamplefv(pname)" );
130bf215546Sopenharmony_ci         return;
131bf215546Sopenharmony_ci      }
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_ci      if (index >= MAX_SAMPLE_LOCATION_TABLE_SIZE * 2) {
134bf215546Sopenharmony_ci         _mesa_error( ctx, GL_INVALID_VALUE, "glGetMultisamplefv(index)" );
135bf215546Sopenharmony_ci         return;
136bf215546Sopenharmony_ci      }
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_ci      if (ctx->DrawBuffer->SampleLocationTable)
139bf215546Sopenharmony_ci         *val = ctx->DrawBuffer->SampleLocationTable[index];
140bf215546Sopenharmony_ci      else
141bf215546Sopenharmony_ci         *val = 0.5f;
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci      return;
144bf215546Sopenharmony_ci
145bf215546Sopenharmony_ci   default:
146bf215546Sopenharmony_ci      _mesa_error( ctx, GL_INVALID_ENUM, "glGetMultisamplefv(pname)" );
147bf215546Sopenharmony_ci      return;
148bf215546Sopenharmony_ci   }
149bf215546Sopenharmony_ci}
150bf215546Sopenharmony_ci
151bf215546Sopenharmony_cistatic void
152bf215546Sopenharmony_cisample_maski(struct gl_context *ctx, GLuint index, GLbitfield mask)
153bf215546Sopenharmony_ci{
154bf215546Sopenharmony_ci   if (ctx->Multisample.SampleMaskValue == mask)
155bf215546Sopenharmony_ci      return;
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_ci   FLUSH_VERTICES(ctx, 0, 0);
158bf215546Sopenharmony_ci   ctx->NewDriverState |= ST_NEW_SAMPLE_STATE;
159bf215546Sopenharmony_ci   ctx->Multisample.SampleMaskValue = mask;
160bf215546Sopenharmony_ci}
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_civoid GLAPIENTRY
163bf215546Sopenharmony_ci_mesa_SampleMaski_no_error(GLuint index, GLbitfield mask)
164bf215546Sopenharmony_ci{
165bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
166bf215546Sopenharmony_ci   sample_maski(ctx, index, mask);
167bf215546Sopenharmony_ci}
168bf215546Sopenharmony_ci
169bf215546Sopenharmony_civoid GLAPIENTRY
170bf215546Sopenharmony_ci_mesa_SampleMaski(GLuint index, GLbitfield mask)
171bf215546Sopenharmony_ci{
172bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
173bf215546Sopenharmony_ci
174bf215546Sopenharmony_ci   if (!ctx->Extensions.ARB_texture_multisample) {
175bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glSampleMaski");
176bf215546Sopenharmony_ci      return;
177bf215546Sopenharmony_ci   }
178bf215546Sopenharmony_ci
179bf215546Sopenharmony_ci   if (index != 0) {
180bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_VALUE, "glSampleMaski(index)");
181bf215546Sopenharmony_ci      return;
182bf215546Sopenharmony_ci   }
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ci   sample_maski(ctx, index, mask);
185bf215546Sopenharmony_ci}
186bf215546Sopenharmony_ci
187bf215546Sopenharmony_cistatic void
188bf215546Sopenharmony_cimin_sample_shading(struct gl_context *ctx, GLclampf value)
189bf215546Sopenharmony_ci{
190bf215546Sopenharmony_ci   value = SATURATE(value);
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_ci   if (ctx->Multisample.MinSampleShadingValue == value)
193bf215546Sopenharmony_ci      return;
194bf215546Sopenharmony_ci
195bf215546Sopenharmony_ci   FLUSH_VERTICES(ctx, 0, GL_MULTISAMPLE_BIT);
196bf215546Sopenharmony_ci   ctx->NewDriverState |= ctx->DriverFlags.NewSampleShading;
197bf215546Sopenharmony_ci   ctx->Multisample.MinSampleShadingValue = value;
198bf215546Sopenharmony_ci}
199bf215546Sopenharmony_ci
200bf215546Sopenharmony_ci/**
201bf215546Sopenharmony_ci * Called via glMinSampleShadingARB
202bf215546Sopenharmony_ci */
203bf215546Sopenharmony_civoid GLAPIENTRY
204bf215546Sopenharmony_ci_mesa_MinSampleShading_no_error(GLclampf value)
205bf215546Sopenharmony_ci{
206bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
207bf215546Sopenharmony_ci   min_sample_shading(ctx, value);
208bf215546Sopenharmony_ci}
209bf215546Sopenharmony_ci
210bf215546Sopenharmony_civoid GLAPIENTRY
211bf215546Sopenharmony_ci_mesa_MinSampleShading(GLclampf value)
212bf215546Sopenharmony_ci{
213bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_ci   if (!_mesa_has_ARB_sample_shading(ctx) &&
216bf215546Sopenharmony_ci       !_mesa_has_OES_sample_shading(ctx)) {
217bf215546Sopenharmony_ci      _mesa_error(ctx, GL_INVALID_OPERATION, "glMinSampleShading");
218bf215546Sopenharmony_ci      return;
219bf215546Sopenharmony_ci   }
220bf215546Sopenharmony_ci
221bf215546Sopenharmony_ci   min_sample_shading(ctx, value);
222bf215546Sopenharmony_ci}
223bf215546Sopenharmony_ci
224bf215546Sopenharmony_ci/**
225bf215546Sopenharmony_ci * Helper for checking a requested sample count against the limit
226bf215546Sopenharmony_ci * for a particular (target, internalFormat) pair. The limit imposed,
227bf215546Sopenharmony_ci * and the error generated, both depend on which extensions are supported.
228bf215546Sopenharmony_ci *
229bf215546Sopenharmony_ci * Returns a GL error enum, or GL_NO_ERROR if the requested sample count is
230bf215546Sopenharmony_ci * acceptable.
231bf215546Sopenharmony_ci */
232bf215546Sopenharmony_ciGLenum
233bf215546Sopenharmony_ci_mesa_check_sample_count(struct gl_context *ctx, GLenum target,
234bf215546Sopenharmony_ci                         GLenum internalFormat, GLsizei samples,
235bf215546Sopenharmony_ci                         GLsizei storageSamples)
236bf215546Sopenharmony_ci{
237bf215546Sopenharmony_ci   /* Section 4.4 (Framebuffer objects), page 198 of the OpenGL ES 3.0.0
238bf215546Sopenharmony_ci    * specification says:
239bf215546Sopenharmony_ci    *
240bf215546Sopenharmony_ci    *     "If internalformat is a signed or unsigned integer format and samples
241bf215546Sopenharmony_ci    *     is greater than zero, then the error INVALID_OPERATION is generated."
242bf215546Sopenharmony_ci    *
243bf215546Sopenharmony_ci    * This restriction is relaxed for OpenGL ES 3.1.
244bf215546Sopenharmony_ci    */
245bf215546Sopenharmony_ci   if ((ctx->API == API_OPENGLES2 && ctx->Version == 30) &&
246bf215546Sopenharmony_ci       _mesa_is_enum_format_integer(internalFormat)
247bf215546Sopenharmony_ci       && samples > 0) {
248bf215546Sopenharmony_ci      return GL_INVALID_OPERATION;
249bf215546Sopenharmony_ci   }
250bf215546Sopenharmony_ci
251bf215546Sopenharmony_ci   if (ctx->Extensions.AMD_framebuffer_multisample_advanced &&
252bf215546Sopenharmony_ci       target == GL_RENDERBUFFER) {
253bf215546Sopenharmony_ci      if (!_mesa_is_depth_or_stencil_format(internalFormat)) {
254bf215546Sopenharmony_ci         /* From the AMD_framebuffer_multisample_advanced spec:
255bf215546Sopenharmony_ci          *
256bf215546Sopenharmony_ci          *    "An INVALID_OPERATION error is generated if <internalformat>
257bf215546Sopenharmony_ci          *     is a color format and <storageSamples> is greater than
258bf215546Sopenharmony_ci          *     the implementation-dependent limit MAX_COLOR_FRAMEBUFFER_-
259bf215546Sopenharmony_ci          *     STORAGE_SAMPLES_AMD."
260bf215546Sopenharmony_ci          */
261bf215546Sopenharmony_ci         if (samples > ctx->Const.MaxColorFramebufferSamples)
262bf215546Sopenharmony_ci            return GL_INVALID_OPERATION;
263bf215546Sopenharmony_ci
264bf215546Sopenharmony_ci         /* From the AMD_framebuffer_multisample_advanced spec:
265bf215546Sopenharmony_ci          *
266bf215546Sopenharmony_ci          *    "An INVALID_OPERATION error is generated if <internalformat>
267bf215546Sopenharmony_ci          *     is a color format and <storageSamples> is greater than
268bf215546Sopenharmony_ci          *     the implementation-dependent limit MAX_COLOR_FRAMEBUFFER_-
269bf215546Sopenharmony_ci          *     STORAGE_SAMPLES_AMD."
270bf215546Sopenharmony_ci          */
271bf215546Sopenharmony_ci         if (storageSamples > ctx->Const.MaxColorFramebufferStorageSamples)
272bf215546Sopenharmony_ci            return GL_INVALID_OPERATION;
273bf215546Sopenharmony_ci
274bf215546Sopenharmony_ci         /* From the AMD_framebuffer_multisample_advanced spec:
275bf215546Sopenharmony_ci          *
276bf215546Sopenharmony_ci          *    "An INVALID_OPERATION error is generated if <storageSamples> is
277bf215546Sopenharmony_ci          *     greater than <samples>."
278bf215546Sopenharmony_ci          */
279bf215546Sopenharmony_ci         if (storageSamples > samples)
280bf215546Sopenharmony_ci            return GL_INVALID_OPERATION;
281bf215546Sopenharmony_ci
282bf215546Sopenharmony_ci         /* Color renderbuffer sample counts are now fully validated
283bf215546Sopenharmony_ci          * according to AMD_framebuffer_multisample_advanced.
284bf215546Sopenharmony_ci          */
285bf215546Sopenharmony_ci         return GL_NO_ERROR;
286bf215546Sopenharmony_ci      } else {
287bf215546Sopenharmony_ci         /* From the AMD_framebuffer_multisample_advanced spec:
288bf215546Sopenharmony_ci          *
289bf215546Sopenharmony_ci          *    "An INVALID_OPERATION error is generated if <internalformat> is
290bf215546Sopenharmony_ci          *     a depth or stencil format and <storageSamples> is not equal to
291bf215546Sopenharmony_ci          *     <samples>."
292bf215546Sopenharmony_ci          */
293bf215546Sopenharmony_ci         if (storageSamples != samples)
294bf215546Sopenharmony_ci            return GL_INVALID_OPERATION;
295bf215546Sopenharmony_ci      }
296bf215546Sopenharmony_ci   } else {
297bf215546Sopenharmony_ci      /* If the extension is unsupported, it's not possible to set
298bf215546Sopenharmony_ci       * storageSamples differently.
299bf215546Sopenharmony_ci       */
300bf215546Sopenharmony_ci      assert(samples == storageSamples);
301bf215546Sopenharmony_ci   }
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_ci   /* If ARB_internalformat_query is supported, then treat its highest
304bf215546Sopenharmony_ci    * returned sample count as the absolute maximum for this format; it is
305bf215546Sopenharmony_ci    * allowed to exceed MAX_SAMPLES.
306bf215546Sopenharmony_ci    *
307bf215546Sopenharmony_ci    * From the ARB_internalformat_query spec:
308bf215546Sopenharmony_ci    *
309bf215546Sopenharmony_ci    * "If <samples is greater than the maximum number of samples supported
310bf215546Sopenharmony_ci    * for <internalformat> then the error INVALID_OPERATION is generated."
311bf215546Sopenharmony_ci    */
312bf215546Sopenharmony_ci   if (ctx->Extensions.ARB_internalformat_query) {
313bf215546Sopenharmony_ci      GLint buffer[16] = {-1};
314bf215546Sopenharmony_ci      GLint limit;
315bf215546Sopenharmony_ci
316bf215546Sopenharmony_ci      st_QueryInternalFormat(ctx, target, internalFormat,
317bf215546Sopenharmony_ci                             GL_SAMPLES, buffer);
318bf215546Sopenharmony_ci      /* since the query returns samples sorted in descending order,
319bf215546Sopenharmony_ci       * the first element is the greatest supported sample value.
320bf215546Sopenharmony_ci       */
321bf215546Sopenharmony_ci      limit = buffer[0];
322bf215546Sopenharmony_ci
323bf215546Sopenharmony_ci      return samples > limit ? GL_INVALID_OPERATION : GL_NO_ERROR;
324bf215546Sopenharmony_ci   }
325bf215546Sopenharmony_ci
326bf215546Sopenharmony_ci   /* If ARB_texture_multisample is supported, we have separate limits,
327bf215546Sopenharmony_ci    * which may be lower than MAX_SAMPLES:
328bf215546Sopenharmony_ci    *
329bf215546Sopenharmony_ci    * From the ARB_texture_multisample spec, when describing the operation
330bf215546Sopenharmony_ci    * of RenderbufferStorageMultisample:
331bf215546Sopenharmony_ci    *
332bf215546Sopenharmony_ci    * "If <internalformat> is a signed or unsigned integer format and
333bf215546Sopenharmony_ci    * <samples> is greater than the value of MAX_INTEGER_SAMPLES, then the
334bf215546Sopenharmony_ci    * error INVALID_OPERATION is generated"
335bf215546Sopenharmony_ci    *
336bf215546Sopenharmony_ci    * And when describing the operation of TexImage*Multisample:
337bf215546Sopenharmony_ci    *
338bf215546Sopenharmony_ci    * "The error INVALID_OPERATION may be generated if any of the following
339bf215546Sopenharmony_ci    * are true:
340bf215546Sopenharmony_ci    *
341bf215546Sopenharmony_ci    * * <internalformat> is a depth/stencil-renderable format and <samples>
342bf215546Sopenharmony_ci    *   is greater than the value of MAX_DEPTH_TEXTURE_SAMPLES
343bf215546Sopenharmony_ci    * * <internalformat> is a color-renderable format and <samples> is
344bf215546Sopenharmony_ci    *   grater than the value of MAX_COLOR_TEXTURE_SAMPLES
345bf215546Sopenharmony_ci    * * <internalformat> is a signed or unsigned integer format and
346bf215546Sopenharmony_ci    *   <samples> is greater than the value of MAX_INTEGER_SAMPLES
347bf215546Sopenharmony_ci    */
348bf215546Sopenharmony_ci
349bf215546Sopenharmony_ci   if (ctx->Extensions.ARB_texture_multisample) {
350bf215546Sopenharmony_ci      if (_mesa_is_enum_format_integer(internalFormat))
351bf215546Sopenharmony_ci         return samples > ctx->Const.MaxIntegerSamples
352bf215546Sopenharmony_ci            ? GL_INVALID_OPERATION : GL_NO_ERROR;
353bf215546Sopenharmony_ci
354bf215546Sopenharmony_ci      if (target == GL_TEXTURE_2D_MULTISAMPLE ||
355bf215546Sopenharmony_ci          target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
356bf215546Sopenharmony_ci
357bf215546Sopenharmony_ci         if (_mesa_is_depth_or_stencil_format(internalFormat))
358bf215546Sopenharmony_ci            return samples > ctx->Const.MaxDepthTextureSamples
359bf215546Sopenharmony_ci               ? GL_INVALID_OPERATION : GL_NO_ERROR;
360bf215546Sopenharmony_ci         else
361bf215546Sopenharmony_ci            return samples > ctx->Const.MaxColorTextureSamples
362bf215546Sopenharmony_ci               ? GL_INVALID_OPERATION : GL_NO_ERROR;
363bf215546Sopenharmony_ci      }
364bf215546Sopenharmony_ci   }
365bf215546Sopenharmony_ci
366bf215546Sopenharmony_ci   /* No more specific limit is available, so just use MAX_SAMPLES:
367bf215546Sopenharmony_ci    *
368bf215546Sopenharmony_ci    * On p205 of the GL3.1 spec:
369bf215546Sopenharmony_ci    *
370bf215546Sopenharmony_ci    * "... or if samples is greater than MAX_SAMPLES, then the error
371bf215546Sopenharmony_ci    * INVALID_VALUE is generated"
372bf215546Sopenharmony_ci    */
373bf215546Sopenharmony_ci   return (GLuint) samples > ctx->Const.MaxSamples
374bf215546Sopenharmony_ci      ? GL_INVALID_VALUE : GL_NO_ERROR;
375bf215546Sopenharmony_ci}
376bf215546Sopenharmony_ci
377bf215546Sopenharmony_civoid GLAPIENTRY
378bf215546Sopenharmony_ci_mesa_AlphaToCoverageDitherControlNV_no_error(GLenum mode)
379bf215546Sopenharmony_ci{
380bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
381bf215546Sopenharmony_ci
382bf215546Sopenharmony_ci   FLUSH_VERTICES(ctx, 0, GL_MULTISAMPLE_BIT);
383bf215546Sopenharmony_ci   ctx->NewDriverState |= ST_NEW_BLEND;
384bf215546Sopenharmony_ci   ctx->Multisample.SampleAlphaToCoverageDitherControl = mode;
385bf215546Sopenharmony_ci}
386bf215546Sopenharmony_ci
387bf215546Sopenharmony_civoid GLAPIENTRY
388bf215546Sopenharmony_ci_mesa_AlphaToCoverageDitherControlNV(GLenum mode)
389bf215546Sopenharmony_ci{
390bf215546Sopenharmony_ci   GET_CURRENT_CONTEXT(ctx);
391bf215546Sopenharmony_ci
392bf215546Sopenharmony_ci   FLUSH_VERTICES(ctx, 0, GL_MULTISAMPLE_BIT);
393bf215546Sopenharmony_ci   ctx->NewDriverState |= ST_NEW_BLEND;
394bf215546Sopenharmony_ci   switch (mode) {
395bf215546Sopenharmony_ci      case GL_ALPHA_TO_COVERAGE_DITHER_DEFAULT_NV:
396bf215546Sopenharmony_ci      case GL_ALPHA_TO_COVERAGE_DITHER_ENABLE_NV:
397bf215546Sopenharmony_ci      case GL_ALPHA_TO_COVERAGE_DITHER_DISABLE_NV:
398bf215546Sopenharmony_ci         ctx->Multisample.SampleAlphaToCoverageDitherControl = mode;
399bf215546Sopenharmony_ci         break;
400bf215546Sopenharmony_ci      default:
401bf215546Sopenharmony_ci         _mesa_error(ctx, GL_INVALID_ENUM, "glAlphaToCoverageDitherControlNV(invalid parameter)");
402bf215546Sopenharmony_ci   }
403bf215546Sopenharmony_ci}
404bf215546Sopenharmony_ci
405bf215546Sopenharmony_civoid
406bf215546Sopenharmony_ci_mesa_GetProgrammableSampleCaps(struct gl_context *ctx, const struct gl_framebuffer *fb,
407bf215546Sopenharmony_ci                                GLuint *outBits, GLuint *outWidth, GLuint *outHeight)
408bf215546Sopenharmony_ci{
409bf215546Sopenharmony_ci   struct st_context *st = st_context(ctx);
410bf215546Sopenharmony_ci   struct pipe_screen *screen = ctx->pipe->screen;
411bf215546Sopenharmony_ci
412bf215546Sopenharmony_ci   st_validate_state(st, ST_PIPELINE_UPDATE_FRAMEBUFFER);
413bf215546Sopenharmony_ci
414bf215546Sopenharmony_ci   *outBits = 4;
415bf215546Sopenharmony_ci   *outWidth = 1;
416bf215546Sopenharmony_ci   *outHeight = 1;
417bf215546Sopenharmony_ci
418bf215546Sopenharmony_ci   if (ctx->Extensions.ARB_sample_locations)
419bf215546Sopenharmony_ci      screen->get_sample_pixel_grid(screen, st->state.fb_num_samples,
420bf215546Sopenharmony_ci                                    outWidth, outHeight);
421bf215546Sopenharmony_ci
422bf215546Sopenharmony_ci   /* We could handle this better in some circumstances,
423bf215546Sopenharmony_ci    * but it's not really an issue */
424bf215546Sopenharmony_ci   if (*outWidth > MAX_SAMPLE_LOCATION_GRID_SIZE ||
425bf215546Sopenharmony_ci       *outHeight > MAX_SAMPLE_LOCATION_GRID_SIZE) {
426bf215546Sopenharmony_ci      *outWidth = 1;
427bf215546Sopenharmony_ci      *outHeight = 1;
428bf215546Sopenharmony_ci   }
429bf215546Sopenharmony_ci}
430