Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 3 | // 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 Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 10 | #include "libGLESv2/validationES2.h" |
| 11 | #include "libGLESv2/validationES3.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 12 | #include "libGLESv2/Context.h" |
| 13 | #include "libGLESv2/Texture.h" |
| 14 | #include "libGLESv2/Framebuffer.h" |
Jamie Madill | e261b44 | 2014-06-25 12:42:21 -0400 | [diff] [blame] | 15 | #include "libGLESv2/FramebufferAttachment.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 16 | #include "libGLESv2/formatutils.h" |
| 17 | #include "libGLESv2/main.h" |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 18 | #include "libGLESv2/Query.h" |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 19 | #include "libGLESv2/ProgramBinary.h" |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 20 | #include "libGLESv2/TransformFeedback.h" |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 21 | #include "libGLESv2/VertexArray.h" |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 22 | #include "libGLESv2/renderer/BufferImpl.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 23 | |
| 24 | #include "common/mathutil.h" |
| 25 | #include "common/utilities.h" |
| 26 | |
| 27 | namespace gl |
| 28 | { |
| 29 | |
Geoff Lang | 0550d03 | 2014-01-30 11:29:07 -0500 | [diff] [blame] | 30 | bool 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 Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 52 | bool ValidTextureTarget(const Context *context, GLenum target) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 53 | { |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 54 | switch (target) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 55 | { |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 56 | case GL_TEXTURE_2D: |
| 57 | case GL_TEXTURE_CUBE_MAP: |
| 58 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 59 | |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 60 | case GL_TEXTURE_3D: |
| 61 | case GL_TEXTURE_2D_ARRAY: |
| 62 | return (context->getClientVersion() >= 3); |
| 63 | |
| 64 | default: |
| 65 | return false; |
| 66 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 67 | } |
| 68 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 69 | // 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 Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 72 | // Note: duplicate of IsInternalTextureTarget |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 73 | bool 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 Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 93 | bool 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 Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 106 | bool 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 Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 114 | case GL_PIXEL_PACK_BUFFER: |
| 115 | case GL_PIXEL_UNPACK_BUFFER: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 116 | return context->getExtensions().pixelBufferObject; |
Shannon Woods | 158c438 | 2014-05-06 13:00:07 -0400 | [diff] [blame] | 117 | |
Shannon Woods | b380174 | 2014-03-27 14:59:19 -0400 | [diff] [blame] | 118 | case GL_COPY_READ_BUFFER: |
| 119 | case GL_COPY_WRITE_BUFFER: |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 120 | 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 Madill | 70656a6 | 2014-03-05 15:01:26 -0500 | [diff] [blame] | 129 | bool 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 Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 150 | bool ValidMipLevel(const Context *context, GLenum target, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 151 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 152 | size_t maxDimension = 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 153 | switch (target) |
| 154 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 155 | case GL_TEXTURE_2D: maxDimension = context->getCaps().max2DTextureSize; break; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 156 | 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 Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 162 | 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 Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 165 | default: UNREACHABLE(); |
| 166 | } |
| 167 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 168 | return level <= gl::log2(maxDimension); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 169 | } |
| 170 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 171 | bool ValidImageSize(const Context *context, GLenum target, GLint level, |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 172 | GLsizei width, GLsizei height, GLsizei depth) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 173 | { |
| 174 | if (level < 0 || width < 0 || height < 0 || depth < 0) |
| 175 | { |
| 176 | return false; |
| 177 | } |
| 178 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 179 | if (!context->getExtensions().textureNPOT && |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 180 | (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 181 | { |
| 182 | return false; |
| 183 | } |
| 184 | |
| 185 | if (!ValidMipLevel(context, target, level)) |
| 186 | { |
| 187 | return false; |
| 188 | } |
| 189 | |
| 190 | return true; |
| 191 | } |
| 192 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 193 | bool ValidCompressedImageSize(const Context *context, GLenum internalFormat, GLsizei width, GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 194 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 195 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat); |
| 196 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 197 | { |
| 198 | return false; |
| 199 | } |
| 200 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 201 | 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 Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 203 | { |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | return true; |
| 208 | } |
| 209 | |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 210 | bool 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 227 | bool ValidProgram(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 228 | { |
| 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 240 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 241 | return false; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 242 | } |
| 243 | else |
| 244 | { |
| 245 | // No shader/program object has this ID |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 246 | context->recordError(Error(GL_INVALID_VALUE)); |
| 247 | return false; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 251 | bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 252 | { |
| 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 Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 257 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 258 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 259 | context->recordError(Error(GL_INVALID_VALUE)); |
| 260 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 261 | } |
| 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 274 | context->recordError(Error(GL_INVALID_ENUM)); |
| 275 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 276 | } |
| 277 | break; |
| 278 | |
| 279 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 280 | context->recordError(Error(GL_INVALID_ENUM)); |
| 281 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | return true; |
| 286 | } |
| 287 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 288 | bool ValidateRenderbufferStorageParameters(gl::Context *context, GLenum target, GLsizei samples, |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 289 | GLenum internalformat, GLsizei width, GLsizei height, |
| 290 | bool angleExtension) |
| 291 | { |
| 292 | switch (target) |
| 293 | { |
| 294 | case GL_RENDERBUFFER: |
| 295 | break; |
| 296 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 297 | context->recordError(Error(GL_INVALID_ENUM)); |
| 298 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | if (width < 0 || height < 0 || samples < 0) |
| 302 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 303 | context->recordError(Error(GL_INVALID_VALUE)); |
| 304 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 305 | } |
| 306 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 307 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 308 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 309 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 310 | context->recordError(Error(GL_INVALID_ENUM)); |
| 311 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 312 | } |
| 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 Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 318 | if (formatInfo.pixelBytes == 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 319 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 320 | context->recordError(Error(GL_INVALID_ENUM)); |
| 321 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 322 | } |
| 323 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 324 | if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && samples > 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 325 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 326 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 327 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 328 | } |
| 329 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 330 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
Geoff Lang | 6cf8e1b | 2014-07-03 13:03:57 -0400 | [diff] [blame] | 331 | if (!formatCaps.renderable) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 332 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 333 | context->recordError(Error(GL_INVALID_ENUM)); |
| 334 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 335 | } |
| 336 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 337 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 338 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 339 | context->recordError(Error(GL_INVALID_VALUE)); |
| 340 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 341 | } |
| 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 Lang | 5f4c463 | 2014-07-03 13:46:52 -0400 | [diff] [blame] | 349 | ASSERT(context->getExtensions().framebufferMultisample); |
| 350 | if (static_cast<GLuint>(samples) > context->getExtensions().maxSamples) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 351 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 352 | context->recordError(Error(GL_INVALID_VALUE)); |
| 353 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 354 | } |
Geoff Lang | 5f4c463 | 2014-07-03 13:46:52 -0400 | [diff] [blame] | 355 | |
| 356 | // Check if this specific format supports enough samples |
| 357 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 358 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 359 | context->recordError(Error(GL_OUT_OF_MEMORY)); |
| 360 | return false; |
Geoff Lang | 5f4c463 | 2014-07-03 13:46:52 -0400 | [diff] [blame] | 361 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 362 | } |
| 363 | else |
| 364 | { |
Geoff Lang | 5f4c463 | 2014-07-03 13:46:52 -0400 | [diff] [blame] | 365 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 366 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 367 | context->recordError(Error(GL_INVALID_VALUE)); |
| 368 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 372 | GLuint handle = context->getState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 373 | if (handle == 0) |
| 374 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 375 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 376 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | return true; |
| 380 | } |
| 381 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 382 | bool ValidateFramebufferRenderbufferParameters(gl::Context *context, GLenum target, GLenum attachment, |
| 383 | GLenum renderbuffertarget, GLuint renderbuffer) |
| 384 | { |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 385 | if (!ValidFramebufferTarget(target)) |
| 386 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 387 | context->recordError(Error(GL_INVALID_ENUM)); |
| 388 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 389 | } |
| 390 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 391 | gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); |
| 392 | GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id(); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 393 | |
| 394 | if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0)) |
| 395 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 396 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 397 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 398 | } |
| 399 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 400 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 401 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 402 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 403 | } |
| 404 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 405 | // [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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 413 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 414 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 418 | return true; |
| 419 | } |
| 420 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 421 | static bool IsPartialBlit(gl::Context *context, gl::FramebufferAttachment *readBuffer, gl::FramebufferAttachment *writeBuffer, |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 422 | 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 431 | else if (context->getState().isScissorTestEnabled()) |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 432 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 433 | const Rectangle &scissor = context->getState().getScissor(); |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 434 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 435 | return scissor.x > 0 || scissor.y > 0 || |
| 436 | scissor.width < writeBuffer->getWidth() || |
| 437 | scissor.height < writeBuffer->getHeight(); |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 438 | } |
| 439 | else |
| 440 | { |
| 441 | return false; |
| 442 | } |
| 443 | } |
| 444 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 445 | bool ValidateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 446 | 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 456 | context->recordError(Error(GL_INVALID_ENUM)); |
| 457 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 458 | } |
| 459 | break; |
| 460 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 461 | context->recordError(Error(GL_INVALID_ENUM)); |
| 462 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 466 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 467 | context->recordError(Error(GL_INVALID_VALUE)); |
| 468 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 469 | } |
| 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 481 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 482 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 483 | } |
| 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 489 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 490 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 491 | } |
| 492 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 493 | if (context->getState().getReadFramebuffer()->id() == context->getState().getDrawFramebuffer()->id()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 494 | { |
| 495 | if (fromAngleExtension) |
| 496 | { |
| 497 | ERR("Blits with the same source and destination framebuffer are not supported by this " |
| 498 | "implementation."); |
| 499 | } |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 500 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 501 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 502 | } |
| 503 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 504 | gl::Framebuffer *readFramebuffer = context->getState().getReadFramebuffer(); |
| 505 | gl::Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 506 | if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE || |
| 507 | !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 508 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 509 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 510 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | if (drawFramebuffer->getSamples() != 0) |
| 514 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 515 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 516 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 517 | } |
| 518 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 519 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 520 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 521 | if (mask & GL_COLOR_BUFFER_BIT) |
| 522 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 523 | gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
| 524 | gl::FramebufferAttachment *drawColorBuffer = drawFramebuffer->getFirstColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 525 | |
| 526 | if (readColorBuffer && drawColorBuffer) |
| 527 | { |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 528 | GLenum readInternalFormat = readColorBuffer->getActualFormat(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 529 | const InternalFormat &readFormatInfo = GetInternalFormatInfo(readInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 530 | |
| 531 | for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++) |
| 532 | { |
| 533 | if (drawFramebuffer->isEnabledColorAttachment(i)) |
| 534 | { |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 535 | GLenum drawInternalFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 536 | const InternalFormat &drawFormatInfo = GetInternalFormatInfo(drawInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 537 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 538 | // 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 Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 542 | if ( (readFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || readFormatInfo.componentType == GL_SIGNED_NORMALIZED) && |
| 543 | !(drawFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || drawFormatInfo.componentType == GL_SIGNED_NORMALIZED)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 544 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 545 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 546 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 547 | } |
| 548 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 549 | if (readFormatInfo.componentType == GL_UNSIGNED_INT && drawFormatInfo.componentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 550 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 551 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 552 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 553 | } |
| 554 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 555 | if (readFormatInfo.componentType == GL_INT && drawFormatInfo.componentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 556 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 557 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 558 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 559 | } |
| 560 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 561 | if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawInternalFormat || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 562 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 563 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 564 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | } |
| 568 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 569 | if ((readFormatInfo.componentType == GL_INT || readFormatInfo.componentType == GL_UNSIGNED_INT) && filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 570 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 571 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 572 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | if (fromAngleExtension) |
| 576 | { |
| 577 | const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType(); |
| 578 | if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER) |
| 579 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 580 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 581 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 585 | { |
| 586 | if (drawFramebuffer->isEnabledColorAttachment(colorAttachment)) |
| 587 | { |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 588 | FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(colorAttachment); |
| 589 | ASSERT(attachment); |
| 590 | |
| 591 | if (attachment->type() != GL_TEXTURE_2D && attachment->type() != GL_RENDERBUFFER) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 592 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 593 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 594 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 595 | } |
| 596 | |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 597 | if (attachment->getActualFormat() != readColorBuffer->getActualFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 598 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 599 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 600 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | } |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 604 | if (readFramebuffer->getSamples() != 0 && IsPartialBlit(context, readColorBuffer, drawColorBuffer, |
| 605 | srcX0, srcY0, srcX1, srcY1, |
| 606 | dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 607 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 608 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 609 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 616 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 617 | gl::FramebufferAttachment *readDepthBuffer = readFramebuffer->getDepthbuffer(); |
| 618 | gl::FramebufferAttachment *drawDepthBuffer = drawFramebuffer->getDepthbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 619 | |
| 620 | if (readDepthBuffer && drawDepthBuffer) |
| 621 | { |
| 622 | if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat()) |
| 623 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 624 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 625 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | if (readDepthBuffer->getSamples() > 0 && !sameBounds) |
| 629 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 630 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 631 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | if (fromAngleExtension) |
| 635 | { |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 636 | if (IsPartialBlit(context, readDepthBuffer, drawDepthBuffer, |
| 637 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 638 | { |
| 639 | ERR("Only whole-buffer depth and stencil blits are supported by this implementation."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 640 | context->recordError(Error(GL_INVALID_OPERATION)); // only whole-buffer copies are permitted |
| 641 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0) |
| 645 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 646 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 647 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | if (mask & GL_STENCIL_BUFFER_BIT) |
| 654 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 655 | gl::FramebufferAttachment *readStencilBuffer = readFramebuffer->getStencilbuffer(); |
| 656 | gl::FramebufferAttachment *drawStencilBuffer = drawFramebuffer->getStencilbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 657 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 658 | if (readStencilBuffer && drawStencilBuffer) |
| 659 | { |
| 660 | if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat()) |
| 661 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 662 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 663 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | if (readStencilBuffer->getSamples() > 0 && !sameBounds) |
| 667 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 668 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 669 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | if (fromAngleExtension) |
| 673 | { |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 674 | if (IsPartialBlit(context, readStencilBuffer, drawStencilBuffer, |
| 675 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 676 | { |
| 677 | ERR("Only whole-buffer depth and stencil blits are supported by this implementation."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 678 | context->recordError(Error(GL_INVALID_OPERATION)); // only whole-buffer copies are permitted |
| 679 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0) |
| 683 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 684 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 685 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | return true; |
| 692 | } |
| 693 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 694 | bool ValidateGetVertexAttribParameters(Context *context, GLenum pname) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 695 | { |
| 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 714 | if (context->getClientVersion() < 3) |
| 715 | { |
| 716 | context->recordError(Error(GL_INVALID_ENUM)); |
| 717 | return false; |
| 718 | } |
| 719 | return true; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 720 | |
| 721 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 722 | context->recordError(Error(GL_INVALID_ENUM)); |
| 723 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 724 | } |
| 725 | } |
| 726 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 727 | bool ValidateTexParamParameters(gl::Context *context, GLenum pname, GLint param) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 728 | { |
| 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 744 | context->recordError(Error(GL_INVALID_ENUM)); |
| 745 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 746 | } |
| 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 764 | context->recordError(Error(GL_INVALID_ENUM)); |
| 765 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 766 | } |
| 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 779 | context->recordError(Error(GL_INVALID_ENUM)); |
| 780 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 781 | } |
| 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 791 | context->recordError(Error(GL_INVALID_ENUM)); |
| 792 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 793 | } |
| 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 803 | context->recordError(Error(GL_INVALID_ENUM)); |
| 804 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 805 | } |
| 806 | break; |
| 807 | |
| 808 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 809 | if (!context->getExtensions().textureFilterAnisotropic) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 810 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 811 | context->recordError(Error(GL_INVALID_ENUM)); |
| 812 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | // we assume the parameter passed to this validation method is truncated, not rounded |
| 816 | if (param < 1) |
| 817 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 818 | context->recordError(Error(GL_INVALID_VALUE)); |
| 819 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 820 | } |
| 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 Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 829 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 830 | switch (param) |
| 831 | { |
| 832 | case GL_NONE: |
| 833 | case GL_COMPARE_REF_TO_TEXTURE: |
| 834 | return true; |
| 835 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 836 | context->recordError(Error(GL_INVALID_ENUM)); |
| 837 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 838 | } |
| 839 | break; |
| 840 | |
| 841 | case GL_TEXTURE_COMPARE_FUNC: |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 842 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 843 | 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 855 | context->recordError(Error(GL_INVALID_ENUM)); |
| 856 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 857 | } |
| 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 Lang | bc90a48 | 2013-09-17 16:51:27 -0400 | [diff] [blame] | 864 | 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 874 | context->recordError(Error(GL_INVALID_ENUM)); |
| 875 | return false; |
Geoff Lang | bc90a48 | 2013-09-17 16:51:27 -0400 | [diff] [blame] | 876 | } |
| 877 | break; |
| 878 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 879 | case GL_TEXTURE_BASE_LEVEL: |
| 880 | case GL_TEXTURE_MAX_LEVEL: |
Nicolas Capens | 8de6828 | 2014-04-04 11:10:27 -0400 | [diff] [blame] | 881 | if (param < 0) |
| 882 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 883 | context->recordError(Error(GL_INVALID_VALUE)); |
| 884 | return false; |
Nicolas Capens | 8de6828 | 2014-04-04 11:10:27 -0400 | [diff] [blame] | 885 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 886 | return true; |
| 887 | |
| 888 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 889 | context->recordError(Error(GL_INVALID_ENUM)); |
| 890 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 894 | bool ValidateSamplerObjectParameter(gl::Context *context, GLenum pname) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 895 | { |
| 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 Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 910 | context->recordError(Error(GL_INVALID_ENUM)); |
| 911 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 915 | bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsizei width, GLsizei height, |
| 916 | GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels) |
| 917 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 918 | gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 919 | ASSERT(framebuffer); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 920 | |
| 921 | if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 922 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 923 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 924 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 925 | } |
| 926 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 927 | if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 928 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 929 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 930 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 931 | } |
| 932 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 933 | if (!framebuffer->getReadColorbuffer()) |
| 934 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 935 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 936 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 937 | } |
| 938 | |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 939 | GLenum currentInternalFormat, currentFormat, currentType; |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 940 | GLuint clientVersion = context->getClientVersion(); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 941 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 942 | context->getCurrentReadFormatType(¤tInternalFormat, ¤tFormat, ¤tType); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 943 | |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 944 | bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) : |
| 945 | ValidES3ReadFormatType(context, currentInternalFormat, format, type); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 946 | |
| 947 | if (!(currentFormat == format && currentType == type) && !validReadFormat) |
| 948 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 949 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 950 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 951 | } |
| 952 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 953 | GLenum sizedInternalFormat = GetSizedInternalFormat(format, type); |
| 954 | const InternalFormat &sizedFormatInfo = GetInternalFormatInfo(sizedInternalFormat); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 955 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 956 | GLsizei outputPitch = sizedFormatInfo.computeRowPitch(type, width, context->getState().getPackAlignment()); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 957 | // sized query sanity check |
| 958 | if (bufSize) |
| 959 | { |
| 960 | int requiredSize = outputPitch * height; |
| 961 | if (requiredSize > *bufSize) |
| 962 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 963 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 964 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | |
| 968 | return true; |
| 969 | } |
| 970 | |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 971 | bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id) |
| 972 | { |
| 973 | if (!ValidQueryType(context, target)) |
| 974 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 975 | context->recordError(Error(GL_INVALID_ENUM)); |
| 976 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | if (id == 0) |
| 980 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 981 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 982 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 983 | } |
| 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 Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1000 | if (context->getState().isQueryActive()) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1001 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1002 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1003 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | Query *queryObject = context->getQuery(id, true, target); |
| 1007 | |
| 1008 | // check that name was obtained with glGenQueries |
| 1009 | if (!queryObject) |
| 1010 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1011 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1012 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | // check for type mismatch |
| 1016 | if (queryObject->getType() != target) |
| 1017 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1018 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1019 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | return true; |
| 1023 | } |
| 1024 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1025 | bool ValidateEndQuery(gl::Context *context, GLenum target) |
| 1026 | { |
| 1027 | if (!ValidQueryType(context, target)) |
| 1028 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1029 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1030 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1031 | } |
| 1032 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1033 | const Query *queryObject = context->getState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1034 | |
| 1035 | if (queryObject == NULL) |
| 1036 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1037 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1038 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1039 | } |
| 1040 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1041 | return true; |
| 1042 | } |
| 1043 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1044 | static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType, |
| 1045 | GLint location, GLsizei count, LinkedUniform **uniformOut) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1046 | { |
| 1047 | if (count < 0) |
| 1048 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1049 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1050 | return false; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1051 | } |
| 1052 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1053 | gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary(); |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1054 | if (!programBinary) |
| 1055 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1056 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1057 | return false; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | if (location == -1) |
| 1061 | { |
| 1062 | // Silently ignore the uniform command |
| 1063 | return false; |
| 1064 | } |
| 1065 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1066 | if (!programBinary->isValidUniformLocation(location)) |
| 1067 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1068 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1069 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | LinkedUniform *uniform = programBinary->getUniformByLocation(location); |
| 1073 | |
| 1074 | // attempting to write an array to a non-array uniform is an INVALID_OPERATION |
| 1075 | if (uniform->elementCount() == 1 && count > 1) |
| 1076 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1077 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1078 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | *uniformOut = uniform; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1082 | return true; |
| 1083 | } |
| 1084 | |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1085 | bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count) |
| 1086 | { |
| 1087 | // Check for ES3 uniform entry points |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1088 | if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1089 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1090 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1091 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1092 | } |
| 1093 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1094 | LinkedUniform *uniform = NULL; |
| 1095 | if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform)) |
| 1096 | { |
| 1097 | return false; |
| 1098 | } |
| 1099 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1100 | GLenum targetBoolType = VariableBoolVectorType(uniformType); |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1101 | bool samplerUniformCheck = (IsSampler(uniform->type) && uniformType == GL_INT); |
| 1102 | if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type) |
| 1103 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1104 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1105 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count, |
| 1112 | GLboolean transpose) |
| 1113 | { |
| 1114 | // Check for ES3 uniform entry points |
| 1115 | int rows = VariableRowCount(matrixType); |
| 1116 | int cols = VariableColumnCount(matrixType); |
| 1117 | if (rows != cols && context->getClientVersion() < 3) |
| 1118 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1119 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1120 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | if (transpose != GL_FALSE && context->getClientVersion() < 3) |
| 1124 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1125 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1126 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1127 | } |
| 1128 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1129 | LinkedUniform *uniform = NULL; |
| 1130 | if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform)) |
| 1131 | { |
| 1132 | return false; |
| 1133 | } |
| 1134 | |
| 1135 | if (uniform->type != matrixType) |
| 1136 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1137 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1138 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1142 | } |
| 1143 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1144 | bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
| 1145 | { |
| 1146 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 1147 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1148 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1149 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 1153 | { |
| 1154 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 1155 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1156 | if (colorAttachment >= context->getCaps().maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1157 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1158 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1159 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | switch (pname) |
| 1164 | { |
| 1165 | case GL_TEXTURE_BINDING_2D: |
| 1166 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1167 | case GL_TEXTURE_BINDING_3D: |
| 1168 | case GL_TEXTURE_BINDING_2D_ARRAY: |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 1169 | if (context->getState().getActiveSampler() >= context->getCaps().maxCombinedTextureImageUnits) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1170 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1171 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1172 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1173 | } |
| 1174 | break; |
| 1175 | |
| 1176 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1177 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1178 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1179 | Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1180 | ASSERT(framebuffer); |
| 1181 | if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1182 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1183 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1184 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1185 | } |
| 1186 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 1187 | FramebufferAttachment *attachment = framebuffer->getReadColorbuffer(); |
| 1188 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1189 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1190 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1191 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | break; |
| 1195 | |
| 1196 | default: |
| 1197 | break; |
| 1198 | } |
| 1199 | |
| 1200 | // pname is valid, but there are no parameters to return |
| 1201 | if (numParams == 0) |
| 1202 | { |
| 1203 | return false; |
| 1204 | } |
| 1205 | |
| 1206 | return true; |
| 1207 | } |
| 1208 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1209 | bool ValidateCopyTexImageParametersBase(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage, |
| 1210 | GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, |
| 1211 | GLint border, GLenum *textureFormatOut) |
| 1212 | { |
| 1213 | |
| 1214 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1215 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1216 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1217 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0) |
| 1221 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1222 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1223 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1227 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1228 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1229 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | if (border != 0) |
| 1233 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1234 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1235 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | if (!ValidMipLevel(context, target, level)) |
| 1239 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1240 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1241 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1242 | } |
| 1243 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1244 | gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1245 | if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1246 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1247 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 1248 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1249 | } |
| 1250 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1251 | if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1252 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1253 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1254 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1255 | } |
| 1256 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1257 | const gl::Caps &caps = context->getCaps(); |
| 1258 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1259 | gl::Texture *texture = NULL; |
| 1260 | GLenum textureInternalFormat = GL_NONE; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1261 | GLint textureLevelWidth = 0; |
| 1262 | GLint textureLevelHeight = 0; |
| 1263 | GLint textureLevelDepth = 0; |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1264 | GLuint maxDimension = 0; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1265 | |
| 1266 | switch (target) |
| 1267 | { |
| 1268 | case GL_TEXTURE_2D: |
| 1269 | { |
| 1270 | gl::Texture2D *texture2d = context->getTexture2D(); |
| 1271 | if (texture2d) |
| 1272 | { |
| 1273 | textureInternalFormat = texture2d->getInternalFormat(level); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1274 | textureLevelWidth = texture2d->getWidth(level); |
| 1275 | textureLevelHeight = texture2d->getHeight(level); |
| 1276 | textureLevelDepth = 1; |
| 1277 | texture = texture2d; |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1278 | maxDimension = caps.max2DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1279 | } |
| 1280 | } |
| 1281 | break; |
| 1282 | |
| 1283 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1284 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1285 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1286 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1287 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1288 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1289 | { |
| 1290 | gl::TextureCubeMap *textureCube = context->getTextureCubeMap(); |
| 1291 | if (textureCube) |
| 1292 | { |
| 1293 | textureInternalFormat = textureCube->getInternalFormat(target, level); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1294 | textureLevelWidth = textureCube->getWidth(target, level); |
| 1295 | textureLevelHeight = textureCube->getHeight(target, level); |
| 1296 | textureLevelDepth = 1; |
| 1297 | texture = textureCube; |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1298 | maxDimension = caps.maxCubeMapTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1299 | } |
| 1300 | } |
| 1301 | break; |
| 1302 | |
| 1303 | case GL_TEXTURE_2D_ARRAY: |
| 1304 | { |
| 1305 | gl::Texture2DArray *texture2dArray = context->getTexture2DArray(); |
| 1306 | if (texture2dArray) |
| 1307 | { |
| 1308 | textureInternalFormat = texture2dArray->getInternalFormat(level); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1309 | textureLevelWidth = texture2dArray->getWidth(level); |
| 1310 | textureLevelHeight = texture2dArray->getHeight(level); |
| 1311 | textureLevelDepth = texture2dArray->getLayers(level); |
| 1312 | texture = texture2dArray; |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1313 | maxDimension = caps.max2DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | break; |
| 1317 | |
| 1318 | case GL_TEXTURE_3D: |
| 1319 | { |
| 1320 | gl::Texture3D *texture3d = context->getTexture3D(); |
| 1321 | if (texture3d) |
| 1322 | { |
| 1323 | textureInternalFormat = texture3d->getInternalFormat(level); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1324 | textureLevelWidth = texture3d->getWidth(level); |
| 1325 | textureLevelHeight = texture3d->getHeight(level); |
| 1326 | textureLevelDepth = texture3d->getDepth(level); |
| 1327 | texture = texture3d; |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1328 | maxDimension = caps.max3DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1329 | } |
| 1330 | } |
| 1331 | break; |
| 1332 | |
| 1333 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1334 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1335 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | if (!texture) |
| 1339 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1340 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1341 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | if (texture->isImmutable() && !isSubImage) |
| 1345 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1346 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1347 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1348 | } |
| 1349 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1350 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 1351 | |
| 1352 | if (formatInfo.depthBits > 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1353 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1354 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1355 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1356 | } |
| 1357 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1358 | if (formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1359 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1360 | if (((width % formatInfo.compressedBlockWidth) != 0 && width != textureLevelWidth) || |
| 1361 | ((height % formatInfo.compressedBlockHeight) != 0 && height != textureLevelHeight)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1362 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1363 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1364 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | if (isSubImage) |
| 1369 | { |
| 1370 | if (xoffset + width > textureLevelWidth || |
| 1371 | yoffset + height > textureLevelHeight || |
| 1372 | zoffset >= textureLevelDepth) |
| 1373 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1374 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1375 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1376 | } |
| 1377 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1378 | else |
| 1379 | { |
| 1380 | if (IsCubemapTextureTarget(target) && width != height) |
| 1381 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1382 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1383 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1384 | } |
| 1385 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1386 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1387 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1388 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1389 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | int maxLevelDimension = (maxDimension >> level); |
| 1393 | if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension) |
| 1394 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1395 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1396 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1397 | } |
| 1398 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1399 | |
| 1400 | *textureFormatOut = textureInternalFormat; |
| 1401 | return true; |
| 1402 | } |
| 1403 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1404 | static bool ValidateDrawBase(Context *context, GLenum mode, GLsizei count, GLsizei maxVertex, GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1405 | { |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1406 | switch (mode) |
| 1407 | { |
| 1408 | case GL_POINTS: |
| 1409 | case GL_LINES: |
| 1410 | case GL_LINE_LOOP: |
| 1411 | case GL_LINE_STRIP: |
| 1412 | case GL_TRIANGLES: |
| 1413 | case GL_TRIANGLE_STRIP: |
| 1414 | case GL_TRIANGLE_FAN: |
| 1415 | break; |
| 1416 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1417 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1418 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1419 | } |
| 1420 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1421 | if (count < 0) |
| 1422 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1423 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1424 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1425 | } |
| 1426 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1427 | const State &state = context->getState(); |
| 1428 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1429 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1430 | if (state.hasMappedBuffer(GL_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1431 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1432 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1433 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1434 | } |
| 1435 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1436 | const gl::DepthStencilState &depthStencilState = state.getDepthStencilState(); |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1437 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1438 | state.getStencilRef() != state.getStencilBackRef() || |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1439 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 1440 | { |
| 1441 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. |
| 1442 | // See Section 6.10 of the WebGL 1.0 spec |
| 1443 | ERR("This ANGLE implementation does not support separate front/back stencil " |
| 1444 | "writemasks, reference values, or stencil mask values."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1445 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1446 | return false; |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1447 | } |
| 1448 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1449 | const gl::Framebuffer *fbo = state.getDrawFramebuffer(); |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1450 | if (!fbo || fbo->completeness() != GL_FRAMEBUFFER_COMPLETE) |
| 1451 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1452 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 1453 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1454 | } |
| 1455 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1456 | if (state.getCurrentProgramId() == 0) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1457 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1458 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1459 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1460 | } |
| 1461 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1462 | gl::ProgramBinary *programBinary = state.getCurrentProgramBinary(); |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 1463 | if (!programBinary->validateSamplers(NULL, context->getCaps())) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1464 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1465 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1466 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1467 | } |
| 1468 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1469 | // Buffer validations |
| 1470 | const VertexArray *vao = state.getVertexArray(); |
| 1471 | for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 1472 | { |
| 1473 | const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex); |
| 1474 | bool attribActive = (programBinary->getSemanticIndex(attributeIndex) != -1); |
| 1475 | if (attribActive && attrib.enabled) |
| 1476 | { |
| 1477 | gl::Buffer *buffer = attrib.buffer.get(); |
| 1478 | |
| 1479 | if (buffer) |
| 1480 | { |
| 1481 | GLint64 attribStride = static_cast<GLint64>(ComputeVertexAttributeStride(attrib)); |
| 1482 | GLint64 maxVertexElement = 0; |
| 1483 | |
| 1484 | if (attrib.divisor > 0) |
| 1485 | { |
| 1486 | maxVertexElement = static_cast<GLint64>(primcount) / static_cast<GLint64>(attrib.divisor); |
| 1487 | } |
| 1488 | else |
| 1489 | { |
| 1490 | maxVertexElement = static_cast<GLint64>(maxVertex); |
| 1491 | } |
| 1492 | |
| 1493 | GLint64 attribDataSize = maxVertexElement * attribStride; |
| 1494 | |
| 1495 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 1496 | // We can return INVALID_OPERATION if our vertex attribute does not have |
| 1497 | // enough backing data. |
| 1498 | if (attribDataSize > buffer->getSize()) |
| 1499 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1500 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1501 | return false; |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | else if (attrib.pointer == NULL) |
| 1505 | { |
| 1506 | // This is an application error that would normally result in a crash, |
| 1507 | // but we catch it and return an error |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1508 | context->recordError(Error(GL_INVALID_OPERATION, "An enabled vertex array has no buffer and no pointer.")); |
| 1509 | return false; |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1510 | } |
| 1511 | } |
| 1512 | } |
| 1513 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1514 | // No-op if zero count |
| 1515 | return (count > 0); |
| 1516 | } |
| 1517 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1518 | bool ValidateDrawArrays(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1519 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1520 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1521 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1522 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1523 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1524 | } |
| 1525 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1526 | const State &state = context->getState(); |
| 1527 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1528 | if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused() && |
| 1529 | curTransformFeedback->getDrawMode() != mode) |
| 1530 | { |
| 1531 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 1532 | // that does not match the current transform feedback object's draw mode (if transform feedback |
| 1533 | // is active), (3.0.2, section 2.14, pg 86) |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1534 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1535 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1536 | } |
| 1537 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1538 | if (!ValidateDrawBase(context, mode, count, count, primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1539 | { |
| 1540 | return false; |
| 1541 | } |
| 1542 | |
| 1543 | return true; |
| 1544 | } |
| 1545 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1546 | bool ValidateDrawArraysInstanced(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1547 | { |
| 1548 | if (primcount < 0) |
| 1549 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1550 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1551 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1552 | } |
| 1553 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1554 | if (!ValidateDrawArrays(context, mode, first, count, primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1555 | { |
| 1556 | return false; |
| 1557 | } |
| 1558 | |
| 1559 | // No-op if zero primitive count |
| 1560 | return (primcount > 0); |
| 1561 | } |
| 1562 | |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1563 | static bool ValidateDrawInstancedANGLE(Context *context) |
| 1564 | { |
| 1565 | // Verify there is at least one active attribute with a divisor of zero |
| 1566 | const gl::State& state = context->getState(); |
| 1567 | |
| 1568 | gl::ProgramBinary *programBinary = state.getCurrentProgramBinary(); |
| 1569 | |
| 1570 | const VertexArray *vao = state.getVertexArray(); |
| 1571 | for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 1572 | { |
| 1573 | const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex); |
| 1574 | bool active = (programBinary->getSemanticIndex(attributeIndex) != -1); |
| 1575 | if (active && attrib.divisor == 0) |
| 1576 | { |
| 1577 | return true; |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | context->recordError(Error(GL_INVALID_OPERATION, "ANGLE_instanced_arrays requires that at least one active attribute" |
| 1582 | "has a divisor of zero.")); |
| 1583 | return false; |
| 1584 | } |
| 1585 | |
| 1586 | bool ValidateDrawArraysInstancedANGLE(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
| 1587 | { |
| 1588 | if (!ValidateDrawInstancedANGLE(context)) |
| 1589 | { |
| 1590 | return false; |
| 1591 | } |
| 1592 | |
| 1593 | return ValidateDrawArraysInstanced(context, mode, first, count, primcount); |
| 1594 | } |
| 1595 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1596 | bool ValidateDrawElements(Context *context, GLenum mode, GLsizei count, GLenum type, |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1597 | const GLvoid* indices, GLsizei primcount, rx::RangeUI *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1598 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1599 | switch (type) |
| 1600 | { |
| 1601 | case GL_UNSIGNED_BYTE: |
| 1602 | case GL_UNSIGNED_SHORT: |
| 1603 | break; |
| 1604 | case GL_UNSIGNED_INT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1605 | if (!context->getExtensions().elementIndexUint) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1606 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1607 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1608 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1609 | } |
| 1610 | break; |
| 1611 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1612 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1613 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1614 | } |
| 1615 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1616 | const State &state = context->getState(); |
| 1617 | |
| 1618 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1619 | if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused()) |
| 1620 | { |
| 1621 | // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced |
| 1622 | // while transform feedback is active, (3.0.2, section 2.14, pg 86) |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1623 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1624 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1628 | if (state.hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1629 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1630 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1631 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1632 | } |
| 1633 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1634 | const gl::VertexArray *vao = state.getVertexArray(); |
| 1635 | const gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer(); |
| 1636 | if (!indices && !elementArrayBuffer) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1637 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1638 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1639 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1640 | } |
| 1641 | |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1642 | if (elementArrayBuffer) |
| 1643 | { |
| 1644 | const gl::Type &typeInfo = gl::GetTypeInfo(type); |
| 1645 | |
| 1646 | GLint64 offset = reinterpret_cast<GLint64>(indices); |
| 1647 | GLint64 byteCount = static_cast<GLint64>(typeInfo.bytes) * static_cast<GLint64>(count)+offset; |
| 1648 | |
| 1649 | // check for integer overflows |
| 1650 | if (static_cast<GLuint>(count) > (std::numeric_limits<GLuint>::max() / typeInfo.bytes) || |
| 1651 | byteCount > static_cast<GLint64>(std::numeric_limits<GLuint>::max())) |
| 1652 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1653 | context->recordError(Error(GL_OUT_OF_MEMORY)); |
| 1654 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | // Check for reading past the end of the bound buffer object |
| 1658 | if (byteCount > elementArrayBuffer->getSize()) |
| 1659 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1660 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1661 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1662 | } |
| 1663 | } |
| 1664 | else if (!indices) |
| 1665 | { |
| 1666 | // Catch this programming error here |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1667 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1668 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1669 | } |
| 1670 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1671 | // Use max index to validate if our vertex buffers are large enough for the pull. |
| 1672 | // TODO: offer fast path, with disabled index validation. |
| 1673 | // TODO: also disable index checking on back-ends that are robust to out-of-range accesses. |
| 1674 | if (elementArrayBuffer) |
| 1675 | { |
| 1676 | unsigned int offset = reinterpret_cast<unsigned int>(indices); |
| 1677 | if (!elementArrayBuffer->getIndexRangeCache()->findRange(type, offset, count, indexRangeOut, NULL)) |
| 1678 | { |
| 1679 | const void *dataPointer = elementArrayBuffer->getImplementation()->getData(); |
| 1680 | const uint8_t *offsetPointer = static_cast<const uint8_t *>(dataPointer) + offset; |
| 1681 | *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, offsetPointer, count); |
| 1682 | } |
| 1683 | } |
| 1684 | else |
| 1685 | { |
| 1686 | *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, indices, count); |
| 1687 | } |
| 1688 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1689 | if (!ValidateDrawBase(context, mode, count, static_cast<GLsizei>(indexRangeOut->end), primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1690 | { |
| 1691 | return false; |
| 1692 | } |
| 1693 | |
| 1694 | return true; |
| 1695 | } |
| 1696 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1697 | bool ValidateDrawElementsInstanced(Context *context, |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1698 | GLenum mode, GLsizei count, GLenum type, |
| 1699 | const GLvoid *indices, GLsizei primcount, |
| 1700 | rx::RangeUI *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1701 | { |
| 1702 | if (primcount < 0) |
| 1703 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1704 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1705 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1706 | } |
| 1707 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1708 | if (!ValidateDrawElements(context, mode, count, type, indices, primcount, indexRangeOut)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1709 | { |
| 1710 | return false; |
| 1711 | } |
| 1712 | |
| 1713 | // No-op zero primitive count |
| 1714 | return (primcount > 0); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1715 | } |
| 1716 | |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1717 | bool ValidateDrawElementsInstancedANGLE(Context *context, GLenum mode, GLsizei count, GLenum type, |
| 1718 | const GLvoid *indices, GLsizei primcount, rx::RangeUI *indexRangeOut) |
| 1719 | { |
| 1720 | if (!ValidateDrawInstancedANGLE(context)) |
| 1721 | { |
| 1722 | return false; |
| 1723 | } |
| 1724 | |
| 1725 | return ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, indexRangeOut); |
| 1726 | } |
| 1727 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1728 | bool ValidateFramebufferTextureBase(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1729 | GLuint texture, GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1730 | { |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1731 | if (!ValidFramebufferTarget(target)) |
| 1732 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1733 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1734 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1738 | { |
| 1739 | return false; |
| 1740 | } |
| 1741 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1742 | if (texture != 0) |
| 1743 | { |
| 1744 | gl::Texture *tex = context->getTexture(texture); |
| 1745 | |
| 1746 | if (tex == NULL) |
| 1747 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1748 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1749 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | if (level < 0) |
| 1753 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1754 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1755 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1756 | } |
| 1757 | } |
| 1758 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1759 | const gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); |
| 1760 | GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id(); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1761 | |
| 1762 | if (framebufferHandle == 0 || !framebuffer) |
| 1763 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1764 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1765 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | return true; |
| 1769 | } |
| 1770 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1771 | bool ValidateFramebufferTexture2D(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1772 | GLenum textarget, GLuint texture, GLint level) |
| 1773 | { |
| 1774 | // Attachments are required to be bound to level 0 in ES2 |
| 1775 | if (context->getClientVersion() < 3 && level != 0) |
| 1776 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1777 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1778 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1782 | { |
| 1783 | return false; |
| 1784 | } |
| 1785 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1786 | if (texture != 0) |
| 1787 | { |
| 1788 | gl::Texture *tex = context->getTexture(texture); |
| 1789 | ASSERT(tex); |
| 1790 | |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1791 | const gl::Caps &caps = context->getCaps(); |
| 1792 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1793 | switch (textarget) |
| 1794 | { |
| 1795 | case GL_TEXTURE_2D: |
| 1796 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1797 | if (level > gl::log2(caps.max2DTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1798 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1799 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1800 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1801 | } |
| 1802 | if (tex->getTarget() != GL_TEXTURE_2D) |
| 1803 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1804 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1805 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1806 | } |
| 1807 | gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex); |
| 1808 | if (tex2d->isCompressed(level)) |
| 1809 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1810 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1811 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1812 | } |
| 1813 | } |
| 1814 | break; |
| 1815 | |
| 1816 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1817 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1818 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1819 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1820 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1821 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1822 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1823 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1824 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1825 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1826 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1827 | } |
| 1828 | if (tex->getTarget() != GL_TEXTURE_CUBE_MAP) |
| 1829 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1830 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1831 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1832 | } |
| 1833 | gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex); |
| 1834 | if (texcube->isCompressed(textarget, level)) |
| 1835 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1836 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1837 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1838 | } |
| 1839 | } |
| 1840 | break; |
| 1841 | |
| 1842 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1843 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1844 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1845 | } |
| 1846 | } |
| 1847 | |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1848 | return true; |
| 1849 | } |
| 1850 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1851 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1852 | { |
| 1853 | if (program == 0) |
| 1854 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1855 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1856 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | gl::Program *programObject = context->getProgram(program); |
| 1860 | |
| 1861 | if (!programObject || !programObject->isLinked()) |
| 1862 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1863 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1864 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | gl::ProgramBinary *programBinary = programObject->getProgramBinary(); |
| 1868 | if (!programBinary) |
| 1869 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1870 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1871 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1872 | } |
| 1873 | |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 1874 | if (!programBinary->isValidUniformLocation(location)) |
| 1875 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1876 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1877 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 1878 | } |
| 1879 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1880 | return true; |
| 1881 | } |
| 1882 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1883 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat* params) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1884 | { |
| 1885 | return ValidateGetUniformBase(context, program, location); |
| 1886 | } |
| 1887 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1888 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1889 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1890 | return ValidateGetUniformBase(context, program, location); |
| 1891 | } |
| 1892 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1893 | static bool ValidateSizedGetUniform(Context *context, GLuint program, GLint location, GLsizei bufSize) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1894 | { |
| 1895 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1896 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1897 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1898 | } |
| 1899 | |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 1900 | gl::Program *programObject = context->getProgram(program); |
| 1901 | ASSERT(programObject); |
| 1902 | gl::ProgramBinary *programBinary = programObject->getProgramBinary(); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1903 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1904 | // sized queries -- ensure the provided buffer is large enough |
| 1905 | LinkedUniform *uniform = programBinary->getUniformByLocation(location); |
| 1906 | size_t requiredBytes = VariableExternalSize(uniform->type); |
| 1907 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1908 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1909 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1910 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | return true; |
| 1914 | } |
| 1915 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1916 | bool ValidateGetnUniformfvEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLfloat* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1917 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1918 | return ValidateSizedGetUniform(context, program, location, bufSize); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1919 | } |
| 1920 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1921 | bool ValidateGetnUniformivEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1922 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1923 | return ValidateSizedGetUniform(context, program, location, bufSize); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1924 | } |
| 1925 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1926 | } |