1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
|
/*
* Copyright © 2012 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "mtypes.h"
#include "context.h"
#include "glformats.h"
#include "macros.h"
#include "enums.h"
#include "fbobject.h"
#include "formatquery.h"
#include "teximage.h"
/* Handles the cases where either ARB_internalformat_query or
* ARB_internalformat_query2 have to return an error.
*/
static bool
_legal_parameters(struct gl_context *ctx, GLenum target, GLenum internalformat,
GLenum pname, GLsizei bufSize, GLint *params)
{
bool query2 = _mesa_has_ARB_internalformat_query2(ctx);
/* The ARB_internalformat_query2 spec says:
*
* "The INVALID_ENUM error is generated if the <target> parameter to
* GetInternalformati*v is not one of the targets listed in Table 6.xx.
*/
switch(target){
case GL_TEXTURE_1D:
case GL_TEXTURE_1D_ARRAY:
case GL_TEXTURE_2D:
case GL_TEXTURE_2D_ARRAY:
case GL_TEXTURE_3D:
case GL_TEXTURE_CUBE_MAP:
case GL_TEXTURE_CUBE_MAP_ARRAY:
case GL_TEXTURE_RECTANGLE:
case GL_TEXTURE_BUFFER:
if (!query2) {
/* The ARB_internalformat_query spec says:
*
* "If the <target> parameter to GetInternalformativ is not one of
* TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY
* or RENDERBUFFER then an INVALID_ENUM error is generated.
*/
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetInternalformativ(target=%s)",
_mesa_enum_to_string(target));
return false;
}
break;
case GL_RENDERBUFFER:
break;
case GL_TEXTURE_2D_MULTISAMPLE:
case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
/* The non-existence of ARB_texture_multisample is treated in
* ARB_internalformat_query implementation like an error.
*/
if (!query2 &&
!(_mesa_has_ARB_texture_multisample(ctx) || _mesa_is_gles31(ctx))) {
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetInternalformativ(target=%s)",
_mesa_enum_to_string(target));
return false;
}
break;
default:
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetInternalformativ(target=%s)",
_mesa_enum_to_string(target));
return false;
}
/* The ARB_internalformat_query2 spec says:
*
* "The INVALID_ENUM error is generated if the <pname> parameter is
* not one of the listed possibilities.
*/
switch(pname){
case GL_SAMPLES:
case GL_NUM_SAMPLE_COUNTS:
break;
case GL_SRGB_DECODE_ARB:
/* The ARB_internalformat_query2 spec says:
*
* "If ARB_texture_sRGB_decode or EXT_texture_sRGB_decode or
* equivalent functionality is not supported, queries for the
* SRGB_DECODE_ARB <pname> set the INVALID_ENUM error.
*/
if (!_mesa_has_EXT_texture_sRGB_decode(ctx)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetInternalformativ(pname=%s)",
_mesa_enum_to_string(pname));
return false;
}
/* fallthrough */
case GL_INTERNALFORMAT_SUPPORTED:
case GL_INTERNALFORMAT_PREFERRED:
case GL_INTERNALFORMAT_RED_SIZE:
case GL_INTERNALFORMAT_GREEN_SIZE:
case GL_INTERNALFORMAT_BLUE_SIZE:
case GL_INTERNALFORMAT_ALPHA_SIZE:
case GL_INTERNALFORMAT_DEPTH_SIZE:
case GL_INTERNALFORMAT_STENCIL_SIZE:
case GL_INTERNALFORMAT_SHARED_SIZE:
case GL_INTERNALFORMAT_RED_TYPE:
case GL_INTERNALFORMAT_GREEN_TYPE:
case GL_INTERNALFORMAT_BLUE_TYPE:
case GL_INTERNALFORMAT_ALPHA_TYPE:
case GL_INTERNALFORMAT_DEPTH_TYPE:
case GL_INTERNALFORMAT_STENCIL_TYPE:
case GL_MAX_WIDTH:
case GL_MAX_HEIGHT:
case GL_MAX_DEPTH:
case GL_MAX_LAYERS:
case GL_MAX_COMBINED_DIMENSIONS:
case GL_COLOR_COMPONENTS:
case GL_DEPTH_COMPONENTS:
case GL_STENCIL_COMPONENTS:
case GL_COLOR_RENDERABLE:
case GL_DEPTH_RENDERABLE:
case GL_STENCIL_RENDERABLE:
case GL_FRAMEBUFFER_RENDERABLE:
case GL_FRAMEBUFFER_RENDERABLE_LAYERED:
case GL_FRAMEBUFFER_BLEND:
case GL_READ_PIXELS:
case GL_READ_PIXELS_FORMAT:
case GL_READ_PIXELS_TYPE:
case GL_TEXTURE_IMAGE_FORMAT:
case GL_TEXTURE_IMAGE_TYPE:
case GL_GET_TEXTURE_IMAGE_FORMAT:
case GL_GET_TEXTURE_IMAGE_TYPE:
case GL_MIPMAP:
case GL_MANUAL_GENERATE_MIPMAP:
case GL_AUTO_GENERATE_MIPMAP:
case GL_COLOR_ENCODING:
case GL_SRGB_READ:
case GL_SRGB_WRITE:
case GL_FILTER:
case GL_VERTEX_TEXTURE:
case GL_TESS_CONTROL_TEXTURE:
case GL_TESS_EVALUATION_TEXTURE:
case GL_GEOMETRY_TEXTURE:
case GL_FRAGMENT_TEXTURE:
case GL_COMPUTE_TEXTURE:
case GL_TEXTURE_SHADOW:
case GL_TEXTURE_GATHER:
case GL_TEXTURE_GATHER_SHADOW:
case GL_SHADER_IMAGE_LOAD:
case GL_SHADER_IMAGE_STORE:
case GL_SHADER_IMAGE_ATOMIC:
case GL_IMAGE_TEXEL_SIZE:
case GL_IMAGE_COMPATIBILITY_CLASS:
case GL_IMAGE_PIXEL_FORMAT:
case GL_IMAGE_PIXEL_TYPE:
case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST:
case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST:
case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE:
case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE:
case GL_TEXTURE_COMPRESSED:
case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH:
case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT:
case GL_TEXTURE_COMPRESSED_BLOCK_SIZE:
case GL_CLEAR_BUFFER:
case GL_TEXTURE_VIEW:
case GL_VIEW_COMPATIBILITY_CLASS:
/* The ARB_internalformat_query spec says:
*
* "If the <pname> parameter to GetInternalformativ is not SAMPLES
* or NUM_SAMPLE_COUNTS, then an INVALID_ENUM error is generated."
*/
if (!query2) {
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetInternalformativ(pname=%s)",
_mesa_enum_to_string(pname));
return false;
}
break;
default:
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetInternalformativ(pname=%s)",
_mesa_enum_to_string(pname));
return false;
}
/* The ARB_internalformat_query spec says:
*
* "If the <bufSize> parameter to GetInternalformativ is negative, then
* an INVALID_VALUE error is generated."
*
* Nothing is said in ARB_internalformat_query2 but we assume the same.
*/
if (bufSize < 0) {
_mesa_error(ctx, GL_INVALID_VALUE,
"glGetInternalformativ(target=%s)",
_mesa_enum_to_string(target));
return false;
}
/* The ARB_internalformat_query spec says:
*
* "If the <internalformat> parameter to GetInternalformativ is not
* color-, depth- or stencil-renderable, then an INVALID_ENUM error is
* generated."
*
* Page 243 of the GLES 3.0.4 spec says this for GetInternalformativ:
*
* "internalformat must be color-renderable, depth-renderable or
* stencilrenderable (as defined in section 4.4.4)."
*
* Section 4.4.4 on page 212 of the same spec says:
*
* "An internal format is color-renderable if it is one of the
* formats from table 3.13 noted as color-renderable or if it
* is unsized format RGBA or RGB."
*
* Therefore, we must accept GL_RGB and GL_RGBA here.
*/
if (!query2 &&
internalformat != GL_RGB && internalformat != GL_RGBA &&
_mesa_base_fbo_format(ctx, internalformat) == 0) {
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetInternalformativ(internalformat=%s)",
_mesa_enum_to_string(internalformat));
return false;
}
return true;
}
/* Sets the appropriate "unsupported" response as defined by the
* ARB_internalformat_query2 spec for each each <pname>.
*/
static void
_set_default_response(GLenum pname, GLint buffer[16])
{
/* The ARB_internalformat_query2 defines which is the reponse best
* representing "not supported" or "not applicable" for each <pname>.
*
* " In general:
* - size- or count-based queries will return zero,
* - support-, format- or type-based queries will return NONE,
* - boolean-based queries will return FALSE, and
* - list-based queries return no entries."
*/
switch(pname) {
case GL_SAMPLES:
break;
case GL_MAX_COMBINED_DIMENSIONS:
case GL_NUM_SAMPLE_COUNTS:
case GL_INTERNALFORMAT_RED_SIZE:
case GL_INTERNALFORMAT_GREEN_SIZE:
case GL_INTERNALFORMAT_BLUE_SIZE:
case GL_INTERNALFORMAT_ALPHA_SIZE:
case GL_INTERNALFORMAT_DEPTH_SIZE:
case GL_INTERNALFORMAT_STENCIL_SIZE:
case GL_INTERNALFORMAT_SHARED_SIZE:
case GL_MAX_WIDTH:
case GL_MAX_HEIGHT:
case GL_MAX_DEPTH:
case GL_MAX_LAYERS:
case GL_IMAGE_TEXEL_SIZE:
case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH:
case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT:
case GL_TEXTURE_COMPRESSED_BLOCK_SIZE:
buffer[0] = 0;
break;
case GL_INTERNALFORMAT_PREFERRED:
case GL_INTERNALFORMAT_RED_TYPE:
case GL_INTERNALFORMAT_GREEN_TYPE:
case GL_INTERNALFORMAT_BLUE_TYPE:
case GL_INTERNALFORMAT_ALPHA_TYPE:
case GL_INTERNALFORMAT_DEPTH_TYPE:
case GL_INTERNALFORMAT_STENCIL_TYPE:
case GL_FRAMEBUFFER_RENDERABLE:
case GL_FRAMEBUFFER_RENDERABLE_LAYERED:
case GL_FRAMEBUFFER_BLEND:
case GL_READ_PIXELS:
case GL_READ_PIXELS_FORMAT:
case GL_READ_PIXELS_TYPE:
case GL_TEXTURE_IMAGE_FORMAT:
case GL_TEXTURE_IMAGE_TYPE:
case GL_GET_TEXTURE_IMAGE_FORMAT:
case GL_GET_TEXTURE_IMAGE_TYPE:
case GL_MANUAL_GENERATE_MIPMAP:
case GL_AUTO_GENERATE_MIPMAP:
case GL_COLOR_ENCODING:
case GL_SRGB_READ:
case GL_SRGB_WRITE:
case GL_SRGB_DECODE_ARB:
case GL_FILTER:
case GL_VERTEX_TEXTURE:
case GL_TESS_CONTROL_TEXTURE:
case GL_TESS_EVALUATION_TEXTURE:
case GL_GEOMETRY_TEXTURE:
case GL_FRAGMENT_TEXTURE:
case GL_COMPUTE_TEXTURE:
case GL_TEXTURE_SHADOW:
case GL_TEXTURE_GATHER:
case GL_TEXTURE_GATHER_SHADOW:
case GL_SHADER_IMAGE_LOAD:
case GL_SHADER_IMAGE_STORE:
case GL_SHADER_IMAGE_ATOMIC:
case GL_IMAGE_COMPATIBILITY_CLASS:
case GL_IMAGE_PIXEL_FORMAT:
case GL_IMAGE_PIXEL_TYPE:
case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST:
case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST:
case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE:
case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE:
case GL_CLEAR_BUFFER:
case GL_TEXTURE_VIEW:
case GL_VIEW_COMPATIBILITY_CLASS:
buffer[0] = GL_NONE;
break;
case GL_INTERNALFORMAT_SUPPORTED:
case GL_COLOR_COMPONENTS:
case GL_DEPTH_COMPONENTS:
case GL_STENCIL_COMPONENTS:
case GL_COLOR_RENDERABLE:
case GL_DEPTH_RENDERABLE:
case GL_STENCIL_RENDERABLE:
case GL_MIPMAP:
case GL_TEXTURE_COMPRESSED:
buffer[0] = GL_FALSE;
break;
default:
unreachable("invalid 'pname'");
}
}
static bool
_is_target_supported(struct gl_context *ctx, GLenum target)
{
/* The ARB_internalformat_query2 spec says:
*
* "if a particular type of <target> is not supported by the
* implementation the "unsupported" answer should be given.
* This is not an error."
*/
switch(target){
case GL_TEXTURE_2D:
case GL_TEXTURE_3D:
break;
case GL_TEXTURE_1D:
if (!_mesa_is_desktop_gl(ctx))
return false;
break;
case GL_TEXTURE_1D_ARRAY:
if (!_mesa_has_EXT_texture_array(ctx))
return false;
break;
case GL_TEXTURE_2D_ARRAY:
if (!(_mesa_has_EXT_texture_array(ctx) || _mesa_is_gles3(ctx)))
return false;
break;
case GL_TEXTURE_CUBE_MAP:
if (!_mesa_has_ARB_texture_cube_map(ctx))
return false;
break;
case GL_TEXTURE_CUBE_MAP_ARRAY:
if (!_mesa_has_ARB_texture_cube_map_array(ctx))
return false;
break;
case GL_TEXTURE_RECTANGLE:
if (!_mesa_has_NV_texture_rectangle(ctx))
return false;
break;
case GL_TEXTURE_BUFFER:
if (!_mesa_has_ARB_texture_buffer_object(ctx))
return false;
break;
case GL_RENDERBUFFER:
if (!(_mesa_has_ARB_framebuffer_object(ctx) ||
_mesa_is_gles3(ctx)))
return false;
break;
case GL_TEXTURE_2D_MULTISAMPLE:
case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
if (!(_mesa_has_ARB_texture_multisample(ctx) ||
_mesa_is_gles31(ctx)))
return false;
break;
default:
unreachable("invalid target");
}
return true;
}
/* default implementation of QueryInternalFormat driverfunc, for
* drivers not implementing ARB_internalformat_query2.
*/
void
_mesa_query_internal_format_default(struct gl_context *ctx, GLenum target,
GLenum internalFormat, GLenum pname,
GLint *params)
{
(void) ctx;
(void) target;
(void) internalFormat;
switch (pname) {
case GL_SAMPLES:
case GL_NUM_SAMPLE_COUNTS:
params[0] = 1;
break;
default:
/* @TODO: handle default values for all the different pnames. */
break;
}
}
void GLAPIENTRY
_mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
GLsizei bufSize, GLint *params)
{
GLint buffer[16];
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (!ctx->Extensions.ARB_internalformat_query) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetInternalformativ");
return;
}
assert(ctx->Driver.QueryInternalFormat != NULL);
/* The ARB_internalformat_query spec says:
*
* "If the <target> parameter to GetInternalformativ is not one of
* TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY or RENDERBUFFER
* then an INVALID_ENUM error is generated."
*/
switch (target) {
case GL_RENDERBUFFER:
break;
case GL_TEXTURE_2D_MULTISAMPLE:
case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
/* These enums are only valid if ARB_texture_multisample is supported */
if ((_mesa_is_desktop_gl(ctx) &&
ctx->Extensions.ARB_texture_multisample) ||
_mesa_is_gles31(ctx))
break;
default:
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetInternalformativ(target=%s)",
_mesa_enum_to_string(target));
return;
}
/* The ARB_internalformat_query spec says:
*
* "If the <internalformat> parameter to GetInternalformativ is not
* color-, depth- or stencil-renderable, then an INVALID_ENUM error is
* generated."
*
* Page 243 of the GLES 3.0.4 spec says this for GetInternalformativ:
*
* "internalformat must be color-renderable, depth-renderable or
* stencilrenderable (as defined in section 4.4.4)."
*
* Section 4.4.4 on page 212 of the same spec says:
*
* "An internal format is color-renderable if it is one of the
* formats from table 3.13 noted as color-renderable or if it
* is unsized format RGBA or RGB."
*
* Therefore, we must accept GL_RGB and GL_RGBA here.
*/
if (internalformat != GL_RGB && internalformat != GL_RGBA &&
_mesa_base_fbo_format(ctx, internalformat) == 0) {
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetInternalformativ(internalformat=%s)",
_mesa_enum_to_string(internalformat));
return;
}
/* The ARB_internalformat_query spec says:
*
* "If the <bufSize> parameter to GetInternalformativ is negative, then
* an INVALID_VALUE error is generated."
*/
if (bufSize < 0) {
_mesa_error(ctx, GL_INVALID_VALUE,
"glGetInternalformativ(target=%s)",
_mesa_enum_to_string(target));
return;
}
/* initialize the contents of the temporary buffer */
memcpy(buffer, params, MIN2(bufSize, 16) * sizeof(GLint));
switch (pname) {
case GL_SAMPLES:
ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
buffer);
break;
case GL_NUM_SAMPLE_COUNTS: {
if ((ctx->API == API_OPENGLES2 && ctx->Version == 30) &&
_mesa_is_enum_format_integer(internalformat)) {
/* From GL ES 3.0 specification, section 6.1.15 page 236: "Since
* multisampling is not supported for signed and unsigned integer
* internal formats, the value of NUM_SAMPLE_COUNTS will be zero
* for such formats.
*
* Such a restriction no longer exists in GL ES 3.1.
*/
buffer[0] = 0;
} else {
ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
buffer);
}
break;
}
default:
_mesa_error(ctx, GL_INVALID_ENUM,
"glGetInternalformativ(pname=%s)",
_mesa_enum_to_string(pname));
return;
}
if (bufSize != 0 && params == NULL) {
/* Emit a warning to aid application debugging, but go ahead and do the
* memcpy (and probably crash) anyway.
*/
_mesa_warning(ctx,
"glGetInternalformativ(bufSize = %d, but params = NULL)",
bufSize);
}
/* Copy the data from the temporary buffer to the buffer supplied by the
* application. Clamp the size of the copy to the size supplied by the
* application.
*/
memcpy(params, buffer, MIN2(bufSize, 16) * sizeof(GLint));
return;
}
|