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 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame^] | 9 | #include "libANGLE/validationES.h" |
| 10 | #include "libANGLE/validationES2.h" |
| 11 | #include "libANGLE/validationES3.h" |
| 12 | #include "libANGLE/Context.h" |
| 13 | #include "libANGLE/Texture.h" |
| 14 | #include "libANGLE/Framebuffer.h" |
| 15 | #include "libANGLE/FramebufferAttachment.h" |
| 16 | #include "libANGLE/formatutils.h" |
| 17 | #include "libANGLE/Query.h" |
| 18 | #include "libANGLE/ProgramBinary.h" |
| 19 | #include "libANGLE/TransformFeedback.h" |
| 20 | #include "libANGLE/VertexArray.h" |
| 21 | #include "libANGLE/renderer/BufferImpl.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 22 | |
| 23 | #include "common/mathutil.h" |
| 24 | #include "common/utilities.h" |
| 25 | |
Jamie Madill | 9ae396b | 2014-10-21 17:46:30 -0400 | [diff] [blame] | 26 | // FIXME(jmadill): remove this when we support buffer data caching |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame^] | 27 | #include "libANGLE/renderer/d3d/BufferD3D.h" |
Jamie Madill | 9ae396b | 2014-10-21 17:46:30 -0400 | [diff] [blame] | 28 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 29 | namespace gl |
| 30 | { |
| 31 | |
Geoff Lang | 0550d03 | 2014-01-30 11:29:07 -0500 | [diff] [blame] | 32 | bool ValidCap(const Context *context, GLenum cap) |
| 33 | { |
| 34 | switch (cap) |
| 35 | { |
| 36 | case GL_CULL_FACE: |
| 37 | case GL_POLYGON_OFFSET_FILL: |
| 38 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 39 | case GL_SAMPLE_COVERAGE: |
| 40 | case GL_SCISSOR_TEST: |
| 41 | case GL_STENCIL_TEST: |
| 42 | case GL_DEPTH_TEST: |
| 43 | case GL_BLEND: |
| 44 | case GL_DITHER: |
| 45 | return true; |
| 46 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 47 | case GL_RASTERIZER_DISCARD: |
| 48 | return (context->getClientVersion() >= 3); |
| 49 | default: |
| 50 | return false; |
| 51 | } |
| 52 | } |
| 53 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 54 | bool ValidTextureTarget(const Context *context, GLenum 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 | switch (target) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 57 | { |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 58 | case GL_TEXTURE_2D: |
| 59 | case GL_TEXTURE_CUBE_MAP: |
| 60 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 61 | |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 62 | case GL_TEXTURE_3D: |
| 63 | case GL_TEXTURE_2D_ARRAY: |
| 64 | return (context->getClientVersion() >= 3); |
| 65 | |
| 66 | default: |
| 67 | return false; |
| 68 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 69 | } |
| 70 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 71 | // This function differs from ValidTextureTarget in that the target must be |
| 72 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 73 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 74 | // Note: duplicate of IsInternalTextureTarget |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 75 | bool ValidTexture2DDestinationTarget(const Context *context, GLenum target) |
| 76 | { |
| 77 | switch (target) |
| 78 | { |
| 79 | case GL_TEXTURE_2D: |
| 80 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 81 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 82 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 83 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 84 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 85 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 86 | return true; |
| 87 | case GL_TEXTURE_2D_ARRAY: |
| 88 | case GL_TEXTURE_3D: |
| 89 | return (context->getClientVersion() >= 3); |
| 90 | default: |
| 91 | return false; |
| 92 | } |
| 93 | } |
| 94 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 95 | bool ValidFramebufferTarget(GLenum target) |
| 96 | { |
| 97 | META_ASSERT(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER); |
| 98 | |
| 99 | switch (target) |
| 100 | { |
| 101 | case GL_FRAMEBUFFER: return true; |
| 102 | case GL_READ_FRAMEBUFFER: return true; |
| 103 | case GL_DRAW_FRAMEBUFFER: return true; |
| 104 | default: return false; |
| 105 | } |
| 106 | } |
| 107 | |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 108 | bool ValidBufferTarget(const Context *context, GLenum target) |
| 109 | { |
| 110 | switch (target) |
| 111 | { |
| 112 | case GL_ARRAY_BUFFER: |
| 113 | case GL_ELEMENT_ARRAY_BUFFER: |
| 114 | return true; |
| 115 | |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 116 | case GL_PIXEL_PACK_BUFFER: |
| 117 | case GL_PIXEL_UNPACK_BUFFER: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 118 | return context->getExtensions().pixelBufferObject; |
Shannon Woods | 158c438 | 2014-05-06 13:00:07 -0400 | [diff] [blame] | 119 | |
Shannon Woods | b380174 | 2014-03-27 14:59:19 -0400 | [diff] [blame] | 120 | case GL_COPY_READ_BUFFER: |
| 121 | case GL_COPY_WRITE_BUFFER: |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 122 | case GL_TRANSFORM_FEEDBACK_BUFFER: |
| 123 | case GL_UNIFORM_BUFFER: |
| 124 | return (context->getClientVersion() >= 3); |
| 125 | |
| 126 | default: |
| 127 | return false; |
| 128 | } |
| 129 | } |
| 130 | |
Jamie Madill | 70656a6 | 2014-03-05 15:01:26 -0500 | [diff] [blame] | 131 | bool ValidBufferParameter(const Context *context, GLenum pname) |
| 132 | { |
| 133 | switch (pname) |
| 134 | { |
| 135 | case GL_BUFFER_USAGE: |
| 136 | case GL_BUFFER_SIZE: |
| 137 | return true; |
| 138 | |
| 139 | // GL_BUFFER_MAP_POINTER is a special case, and may only be |
| 140 | // queried with GetBufferPointerv |
| 141 | case GL_BUFFER_ACCESS_FLAGS: |
| 142 | case GL_BUFFER_MAPPED: |
| 143 | case GL_BUFFER_MAP_OFFSET: |
| 144 | case GL_BUFFER_MAP_LENGTH: |
| 145 | return (context->getClientVersion() >= 3); |
| 146 | |
| 147 | default: |
| 148 | return false; |
| 149 | } |
| 150 | } |
| 151 | |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 152 | bool ValidMipLevel(const Context *context, GLenum target, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 153 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 154 | size_t maxDimension = 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 155 | switch (target) |
| 156 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 157 | case GL_TEXTURE_2D: maxDimension = context->getCaps().max2DTextureSize; break; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 158 | case GL_TEXTURE_CUBE_MAP: |
| 159 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 160 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 161 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 162 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 163 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 164 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: maxDimension = context->getCaps().maxCubeMapTextureSize; break; |
| 165 | case GL_TEXTURE_3D: maxDimension = context->getCaps().max3DTextureSize; break; |
| 166 | case GL_TEXTURE_2D_ARRAY: maxDimension = context->getCaps().max2DTextureSize; break; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 167 | default: UNREACHABLE(); |
| 168 | } |
| 169 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 170 | return level <= gl::log2(maxDimension); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 171 | } |
| 172 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 173 | bool ValidImageSize(const Context *context, GLenum target, GLint level, |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 174 | GLsizei width, GLsizei height, GLsizei depth) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 175 | { |
| 176 | if (level < 0 || width < 0 || height < 0 || depth < 0) |
| 177 | { |
| 178 | return false; |
| 179 | } |
| 180 | |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 181 | if (!context->getExtensions().textureNPOT && |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 182 | (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 183 | { |
| 184 | return false; |
| 185 | } |
| 186 | |
| 187 | if (!ValidMipLevel(context, target, level)) |
| 188 | { |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | return true; |
| 193 | } |
| 194 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 195 | bool ValidCompressedImageSize(const Context *context, GLenum internalFormat, GLsizei width, GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 196 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 197 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat); |
| 198 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 199 | { |
| 200 | return false; |
| 201 | } |
| 202 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 203 | if (width < 0 || (static_cast<GLuint>(width) > formatInfo.compressedBlockWidth && width % formatInfo.compressedBlockWidth != 0) || |
| 204 | height < 0 || (static_cast<GLuint>(height) > formatInfo.compressedBlockHeight && height % formatInfo.compressedBlockHeight != 0)) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 205 | { |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | return true; |
| 210 | } |
| 211 | |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 212 | bool ValidQueryType(const Context *context, GLenum queryType) |
| 213 | { |
| 214 | META_ASSERT(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT); |
| 215 | META_ASSERT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT); |
| 216 | |
| 217 | switch (queryType) |
| 218 | { |
| 219 | case GL_ANY_SAMPLES_PASSED: |
| 220 | case GL_ANY_SAMPLES_PASSED_CONSERVATIVE: |
| 221 | return true; |
| 222 | case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: |
| 223 | return (context->getClientVersion() >= 3); |
| 224 | default: |
| 225 | return false; |
| 226 | } |
| 227 | } |
| 228 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 229 | bool ValidProgram(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 230 | { |
| 231 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will generate the |
| 232 | // error INVALID_VALUE if the provided name is not the name of either a shader or program object and |
| 233 | // INVALID_OPERATION if the provided name identifies an object that is not the expected type." |
| 234 | |
| 235 | if (context->getProgram(id) != NULL) |
| 236 | { |
| 237 | return true; |
| 238 | } |
| 239 | else if (context->getShader(id) != NULL) |
| 240 | { |
| 241 | // ID is the wrong type |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 242 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 243 | return false; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 244 | } |
| 245 | else |
| 246 | { |
| 247 | // No shader/program object has this ID |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 248 | context->recordError(Error(GL_INVALID_VALUE)); |
| 249 | return false; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 253 | bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 254 | { |
| 255 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 256 | { |
| 257 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
| 258 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 259 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 260 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 261 | context->recordError(Error(GL_INVALID_VALUE)); |
| 262 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | switch (attachment) |
| 268 | { |
| 269 | case GL_DEPTH_ATTACHMENT: |
| 270 | case GL_STENCIL_ATTACHMENT: |
| 271 | break; |
| 272 | |
| 273 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 274 | if (context->getClientVersion() < 3) |
| 275 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 276 | context->recordError(Error(GL_INVALID_ENUM)); |
| 277 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 278 | } |
| 279 | break; |
| 280 | |
| 281 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 282 | context->recordError(Error(GL_INVALID_ENUM)); |
| 283 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
| 287 | return true; |
| 288 | } |
| 289 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 290 | bool ValidateRenderbufferStorageParametersBase(gl::Context *context, GLenum target, GLsizei samples, |
| 291 | GLenum internalformat, GLsizei width, GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 292 | { |
| 293 | switch (target) |
| 294 | { |
| 295 | case GL_RENDERBUFFER: |
| 296 | break; |
| 297 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 298 | context->recordError(Error(GL_INVALID_ENUM)); |
| 299 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | if (width < 0 || height < 0 || samples < 0) |
| 303 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 304 | context->recordError(Error(GL_INVALID_VALUE)); |
| 305 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 308 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 309 | if (!formatCaps.renderable) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 310 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 311 | context->recordError(Error(GL_INVALID_ENUM)); |
| 312 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 316 | // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 317 | // only sized internal formats. |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 318 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 319 | if (formatInfo.pixelBytes == 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 320 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 321 | context->recordError(Error(GL_INVALID_ENUM)); |
| 322 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 323 | } |
| 324 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 325 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 326 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 327 | context->recordError(Error(GL_INVALID_VALUE)); |
| 328 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 329 | } |
| 330 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 331 | GLuint handle = context->getState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 332 | if (handle == 0) |
| 333 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 334 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 335 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | return true; |
| 339 | } |
| 340 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 341 | bool ValidateRenderbufferStorageParametersANGLE(gl::Context *context, GLenum target, GLsizei samples, |
| 342 | GLenum internalformat, GLsizei width, GLsizei height) |
| 343 | { |
| 344 | ASSERT(context->getExtensions().framebufferMultisample); |
| 345 | |
| 346 | // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal |
| 347 | // to MAX_SAMPLES_ANGLE (Context::getExtensions().maxSamples) otherwise GL_INVALID_VALUE is |
| 348 | // generated. |
| 349 | if (static_cast<GLuint>(samples) > context->getExtensions().maxSamples) |
| 350 | { |
| 351 | context->recordError(Error(GL_INVALID_VALUE)); |
| 352 | return false; |
| 353 | } |
| 354 | |
| 355 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 356 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 357 | // than the maximum sample number supported by this format generates a GL_INVALID_VALUE. |
| 358 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 359 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 360 | { |
| 361 | context->recordError(Error(GL_OUT_OF_MEMORY)); |
| 362 | return false; |
| 363 | } |
| 364 | |
| 365 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width, height); |
| 366 | } |
| 367 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 368 | bool ValidateFramebufferRenderbufferParameters(gl::Context *context, GLenum target, GLenum attachment, |
| 369 | GLenum renderbuffertarget, GLuint renderbuffer) |
| 370 | { |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 371 | if (!ValidFramebufferTarget(target)) |
| 372 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 373 | context->recordError(Error(GL_INVALID_ENUM)); |
| 374 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 375 | } |
| 376 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 377 | gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); |
| 378 | GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id(); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 379 | |
| 380 | if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0)) |
| 381 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 382 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 383 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 384 | } |
| 385 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 386 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 387 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 388 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 389 | } |
| 390 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 391 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 392 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 393 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 394 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 395 | if (renderbuffer != 0) |
| 396 | { |
| 397 | if (!context->getRenderbuffer(renderbuffer)) |
| 398 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 399 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 400 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 404 | return true; |
| 405 | } |
| 406 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 407 | static bool IsPartialBlit(gl::Context *context, gl::FramebufferAttachment *readBuffer, gl::FramebufferAttachment *writeBuffer, |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 408 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 409 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1) |
| 410 | { |
| 411 | if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 || |
| 412 | dstX1 != writeBuffer->getWidth() || dstY1 != writeBuffer->getHeight() || |
| 413 | srcX1 != readBuffer->getWidth() || srcY1 != readBuffer->getHeight()) |
| 414 | { |
| 415 | return true; |
| 416 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 417 | else if (context->getState().isScissorTestEnabled()) |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 418 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 419 | const Rectangle &scissor = context->getState().getScissor(); |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 420 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 421 | return scissor.x > 0 || scissor.y > 0 || |
| 422 | scissor.width < writeBuffer->getWidth() || |
| 423 | scissor.height < writeBuffer->getHeight(); |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 424 | } |
| 425 | else |
| 426 | { |
| 427 | return false; |
| 428 | } |
| 429 | } |
| 430 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 431 | 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] | 432 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, |
| 433 | GLenum filter, bool fromAngleExtension) |
| 434 | { |
| 435 | switch (filter) |
| 436 | { |
| 437 | case GL_NEAREST: |
| 438 | break; |
| 439 | case GL_LINEAR: |
| 440 | if (fromAngleExtension) |
| 441 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 442 | context->recordError(Error(GL_INVALID_ENUM)); |
| 443 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 444 | } |
| 445 | break; |
| 446 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 447 | context->recordError(Error(GL_INVALID_ENUM)); |
| 448 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 452 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 453 | context->recordError(Error(GL_INVALID_VALUE)); |
| 454 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | if (mask == 0) |
| 458 | { |
| 459 | // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no |
| 460 | // buffers are copied. |
| 461 | return false; |
| 462 | } |
| 463 | |
| 464 | if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0)) |
| 465 | { |
| 466 | ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 467 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 468 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 472 | // color buffer, leaving only nearest being unfiltered from above |
| 473 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 474 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 475 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 476 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 477 | } |
| 478 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 479 | if (context->getState().getReadFramebuffer()->id() == context->getState().getDrawFramebuffer()->id()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 480 | { |
| 481 | if (fromAngleExtension) |
| 482 | { |
| 483 | ERR("Blits with the same source and destination framebuffer are not supported by this " |
| 484 | "implementation."); |
| 485 | } |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 486 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 487 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 488 | } |
| 489 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 490 | gl::Framebuffer *readFramebuffer = context->getState().getReadFramebuffer(); |
| 491 | gl::Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 492 | |
| 493 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 494 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 495 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 496 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 499 | if (!readFramebuffer->completeness(context->getData())) |
| 500 | { |
| 501 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 502 | return false; |
| 503 | } |
| 504 | |
| 505 | if (!drawFramebuffer->completeness(context->getData())) |
| 506 | { |
| 507 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 508 | return false; |
| 509 | } |
| 510 | |
| 511 | if (drawFramebuffer->getSamples(context->getData()) != 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 512 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 513 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 514 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 515 | } |
| 516 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 517 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 518 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 519 | if (mask & GL_COLOR_BUFFER_BIT) |
| 520 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 521 | gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
| 522 | gl::FramebufferAttachment *drawColorBuffer = drawFramebuffer->getFirstColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 523 | |
| 524 | if (readColorBuffer && drawColorBuffer) |
| 525 | { |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 526 | GLenum readInternalFormat = readColorBuffer->getActualFormat(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 527 | const InternalFormat &readFormatInfo = GetInternalFormatInfo(readInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 528 | |
| 529 | for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++) |
| 530 | { |
| 531 | if (drawFramebuffer->isEnabledColorAttachment(i)) |
| 532 | { |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 533 | GLenum drawInternalFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 534 | const InternalFormat &drawFormatInfo = GetInternalFormatInfo(drawInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 535 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 536 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 537 | // 1) If the read buffer is fixed point format, the draw buffer must be as well |
| 538 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be as well |
| 539 | // 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] | 540 | if ( (readFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || readFormatInfo.componentType == GL_SIGNED_NORMALIZED) && |
| 541 | !(drawFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || drawFormatInfo.componentType == GL_SIGNED_NORMALIZED)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 542 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 543 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 544 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 545 | } |
| 546 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 547 | if (readFormatInfo.componentType == GL_UNSIGNED_INT && drawFormatInfo.componentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 548 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 549 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 550 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 551 | } |
| 552 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 553 | if (readFormatInfo.componentType == GL_INT && drawFormatInfo.componentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 554 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 555 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 556 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 557 | } |
| 558 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 559 | if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawInternalFormat || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 560 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 561 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 562 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | } |
| 566 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 567 | 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] | 568 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 569 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 570 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | if (fromAngleExtension) |
| 574 | { |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 575 | FramebufferAttachment *readColorAttachment = readFramebuffer->getReadColorbuffer(); |
| 576 | if (!readColorAttachment || |
| 577 | (!(readColorAttachment->type() == GL_TEXTURE && readColorAttachment->getTextureImageIndex()->type == GL_TEXTURE_2D) && |
| 578 | readColorAttachment->type() != GL_RENDERBUFFER && |
| 579 | readColorAttachment->type() != GL_FRAMEBUFFER_DEFAULT)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 580 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 581 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 582 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
| 586 | { |
| 587 | if (drawFramebuffer->isEnabledColorAttachment(colorAttachment)) |
| 588 | { |
Jamie Madill | e92a354 | 2014-07-03 10:38:58 -0400 | [diff] [blame] | 589 | FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(colorAttachment); |
| 590 | ASSERT(attachment); |
| 591 | |
Geoff Lang | 6a1e6b9 | 2014-11-06 10:42:45 -0500 | [diff] [blame] | 592 | if (!(attachment->type() == GL_TEXTURE && attachment->getTextureImageIndex()->type == GL_TEXTURE_2D) && |
| 593 | attachment->type() != GL_RENDERBUFFER && |
| 594 | attachment->type() != GL_FRAMEBUFFER_DEFAULT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 595 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 596 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 597 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 598 | } |
| 599 | |
Jamie Madill | f8f18f0 | 2014-10-02 10:44:17 -0400 | [diff] [blame] | 600 | // Return an error if the destination formats do not match |
| 601 | if (attachment->getInternalFormat() != readColorBuffer->getInternalFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 602 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 603 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 604 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | } |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 608 | |
| 609 | int readSamples = readFramebuffer->getSamples(context->getData()); |
| 610 | |
| 611 | if (readSamples != 0 && IsPartialBlit(context, readColorBuffer, drawColorBuffer, |
| 612 | srcX0, srcY0, srcX1, srcY1, |
| 613 | dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 614 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 615 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 616 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | if (mask & GL_DEPTH_BUFFER_BIT) |
| 623 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 624 | gl::FramebufferAttachment *readDepthBuffer = readFramebuffer->getDepthbuffer(); |
| 625 | gl::FramebufferAttachment *drawDepthBuffer = drawFramebuffer->getDepthbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 626 | |
| 627 | if (readDepthBuffer && drawDepthBuffer) |
| 628 | { |
| 629 | if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat()) |
| 630 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 631 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 632 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | if (readDepthBuffer->getSamples() > 0 && !sameBounds) |
| 636 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 637 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 638 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | if (fromAngleExtension) |
| 642 | { |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 643 | if (IsPartialBlit(context, readDepthBuffer, drawDepthBuffer, |
| 644 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 645 | { |
| 646 | 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] | 647 | context->recordError(Error(GL_INVALID_OPERATION)); // only whole-buffer copies are permitted |
| 648 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0) |
| 652 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 653 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 654 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | if (mask & GL_STENCIL_BUFFER_BIT) |
| 661 | { |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 662 | gl::FramebufferAttachment *readStencilBuffer = readFramebuffer->getStencilbuffer(); |
| 663 | gl::FramebufferAttachment *drawStencilBuffer = drawFramebuffer->getStencilbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 664 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 665 | if (readStencilBuffer && drawStencilBuffer) |
| 666 | { |
| 667 | if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat()) |
| 668 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 669 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 670 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | if (readStencilBuffer->getSamples() > 0 && !sameBounds) |
| 674 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 675 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 676 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | if (fromAngleExtension) |
| 680 | { |
Geoff Lang | 125deab | 2013-08-09 13:34:16 -0400 | [diff] [blame] | 681 | if (IsPartialBlit(context, readStencilBuffer, drawStencilBuffer, |
| 682 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 683 | { |
| 684 | 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] | 685 | context->recordError(Error(GL_INVALID_OPERATION)); // only whole-buffer copies are permitted |
| 686 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0) |
| 690 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 691 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 692 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | return true; |
| 699 | } |
| 700 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 701 | bool ValidateGetVertexAttribParameters(Context *context, GLenum pname) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 702 | { |
| 703 | switch (pname) |
| 704 | { |
| 705 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 706 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 707 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 708 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 709 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 710 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 711 | case GL_CURRENT_VERTEX_ATTRIB: |
| 712 | return true; |
| 713 | |
| 714 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 715 | // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses |
| 716 | // the same constant. |
| 717 | META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE); |
| 718 | return true; |
| 719 | |
| 720 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 721 | if (context->getClientVersion() < 3) |
| 722 | { |
| 723 | context->recordError(Error(GL_INVALID_ENUM)); |
| 724 | return false; |
| 725 | } |
| 726 | return true; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 727 | |
| 728 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 729 | context->recordError(Error(GL_INVALID_ENUM)); |
| 730 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 731 | } |
| 732 | } |
| 733 | |
Geoff Lang | 34dbb6f | 2013-08-05 15:05:47 -0400 | [diff] [blame] | 734 | bool ValidateTexParamParameters(gl::Context *context, GLenum pname, GLint param) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 735 | { |
| 736 | switch (pname) |
| 737 | { |
| 738 | case GL_TEXTURE_WRAP_R: |
| 739 | case GL_TEXTURE_SWIZZLE_R: |
| 740 | case GL_TEXTURE_SWIZZLE_G: |
| 741 | case GL_TEXTURE_SWIZZLE_B: |
| 742 | case GL_TEXTURE_SWIZZLE_A: |
| 743 | case GL_TEXTURE_BASE_LEVEL: |
| 744 | case GL_TEXTURE_MAX_LEVEL: |
| 745 | case GL_TEXTURE_COMPARE_MODE: |
| 746 | case GL_TEXTURE_COMPARE_FUNC: |
| 747 | case GL_TEXTURE_MIN_LOD: |
| 748 | case GL_TEXTURE_MAX_LOD: |
| 749 | if (context->getClientVersion() < 3) |
| 750 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 751 | context->recordError(Error(GL_INVALID_ENUM)); |
| 752 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 753 | } |
| 754 | break; |
| 755 | |
| 756 | default: break; |
| 757 | } |
| 758 | |
| 759 | switch (pname) |
| 760 | { |
| 761 | case GL_TEXTURE_WRAP_S: |
| 762 | case GL_TEXTURE_WRAP_T: |
| 763 | case GL_TEXTURE_WRAP_R: |
| 764 | switch (param) |
| 765 | { |
| 766 | case GL_REPEAT: |
| 767 | case GL_CLAMP_TO_EDGE: |
| 768 | case GL_MIRRORED_REPEAT: |
| 769 | return true; |
| 770 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 771 | context->recordError(Error(GL_INVALID_ENUM)); |
| 772 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | case GL_TEXTURE_MIN_FILTER: |
| 776 | switch (param) |
| 777 | { |
| 778 | case GL_NEAREST: |
| 779 | case GL_LINEAR: |
| 780 | case GL_NEAREST_MIPMAP_NEAREST: |
| 781 | case GL_LINEAR_MIPMAP_NEAREST: |
| 782 | case GL_NEAREST_MIPMAP_LINEAR: |
| 783 | case GL_LINEAR_MIPMAP_LINEAR: |
| 784 | return true; |
| 785 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 786 | context->recordError(Error(GL_INVALID_ENUM)); |
| 787 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 788 | } |
| 789 | break; |
| 790 | |
| 791 | case GL_TEXTURE_MAG_FILTER: |
| 792 | switch (param) |
| 793 | { |
| 794 | case GL_NEAREST: |
| 795 | case GL_LINEAR: |
| 796 | return true; |
| 797 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 798 | context->recordError(Error(GL_INVALID_ENUM)); |
| 799 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 800 | } |
| 801 | break; |
| 802 | |
| 803 | case GL_TEXTURE_USAGE_ANGLE: |
| 804 | switch (param) |
| 805 | { |
| 806 | case GL_NONE: |
| 807 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 808 | return true; |
| 809 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 810 | context->recordError(Error(GL_INVALID_ENUM)); |
| 811 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 812 | } |
| 813 | break; |
| 814 | |
| 815 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 816 | if (!context->getExtensions().textureFilterAnisotropic) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 817 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 818 | context->recordError(Error(GL_INVALID_ENUM)); |
| 819 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | // we assume the parameter passed to this validation method is truncated, not rounded |
| 823 | if (param < 1) |
| 824 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 825 | context->recordError(Error(GL_INVALID_VALUE)); |
| 826 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 827 | } |
| 828 | return true; |
| 829 | |
| 830 | case GL_TEXTURE_MIN_LOD: |
| 831 | case GL_TEXTURE_MAX_LOD: |
| 832 | // any value is permissible |
| 833 | return true; |
| 834 | |
| 835 | case GL_TEXTURE_COMPARE_MODE: |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 836 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 837 | switch (param) |
| 838 | { |
| 839 | case GL_NONE: |
| 840 | case GL_COMPARE_REF_TO_TEXTURE: |
| 841 | return true; |
| 842 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 843 | context->recordError(Error(GL_INVALID_ENUM)); |
| 844 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 845 | } |
| 846 | break; |
| 847 | |
| 848 | case GL_TEXTURE_COMPARE_FUNC: |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 849 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 850 | switch (param) |
| 851 | { |
| 852 | case GL_LEQUAL: |
| 853 | case GL_GEQUAL: |
| 854 | case GL_LESS: |
| 855 | case GL_GREATER: |
| 856 | case GL_EQUAL: |
| 857 | case GL_NOTEQUAL: |
| 858 | case GL_ALWAYS: |
| 859 | case GL_NEVER: |
| 860 | return true; |
| 861 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 862 | context->recordError(Error(GL_INVALID_ENUM)); |
| 863 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 864 | } |
| 865 | break; |
| 866 | |
| 867 | case GL_TEXTURE_SWIZZLE_R: |
| 868 | case GL_TEXTURE_SWIZZLE_G: |
| 869 | case GL_TEXTURE_SWIZZLE_B: |
| 870 | case GL_TEXTURE_SWIZZLE_A: |
Geoff Lang | bc90a48 | 2013-09-17 16:51:27 -0400 | [diff] [blame] | 871 | switch (param) |
| 872 | { |
| 873 | case GL_RED: |
| 874 | case GL_GREEN: |
| 875 | case GL_BLUE: |
| 876 | case GL_ALPHA: |
| 877 | case GL_ZERO: |
| 878 | case GL_ONE: |
| 879 | return true; |
| 880 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 881 | context->recordError(Error(GL_INVALID_ENUM)); |
| 882 | return false; |
Geoff Lang | bc90a48 | 2013-09-17 16:51:27 -0400 | [diff] [blame] | 883 | } |
| 884 | break; |
| 885 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 886 | case GL_TEXTURE_BASE_LEVEL: |
| 887 | case GL_TEXTURE_MAX_LEVEL: |
Nicolas Capens | 8de6828 | 2014-04-04 11:10:27 -0400 | [diff] [blame] | 888 | if (param < 0) |
| 889 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 890 | context->recordError(Error(GL_INVALID_VALUE)); |
| 891 | return false; |
Nicolas Capens | 8de6828 | 2014-04-04 11:10:27 -0400 | [diff] [blame] | 892 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 893 | return true; |
| 894 | |
| 895 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 896 | context->recordError(Error(GL_INVALID_ENUM)); |
| 897 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 901 | bool ValidateSamplerObjectParameter(gl::Context *context, GLenum pname) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 902 | { |
| 903 | switch (pname) |
| 904 | { |
| 905 | case GL_TEXTURE_MIN_FILTER: |
| 906 | case GL_TEXTURE_MAG_FILTER: |
| 907 | case GL_TEXTURE_WRAP_S: |
| 908 | case GL_TEXTURE_WRAP_T: |
| 909 | case GL_TEXTURE_WRAP_R: |
| 910 | case GL_TEXTURE_MIN_LOD: |
| 911 | case GL_TEXTURE_MAX_LOD: |
| 912 | case GL_TEXTURE_COMPARE_MODE: |
| 913 | case GL_TEXTURE_COMPARE_FUNC: |
| 914 | return true; |
| 915 | |
| 916 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 917 | context->recordError(Error(GL_INVALID_ENUM)); |
| 918 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 919 | } |
| 920 | } |
| 921 | |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 922 | bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsizei width, GLsizei height, |
| 923 | GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels) |
| 924 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 925 | gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 926 | ASSERT(framebuffer); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 927 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 928 | if (framebuffer->completeness(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 929 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 930 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 931 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 932 | } |
| 933 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 934 | if (context->getState().getReadFramebuffer()->id() != 0 && |
| 935 | framebuffer->getSamples(context->getData()) != 0) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 936 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 937 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 938 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 939 | } |
| 940 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 941 | if (!framebuffer->getReadColorbuffer()) |
| 942 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 943 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 944 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 945 | } |
| 946 | |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 947 | GLenum currentInternalFormat, currentFormat, currentType; |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 948 | GLuint clientVersion = context->getClientVersion(); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 949 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 950 | context->getCurrentReadFormatType(¤tInternalFormat, ¤tFormat, ¤tType); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 951 | |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 952 | bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) : |
| 953 | ValidES3ReadFormatType(context, currentInternalFormat, format, type); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 954 | |
| 955 | if (!(currentFormat == format && currentType == type) && !validReadFormat) |
| 956 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 957 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 958 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 959 | } |
| 960 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 961 | GLenum sizedInternalFormat = GetSizedInternalFormat(format, type); |
| 962 | const InternalFormat &sizedFormatInfo = GetInternalFormatInfo(sizedInternalFormat); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 963 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 964 | GLsizei outputPitch = sizedFormatInfo.computeRowPitch(type, width, context->getState().getPackAlignment()); |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 965 | // sized query sanity check |
| 966 | if (bufSize) |
| 967 | { |
| 968 | int requiredSize = outputPitch * height; |
| 969 | if (requiredSize > *bufSize) |
| 970 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 971 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 972 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
| 976 | return true; |
| 977 | } |
| 978 | |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 979 | bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id) |
| 980 | { |
| 981 | if (!ValidQueryType(context, target)) |
| 982 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 983 | context->recordError(Error(GL_INVALID_ENUM)); |
| 984 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | if (id == 0) |
| 988 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 989 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 990 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 994 | // of zero, if the active query object name for <target> is non-zero (for the |
| 995 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 996 | // the active query for either target is non-zero), if <id> is the name of an |
| 997 | // existing query object whose type does not match <target>, or if <id> is the |
| 998 | // active query object name for any query type, the error INVALID_OPERATION is |
| 999 | // generated. |
| 1000 | |
| 1001 | // Ensure no other queries are active |
| 1002 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1003 | // separately that: |
| 1004 | // a) The query ID passed is not the current active query for any target/type |
| 1005 | // b) There are no active queries for the requested target (and in the case |
| 1006 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1007 | // no query may be active for either if glBeginQuery targets either. |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1008 | if (context->getState().isQueryActive()) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1009 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1010 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1011 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | Query *queryObject = context->getQuery(id, true, target); |
| 1015 | |
| 1016 | // check that name was obtained with glGenQueries |
| 1017 | if (!queryObject) |
| 1018 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1019 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1020 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | // check for type mismatch |
| 1024 | if (queryObject->getType() != target) |
| 1025 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1026 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1027 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | return true; |
| 1031 | } |
| 1032 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1033 | bool ValidateEndQuery(gl::Context *context, GLenum target) |
| 1034 | { |
| 1035 | if (!ValidQueryType(context, target)) |
| 1036 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1037 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1038 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1039 | } |
| 1040 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1041 | const Query *queryObject = context->getState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1042 | |
| 1043 | if (queryObject == NULL) |
| 1044 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1045 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1046 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1047 | } |
| 1048 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1049 | return true; |
| 1050 | } |
| 1051 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1052 | static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType, |
| 1053 | GLint location, GLsizei count, LinkedUniform **uniformOut) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1054 | { |
| 1055 | if (count < 0) |
| 1056 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1057 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1058 | return false; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1059 | } |
| 1060 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1061 | gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary(); |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1062 | if (!programBinary) |
| 1063 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1064 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1065 | return false; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | if (location == -1) |
| 1069 | { |
| 1070 | // Silently ignore the uniform command |
| 1071 | return false; |
| 1072 | } |
| 1073 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1074 | if (!programBinary->isValidUniformLocation(location)) |
| 1075 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1076 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1077 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | LinkedUniform *uniform = programBinary->getUniformByLocation(location); |
| 1081 | |
| 1082 | // attempting to write an array to a non-array uniform is an INVALID_OPERATION |
| 1083 | if (uniform->elementCount() == 1 && count > 1) |
| 1084 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1085 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1086 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | *uniformOut = uniform; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 1090 | return true; |
| 1091 | } |
| 1092 | |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1093 | bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count) |
| 1094 | { |
| 1095 | // Check for ES3 uniform entry points |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1096 | if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1097 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1098 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1099 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1100 | } |
| 1101 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1102 | LinkedUniform *uniform = NULL; |
| 1103 | if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform)) |
| 1104 | { |
| 1105 | return false; |
| 1106 | } |
| 1107 | |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 1108 | GLenum targetBoolType = VariableBoolVectorType(uniformType); |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1109 | bool samplerUniformCheck = (IsSampler(uniform->type) && uniformType == GL_INT); |
| 1110 | if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type) |
| 1111 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1112 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1113 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count, |
| 1120 | GLboolean transpose) |
| 1121 | { |
| 1122 | // Check for ES3 uniform entry points |
| 1123 | int rows = VariableRowCount(matrixType); |
| 1124 | int cols = VariableColumnCount(matrixType); |
| 1125 | if (rows != cols && context->getClientVersion() < 3) |
| 1126 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1127 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1128 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | if (transpose != GL_FALSE && context->getClientVersion() < 3) |
| 1132 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1133 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1134 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1135 | } |
| 1136 | |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1137 | LinkedUniform *uniform = NULL; |
| 1138 | if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform)) |
| 1139 | { |
| 1140 | return false; |
| 1141 | } |
| 1142 | |
| 1143 | if (uniform->type != matrixType) |
| 1144 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1145 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1146 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1152 | bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
| 1153 | { |
| 1154 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 1155 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1156 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1157 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 1161 | { |
| 1162 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 1163 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1164 | if (colorAttachment >= context->getCaps().maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1165 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1166 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1167 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | switch (pname) |
| 1172 | { |
| 1173 | case GL_TEXTURE_BINDING_2D: |
| 1174 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 1175 | case GL_TEXTURE_BINDING_3D: |
| 1176 | case GL_TEXTURE_BINDING_2D_ARRAY: |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 1177 | if (context->getState().getActiveSampler() >= context->getCaps().maxCombinedTextureImageUnits) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1178 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1179 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1180 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1181 | } |
| 1182 | break; |
| 1183 | |
| 1184 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 1185 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 1186 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1187 | Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1188 | ASSERT(framebuffer); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1189 | if (framebuffer->completeness(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1190 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1191 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1192 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1193 | } |
| 1194 | |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 1195 | FramebufferAttachment *attachment = framebuffer->getReadColorbuffer(); |
| 1196 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1197 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1198 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1199 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1200 | } |
| 1201 | } |
| 1202 | break; |
| 1203 | |
| 1204 | default: |
| 1205 | break; |
| 1206 | } |
| 1207 | |
| 1208 | // pname is valid, but there are no parameters to return |
| 1209 | if (numParams == 0) |
| 1210 | { |
| 1211 | return false; |
| 1212 | } |
| 1213 | |
| 1214 | return true; |
| 1215 | } |
| 1216 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1217 | bool ValidateCopyTexImageParametersBase(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage, |
| 1218 | GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, |
| 1219 | GLint border, GLenum *textureFormatOut) |
| 1220 | { |
| 1221 | |
| 1222 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 1223 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1224 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1225 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0) |
| 1229 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1230 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1231 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height) |
| 1235 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1236 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1237 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | if (border != 0) |
| 1241 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1242 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1243 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | if (!ValidMipLevel(context, target, level)) |
| 1247 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1248 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1249 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1250 | } |
| 1251 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1252 | gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1253 | if (framebuffer->completeness(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1254 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1255 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 1256 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1257 | } |
| 1258 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1259 | if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples(context->getData()) != 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1260 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1261 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1262 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1265 | const gl::Caps &caps = context->getCaps(); |
| 1266 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1267 | gl::Texture *texture = NULL; |
| 1268 | GLenum textureInternalFormat = GL_NONE; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1269 | GLint textureLevelWidth = 0; |
| 1270 | GLint textureLevelHeight = 0; |
| 1271 | GLint textureLevelDepth = 0; |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1272 | GLuint maxDimension = 0; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1273 | |
| 1274 | switch (target) |
| 1275 | { |
| 1276 | case GL_TEXTURE_2D: |
| 1277 | { |
| 1278 | gl::Texture2D *texture2d = context->getTexture2D(); |
| 1279 | if (texture2d) |
| 1280 | { |
| 1281 | textureInternalFormat = texture2d->getInternalFormat(level); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1282 | textureLevelWidth = texture2d->getWidth(level); |
| 1283 | textureLevelHeight = texture2d->getHeight(level); |
| 1284 | textureLevelDepth = 1; |
| 1285 | texture = texture2d; |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1286 | maxDimension = caps.max2DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | break; |
| 1290 | |
| 1291 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1292 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1293 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1294 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1295 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1296 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1297 | { |
| 1298 | gl::TextureCubeMap *textureCube = context->getTextureCubeMap(); |
| 1299 | if (textureCube) |
| 1300 | { |
| 1301 | textureInternalFormat = textureCube->getInternalFormat(target, level); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1302 | textureLevelWidth = textureCube->getWidth(target, level); |
| 1303 | textureLevelHeight = textureCube->getHeight(target, level); |
| 1304 | textureLevelDepth = 1; |
| 1305 | texture = textureCube; |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1306 | maxDimension = caps.maxCubeMapTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1307 | } |
| 1308 | } |
| 1309 | break; |
| 1310 | |
| 1311 | case GL_TEXTURE_2D_ARRAY: |
| 1312 | { |
| 1313 | gl::Texture2DArray *texture2dArray = context->getTexture2DArray(); |
| 1314 | if (texture2dArray) |
| 1315 | { |
| 1316 | textureInternalFormat = texture2dArray->getInternalFormat(level); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1317 | textureLevelWidth = texture2dArray->getWidth(level); |
| 1318 | textureLevelHeight = texture2dArray->getHeight(level); |
| 1319 | textureLevelDepth = texture2dArray->getLayers(level); |
| 1320 | texture = texture2dArray; |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1321 | maxDimension = caps.max2DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1322 | } |
| 1323 | } |
| 1324 | break; |
| 1325 | |
| 1326 | case GL_TEXTURE_3D: |
| 1327 | { |
| 1328 | gl::Texture3D *texture3d = context->getTexture3D(); |
| 1329 | if (texture3d) |
| 1330 | { |
| 1331 | textureInternalFormat = texture3d->getInternalFormat(level); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1332 | textureLevelWidth = texture3d->getWidth(level); |
| 1333 | textureLevelHeight = texture3d->getHeight(level); |
| 1334 | textureLevelDepth = texture3d->getDepth(level); |
| 1335 | texture = texture3d; |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1336 | maxDimension = caps.max3DTextureSize; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1337 | } |
| 1338 | } |
| 1339 | break; |
| 1340 | |
| 1341 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1342 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1343 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | if (!texture) |
| 1347 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1348 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1349 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | if (texture->isImmutable() && !isSubImage) |
| 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 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 1359 | |
| 1360 | if (formatInfo.depthBits > 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1361 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1362 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1363 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1364 | } |
| 1365 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1366 | if (formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1367 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1368 | if (((width % formatInfo.compressedBlockWidth) != 0 && width != textureLevelWidth) || |
| 1369 | ((height % formatInfo.compressedBlockHeight) != 0 && height != textureLevelHeight)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1370 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1371 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1372 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | if (isSubImage) |
| 1377 | { |
| 1378 | if (xoffset + width > textureLevelWidth || |
| 1379 | yoffset + height > textureLevelHeight || |
| 1380 | zoffset >= textureLevelDepth) |
| 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 | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1384 | } |
| 1385 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1386 | else |
| 1387 | { |
| 1388 | if (IsCubemapTextureTarget(target) && width != height) |
| 1389 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1390 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1391 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1392 | } |
| 1393 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1394 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1395 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1396 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1397 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | int maxLevelDimension = (maxDimension >> level); |
| 1401 | if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension) |
| 1402 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1403 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1404 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 1405 | } |
| 1406 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1407 | |
| 1408 | *textureFormatOut = textureInternalFormat; |
| 1409 | return true; |
| 1410 | } |
| 1411 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1412 | 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] | 1413 | { |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1414 | switch (mode) |
| 1415 | { |
| 1416 | case GL_POINTS: |
| 1417 | case GL_LINES: |
| 1418 | case GL_LINE_LOOP: |
| 1419 | case GL_LINE_STRIP: |
| 1420 | case GL_TRIANGLES: |
| 1421 | case GL_TRIANGLE_STRIP: |
| 1422 | case GL_TRIANGLE_FAN: |
| 1423 | break; |
| 1424 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1425 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1426 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 1427 | } |
| 1428 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1429 | if (count < 0) |
| 1430 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1431 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1432 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1433 | } |
| 1434 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1435 | const State &state = context->getState(); |
| 1436 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1437 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1438 | if (state.hasMappedBuffer(GL_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1439 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1440 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1441 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1442 | } |
| 1443 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1444 | const gl::DepthStencilState &depthStencilState = state.getDepthStencilState(); |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1445 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1446 | state.getStencilRef() != state.getStencilBackRef() || |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1447 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 1448 | { |
| 1449 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. |
| 1450 | // See Section 6.10 of the WebGL 1.0 spec |
| 1451 | ERR("This ANGLE implementation does not support separate front/back stencil " |
| 1452 | "writemasks, reference values, or stencil mask values."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1453 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1454 | return false; |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 1455 | } |
| 1456 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1457 | const gl::Framebuffer *fbo = state.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1458 | if (!fbo || fbo->completeness(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1459 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1460 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 1461 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1462 | } |
| 1463 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1464 | if (state.getCurrentProgramId() == 0) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1465 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1466 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1467 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1468 | } |
| 1469 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1470 | gl::ProgramBinary *programBinary = state.getCurrentProgramBinary(); |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 1471 | if (!programBinary->validateSamplers(NULL, context->getCaps())) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1472 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1473 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1474 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1475 | } |
| 1476 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1477 | // Buffer validations |
| 1478 | const VertexArray *vao = state.getVertexArray(); |
| 1479 | for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 1480 | { |
| 1481 | const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex); |
| 1482 | bool attribActive = (programBinary->getSemanticIndex(attributeIndex) != -1); |
| 1483 | if (attribActive && attrib.enabled) |
| 1484 | { |
| 1485 | gl::Buffer *buffer = attrib.buffer.get(); |
| 1486 | |
| 1487 | if (buffer) |
| 1488 | { |
| 1489 | GLint64 attribStride = static_cast<GLint64>(ComputeVertexAttributeStride(attrib)); |
| 1490 | GLint64 maxVertexElement = 0; |
| 1491 | |
| 1492 | if (attrib.divisor > 0) |
| 1493 | { |
| 1494 | maxVertexElement = static_cast<GLint64>(primcount) / static_cast<GLint64>(attrib.divisor); |
| 1495 | } |
| 1496 | else |
| 1497 | { |
| 1498 | maxVertexElement = static_cast<GLint64>(maxVertex); |
| 1499 | } |
| 1500 | |
| 1501 | GLint64 attribDataSize = maxVertexElement * attribStride; |
| 1502 | |
| 1503 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 1504 | // We can return INVALID_OPERATION if our vertex attribute does not have |
| 1505 | // enough backing data. |
| 1506 | if (attribDataSize > buffer->getSize()) |
| 1507 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1508 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1509 | return false; |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1510 | } |
| 1511 | } |
| 1512 | else if (attrib.pointer == NULL) |
| 1513 | { |
| 1514 | // This is an application error that would normally result in a crash, |
| 1515 | // but we catch it and return an error |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1516 | context->recordError(Error(GL_INVALID_OPERATION, "An enabled vertex array has no buffer and no pointer.")); |
| 1517 | return false; |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1518 | } |
| 1519 | } |
| 1520 | } |
| 1521 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1522 | // No-op if zero count |
| 1523 | return (count > 0); |
| 1524 | } |
| 1525 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1526 | bool ValidateDrawArrays(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1527 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1528 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1529 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1530 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1531 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1532 | } |
| 1533 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1534 | const State &state = context->getState(); |
| 1535 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1536 | if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused() && |
| 1537 | curTransformFeedback->getDrawMode() != mode) |
| 1538 | { |
| 1539 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 1540 | // that does not match the current transform feedback object's draw mode (if transform feedback |
| 1541 | // is active), (3.0.2, section 2.14, pg 86) |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1542 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1543 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1544 | } |
| 1545 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1546 | if (!ValidateDrawBase(context, mode, count, count, primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1547 | { |
| 1548 | return false; |
| 1549 | } |
| 1550 | |
| 1551 | return true; |
| 1552 | } |
| 1553 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1554 | bool ValidateDrawArraysInstanced(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1555 | { |
| 1556 | if (primcount < 0) |
| 1557 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1558 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1559 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1560 | } |
| 1561 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1562 | if (!ValidateDrawArrays(context, mode, first, count, primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1563 | { |
| 1564 | return false; |
| 1565 | } |
| 1566 | |
| 1567 | // No-op if zero primitive count |
| 1568 | return (primcount > 0); |
| 1569 | } |
| 1570 | |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1571 | static bool ValidateDrawInstancedANGLE(Context *context) |
| 1572 | { |
| 1573 | // Verify there is at least one active attribute with a divisor of zero |
| 1574 | const gl::State& state = context->getState(); |
| 1575 | |
| 1576 | gl::ProgramBinary *programBinary = state.getCurrentProgramBinary(); |
| 1577 | |
| 1578 | const VertexArray *vao = state.getVertexArray(); |
| 1579 | for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 1580 | { |
| 1581 | const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex); |
| 1582 | bool active = (programBinary->getSemanticIndex(attributeIndex) != -1); |
| 1583 | if (active && attrib.divisor == 0) |
| 1584 | { |
| 1585 | return true; |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | context->recordError(Error(GL_INVALID_OPERATION, "ANGLE_instanced_arrays requires that at least one active attribute" |
| 1590 | "has a divisor of zero.")); |
| 1591 | return false; |
| 1592 | } |
| 1593 | |
| 1594 | bool ValidateDrawArraysInstancedANGLE(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount) |
| 1595 | { |
| 1596 | if (!ValidateDrawInstancedANGLE(context)) |
| 1597 | { |
| 1598 | return false; |
| 1599 | } |
| 1600 | |
| 1601 | return ValidateDrawArraysInstanced(context, mode, first, count, primcount); |
| 1602 | } |
| 1603 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1604 | bool ValidateDrawElements(Context *context, GLenum mode, GLsizei count, GLenum type, |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1605 | const GLvoid* indices, GLsizei primcount, rx::RangeUI *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1606 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1607 | switch (type) |
| 1608 | { |
| 1609 | case GL_UNSIGNED_BYTE: |
| 1610 | case GL_UNSIGNED_SHORT: |
| 1611 | break; |
| 1612 | case GL_UNSIGNED_INT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1613 | if (!context->getExtensions().elementIndexUint) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1614 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1615 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1616 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1617 | } |
| 1618 | break; |
| 1619 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1620 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1621 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1622 | } |
| 1623 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1624 | const State &state = context->getState(); |
| 1625 | |
| 1626 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1627 | if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused()) |
| 1628 | { |
| 1629 | // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced |
| 1630 | // 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] | 1631 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1632 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1636 | if (state.hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -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 | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1640 | } |
| 1641 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1642 | const gl::VertexArray *vao = state.getVertexArray(); |
| 1643 | const gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer(); |
| 1644 | if (!indices && !elementArrayBuffer) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1645 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1646 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1647 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 1648 | } |
| 1649 | |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1650 | if (elementArrayBuffer) |
| 1651 | { |
| 1652 | const gl::Type &typeInfo = gl::GetTypeInfo(type); |
| 1653 | |
| 1654 | GLint64 offset = reinterpret_cast<GLint64>(indices); |
| 1655 | GLint64 byteCount = static_cast<GLint64>(typeInfo.bytes) * static_cast<GLint64>(count)+offset; |
| 1656 | |
| 1657 | // check for integer overflows |
| 1658 | if (static_cast<GLuint>(count) > (std::numeric_limits<GLuint>::max() / typeInfo.bytes) || |
| 1659 | byteCount > static_cast<GLint64>(std::numeric_limits<GLuint>::max())) |
| 1660 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1661 | context->recordError(Error(GL_OUT_OF_MEMORY)); |
| 1662 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | // Check for reading past the end of the bound buffer object |
| 1666 | if (byteCount > elementArrayBuffer->getSize()) |
| 1667 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1668 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1669 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | else if (!indices) |
| 1673 | { |
| 1674 | // Catch this programming error here |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1675 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1676 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 1677 | } |
| 1678 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1679 | // Use max index to validate if our vertex buffers are large enough for the pull. |
| 1680 | // TODO: offer fast path, with disabled index validation. |
| 1681 | // TODO: also disable index checking on back-ends that are robust to out-of-range accesses. |
| 1682 | if (elementArrayBuffer) |
| 1683 | { |
Jacek Caban | a5521de | 2014-10-01 17:23:46 +0200 | [diff] [blame] | 1684 | uintptr_t offset = reinterpret_cast<uintptr_t>(indices); |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1685 | if (!elementArrayBuffer->getIndexRangeCache()->findRange(type, offset, count, indexRangeOut, NULL)) |
| 1686 | { |
Jamie Madill | 9ae396b | 2014-10-21 17:46:30 -0400 | [diff] [blame] | 1687 | // FIXME(jmadill): Use buffer data caching instead of the D3D back-end |
| 1688 | rx::BufferD3D *bufferD3D = rx::BufferD3D::makeBufferD3D(elementArrayBuffer->getImplementation()); |
Geoff Lang | c8d297a | 2014-09-19 11:09:08 -0400 | [diff] [blame] | 1689 | const uint8_t *dataPointer = NULL; |
Jamie Madill | 9ae396b | 2014-10-21 17:46:30 -0400 | [diff] [blame] | 1690 | Error error = bufferD3D->getData(&dataPointer); |
Geoff Lang | c8d297a | 2014-09-19 11:09:08 -0400 | [diff] [blame] | 1691 | if (error.isError()) |
| 1692 | { |
| 1693 | context->recordError(error); |
| 1694 | return false; |
| 1695 | } |
| 1696 | |
| 1697 | const uint8_t *offsetPointer = dataPointer + offset; |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1698 | *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, offsetPointer, count); |
| 1699 | } |
| 1700 | } |
| 1701 | else |
| 1702 | { |
| 1703 | *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, indices, count); |
| 1704 | } |
| 1705 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1706 | if (!ValidateDrawBase(context, mode, count, static_cast<GLsizei>(indexRangeOut->end), primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1707 | { |
| 1708 | return false; |
| 1709 | } |
| 1710 | |
| 1711 | return true; |
| 1712 | } |
| 1713 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1714 | bool ValidateDrawElementsInstanced(Context *context, |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1715 | GLenum mode, GLsizei count, GLenum type, |
| 1716 | const GLvoid *indices, GLsizei primcount, |
| 1717 | rx::RangeUI *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1718 | { |
| 1719 | if (primcount < 0) |
| 1720 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1721 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1722 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1723 | } |
| 1724 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 1725 | if (!ValidateDrawElements(context, mode, count, type, indices, primcount, indexRangeOut)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 1726 | { |
| 1727 | return false; |
| 1728 | } |
| 1729 | |
| 1730 | // No-op zero primitive count |
| 1731 | return (primcount > 0); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 1732 | } |
| 1733 | |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 1734 | bool ValidateDrawElementsInstancedANGLE(Context *context, GLenum mode, GLsizei count, GLenum type, |
| 1735 | const GLvoid *indices, GLsizei primcount, rx::RangeUI *indexRangeOut) |
| 1736 | { |
| 1737 | if (!ValidateDrawInstancedANGLE(context)) |
| 1738 | { |
| 1739 | return false; |
| 1740 | } |
| 1741 | |
| 1742 | return ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, indexRangeOut); |
| 1743 | } |
| 1744 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1745 | bool ValidateFramebufferTextureBase(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1746 | GLuint texture, GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1747 | { |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1748 | if (!ValidFramebufferTarget(target)) |
| 1749 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1750 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1751 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1755 | { |
| 1756 | return false; |
| 1757 | } |
| 1758 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1759 | if (texture != 0) |
| 1760 | { |
| 1761 | gl::Texture *tex = context->getTexture(texture); |
| 1762 | |
| 1763 | if (tex == NULL) |
| 1764 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1765 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1766 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | if (level < 0) |
| 1770 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1771 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1772 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1773 | } |
| 1774 | } |
| 1775 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1776 | const gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); |
| 1777 | GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id(); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1778 | |
| 1779 | if (framebufferHandle == 0 || !framebuffer) |
| 1780 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1781 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1782 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | return true; |
| 1786 | } |
| 1787 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1788 | bool ValidateFramebufferTexture2D(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1789 | GLenum textarget, GLuint texture, GLint level) |
| 1790 | { |
| 1791 | // Attachments are required to be bound to level 0 in ES2 |
| 1792 | if (context->getClientVersion() < 3 && level != 0) |
| 1793 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1794 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1795 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1799 | { |
| 1800 | return false; |
| 1801 | } |
| 1802 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1803 | if (texture != 0) |
| 1804 | { |
| 1805 | gl::Texture *tex = context->getTexture(texture); |
| 1806 | ASSERT(tex); |
| 1807 | |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1808 | const gl::Caps &caps = context->getCaps(); |
| 1809 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1810 | switch (textarget) |
| 1811 | { |
| 1812 | case GL_TEXTURE_2D: |
| 1813 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1814 | if (level > gl::log2(caps.max2DTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1815 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1816 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1817 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1818 | } |
| 1819 | if (tex->getTarget() != GL_TEXTURE_2D) |
| 1820 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1821 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1822 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1823 | } |
| 1824 | gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex); |
| 1825 | if (tex2d->isCompressed(level)) |
| 1826 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1827 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1828 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1829 | } |
| 1830 | } |
| 1831 | break; |
| 1832 | |
| 1833 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1834 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1835 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1836 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1837 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1838 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1839 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 1840 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1841 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1842 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1843 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1844 | } |
| 1845 | if (tex->getTarget() != GL_TEXTURE_CUBE_MAP) |
| 1846 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1847 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1848 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1849 | } |
| 1850 | gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex); |
| 1851 | if (texcube->isCompressed(textarget, level)) |
| 1852 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1853 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1854 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1855 | } |
| 1856 | } |
| 1857 | break; |
| 1858 | |
| 1859 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1860 | context->recordError(Error(GL_INVALID_ENUM)); |
| 1861 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1862 | } |
| 1863 | } |
| 1864 | |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1865 | return true; |
| 1866 | } |
| 1867 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1868 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1869 | { |
| 1870 | if (program == 0) |
| 1871 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1872 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1873 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1874 | } |
| 1875 | |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 1876 | if (!ValidProgram(context, program)) |
| 1877 | { |
| 1878 | return false; |
| 1879 | } |
| 1880 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1881 | gl::Program *programObject = context->getProgram(program); |
| 1882 | |
| 1883 | if (!programObject || !programObject->isLinked()) |
| 1884 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1885 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1886 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | gl::ProgramBinary *programBinary = programObject->getProgramBinary(); |
| 1890 | if (!programBinary) |
| 1891 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1892 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1893 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1894 | } |
| 1895 | |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 1896 | if (!programBinary->isValidUniformLocation(location)) |
| 1897 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1898 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1899 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 1900 | } |
| 1901 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1902 | return true; |
| 1903 | } |
| 1904 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1905 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat* params) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1906 | { |
| 1907 | return ValidateGetUniformBase(context, program, location); |
| 1908 | } |
| 1909 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1910 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1911 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1912 | return ValidateGetUniformBase(context, program, location); |
| 1913 | } |
| 1914 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1915 | static bool ValidateSizedGetUniform(Context *context, GLuint program, GLint location, GLsizei bufSize) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1916 | { |
| 1917 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1918 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1919 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1920 | } |
| 1921 | |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 1922 | gl::Program *programObject = context->getProgram(program); |
| 1923 | ASSERT(programObject); |
| 1924 | gl::ProgramBinary *programBinary = programObject->getProgramBinary(); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1925 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1926 | // sized queries -- ensure the provided buffer is large enough |
| 1927 | LinkedUniform *uniform = programBinary->getUniformByLocation(location); |
| 1928 | size_t requiredBytes = VariableExternalSize(uniform->type); |
| 1929 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1930 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1931 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1932 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | return true; |
| 1936 | } |
| 1937 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1938 | bool ValidateGetnUniformfvEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLfloat* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1939 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1940 | return ValidateSizedGetUniform(context, program, location, bufSize); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1941 | } |
| 1942 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1943 | bool ValidateGetnUniformivEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1944 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1945 | return ValidateSizedGetUniform(context, program, location, bufSize); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1946 | } |
| 1947 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1948 | } |