2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 #include "glformats.h"
27 #include "mfeatures.h"
30 #include "formatquery.h"
33 _mesa_GetInternalformativ(GLenum target
, GLenum internalformat
, GLenum pname
,
34 GLsizei bufSize
, GLint
*params
)
38 GET_CURRENT_CONTEXT(ctx
);
40 if (!ctx
->Extensions
.ARB_internalformat_query
) {
41 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformativ");
45 assert(ctx
->Driver
.QuerySamplesForFormat
!= NULL
);
47 /* The ARB_internalformat_query spec says:
49 * "If the <target> parameter to GetInternalformativ is not one of
50 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY or RENDERBUFFER
51 * then an INVALID_ENUM error is generated."
57 case GL_TEXTURE_2D_MULTISAMPLE
:
58 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
59 /* Mesa does not currently support GL_ARB_texture_multisample, so these
60 * enums are not valid on this implementation either.
63 _mesa_error(ctx
, GL_INVALID_ENUM
,
64 "glGetInternalformativ(target=%s)",
65 _mesa_lookup_enum_by_nr(target
));
69 /* The ARB_internalformat_query spec says:
71 * "If the <internalformat> parameter to GetInternalformativ is not
72 * color-, depth- or stencil-renderable, then an INVALID_ENUM error is
75 if (_mesa_base_fbo_format(ctx
, internalformat
) == 0) {
76 _mesa_error(ctx
, GL_INVALID_ENUM
,
77 "glGetInternalformativ(internalformat=%s)",
78 _mesa_lookup_enum_by_nr(internalformat
));
82 /* The ARB_internalformat_query spec says:
84 * "If the <bufSize> parameter to GetInternalformativ is negative, then
85 * an INVALID_VALUE error is generated."
88 _mesa_error(ctx
, GL_INVALID_VALUE
,
89 "glGetInternalformativ(target=%s)",
90 _mesa_lookup_enum_by_nr(target
));
96 count
= ctx
->Driver
.QuerySamplesForFormat(ctx
, internalformat
, buffer
);
98 case GL_NUM_SAMPLE_COUNTS
: {
99 /* The driver can return 0, and we should pass that along to the
100 * application. The ARB decided that ARB_internalformat_query should
101 * behave as ARB_internalformat_query2 in this situation.
103 * The ARB_internalformat_query2 spec says:
105 * "- NUM_SAMPLE_COUNTS: The number of sample counts that would be
106 * returned by querying SAMPLES is returned in <params>.
107 * * If <internalformat> is not color-renderable,
108 * depth-renderable, or stencil-renderable (as defined in
109 * section 4.4.4), or if <target> does not support multiple
110 * samples (ie other than TEXTURE_2D_MULTISAMPLE,
111 * TEXTURE_2D_MULTISAMPLE_ARRAY, or RENDERBUFFER), 0 is
114 const size_t num_samples
=
115 ctx
->Driver
.QuerySamplesForFormat(ctx
, internalformat
, buffer
);
117 /* QuerySamplesForFormat writes some stuff to buffer, so we have to
118 * separately over-write it with the requested value.
120 buffer
[0] = (GLint
) num_samples
;
125 _mesa_error(ctx
, GL_INVALID_ENUM
,
126 "glGetInternalformativ(pname=%s)",
127 _mesa_lookup_enum_by_nr(pname
));
131 if (bufSize
!= 0 && params
== NULL
) {
132 /* Emit a warning to aid application debugging, but go ahead and do the
133 * memcpy (and probably crash) anyway.
136 "glGetInternalformativ(bufSize = %d, but params = NULL)",
140 /* Copy the data from the temporary buffer to the buffer supplied by the
141 * application. Clamp the size of the copy to the size supplied by the
144 memcpy(params
, buffer
, MIN2(count
, bufSize
) * sizeof(GLint
));