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.
26 #include "glformats.h"
28 #include "mfeatures.h"
31 #include "formatquery.h"
34 _mesa_GetInternalformativ(GLenum target
, GLenum internalformat
, GLenum pname
,
35 GLsizei bufSize
, GLint
*params
)
39 GET_CURRENT_CONTEXT(ctx
);
41 ASSERT_OUTSIDE_BEGIN_END(ctx
);
43 if (!ctx
->Extensions
.ARB_internalformat_query
) {
44 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformativ");
48 assert(ctx
->Driver
.QuerySamplesForFormat
!= NULL
);
50 /* The ARB_internalformat_query spec says:
52 * "If the <target> parameter to GetInternalformativ is not one of
53 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY or RENDERBUFFER
54 * then an INVALID_ENUM error is generated."
60 case GL_TEXTURE_2D_MULTISAMPLE
:
61 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
62 /* These enums are only valid if ARB_texture_multisample is supported */
63 if (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
)
67 _mesa_error(ctx
, GL_INVALID_ENUM
,
68 "glGetInternalformativ(target=%s)",
69 _mesa_lookup_enum_by_nr(target
));
73 /* The ARB_internalformat_query spec says:
75 * "If the <internalformat> parameter to GetInternalformativ is not
76 * color-, depth- or stencil-renderable, then an INVALID_ENUM error is
79 if (_mesa_base_fbo_format(ctx
, internalformat
) == 0) {
80 _mesa_error(ctx
, GL_INVALID_ENUM
,
81 "glGetInternalformativ(internalformat=%s)",
82 _mesa_lookup_enum_by_nr(internalformat
));
86 /* The ARB_internalformat_query spec says:
88 * "If the <bufSize> parameter to GetInternalformativ is negative, then
89 * an INVALID_VALUE error is generated."
92 _mesa_error(ctx
, GL_INVALID_VALUE
,
93 "glGetInternalformativ(target=%s)",
94 _mesa_lookup_enum_by_nr(target
));
100 count
= ctx
->Driver
.QuerySamplesForFormat(ctx
, target
,
101 internalformat
, buffer
);
103 case GL_NUM_SAMPLE_COUNTS
: {
104 /* The driver can return 0, and we should pass that along to the
105 * application. The ARB decided that ARB_internalformat_query should
106 * behave as ARB_internalformat_query2 in this situation.
108 * The ARB_internalformat_query2 spec says:
110 * "- NUM_SAMPLE_COUNTS: The number of sample counts that would be
111 * returned by querying SAMPLES is returned in <params>.
112 * * If <internalformat> is not color-renderable,
113 * depth-renderable, or stencil-renderable (as defined in
114 * section 4.4.4), or if <target> does not support multiple
115 * samples (ie other than TEXTURE_2D_MULTISAMPLE,
116 * TEXTURE_2D_MULTISAMPLE_ARRAY, or RENDERBUFFER), 0 is
119 const size_t num_samples
=
120 ctx
->Driver
.QuerySamplesForFormat(ctx
, target
, internalformat
, buffer
);
122 /* QuerySamplesForFormat writes some stuff to buffer, so we have to
123 * separately over-write it with the requested value.
125 buffer
[0] = (GLint
) num_samples
;
130 _mesa_error(ctx
, GL_INVALID_ENUM
,
131 "glGetInternalformativ(pname=%s)",
132 _mesa_lookup_enum_by_nr(pname
));
136 if (bufSize
!= 0 && params
== NULL
) {
137 /* Emit a warning to aid application debugging, but go ahead and do the
138 * memcpy (and probably crash) anyway.
141 "glGetInternalformativ(bufSize = %d, but params = NULL)",
145 /* Copy the data from the temporary buffer to the buffer supplied by the
146 * application. Clamp the size of the copy to the size supplied by the
149 memcpy(params
, buffer
, MIN2(count
, bufSize
) * sizeof(GLint
));