blob: 309c4daedb767020b5f1765a67f6df4633d91b54 [file] [log] [blame]
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001#include "precompiled.h"
2//
Geoff Langcec35902014-04-16 10:52:36 -04003// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
Geoff Lange8ebe7f2013-08-05 15:03:13 -04004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// validationES.h: Validation functions for generic OpenGL ES entry point parameters
9
10#include "libGLESv2/validationES.h"
Jamie Madill26e91952014-03-05 15:01:27 -050011#include "libGLESv2/validationES2.h"
12#include "libGLESv2/validationES3.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040013#include "libGLESv2/Context.h"
14#include "libGLESv2/Texture.h"
15#include "libGLESv2/Framebuffer.h"
Jamie Madille261b442014-06-25 12:42:21 -040016#include "libGLESv2/FramebufferAttachment.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040017#include "libGLESv2/formatutils.h"
18#include "libGLESv2/main.h"
Jamie Madilldb2f14c2014-05-13 13:56:30 -040019#include "libGLESv2/Query.h"
Jamie Madill36398922014-05-20 14:51:53 -040020#include "libGLESv2/ProgramBinary.h"
Jamie Madill250d33f2014-06-06 17:09:03 -040021#include "libGLESv2/TransformFeedback.h"
Jamie Madilld4cfa572014-07-08 10:00:32 -040022#include "libGLESv2/VertexArray.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040023
24#include "common/mathutil.h"
25#include "common/utilities.h"
26
27namespace gl
28{
29
Geoff Lang0550d032014-01-30 11:29:07 -050030bool ValidCap(const Context *context, GLenum cap)
31{
32 switch (cap)
33 {
34 case GL_CULL_FACE:
35 case GL_POLYGON_OFFSET_FILL:
36 case GL_SAMPLE_ALPHA_TO_COVERAGE:
37 case GL_SAMPLE_COVERAGE:
38 case GL_SCISSOR_TEST:
39 case GL_STENCIL_TEST:
40 case GL_DEPTH_TEST:
41 case GL_BLEND:
42 case GL_DITHER:
43 return true;
44 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
45 case GL_RASTERIZER_DISCARD:
46 return (context->getClientVersion() >= 3);
47 default:
48 return false;
49 }
50}
51
Jamie Madill1fc7e2c2014-01-21 16:47:10 -050052bool ValidTextureTarget(const Context *context, GLenum target)
Jamie Madill35d15012013-10-07 10:46:37 -040053{
Jamie Madilld7460c72014-01-21 16:38:14 -050054 switch (target)
Jamie Madill35d15012013-10-07 10:46:37 -040055 {
Jamie Madilld7460c72014-01-21 16:38:14 -050056 case GL_TEXTURE_2D:
57 case GL_TEXTURE_CUBE_MAP:
58 return true;
Jamie Madill35d15012013-10-07 10:46:37 -040059
Jamie Madilld7460c72014-01-21 16:38:14 -050060 case GL_TEXTURE_3D:
61 case GL_TEXTURE_2D_ARRAY:
62 return (context->getClientVersion() >= 3);
63
64 default:
65 return false;
66 }
Jamie Madill35d15012013-10-07 10:46:37 -040067}
68
Shannon Woods4dfed832014-03-17 20:03:39 -040069// This function differs from ValidTextureTarget in that the target must be
70// usable as the destination of a 2D operation-- so a cube face is valid, but
71// GL_TEXTURE_CUBE_MAP is not.
Jamie Madill560a8d82014-05-21 13:06:20 -040072// Note: duplicate of IsInternalTextureTarget
Shannon Woods4dfed832014-03-17 20:03:39 -040073bool ValidTexture2DDestinationTarget(const Context *context, GLenum target)
74{
75 switch (target)
76 {
77 case GL_TEXTURE_2D:
78 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
79 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
80 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
81 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
82 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
83 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
84 return true;
85 case GL_TEXTURE_2D_ARRAY:
86 case GL_TEXTURE_3D:
87 return (context->getClientVersion() >= 3);
88 default:
89 return false;
90 }
91}
92
Jamie Madill1fc7e2c2014-01-21 16:47:10 -050093bool ValidFramebufferTarget(GLenum target)
94{
95 META_ASSERT(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER);
96
97 switch (target)
98 {
99 case GL_FRAMEBUFFER: return true;
100 case GL_READ_FRAMEBUFFER: return true;
101 case GL_DRAW_FRAMEBUFFER: return true;
102 default: return false;
103 }
104}
105
Jamie Madill8c96d582014-03-05 15:01:23 -0500106bool ValidBufferTarget(const Context *context, GLenum target)
107{
108 switch (target)
109 {
110 case GL_ARRAY_BUFFER:
111 case GL_ELEMENT_ARRAY_BUFFER:
112 return true;
113
Jamie Madill8c96d582014-03-05 15:01:23 -0500114 case GL_PIXEL_PACK_BUFFER:
115 case GL_PIXEL_UNPACK_BUFFER:
Geoff Langc0b9ef42014-07-02 10:02:37 -0400116 return context->getExtensions().pixelBufferObject;
Shannon Woods158c4382014-05-06 13:00:07 -0400117
Shannon Woodsb3801742014-03-27 14:59:19 -0400118 case GL_COPY_READ_BUFFER:
119 case GL_COPY_WRITE_BUFFER:
Jamie Madill8c96d582014-03-05 15:01:23 -0500120 case GL_TRANSFORM_FEEDBACK_BUFFER:
121 case GL_UNIFORM_BUFFER:
122 return (context->getClientVersion() >= 3);
123
124 default:
125 return false;
126 }
127}
128
Jamie Madill70656a62014-03-05 15:01:26 -0500129bool ValidBufferParameter(const Context *context, GLenum pname)
130{
131 switch (pname)
132 {
133 case GL_BUFFER_USAGE:
134 case GL_BUFFER_SIZE:
135 return true;
136
137 // GL_BUFFER_MAP_POINTER is a special case, and may only be
138 // queried with GetBufferPointerv
139 case GL_BUFFER_ACCESS_FLAGS:
140 case GL_BUFFER_MAPPED:
141 case GL_BUFFER_MAP_OFFSET:
142 case GL_BUFFER_MAP_LENGTH:
143 return (context->getClientVersion() >= 3);
144
145 default:
146 return false;
147 }
148}
149
Jamie Madill8c96d582014-03-05 15:01:23 -0500150bool ValidMipLevel(const Context *context, GLenum target, GLint level)
Geoff Langce635692013-09-24 13:56:32 -0400151{
Geoff Langaae65a42014-05-26 12:43:44 -0400152 size_t maxDimension = 0;
Geoff Langce635692013-09-24 13:56:32 -0400153 switch (target)
154 {
Geoff Langaae65a42014-05-26 12:43:44 -0400155 case GL_TEXTURE_2D: maxDimension = context->getCaps().max2DTextureSize; break;
Geoff Langce635692013-09-24 13:56:32 -0400156 case GL_TEXTURE_CUBE_MAP:
157 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
158 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
159 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
160 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
161 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
Geoff Langaae65a42014-05-26 12:43:44 -0400162 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: maxDimension = context->getCaps().maxCubeMapTextureSize; break;
163 case GL_TEXTURE_3D: maxDimension = context->getCaps().max3DTextureSize; break;
164 case GL_TEXTURE_2D_ARRAY: maxDimension = context->getCaps().max2DTextureSize; break;
Geoff Langce635692013-09-24 13:56:32 -0400165 default: UNREACHABLE();
166 }
167
Geoff Langaae65a42014-05-26 12:43:44 -0400168 return level <= gl::log2(maxDimension);
Geoff Langce635692013-09-24 13:56:32 -0400169}
170
Jamie Madill4fd75c12014-06-23 10:53:54 -0400171bool ValidImageSize(const gl::Context *context, GLenum target, GLint level,
172 GLsizei width, GLsizei height, GLsizei depth)
Geoff Langce635692013-09-24 13:56:32 -0400173{
174 if (level < 0 || width < 0 || height < 0 || depth < 0)
175 {
176 return false;
177 }
178
Geoff Langc0b9ef42014-07-02 10:02:37 -0400179 if (!context->getExtensions().textureNPOT &&
Jamie Madill4fd75c12014-06-23 10:53:54 -0400180 (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth))))
Geoff Langce635692013-09-24 13:56:32 -0400181 {
182 return false;
183 }
184
185 if (!ValidMipLevel(context, target, level))
186 {
187 return false;
188 }
189
190 return true;
191}
192
Geoff Lang005df412013-10-16 14:12:50 -0400193bool ValidCompressedImageSize(const gl::Context *context, GLenum internalFormat, GLsizei width, GLsizei height)
Geoff Langd4f180b2013-09-24 13:57:44 -0400194{
Geoff Lange4a492b2014-06-19 14:14:41 -0400195 if (!IsFormatCompressed(internalFormat))
Geoff Langd4f180b2013-09-24 13:57:44 -0400196 {
197 return false;
198 }
199
Geoff Lange4a492b2014-06-19 14:14:41 -0400200 GLint blockWidth = GetCompressedBlockWidth(internalFormat);
201 GLint blockHeight = GetCompressedBlockHeight(internalFormat);
Geoff Langd4f180b2013-09-24 13:57:44 -0400202 if (width < 0 || (width > blockWidth && width % blockWidth != 0) ||
203 height < 0 || (height > blockHeight && height % blockHeight != 0))
204 {
205 return false;
206 }
207
208 return true;
209}
210
Geoff Lang37dde692014-01-31 16:34:54 -0500211bool ValidQueryType(const Context *context, GLenum queryType)
212{
213 META_ASSERT(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT);
214 META_ASSERT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT);
215
216 switch (queryType)
217 {
218 case GL_ANY_SAMPLES_PASSED:
219 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
220 return true;
221 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
222 return (context->getClientVersion() >= 3);
223 default:
224 return false;
225 }
226}
227
Geoff Lang48dcae72014-02-05 16:28:24 -0500228bool ValidProgram(const Context *context, GLuint id)
229{
230 // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will generate the
231 // error INVALID_VALUE if the provided name is not the name of either a shader or program object and
232 // INVALID_OPERATION if the provided name identifies an object that is not the expected type."
233
234 if (context->getProgram(id) != NULL)
235 {
236 return true;
237 }
238 else if (context->getShader(id) != NULL)
239 {
240 // ID is the wrong type
241 return gl::error(GL_INVALID_OPERATION, false);
242 }
243 else
244 {
245 // No shader/program object has this ID
246 return gl::error(GL_INVALID_VALUE, false);
247 }
248}
249
Jamie Madillb4472272014-07-03 10:38:55 -0400250bool ValidateAttachmentTarget(const gl::Context *context, GLenum attachment)
251{
252 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
253 {
254 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
255
Geoff Langaae65a42014-05-26 12:43:44 -0400256 if (colorAttachment >= context->getCaps().maxColorAttachments)
Jamie Madillb4472272014-07-03 10:38:55 -0400257 {
258 return gl::error(GL_INVALID_VALUE, false);
259 }
260 }
261 else
262 {
263 switch (attachment)
264 {
265 case GL_DEPTH_ATTACHMENT:
266 case GL_STENCIL_ATTACHMENT:
267 break;
268
269 case GL_DEPTH_STENCIL_ATTACHMENT:
270 if (context->getClientVersion() < 3)
271 {
272 return gl::error(GL_INVALID_ENUM, false);
273 }
274 break;
275
276 default:
277 return gl::error(GL_INVALID_ENUM, false);
278 }
279 }
280
281 return true;
282}
283
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400284bool ValidateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400285 GLenum internalformat, GLsizei width, GLsizei height,
286 bool angleExtension)
287{
288 switch (target)
289 {
290 case GL_RENDERBUFFER:
291 break;
292 default:
293 return gl::error(GL_INVALID_ENUM, false);
294 }
295
296 if (width < 0 || height < 0 || samples < 0)
297 {
298 return gl::error(GL_INVALID_VALUE, false);
299 }
300
Geoff Langc0b9ef42014-07-02 10:02:37 -0400301 if (!gl::IsValidInternalFormat(internalformat, context->getExtensions(), context->getClientVersion()))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400302 {
303 return gl::error(GL_INVALID_ENUM, false);
304 }
305
306 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
307 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
308 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
309 // internal format must be sized and not an integer format if samples is greater than zero.
Geoff Lange4a492b2014-06-19 14:14:41 -0400310 if (!gl::IsSizedInternalFormat(internalformat))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400311 {
312 return gl::error(GL_INVALID_ENUM, false);
313 }
314
Geoff Lange4a492b2014-06-19 14:14:41 -0400315 GLenum componentType = gl::GetComponentType(internalformat);
Geoff Langb2f3d052013-08-13 12:49:27 -0400316 if ((componentType == GL_UNSIGNED_INT || componentType == GL_INT) && samples > 0)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400317 {
318 return gl::error(GL_INVALID_OPERATION, false);
319 }
320
Geoff Langc0b9ef42014-07-02 10:02:37 -0400321 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
Geoff Lang6cf8e1b2014-07-03 13:03:57 -0400322 if (!formatCaps.renderable)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400323 {
324 return gl::error(GL_INVALID_ENUM, false);
325 }
326
Geoff Langaae65a42014-05-26 12:43:44 -0400327 if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400328 {
329 return gl::error(GL_INVALID_VALUE, false);
330 }
331
332 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
333 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
334 // states that samples must be less than or equal to the maximum samples for the specified
335 // internal format.
336 if (angleExtension)
337 {
338 if (samples > context->getMaxSupportedSamples())
339 {
340 return gl::error(GL_INVALID_VALUE, false);
341 }
342 }
343 else
344 {
345 if (samples > context->getMaxSupportedFormatSamples(internalformat))
346 {
347 return gl::error(GL_INVALID_VALUE, false);
348 }
349 }
350
Shannon Woods53a94a82014-06-24 15:20:36 -0400351 GLuint handle = context->getState().getRenderbufferId();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400352 if (handle == 0)
353 {
354 return gl::error(GL_INVALID_OPERATION, false);
355 }
356
357 return true;
358}
359
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500360bool ValidateFramebufferRenderbufferParameters(gl::Context *context, GLenum target, GLenum attachment,
361 GLenum renderbuffertarget, GLuint renderbuffer)
362{
Shannon Woods1da3cf62014-06-27 15:32:23 -0400363 if (!ValidFramebufferTarget(target))
364 {
365 return gl::error(GL_INVALID_ENUM, false);
366 }
367
Shannon Woods53a94a82014-06-24 15:20:36 -0400368 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
369 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500370
371 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
372 {
373 return gl::error(GL_INVALID_OPERATION, false);
374 }
375
Jamie Madillb4472272014-07-03 10:38:55 -0400376 if (!ValidateAttachmentTarget(context, attachment))
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500377 {
Jamie Madillb4472272014-07-03 10:38:55 -0400378 return false;
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500379 }
380
Jamie Madillab9d82c2014-01-21 16:38:14 -0500381 // [OpenGL ES 2.0.25] Section 4.4.3 page 112
382 // [OpenGL ES 3.0.2] Section 4.4.2 page 201
383 // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of
384 // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated.
385 if (renderbuffer != 0)
386 {
387 if (!context->getRenderbuffer(renderbuffer))
388 {
389 return gl::error(GL_INVALID_OPERATION, false);
390 }
391 }
392
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500393 return true;
394}
395
Jamie Madill3c7fa222014-06-05 13:08:51 -0400396static bool IsPartialBlit(gl::Context *context, gl::FramebufferAttachment *readBuffer, gl::FramebufferAttachment *writeBuffer,
Geoff Lang125deab2013-08-09 13:34:16 -0400397 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
398 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1)
399{
400 if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 ||
401 dstX1 != writeBuffer->getWidth() || dstY1 != writeBuffer->getHeight() ||
402 srcX1 != readBuffer->getWidth() || srcY1 != readBuffer->getHeight())
403 {
404 return true;
405 }
Shannon Woods53a94a82014-06-24 15:20:36 -0400406 else if (context->getState().isScissorTestEnabled())
Geoff Lang125deab2013-08-09 13:34:16 -0400407 {
Shannon Woods53a94a82014-06-24 15:20:36 -0400408 const Rectangle &scissor = context->getState().getScissor();
Geoff Lang125deab2013-08-09 13:34:16 -0400409
Shannon Woods53a94a82014-06-24 15:20:36 -0400410 return scissor.x > 0 || scissor.y > 0 ||
411 scissor.width < writeBuffer->getWidth() ||
412 scissor.height < writeBuffer->getHeight();
Geoff Lang125deab2013-08-09 13:34:16 -0400413 }
414 else
415 {
416 return false;
417 }
418}
419
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400420bool ValidateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400421 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
422 GLenum filter, bool fromAngleExtension)
423{
424 switch (filter)
425 {
426 case GL_NEAREST:
427 break;
428 case GL_LINEAR:
429 if (fromAngleExtension)
430 {
431 return gl::error(GL_INVALID_ENUM, false);
432 }
433 break;
434 default:
435 return gl::error(GL_INVALID_ENUM, false);
436 }
437
438 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
439 {
440 return gl::error(GL_INVALID_VALUE, false);
441 }
442
443 if (mask == 0)
444 {
445 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
446 // buffers are copied.
447 return false;
448 }
449
450 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
451 {
452 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
453 return gl::error(GL_INVALID_OPERATION, false);
454 }
455
456 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
457 // color buffer, leaving only nearest being unfiltered from above
458 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
459 {
460 return gl::error(GL_INVALID_OPERATION, false);
461 }
462
Shannon Woods53a94a82014-06-24 15:20:36 -0400463 if (context->getState().getReadFramebuffer()->id() == context->getState().getDrawFramebuffer()->id())
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400464 {
465 if (fromAngleExtension)
466 {
467 ERR("Blits with the same source and destination framebuffer are not supported by this "
468 "implementation.");
469 }
470 return gl::error(GL_INVALID_OPERATION, false);
471 }
472
Shannon Woods53a94a82014-06-24 15:20:36 -0400473 gl::Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
474 gl::Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400475 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
476 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
477 {
478 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
479 }
480
481 if (drawFramebuffer->getSamples() != 0)
482 {
483 return gl::error(GL_INVALID_OPERATION, false);
484 }
485
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400486 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
487
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400488 if (mask & GL_COLOR_BUFFER_BIT)
489 {
Jamie Madill3c7fa222014-06-05 13:08:51 -0400490 gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer();
491 gl::FramebufferAttachment *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400492
493 if (readColorBuffer && drawColorBuffer)
494 {
Geoff Lang005df412013-10-16 14:12:50 -0400495 GLenum readInternalFormat = readColorBuffer->getActualFormat();
Geoff Lange4a492b2014-06-19 14:14:41 -0400496 GLenum readComponentType = gl::GetComponentType(readInternalFormat);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400497
498 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
499 {
500 if (drawFramebuffer->isEnabledColorAttachment(i))
501 {
Geoff Lang005df412013-10-16 14:12:50 -0400502 GLenum drawInternalFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
Geoff Lange4a492b2014-06-19 14:14:41 -0400503 GLenum drawComponentType = gl::GetComponentType(drawInternalFormat);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400504
Geoff Langb2f3d052013-08-13 12:49:27 -0400505 // The GL ES 3.0.2 spec (pg 193) states that:
506 // 1) If the read buffer is fixed point format, the draw buffer must be as well
507 // 2) If the read buffer is an unsigned integer format, the draw buffer must be as well
508 // 3) If the read buffer is a signed integer format, the draw buffer must be as well
509 if ( (readComponentType == GL_UNSIGNED_NORMALIZED || readComponentType == GL_SIGNED_NORMALIZED) &&
510 !(drawComponentType == GL_UNSIGNED_NORMALIZED || drawComponentType == GL_SIGNED_NORMALIZED))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400511 {
512 return gl::error(GL_INVALID_OPERATION, false);
513 }
514
Geoff Langb2f3d052013-08-13 12:49:27 -0400515 if (readComponentType == GL_UNSIGNED_INT && drawComponentType != GL_UNSIGNED_INT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400516 {
517 return gl::error(GL_INVALID_OPERATION, false);
518 }
519
Geoff Langb2f3d052013-08-13 12:49:27 -0400520 if (readComponentType == GL_INT && drawComponentType != GL_INT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400521 {
522 return gl::error(GL_INVALID_OPERATION, false);
523 }
524
Geoff Langb2f3d052013-08-13 12:49:27 -0400525 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawInternalFormat || !sameBounds))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400526 {
527 return gl::error(GL_INVALID_OPERATION, false);
528 }
529 }
530 }
531
Geoff Langb2f3d052013-08-13 12:49:27 -0400532 if ((readComponentType == GL_INT || readComponentType == GL_UNSIGNED_INT) && filter == GL_LINEAR)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400533 {
534 return gl::error(GL_INVALID_OPERATION, false);
535 }
536
537 if (fromAngleExtension)
538 {
539 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
540 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
541 {
542 return gl::error(GL_INVALID_OPERATION, false);
543 }
544
545 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
546 {
547 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
548 {
Jamie Madille92a3542014-07-03 10:38:58 -0400549 FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(colorAttachment);
550 ASSERT(attachment);
551
552 if (attachment->type() != GL_TEXTURE_2D && attachment->type() != GL_RENDERBUFFER)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400553 {
554 return gl::error(GL_INVALID_OPERATION, false);
555 }
556
Jamie Madille92a3542014-07-03 10:38:58 -0400557 if (attachment->getActualFormat() != readColorBuffer->getActualFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400558 {
559 return gl::error(GL_INVALID_OPERATION, false);
560 }
561 }
562 }
Geoff Lang125deab2013-08-09 13:34:16 -0400563 if (readFramebuffer->getSamples() != 0 && IsPartialBlit(context, readColorBuffer, drawColorBuffer,
564 srcX0, srcY0, srcX1, srcY1,
565 dstX0, dstY0, dstX1, dstY1))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400566 {
567 return gl::error(GL_INVALID_OPERATION, false);
568 }
569 }
570 }
571 }
572
573 if (mask & GL_DEPTH_BUFFER_BIT)
574 {
Jamie Madill3c7fa222014-06-05 13:08:51 -0400575 gl::FramebufferAttachment *readDepthBuffer = readFramebuffer->getDepthbuffer();
576 gl::FramebufferAttachment *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400577
578 if (readDepthBuffer && drawDepthBuffer)
579 {
580 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
581 {
582 return gl::error(GL_INVALID_OPERATION, false);
583 }
584
585 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
586 {
587 return gl::error(GL_INVALID_OPERATION, false);
588 }
589
590 if (fromAngleExtension)
591 {
Geoff Lang125deab2013-08-09 13:34:16 -0400592 if (IsPartialBlit(context, readDepthBuffer, drawDepthBuffer,
593 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400594 {
595 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
596 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
597 }
598
599 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
600 {
601 return gl::error(GL_INVALID_OPERATION, false);
602 }
603 }
604 }
605 }
606
607 if (mask & GL_STENCIL_BUFFER_BIT)
608 {
Jamie Madill3c7fa222014-06-05 13:08:51 -0400609 gl::FramebufferAttachment *readStencilBuffer = readFramebuffer->getStencilbuffer();
610 gl::FramebufferAttachment *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400611
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400612 if (readStencilBuffer && drawStencilBuffer)
613 {
614 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
615 {
616 return gl::error(GL_INVALID_OPERATION, false);
617 }
618
619 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
620 {
621 return gl::error(GL_INVALID_OPERATION, false);
622 }
623
624 if (fromAngleExtension)
625 {
Geoff Lang125deab2013-08-09 13:34:16 -0400626 if (IsPartialBlit(context, readStencilBuffer, drawStencilBuffer,
627 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400628 {
629 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
630 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
631 }
632
633 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
634 {
635 return gl::error(GL_INVALID_OPERATION, false);
636 }
637 }
638 }
639 }
640
641 return true;
642}
643
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400644bool ValidateGetVertexAttribParameters(GLenum pname, int clientVersion)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400645{
646 switch (pname)
647 {
648 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
649 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
650 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
651 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
652 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
653 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
654 case GL_CURRENT_VERTEX_ATTRIB:
655 return true;
656
657 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
658 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
659 // the same constant.
660 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
661 return true;
662
663 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
664 return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false));
665
666 default:
667 return gl::error(GL_INVALID_ENUM, false);
668 }
669}
670
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400671bool ValidateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400672{
673 switch (pname)
674 {
675 case GL_TEXTURE_WRAP_R:
676 case GL_TEXTURE_SWIZZLE_R:
677 case GL_TEXTURE_SWIZZLE_G:
678 case GL_TEXTURE_SWIZZLE_B:
679 case GL_TEXTURE_SWIZZLE_A:
680 case GL_TEXTURE_BASE_LEVEL:
681 case GL_TEXTURE_MAX_LEVEL:
682 case GL_TEXTURE_COMPARE_MODE:
683 case GL_TEXTURE_COMPARE_FUNC:
684 case GL_TEXTURE_MIN_LOD:
685 case GL_TEXTURE_MAX_LOD:
686 if (context->getClientVersion() < 3)
687 {
688 return gl::error(GL_INVALID_ENUM, false);
689 }
690 break;
691
692 default: break;
693 }
694
695 switch (pname)
696 {
697 case GL_TEXTURE_WRAP_S:
698 case GL_TEXTURE_WRAP_T:
699 case GL_TEXTURE_WRAP_R:
700 switch (param)
701 {
702 case GL_REPEAT:
703 case GL_CLAMP_TO_EDGE:
704 case GL_MIRRORED_REPEAT:
705 return true;
706 default:
707 return gl::error(GL_INVALID_ENUM, false);
708 }
709
710 case GL_TEXTURE_MIN_FILTER:
711 switch (param)
712 {
713 case GL_NEAREST:
714 case GL_LINEAR:
715 case GL_NEAREST_MIPMAP_NEAREST:
716 case GL_LINEAR_MIPMAP_NEAREST:
717 case GL_NEAREST_MIPMAP_LINEAR:
718 case GL_LINEAR_MIPMAP_LINEAR:
719 return true;
720 default:
721 return gl::error(GL_INVALID_ENUM, false);
722 }
723 break;
724
725 case GL_TEXTURE_MAG_FILTER:
726 switch (param)
727 {
728 case GL_NEAREST:
729 case GL_LINEAR:
730 return true;
731 default:
732 return gl::error(GL_INVALID_ENUM, false);
733 }
734 break;
735
736 case GL_TEXTURE_USAGE_ANGLE:
737 switch (param)
738 {
739 case GL_NONE:
740 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
741 return true;
742 default:
743 return gl::error(GL_INVALID_ENUM, false);
744 }
745 break;
746
747 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
Geoff Langc0b9ef42014-07-02 10:02:37 -0400748 if (!context->getExtensions().textureFilterAnisotropic)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400749 {
750 return gl::error(GL_INVALID_ENUM, false);
751 }
752
753 // we assume the parameter passed to this validation method is truncated, not rounded
754 if (param < 1)
755 {
756 return gl::error(GL_INVALID_VALUE, false);
757 }
758 return true;
759
760 case GL_TEXTURE_MIN_LOD:
761 case GL_TEXTURE_MAX_LOD:
762 // any value is permissible
763 return true;
764
765 case GL_TEXTURE_COMPARE_MODE:
Geoff Lang63b5f1f2013-09-23 14:52:14 -0400766 // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400767 switch (param)
768 {
769 case GL_NONE:
770 case GL_COMPARE_REF_TO_TEXTURE:
771 return true;
772 default:
773 return gl::error(GL_INVALID_ENUM, false);
774 }
775 break;
776
777 case GL_TEXTURE_COMPARE_FUNC:
Geoff Lang63b5f1f2013-09-23 14:52:14 -0400778 // Acceptable function parameters from GLES 3.0.2 spec, table 3.17
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400779 switch (param)
780 {
781 case GL_LEQUAL:
782 case GL_GEQUAL:
783 case GL_LESS:
784 case GL_GREATER:
785 case GL_EQUAL:
786 case GL_NOTEQUAL:
787 case GL_ALWAYS:
788 case GL_NEVER:
789 return true;
790 default:
791 return gl::error(GL_INVALID_ENUM, false);
792 }
793 break;
794
795 case GL_TEXTURE_SWIZZLE_R:
796 case GL_TEXTURE_SWIZZLE_G:
797 case GL_TEXTURE_SWIZZLE_B:
798 case GL_TEXTURE_SWIZZLE_A:
Geoff Langbc90a482013-09-17 16:51:27 -0400799 switch (param)
800 {
801 case GL_RED:
802 case GL_GREEN:
803 case GL_BLUE:
804 case GL_ALPHA:
805 case GL_ZERO:
806 case GL_ONE:
807 return true;
808 default:
809 return gl::error(GL_INVALID_ENUM, false);
810 }
811 break;
812
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400813 case GL_TEXTURE_BASE_LEVEL:
814 case GL_TEXTURE_MAX_LEVEL:
Nicolas Capens8de68282014-04-04 11:10:27 -0400815 if (param < 0)
816 {
817 return gl::error(GL_INVALID_VALUE, false);
818 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400819 return true;
820
821 default:
822 return gl::error(GL_INVALID_ENUM, false);
823 }
824}
825
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400826bool ValidateSamplerObjectParameter(GLenum pname)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400827{
828 switch (pname)
829 {
830 case GL_TEXTURE_MIN_FILTER:
831 case GL_TEXTURE_MAG_FILTER:
832 case GL_TEXTURE_WRAP_S:
833 case GL_TEXTURE_WRAP_T:
834 case GL_TEXTURE_WRAP_R:
835 case GL_TEXTURE_MIN_LOD:
836 case GL_TEXTURE_MAX_LOD:
837 case GL_TEXTURE_COMPARE_MODE:
838 case GL_TEXTURE_COMPARE_FUNC:
839 return true;
840
841 default:
842 return gl::error(GL_INVALID_ENUM, false);
843 }
844}
845
Jamie Madill26e91952014-03-05 15:01:27 -0500846bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsizei width, GLsizei height,
847 GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels)
848{
Shannon Woods53a94a82014-06-24 15:20:36 -0400849 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madill893ab082014-05-16 16:56:10 -0400850 ASSERT(framebuffer);
Jamie Madill26e91952014-03-05 15:01:27 -0500851
852 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
853 {
854 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
855 }
856
Shannon Woods53a94a82014-06-24 15:20:36 -0400857 if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
Jamie Madill26e91952014-03-05 15:01:27 -0500858 {
859 return gl::error(GL_INVALID_OPERATION, false);
860 }
861
Jamie Madill893ab082014-05-16 16:56:10 -0400862 if (!framebuffer->getReadColorbuffer())
863 {
864 return gl::error(GL_INVALID_OPERATION, false);
865 }
866
Jamie Madill26e91952014-03-05 15:01:27 -0500867 GLenum currentInternalFormat, currentFormat, currentType;
Geoff Lange4a492b2014-06-19 14:14:41 -0400868 GLuint clientVersion = context->getClientVersion();
Jamie Madill26e91952014-03-05 15:01:27 -0500869
Jamie Madill893ab082014-05-16 16:56:10 -0400870 context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType);
Jamie Madill26e91952014-03-05 15:01:27 -0500871
Geoff Langbdc9b2f2014-04-16 14:41:54 -0400872 bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) :
873 ValidES3ReadFormatType(context, currentInternalFormat, format, type);
Jamie Madill26e91952014-03-05 15:01:27 -0500874
875 if (!(currentFormat == format && currentType == type) && !validReadFormat)
876 {
877 return gl::error(GL_INVALID_OPERATION, false);
878 }
879
Geoff Lange4a492b2014-06-19 14:14:41 -0400880 GLenum sizedInternalFormat = IsSizedInternalFormat(format) ? format
881 : GetSizedInternalFormat(format, type);
Jamie Madill26e91952014-03-05 15:01:27 -0500882
Shannon Woods53a94a82014-06-24 15:20:36 -0400883 GLsizei outputPitch = GetRowPitch(sizedInternalFormat, type, width, context->getState().getPackAlignment());
Jamie Madill26e91952014-03-05 15:01:27 -0500884 // sized query sanity check
885 if (bufSize)
886 {
887 int requiredSize = outputPitch * height;
888 if (requiredSize > *bufSize)
889 {
890 return gl::error(GL_INVALID_OPERATION, false);
891 }
892 }
893
894 return true;
895}
896
Jamie Madilldb2f14c2014-05-13 13:56:30 -0400897bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id)
898{
899 if (!ValidQueryType(context, target))
900 {
901 return gl::error(GL_INVALID_ENUM, false);
902 }
903
904 if (id == 0)
905 {
906 return gl::error(GL_INVALID_OPERATION, false);
907 }
908
909 // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id>
910 // of zero, if the active query object name for <target> is non-zero (for the
911 // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if
912 // the active query for either target is non-zero), if <id> is the name of an
913 // existing query object whose type does not match <target>, or if <id> is the
914 // active query object name for any query type, the error INVALID_OPERATION is
915 // generated.
916
917 // Ensure no other queries are active
918 // NOTE: If other queries than occlusion are supported, we will need to check
919 // separately that:
920 // a) The query ID passed is not the current active query for any target/type
921 // b) There are no active queries for the requested target (and in the case
922 // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
923 // no query may be active for either if glBeginQuery targets either.
Shannon Woods53a94a82014-06-24 15:20:36 -0400924 if (context->getState().isQueryActive())
Jamie Madilldb2f14c2014-05-13 13:56:30 -0400925 {
926 return gl::error(GL_INVALID_OPERATION, false);
927 }
928
929 Query *queryObject = context->getQuery(id, true, target);
930
931 // check that name was obtained with glGenQueries
932 if (!queryObject)
933 {
934 return gl::error(GL_INVALID_OPERATION, false);
935 }
936
937 // check for type mismatch
938 if (queryObject->getType() != target)
939 {
940 return gl::error(GL_INVALID_OPERATION, false);
941 }
942
943 return true;
944}
945
Jamie Madill45c785d2014-05-13 14:09:34 -0400946bool ValidateEndQuery(gl::Context *context, GLenum target)
947{
948 if (!ValidQueryType(context, target))
949 {
950 return gl::error(GL_INVALID_ENUM, false);
951 }
952
Shannon Woods53a94a82014-06-24 15:20:36 -0400953 const Query *queryObject = context->getState().getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -0400954
955 if (queryObject == NULL)
956 {
957 return gl::error(GL_INVALID_OPERATION, false);
958 }
959
960 if (!queryObject->isStarted())
961 {
962 return gl::error(GL_INVALID_OPERATION, false);
963 }
964
965 return true;
966}
967
Jamie Madill36398922014-05-20 14:51:53 -0400968static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType,
969 GLint location, GLsizei count, LinkedUniform **uniformOut)
Jamie Madilld7c7bb22014-05-20 10:55:54 -0400970{
971 if (count < 0)
972 {
973 return gl::error(GL_INVALID_VALUE, false);
974 }
975
Shannon Woods53a94a82014-06-24 15:20:36 -0400976 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
Jamie Madilld7c7bb22014-05-20 10:55:54 -0400977 if (!programBinary)
978 {
979 return gl::error(GL_INVALID_OPERATION, false);
980 }
981
982 if (location == -1)
983 {
984 // Silently ignore the uniform command
985 return false;
986 }
987
Jamie Madill36398922014-05-20 14:51:53 -0400988 if (!programBinary->isValidUniformLocation(location))
989 {
990 return gl::error(GL_INVALID_OPERATION, false);
991 }
992
993 LinkedUniform *uniform = programBinary->getUniformByLocation(location);
994
995 // attempting to write an array to a non-array uniform is an INVALID_OPERATION
996 if (uniform->elementCount() == 1 && count > 1)
997 {
998 return gl::error(GL_INVALID_OPERATION, false);
999 }
1000
1001 *uniformOut = uniform;
Jamie Madilld7c7bb22014-05-20 10:55:54 -04001002 return true;
1003}
1004
Jamie Madillaa981bd2014-05-20 10:55:55 -04001005bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count)
1006{
1007 // Check for ES3 uniform entry points
Jamie Madillf2575982014-06-25 16:04:54 -04001008 if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3)
Jamie Madillaa981bd2014-05-20 10:55:55 -04001009 {
1010 return gl::error(GL_INVALID_OPERATION, false);
1011 }
1012
Jamie Madill36398922014-05-20 14:51:53 -04001013 LinkedUniform *uniform = NULL;
1014 if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform))
1015 {
1016 return false;
1017 }
1018
Jamie Madillf2575982014-06-25 16:04:54 -04001019 GLenum targetBoolType = VariableBoolVectorType(uniformType);
Jamie Madill36398922014-05-20 14:51:53 -04001020 bool samplerUniformCheck = (IsSampler(uniform->type) && uniformType == GL_INT);
1021 if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type)
1022 {
1023 return gl::error(GL_INVALID_OPERATION, false);
1024 }
1025
1026 return true;
Jamie Madillaa981bd2014-05-20 10:55:55 -04001027}
1028
1029bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count,
1030 GLboolean transpose)
1031{
1032 // Check for ES3 uniform entry points
1033 int rows = VariableRowCount(matrixType);
1034 int cols = VariableColumnCount(matrixType);
1035 if (rows != cols && context->getClientVersion() < 3)
1036 {
1037 return gl::error(GL_INVALID_OPERATION, false);
1038 }
1039
1040 if (transpose != GL_FALSE && context->getClientVersion() < 3)
1041 {
1042 return gl::error(GL_INVALID_VALUE, false);
1043 }
1044
Jamie Madill36398922014-05-20 14:51:53 -04001045 LinkedUniform *uniform = NULL;
1046 if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform))
1047 {
1048 return false;
1049 }
1050
1051 if (uniform->type != matrixType)
1052 {
1053 return gl::error(GL_INVALID_OPERATION, false);
1054 }
1055
1056 return true;
Jamie Madillaa981bd2014-05-20 10:55:55 -04001057}
1058
Jamie Madill893ab082014-05-16 16:56:10 -04001059bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams)
1060{
1061 if (!context->getQueryParameterInfo(pname, nativeType, numParams))
1062 {
1063 return gl::error(GL_INVALID_ENUM, false);
1064 }
1065
1066 if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15)
1067 {
1068 unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0);
1069
Geoff Langaae65a42014-05-26 12:43:44 -04001070 if (colorAttachment >= context->getCaps().maxDrawBuffers)
Jamie Madill893ab082014-05-16 16:56:10 -04001071 {
1072 return gl::error(GL_INVALID_OPERATION, false);
1073 }
1074 }
1075
1076 switch (pname)
1077 {
1078 case GL_TEXTURE_BINDING_2D:
1079 case GL_TEXTURE_BINDING_CUBE_MAP:
1080 case GL_TEXTURE_BINDING_3D:
1081 case GL_TEXTURE_BINDING_2D_ARRAY:
Shannon Woods53a94a82014-06-24 15:20:36 -04001082 if (context->getState().getActiveSampler() >= context->getMaximumCombinedTextureImageUnits())
Jamie Madill893ab082014-05-16 16:56:10 -04001083 {
1084 return gl::error(GL_INVALID_OPERATION, false);
1085 }
1086 break;
1087
1088 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
1089 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
1090 {
Shannon Woods53a94a82014-06-24 15:20:36 -04001091 Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madill893ab082014-05-16 16:56:10 -04001092 ASSERT(framebuffer);
1093 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1094 {
1095 return gl::error(GL_INVALID_OPERATION, false);
1096 }
1097
Jamie Madill3c7fa222014-06-05 13:08:51 -04001098 FramebufferAttachment *attachment = framebuffer->getReadColorbuffer();
1099 if (!attachment)
Jamie Madill893ab082014-05-16 16:56:10 -04001100 {
1101 return gl::error(GL_INVALID_OPERATION, false);
1102 }
1103 }
1104 break;
1105
1106 default:
1107 break;
1108 }
1109
1110 // pname is valid, but there are no parameters to return
1111 if (numParams == 0)
1112 {
1113 return false;
1114 }
1115
1116 return true;
1117}
1118
Jamie Madill560a8d82014-05-21 13:06:20 -04001119bool ValidateCopyTexImageParametersBase(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
1120 GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height,
1121 GLint border, GLenum *textureFormatOut)
1122{
1123
1124 if (!ValidTexture2DDestinationTarget(context, target))
1125 {
1126 return gl::error(GL_INVALID_ENUM, false);
1127 }
1128
1129 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
1130 {
1131 return gl::error(GL_INVALID_VALUE, false);
1132 }
1133
1134 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1135 {
1136 return gl::error(GL_INVALID_VALUE, false);
1137 }
1138
1139 if (border != 0)
1140 {
1141 return gl::error(GL_INVALID_VALUE, false);
1142 }
1143
1144 if (!ValidMipLevel(context, target, level))
1145 {
1146 return gl::error(GL_INVALID_VALUE, false);
1147 }
1148
Shannon Woods53a94a82014-06-24 15:20:36 -04001149 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madill560a8d82014-05-21 13:06:20 -04001150 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1151 {
1152 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1153 }
1154
Shannon Woods53a94a82014-06-24 15:20:36 -04001155 if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
Jamie Madill560a8d82014-05-21 13:06:20 -04001156 {
1157 return gl::error(GL_INVALID_OPERATION, false);
1158 }
1159
Geoff Langaae65a42014-05-26 12:43:44 -04001160 const gl::Caps &caps = context->getCaps();
1161
Jamie Madill560a8d82014-05-21 13:06:20 -04001162 gl::Texture *texture = NULL;
1163 GLenum textureInternalFormat = GL_NONE;
1164 bool textureCompressed = false;
1165 bool textureIsDepth = false;
1166 GLint textureLevelWidth = 0;
1167 GLint textureLevelHeight = 0;
1168 GLint textureLevelDepth = 0;
Geoff Langaae65a42014-05-26 12:43:44 -04001169 GLuint maxDimension = 0;
Jamie Madill560a8d82014-05-21 13:06:20 -04001170
1171 switch (target)
1172 {
1173 case GL_TEXTURE_2D:
1174 {
1175 gl::Texture2D *texture2d = context->getTexture2D();
1176 if (texture2d)
1177 {
1178 textureInternalFormat = texture2d->getInternalFormat(level);
1179 textureCompressed = texture2d->isCompressed(level);
1180 textureIsDepth = texture2d->isDepth(level);
1181 textureLevelWidth = texture2d->getWidth(level);
1182 textureLevelHeight = texture2d->getHeight(level);
1183 textureLevelDepth = 1;
1184 texture = texture2d;
Geoff Langaae65a42014-05-26 12:43:44 -04001185 maxDimension = caps.max2DTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001186 }
1187 }
1188 break;
1189
1190 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1191 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1192 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1193 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1194 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1195 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1196 {
1197 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1198 if (textureCube)
1199 {
1200 textureInternalFormat = textureCube->getInternalFormat(target, level);
1201 textureCompressed = textureCube->isCompressed(target, level);
1202 textureIsDepth = false;
1203 textureLevelWidth = textureCube->getWidth(target, level);
1204 textureLevelHeight = textureCube->getHeight(target, level);
1205 textureLevelDepth = 1;
1206 texture = textureCube;
Geoff Langaae65a42014-05-26 12:43:44 -04001207 maxDimension = caps.maxCubeMapTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001208 }
1209 }
1210 break;
1211
1212 case GL_TEXTURE_2D_ARRAY:
1213 {
1214 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1215 if (texture2dArray)
1216 {
1217 textureInternalFormat = texture2dArray->getInternalFormat(level);
1218 textureCompressed = texture2dArray->isCompressed(level);
1219 textureIsDepth = texture2dArray->isDepth(level);
1220 textureLevelWidth = texture2dArray->getWidth(level);
1221 textureLevelHeight = texture2dArray->getHeight(level);
1222 textureLevelDepth = texture2dArray->getLayers(level);
1223 texture = texture2dArray;
Geoff Langaae65a42014-05-26 12:43:44 -04001224 maxDimension = caps.max2DTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001225 }
1226 }
1227 break;
1228
1229 case GL_TEXTURE_3D:
1230 {
1231 gl::Texture3D *texture3d = context->getTexture3D();
1232 if (texture3d)
1233 {
1234 textureInternalFormat = texture3d->getInternalFormat(level);
1235 textureCompressed = texture3d->isCompressed(level);
1236 textureIsDepth = texture3d->isDepth(level);
1237 textureLevelWidth = texture3d->getWidth(level);
1238 textureLevelHeight = texture3d->getHeight(level);
1239 textureLevelDepth = texture3d->getDepth(level);
1240 texture = texture3d;
Geoff Langaae65a42014-05-26 12:43:44 -04001241 maxDimension = caps.max3DTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001242 }
1243 }
1244 break;
1245
1246 default:
1247 return gl::error(GL_INVALID_ENUM, false);
1248 }
1249
1250 if (!texture)
1251 {
1252 return gl::error(GL_INVALID_OPERATION, false);
1253 }
1254
1255 if (texture->isImmutable() && !isSubImage)
1256 {
1257 return gl::error(GL_INVALID_OPERATION, false);
1258 }
1259
1260 if (textureIsDepth)
1261 {
1262 return gl::error(GL_INVALID_OPERATION, false);
1263 }
1264
1265 if (textureCompressed)
1266 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001267 GLint blockWidth = GetCompressedBlockWidth(textureInternalFormat);
1268 GLint blockHeight = GetCompressedBlockHeight(textureInternalFormat);
Jamie Madill560a8d82014-05-21 13:06:20 -04001269
1270 if (((width % blockWidth) != 0 && width != textureLevelWidth) ||
1271 ((height % blockHeight) != 0 && height != textureLevelHeight))
1272 {
1273 return gl::error(GL_INVALID_OPERATION, false);
1274 }
1275 }
1276
1277 if (isSubImage)
1278 {
1279 if (xoffset + width > textureLevelWidth ||
1280 yoffset + height > textureLevelHeight ||
1281 zoffset >= textureLevelDepth)
1282 {
1283 return gl::error(GL_INVALID_VALUE, false);
1284 }
1285 }
Jamie Madill6f38f822014-06-06 17:12:20 -04001286 else
1287 {
1288 if (IsCubemapTextureTarget(target) && width != height)
1289 {
1290 return gl::error(GL_INVALID_VALUE, false);
1291 }
1292
Geoff Langc0b9ef42014-07-02 10:02:37 -04001293 if (!IsValidInternalFormat(internalformat, context->getExtensions(), context->getClientVersion()))
Jamie Madill6f38f822014-06-06 17:12:20 -04001294 {
1295 return gl::error(GL_INVALID_ENUM, false);
1296 }
1297
1298 int maxLevelDimension = (maxDimension >> level);
1299 if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension)
1300 {
1301 return gl::error(GL_INVALID_VALUE, false);
1302 }
1303 }
Jamie Madill560a8d82014-05-21 13:06:20 -04001304
1305 *textureFormatOut = textureInternalFormat;
1306 return true;
1307}
1308
Jamie Madill1aeb1312014-06-20 13:21:25 -04001309static bool ValidateDrawBase(const gl::Context *context, GLenum mode, GLsizei count)
Jamie Madill250d33f2014-06-06 17:09:03 -04001310{
Jamie Madill1aeb1312014-06-20 13:21:25 -04001311 switch (mode)
1312 {
1313 case GL_POINTS:
1314 case GL_LINES:
1315 case GL_LINE_LOOP:
1316 case GL_LINE_STRIP:
1317 case GL_TRIANGLES:
1318 case GL_TRIANGLE_STRIP:
1319 case GL_TRIANGLE_FAN:
1320 break;
1321 default:
1322 return gl::error(GL_INVALID_ENUM, false);
1323 }
1324
Jamie Madill250d33f2014-06-06 17:09:03 -04001325 if (count < 0)
1326 {
1327 return gl::error(GL_INVALID_VALUE, false);
1328 }
1329
Jamie Madill250d33f2014-06-06 17:09:03 -04001330 // Check for mapped buffers
Jamie Madillfd716582014-06-06 17:09:04 -04001331 if (context->hasMappedBuffer(GL_ARRAY_BUFFER))
Jamie Madill250d33f2014-06-06 17:09:03 -04001332 {
1333 return gl::error(GL_INVALID_OPERATION, false);
1334 }
1335
Shannon Woods53a94a82014-06-24 15:20:36 -04001336 const gl::DepthStencilState &depthStencilState = context->getState().getDepthStencilState();
Jamie Madillac528012014-06-20 13:21:23 -04001337 if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask ||
Shannon Woods53a94a82014-06-24 15:20:36 -04001338 context->getState().getStencilRef() != context->getState().getStencilBackRef() ||
Jamie Madillac528012014-06-20 13:21:23 -04001339 depthStencilState.stencilMask != depthStencilState.stencilBackMask)
1340 {
1341 // Note: these separate values are not supported in WebGL, due to D3D's limitations.
1342 // See Section 6.10 of the WebGL 1.0 spec
1343 ERR("This ANGLE implementation does not support separate front/back stencil "
1344 "writemasks, reference values, or stencil mask values.");
1345 return gl::error(GL_INVALID_OPERATION, false);
1346 }
1347
Shannon Woods53a94a82014-06-24 15:20:36 -04001348 const gl::Framebuffer *fbo = context->getState().getDrawFramebuffer();
Jamie Madill13f7d7d2014-06-20 13:21:27 -04001349 if (!fbo || fbo->completeness() != GL_FRAMEBUFFER_COMPLETE)
1350 {
1351 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1352 }
1353
Shannon Woods53a94a82014-06-24 15:20:36 -04001354 if (context->getState().getCurrentProgramId() == 0)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001355 {
1356 return gl::error(GL_INVALID_OPERATION, false);
1357 }
1358
Shannon Woods53a94a82014-06-24 15:20:36 -04001359 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
Jamie Madilld4cfa572014-07-08 10:00:32 -04001360 if (!programBinary->validateSamplers(NULL))
1361 {
1362 return gl::error(GL_INVALID_OPERATION, false);
1363 }
1364
Jamie Madill250d33f2014-06-06 17:09:03 -04001365 // No-op if zero count
1366 return (count > 0);
1367}
1368
Jamie Madillfd716582014-06-06 17:09:04 -04001369bool ValidateDrawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count)
Jamie Madill250d33f2014-06-06 17:09:03 -04001370{
Jamie Madillfd716582014-06-06 17:09:04 -04001371 if (first < 0)
Jamie Madill250d33f2014-06-06 17:09:03 -04001372 {
1373 return gl::error(GL_INVALID_VALUE, false);
1374 }
1375
Shannon Woods53a94a82014-06-24 15:20:36 -04001376 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
Jamie Madillfd716582014-06-06 17:09:04 -04001377 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused() &&
1378 curTransformFeedback->getDrawMode() != mode)
1379 {
1380 // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode
1381 // that does not match the current transform feedback object's draw mode (if transform feedback
1382 // is active), (3.0.2, section 2.14, pg 86)
1383 return gl::error(GL_INVALID_OPERATION, false);
1384 }
1385
Jamie Madill1aeb1312014-06-20 13:21:25 -04001386 if (!ValidateDrawBase(context, mode, count))
Jamie Madillfd716582014-06-06 17:09:04 -04001387 {
1388 return false;
1389 }
1390
1391 return true;
1392}
1393
1394bool ValidateDrawArraysInstanced(const gl::Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1395{
1396 if (primcount < 0)
1397 {
1398 return gl::error(GL_INVALID_VALUE, false);
1399 }
1400
1401 if (!ValidateDrawArrays(context, mode, first, count))
1402 {
1403 return false;
1404 }
1405
1406 // No-op if zero primitive count
1407 return (primcount > 0);
1408}
1409
1410bool ValidateDrawElements(const gl::Context *context, GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
1411{
Jamie Madill250d33f2014-06-06 17:09:03 -04001412 switch (type)
1413 {
1414 case GL_UNSIGNED_BYTE:
1415 case GL_UNSIGNED_SHORT:
1416 break;
1417 case GL_UNSIGNED_INT:
Geoff Langc0b9ef42014-07-02 10:02:37 -04001418 if (!context->getExtensions().elementIndexUint)
Jamie Madill250d33f2014-06-06 17:09:03 -04001419 {
1420 return gl::error(GL_INVALID_ENUM, false);
1421 }
1422 break;
1423 default:
1424 return gl::error(GL_INVALID_ENUM, false);
1425 }
1426
Shannon Woods53a94a82014-06-24 15:20:36 -04001427 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
Jamie Madill250d33f2014-06-06 17:09:03 -04001428 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
1429 {
1430 // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced
1431 // while transform feedback is active, (3.0.2, section 2.14, pg 86)
1432 return gl::error(GL_INVALID_OPERATION, false);
1433 }
1434
1435 // Check for mapped buffers
Jamie Madillfd716582014-06-06 17:09:04 -04001436 if (context->hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER))
Jamie Madill250d33f2014-06-06 17:09:03 -04001437 {
1438 return gl::error(GL_INVALID_OPERATION, false);
1439 }
1440
Shannon Woods53a94a82014-06-24 15:20:36 -04001441 gl::VertexArray *vao = context->getState().getVertexArray();
Jamie Madilld4cfa572014-07-08 10:00:32 -04001442 if (!indices && !vao->getElementArrayBuffer())
1443 {
1444 return gl::error(GL_INVALID_OPERATION, false);
1445 }
1446
Jamie Madill1aeb1312014-06-20 13:21:25 -04001447 if (!ValidateDrawBase(context, mode, count))
Jamie Madillfd716582014-06-06 17:09:04 -04001448 {
1449 return false;
1450 }
1451
1452 return true;
1453}
1454
1455bool ValidateDrawElementsInstanced(const gl::Context *context, GLenum mode, GLsizei count, GLenum type,
1456 const GLvoid *indices, GLsizei primcount)
1457{
1458 if (primcount < 0)
1459 {
1460 return gl::error(GL_INVALID_VALUE, false);
1461 }
1462
1463 if (!ValidateDrawElements(context, mode, count, type, indices))
1464 {
1465 return false;
1466 }
1467
1468 // No-op zero primitive count
1469 return (primcount > 0);
Jamie Madill250d33f2014-06-06 17:09:03 -04001470}
1471
Jamie Madill55ec3b12014-07-03 10:38:57 -04001472bool ValidateFramebufferTextureBase(const gl::Context *context, GLenum target, GLenum attachment,
1473 GLuint texture, GLint level)
Jamie Madill570f7c82014-07-03 10:38:54 -04001474{
Jamie Madill55ec3b12014-07-03 10:38:57 -04001475 if (!ValidFramebufferTarget(target))
1476 {
1477 return gl::error(GL_INVALID_ENUM, false);
1478 }
1479
1480 if (!ValidateAttachmentTarget(context, attachment))
Jamie Madill570f7c82014-07-03 10:38:54 -04001481 {
1482 return false;
1483 }
1484
Jamie Madill55ec3b12014-07-03 10:38:57 -04001485 if (texture != 0)
1486 {
1487 gl::Texture *tex = context->getTexture(texture);
1488
1489 if (tex == NULL)
1490 {
1491 return gl::error(GL_INVALID_OPERATION, false);
1492 }
1493
1494 if (level < 0)
1495 {
1496 return gl::error(GL_INVALID_VALUE, false);
1497 }
1498 }
1499
Shannon Woods53a94a82014-06-24 15:20:36 -04001500 const gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1501 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
Jamie Madill55ec3b12014-07-03 10:38:57 -04001502
1503 if (framebufferHandle == 0 || !framebuffer)
1504 {
1505 return gl::error(GL_INVALID_OPERATION, false);
1506 }
1507
1508 return true;
1509}
1510
1511bool ValidateFramebufferTexture2D(const gl::Context *context, GLenum target, GLenum attachment,
1512 GLenum textarget, GLuint texture, GLint level)
1513{
1514 // Attachments are required to be bound to level 0 in ES2
1515 if (context->getClientVersion() < 3 && level != 0)
1516 {
1517 return gl::error(GL_INVALID_VALUE, false);
1518 }
1519
1520 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
Jamie Madill570f7c82014-07-03 10:38:54 -04001521 {
1522 return false;
1523 }
1524
Jamie Madill55ec3b12014-07-03 10:38:57 -04001525 if (texture != 0)
1526 {
1527 gl::Texture *tex = context->getTexture(texture);
1528 ASSERT(tex);
1529
Jamie Madill2a6564e2014-07-11 09:53:19 -04001530 const gl::Caps &caps = context->getCaps();
1531
Jamie Madill55ec3b12014-07-03 10:38:57 -04001532 switch (textarget)
1533 {
1534 case GL_TEXTURE_2D:
1535 {
Jamie Madill2a6564e2014-07-11 09:53:19 -04001536 if (level > gl::log2(caps.max2DTextureSize))
Jamie Madill55ec3b12014-07-03 10:38:57 -04001537 {
1538 return gl::error(GL_INVALID_VALUE, false);
1539 }
1540 if (tex->getTarget() != GL_TEXTURE_2D)
1541 {
1542 return gl::error(GL_INVALID_OPERATION, false);
1543 }
1544 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
1545 if (tex2d->isCompressed(level))
1546 {
1547 return gl::error(GL_INVALID_OPERATION, false);
1548 }
1549 }
1550 break;
1551
1552 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1553 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1554 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1555 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1556 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1557 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1558 {
Jamie Madill2a6564e2014-07-11 09:53:19 -04001559 if (level > gl::log2(caps.maxCubeMapTextureSize))
Jamie Madill55ec3b12014-07-03 10:38:57 -04001560 {
1561 return gl::error(GL_INVALID_VALUE, false);
1562 }
1563 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
1564 {
1565 return gl::error(GL_INVALID_OPERATION, false);
1566 }
1567 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
1568 if (texcube->isCompressed(textarget, level))
1569 {
1570 return gl::error(GL_INVALID_OPERATION, false);
1571 }
1572 }
1573 break;
1574
1575 default:
1576 return gl::error(GL_INVALID_ENUM, false);
1577 }
1578 }
1579
Jamie Madill570f7c82014-07-03 10:38:54 -04001580 return true;
1581}
1582
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001583}