blob: 8016dfbf90eaf8bd3db2190a6eb18cca0aac3ebb [file] [log] [blame]
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
Geoff Lange8ebe7f2013-08-05 15:03:13 -04003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// validationES.h: Validation functions for generic OpenGL ES entry point parameters
8
9#include "libGLESv2/validationES.h"
Jamie Madill26e91952014-03-05 15:01:27 -050010#include "libGLESv2/validationES2.h"
11#include "libGLESv2/validationES3.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040012#include "libGLESv2/Context.h"
13#include "libGLESv2/Texture.h"
14#include "libGLESv2/Framebuffer.h"
Jamie Madille261b442014-06-25 12:42:21 -040015#include "libGLESv2/FramebufferAttachment.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040016#include "libGLESv2/formatutils.h"
17#include "libGLESv2/main.h"
Jamie Madilldb2f14c2014-05-13 13:56:30 -040018#include "libGLESv2/Query.h"
Jamie Madill36398922014-05-20 14:51:53 -040019#include "libGLESv2/ProgramBinary.h"
Jamie Madill250d33f2014-06-06 17:09:03 -040020#include "libGLESv2/TransformFeedback.h"
Jamie Madilld4cfa572014-07-08 10:00:32 -040021#include "libGLESv2/VertexArray.h"
Jamie Madill2b976812014-08-25 15:47:49 -040022#include "libGLESv2/renderer/BufferImpl.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
Geoff Langb1196682014-07-23 13:47:29 -0400171bool ValidImageSize(const Context *context, GLenum target, GLint level,
Jamie Madill4fd75c12014-06-23 10:53:54 -0400172 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 Langb1196682014-07-23 13:47:29 -0400193bool ValidCompressedImageSize(const Context *context, GLenum internalFormat, GLsizei width, GLsizei height)
Geoff Langd4f180b2013-09-24 13:57:44 -0400194{
Geoff Lang5d601382014-07-22 15:14:06 -0400195 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
196 if (!formatInfo.compressed)
Geoff Langd4f180b2013-09-24 13:57:44 -0400197 {
198 return false;
199 }
200
Geoff Lang5d601382014-07-22 15:14:06 -0400201 if (width < 0 || (static_cast<GLuint>(width) > formatInfo.compressedBlockWidth && width % formatInfo.compressedBlockWidth != 0) ||
202 height < 0 || (static_cast<GLuint>(height) > formatInfo.compressedBlockHeight && height % formatInfo.compressedBlockHeight != 0))
Geoff Langd4f180b2013-09-24 13:57:44 -0400203 {
204 return false;
205 }
206
207 return true;
208}
209
Geoff Lang37dde692014-01-31 16:34:54 -0500210bool ValidQueryType(const Context *context, GLenum queryType)
211{
212 META_ASSERT(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT);
213 META_ASSERT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT);
214
215 switch (queryType)
216 {
217 case GL_ANY_SAMPLES_PASSED:
218 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
219 return true;
220 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
221 return (context->getClientVersion() >= 3);
222 default:
223 return false;
224 }
225}
226
Geoff Langb1196682014-07-23 13:47:29 -0400227bool ValidProgram(Context *context, GLuint id)
Geoff Lang48dcae72014-02-05 16:28:24 -0500228{
229 // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will generate the
230 // error INVALID_VALUE if the provided name is not the name of either a shader or program object and
231 // INVALID_OPERATION if the provided name identifies an object that is not the expected type."
232
233 if (context->getProgram(id) != NULL)
234 {
235 return true;
236 }
237 else if (context->getShader(id) != NULL)
238 {
239 // ID is the wrong type
Geoff Langb1196682014-07-23 13:47:29 -0400240 context->recordError(Error(GL_INVALID_OPERATION));
241 return false;
Geoff Lang48dcae72014-02-05 16:28:24 -0500242 }
243 else
244 {
245 // No shader/program object has this ID
Geoff Langb1196682014-07-23 13:47:29 -0400246 context->recordError(Error(GL_INVALID_VALUE));
247 return false;
Geoff Lang48dcae72014-02-05 16:28:24 -0500248 }
249}
250
Geoff Langb1196682014-07-23 13:47:29 -0400251bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment)
Jamie Madillb4472272014-07-03 10:38:55 -0400252{
253 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
254 {
255 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
256
Geoff Langaae65a42014-05-26 12:43:44 -0400257 if (colorAttachment >= context->getCaps().maxColorAttachments)
Jamie Madillb4472272014-07-03 10:38:55 -0400258 {
Geoff Langb1196682014-07-23 13:47:29 -0400259 context->recordError(Error(GL_INVALID_VALUE));
260 return false;
Jamie Madillb4472272014-07-03 10:38:55 -0400261 }
262 }
263 else
264 {
265 switch (attachment)
266 {
267 case GL_DEPTH_ATTACHMENT:
268 case GL_STENCIL_ATTACHMENT:
269 break;
270
271 case GL_DEPTH_STENCIL_ATTACHMENT:
272 if (context->getClientVersion() < 3)
273 {
Geoff Langb1196682014-07-23 13:47:29 -0400274 context->recordError(Error(GL_INVALID_ENUM));
275 return false;
Jamie Madillb4472272014-07-03 10:38:55 -0400276 }
277 break;
278
279 default:
Geoff Langb1196682014-07-23 13:47:29 -0400280 context->recordError(Error(GL_INVALID_ENUM));
281 return false;
Jamie Madillb4472272014-07-03 10:38:55 -0400282 }
283 }
284
285 return true;
286}
287
Geoff Langb1196682014-07-23 13:47:29 -0400288bool ValidateRenderbufferStorageParameters(gl::Context *context, GLenum target, GLsizei samples,
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400289 GLenum internalformat, GLsizei width, GLsizei height,
290 bool angleExtension)
291{
292 switch (target)
293 {
294 case GL_RENDERBUFFER:
295 break;
296 default:
Geoff Langb1196682014-07-23 13:47:29 -0400297 context->recordError(Error(GL_INVALID_ENUM));
298 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400299 }
300
301 if (width < 0 || height < 0 || samples < 0)
302 {
Geoff Langb1196682014-07-23 13:47:29 -0400303 context->recordError(Error(GL_INVALID_VALUE));
304 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400305 }
306
Geoff Lang5d601382014-07-22 15:14:06 -0400307 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
308 if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400309 {
Geoff Langb1196682014-07-23 13:47:29 -0400310 context->recordError(Error(GL_INVALID_ENUM));
311 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400312 }
313
314 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
315 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
316 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
317 // internal format must be sized and not an integer format if samples is greater than zero.
Geoff Lang5d601382014-07-22 15:14:06 -0400318 if (formatInfo.pixelBytes == 0)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400319 {
Geoff Langb1196682014-07-23 13:47:29 -0400320 context->recordError(Error(GL_INVALID_ENUM));
321 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400322 }
323
Geoff Lang5d601382014-07-22 15:14:06 -0400324 if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && samples > 0)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400325 {
Geoff Langb1196682014-07-23 13:47:29 -0400326 context->recordError(Error(GL_INVALID_OPERATION));
327 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400328 }
329
Geoff Langc0b9ef42014-07-02 10:02:37 -0400330 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
Geoff Lang6cf8e1b2014-07-03 13:03:57 -0400331 if (!formatCaps.renderable)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400332 {
Geoff Langb1196682014-07-23 13:47:29 -0400333 context->recordError(Error(GL_INVALID_ENUM));
334 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400335 }
336
Geoff Langaae65a42014-05-26 12:43:44 -0400337 if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400338 {
Geoff Langb1196682014-07-23 13:47:29 -0400339 context->recordError(Error(GL_INVALID_VALUE));
340 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400341 }
342
343 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
344 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
345 // states that samples must be less than or equal to the maximum samples for the specified
346 // internal format.
347 if (angleExtension)
348 {
Geoff Lang5f4c4632014-07-03 13:46:52 -0400349 ASSERT(context->getExtensions().framebufferMultisample);
350 if (static_cast<GLuint>(samples) > context->getExtensions().maxSamples)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400351 {
Geoff Langb1196682014-07-23 13:47:29 -0400352 context->recordError(Error(GL_INVALID_VALUE));
353 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400354 }
Geoff Lang5f4c4632014-07-03 13:46:52 -0400355
356 // Check if this specific format supports enough samples
357 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
358 {
Geoff Langb1196682014-07-23 13:47:29 -0400359 context->recordError(Error(GL_OUT_OF_MEMORY));
360 return false;
Geoff Lang5f4c4632014-07-03 13:46:52 -0400361 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400362 }
363 else
364 {
Geoff Lang5f4c4632014-07-03 13:46:52 -0400365 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400366 {
Geoff Langb1196682014-07-23 13:47:29 -0400367 context->recordError(Error(GL_INVALID_VALUE));
368 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400369 }
370 }
371
Shannon Woods53a94a82014-06-24 15:20:36 -0400372 GLuint handle = context->getState().getRenderbufferId();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400373 if (handle == 0)
374 {
Geoff Langb1196682014-07-23 13:47:29 -0400375 context->recordError(Error(GL_INVALID_OPERATION));
376 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400377 }
378
379 return true;
380}
381
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500382bool ValidateFramebufferRenderbufferParameters(gl::Context *context, GLenum target, GLenum attachment,
383 GLenum renderbuffertarget, GLuint renderbuffer)
384{
Shannon Woods1da3cf62014-06-27 15:32:23 -0400385 if (!ValidFramebufferTarget(target))
386 {
Geoff Langb1196682014-07-23 13:47:29 -0400387 context->recordError(Error(GL_INVALID_ENUM));
388 return false;
Shannon Woods1da3cf62014-06-27 15:32:23 -0400389 }
390
Shannon Woods53a94a82014-06-24 15:20:36 -0400391 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
392 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500393
394 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
395 {
Geoff Langb1196682014-07-23 13:47:29 -0400396 context->recordError(Error(GL_INVALID_OPERATION));
397 return false;
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500398 }
399
Jamie Madillb4472272014-07-03 10:38:55 -0400400 if (!ValidateAttachmentTarget(context, attachment))
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500401 {
Jamie Madillb4472272014-07-03 10:38:55 -0400402 return false;
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500403 }
404
Jamie Madillab9d82c2014-01-21 16:38:14 -0500405 // [OpenGL ES 2.0.25] Section 4.4.3 page 112
406 // [OpenGL ES 3.0.2] Section 4.4.2 page 201
407 // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of
408 // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated.
409 if (renderbuffer != 0)
410 {
411 if (!context->getRenderbuffer(renderbuffer))
412 {
Geoff Langb1196682014-07-23 13:47:29 -0400413 context->recordError(Error(GL_INVALID_OPERATION));
414 return false;
Jamie Madillab9d82c2014-01-21 16:38:14 -0500415 }
416 }
417
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500418 return true;
419}
420
Jamie Madill3c7fa222014-06-05 13:08:51 -0400421static bool IsPartialBlit(gl::Context *context, gl::FramebufferAttachment *readBuffer, gl::FramebufferAttachment *writeBuffer,
Geoff Lang125deab2013-08-09 13:34:16 -0400422 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
423 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1)
424{
425 if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 ||
426 dstX1 != writeBuffer->getWidth() || dstY1 != writeBuffer->getHeight() ||
427 srcX1 != readBuffer->getWidth() || srcY1 != readBuffer->getHeight())
428 {
429 return true;
430 }
Shannon Woods53a94a82014-06-24 15:20:36 -0400431 else if (context->getState().isScissorTestEnabled())
Geoff Lang125deab2013-08-09 13:34:16 -0400432 {
Shannon Woods53a94a82014-06-24 15:20:36 -0400433 const Rectangle &scissor = context->getState().getScissor();
Geoff Lang125deab2013-08-09 13:34:16 -0400434
Shannon Woods53a94a82014-06-24 15:20:36 -0400435 return scissor.x > 0 || scissor.y > 0 ||
436 scissor.width < writeBuffer->getWidth() ||
437 scissor.height < writeBuffer->getHeight();
Geoff Lang125deab2013-08-09 13:34:16 -0400438 }
439 else
440 {
441 return false;
442 }
443}
444
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400445bool ValidateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400446 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
447 GLenum filter, bool fromAngleExtension)
448{
449 switch (filter)
450 {
451 case GL_NEAREST:
452 break;
453 case GL_LINEAR:
454 if (fromAngleExtension)
455 {
Geoff Langb1196682014-07-23 13:47:29 -0400456 context->recordError(Error(GL_INVALID_ENUM));
457 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400458 }
459 break;
460 default:
Geoff Langb1196682014-07-23 13:47:29 -0400461 context->recordError(Error(GL_INVALID_ENUM));
462 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400463 }
464
465 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
466 {
Geoff Langb1196682014-07-23 13:47:29 -0400467 context->recordError(Error(GL_INVALID_VALUE));
468 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400469 }
470
471 if (mask == 0)
472 {
473 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
474 // buffers are copied.
475 return false;
476 }
477
478 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
479 {
480 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
Geoff Langb1196682014-07-23 13:47:29 -0400481 context->recordError(Error(GL_INVALID_OPERATION));
482 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400483 }
484
485 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
486 // color buffer, leaving only nearest being unfiltered from above
487 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
488 {
Geoff Langb1196682014-07-23 13:47:29 -0400489 context->recordError(Error(GL_INVALID_OPERATION));
490 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400491 }
492
Shannon Woods53a94a82014-06-24 15:20:36 -0400493 if (context->getState().getReadFramebuffer()->id() == context->getState().getDrawFramebuffer()->id())
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400494 {
495 if (fromAngleExtension)
496 {
497 ERR("Blits with the same source and destination framebuffer are not supported by this "
498 "implementation.");
499 }
Geoff Langb1196682014-07-23 13:47:29 -0400500 context->recordError(Error(GL_INVALID_OPERATION));
501 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400502 }
503
Shannon Woods53a94a82014-06-24 15:20:36 -0400504 gl::Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
505 gl::Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400506 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
507 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
508 {
Geoff Langb1196682014-07-23 13:47:29 -0400509 context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
510 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400511 }
512
513 if (drawFramebuffer->getSamples() != 0)
514 {
Geoff Langb1196682014-07-23 13:47:29 -0400515 context->recordError(Error(GL_INVALID_OPERATION));
516 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400517 }
518
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400519 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
520
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400521 if (mask & GL_COLOR_BUFFER_BIT)
522 {
Jamie Madill3c7fa222014-06-05 13:08:51 -0400523 gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer();
524 gl::FramebufferAttachment *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400525
526 if (readColorBuffer && drawColorBuffer)
527 {
Geoff Lang005df412013-10-16 14:12:50 -0400528 GLenum readInternalFormat = readColorBuffer->getActualFormat();
Geoff Lang5d601382014-07-22 15:14:06 -0400529 const InternalFormat &readFormatInfo = GetInternalFormatInfo(readInternalFormat);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400530
531 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
532 {
533 if (drawFramebuffer->isEnabledColorAttachment(i))
534 {
Geoff Lang005df412013-10-16 14:12:50 -0400535 GLenum drawInternalFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
Geoff Lang5d601382014-07-22 15:14:06 -0400536 const InternalFormat &drawFormatInfo = GetInternalFormatInfo(drawInternalFormat);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400537
Geoff Langb2f3d052013-08-13 12:49:27 -0400538 // The GL ES 3.0.2 spec (pg 193) states that:
539 // 1) If the read buffer is fixed point format, the draw buffer must be as well
540 // 2) If the read buffer is an unsigned integer format, the draw buffer must be as well
541 // 3) If the read buffer is a signed integer format, the draw buffer must be as well
Geoff Lang5d601382014-07-22 15:14:06 -0400542 if ( (readFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || readFormatInfo.componentType == GL_SIGNED_NORMALIZED) &&
543 !(drawFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || drawFormatInfo.componentType == GL_SIGNED_NORMALIZED))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400544 {
Geoff Langb1196682014-07-23 13:47:29 -0400545 context->recordError(Error(GL_INVALID_OPERATION));
546 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400547 }
548
Geoff Lang5d601382014-07-22 15:14:06 -0400549 if (readFormatInfo.componentType == GL_UNSIGNED_INT && drawFormatInfo.componentType != GL_UNSIGNED_INT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400550 {
Geoff Langb1196682014-07-23 13:47:29 -0400551 context->recordError(Error(GL_INVALID_OPERATION));
552 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400553 }
554
Geoff Lang5d601382014-07-22 15:14:06 -0400555 if (readFormatInfo.componentType == GL_INT && drawFormatInfo.componentType != GL_INT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400556 {
Geoff Langb1196682014-07-23 13:47:29 -0400557 context->recordError(Error(GL_INVALID_OPERATION));
558 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400559 }
560
Geoff Langb2f3d052013-08-13 12:49:27 -0400561 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawInternalFormat || !sameBounds))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400562 {
Geoff Langb1196682014-07-23 13:47:29 -0400563 context->recordError(Error(GL_INVALID_OPERATION));
564 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400565 }
566 }
567 }
568
Geoff Lang5d601382014-07-22 15:14:06 -0400569 if ((readFormatInfo.componentType == GL_INT || readFormatInfo.componentType == GL_UNSIGNED_INT) && filter == GL_LINEAR)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400570 {
Geoff Langb1196682014-07-23 13:47:29 -0400571 context->recordError(Error(GL_INVALID_OPERATION));
572 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400573 }
574
575 if (fromAngleExtension)
576 {
577 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
578 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
579 {
Geoff Langb1196682014-07-23 13:47:29 -0400580 context->recordError(Error(GL_INVALID_OPERATION));
581 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400582 }
583
584 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
585 {
586 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
587 {
Jamie Madille92a3542014-07-03 10:38:58 -0400588 FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(colorAttachment);
589 ASSERT(attachment);
590
591 if (attachment->type() != GL_TEXTURE_2D && attachment->type() != GL_RENDERBUFFER)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400592 {
Geoff Langb1196682014-07-23 13:47:29 -0400593 context->recordError(Error(GL_INVALID_OPERATION));
594 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400595 }
596
Jamie Madille92a3542014-07-03 10:38:58 -0400597 if (attachment->getActualFormat() != readColorBuffer->getActualFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400598 {
Geoff Langb1196682014-07-23 13:47:29 -0400599 context->recordError(Error(GL_INVALID_OPERATION));
600 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400601 }
602 }
603 }
Geoff Lang125deab2013-08-09 13:34:16 -0400604 if (readFramebuffer->getSamples() != 0 && IsPartialBlit(context, readColorBuffer, drawColorBuffer,
605 srcX0, srcY0, srcX1, srcY1,
606 dstX0, dstY0, dstX1, dstY1))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400607 {
Geoff Langb1196682014-07-23 13:47:29 -0400608 context->recordError(Error(GL_INVALID_OPERATION));
609 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400610 }
611 }
612 }
613 }
614
615 if (mask & GL_DEPTH_BUFFER_BIT)
616 {
Jamie Madill3c7fa222014-06-05 13:08:51 -0400617 gl::FramebufferAttachment *readDepthBuffer = readFramebuffer->getDepthbuffer();
618 gl::FramebufferAttachment *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400619
620 if (readDepthBuffer && drawDepthBuffer)
621 {
622 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
623 {
Geoff Langb1196682014-07-23 13:47:29 -0400624 context->recordError(Error(GL_INVALID_OPERATION));
625 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400626 }
627
628 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
629 {
Geoff Langb1196682014-07-23 13:47:29 -0400630 context->recordError(Error(GL_INVALID_OPERATION));
631 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400632 }
633
634 if (fromAngleExtension)
635 {
Geoff Lang125deab2013-08-09 13:34:16 -0400636 if (IsPartialBlit(context, readDepthBuffer, drawDepthBuffer,
637 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400638 {
639 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
Geoff Langb1196682014-07-23 13:47:29 -0400640 context->recordError(Error(GL_INVALID_OPERATION)); // only whole-buffer copies are permitted
641 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400642 }
643
644 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
645 {
Geoff Langb1196682014-07-23 13:47:29 -0400646 context->recordError(Error(GL_INVALID_OPERATION));
647 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400648 }
649 }
650 }
651 }
652
653 if (mask & GL_STENCIL_BUFFER_BIT)
654 {
Jamie Madill3c7fa222014-06-05 13:08:51 -0400655 gl::FramebufferAttachment *readStencilBuffer = readFramebuffer->getStencilbuffer();
656 gl::FramebufferAttachment *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400657
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400658 if (readStencilBuffer && drawStencilBuffer)
659 {
660 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
661 {
Geoff Langb1196682014-07-23 13:47:29 -0400662 context->recordError(Error(GL_INVALID_OPERATION));
663 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400664 }
665
666 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
667 {
Geoff Langb1196682014-07-23 13:47:29 -0400668 context->recordError(Error(GL_INVALID_OPERATION));
669 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400670 }
671
672 if (fromAngleExtension)
673 {
Geoff Lang125deab2013-08-09 13:34:16 -0400674 if (IsPartialBlit(context, readStencilBuffer, drawStencilBuffer,
675 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400676 {
677 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
Geoff Langb1196682014-07-23 13:47:29 -0400678 context->recordError(Error(GL_INVALID_OPERATION)); // only whole-buffer copies are permitted
679 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400680 }
681
682 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
683 {
Geoff Langb1196682014-07-23 13:47:29 -0400684 context->recordError(Error(GL_INVALID_OPERATION));
685 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400686 }
687 }
688 }
689 }
690
691 return true;
692}
693
Geoff Langb1196682014-07-23 13:47:29 -0400694bool ValidateGetVertexAttribParameters(Context *context, GLenum pname)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400695{
696 switch (pname)
697 {
698 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
699 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
700 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
701 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
702 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
703 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
704 case GL_CURRENT_VERTEX_ATTRIB:
705 return true;
706
707 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
708 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
709 // the same constant.
710 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
711 return true;
712
713 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
Geoff Langb1196682014-07-23 13:47:29 -0400714 if (context->getClientVersion() < 3)
715 {
716 context->recordError(Error(GL_INVALID_ENUM));
717 return false;
718 }
719 return true;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400720
721 default:
Geoff Langb1196682014-07-23 13:47:29 -0400722 context->recordError(Error(GL_INVALID_ENUM));
723 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400724 }
725}
726
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400727bool ValidateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400728{
729 switch (pname)
730 {
731 case GL_TEXTURE_WRAP_R:
732 case GL_TEXTURE_SWIZZLE_R:
733 case GL_TEXTURE_SWIZZLE_G:
734 case GL_TEXTURE_SWIZZLE_B:
735 case GL_TEXTURE_SWIZZLE_A:
736 case GL_TEXTURE_BASE_LEVEL:
737 case GL_TEXTURE_MAX_LEVEL:
738 case GL_TEXTURE_COMPARE_MODE:
739 case GL_TEXTURE_COMPARE_FUNC:
740 case GL_TEXTURE_MIN_LOD:
741 case GL_TEXTURE_MAX_LOD:
742 if (context->getClientVersion() < 3)
743 {
Geoff Langb1196682014-07-23 13:47:29 -0400744 context->recordError(Error(GL_INVALID_ENUM));
745 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400746 }
747 break;
748
749 default: break;
750 }
751
752 switch (pname)
753 {
754 case GL_TEXTURE_WRAP_S:
755 case GL_TEXTURE_WRAP_T:
756 case GL_TEXTURE_WRAP_R:
757 switch (param)
758 {
759 case GL_REPEAT:
760 case GL_CLAMP_TO_EDGE:
761 case GL_MIRRORED_REPEAT:
762 return true;
763 default:
Geoff Langb1196682014-07-23 13:47:29 -0400764 context->recordError(Error(GL_INVALID_ENUM));
765 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400766 }
767
768 case GL_TEXTURE_MIN_FILTER:
769 switch (param)
770 {
771 case GL_NEAREST:
772 case GL_LINEAR:
773 case GL_NEAREST_MIPMAP_NEAREST:
774 case GL_LINEAR_MIPMAP_NEAREST:
775 case GL_NEAREST_MIPMAP_LINEAR:
776 case GL_LINEAR_MIPMAP_LINEAR:
777 return true;
778 default:
Geoff Langb1196682014-07-23 13:47:29 -0400779 context->recordError(Error(GL_INVALID_ENUM));
780 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400781 }
782 break;
783
784 case GL_TEXTURE_MAG_FILTER:
785 switch (param)
786 {
787 case GL_NEAREST:
788 case GL_LINEAR:
789 return true;
790 default:
Geoff Langb1196682014-07-23 13:47:29 -0400791 context->recordError(Error(GL_INVALID_ENUM));
792 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400793 }
794 break;
795
796 case GL_TEXTURE_USAGE_ANGLE:
797 switch (param)
798 {
799 case GL_NONE:
800 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
801 return true;
802 default:
Geoff Langb1196682014-07-23 13:47:29 -0400803 context->recordError(Error(GL_INVALID_ENUM));
804 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400805 }
806 break;
807
808 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
Geoff Langc0b9ef42014-07-02 10:02:37 -0400809 if (!context->getExtensions().textureFilterAnisotropic)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400810 {
Geoff Langb1196682014-07-23 13:47:29 -0400811 context->recordError(Error(GL_INVALID_ENUM));
812 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400813 }
814
815 // we assume the parameter passed to this validation method is truncated, not rounded
816 if (param < 1)
817 {
Geoff Langb1196682014-07-23 13:47:29 -0400818 context->recordError(Error(GL_INVALID_VALUE));
819 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400820 }
821 return true;
822
823 case GL_TEXTURE_MIN_LOD:
824 case GL_TEXTURE_MAX_LOD:
825 // any value is permissible
826 return true;
827
828 case GL_TEXTURE_COMPARE_MODE:
Geoff Lang63b5f1f2013-09-23 14:52:14 -0400829 // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400830 switch (param)
831 {
832 case GL_NONE:
833 case GL_COMPARE_REF_TO_TEXTURE:
834 return true;
835 default:
Geoff Langb1196682014-07-23 13:47:29 -0400836 context->recordError(Error(GL_INVALID_ENUM));
837 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400838 }
839 break;
840
841 case GL_TEXTURE_COMPARE_FUNC:
Geoff Lang63b5f1f2013-09-23 14:52:14 -0400842 // Acceptable function parameters from GLES 3.0.2 spec, table 3.17
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400843 switch (param)
844 {
845 case GL_LEQUAL:
846 case GL_GEQUAL:
847 case GL_LESS:
848 case GL_GREATER:
849 case GL_EQUAL:
850 case GL_NOTEQUAL:
851 case GL_ALWAYS:
852 case GL_NEVER:
853 return true;
854 default:
Geoff Langb1196682014-07-23 13:47:29 -0400855 context->recordError(Error(GL_INVALID_ENUM));
856 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400857 }
858 break;
859
860 case GL_TEXTURE_SWIZZLE_R:
861 case GL_TEXTURE_SWIZZLE_G:
862 case GL_TEXTURE_SWIZZLE_B:
863 case GL_TEXTURE_SWIZZLE_A:
Geoff Langbc90a482013-09-17 16:51:27 -0400864 switch (param)
865 {
866 case GL_RED:
867 case GL_GREEN:
868 case GL_BLUE:
869 case GL_ALPHA:
870 case GL_ZERO:
871 case GL_ONE:
872 return true;
873 default:
Geoff Langb1196682014-07-23 13:47:29 -0400874 context->recordError(Error(GL_INVALID_ENUM));
875 return false;
Geoff Langbc90a482013-09-17 16:51:27 -0400876 }
877 break;
878
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400879 case GL_TEXTURE_BASE_LEVEL:
880 case GL_TEXTURE_MAX_LEVEL:
Nicolas Capens8de68282014-04-04 11:10:27 -0400881 if (param < 0)
882 {
Geoff Langb1196682014-07-23 13:47:29 -0400883 context->recordError(Error(GL_INVALID_VALUE));
884 return false;
Nicolas Capens8de68282014-04-04 11:10:27 -0400885 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400886 return true;
887
888 default:
Geoff Langb1196682014-07-23 13:47:29 -0400889 context->recordError(Error(GL_INVALID_ENUM));
890 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400891 }
892}
893
Geoff Langb1196682014-07-23 13:47:29 -0400894bool ValidateSamplerObjectParameter(gl::Context *context, GLenum pname)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400895{
896 switch (pname)
897 {
898 case GL_TEXTURE_MIN_FILTER:
899 case GL_TEXTURE_MAG_FILTER:
900 case GL_TEXTURE_WRAP_S:
901 case GL_TEXTURE_WRAP_T:
902 case GL_TEXTURE_WRAP_R:
903 case GL_TEXTURE_MIN_LOD:
904 case GL_TEXTURE_MAX_LOD:
905 case GL_TEXTURE_COMPARE_MODE:
906 case GL_TEXTURE_COMPARE_FUNC:
907 return true;
908
909 default:
Geoff Langb1196682014-07-23 13:47:29 -0400910 context->recordError(Error(GL_INVALID_ENUM));
911 return false;
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400912 }
913}
914
Jamie Madill26e91952014-03-05 15:01:27 -0500915bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsizei width, GLsizei height,
916 GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels)
917{
Shannon Woods53a94a82014-06-24 15:20:36 -0400918 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madill893ab082014-05-16 16:56:10 -0400919 ASSERT(framebuffer);
Jamie Madill26e91952014-03-05 15:01:27 -0500920
921 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
922 {
Geoff Langb1196682014-07-23 13:47:29 -0400923 context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
924 return false;
Jamie Madill26e91952014-03-05 15:01:27 -0500925 }
926
Shannon Woods53a94a82014-06-24 15:20:36 -0400927 if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
Jamie Madill26e91952014-03-05 15:01:27 -0500928 {
Geoff Langb1196682014-07-23 13:47:29 -0400929 context->recordError(Error(GL_INVALID_OPERATION));
930 return false;
Jamie Madill26e91952014-03-05 15:01:27 -0500931 }
932
Jamie Madill893ab082014-05-16 16:56:10 -0400933 if (!framebuffer->getReadColorbuffer())
934 {
Geoff Langb1196682014-07-23 13:47:29 -0400935 context->recordError(Error(GL_INVALID_OPERATION));
936 return false;
Jamie Madill893ab082014-05-16 16:56:10 -0400937 }
938
Jamie Madill26e91952014-03-05 15:01:27 -0500939 GLenum currentInternalFormat, currentFormat, currentType;
Geoff Lange4a492b2014-06-19 14:14:41 -0400940 GLuint clientVersion = context->getClientVersion();
Jamie Madill26e91952014-03-05 15:01:27 -0500941
Jamie Madill893ab082014-05-16 16:56:10 -0400942 context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType);
Jamie Madill26e91952014-03-05 15:01:27 -0500943
Geoff Langbdc9b2f2014-04-16 14:41:54 -0400944 bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) :
945 ValidES3ReadFormatType(context, currentInternalFormat, format, type);
Jamie Madill26e91952014-03-05 15:01:27 -0500946
947 if (!(currentFormat == format && currentType == type) && !validReadFormat)
948 {
Geoff Langb1196682014-07-23 13:47:29 -0400949 context->recordError(Error(GL_INVALID_OPERATION));
950 return false;
Jamie Madill26e91952014-03-05 15:01:27 -0500951 }
952
Geoff Lang5d601382014-07-22 15:14:06 -0400953 GLenum sizedInternalFormat = GetSizedInternalFormat(format, type);
954 const InternalFormat &sizedFormatInfo = GetInternalFormatInfo(sizedInternalFormat);
Jamie Madill26e91952014-03-05 15:01:27 -0500955
Geoff Lang5d601382014-07-22 15:14:06 -0400956 GLsizei outputPitch = sizedFormatInfo.computeRowPitch(type, width, context->getState().getPackAlignment());
Jamie Madill26e91952014-03-05 15:01:27 -0500957 // sized query sanity check
958 if (bufSize)
959 {
960 int requiredSize = outputPitch * height;
961 if (requiredSize > *bufSize)
962 {
Geoff Langb1196682014-07-23 13:47:29 -0400963 context->recordError(Error(GL_INVALID_OPERATION));
964 return false;
Jamie Madill26e91952014-03-05 15:01:27 -0500965 }
966 }
967
968 return true;
969}
970
Jamie Madilldb2f14c2014-05-13 13:56:30 -0400971bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id)
972{
973 if (!ValidQueryType(context, target))
974 {
Geoff Langb1196682014-07-23 13:47:29 -0400975 context->recordError(Error(GL_INVALID_ENUM));
976 return false;
Jamie Madilldb2f14c2014-05-13 13:56:30 -0400977 }
978
979 if (id == 0)
980 {
Geoff Langb1196682014-07-23 13:47:29 -0400981 context->recordError(Error(GL_INVALID_OPERATION));
982 return false;
Jamie Madilldb2f14c2014-05-13 13:56:30 -0400983 }
984
985 // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id>
986 // of zero, if the active query object name for <target> is non-zero (for the
987 // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if
988 // the active query for either target is non-zero), if <id> is the name of an
989 // existing query object whose type does not match <target>, or if <id> is the
990 // active query object name for any query type, the error INVALID_OPERATION is
991 // generated.
992
993 // Ensure no other queries are active
994 // NOTE: If other queries than occlusion are supported, we will need to check
995 // separately that:
996 // a) The query ID passed is not the current active query for any target/type
997 // b) There are no active queries for the requested target (and in the case
998 // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
999 // no query may be active for either if glBeginQuery targets either.
Shannon Woods53a94a82014-06-24 15:20:36 -04001000 if (context->getState().isQueryActive())
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001001 {
Geoff Langb1196682014-07-23 13:47:29 -04001002 context->recordError(Error(GL_INVALID_OPERATION));
1003 return false;
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001004 }
1005
1006 Query *queryObject = context->getQuery(id, true, target);
1007
1008 // check that name was obtained with glGenQueries
1009 if (!queryObject)
1010 {
Geoff Langb1196682014-07-23 13:47:29 -04001011 context->recordError(Error(GL_INVALID_OPERATION));
1012 return false;
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001013 }
1014
1015 // check for type mismatch
1016 if (queryObject->getType() != target)
1017 {
Geoff Langb1196682014-07-23 13:47:29 -04001018 context->recordError(Error(GL_INVALID_OPERATION));
1019 return false;
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001020 }
1021
1022 return true;
1023}
1024
Jamie Madill45c785d2014-05-13 14:09:34 -04001025bool ValidateEndQuery(gl::Context *context, GLenum target)
1026{
1027 if (!ValidQueryType(context, target))
1028 {
Geoff Langb1196682014-07-23 13:47:29 -04001029 context->recordError(Error(GL_INVALID_ENUM));
1030 return false;
Jamie Madill45c785d2014-05-13 14:09:34 -04001031 }
1032
Shannon Woods53a94a82014-06-24 15:20:36 -04001033 const Query *queryObject = context->getState().getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001034
1035 if (queryObject == NULL)
1036 {
Geoff Langb1196682014-07-23 13:47:29 -04001037 context->recordError(Error(GL_INVALID_OPERATION));
1038 return false;
Jamie Madill45c785d2014-05-13 14:09:34 -04001039 }
1040
1041 if (!queryObject->isStarted())
1042 {
Geoff Langb1196682014-07-23 13:47:29 -04001043 context->recordError(Error(GL_INVALID_OPERATION));
1044 return false;
Jamie Madill45c785d2014-05-13 14:09:34 -04001045 }
1046
1047 return true;
1048}
1049
Jamie Madill36398922014-05-20 14:51:53 -04001050static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType,
1051 GLint location, GLsizei count, LinkedUniform **uniformOut)
Jamie Madilld7c7bb22014-05-20 10:55:54 -04001052{
1053 if (count < 0)
1054 {
Geoff Langb1196682014-07-23 13:47:29 -04001055 context->recordError(Error(GL_INVALID_VALUE));
1056 return false;
Jamie Madilld7c7bb22014-05-20 10:55:54 -04001057 }
1058
Shannon Woods53a94a82014-06-24 15:20:36 -04001059 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
Jamie Madilld7c7bb22014-05-20 10:55:54 -04001060 if (!programBinary)
1061 {
Geoff Langb1196682014-07-23 13:47:29 -04001062 context->recordError(Error(GL_INVALID_OPERATION));
1063 return false;
Jamie Madilld7c7bb22014-05-20 10:55:54 -04001064 }
1065
1066 if (location == -1)
1067 {
1068 // Silently ignore the uniform command
1069 return false;
1070 }
1071
Jamie Madill36398922014-05-20 14:51:53 -04001072 if (!programBinary->isValidUniformLocation(location))
1073 {
Geoff Langb1196682014-07-23 13:47:29 -04001074 context->recordError(Error(GL_INVALID_OPERATION));
1075 return false;
Jamie Madill36398922014-05-20 14:51:53 -04001076 }
1077
1078 LinkedUniform *uniform = programBinary->getUniformByLocation(location);
1079
1080 // attempting to write an array to a non-array uniform is an INVALID_OPERATION
1081 if (uniform->elementCount() == 1 && count > 1)
1082 {
Geoff Langb1196682014-07-23 13:47:29 -04001083 context->recordError(Error(GL_INVALID_OPERATION));
1084 return false;
Jamie Madill36398922014-05-20 14:51:53 -04001085 }
1086
1087 *uniformOut = uniform;
Jamie Madilld7c7bb22014-05-20 10:55:54 -04001088 return true;
1089}
1090
Jamie Madillaa981bd2014-05-20 10:55:55 -04001091bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count)
1092{
1093 // Check for ES3 uniform entry points
Jamie Madillf2575982014-06-25 16:04:54 -04001094 if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3)
Jamie Madillaa981bd2014-05-20 10:55:55 -04001095 {
Geoff Langb1196682014-07-23 13:47:29 -04001096 context->recordError(Error(GL_INVALID_OPERATION));
1097 return false;
Jamie Madillaa981bd2014-05-20 10:55:55 -04001098 }
1099
Jamie Madill36398922014-05-20 14:51:53 -04001100 LinkedUniform *uniform = NULL;
1101 if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform))
1102 {
1103 return false;
1104 }
1105
Jamie Madillf2575982014-06-25 16:04:54 -04001106 GLenum targetBoolType = VariableBoolVectorType(uniformType);
Jamie Madill36398922014-05-20 14:51:53 -04001107 bool samplerUniformCheck = (IsSampler(uniform->type) && uniformType == GL_INT);
1108 if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type)
1109 {
Geoff Langb1196682014-07-23 13:47:29 -04001110 context->recordError(Error(GL_INVALID_OPERATION));
1111 return false;
Jamie Madill36398922014-05-20 14:51:53 -04001112 }
1113
1114 return true;
Jamie Madillaa981bd2014-05-20 10:55:55 -04001115}
1116
1117bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count,
1118 GLboolean transpose)
1119{
1120 // Check for ES3 uniform entry points
1121 int rows = VariableRowCount(matrixType);
1122 int cols = VariableColumnCount(matrixType);
1123 if (rows != cols && context->getClientVersion() < 3)
1124 {
Geoff Langb1196682014-07-23 13:47:29 -04001125 context->recordError(Error(GL_INVALID_OPERATION));
1126 return false;
Jamie Madillaa981bd2014-05-20 10:55:55 -04001127 }
1128
1129 if (transpose != GL_FALSE && context->getClientVersion() < 3)
1130 {
Geoff Langb1196682014-07-23 13:47:29 -04001131 context->recordError(Error(GL_INVALID_VALUE));
1132 return false;
Jamie Madillaa981bd2014-05-20 10:55:55 -04001133 }
1134
Jamie Madill36398922014-05-20 14:51:53 -04001135 LinkedUniform *uniform = NULL;
1136 if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform))
1137 {
1138 return false;
1139 }
1140
1141 if (uniform->type != matrixType)
1142 {
Geoff Langb1196682014-07-23 13:47:29 -04001143 context->recordError(Error(GL_INVALID_OPERATION));
1144 return false;
Jamie Madill36398922014-05-20 14:51:53 -04001145 }
1146
1147 return true;
Jamie Madillaa981bd2014-05-20 10:55:55 -04001148}
1149
Jamie Madill893ab082014-05-16 16:56:10 -04001150bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams)
1151{
1152 if (!context->getQueryParameterInfo(pname, nativeType, numParams))
1153 {
Geoff Langb1196682014-07-23 13:47:29 -04001154 context->recordError(Error(GL_INVALID_ENUM));
1155 return false;
Jamie Madill893ab082014-05-16 16:56:10 -04001156 }
1157
1158 if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15)
1159 {
1160 unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0);
1161
Geoff Langaae65a42014-05-26 12:43:44 -04001162 if (colorAttachment >= context->getCaps().maxDrawBuffers)
Jamie Madill893ab082014-05-16 16:56:10 -04001163 {
Geoff Langb1196682014-07-23 13:47:29 -04001164 context->recordError(Error(GL_INVALID_OPERATION));
1165 return false;
Jamie Madill893ab082014-05-16 16:56:10 -04001166 }
1167 }
1168
1169 switch (pname)
1170 {
1171 case GL_TEXTURE_BINDING_2D:
1172 case GL_TEXTURE_BINDING_CUBE_MAP:
1173 case GL_TEXTURE_BINDING_3D:
1174 case GL_TEXTURE_BINDING_2D_ARRAY:
Geoff Lang3a61c322014-07-10 13:01:54 -04001175 if (context->getState().getActiveSampler() >= context->getCaps().maxCombinedTextureImageUnits)
Jamie Madill893ab082014-05-16 16:56:10 -04001176 {
Geoff Langb1196682014-07-23 13:47:29 -04001177 context->recordError(Error(GL_INVALID_OPERATION));
1178 return false;
Jamie Madill893ab082014-05-16 16:56:10 -04001179 }
1180 break;
1181
1182 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
1183 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
1184 {
Shannon Woods53a94a82014-06-24 15:20:36 -04001185 Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madill893ab082014-05-16 16:56:10 -04001186 ASSERT(framebuffer);
1187 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1188 {
Geoff Langb1196682014-07-23 13:47:29 -04001189 context->recordError(Error(GL_INVALID_OPERATION));
1190 return false;
Jamie Madill893ab082014-05-16 16:56:10 -04001191 }
1192
Jamie Madill3c7fa222014-06-05 13:08:51 -04001193 FramebufferAttachment *attachment = framebuffer->getReadColorbuffer();
1194 if (!attachment)
Jamie Madill893ab082014-05-16 16:56:10 -04001195 {
Geoff Langb1196682014-07-23 13:47:29 -04001196 context->recordError(Error(GL_INVALID_OPERATION));
1197 return false;
Jamie Madill893ab082014-05-16 16:56:10 -04001198 }
1199 }
1200 break;
1201
1202 default:
1203 break;
1204 }
1205
1206 // pname is valid, but there are no parameters to return
1207 if (numParams == 0)
1208 {
1209 return false;
1210 }
1211
1212 return true;
1213}
1214
Jamie Madill560a8d82014-05-21 13:06:20 -04001215bool ValidateCopyTexImageParametersBase(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
1216 GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height,
1217 GLint border, GLenum *textureFormatOut)
1218{
1219
1220 if (!ValidTexture2DDestinationTarget(context, target))
1221 {
Geoff Langb1196682014-07-23 13:47:29 -04001222 context->recordError(Error(GL_INVALID_ENUM));
1223 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001224 }
1225
1226 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
1227 {
Geoff Langb1196682014-07-23 13:47:29 -04001228 context->recordError(Error(GL_INVALID_VALUE));
1229 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001230 }
1231
1232 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1233 {
Geoff Langb1196682014-07-23 13:47:29 -04001234 context->recordError(Error(GL_INVALID_VALUE));
1235 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001236 }
1237
1238 if (border != 0)
1239 {
Geoff Langb1196682014-07-23 13:47:29 -04001240 context->recordError(Error(GL_INVALID_VALUE));
1241 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001242 }
1243
1244 if (!ValidMipLevel(context, target, level))
1245 {
Geoff Langb1196682014-07-23 13:47:29 -04001246 context->recordError(Error(GL_INVALID_VALUE));
1247 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001248 }
1249
Shannon Woods53a94a82014-06-24 15:20:36 -04001250 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madill560a8d82014-05-21 13:06:20 -04001251 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1252 {
Geoff Langb1196682014-07-23 13:47:29 -04001253 context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
1254 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001255 }
1256
Shannon Woods53a94a82014-06-24 15:20:36 -04001257 if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
Jamie Madill560a8d82014-05-21 13:06:20 -04001258 {
Geoff Langb1196682014-07-23 13:47:29 -04001259 context->recordError(Error(GL_INVALID_OPERATION));
1260 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001261 }
1262
Geoff Langaae65a42014-05-26 12:43:44 -04001263 const gl::Caps &caps = context->getCaps();
1264
Jamie Madill560a8d82014-05-21 13:06:20 -04001265 gl::Texture *texture = NULL;
1266 GLenum textureInternalFormat = GL_NONE;
Jamie Madill560a8d82014-05-21 13:06:20 -04001267 GLint textureLevelWidth = 0;
1268 GLint textureLevelHeight = 0;
1269 GLint textureLevelDepth = 0;
Geoff Langaae65a42014-05-26 12:43:44 -04001270 GLuint maxDimension = 0;
Jamie Madill560a8d82014-05-21 13:06:20 -04001271
1272 switch (target)
1273 {
1274 case GL_TEXTURE_2D:
1275 {
1276 gl::Texture2D *texture2d = context->getTexture2D();
1277 if (texture2d)
1278 {
1279 textureInternalFormat = texture2d->getInternalFormat(level);
Jamie Madill560a8d82014-05-21 13:06:20 -04001280 textureLevelWidth = texture2d->getWidth(level);
1281 textureLevelHeight = texture2d->getHeight(level);
1282 textureLevelDepth = 1;
1283 texture = texture2d;
Geoff Langaae65a42014-05-26 12:43:44 -04001284 maxDimension = caps.max2DTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001285 }
1286 }
1287 break;
1288
1289 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1290 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1291 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1292 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1293 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1294 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1295 {
1296 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1297 if (textureCube)
1298 {
1299 textureInternalFormat = textureCube->getInternalFormat(target, level);
Jamie Madill560a8d82014-05-21 13:06:20 -04001300 textureLevelWidth = textureCube->getWidth(target, level);
1301 textureLevelHeight = textureCube->getHeight(target, level);
1302 textureLevelDepth = 1;
1303 texture = textureCube;
Geoff Langaae65a42014-05-26 12:43:44 -04001304 maxDimension = caps.maxCubeMapTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001305 }
1306 }
1307 break;
1308
1309 case GL_TEXTURE_2D_ARRAY:
1310 {
1311 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1312 if (texture2dArray)
1313 {
1314 textureInternalFormat = texture2dArray->getInternalFormat(level);
Jamie Madill560a8d82014-05-21 13:06:20 -04001315 textureLevelWidth = texture2dArray->getWidth(level);
1316 textureLevelHeight = texture2dArray->getHeight(level);
1317 textureLevelDepth = texture2dArray->getLayers(level);
1318 texture = texture2dArray;
Geoff Langaae65a42014-05-26 12:43:44 -04001319 maxDimension = caps.max2DTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001320 }
1321 }
1322 break;
1323
1324 case GL_TEXTURE_3D:
1325 {
1326 gl::Texture3D *texture3d = context->getTexture3D();
1327 if (texture3d)
1328 {
1329 textureInternalFormat = texture3d->getInternalFormat(level);
Jamie Madill560a8d82014-05-21 13:06:20 -04001330 textureLevelWidth = texture3d->getWidth(level);
1331 textureLevelHeight = texture3d->getHeight(level);
1332 textureLevelDepth = texture3d->getDepth(level);
1333 texture = texture3d;
Geoff Langaae65a42014-05-26 12:43:44 -04001334 maxDimension = caps.max3DTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001335 }
1336 }
1337 break;
1338
1339 default:
Geoff Langb1196682014-07-23 13:47:29 -04001340 context->recordError(Error(GL_INVALID_ENUM));
1341 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001342 }
1343
1344 if (!texture)
1345 {
Geoff Langb1196682014-07-23 13:47:29 -04001346 context->recordError(Error(GL_INVALID_OPERATION));
1347 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001348 }
1349
1350 if (texture->isImmutable() && !isSubImage)
1351 {
Geoff Langb1196682014-07-23 13:47:29 -04001352 context->recordError(Error(GL_INVALID_OPERATION));
1353 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001354 }
1355
Geoff Lang5d601382014-07-22 15:14:06 -04001356 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
1357
1358 if (formatInfo.depthBits > 0)
Jamie Madill560a8d82014-05-21 13:06:20 -04001359 {
Geoff Langb1196682014-07-23 13:47:29 -04001360 context->recordError(Error(GL_INVALID_OPERATION));
1361 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001362 }
1363
Geoff Lang5d601382014-07-22 15:14:06 -04001364 if (formatInfo.compressed)
Jamie Madill560a8d82014-05-21 13:06:20 -04001365 {
Geoff Lang5d601382014-07-22 15:14:06 -04001366 if (((width % formatInfo.compressedBlockWidth) != 0 && width != textureLevelWidth) ||
1367 ((height % formatInfo.compressedBlockHeight) != 0 && height != textureLevelHeight))
Jamie Madill560a8d82014-05-21 13:06:20 -04001368 {
Geoff Langb1196682014-07-23 13:47:29 -04001369 context->recordError(Error(GL_INVALID_OPERATION));
1370 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001371 }
1372 }
1373
1374 if (isSubImage)
1375 {
1376 if (xoffset + width > textureLevelWidth ||
1377 yoffset + height > textureLevelHeight ||
1378 zoffset >= textureLevelDepth)
1379 {
Geoff Langb1196682014-07-23 13:47:29 -04001380 context->recordError(Error(GL_INVALID_VALUE));
1381 return false;
Jamie Madill560a8d82014-05-21 13:06:20 -04001382 }
1383 }
Jamie Madill6f38f822014-06-06 17:12:20 -04001384 else
1385 {
1386 if (IsCubemapTextureTarget(target) && width != height)
1387 {
Geoff Langb1196682014-07-23 13:47:29 -04001388 context->recordError(Error(GL_INVALID_VALUE));
1389 return false;
Jamie Madill6f38f822014-06-06 17:12:20 -04001390 }
1391
Geoff Lang5d601382014-07-22 15:14:06 -04001392 if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
Jamie Madill6f38f822014-06-06 17:12:20 -04001393 {
Geoff Langb1196682014-07-23 13:47:29 -04001394 context->recordError(Error(GL_INVALID_ENUM));
1395 return false;
Jamie Madill6f38f822014-06-06 17:12:20 -04001396 }
1397
1398 int maxLevelDimension = (maxDimension >> level);
1399 if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension)
1400 {
Geoff Langb1196682014-07-23 13:47:29 -04001401 context->recordError(Error(GL_INVALID_VALUE));
1402 return false;
Jamie Madill6f38f822014-06-06 17:12:20 -04001403 }
1404 }
Jamie Madill560a8d82014-05-21 13:06:20 -04001405
1406 *textureFormatOut = textureInternalFormat;
1407 return true;
1408}
1409
Geoff Langb1196682014-07-23 13:47:29 -04001410static bool ValidateDrawBase(Context *context, GLenum mode, GLsizei count, GLsizei maxVertex, GLsizei primcount)
Jamie Madill250d33f2014-06-06 17:09:03 -04001411{
Jamie Madill1aeb1312014-06-20 13:21:25 -04001412 switch (mode)
1413 {
1414 case GL_POINTS:
1415 case GL_LINES:
1416 case GL_LINE_LOOP:
1417 case GL_LINE_STRIP:
1418 case GL_TRIANGLES:
1419 case GL_TRIANGLE_STRIP:
1420 case GL_TRIANGLE_FAN:
1421 break;
1422 default:
Geoff Langb1196682014-07-23 13:47:29 -04001423 context->recordError(Error(GL_INVALID_ENUM));
1424 return false;
Jamie Madill1aeb1312014-06-20 13:21:25 -04001425 }
1426
Jamie Madill250d33f2014-06-06 17:09:03 -04001427 if (count < 0)
1428 {
Geoff Langb1196682014-07-23 13:47:29 -04001429 context->recordError(Error(GL_INVALID_VALUE));
1430 return false;
Jamie Madill250d33f2014-06-06 17:09:03 -04001431 }
1432
Geoff Langb1196682014-07-23 13:47:29 -04001433 const State &state = context->getState();
1434
Jamie Madill250d33f2014-06-06 17:09:03 -04001435 // Check for mapped buffers
Jamie Madilld9ba4f72014-08-04 10:47:59 -04001436 if (state.hasMappedBuffer(GL_ARRAY_BUFFER))
Jamie Madill250d33f2014-06-06 17:09:03 -04001437 {
Geoff Langb1196682014-07-23 13:47:29 -04001438 context->recordError(Error(GL_INVALID_OPERATION));
1439 return false;
Jamie Madill250d33f2014-06-06 17:09:03 -04001440 }
1441
Jamie Madilld9ba4f72014-08-04 10:47:59 -04001442 const gl::DepthStencilState &depthStencilState = state.getDepthStencilState();
Jamie Madillac528012014-06-20 13:21:23 -04001443 if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask ||
Jamie Madilld9ba4f72014-08-04 10:47:59 -04001444 state.getStencilRef() != state.getStencilBackRef() ||
Jamie Madillac528012014-06-20 13:21:23 -04001445 depthStencilState.stencilMask != depthStencilState.stencilBackMask)
1446 {
1447 // Note: these separate values are not supported in WebGL, due to D3D's limitations.
1448 // See Section 6.10 of the WebGL 1.0 spec
1449 ERR("This ANGLE implementation does not support separate front/back stencil "
1450 "writemasks, reference values, or stencil mask values.");
Geoff Langb1196682014-07-23 13:47:29 -04001451 context->recordError(Error(GL_INVALID_OPERATION));
1452 return false;
Jamie Madillac528012014-06-20 13:21:23 -04001453 }
1454
Jamie Madilld9ba4f72014-08-04 10:47:59 -04001455 const gl::Framebuffer *fbo = state.getDrawFramebuffer();
Jamie Madill13f7d7d2014-06-20 13:21:27 -04001456 if (!fbo || fbo->completeness() != GL_FRAMEBUFFER_COMPLETE)
1457 {
Geoff Langb1196682014-07-23 13:47:29 -04001458 context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
1459 return false;
Jamie Madill13f7d7d2014-06-20 13:21:27 -04001460 }
1461
Jamie Madilld9ba4f72014-08-04 10:47:59 -04001462 if (state.getCurrentProgramId() == 0)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001463 {
Geoff Langb1196682014-07-23 13:47:29 -04001464 context->recordError(Error(GL_INVALID_OPERATION));
1465 return false;
Jamie Madilld4cfa572014-07-08 10:00:32 -04001466 }
1467
Jamie Madilld9ba4f72014-08-04 10:47:59 -04001468 gl::ProgramBinary *programBinary = state.getCurrentProgramBinary();
Brandon Jones43a53e22014-08-28 16:23:22 -07001469 if (!programBinary->validateSamplers(NULL, context->getCaps()))
Jamie Madilld4cfa572014-07-08 10:00:32 -04001470 {
Geoff Langb1196682014-07-23 13:47:29 -04001471 context->recordError(Error(GL_INVALID_OPERATION));
1472 return false;
Jamie Madilld4cfa572014-07-08 10:00:32 -04001473 }
1474
Jamie Madill2b976812014-08-25 15:47:49 -04001475 // Buffer validations
1476 const VertexArray *vao = state.getVertexArray();
1477 for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
1478 {
1479 const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex);
1480 bool attribActive = (programBinary->getSemanticIndex(attributeIndex) != -1);
1481 if (attribActive && attrib.enabled)
1482 {
1483 gl::Buffer *buffer = attrib.buffer.get();
1484
1485 if (buffer)
1486 {
1487 GLint64 attribStride = static_cast<GLint64>(ComputeVertexAttributeStride(attrib));
1488 GLint64 maxVertexElement = 0;
1489
1490 if (attrib.divisor > 0)
1491 {
1492 maxVertexElement = static_cast<GLint64>(primcount) / static_cast<GLint64>(attrib.divisor);
1493 }
1494 else
1495 {
1496 maxVertexElement = static_cast<GLint64>(maxVertex);
1497 }
1498
1499 GLint64 attribDataSize = maxVertexElement * attribStride;
1500
1501 // [OpenGL ES 3.0.2] section 2.9.4 page 40:
1502 // We can return INVALID_OPERATION if our vertex attribute does not have
1503 // enough backing data.
1504 if (attribDataSize > buffer->getSize())
1505 {
Geoff Langb1196682014-07-23 13:47:29 -04001506 context->recordError(Error(GL_INVALID_OPERATION));
1507 return false;
Jamie Madill2b976812014-08-25 15:47:49 -04001508 }
1509 }
1510 else if (attrib.pointer == NULL)
1511 {
1512 // This is an application error that would normally result in a crash,
1513 // but we catch it and return an error
Geoff Langb1196682014-07-23 13:47:29 -04001514 context->recordError(Error(GL_INVALID_OPERATION, "An enabled vertex array has no buffer and no pointer."));
1515 return false;
Jamie Madill2b976812014-08-25 15:47:49 -04001516 }
1517 }
1518 }
1519
Jamie Madill250d33f2014-06-06 17:09:03 -04001520 // No-op if zero count
1521 return (count > 0);
1522}
1523
Geoff Langb1196682014-07-23 13:47:29 -04001524bool ValidateDrawArrays(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount)
Jamie Madill250d33f2014-06-06 17:09:03 -04001525{
Jamie Madillfd716582014-06-06 17:09:04 -04001526 if (first < 0)
Jamie Madill250d33f2014-06-06 17:09:03 -04001527 {
Geoff Langb1196682014-07-23 13:47:29 -04001528 context->recordError(Error(GL_INVALID_VALUE));
1529 return false;
Jamie Madill250d33f2014-06-06 17:09:03 -04001530 }
1531
Jamie Madilld9ba4f72014-08-04 10:47:59 -04001532 const State &state = context->getState();
1533 gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
Jamie Madillfd716582014-06-06 17:09:04 -04001534 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused() &&
1535 curTransformFeedback->getDrawMode() != mode)
1536 {
1537 // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode
1538 // that does not match the current transform feedback object's draw mode (if transform feedback
1539 // is active), (3.0.2, section 2.14, pg 86)
Geoff Langb1196682014-07-23 13:47:29 -04001540 context->recordError(Error(GL_INVALID_OPERATION));
1541 return false;
Jamie Madillfd716582014-06-06 17:09:04 -04001542 }
1543
Geoff Langb1196682014-07-23 13:47:29 -04001544 if (!ValidateDrawBase(context, mode, count, count, primcount))
Jamie Madillfd716582014-06-06 17:09:04 -04001545 {
1546 return false;
1547 }
1548
1549 return true;
1550}
1551
Geoff Langb1196682014-07-23 13:47:29 -04001552bool ValidateDrawArraysInstanced(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount)
Jamie Madillfd716582014-06-06 17:09:04 -04001553{
1554 if (primcount < 0)
1555 {
Geoff Langb1196682014-07-23 13:47:29 -04001556 context->recordError(Error(GL_INVALID_VALUE));
1557 return false;
Jamie Madillfd716582014-06-06 17:09:04 -04001558 }
1559
Jamie Madill2b976812014-08-25 15:47:49 -04001560 if (!ValidateDrawArrays(context, mode, first, count, primcount))
Jamie Madillfd716582014-06-06 17:09:04 -04001561 {
1562 return false;
1563 }
1564
1565 // No-op if zero primitive count
1566 return (primcount > 0);
1567}
1568
Geoff Langb1196682014-07-23 13:47:29 -04001569bool ValidateDrawElements(Context *context, GLenum mode, GLsizei count, GLenum type,
Jamie Madill2b976812014-08-25 15:47:49 -04001570 const GLvoid* indices, GLsizei primcount, rx::RangeUI *indexRangeOut)
Jamie Madillfd716582014-06-06 17:09:04 -04001571{
Jamie Madill250d33f2014-06-06 17:09:03 -04001572 switch (type)
1573 {
1574 case GL_UNSIGNED_BYTE:
1575 case GL_UNSIGNED_SHORT:
1576 break;
1577 case GL_UNSIGNED_INT:
Geoff Langc0b9ef42014-07-02 10:02:37 -04001578 if (!context->getExtensions().elementIndexUint)
Jamie Madill250d33f2014-06-06 17:09:03 -04001579 {
Geoff Langb1196682014-07-23 13:47:29 -04001580 context->recordError(Error(GL_INVALID_ENUM));
1581 return false;
Jamie Madill250d33f2014-06-06 17:09:03 -04001582 }
1583 break;
1584 default:
Geoff Langb1196682014-07-23 13:47:29 -04001585 context->recordError(Error(GL_INVALID_ENUM));
1586 return false;
Jamie Madill250d33f2014-06-06 17:09:03 -04001587 }
1588
Jamie Madilld9ba4f72014-08-04 10:47:59 -04001589 const State &state = context->getState();
1590
1591 gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
Jamie Madill250d33f2014-06-06 17:09:03 -04001592 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
1593 {
1594 // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced
1595 // while transform feedback is active, (3.0.2, section 2.14, pg 86)
Geoff Langb1196682014-07-23 13:47:29 -04001596 context->recordError(Error(GL_INVALID_OPERATION));
1597 return false;
Jamie Madill250d33f2014-06-06 17:09:03 -04001598 }
1599
1600 // Check for mapped buffers
Jamie Madilld9ba4f72014-08-04 10:47:59 -04001601 if (state.hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER))
Jamie Madill250d33f2014-06-06 17:09:03 -04001602 {
Geoff Langb1196682014-07-23 13:47:29 -04001603 context->recordError(Error(GL_INVALID_OPERATION));
1604 return false;
Jamie Madill250d33f2014-06-06 17:09:03 -04001605 }
1606
Jamie Madill2b976812014-08-25 15:47:49 -04001607 const gl::VertexArray *vao = state.getVertexArray();
1608 const gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer();
1609 if (!indices && !elementArrayBuffer)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001610 {
Geoff Langb1196682014-07-23 13:47:29 -04001611 context->recordError(Error(GL_INVALID_OPERATION));
1612 return false;
Jamie Madilld4cfa572014-07-08 10:00:32 -04001613 }
1614
Jamie Madillae3000b2014-08-25 15:47:51 -04001615 if (elementArrayBuffer)
1616 {
1617 const gl::Type &typeInfo = gl::GetTypeInfo(type);
1618
1619 GLint64 offset = reinterpret_cast<GLint64>(indices);
1620 GLint64 byteCount = static_cast<GLint64>(typeInfo.bytes) * static_cast<GLint64>(count)+offset;
1621
1622 // check for integer overflows
1623 if (static_cast<GLuint>(count) > (std::numeric_limits<GLuint>::max() / typeInfo.bytes) ||
1624 byteCount > static_cast<GLint64>(std::numeric_limits<GLuint>::max()))
1625 {
Geoff Langb1196682014-07-23 13:47:29 -04001626 context->recordError(Error(GL_OUT_OF_MEMORY));
1627 return false;
Jamie Madillae3000b2014-08-25 15:47:51 -04001628 }
1629
1630 // Check for reading past the end of the bound buffer object
1631 if (byteCount > elementArrayBuffer->getSize())
1632 {
Geoff Langb1196682014-07-23 13:47:29 -04001633 context->recordError(Error(GL_INVALID_OPERATION));
1634 return false;
Jamie Madillae3000b2014-08-25 15:47:51 -04001635 }
1636 }
1637 else if (!indices)
1638 {
1639 // Catch this programming error here
Geoff Langb1196682014-07-23 13:47:29 -04001640 context->recordError(Error(GL_INVALID_OPERATION));
1641 return false;
Jamie Madillae3000b2014-08-25 15:47:51 -04001642 }
1643
Jamie Madill2b976812014-08-25 15:47:49 -04001644 // Use max index to validate if our vertex buffers are large enough for the pull.
1645 // TODO: offer fast path, with disabled index validation.
1646 // TODO: also disable index checking on back-ends that are robust to out-of-range accesses.
1647 if (elementArrayBuffer)
1648 {
1649 unsigned int offset = reinterpret_cast<unsigned int>(indices);
1650 if (!elementArrayBuffer->getIndexRangeCache()->findRange(type, offset, count, indexRangeOut, NULL))
1651 {
1652 const void *dataPointer = elementArrayBuffer->getImplementation()->getData();
1653 const uint8_t *offsetPointer = static_cast<const uint8_t *>(dataPointer) + offset;
1654 *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, offsetPointer, count);
1655 }
1656 }
1657 else
1658 {
1659 *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, indices, count);
1660 }
1661
Geoff Langb1196682014-07-23 13:47:29 -04001662 if (!ValidateDrawBase(context, mode, count, static_cast<GLsizei>(indexRangeOut->end), primcount))
Jamie Madillfd716582014-06-06 17:09:04 -04001663 {
1664 return false;
1665 }
1666
1667 return true;
1668}
1669
Geoff Langb1196682014-07-23 13:47:29 -04001670bool ValidateDrawElementsInstanced(Context *context,
Jamie Madill2b976812014-08-25 15:47:49 -04001671 GLenum mode, GLsizei count, GLenum type,
1672 const GLvoid *indices, GLsizei primcount,
1673 rx::RangeUI *indexRangeOut)
Jamie Madillfd716582014-06-06 17:09:04 -04001674{
1675 if (primcount < 0)
1676 {
Geoff Langb1196682014-07-23 13:47:29 -04001677 context->recordError(Error(GL_INVALID_VALUE));
1678 return false;
Jamie Madillfd716582014-06-06 17:09:04 -04001679 }
1680
Jamie Madill2b976812014-08-25 15:47:49 -04001681 if (!ValidateDrawElements(context, mode, count, type, indices, primcount, indexRangeOut))
Jamie Madillfd716582014-06-06 17:09:04 -04001682 {
1683 return false;
1684 }
1685
1686 // No-op zero primitive count
1687 return (primcount > 0);
Jamie Madill250d33f2014-06-06 17:09:03 -04001688}
1689
Geoff Langb1196682014-07-23 13:47:29 -04001690bool ValidateFramebufferTextureBase(Context *context, GLenum target, GLenum attachment,
Jamie Madill55ec3b12014-07-03 10:38:57 -04001691 GLuint texture, GLint level)
Jamie Madill570f7c82014-07-03 10:38:54 -04001692{
Jamie Madill55ec3b12014-07-03 10:38:57 -04001693 if (!ValidFramebufferTarget(target))
1694 {
Geoff Langb1196682014-07-23 13:47:29 -04001695 context->recordError(Error(GL_INVALID_ENUM));
1696 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001697 }
1698
1699 if (!ValidateAttachmentTarget(context, attachment))
Jamie Madill570f7c82014-07-03 10:38:54 -04001700 {
1701 return false;
1702 }
1703
Jamie Madill55ec3b12014-07-03 10:38:57 -04001704 if (texture != 0)
1705 {
1706 gl::Texture *tex = context->getTexture(texture);
1707
1708 if (tex == NULL)
1709 {
Geoff Langb1196682014-07-23 13:47:29 -04001710 context->recordError(Error(GL_INVALID_OPERATION));
1711 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001712 }
1713
1714 if (level < 0)
1715 {
Geoff Langb1196682014-07-23 13:47:29 -04001716 context->recordError(Error(GL_INVALID_VALUE));
1717 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001718 }
1719 }
1720
Shannon Woods53a94a82014-06-24 15:20:36 -04001721 const gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1722 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
Jamie Madill55ec3b12014-07-03 10:38:57 -04001723
1724 if (framebufferHandle == 0 || !framebuffer)
1725 {
Geoff Langb1196682014-07-23 13:47:29 -04001726 context->recordError(Error(GL_INVALID_OPERATION));
1727 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001728 }
1729
1730 return true;
1731}
1732
Geoff Langb1196682014-07-23 13:47:29 -04001733bool ValidateFramebufferTexture2D(Context *context, GLenum target, GLenum attachment,
Jamie Madill55ec3b12014-07-03 10:38:57 -04001734 GLenum textarget, GLuint texture, GLint level)
1735{
1736 // Attachments are required to be bound to level 0 in ES2
1737 if (context->getClientVersion() < 3 && level != 0)
1738 {
Geoff Langb1196682014-07-23 13:47:29 -04001739 context->recordError(Error(GL_INVALID_VALUE));
1740 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001741 }
1742
1743 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
Jamie Madill570f7c82014-07-03 10:38:54 -04001744 {
1745 return false;
1746 }
1747
Jamie Madill55ec3b12014-07-03 10:38:57 -04001748 if (texture != 0)
1749 {
1750 gl::Texture *tex = context->getTexture(texture);
1751 ASSERT(tex);
1752
Jamie Madill2a6564e2014-07-11 09:53:19 -04001753 const gl::Caps &caps = context->getCaps();
1754
Jamie Madill55ec3b12014-07-03 10:38:57 -04001755 switch (textarget)
1756 {
1757 case GL_TEXTURE_2D:
1758 {
Jamie Madill2a6564e2014-07-11 09:53:19 -04001759 if (level > gl::log2(caps.max2DTextureSize))
Jamie Madill55ec3b12014-07-03 10:38:57 -04001760 {
Geoff Langb1196682014-07-23 13:47:29 -04001761 context->recordError(Error(GL_INVALID_VALUE));
1762 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001763 }
1764 if (tex->getTarget() != GL_TEXTURE_2D)
1765 {
Geoff Langb1196682014-07-23 13:47:29 -04001766 context->recordError(Error(GL_INVALID_OPERATION));
1767 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001768 }
1769 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
1770 if (tex2d->isCompressed(level))
1771 {
Geoff Langb1196682014-07-23 13:47:29 -04001772 context->recordError(Error(GL_INVALID_OPERATION));
1773 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001774 }
1775 }
1776 break;
1777
1778 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1779 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1780 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1781 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1782 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1783 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1784 {
Jamie Madill2a6564e2014-07-11 09:53:19 -04001785 if (level > gl::log2(caps.maxCubeMapTextureSize))
Jamie Madill55ec3b12014-07-03 10:38:57 -04001786 {
Geoff Langb1196682014-07-23 13:47:29 -04001787 context->recordError(Error(GL_INVALID_VALUE));
1788 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001789 }
1790 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
1791 {
Geoff Langb1196682014-07-23 13:47:29 -04001792 context->recordError(Error(GL_INVALID_OPERATION));
1793 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001794 }
1795 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
1796 if (texcube->isCompressed(textarget, level))
1797 {
Geoff Langb1196682014-07-23 13:47:29 -04001798 context->recordError(Error(GL_INVALID_OPERATION));
1799 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001800 }
1801 }
1802 break;
1803
1804 default:
Geoff Langb1196682014-07-23 13:47:29 -04001805 context->recordError(Error(GL_INVALID_ENUM));
1806 return false;
Jamie Madill55ec3b12014-07-03 10:38:57 -04001807 }
1808 }
1809
Jamie Madill570f7c82014-07-03 10:38:54 -04001810 return true;
1811}
1812
Geoff Langb1196682014-07-23 13:47:29 -04001813bool ValidateGetUniformBase(Context *context, GLuint program, GLint location)
Jamie Madill0063c512014-08-25 15:47:53 -04001814{
1815 if (program == 0)
1816 {
Geoff Langb1196682014-07-23 13:47:29 -04001817 context->recordError(Error(GL_INVALID_VALUE));
1818 return false;
Jamie Madill0063c512014-08-25 15:47:53 -04001819 }
1820
1821 gl::Program *programObject = context->getProgram(program);
1822
1823 if (!programObject || !programObject->isLinked())
1824 {
Geoff Langb1196682014-07-23 13:47:29 -04001825 context->recordError(Error(GL_INVALID_OPERATION));
1826 return false;
Jamie Madill0063c512014-08-25 15:47:53 -04001827 }
1828
1829 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1830 if (!programBinary)
1831 {
Geoff Langb1196682014-07-23 13:47:29 -04001832 context->recordError(Error(GL_INVALID_OPERATION));
1833 return false;
Jamie Madill0063c512014-08-25 15:47:53 -04001834 }
1835
Jamie Madill549c7fd2014-08-25 15:47:56 -04001836 if (!programBinary->isValidUniformLocation(location))
1837 {
Geoff Langb1196682014-07-23 13:47:29 -04001838 context->recordError(Error(GL_INVALID_OPERATION));
1839 return false;
Jamie Madill549c7fd2014-08-25 15:47:56 -04001840 }
1841
Jamie Madill0063c512014-08-25 15:47:53 -04001842 return true;
1843}
1844
Geoff Langb1196682014-07-23 13:47:29 -04001845bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat* params)
Jamie Madill78f41802014-08-25 15:47:55 -04001846{
1847 return ValidateGetUniformBase(context, program, location);
1848}
1849
Geoff Langb1196682014-07-23 13:47:29 -04001850bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint* params)
Jamie Madill0063c512014-08-25 15:47:53 -04001851{
Jamie Madill78f41802014-08-25 15:47:55 -04001852 return ValidateGetUniformBase(context, program, location);
1853}
1854
Geoff Langb1196682014-07-23 13:47:29 -04001855static bool ValidateSizedGetUniform(Context *context, GLuint program, GLint location, GLsizei bufSize)
Jamie Madill78f41802014-08-25 15:47:55 -04001856{
1857 if (!ValidateGetUniformBase(context, program, location))
Jamie Madill0063c512014-08-25 15:47:53 -04001858 {
Jamie Madill78f41802014-08-25 15:47:55 -04001859 return false;
Jamie Madill0063c512014-08-25 15:47:53 -04001860 }
1861
Jamie Madilla502c742014-08-28 17:19:13 -04001862 gl::Program *programObject = context->getProgram(program);
1863 ASSERT(programObject);
1864 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04001865
Jamie Madill78f41802014-08-25 15:47:55 -04001866 // sized queries -- ensure the provided buffer is large enough
1867 LinkedUniform *uniform = programBinary->getUniformByLocation(location);
1868 size_t requiredBytes = VariableExternalSize(uniform->type);
1869 if (static_cast<size_t>(bufSize) < requiredBytes)
Jamie Madill0063c512014-08-25 15:47:53 -04001870 {
Geoff Langb1196682014-07-23 13:47:29 -04001871 context->recordError(Error(GL_INVALID_OPERATION));
1872 return false;
Jamie Madill0063c512014-08-25 15:47:53 -04001873 }
1874
1875 return true;
1876}
1877
Geoff Langb1196682014-07-23 13:47:29 -04001878bool ValidateGetnUniformfvEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
Jamie Madill0063c512014-08-25 15:47:53 -04001879{
Jamie Madill78f41802014-08-25 15:47:55 -04001880 return ValidateSizedGetUniform(context, program, location, bufSize);
Jamie Madill0063c512014-08-25 15:47:53 -04001881}
1882
Geoff Langb1196682014-07-23 13:47:29 -04001883bool ValidateGetnUniformivEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLint* params)
Jamie Madill0063c512014-08-25 15:47:53 -04001884{
Jamie Madill78f41802014-08-25 15:47:55 -04001885 return ValidateSizedGetUniform(context, program, location, bufSize);
Jamie Madill0063c512014-08-25 15:47:53 -04001886}
1887
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001888}