blob: 0139245780232ac4a2620feca1d45223772cc83b [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Geoff Lang48dcae72014-02-05 16:28:24 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// libGLESv2.cpp: Implements the exported OpenGL ES 2.0 functions.
8
Geoff Lang2b5420c2014-11-19 14:20:15 -05009#include "libGLESv2/main.h"
10
11#include "libANGLE/formatutils.h"
12#include "libANGLE/Buffer.h"
13#include "libANGLE/Fence.h"
14#include "libANGLE/Framebuffer.h"
15#include "libANGLE/Renderbuffer.h"
16#include "libANGLE/Program.h"
17#include "libANGLE/ProgramBinary.h"
18#include "libANGLE/Texture.h"
19#include "libANGLE/Query.h"
20#include "libANGLE/Context.h"
21#include "libANGLE/VertexArray.h"
22#include "libANGLE/VertexAttribute.h"
23#include "libANGLE/TransformFeedback.h"
24#include "libANGLE/FramebufferAttachment.h"
25
26#include "libANGLE/validationES.h"
27#include "libANGLE/validationES2.h"
28#include "libANGLE/validationES3.h"
29#include "libANGLE/queryconversions.h"
Geoff Langf0a2c772014-11-20 15:15:01 -050030#include "libANGLE/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050031
Geoff Lang0b7eef72014-06-12 14:10:47 -040032#include "common/utilities.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000033
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000034extern "C"
35{
36
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +000037// OpenGL ES 2.0 functions
38
Kenneth Russell67ea1902014-10-06 16:44:50 -070039void GL_APIENTRY glActiveTexture(GLenum texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000040{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000041 EVENT("(GLenum texture = 0x%X)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000042
Geoff Langbfdea662014-07-23 14:16:32 -040043 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -040044 if (context)
45 {
Geoff Lang3a61c322014-07-10 13:01:54 -040046 if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000047 {
Geoff Langb1196682014-07-23 13:47:29 -040048 context->recordError(gl::Error(GL_INVALID_ENUM));
49 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000050 }
Geoff Langbfdea662014-07-23 14:16:32 -040051
52 context->getState().setActiveSampler(texture - GL_TEXTURE0);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000053 }
54}
55
Kenneth Russell67ea1902014-10-06 16:44:50 -070056void GL_APIENTRY glAttachShader(GLuint program, GLuint shader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000057{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +000058 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000059
Geoff Langbfdea662014-07-23 14:16:32 -040060 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -040061 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000062 {
Geoff Langbfdea662014-07-23 14:16:32 -040063 gl::Program *programObject = context->getProgram(program);
64 gl::Shader *shaderObject = context->getShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000065
Geoff Langbfdea662014-07-23 14:16:32 -040066 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000067 {
Geoff Langbfdea662014-07-23 14:16:32 -040068 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000069 {
Geoff Langb1196682014-07-23 13:47:29 -040070 context->recordError(gl::Error(GL_INVALID_OPERATION));
71 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000072 }
Geoff Langbfdea662014-07-23 14:16:32 -040073 else
74 {
Geoff Langb1196682014-07-23 13:47:29 -040075 context->recordError(gl::Error(GL_INVALID_VALUE));
76 return;
Geoff Langbfdea662014-07-23 14:16:32 -040077 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000078 }
Geoff Langbfdea662014-07-23 14:16:32 -040079
80 if (!shaderObject)
81 {
82 if (context->getProgram(shader))
83 {
Geoff Langb1196682014-07-23 13:47:29 -040084 context->recordError(gl::Error(GL_INVALID_OPERATION));
85 return;
Geoff Langbfdea662014-07-23 14:16:32 -040086 }
87 else
88 {
Geoff Langb1196682014-07-23 13:47:29 -040089 context->recordError(gl::Error(GL_INVALID_VALUE));
90 return;
Geoff Langbfdea662014-07-23 14:16:32 -040091 }
92 }
93
94 if (!programObject->attachShader(shaderObject))
95 {
Geoff Langb1196682014-07-23 13:47:29 -040096 context->recordError(gl::Error(GL_INVALID_OPERATION));
97 return;
Geoff Langbfdea662014-07-23 14:16:32 -040098 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000099 }
100}
101
Kenneth Russell67ea1902014-10-06 16:44:50 -0700102void GL_APIENTRY glBeginQueryEXT(GLenum target, GLuint id)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000103{
104 EVENT("(GLenum target = 0x%X, GLuint %d)", target, id);
105
Geoff Langbfdea662014-07-23 14:16:32 -0400106 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400107 if (context)
108 {
109 if (!ValidateBeginQuery(context, target, id))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000110 {
Geoff Langbfdea662014-07-23 14:16:32 -0400111 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000112 }
Geoff Langbfdea662014-07-23 14:16:32 -0400113
Geoff Lang5aad9672014-09-08 11:10:42 -0400114 gl::Error error = context->beginQuery(target, id);
115 if (error.isError())
116 {
117 context->recordError(error);
118 return;
119 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +0000120 }
121}
122
Kenneth Russell67ea1902014-10-06 16:44:50 -0700123void GL_APIENTRY glBindAttribLocation(GLuint program, GLuint index, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000124{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000125 EVENT("(GLuint program = %d, GLuint index = %d, const GLchar* name = 0x%0.8p)", program, index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000126
Geoff Langbfdea662014-07-23 14:16:32 -0400127 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400128 if (context)
129 {
Geoff Langb1196682014-07-23 13:47:29 -0400130 if (index >= gl::MAX_VERTEX_ATTRIBS)
131 {
132 context->recordError(gl::Error(GL_INVALID_VALUE));
133 return;
134 }
135
Geoff Langbfdea662014-07-23 14:16:32 -0400136 gl::Program *programObject = context->getProgram(program);
137
138 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000139 {
Geoff Langbfdea662014-07-23 14:16:32 -0400140 if (context->getShader(program))
daniel@transgaming.com98079832010-04-13 03:26:29 +0000141 {
Geoff Langb1196682014-07-23 13:47:29 -0400142 context->recordError(gl::Error(GL_INVALID_OPERATION));
143 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000144 }
Geoff Langbfdea662014-07-23 14:16:32 -0400145 else
146 {
Geoff Langb1196682014-07-23 13:47:29 -0400147 context->recordError(gl::Error(GL_INVALID_VALUE));
148 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400149 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000150 }
Geoff Langbfdea662014-07-23 14:16:32 -0400151
152 if (strncmp(name, "gl_", 3) == 0)
153 {
Geoff Langb1196682014-07-23 13:47:29 -0400154 context->recordError(gl::Error(GL_INVALID_OPERATION));
155 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400156 }
157
158 programObject->bindAttributeLocation(index, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000159 }
160}
161
Kenneth Russell67ea1902014-10-06 16:44:50 -0700162void GL_APIENTRY glBindBuffer(GLenum target, GLuint buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000163{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000164 EVENT("(GLenum target = 0x%X, GLuint buffer = %d)", target, buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000165
Geoff Langbfdea662014-07-23 14:16:32 -0400166 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400167 if (context)
168 {
169 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000170 {
Geoff Langb1196682014-07-23 13:47:29 -0400171 context->recordError(gl::Error(GL_INVALID_ENUM));
172 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000173 }
Geoff Langbfdea662014-07-23 14:16:32 -0400174
175 switch (target)
176 {
177 case GL_ARRAY_BUFFER:
178 context->bindArrayBuffer(buffer);
179 return;
180 case GL_ELEMENT_ARRAY_BUFFER:
181 context->bindElementArrayBuffer(buffer);
182 return;
183 case GL_COPY_READ_BUFFER:
184 context->bindCopyReadBuffer(buffer);
185 return;
186 case GL_COPY_WRITE_BUFFER:
187 context->bindCopyWriteBuffer(buffer);
188 return;
189 case GL_PIXEL_PACK_BUFFER:
190 context->bindPixelPackBuffer(buffer);
191 return;
192 case GL_PIXEL_UNPACK_BUFFER:
193 context->bindPixelUnpackBuffer(buffer);
194 return;
195 case GL_UNIFORM_BUFFER:
196 context->bindGenericUniformBuffer(buffer);
197 return;
198 case GL_TRANSFORM_FEEDBACK_BUFFER:
199 context->bindGenericTransformFeedbackBuffer(buffer);
200 return;
Geoff Langb1196682014-07-23 13:47:29 -0400201
Geoff Langbfdea662014-07-23 14:16:32 -0400202 default:
Geoff Langb1196682014-07-23 13:47:29 -0400203 context->recordError(gl::Error(GL_INVALID_ENUM));
204 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400205 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000206 }
207}
208
Kenneth Russell67ea1902014-10-06 16:44:50 -0700209void GL_APIENTRY glBindFramebuffer(GLenum target, GLuint framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000210{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000211 EVENT("(GLenum target = 0x%X, GLuint framebuffer = %d)", target, framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000212
Geoff Langbfdea662014-07-23 14:16:32 -0400213 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400214 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000215 {
Geoff Langb1196682014-07-23 13:47:29 -0400216 if (!gl::ValidFramebufferTarget(target))
217 {
218 context->recordError(gl::Error(GL_INVALID_ENUM));
219 return;
220 }
221
Geoff Langbfdea662014-07-23 14:16:32 -0400222 if (target == GL_READ_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
223 {
224 context->bindReadFramebuffer(framebuffer);
225 }
226
227 if (target == GL_DRAW_FRAMEBUFFER_ANGLE || target == GL_FRAMEBUFFER)
228 {
229 context->bindDrawFramebuffer(framebuffer);
230 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000231 }
232}
233
Kenneth Russell67ea1902014-10-06 16:44:50 -0700234void GL_APIENTRY glBindRenderbuffer(GLenum target, GLuint renderbuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000235{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000236 EVENT("(GLenum target = 0x%X, GLuint renderbuffer = %d)", target, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000237
Geoff Langbfdea662014-07-23 14:16:32 -0400238 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400239 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000240 {
Geoff Langb1196682014-07-23 13:47:29 -0400241 if (target != GL_RENDERBUFFER)
242 {
243 context->recordError(gl::Error(GL_INVALID_ENUM));
244 return;
245 }
246
Geoff Langbfdea662014-07-23 14:16:32 -0400247 context->bindRenderbuffer(renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000248 }
249}
250
Kenneth Russell67ea1902014-10-06 16:44:50 -0700251void GL_APIENTRY glBindTexture(GLenum target, GLuint texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000252{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000253 EVENT("(GLenum target = 0x%X, GLuint texture = %d)", target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000254
Geoff Langbfdea662014-07-23 14:16:32 -0400255 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400256 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000257 {
Geoff Langbfdea662014-07-23 14:16:32 -0400258 gl::Texture *textureObject = context->getTexture(texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000259
Geoff Langbfdea662014-07-23 14:16:32 -0400260 if (textureObject && textureObject->getTarget() != target && texture != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000261 {
Geoff Langb1196682014-07-23 13:47:29 -0400262 context->recordError(gl::Error(GL_INVALID_OPERATION));
263 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400264 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000265
Geoff Langbfdea662014-07-23 14:16:32 -0400266 switch (target)
267 {
268 case GL_TEXTURE_2D:
Geoff Langbfdea662014-07-23 14:16:32 -0400269 case GL_TEXTURE_CUBE_MAP:
Geoff Lang76b10c92014-09-05 16:28:14 -0400270 break;
Geoff Langb1196682014-07-23 13:47:29 -0400271
Geoff Langbfdea662014-07-23 14:16:32 -0400272 case GL_TEXTURE_3D:
Geoff Langbfdea662014-07-23 14:16:32 -0400273 case GL_TEXTURE_2D_ARRAY:
274 if (context->getClientVersion() < 3)
275 {
Geoff Langb1196682014-07-23 13:47:29 -0400276 context->recordError(gl::Error(GL_INVALID_ENUM));
277 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400278 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400279 break;
Geoff Langb1196682014-07-23 13:47:29 -0400280
Geoff Langbfdea662014-07-23 14:16:32 -0400281 default:
Geoff Langb1196682014-07-23 13:47:29 -0400282 context->recordError(gl::Error(GL_INVALID_ENUM));
283 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000284 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400285
286 context->bindTexture(target, texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000287 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000288}
289
Kenneth Russell67ea1902014-10-06 16:44:50 -0700290void GL_APIENTRY glBlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000291{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000292 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000293 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000294
Geoff Langbfdea662014-07-23 14:16:32 -0400295 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000296
Geoff Langbfdea662014-07-23 14:16:32 -0400297 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000298 {
Geoff Langbfdea662014-07-23 14:16:32 -0400299 context->getState().setBlendColor(gl::clamp01(red), gl::clamp01(green), gl::clamp01(blue), gl::clamp01(alpha));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000300 }
301}
302
Kenneth Russell67ea1902014-10-06 16:44:50 -0700303void GL_APIENTRY glBlendEquation(GLenum mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000304{
305 glBlendEquationSeparate(mode, mode);
306}
307
Kenneth Russell67ea1902014-10-06 16:44:50 -0700308void GL_APIENTRY glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000309{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000310 EVENT("(GLenum modeRGB = 0x%X, GLenum modeAlpha = 0x%X)", modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000311
Geoff Langbfdea662014-07-23 14:16:32 -0400312 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400313 if (context)
314 {
Geoff Langb1196682014-07-23 13:47:29 -0400315 switch (modeRGB)
316 {
317 case GL_FUNC_ADD:
318 case GL_FUNC_SUBTRACT:
319 case GL_FUNC_REVERSE_SUBTRACT:
320 case GL_MIN:
321 case GL_MAX:
322 break;
323
324 default:
325 context->recordError(gl::Error(GL_INVALID_ENUM));
326 return;
327 }
328
329 switch (modeAlpha)
330 {
331 case GL_FUNC_ADD:
332 case GL_FUNC_SUBTRACT:
333 case GL_FUNC_REVERSE_SUBTRACT:
334 case GL_MIN:
335 case GL_MAX:
336 break;
337
338 default:
339 context->recordError(gl::Error(GL_INVALID_ENUM));
340 return;
341 }
342
Geoff Langbfdea662014-07-23 14:16:32 -0400343 context->getState().setBlendEquation(modeRGB, modeAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000344 }
345}
346
Kenneth Russell67ea1902014-10-06 16:44:50 -0700347void GL_APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000348{
349 glBlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
350}
351
Kenneth Russell67ea1902014-10-06 16:44:50 -0700352void GL_APIENTRY glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000353{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000354 EVENT("(GLenum srcRGB = 0x%X, GLenum dstRGB = 0x%X, GLenum srcAlpha = 0x%X, GLenum dstAlpha = 0x%X)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000355 srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000356
Geoff Langbfdea662014-07-23 14:16:32 -0400357 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400358 if (context)
359 {
Geoff Langb1196682014-07-23 13:47:29 -0400360 switch (srcRGB)
361 {
362 case GL_ZERO:
363 case GL_ONE:
364 case GL_SRC_COLOR:
365 case GL_ONE_MINUS_SRC_COLOR:
366 case GL_DST_COLOR:
367 case GL_ONE_MINUS_DST_COLOR:
368 case GL_SRC_ALPHA:
369 case GL_ONE_MINUS_SRC_ALPHA:
370 case GL_DST_ALPHA:
371 case GL_ONE_MINUS_DST_ALPHA:
372 case GL_CONSTANT_COLOR:
373 case GL_ONE_MINUS_CONSTANT_COLOR:
374 case GL_CONSTANT_ALPHA:
375 case GL_ONE_MINUS_CONSTANT_ALPHA:
376 case GL_SRC_ALPHA_SATURATE:
377 break;
378
379 default:
380 context->recordError(gl::Error(GL_INVALID_ENUM));
381 return;
382 }
383
384 switch (dstRGB)
385 {
386 case GL_ZERO:
387 case GL_ONE:
388 case GL_SRC_COLOR:
389 case GL_ONE_MINUS_SRC_COLOR:
390 case GL_DST_COLOR:
391 case GL_ONE_MINUS_DST_COLOR:
392 case GL_SRC_ALPHA:
393 case GL_ONE_MINUS_SRC_ALPHA:
394 case GL_DST_ALPHA:
395 case GL_ONE_MINUS_DST_ALPHA:
396 case GL_CONSTANT_COLOR:
397 case GL_ONE_MINUS_CONSTANT_COLOR:
398 case GL_CONSTANT_ALPHA:
399 case GL_ONE_MINUS_CONSTANT_ALPHA:
400 break;
401
402 case GL_SRC_ALPHA_SATURATE:
403 if (context->getClientVersion() < 3)
404 {
405 context->recordError(gl::Error(GL_INVALID_ENUM));
406 return;
407 }
408 break;
409
410 default:
411 context->recordError(gl::Error(GL_INVALID_ENUM));
412 return;
413 }
414
415 switch (srcAlpha)
416 {
417 case GL_ZERO:
418 case GL_ONE:
419 case GL_SRC_COLOR:
420 case GL_ONE_MINUS_SRC_COLOR:
421 case GL_DST_COLOR:
422 case GL_ONE_MINUS_DST_COLOR:
423 case GL_SRC_ALPHA:
424 case GL_ONE_MINUS_SRC_ALPHA:
425 case GL_DST_ALPHA:
426 case GL_ONE_MINUS_DST_ALPHA:
427 case GL_CONSTANT_COLOR:
428 case GL_ONE_MINUS_CONSTANT_COLOR:
429 case GL_CONSTANT_ALPHA:
430 case GL_ONE_MINUS_CONSTANT_ALPHA:
431 case GL_SRC_ALPHA_SATURATE:
432 break;
433
434 default:
435 context->recordError(gl::Error(GL_INVALID_ENUM));
436 return;
437 }
438
439 switch (dstAlpha)
440 {
441 case GL_ZERO:
442 case GL_ONE:
443 case GL_SRC_COLOR:
444 case GL_ONE_MINUS_SRC_COLOR:
445 case GL_DST_COLOR:
446 case GL_ONE_MINUS_DST_COLOR:
447 case GL_SRC_ALPHA:
448 case GL_ONE_MINUS_SRC_ALPHA:
449 case GL_DST_ALPHA:
450 case GL_ONE_MINUS_DST_ALPHA:
451 case GL_CONSTANT_COLOR:
452 case GL_ONE_MINUS_CONSTANT_COLOR:
453 case GL_CONSTANT_ALPHA:
454 case GL_ONE_MINUS_CONSTANT_ALPHA:
455 break;
456
457 case GL_SRC_ALPHA_SATURATE:
458 if (context->getClientVersion() < 3)
459 {
460 context->recordError(gl::Error(GL_INVALID_ENUM));
461 return;
462 }
463 break;
464
465 default:
466 context->recordError(gl::Error(GL_INVALID_ENUM));
467 return;
468 }
469
470 bool constantColorUsed = (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
471 dstRGB == GL_CONSTANT_COLOR || dstRGB == GL_ONE_MINUS_CONSTANT_COLOR);
472
473 bool constantAlphaUsed = (srcRGB == GL_CONSTANT_ALPHA || srcRGB == GL_ONE_MINUS_CONSTANT_ALPHA ||
474 dstRGB == GL_CONSTANT_ALPHA || dstRGB == GL_ONE_MINUS_CONSTANT_ALPHA);
475
476 if (constantColorUsed && constantAlphaUsed)
477 {
478 ERR("Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR invalid under WebGL");
479 context->recordError(gl::Error(GL_INVALID_OPERATION));
480 return;
481 }
482
Geoff Langbfdea662014-07-23 14:16:32 -0400483 context->getState().setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000484 }
485}
486
Kenneth Russell67ea1902014-10-06 16:44:50 -0700487void GL_APIENTRY glBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000488{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000489 EVENT("(GLenum target = 0x%X, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p, GLenum usage = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000490 target, size, data, usage);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000491
Geoff Langbfdea662014-07-23 14:16:32 -0400492 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400493 if (context)
494 {
Geoff Langb1196682014-07-23 13:47:29 -0400495 if (size < 0)
496 {
497 context->recordError(gl::Error(GL_INVALID_VALUE));
498 return;
499 }
500
501 switch (usage)
502 {
503 case GL_STREAM_DRAW:
504 case GL_STATIC_DRAW:
505 case GL_DYNAMIC_DRAW:
506 break;
507
508 case GL_STREAM_READ:
509 case GL_STREAM_COPY:
510 case GL_STATIC_READ:
511 case GL_STATIC_COPY:
512 case GL_DYNAMIC_READ:
513 case GL_DYNAMIC_COPY:
514 if (context->getClientVersion() < 3)
515 {
516 context->recordError(gl::Error(GL_INVALID_ENUM));
517 return;
518 }
519 break;
520
521 default:
522 context->recordError(gl::Error(GL_INVALID_ENUM));
523 return;
524 }
525
Geoff Langbfdea662014-07-23 14:16:32 -0400526 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000527 {
Geoff Langb1196682014-07-23 13:47:29 -0400528 context->recordError(gl::Error(GL_INVALID_ENUM));
529 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000530 }
531
Geoff Langbfdea662014-07-23 14:16:32 -0400532 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
533
534 if (!buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000535 {
Geoff Langb1196682014-07-23 13:47:29 -0400536 context->recordError(gl::Error(GL_INVALID_OPERATION));
537 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000538 }
Geoff Langbfdea662014-07-23 14:16:32 -0400539
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400540 gl::Error error = buffer->bufferData(data, size, usage);
541 if (error.isError())
542 {
543 context->recordError(error);
544 return;
545 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000546 }
547}
548
Kenneth Russell67ea1902014-10-06 16:44:50 -0700549void GL_APIENTRY glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000550{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000551 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr size = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000552 target, offset, size, data);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000553
Geoff Langbfdea662014-07-23 14:16:32 -0400554 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400555 if (context)
556 {
Geoff Langb1196682014-07-23 13:47:29 -0400557 if (size < 0 || offset < 0)
558 {
559 context->recordError(gl::Error(GL_INVALID_VALUE));
560 return;
561 }
562
563 if (data == NULL)
564 {
565 return;
566 }
567
Geoff Langbfdea662014-07-23 14:16:32 -0400568 if (!gl::ValidBufferTarget(context, target))
569 {
Geoff Langb1196682014-07-23 13:47:29 -0400570 context->recordError(gl::Error(GL_INVALID_ENUM));
571 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400572 }
573
574 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
575
576 if (!buffer)
577 {
Geoff Langb1196682014-07-23 13:47:29 -0400578 context->recordError(gl::Error(GL_INVALID_OPERATION));
579 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400580 }
581
582 if (buffer->isMapped())
583 {
Geoff Langb1196682014-07-23 13:47:29 -0400584 context->recordError(gl::Error(GL_INVALID_OPERATION));
585 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400586 }
587
588 // Check for possible overflow of size + offset
589 if (!rx::IsUnsignedAdditionSafe<size_t>(size, offset))
590 {
Geoff Langb1196682014-07-23 13:47:29 -0400591 context->recordError(gl::Error(GL_OUT_OF_MEMORY));
592 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400593 }
594
595 if (size + offset > buffer->getSize())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000596 {
Geoff Langb1196682014-07-23 13:47:29 -0400597 context->recordError(gl::Error(GL_INVALID_VALUE));
598 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000599 }
600
Geoff Lang2a1c15a2014-07-25 11:43:00 -0400601 gl::Error error = buffer->bufferSubData(data, size, offset);
602 if (error.isError())
603 {
604 context->recordError(error);
605 return;
606 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000607 }
608}
609
Kenneth Russell67ea1902014-10-06 16:44:50 -0700610GLenum GL_APIENTRY glCheckFramebufferStatus(GLenum target)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000611{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000612 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000613
Geoff Langbfdea662014-07-23 14:16:32 -0400614 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400615 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000616 {
Geoff Langb1196682014-07-23 13:47:29 -0400617 if (!gl::ValidFramebufferTarget(target))
618 {
619 context->recordError(gl::Error(GL_INVALID_ENUM));
620 return 0;
621 }
622
Geoff Langbfdea662014-07-23 14:16:32 -0400623 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
624 ASSERT(framebuffer);
Jamie Madill48faf802014-11-06 15:27:22 -0500625
626 return framebuffer->completeness(context->getData());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000627 }
628
629 return 0;
630}
631
Kenneth Russell67ea1902014-10-06 16:44:50 -0700632void GL_APIENTRY glClear(GLbitfield mask)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000633{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000634 EVENT("(GLbitfield mask = 0x%X)", mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000635
Geoff Langbfdea662014-07-23 14:16:32 -0400636 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400637 if (context)
638 {
639 gl::Framebuffer *framebufferObject = context->getState().getDrawFramebuffer();
Jamie Madill48faf802014-11-06 15:27:22 -0500640 ASSERT(framebufferObject);
Geoff Langbfdea662014-07-23 14:16:32 -0400641
Jamie Madill48faf802014-11-06 15:27:22 -0500642 if (framebufferObject->completeness(context->getData()) != GL_FRAMEBUFFER_COMPLETE)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000643 {
Geoff Langb1196682014-07-23 13:47:29 -0400644 context->recordError(gl::Error(GL_INVALID_FRAMEBUFFER_OPERATION));
645 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000646 }
Geoff Langbfdea662014-07-23 14:16:32 -0400647
648 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)) != 0)
649 {
Geoff Langb1196682014-07-23 13:47:29 -0400650 context->recordError(gl::Error(GL_INVALID_VALUE));
651 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400652 }
653
Geoff Langcc79b8c2014-07-25 13:48:02 -0400654 gl::Error error = context->clear(mask);
655 if (error.isError())
656 {
657 context->recordError(error);
658 return;
659 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000660 }
661}
662
Kenneth Russell67ea1902014-10-06 16:44:50 -0700663void GL_APIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000664{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000665 EVENT("(GLclampf red = %f, GLclampf green = %f, GLclampf blue = %f, GLclampf alpha = %f)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000666 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000667
Geoff Langbfdea662014-07-23 14:16:32 -0400668 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400669 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000670 {
Geoff Langbfdea662014-07-23 14:16:32 -0400671 context->getState().setClearColor(red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000672 }
673}
674
Kenneth Russell67ea1902014-10-06 16:44:50 -0700675void GL_APIENTRY glClearDepthf(GLclampf depth)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000676{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000677 EVENT("(GLclampf depth = %f)", depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000678
Geoff Langbfdea662014-07-23 14:16:32 -0400679 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400680 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000681 {
Geoff Langbfdea662014-07-23 14:16:32 -0400682 context->getState().setClearDepth(depth);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000683 }
684}
685
Kenneth Russell67ea1902014-10-06 16:44:50 -0700686void GL_APIENTRY glClearStencil(GLint s)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000687{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000688 EVENT("(GLint s = %d)", s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000689
Geoff Langbfdea662014-07-23 14:16:32 -0400690 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400691 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000692 {
Geoff Langbfdea662014-07-23 14:16:32 -0400693 context->getState().setClearStencil(s);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000694 }
695}
696
Kenneth Russell67ea1902014-10-06 16:44:50 -0700697void GL_APIENTRY glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000698{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +0000699 EVENT("(GLboolean red = %d, GLboolean green = %u, GLboolean blue = %u, GLboolean alpha = %u)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000700 red, green, blue, alpha);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000701
Geoff Langbfdea662014-07-23 14:16:32 -0400702 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400703 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000704 {
Geoff Langbfdea662014-07-23 14:16:32 -0400705 context->getState().setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000706 }
707}
708
Kenneth Russell67ea1902014-10-06 16:44:50 -0700709void GL_APIENTRY glCompileShader(GLuint shader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000710{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000711 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000712
Geoff Langbfdea662014-07-23 14:16:32 -0400713 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400714 if (context)
715 {
716 gl::Shader *shaderObject = context->getShader(shader);
717
718 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000719 {
Geoff Langbfdea662014-07-23 14:16:32 -0400720 if (context->getProgram(shader))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000721 {
Geoff Langb1196682014-07-23 13:47:29 -0400722 context->recordError(gl::Error(GL_INVALID_OPERATION));
723 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000724 }
Geoff Langbfdea662014-07-23 14:16:32 -0400725 else
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000726 {
Geoff Langb1196682014-07-23 13:47:29 -0400727 context->recordError(gl::Error(GL_INVALID_VALUE));
728 return;
daniel@transgaming.com5d752f22010-10-07 13:37:20 +0000729 }
daniel@transgaming.com01868132010-08-24 19:21:17 +0000730 }
Geoff Langbfdea662014-07-23 14:16:32 -0400731
Jamie Madill245d3602014-11-13 10:03:30 -0500732 shaderObject->compile(context->getData());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000733 }
Geoff Langbfdea662014-07-23 14:16:32 -0400734}
735
Kenneth Russell67ea1902014-10-06 16:44:50 -0700736void GL_APIENTRY glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
Geoff Langbfdea662014-07-23 14:16:32 -0400737 GLint border, GLsizei imageSize, const GLvoid* data)
738{
739 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
740 "GLsizei height = %d, GLint border = %d, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
741 target, level, internalformat, width, height, border, imageSize, data);
742
743 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400744 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000745 {
Geoff Langbfdea662014-07-23 14:16:32 -0400746 if (context->getClientVersion() < 3 &&
747 !ValidateES2TexImageParameters(context, target, level, internalformat, true, false,
748 0, 0, width, height, border, GL_NONE, GL_NONE, data))
749 {
750 return;
751 }
752
753 if (context->getClientVersion() >= 3 &&
754 !ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
755 0, 0, 0, width, height, 1, border, GL_NONE, GL_NONE, data))
756 {
757 return;
758 }
759
Geoff Lang5d601382014-07-22 15:14:06 -0400760 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
761 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400762 {
Geoff Langb1196682014-07-23 13:47:29 -0400763 context->recordError(gl::Error(GL_INVALID_VALUE));
764 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400765 }
766
767 switch (target)
768 {
769 case GL_TEXTURE_2D:
770 {
771 gl::Texture2D *texture = context->getTexture2D();
Jamie Madillc751d1e2014-10-21 17:46:29 -0400772 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, imageSize, context->getState().getUnpackState(), data);
Geoff Langb5348332014-09-02 13:16:34 -0400773 if (error.isError())
774 {
775 context->recordError(error);
776 return;
777 }
Geoff Langbfdea662014-07-23 14:16:32 -0400778 }
779 break;
780
781 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
782 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
783 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
784 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
785 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
786 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
787 {
788 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Jamie Madillc751d1e2014-10-21 17:46:29 -0400789 gl::Error error = texture->setCompressedImage(target, level, internalformat, width, height, imageSize, context->getState().getUnpackState(), data);
Geoff Langb5348332014-09-02 13:16:34 -0400790 if (error.isError())
791 {
792 context->recordError(error);
793 return;
794 }
Geoff Langbfdea662014-07-23 14:16:32 -0400795 }
796 break;
797
798 default:
Geoff Langb1196682014-07-23 13:47:29 -0400799 context->recordError(gl::Error(GL_INVALID_ENUM));
800 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400801 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000802 }
803}
804
Kenneth Russell67ea1902014-10-06 16:44:50 -0700805void GL_APIENTRY glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000806 GLenum format, GLsizei imageSize, const GLvoid* data)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000807{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000808 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000809 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +0000810 "GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000811 target, level, xoffset, yoffset, width, height, format, imageSize, data);
812
Geoff Langbfdea662014-07-23 14:16:32 -0400813 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400814 if (context)
815 {
816 if (context->getClientVersion() < 3 &&
817 !ValidateES2TexImageParameters(context, target, level, GL_NONE, true, true,
818 xoffset, yoffset, width, height, 0, GL_NONE, GL_NONE, data))
daniel@transgaming.com01868132010-08-24 19:21:17 +0000819 {
Geoff Langbfdea662014-07-23 14:16:32 -0400820 return;
daniel@transgaming.com01868132010-08-24 19:21:17 +0000821 }
Geoff Langbfdea662014-07-23 14:16:32 -0400822
823 if (context->getClientVersion() >= 3 &&
824 !ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
825 xoffset, yoffset, 0, width, height, 1, 0, GL_NONE, GL_NONE, data))
826 {
827 return;
828 }
829
Geoff Lang5d601382014-07-22 15:14:06 -0400830 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
831 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -0400832 {
Geoff Langb1196682014-07-23 13:47:29 -0400833 context->recordError(gl::Error(GL_INVALID_VALUE));
834 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400835 }
836
837 switch (target)
838 {
839 case GL_TEXTURE_2D:
840 {
841 gl::Texture2D *texture = context->getTexture2D();
Jamie Madillc751d1e2014-10-21 17:46:29 -0400842 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, width, height, format, imageSize, context->getState().getUnpackState(), data);
Geoff Langb5348332014-09-02 13:16:34 -0400843 if (error.isError())
844 {
845 context->recordError(error);
846 return;
847 }
Geoff Langbfdea662014-07-23 14:16:32 -0400848 }
849 break;
850
851 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
852 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
853 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
854 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
855 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
856 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
857 {
858 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Jamie Madillc751d1e2014-10-21 17:46:29 -0400859 gl::Error error = texture->subImageCompressed(target, level, xoffset, yoffset, width, height, format, imageSize, context->getState().getUnpackState(), data);
Geoff Langb5348332014-09-02 13:16:34 -0400860 if (error.isError())
861 {
862 context->recordError(error);
863 return;
864 }
Geoff Langbfdea662014-07-23 14:16:32 -0400865 }
866 break;
867
868 default:
Geoff Langb1196682014-07-23 13:47:29 -0400869 context->recordError(gl::Error(GL_INVALID_ENUM));
870 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400871 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000872 }
873}
874
Kenneth Russell67ea1902014-10-06 16:44:50 -0700875void GL_APIENTRY glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000876{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000877 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000878 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, GLint border = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000879 target, level, internalformat, x, y, width, height, border);
880
Geoff Langbfdea662014-07-23 14:16:32 -0400881 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400882 if (context)
883 {
884 if (context->getClientVersion() < 3 &&
885 !ValidateES2CopyTexImageParameters(context, target, level, internalformat, false,
886 0, 0, x, y, width, height, border))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000887 {
Geoff Langbfdea662014-07-23 14:16:32 -0400888 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000889 }
Geoff Langbfdea662014-07-23 14:16:32 -0400890
891 if (context->getClientVersion() >= 3 &&
892 !ValidateES3CopyTexImageParameters(context, target, level, internalformat, false,
893 0, 0, 0, x, y, width, height, border))
894 {
895 return;
896 }
897
898 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
899
900 switch (target)
901 {
902 case GL_TEXTURE_2D:
903 {
904 gl::Texture2D *texture = context->getTexture2D();
Geoff Langef7b0162014-09-04 13:29:23 -0400905 gl::Error error = texture->copyImage(level, internalformat, x, y, width, height, framebuffer);
906 if (error.isError())
907 {
908 context->recordError(error);
909 return;
910 }
Geoff Langbfdea662014-07-23 14:16:32 -0400911 }
912 break;
913
914 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
915 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
916 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
917 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
918 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
919 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
920 {
921 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Langef7b0162014-09-04 13:29:23 -0400922 gl::Error error = texture->copyImage(target, level, internalformat, x, y, width, height, framebuffer);
923 if (error.isError())
924 {
925 context->recordError(error);
926 return;
927 }
Geoff Langbfdea662014-07-23 14:16:32 -0400928 }
929 break;
930
Geoff Langb1196682014-07-23 13:47:29 -0400931 default:
932 context->recordError(gl::Error(GL_INVALID_ENUM));
933 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400934 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000935 }
936}
937
Kenneth Russell67ea1902014-10-06 16:44:50 -0700938void GL_APIENTRY glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000939{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000940 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +0000941 "GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000942 target, level, xoffset, yoffset, x, y, width, height);
943
Geoff Langbfdea662014-07-23 14:16:32 -0400944 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -0400945 if (context)
946 {
947 if (context->getClientVersion() < 3 &&
948 !ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true,
949 xoffset, yoffset, x, y, width, height, 0))
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000950 {
Geoff Langbfdea662014-07-23 14:16:32 -0400951 return;
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000952 }
daniel@transgaming.comb8c28ed2010-04-13 03:26:32 +0000953
Geoff Langbfdea662014-07-23 14:16:32 -0400954 if (context->getClientVersion() >= 3 &&
955 !ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true,
956 xoffset, yoffset, 0, x, y, width, height, 0))
957 {
958 return;
959 }
960
961 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
962
963 switch (target)
964 {
965 case GL_TEXTURE_2D:
966 {
967 gl::Texture2D *texture = context->getTexture2D();
Geoff Langef7b0162014-09-04 13:29:23 -0400968 gl::Error error = texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
969 if (error.isError())
970 {
971 context->recordError(error);
972 return;
973 }
Geoff Langbfdea662014-07-23 14:16:32 -0400974 }
975 break;
976
977 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
978 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
979 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
980 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
981 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
982 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
983 {
984 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Langef7b0162014-09-04 13:29:23 -0400985 gl::Error error = texture->copySubImage(target, level, xoffset, yoffset, 0, x, y, width, height, framebuffer);
986 if (error.isError())
987 {
988 context->recordError(error);
989 return;
990 }
Geoff Langbfdea662014-07-23 14:16:32 -0400991 }
992 break;
993
994 default:
Geoff Langb1196682014-07-23 13:47:29 -0400995 context->recordError(gl::Error(GL_INVALID_ENUM));
996 return;
Geoff Langbfdea662014-07-23 14:16:32 -0400997 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000998 }
999}
1000
Kenneth Russell67ea1902014-10-06 16:44:50 -07001001GLuint GL_APIENTRY glCreateProgram(void)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001002{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001003 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001004
Geoff Langbfdea662014-07-23 14:16:32 -04001005 gl::Context *context = gl::getNonLostContext();
1006 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001007 {
Geoff Langbfdea662014-07-23 14:16:32 -04001008 return context->createProgram();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001009 }
1010
1011 return 0;
1012}
1013
Kenneth Russell67ea1902014-10-06 16:44:50 -07001014GLuint GL_APIENTRY glCreateShader(GLenum type)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001015{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001016 EVENT("(GLenum type = 0x%X)", type);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001017
Geoff Langbfdea662014-07-23 14:16:32 -04001018 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001019 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001020 {
Geoff Langbfdea662014-07-23 14:16:32 -04001021 switch (type)
1022 {
1023 case GL_FRAGMENT_SHADER:
1024 case GL_VERTEX_SHADER:
1025 return context->createShader(type);
Geoff Langb1196682014-07-23 13:47:29 -04001026
Geoff Langbfdea662014-07-23 14:16:32 -04001027 default:
Geoff Langb1196682014-07-23 13:47:29 -04001028 context->recordError(gl::Error(GL_INVALID_ENUM));
1029 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04001030 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001031 }
1032
1033 return 0;
1034}
1035
Kenneth Russell67ea1902014-10-06 16:44:50 -07001036void GL_APIENTRY glCullFace(GLenum mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001037{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001038 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001039
Geoff Langb1196682014-07-23 13:47:29 -04001040 gl::Context *context = gl::getNonLostContext();
1041 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001042 {
Geoff Langb1196682014-07-23 13:47:29 -04001043 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001044 {
Geoff Langb1196682014-07-23 13:47:29 -04001045 case GL_FRONT:
1046 case GL_BACK:
1047 case GL_FRONT_AND_BACK:
1048 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001049
Geoff Langb1196682014-07-23 13:47:29 -04001050 default:
1051 context->recordError(gl::Error(GL_INVALID_ENUM));
1052 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001053 }
Geoff Langb1196682014-07-23 13:47:29 -04001054
1055 context->getState().setCullMode(mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001056 }
1057}
1058
Kenneth Russell67ea1902014-10-06 16:44:50 -07001059void GL_APIENTRY glDeleteBuffers(GLsizei n, const GLuint* buffers)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001060{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001061 EVENT("(GLsizei n = %d, const GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001062
Geoff Langbfdea662014-07-23 14:16:32 -04001063 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001064 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001065 {
Geoff Langb1196682014-07-23 13:47:29 -04001066 if (n < 0)
1067 {
1068 context->recordError(gl::Error(GL_INVALID_VALUE));
1069 return;
1070 }
1071
Geoff Langbfdea662014-07-23 14:16:32 -04001072 for (int i = 0; i < n; i++)
1073 {
1074 context->deleteBuffer(buffers[i]);
1075 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001076 }
1077}
1078
Kenneth Russell67ea1902014-10-06 16:44:50 -07001079void GL_APIENTRY glDeleteFencesNV(GLsizei n, const GLuint* fences)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001080{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001081 EVENT("(GLsizei n = %d, const GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001082
Geoff Langbfdea662014-07-23 14:16:32 -04001083 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001084 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001085 {
Geoff Langb1196682014-07-23 13:47:29 -04001086 if (n < 0)
1087 {
1088 context->recordError(gl::Error(GL_INVALID_VALUE));
1089 return;
1090 }
1091
Geoff Langbfdea662014-07-23 14:16:32 -04001092 for (int i = 0; i < n; i++)
1093 {
1094 context->deleteFenceNV(fences[i]);
1095 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001096 }
1097}
1098
Kenneth Russell67ea1902014-10-06 16:44:50 -07001099void GL_APIENTRY glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001100{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001101 EVENT("(GLsizei n = %d, const GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001102
Geoff Langbfdea662014-07-23 14:16:32 -04001103 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001104 if (context)
1105 {
Geoff Langb1196682014-07-23 13:47:29 -04001106 if (n < 0)
1107 {
1108 context->recordError(gl::Error(GL_INVALID_VALUE));
1109 return;
1110 }
1111
Geoff Langbfdea662014-07-23 14:16:32 -04001112 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001113 {
Geoff Langbfdea662014-07-23 14:16:32 -04001114 if (framebuffers[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001115 {
Geoff Langbfdea662014-07-23 14:16:32 -04001116 context->deleteFramebuffer(framebuffers[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001117 }
1118 }
1119 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001120}
1121
Kenneth Russell67ea1902014-10-06 16:44:50 -07001122void GL_APIENTRY glDeleteProgram(GLuint program)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001123{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001124 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001125
Geoff Langbfdea662014-07-23 14:16:32 -04001126 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001127 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001128 {
Geoff Langb1196682014-07-23 13:47:29 -04001129 if (program == 0)
1130 {
1131 return;
1132 }
1133
Geoff Langbfdea662014-07-23 14:16:32 -04001134 if (!context->getProgram(program))
1135 {
1136 if(context->getShader(program))
1137 {
Geoff Langb1196682014-07-23 13:47:29 -04001138 context->recordError(gl::Error(GL_INVALID_OPERATION));
1139 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001140 }
1141 else
1142 {
Geoff Langb1196682014-07-23 13:47:29 -04001143 context->recordError(gl::Error(GL_INVALID_VALUE));
1144 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001145 }
1146 }
1147
1148 context->deleteProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001149 }
1150}
1151
Kenneth Russell67ea1902014-10-06 16:44:50 -07001152void GL_APIENTRY glDeleteQueriesEXT(GLsizei n, const GLuint *ids)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001153{
1154 EVENT("(GLsizei n = %d, const GLuint *ids = 0x%0.8p)", n, ids);
1155
Geoff Langbfdea662014-07-23 14:16:32 -04001156 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001157 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001158 {
Geoff Langb1196682014-07-23 13:47:29 -04001159 if (n < 0)
1160 {
1161 context->recordError(gl::Error(GL_INVALID_VALUE));
1162 return;
1163 }
1164
Geoff Langbfdea662014-07-23 14:16:32 -04001165 for (int i = 0; i < n; i++)
1166 {
1167 context->deleteQuery(ids[i]);
1168 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001169 }
1170}
1171
Kenneth Russell67ea1902014-10-06 16:44:50 -07001172void GL_APIENTRY glDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001173{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001174 EVENT("(GLsizei n = %d, const GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001175
Geoff Langbfdea662014-07-23 14:16:32 -04001176 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001177 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001178 {
Geoff Langb1196682014-07-23 13:47:29 -04001179 if (n < 0)
1180 {
1181 context->recordError(gl::Error(GL_INVALID_VALUE));
1182 return;
1183 }
1184
Geoff Langbfdea662014-07-23 14:16:32 -04001185 for (int i = 0; i < n; i++)
1186 {
1187 context->deleteRenderbuffer(renderbuffers[i]);
1188 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001189 }
1190}
1191
Kenneth Russell67ea1902014-10-06 16:44:50 -07001192void GL_APIENTRY glDeleteShader(GLuint shader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001193{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001194 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001195
Geoff Langbfdea662014-07-23 14:16:32 -04001196 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001197 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001198 {
Geoff Langb1196682014-07-23 13:47:29 -04001199 if (shader == 0)
1200 {
1201 return;
1202 }
1203
Geoff Langbfdea662014-07-23 14:16:32 -04001204 if (!context->getShader(shader))
1205 {
1206 if(context->getProgram(shader))
1207 {
Geoff Langb1196682014-07-23 13:47:29 -04001208 context->recordError(gl::Error(GL_INVALID_OPERATION));
1209 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001210 }
1211 else
1212 {
Geoff Langb1196682014-07-23 13:47:29 -04001213 context->recordError(gl::Error(GL_INVALID_VALUE));
1214 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001215 }
1216 }
1217
1218 context->deleteShader(shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001219 }
1220}
1221
Kenneth Russell67ea1902014-10-06 16:44:50 -07001222void GL_APIENTRY glDeleteTextures(GLsizei n, const GLuint* textures)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001223{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001224 EVENT("(GLsizei n = %d, const GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001225
Geoff Langbfdea662014-07-23 14:16:32 -04001226 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001227 if (context)
1228 {
Geoff Langb1196682014-07-23 13:47:29 -04001229 if (n < 0)
1230 {
1231 context->recordError(gl::Error(GL_INVALID_VALUE));
1232 return;
1233 }
1234
Geoff Langbfdea662014-07-23 14:16:32 -04001235 for (int i = 0; i < n; i++)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001236 {
Geoff Langbfdea662014-07-23 14:16:32 -04001237 if (textures[i] != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001238 {
Geoff Langbfdea662014-07-23 14:16:32 -04001239 context->deleteTexture(textures[i]);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001240 }
1241 }
1242 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001243}
1244
Kenneth Russell67ea1902014-10-06 16:44:50 -07001245void GL_APIENTRY glDepthFunc(GLenum func)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001246{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001247 EVENT("(GLenum func = 0x%X)", func);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001248
Geoff Langbfdea662014-07-23 14:16:32 -04001249 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001250 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001251 {
Geoff Langb1196682014-07-23 13:47:29 -04001252 switch (func)
1253 {
1254 case GL_NEVER:
1255 case GL_ALWAYS:
1256 case GL_LESS:
1257 case GL_LEQUAL:
1258 case GL_EQUAL:
1259 case GL_GREATER:
1260 case GL_GEQUAL:
1261 case GL_NOTEQUAL:
1262 context->getState().setDepthFunc(func);
1263 break;
1264
1265 default:
1266 context->recordError(gl::Error(GL_INVALID_ENUM));
1267 return;
1268 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001269 }
1270}
1271
Kenneth Russell67ea1902014-10-06 16:44:50 -07001272void GL_APIENTRY glDepthMask(GLboolean flag)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001273{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00001274 EVENT("(GLboolean flag = %u)", flag);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001275
Geoff Langbfdea662014-07-23 14:16:32 -04001276 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001277 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001278 {
Geoff Langbfdea662014-07-23 14:16:32 -04001279 context->getState().setDepthMask(flag != GL_FALSE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001280 }
1281}
1282
Kenneth Russell67ea1902014-10-06 16:44:50 -07001283void GL_APIENTRY glDepthRangef(GLclampf zNear, GLclampf zFar)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001284{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001285 EVENT("(GLclampf zNear = %f, GLclampf zFar = %f)", zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001286
Geoff Langbfdea662014-07-23 14:16:32 -04001287 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001288 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001289 {
Geoff Langbfdea662014-07-23 14:16:32 -04001290 context->getState().setDepthRange(zNear, zFar);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001291 }
1292}
1293
Kenneth Russell67ea1902014-10-06 16:44:50 -07001294void GL_APIENTRY glDetachShader(GLuint program, GLuint shader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001295{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001296 EVENT("(GLuint program = %d, GLuint shader = %d)", program, shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001297
Geoff Langbfdea662014-07-23 14:16:32 -04001298 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001299 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001300 {
Geoff Langbfdea662014-07-23 14:16:32 -04001301 gl::Program *programObject = context->getProgram(program);
1302 gl::Shader *shaderObject = context->getShader(shader);
1303
1304 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001305 {
Geoff Langbfdea662014-07-23 14:16:32 -04001306 gl::Shader *shaderByProgramHandle;
1307 shaderByProgramHandle = context->getShader(program);
1308 if (!shaderByProgramHandle)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001309 {
Geoff Langb1196682014-07-23 13:47:29 -04001310 context->recordError(gl::Error(GL_INVALID_VALUE));
1311 return;
daniel@transgaming.com73c2c2e2010-04-13 03:26:11 +00001312 }
Geoff Langbfdea662014-07-23 14:16:32 -04001313 else
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001314 {
Geoff Langb1196682014-07-23 13:47:29 -04001315 context->recordError(gl::Error(GL_INVALID_OPERATION));
1316 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001317 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001318 }
Geoff Langbfdea662014-07-23 14:16:32 -04001319
1320 if (!shaderObject)
1321 {
1322 gl::Program *programByShaderHandle = context->getProgram(shader);
1323 if (!programByShaderHandle)
1324 {
Geoff Langb1196682014-07-23 13:47:29 -04001325 context->recordError(gl::Error(GL_INVALID_VALUE));
1326 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001327 }
1328 else
1329 {
Geoff Langb1196682014-07-23 13:47:29 -04001330 context->recordError(gl::Error(GL_INVALID_OPERATION));
1331 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001332 }
1333 }
1334
1335 if (!programObject->detachShader(shaderObject))
1336 {
Geoff Langb1196682014-07-23 13:47:29 -04001337 context->recordError(gl::Error(GL_INVALID_OPERATION));
1338 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001339 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001340 }
1341}
1342
Kenneth Russell67ea1902014-10-06 16:44:50 -07001343void GL_APIENTRY glDisable(GLenum cap)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001344{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001345 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001346
Geoff Langbfdea662014-07-23 14:16:32 -04001347 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001348 if (context)
1349 {
1350 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001351 {
Geoff Langb1196682014-07-23 13:47:29 -04001352 context->recordError(gl::Error(GL_INVALID_ENUM));
1353 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001354 }
Geoff Langbfdea662014-07-23 14:16:32 -04001355
1356 context->getState().setEnableFeature(cap, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001357 }
1358}
1359
Kenneth Russell67ea1902014-10-06 16:44:50 -07001360void GL_APIENTRY glDisableVertexAttribArray(GLuint index)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001361{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001362 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001363
Geoff Langbfdea662014-07-23 14:16:32 -04001364 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001365 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001366 {
Geoff Langb1196682014-07-23 13:47:29 -04001367 if (index >= gl::MAX_VERTEX_ATTRIBS)
1368 {
1369 context->recordError(gl::Error(GL_INVALID_VALUE));
1370 return;
1371 }
1372
Geoff Langbfdea662014-07-23 14:16:32 -04001373 context->getState().setEnableVertexAttribArray(index, false);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001374 }
1375}
1376
Kenneth Russell67ea1902014-10-06 16:44:50 -07001377void GL_APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001378{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001379 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d)", mode, first, count);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001380
Geoff Langbfdea662014-07-23 14:16:32 -04001381 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001382 if (context)
1383 {
Jamie Madill2b976812014-08-25 15:47:49 -04001384 if (!ValidateDrawArrays(context, mode, first, count, 0))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001385 {
Geoff Langbfdea662014-07-23 14:16:32 -04001386 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001387 }
Geoff Langbfdea662014-07-23 14:16:32 -04001388
Geoff Langc77e8c32014-09-08 16:28:24 -04001389 gl::Error error = context->drawArrays(mode, first, count, 0);
1390 if (error.isError())
1391 {
1392 context->recordError(error);
1393 return;
1394 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001395 }
1396}
1397
Kenneth Russell67ea1902014-10-06 16:44:50 -07001398void GL_APIENTRY glDrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001399{
1400 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei primcount = %d)", mode, first, count, primcount);
1401
Geoff Langbfdea662014-07-23 14:16:32 -04001402 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001403 if (context)
1404 {
Geoff Lang87a93302014-09-16 13:29:43 -04001405 if (!ValidateDrawArraysInstancedANGLE(context, mode, first, count, primcount))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001406 {
Geoff Langbfdea662014-07-23 14:16:32 -04001407 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001408 }
Geoff Langbfdea662014-07-23 14:16:32 -04001409
Geoff Langc77e8c32014-09-08 16:28:24 -04001410 gl::Error error = context->drawArrays(mode, first, count, primcount);
1411 if (error.isError())
1412 {
1413 context->recordError(error);
1414 return;
1415 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001416 }
1417}
1418
Kenneth Russell67ea1902014-10-06 16:44:50 -07001419void GL_APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001420{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001421 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001422 mode, count, type, indices);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001423
Geoff Langbfdea662014-07-23 14:16:32 -04001424 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001425 if (context)
1426 {
Jamie Madill2b976812014-08-25 15:47:49 -04001427 rx::RangeUI indexRange;
1428 if (!ValidateDrawElements(context, mode, count, type, indices, 0, &indexRange))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001429 {
Geoff Langbfdea662014-07-23 14:16:32 -04001430 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001431 }
Geoff Langbfdea662014-07-23 14:16:32 -04001432
Geoff Langc77e8c32014-09-08 16:28:24 -04001433 gl::Error error = context->drawElements(mode, count, type, indices, 0, indexRange);
1434 if (error.isError())
1435 {
1436 context->recordError(error);
1437 return;
1438 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001439 }
1440}
1441
Kenneth Russell67ea1902014-10-06 16:44:50 -07001442void GL_APIENTRY glDrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001443{
1444 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei primcount = %d)",
1445 mode, count, type, indices, primcount);
1446
Geoff Langbfdea662014-07-23 14:16:32 -04001447 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001448 if (context)
1449 {
Jamie Madill2b976812014-08-25 15:47:49 -04001450 rx::RangeUI indexRange;
Geoff Lang87a93302014-09-16 13:29:43 -04001451 if (!ValidateDrawElementsInstancedANGLE(context, mode, count, type, indices, primcount, &indexRange))
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001452 {
Geoff Langbfdea662014-07-23 14:16:32 -04001453 return;
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001454 }
Geoff Langbfdea662014-07-23 14:16:32 -04001455
Geoff Langc77e8c32014-09-08 16:28:24 -04001456 gl::Error error = context->drawElements(mode, count, type, indices, primcount, indexRange);
1457 if (error.isError())
1458 {
1459 context->recordError(error);
1460 return;
1461 }
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00001462 }
1463}
1464
Kenneth Russell67ea1902014-10-06 16:44:50 -07001465void GL_APIENTRY glEnable(GLenum cap)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001466{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001467 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001468
Geoff Langbfdea662014-07-23 14:16:32 -04001469 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001470 if (context)
1471 {
1472 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001473 {
Geoff Langb1196682014-07-23 13:47:29 -04001474 context->recordError(gl::Error(GL_INVALID_ENUM));
1475 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001476 }
Geoff Langbfdea662014-07-23 14:16:32 -04001477
1478 context->getState().setEnableFeature(cap, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001479 }
1480}
1481
Kenneth Russell67ea1902014-10-06 16:44:50 -07001482void GL_APIENTRY glEnableVertexAttribArray(GLuint index)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001483{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001484 EVENT("(GLuint index = %d)", index);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001485
Geoff Langbfdea662014-07-23 14:16:32 -04001486 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001487 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001488 {
Geoff Langb1196682014-07-23 13:47:29 -04001489 if (index >= gl::MAX_VERTEX_ATTRIBS)
1490 {
1491 context->recordError(gl::Error(GL_INVALID_VALUE));
1492 return;
1493 }
1494
Geoff Langbfdea662014-07-23 14:16:32 -04001495 context->getState().setEnableVertexAttribArray(index, true);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001496 }
1497}
1498
Kenneth Russell67ea1902014-10-06 16:44:50 -07001499void GL_APIENTRY glEndQueryEXT(GLenum target)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001500{
1501 EVENT("GLenum target = 0x%X)", target);
1502
Geoff Langbfdea662014-07-23 14:16:32 -04001503 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001504 if (context)
1505 {
1506 if (!ValidateEndQuery(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001507 {
Geoff Langbfdea662014-07-23 14:16:32 -04001508 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001509 }
Geoff Langbfdea662014-07-23 14:16:32 -04001510
Geoff Lang5aad9672014-09-08 11:10:42 -04001511 gl::Error error = context->endQuery(target);
1512 if (error.isError())
1513 {
1514 context->recordError(error);
1515 return;
1516 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001517 }
1518}
1519
Kenneth Russell67ea1902014-10-06 16:44:50 -07001520void GL_APIENTRY glFinishFenceNV(GLuint fence)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001521{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001522 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001523
Geoff Langbfdea662014-07-23 14:16:32 -04001524 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001525 if (context)
1526 {
1527 gl::FenceNV *fenceObject = context->getFenceNV(fence);
1528
1529 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001530 {
Geoff Langb1196682014-07-23 13:47:29 -04001531 context->recordError(gl::Error(GL_INVALID_OPERATION));
1532 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001533 }
Geoff Langbfdea662014-07-23 14:16:32 -04001534
1535 if (fenceObject->isFence() != GL_TRUE)
1536 {
Geoff Langb1196682014-07-23 13:47:29 -04001537 context->recordError(gl::Error(GL_INVALID_OPERATION));
1538 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001539 }
1540
1541 fenceObject->finishFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001542 }
1543}
1544
Kenneth Russell67ea1902014-10-06 16:44:50 -07001545void GL_APIENTRY glFinish(void)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001546{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001547 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001548
Geoff Langbfdea662014-07-23 14:16:32 -04001549 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001550 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001551 {
Geoff Lang26298562014-10-01 10:49:03 -04001552 gl::Error error = context->sync(true);
1553 if (error.isError())
1554 {
1555 context->recordError(error);
1556 return;
1557 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001558 }
1559}
1560
Kenneth Russell67ea1902014-10-06 16:44:50 -07001561void GL_APIENTRY glFlush(void)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001562{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001563 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001564
Geoff Langbfdea662014-07-23 14:16:32 -04001565 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001566 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001567 {
Geoff Lang26298562014-10-01 10:49:03 -04001568 gl::Error error = context->sync(false);
1569 if (error.isError())
1570 {
1571 context->recordError(error);
1572 return;
1573 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001574 }
1575}
1576
Kenneth Russell67ea1902014-10-06 16:44:50 -07001577void GL_APIENTRY glFramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001578{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001579 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum renderbuffertarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001580 "GLuint renderbuffer = %d)", target, attachment, renderbuffertarget, renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001581
Geoff Langbfdea662014-07-23 14:16:32 -04001582 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001583 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001584 {
Geoff Langb1196682014-07-23 13:47:29 -04001585 if (!gl::ValidFramebufferTarget(target) || (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0))
1586 {
1587 context->recordError(gl::Error(GL_INVALID_ENUM));
1588 return;
1589 }
1590
Geoff Langbfdea662014-07-23 14:16:32 -04001591 if (!gl::ValidateFramebufferRenderbufferParameters(context, target, attachment, renderbuffertarget, renderbuffer))
1592 {
1593 return;
1594 }
1595
1596 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1597 ASSERT(framebuffer);
1598
Geoff Langab75a052014-10-15 12:56:37 -04001599 if (renderbuffer != 0)
Geoff Langbfdea662014-07-23 14:16:32 -04001600 {
Geoff Langab75a052014-10-15 12:56:37 -04001601 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
1602 framebuffer->setRenderbufferAttachment(attachment, renderbufferObject);
Geoff Langbfdea662014-07-23 14:16:32 -04001603 }
1604 else
1605 {
Geoff Langab75a052014-10-15 12:56:37 -04001606 framebuffer->setNULLAttachment(attachment);
Geoff Langbfdea662014-07-23 14:16:32 -04001607 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001608 }
1609}
1610
Kenneth Russell67ea1902014-10-06 16:44:50 -07001611void GL_APIENTRY glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001612{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001613 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum textarget = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001614 "GLuint texture = %d, GLint level = %d)", target, attachment, textarget, texture, level);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001615
Geoff Langbfdea662014-07-23 14:16:32 -04001616 gl::Context *context = gl::getNonLostContext();
1617 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001618 {
Geoff Langbfdea662014-07-23 14:16:32 -04001619 if (!ValidateFramebufferTexture2D(context, target, attachment, textarget, texture, level))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001620 {
Geoff Langbfdea662014-07-23 14:16:32 -04001621 return;
1622 }
shannon.woods%transgaming.com@gtempaccount.com89ae1132013-04-13 03:28:43 +00001623
Geoff Langbfdea662014-07-23 14:16:32 -04001624 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
Jamie Madill48faf802014-11-06 15:27:22 -05001625 ASSERT(framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001626
Geoff Langab75a052014-10-15 12:56:37 -04001627 if (texture != 0)
Geoff Langbfdea662014-07-23 14:16:32 -04001628 {
Geoff Langab75a052014-10-15 12:56:37 -04001629 gl::Texture *textureObj = context->getTexture(texture);
1630 gl::ImageIndex index(textarget, level, gl::ImageIndex::ENTIRE_LEVEL);
1631 framebuffer->setTextureAttachment(attachment, textureObj, index);
Geoff Langbfdea662014-07-23 14:16:32 -04001632 }
1633 else
1634 {
Geoff Langab75a052014-10-15 12:56:37 -04001635 framebuffer->setNULLAttachment(attachment);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001636 }
1637 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001638}
1639
Kenneth Russell67ea1902014-10-06 16:44:50 -07001640void GL_APIENTRY glFrontFace(GLenum mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001641{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001642 EVENT("(GLenum mode = 0x%X)", mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001643
Geoff Langb1196682014-07-23 13:47:29 -04001644 gl::Context *context = gl::getNonLostContext();
1645 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001646 {
Geoff Langb1196682014-07-23 13:47:29 -04001647 switch (mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001648 {
Geoff Langb1196682014-07-23 13:47:29 -04001649 case GL_CW:
1650 case GL_CCW:
1651 context->getState().setFrontFace(mode);
1652 break;
1653 default:
1654 context->recordError(gl::Error(GL_INVALID_ENUM));
1655 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001656 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001657 }
1658}
1659
Kenneth Russell67ea1902014-10-06 16:44:50 -07001660void GL_APIENTRY glGenBuffers(GLsizei n, GLuint* buffers)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001661{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001662 EVENT("(GLsizei n = %d, GLuint* buffers = 0x%0.8p)", n, buffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001663
Geoff Langbfdea662014-07-23 14:16:32 -04001664 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001665 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001666 {
Geoff Langb1196682014-07-23 13:47:29 -04001667 if (n < 0)
1668 {
1669 context->recordError(gl::Error(GL_INVALID_VALUE));
1670 return;
1671 }
1672
Geoff Langbfdea662014-07-23 14:16:32 -04001673 for (int i = 0; i < n; i++)
1674 {
1675 buffers[i] = context->createBuffer();
1676 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001677 }
1678}
1679
Kenneth Russell67ea1902014-10-06 16:44:50 -07001680void GL_APIENTRY glGenerateMipmap(GLenum target)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001681{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001682 EVENT("(GLenum target = 0x%X)", target);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001683
Geoff Langbfdea662014-07-23 14:16:32 -04001684 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001685 if (context)
1686 {
1687 if (!ValidTextureTarget(context, target))
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001688 {
Geoff Langb1196682014-07-23 13:47:29 -04001689 context->recordError(gl::Error(GL_INVALID_ENUM));
1690 return;
daniel@transgaming.com8fd99e22010-04-20 18:52:00 +00001691 }
Geoff Langbfdea662014-07-23 14:16:32 -04001692
1693 gl::Texture *texture = context->getTargetTexture(target);
1694
1695 if (texture == NULL)
1696 {
Geoff Langb1196682014-07-23 13:47:29 -04001697 context->recordError(gl::Error(GL_INVALID_OPERATION));
1698 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001699 }
1700
1701 GLenum internalFormat = texture->getBaseLevelInternalFormat();
1702 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -04001703 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
Geoff Langbfdea662014-07-23 14:16:32 -04001704
1705 // GenerateMipmap should not generate an INVALID_OPERATION for textures created with
1706 // unsized formats or that are color renderable and filterable. Since we do not track if
1707 // the texture was created with sized or unsized format (only sized formats are stored),
1708 // it is not possible to make sure the the LUMA formats can generate mipmaps (they should
1709 // be able to) because they aren't color renderable. Simply do a special case for LUMA
1710 // textures since they're the only texture format that can be created with unsized formats
1711 // that is not color renderable. New unsized formats are unlikely to be added, since ES2
1712 // was the last version to use add them.
1713 bool isLUMA = internalFormat == GL_LUMINANCE8_EXT ||
1714 internalFormat == GL_LUMINANCE8_ALPHA8_EXT ||
1715 internalFormat == GL_ALPHA8_EXT;
1716
Geoff Lang5d601382014-07-22 15:14:06 -04001717 if (formatInfo.depthBits > 0 || formatInfo.stencilBits > 0 || !formatCaps.filterable ||
1718 (!formatCaps.renderable && !isLUMA) || formatInfo.compressed)
Geoff Langbfdea662014-07-23 14:16:32 -04001719 {
Geoff Langb1196682014-07-23 13:47:29 -04001720 context->recordError(gl::Error(GL_INVALID_OPERATION));
1721 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001722 }
1723
1724 // GL_EXT_sRGB does not support mipmap generation on sRGB textures
Geoff Lang5d601382014-07-22 15:14:06 -04001725 if (context->getClientVersion() == 2 && formatInfo.colorEncoding == GL_SRGB)
Geoff Langbfdea662014-07-23 14:16:32 -04001726 {
Geoff Langb1196682014-07-23 13:47:29 -04001727 context->recordError(gl::Error(GL_INVALID_OPERATION));
1728 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001729 }
1730
1731 // Non-power of 2 ES2 check
1732 if (!context->getExtensions().textureNPOT && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
1733 {
1734 ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
Geoff Langb1196682014-07-23 13:47:29 -04001735 context->recordError(gl::Error(GL_INVALID_OPERATION));
1736 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001737 }
1738
1739 // Cube completeness check
1740 if (target == GL_TEXTURE_CUBE_MAP)
1741 {
1742 gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
1743 if (!textureCube->isCubeComplete())
1744 {
Geoff Langb1196682014-07-23 13:47:29 -04001745 context->recordError(gl::Error(GL_INVALID_OPERATION));
1746 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001747 }
1748 }
1749
Geoff Lang06ecf3d2014-09-23 16:39:50 -04001750 gl::Error error = texture->generateMipmaps();
1751 if (error.isError())
1752 {
1753 context->recordError(error);
1754 return;
1755 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001756 }
1757}
1758
Kenneth Russell67ea1902014-10-06 16:44:50 -07001759void GL_APIENTRY glGenFencesNV(GLsizei n, GLuint* fences)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001760{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001761 EVENT("(GLsizei n = %d, GLuint* fences = 0x%0.8p)", n, fences);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001762
Geoff Langbfdea662014-07-23 14:16:32 -04001763 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001764 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001765 {
Geoff Langb1196682014-07-23 13:47:29 -04001766 if (n < 0)
1767 {
1768 context->recordError(gl::Error(GL_INVALID_VALUE));
1769 return;
1770 }
1771
Geoff Langbfdea662014-07-23 14:16:32 -04001772 for (int i = 0; i < n; i++)
1773 {
1774 fences[i] = context->createFenceNV();
1775 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00001776 }
1777}
1778
Kenneth Russell67ea1902014-10-06 16:44:50 -07001779void GL_APIENTRY glGenFramebuffers(GLsizei n, GLuint* framebuffers)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001780{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001781 EVENT("(GLsizei n = %d, GLuint* framebuffers = 0x%0.8p)", n, framebuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001782
Geoff Langbfdea662014-07-23 14:16:32 -04001783 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001784 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001785 {
Geoff Langb1196682014-07-23 13:47:29 -04001786 if (n < 0)
1787 {
1788 context->recordError(gl::Error(GL_INVALID_VALUE));
1789 return;
1790 }
1791
Geoff Langbfdea662014-07-23 14:16:32 -04001792 for (int i = 0; i < n; i++)
1793 {
1794 framebuffers[i] = context->createFramebuffer();
1795 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001796 }
1797}
1798
Kenneth Russell67ea1902014-10-06 16:44:50 -07001799void GL_APIENTRY glGenQueriesEXT(GLsizei n, GLuint* ids)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001800{
1801 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
1802
Geoff Langbfdea662014-07-23 14:16:32 -04001803 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001804 if (context)
1805 {
1806 if (n < 0)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001807 {
Geoff Langb1196682014-07-23 13:47:29 -04001808 context->recordError(gl::Error(GL_INVALID_VALUE));
1809 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001810 }
Geoff Langbfdea662014-07-23 14:16:32 -04001811
1812 for (GLsizei i = 0; i < n; i++)
1813 {
1814 ids[i] = context->createQuery();
1815 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00001816 }
1817}
1818
Kenneth Russell67ea1902014-10-06 16:44:50 -07001819void GL_APIENTRY glGenRenderbuffers(GLsizei n, GLuint* renderbuffers)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001820{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001821 EVENT("(GLsizei n = %d, GLuint* renderbuffers = 0x%0.8p)", n, renderbuffers);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001822
Geoff Langbfdea662014-07-23 14:16:32 -04001823 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001824 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001825 {
Geoff Langb1196682014-07-23 13:47:29 -04001826 if (n < 0)
1827 {
1828 context->recordError(gl::Error(GL_INVALID_VALUE));
1829 return;
1830 }
1831
Geoff Langbfdea662014-07-23 14:16:32 -04001832 for (int i = 0; i < n; i++)
1833 {
1834 renderbuffers[i] = context->createRenderbuffer();
1835 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001836 }
1837}
1838
Kenneth Russell67ea1902014-10-06 16:44:50 -07001839void GL_APIENTRY glGenTextures(GLsizei n, GLuint* textures)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001840{
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001841 EVENT("(GLsizei n = %d, GLuint* textures = 0x%0.8p)", n, textures);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001842
Geoff Langbfdea662014-07-23 14:16:32 -04001843 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001844 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001845 {
Geoff Langb1196682014-07-23 13:47:29 -04001846 if (n < 0)
1847 {
1848 context->recordError(gl::Error(GL_INVALID_VALUE));
1849 return;
1850 }
1851
Geoff Langbfdea662014-07-23 14:16:32 -04001852 for (int i = 0; i < n; i++)
1853 {
1854 textures[i] = context->createTexture();
1855 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001856 }
1857}
1858
Kenneth Russell67ea1902014-10-06 16:44:50 -07001859void GL_APIENTRY glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001860{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001861 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, GLsizei *length = 0x%0.8p, "
daniel@transgaming.com85423182010-04-22 13:35:27 +00001862 "GLint *size = 0x%0.8p, GLenum *type = %0.8p, GLchar *name = %0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001863 program, index, bufsize, length, size, type, name);
1864
Geoff Langbfdea662014-07-23 14:16:32 -04001865 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001866 if (context)
1867 {
Geoff Langb1196682014-07-23 13:47:29 -04001868 if (bufsize < 0)
1869 {
1870 context->recordError(gl::Error(GL_INVALID_VALUE));
1871 return;
1872 }
1873
Geoff Langbfdea662014-07-23 14:16:32 -04001874 gl::Program *programObject = context->getProgram(program);
1875
1876 if (!programObject)
1877 {
1878 if (context->getShader(program))
1879 {
Geoff Langb1196682014-07-23 13:47:29 -04001880 context->recordError(gl::Error(GL_INVALID_OPERATION));
1881 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001882 }
1883 else
1884 {
Geoff Langb1196682014-07-23 13:47:29 -04001885 context->recordError(gl::Error(GL_INVALID_VALUE));
1886 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001887 }
1888 }
1889
1890 if (index >= (GLuint)programObject->getActiveAttributeCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001891 {
Geoff Langb1196682014-07-23 13:47:29 -04001892 context->recordError(gl::Error(GL_INVALID_VALUE));
1893 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001894 }
1895
Geoff Langbfdea662014-07-23 14:16:32 -04001896 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001897 }
1898}
1899
Kenneth Russell67ea1902014-10-06 16:44:50 -07001900void GL_APIENTRY glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001901{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001902 EVENT("(GLuint program = %d, GLuint index = %d, GLsizei bufsize = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00001903 "GLsizei* length = 0x%0.8p, GLint* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001904 program, index, bufsize, length, size, type, name);
1905
Geoff Langbfdea662014-07-23 14:16:32 -04001906
1907 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001908 if (context)
1909 {
Geoff Langb1196682014-07-23 13:47:29 -04001910 if (bufsize < 0)
1911 {
1912 context->recordError(gl::Error(GL_INVALID_VALUE));
1913 return;
1914 }
1915
Geoff Langbfdea662014-07-23 14:16:32 -04001916 gl::Program *programObject = context->getProgram(program);
1917
1918 if (!programObject)
1919 {
1920 if (context->getShader(program))
1921 {
Geoff Langb1196682014-07-23 13:47:29 -04001922 context->recordError(gl::Error(GL_INVALID_OPERATION));
1923 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001924 }
1925 else
1926 {
Geoff Langb1196682014-07-23 13:47:29 -04001927 context->recordError(gl::Error(GL_INVALID_VALUE));
1928 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001929 }
1930 }
1931
1932 if (index >= (GLuint)programObject->getActiveUniformCount())
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001933 {
Geoff Langb1196682014-07-23 13:47:29 -04001934 context->recordError(gl::Error(GL_INVALID_VALUE));
1935 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001936 }
1937
Geoff Langbfdea662014-07-23 14:16:32 -04001938 programObject->getActiveUniform(index, bufsize, length, size, type, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001939 }
1940}
1941
Kenneth Russell67ea1902014-10-06 16:44:50 -07001942void GL_APIENTRY glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001943{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001944 EVENT("(GLuint program = %d, GLsizei maxcount = %d, GLsizei* count = 0x%0.8p, GLuint* shaders = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00001945 program, maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001946
Geoff Langbfdea662014-07-23 14:16:32 -04001947 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001948 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001949 {
Geoff Langb1196682014-07-23 13:47:29 -04001950 if (maxcount < 0)
1951 {
1952 context->recordError(gl::Error(GL_INVALID_VALUE));
1953 return;
1954 }
1955
Geoff Langbfdea662014-07-23 14:16:32 -04001956 gl::Program *programObject = context->getProgram(program);
1957
1958 if (!programObject)
1959 {
1960 if (context->getShader(program))
1961 {
Geoff Langb1196682014-07-23 13:47:29 -04001962 context->recordError(gl::Error(GL_INVALID_OPERATION));
1963 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001964 }
1965 else
1966 {
Geoff Langb1196682014-07-23 13:47:29 -04001967 context->recordError(gl::Error(GL_INVALID_VALUE));
1968 return;
Geoff Langbfdea662014-07-23 14:16:32 -04001969 }
1970 }
1971
1972 return programObject->getAttachedShaders(maxcount, count, shaders);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001973 }
1974}
1975
Kenneth Russell67ea1902014-10-06 16:44:50 -07001976GLint GL_APIENTRY glGetAttribLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001977{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00001978 EVENT("(GLuint program = %d, const GLchar* name = %s)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001979
Geoff Langbfdea662014-07-23 14:16:32 -04001980 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04001981 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001982 {
Geoff Langbfdea662014-07-23 14:16:32 -04001983 gl::Program *programObject = context->getProgram(program);
1984
1985 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001986 {
Geoff Langbfdea662014-07-23 14:16:32 -04001987 if (context->getShader(program))
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001988 {
Geoff Langb1196682014-07-23 13:47:29 -04001989 context->recordError(gl::Error(GL_INVALID_OPERATION));
1990 return -1;
daniel@transgaming.comcf4aa872010-04-13 03:26:27 +00001991 }
Geoff Langbfdea662014-07-23 14:16:32 -04001992 else
1993 {
Geoff Langb1196682014-07-23 13:47:29 -04001994 context->recordError(gl::Error(GL_INVALID_VALUE));
1995 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04001996 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001997 }
Geoff Langbfdea662014-07-23 14:16:32 -04001998
1999 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
2000 if (!programObject->isLinked() || !programBinary)
2001 {
Geoff Langb1196682014-07-23 13:47:29 -04002002 context->recordError(gl::Error(GL_INVALID_OPERATION));
2003 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04002004 }
2005
2006 return programBinary->getAttributeLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002007 }
2008
2009 return -1;
2010}
2011
Kenneth Russell67ea1902014-10-06 16:44:50 -07002012void GL_APIENTRY glGetBooleanv(GLenum pname, GLboolean* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002013{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002014 EVENT("(GLenum pname = 0x%X, GLboolean* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002015
Geoff Langbfdea662014-07-23 14:16:32 -04002016 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002017 if (context)
2018 {
2019 GLenum nativeType;
2020 unsigned int numParams = 0;
2021 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002022 {
Geoff Langbfdea662014-07-23 14:16:32 -04002023 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002024 }
Geoff Langbfdea662014-07-23 14:16:32 -04002025
2026 if (nativeType == GL_BOOL)
2027 {
2028 context->getBooleanv(pname, params);
2029 }
2030 else
2031 {
2032 CastStateValues(context, nativeType, pname, numParams, params);
2033 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002034 }
2035}
2036
Kenneth Russell67ea1902014-10-06 16:44:50 -07002037void GL_APIENTRY glGetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002038{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002039 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002040
Geoff Langbfdea662014-07-23 14:16:32 -04002041 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002042 if (context)
2043 {
2044 if (!gl::ValidBufferTarget(context, target))
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00002045 {
Geoff Langb1196682014-07-23 13:47:29 -04002046 context->recordError(gl::Error(GL_INVALID_ENUM));
2047 return;
daniel@transgaming.comaa0ccbd2010-04-15 20:45:05 +00002048 }
Geoff Langbfdea662014-07-23 14:16:32 -04002049
2050 if (!gl::ValidBufferParameter(context, pname))
2051 {
Geoff Langb1196682014-07-23 13:47:29 -04002052 context->recordError(gl::Error(GL_INVALID_ENUM));
2053 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002054 }
2055
2056 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
2057
2058 if (!buffer)
2059 {
2060 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04002061 context->recordError(gl::Error(GL_INVALID_OPERATION));
2062 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002063 }
2064
2065 switch (pname)
2066 {
2067 case GL_BUFFER_USAGE:
2068 *params = static_cast<GLint>(buffer->getUsage());
2069 break;
2070 case GL_BUFFER_SIZE:
2071 *params = gl::clampCast<GLint>(buffer->getSize());
2072 break;
2073 case GL_BUFFER_ACCESS_FLAGS:
2074 *params = buffer->getAccessFlags();
2075 break;
2076 case GL_BUFFER_MAPPED:
2077 *params = static_cast<GLint>(buffer->isMapped());
2078 break;
2079 case GL_BUFFER_MAP_OFFSET:
2080 *params = gl::clampCast<GLint>(buffer->getMapOffset());
2081 break;
2082 case GL_BUFFER_MAP_LENGTH:
2083 *params = gl::clampCast<GLint>(buffer->getMapLength());
2084 break;
2085 default: UNREACHABLE(); break;
2086 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002087 }
2088}
2089
Kenneth Russell67ea1902014-10-06 16:44:50 -07002090GLenum GL_APIENTRY glGetError(void)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002091{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002092 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002093
2094 gl::Context *context = gl::getContext();
2095
2096 if (context)
2097 {
daniel@transgaming.com82b28912011-12-12 21:01:35 +00002098 return context->getError();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002099 }
2100
2101 return GL_NO_ERROR;
2102}
2103
Kenneth Russell67ea1902014-10-06 16:44:50 -07002104void GL_APIENTRY glGetFenceivNV(GLuint fence, GLenum pname, GLint *params)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002105{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002106 EVENT("(GLuint fence = %d, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", fence, pname, params);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002107
Geoff Langbfdea662014-07-23 14:16:32 -04002108 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002109 if (context)
2110 {
2111 gl::FenceNV *fenceObject = context->getFenceNV(fence);
2112
2113 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002114 {
Geoff Langb1196682014-07-23 13:47:29 -04002115 context->recordError(gl::Error(GL_INVALID_OPERATION));
2116 return;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002117 }
Geoff Langbfdea662014-07-23 14:16:32 -04002118
2119 if (fenceObject->isFence() != GL_TRUE)
2120 {
Geoff Langb1196682014-07-23 13:47:29 -04002121 context->recordError(gl::Error(GL_INVALID_OPERATION));
2122 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002123 }
2124
2125 switch (pname)
2126 {
2127 case GL_FENCE_STATUS_NV:
Kenneth Russellcaa549c2014-10-10 17:52:59 -07002128 {
2129 // GL_NV_fence spec:
2130 // Once the status of a fence has been finished (via FinishFenceNV) or tested and the returned status is TRUE (via either TestFenceNV
2131 // or GetFenceivNV querying the FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
2132 GLboolean status = GL_TRUE;
2133 if (fenceObject->getStatus() != GL_TRUE)
2134 {
2135 gl::Error error = fenceObject->testFence(&status);
2136 if (error.isError())
2137 {
2138 context->recordError(error);
2139 return;
2140 }
2141 }
2142 *params = status;
2143 break;
2144 }
2145
Geoff Langbfdea662014-07-23 14:16:32 -04002146 case GL_FENCE_CONDITION_NV:
Kenneth Russellcaa549c2014-10-10 17:52:59 -07002147 {
2148 *params = fenceObject->getCondition();
2149 break;
2150 }
Geoff Langbfdea662014-07-23 14:16:32 -04002151
Geoff Langb1196682014-07-23 13:47:29 -04002152 default:
Kenneth Russellcaa549c2014-10-10 17:52:59 -07002153 {
2154 context->recordError(gl::Error(GL_INVALID_ENUM));
2155 return;
2156 }
Geoff Lang882033e2014-09-30 11:26:07 -04002157 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00002158 }
2159}
2160
Kenneth Russell67ea1902014-10-06 16:44:50 -07002161void GL_APIENTRY glGetFloatv(GLenum pname, GLfloat* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002162{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002163 EVENT("(GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002164
Geoff Langbfdea662014-07-23 14:16:32 -04002165 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002166 if (context)
2167 {
2168 GLenum nativeType;
2169 unsigned int numParams = 0;
2170 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002171 {
Geoff Langbfdea662014-07-23 14:16:32 -04002172 return;
daniel@transgaming.com32e58cd2010-03-24 09:44:10 +00002173 }
Geoff Langbfdea662014-07-23 14:16:32 -04002174
2175 if (nativeType == GL_FLOAT)
2176 {
2177 context->getFloatv(pname, params);
2178 }
2179 else
2180 {
2181 CastStateValues(context, nativeType, pname, numParams, params);
2182 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002183 }
2184}
2185
Kenneth Russell67ea1902014-10-06 16:44:50 -07002186void GL_APIENTRY glGetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002187{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002188 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002189 target, attachment, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002190
Geoff Langbfdea662014-07-23 14:16:32 -04002191 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002192 if (context)
2193 {
2194 if (!gl::ValidFramebufferTarget(target))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002195 {
Geoff Langb1196682014-07-23 13:47:29 -04002196 context->recordError(gl::Error(GL_INVALID_ENUM));
2197 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002198 }
2199
2200 int clientVersion = context->getClientVersion();
2201
2202 switch (pname)
2203 {
2204 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2205 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2206 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
2207 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
2208 break;
Geoff Langb1196682014-07-23 13:47:29 -04002209
Geoff Langbfdea662014-07-23 14:16:32 -04002210 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2211 if (clientVersion < 3 && !context->getExtensions().sRGB)
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002212 {
Geoff Langb1196682014-07-23 13:47:29 -04002213 context->recordError(gl::Error(GL_INVALID_ENUM));
2214 return;
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002215 }
Geoff Langbfdea662014-07-23 14:16:32 -04002216 break;
Geoff Langb1196682014-07-23 13:47:29 -04002217
Geoff Langbfdea662014-07-23 14:16:32 -04002218 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2219 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2220 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2221 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2222 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2223 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2224 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
2225 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
2226 if (clientVersion < 3)
2227 {
Geoff Langb1196682014-07-23 13:47:29 -04002228 context->recordError(gl::Error(GL_INVALID_ENUM));
2229 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002230 }
2231 break;
Geoff Langb1196682014-07-23 13:47:29 -04002232
Geoff Langbfdea662014-07-23 14:16:32 -04002233 default:
Geoff Langb1196682014-07-23 13:47:29 -04002234 context->recordError(gl::Error(GL_INVALID_ENUM));
2235 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002236 }
daniel@transgaming.comc46c9c02010-04-23 18:34:55 +00002237
Geoff Langbfdea662014-07-23 14:16:32 -04002238 // Determine if the attachment is a valid enum
2239 switch (attachment)
2240 {
2241 case GL_BACK:
2242 case GL_FRONT:
2243 case GL_DEPTH:
2244 case GL_STENCIL:
2245 case GL_DEPTH_STENCIL_ATTACHMENT:
2246 if (clientVersion < 3)
2247 {
Geoff Langb1196682014-07-23 13:47:29 -04002248 context->recordError(gl::Error(GL_INVALID_ENUM));
2249 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002250 }
2251 break;
2252
2253 case GL_DEPTH_ATTACHMENT:
2254 case GL_STENCIL_ATTACHMENT:
2255 break;
2256
2257 default:
2258 if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
2259 (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
2260 {
Geoff Langb1196682014-07-23 13:47:29 -04002261 context->recordError(gl::Error(GL_INVALID_ENUM));
2262 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002263 }
2264 break;
2265 }
2266
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002267 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
Jamie Madill48faf802014-11-06 15:27:22 -05002268 ASSERT(framebuffer);
Geoff Langbfdea662014-07-23 14:16:32 -04002269
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002270 if (framebuffer->id() == 0)
Geoff Langbfdea662014-07-23 14:16:32 -04002271 {
2272 if (clientVersion < 3)
2273 {
Geoff Langb1196682014-07-23 13:47:29 -04002274 context->recordError(gl::Error(GL_INVALID_OPERATION));
2275 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002276 }
2277
2278 switch (attachment)
2279 {
2280 case GL_BACK:
2281 case GL_DEPTH:
2282 case GL_STENCIL:
2283 break;
Geoff Langb1196682014-07-23 13:47:29 -04002284
Geoff Langbfdea662014-07-23 14:16:32 -04002285 default:
Geoff Langb1196682014-07-23 13:47:29 -04002286 context->recordError(gl::Error(GL_INVALID_OPERATION));
2287 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002288 }
2289 }
2290 else
2291 {
2292 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
2293 {
2294 // Valid attachment query
2295 }
2296 else
2297 {
2298 switch (attachment)
2299 {
2300 case GL_DEPTH_ATTACHMENT:
2301 case GL_STENCIL_ATTACHMENT:
2302 break;
Geoff Langb1196682014-07-23 13:47:29 -04002303
Geoff Langbfdea662014-07-23 14:16:32 -04002304 case GL_DEPTH_STENCIL_ATTACHMENT:
2305 if (framebuffer->hasValidDepthStencil())
2306 {
Geoff Langb1196682014-07-23 13:47:29 -04002307 context->recordError(gl::Error(GL_INVALID_OPERATION));
2308 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002309 }
2310 break;
Geoff Langb1196682014-07-23 13:47:29 -04002311
Geoff Langbfdea662014-07-23 14:16:32 -04002312 default:
Geoff Langb1196682014-07-23 13:47:29 -04002313 context->recordError(gl::Error(GL_INVALID_OPERATION));
2314 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002315 }
2316 }
2317 }
2318
Geoff Langbfdea662014-07-23 14:16:32 -04002319 const gl::FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment);
Geoff Langbfdea662014-07-23 14:16:32 -04002320 if (attachmentObject)
2321 {
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002322 ASSERT(attachmentObject->type() == GL_RENDERBUFFER ||
2323 attachmentObject->type() == GL_TEXTURE ||
2324 attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT);
Jamie Madill1e3fa742014-06-16 10:34:00 -04002325
Geoff Lang646559f2013-08-15 11:08:15 -04002326 switch (pname)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002327 {
Geoff Lang646559f2013-08-15 11:08:15 -04002328 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002329 *params = attachmentObject->type();
Geoff Langbfdea662014-07-23 14:16:32 -04002330 break;
2331
Geoff Lang646559f2013-08-15 11:08:15 -04002332 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002333 if (attachmentObject->type() != GL_RENDERBUFFER && attachmentObject->type() != GL_TEXTURE)
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002334 {
Geoff Langb1196682014-07-23 13:47:29 -04002335 context->recordError(gl::Error(GL_INVALID_ENUM));
2336 return;
daniel@transgaming.coma27ff1e2010-08-24 19:20:11 +00002337 }
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002338 *params = attachmentObject->id();
Geoff Langbfdea662014-07-23 14:16:32 -04002339 break;
2340
2341 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002342 if (attachmentObject->type() != GL_TEXTURE)
Geoff Langbfdea662014-07-23 14:16:32 -04002343 {
Geoff Langb1196682014-07-23 13:47:29 -04002344 context->recordError(gl::Error(GL_INVALID_ENUM));
2345 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002346 }
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002347 *params = attachmentObject->mipLevel();
Geoff Langbfdea662014-07-23 14:16:32 -04002348 break;
2349
2350 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002351 if (attachmentObject->type() != GL_TEXTURE)
Geoff Langbfdea662014-07-23 14:16:32 -04002352 {
Geoff Langb1196682014-07-23 13:47:29 -04002353 context->recordError(gl::Error(GL_INVALID_ENUM));
2354 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002355 }
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002356 *params = attachmentObject->cubeMapFace();
Geoff Langbfdea662014-07-23 14:16:32 -04002357 break;
2358
2359 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
2360 *params = attachmentObject->getRedSize();
2361 break;
2362
2363 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
2364 *params = attachmentObject->getGreenSize();
2365 break;
2366
2367 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
2368 *params = attachmentObject->getBlueSize();
2369 break;
2370
2371 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
2372 *params = attachmentObject->getAlphaSize();
2373 break;
2374
2375 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
2376 *params = attachmentObject->getDepthSize();
2377 break;
2378
2379 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
2380 *params = attachmentObject->getStencilSize();
2381 break;
2382
2383 case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE:
Jamie Madillee85d1b2014-09-17 10:35:23 -04002384 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT)
Geoff Langbfdea662014-07-23 14:16:32 -04002385 {
Geoff Langb1196682014-07-23 13:47:29 -04002386 context->recordError(gl::Error(GL_INVALID_OPERATION));
2387 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002388 }
2389 *params = attachmentObject->getComponentType();
2390 break;
2391
2392 case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:
2393 *params = attachmentObject->getColorEncoding();
2394 break;
2395
2396 case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER:
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002397 if (attachmentObject->type() != GL_TEXTURE)
Geoff Langbfdea662014-07-23 14:16:32 -04002398 {
Geoff Langb1196682014-07-23 13:47:29 -04002399 context->recordError(gl::Error(GL_INVALID_ENUM));
2400 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002401 }
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002402 *params = attachmentObject->layer();
Geoff Langbfdea662014-07-23 14:16:32 -04002403 break;
2404
2405 default:
2406 UNREACHABLE();
2407 break;
2408 }
2409 }
Geoff Lang6a1e6b92014-11-06 10:42:45 -05002410 else
2411 {
2412 // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
2413 // is NONE, then querying any other pname will generate INVALID_ENUM.
2414
2415 // ES 3.0.2 spec pg 235 states that if the attachment type is none,
2416 // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an
2417 // INVALID_OPERATION for all other pnames
2418
2419 switch (pname)
2420 {
2421 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
2422 *params = GL_NONE;
2423 break;
2424
2425 case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
2426 if (clientVersion < 3)
2427 {
2428 context->recordError(gl::Error(GL_INVALID_ENUM));
2429 return;
2430 }
2431 *params = 0;
2432 break;
2433
2434 default:
2435 if (clientVersion < 3)
2436 {
2437 context->recordError(gl::Error(GL_INVALID_ENUM));
2438 return;
2439 }
2440 else
2441 {
2442 context->recordError(gl::Error(GL_INVALID_OPERATION));
2443 return;
2444 }
2445 }
2446 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002447 }
2448}
2449
Kenneth Russell67ea1902014-10-06 16:44:50 -07002450GLenum GL_APIENTRY glGetGraphicsResetStatusEXT(void)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002451{
2452 EVENT("()");
2453
Geoff Langbfdea662014-07-23 14:16:32 -04002454 gl::Context *context = gl::getContext();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002455
Geoff Langbfdea662014-07-23 14:16:32 -04002456 if (context)
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002457 {
Geoff Langbfdea662014-07-23 14:16:32 -04002458 return context->getResetStatus();
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002459 }
Geoff Langbfdea662014-07-23 14:16:32 -04002460
2461 return GL_NO_ERROR;
daniel@transgaming.com17f548c2011-11-09 17:47:02 +00002462}
2463
Kenneth Russell67ea1902014-10-06 16:44:50 -07002464void GL_APIENTRY glGetIntegerv(GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002465{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002466 EVENT("(GLenum pname = 0x%X, GLint* params = 0x%0.8p)", pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002467
Geoff Langbfdea662014-07-23 14:16:32 -04002468 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002469 if (context)
2470 {
2471 GLenum nativeType;
2472 unsigned int numParams = 0;
2473
2474 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002475 {
Geoff Langbfdea662014-07-23 14:16:32 -04002476 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002477 }
Geoff Langbfdea662014-07-23 14:16:32 -04002478
2479 if (nativeType == GL_INT)
2480 {
2481 context->getIntegerv(pname, params);
2482 }
2483 else
2484 {
2485 CastStateValues(context, nativeType, pname, numParams, params);
2486 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002487 }
2488}
2489
Kenneth Russell67ea1902014-10-06 16:44:50 -07002490void GL_APIENTRY glGetProgramiv(GLuint program, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002491{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002492 EVENT("(GLuint program = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", program, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002493
Geoff Langbfdea662014-07-23 14:16:32 -04002494 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002495 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002496 {
Geoff Langbfdea662014-07-23 14:16:32 -04002497 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002498
Geoff Langbfdea662014-07-23 14:16:32 -04002499 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002500 {
Geoff Langb1196682014-07-23 13:47:29 -04002501 context->recordError(gl::Error(GL_INVALID_VALUE));
2502 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002503 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002504
Geoff Langbfdea662014-07-23 14:16:32 -04002505 if (context->getClientVersion() < 3)
2506 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002507 switch (pname)
2508 {
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002509 case GL_ACTIVE_UNIFORM_BLOCKS:
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +00002510 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002511 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002512 case GL_TRANSFORM_FEEDBACK_VARYINGS:
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002513 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
Geoff Langb1196682014-07-23 13:47:29 -04002514 context->recordError(gl::Error(GL_INVALID_ENUM));
2515 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002516 }
2517 }
Geoff Langbfdea662014-07-23 14:16:32 -04002518
2519 switch (pname)
2520 {
2521 case GL_DELETE_STATUS:
2522 *params = programObject->isFlaggedForDeletion();
2523 return;
2524 case GL_LINK_STATUS:
2525 *params = programObject->isLinked();
2526 return;
2527 case GL_VALIDATE_STATUS:
2528 *params = programObject->isValidated();
2529 return;
2530 case GL_INFO_LOG_LENGTH:
2531 *params = programObject->getInfoLogLength();
2532 return;
2533 case GL_ATTACHED_SHADERS:
2534 *params = programObject->getAttachedShadersCount();
2535 return;
2536 case GL_ACTIVE_ATTRIBUTES:
2537 *params = programObject->getActiveAttributeCount();
2538 return;
2539 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
2540 *params = programObject->getActiveAttributeMaxLength();
2541 return;
2542 case GL_ACTIVE_UNIFORMS:
2543 *params = programObject->getActiveUniformCount();
2544 return;
2545 case GL_ACTIVE_UNIFORM_MAX_LENGTH:
2546 *params = programObject->getActiveUniformMaxLength();
2547 return;
2548 case GL_PROGRAM_BINARY_LENGTH_OES:
2549 *params = programObject->getProgramBinaryLength();
2550 return;
2551 case GL_ACTIVE_UNIFORM_BLOCKS:
2552 *params = programObject->getActiveUniformBlockCount();
2553 return;
2554 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH:
2555 *params = programObject->getActiveUniformBlockMaxLength();
2556 break;
2557 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE:
2558 *params = programObject->getTransformFeedbackBufferMode();
2559 break;
2560 case GL_TRANSFORM_FEEDBACK_VARYINGS:
2561 *params = programObject->getTransformFeedbackVaryingCount();
2562 break;
2563 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH:
2564 *params = programObject->getTransformFeedbackVaryingMaxLength();
2565 break;
Geoff Langb1196682014-07-23 13:47:29 -04002566
Geoff Langbfdea662014-07-23 14:16:32 -04002567 default:
Geoff Langb1196682014-07-23 13:47:29 -04002568 context->recordError(gl::Error(GL_INVALID_ENUM));
2569 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002570 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002571 }
2572}
2573
Kenneth Russell67ea1902014-10-06 16:44:50 -07002574void GL_APIENTRY glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002575{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002576 EVENT("(GLuint program = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* infolog = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002577 program, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002578
Geoff Langbfdea662014-07-23 14:16:32 -04002579 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002580 if (context)
2581 {
Geoff Langb1196682014-07-23 13:47:29 -04002582 if (bufsize < 0)
2583 {
2584 context->recordError(gl::Error(GL_INVALID_VALUE));
2585 return;
2586 }
2587
Geoff Langbfdea662014-07-23 14:16:32 -04002588 gl::Program *programObject = context->getProgram(program);
2589
2590 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002591 {
Geoff Langb1196682014-07-23 13:47:29 -04002592 context->recordError(gl::Error(GL_INVALID_VALUE));
2593 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002594 }
2595
Geoff Langbfdea662014-07-23 14:16:32 -04002596 programObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002597 }
2598}
2599
Kenneth Russell67ea1902014-10-06 16:44:50 -07002600void GL_APIENTRY glGetQueryivEXT(GLenum target, GLenum pname, GLint *params)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002601{
2602 EVENT("GLenum target = 0x%X, GLenum pname = 0x%X, GLint *params = 0x%0.8p)", target, pname, params);
2603
Geoff Langbfdea662014-07-23 14:16:32 -04002604 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002605 if (context)
2606 {
2607 if (!ValidQueryType(context, target))
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002608 {
Geoff Langb1196682014-07-23 13:47:29 -04002609 context->recordError(gl::Error(GL_INVALID_ENUM));
2610 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002611 }
Geoff Langbfdea662014-07-23 14:16:32 -04002612
2613 switch (pname)
2614 {
2615 case GL_CURRENT_QUERY_EXT:
2616 params[0] = context->getState().getActiveQueryId(target);
2617 break;
2618
2619 default:
Geoff Langb1196682014-07-23 13:47:29 -04002620 context->recordError(gl::Error(GL_INVALID_ENUM));
2621 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002622 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002623 }
2624}
2625
Kenneth Russell67ea1902014-10-06 16:44:50 -07002626void GL_APIENTRY glGetQueryObjectuivEXT(GLuint id, GLenum pname, GLuint *params)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002627{
2628 EVENT("(GLuint id = %d, GLenum pname = 0x%X, GLuint *params = 0x%0.8p)", id, pname, params);
2629
Geoff Langbfdea662014-07-23 14:16:32 -04002630 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002631 if (context)
2632 {
2633 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
2634
2635 if (!queryObject)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002636 {
Geoff Langb1196682014-07-23 13:47:29 -04002637 context->recordError(gl::Error(GL_INVALID_OPERATION));
2638 return;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002639 }
Geoff Langbfdea662014-07-23 14:16:32 -04002640
2641 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
2642 {
Geoff Langb1196682014-07-23 13:47:29 -04002643 context->recordError(gl::Error(GL_INVALID_OPERATION));
2644 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002645 }
2646
2647 switch(pname)
2648 {
2649 case GL_QUERY_RESULT_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002650 {
2651 gl::Error error = queryObject->getResult(params);
2652 if (error.isError())
2653 {
2654 context->recordError(error);
2655 return;
2656 }
2657 }
Geoff Langbfdea662014-07-23 14:16:32 -04002658 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002659
Geoff Langbfdea662014-07-23 14:16:32 -04002660 case GL_QUERY_RESULT_AVAILABLE_EXT:
Geoff Lang5aad9672014-09-08 11:10:42 -04002661 {
2662 gl::Error error = queryObject->isResultAvailable(params);
2663 if (error.isError())
2664 {
2665 context->recordError(error);
2666 return;
2667 }
2668 }
Geoff Langbfdea662014-07-23 14:16:32 -04002669 break;
Geoff Lang5aad9672014-09-08 11:10:42 -04002670
Geoff Langbfdea662014-07-23 14:16:32 -04002671 default:
Geoff Langb1196682014-07-23 13:47:29 -04002672 context->recordError(gl::Error(GL_INVALID_ENUM));
2673 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002674 }
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00002675 }
2676}
2677
Kenneth Russell67ea1902014-10-06 16:44:50 -07002678void GL_APIENTRY glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002679{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002680 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002681
Geoff Langbfdea662014-07-23 14:16:32 -04002682 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002683 if (context)
2684 {
2685 if (target != GL_RENDERBUFFER)
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002686 {
Geoff Langb1196682014-07-23 13:47:29 -04002687 context->recordError(gl::Error(GL_INVALID_ENUM));
2688 return;
daniel@transgaming.com4901fca2010-04-20 18:52:41 +00002689 }
Geoff Langbfdea662014-07-23 14:16:32 -04002690
2691 if (context->getState().getRenderbufferId() == 0)
2692 {
Geoff Langb1196682014-07-23 13:47:29 -04002693 context->recordError(gl::Error(GL_INVALID_OPERATION));
2694 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002695 }
2696
2697 gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getState().getRenderbufferId());
2698
2699 switch (pname)
2700 {
2701 case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
2702 case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
2703 case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
2704 case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
2705 case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
2706 case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
2707 case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
2708 case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
2709 case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
Geoff Langb1196682014-07-23 13:47:29 -04002710
Geoff Langbfdea662014-07-23 14:16:32 -04002711 case GL_RENDERBUFFER_SAMPLES_ANGLE:
2712 if (!context->getExtensions().framebufferMultisample)
2713 {
Geoff Langb1196682014-07-23 13:47:29 -04002714 context->recordError(gl::Error(GL_INVALID_ENUM));
2715 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002716 }
2717 *params = renderbuffer->getSamples();
2718 break;
Geoff Langb1196682014-07-23 13:47:29 -04002719
Geoff Langbfdea662014-07-23 14:16:32 -04002720 default:
Geoff Langb1196682014-07-23 13:47:29 -04002721 context->recordError(gl::Error(GL_INVALID_ENUM));
2722 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002723 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002724 }
2725}
2726
Kenneth Russell67ea1902014-10-06 16:44:50 -07002727void GL_APIENTRY glGetShaderiv(GLuint shader, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002728{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002729 EVENT("(GLuint shader = %d, GLenum pname = %d, GLint* params = 0x%0.8p)", shader, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002730
Geoff Langbfdea662014-07-23 14:16:32 -04002731 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002732 if (context)
2733 {
2734 gl::Shader *shaderObject = context->getShader(shader);
2735
2736 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002737 {
Geoff Langb1196682014-07-23 13:47:29 -04002738 context->recordError(gl::Error(GL_INVALID_VALUE));
2739 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002740 }
Geoff Langbfdea662014-07-23 14:16:32 -04002741
2742 switch (pname)
2743 {
2744 case GL_SHADER_TYPE:
2745 *params = shaderObject->getType();
2746 return;
2747 case GL_DELETE_STATUS:
2748 *params = shaderObject->isFlaggedForDeletion();
2749 return;
2750 case GL_COMPILE_STATUS:
2751 *params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
2752 return;
2753 case GL_INFO_LOG_LENGTH:
2754 *params = shaderObject->getInfoLogLength();
2755 return;
2756 case GL_SHADER_SOURCE_LENGTH:
2757 *params = shaderObject->getSourceLength();
2758 return;
2759 case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE:
2760 *params = shaderObject->getTranslatedSourceLength();
2761 return;
Geoff Langb1196682014-07-23 13:47:29 -04002762
Geoff Langbfdea662014-07-23 14:16:32 -04002763 default:
Geoff Langb1196682014-07-23 13:47:29 -04002764 context->recordError(gl::Error(GL_INVALID_ENUM));
2765 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002766 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002767 }
2768}
2769
Kenneth Russell67ea1902014-10-06 16:44:50 -07002770void GL_APIENTRY glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002771{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002772 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* infolog = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002773 shader, bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002774
Geoff Langbfdea662014-07-23 14:16:32 -04002775 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002776 if (context)
2777 {
Geoff Langb1196682014-07-23 13:47:29 -04002778 if (bufsize < 0)
2779 {
2780 context->recordError(gl::Error(GL_INVALID_VALUE));
2781 return;
2782 }
2783
Geoff Langbfdea662014-07-23 14:16:32 -04002784 gl::Shader *shaderObject = context->getShader(shader);
2785
2786 if (!shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002787 {
Geoff Langb1196682014-07-23 13:47:29 -04002788 context->recordError(gl::Error(GL_INVALID_VALUE));
2789 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002790 }
2791
Geoff Langbfdea662014-07-23 14:16:32 -04002792 shaderObject->getInfoLog(bufsize, length, infolog);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002793 }
2794}
2795
Kenneth Russell67ea1902014-10-06 16:44:50 -07002796void GL_APIENTRY glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002797{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002798 EVENT("(GLenum shadertype = 0x%X, GLenum precisiontype = 0x%X, GLint* range = 0x%0.8p, GLint* precision = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002799 shadertype, precisiontype, range, precision);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002800
Geoff Langb1196682014-07-23 13:47:29 -04002801 gl::Context *context = gl::getNonLostContext();
2802 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002803 {
Geoff Langb1196682014-07-23 13:47:29 -04002804 switch (shadertype)
2805 {
2806 case GL_VERTEX_SHADER:
2807 case GL_FRAGMENT_SHADER:
2808 break;
Geoff Langbfdea662014-07-23 14:16:32 -04002809
Geoff Langb1196682014-07-23 13:47:29 -04002810 default:
2811 context->recordError(gl::Error(GL_INVALID_ENUM));
2812 return;
2813 }
2814
2815 switch (precisiontype)
2816 {
2817 case GL_LOW_FLOAT:
2818 case GL_MEDIUM_FLOAT:
2819 case GL_HIGH_FLOAT:
2820 // Assume IEEE 754 precision
2821 range[0] = 127;
2822 range[1] = 127;
2823 *precision = 23;
2824 break;
2825
2826 case GL_LOW_INT:
2827 case GL_MEDIUM_INT:
2828 case GL_HIGH_INT:
2829 // Some (most) hardware only supports single-precision floating-point numbers,
2830 // which can accurately represent integers up to +/-16777216
2831 range[0] = 24;
2832 range[1] = 24;
2833 *precision = 0;
2834 break;
2835
2836 default:
2837 context->recordError(gl::Error(GL_INVALID_ENUM));
2838 return;
2839 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002840 }
2841}
2842
Kenneth Russell67ea1902014-10-06 16:44:50 -07002843void GL_APIENTRY glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002844{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002845 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00002846 shader, bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002847
Geoff Langbfdea662014-07-23 14:16:32 -04002848 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002849 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002850 {
Geoff Langb1196682014-07-23 13:47:29 -04002851 if (bufsize < 0)
2852 {
2853 context->recordError(gl::Error(GL_INVALID_VALUE));
2854 return;
2855 }
2856
Geoff Langbfdea662014-07-23 14:16:32 -04002857 gl::Shader *shaderObject = context->getShader(shader);
2858
2859 if (!shaderObject)
2860 {
Geoff Langb1196682014-07-23 13:47:29 -04002861 context->recordError(gl::Error(GL_INVALID_OPERATION));
2862 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002863 }
2864
2865 shaderObject->getSource(bufsize, length, source);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002866 }
2867}
2868
Kenneth Russell67ea1902014-10-06 16:44:50 -07002869void GL_APIENTRY glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source)
zmo@google.coma574f782011-10-03 21:45:23 +00002870{
2871 EVENT("(GLuint shader = %d, GLsizei bufsize = %d, GLsizei* length = 0x%0.8p, GLchar* source = 0x%0.8p)",
2872 shader, bufsize, length, source);
2873
Geoff Langbfdea662014-07-23 14:16:32 -04002874 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002875 if (context)
zmo@google.coma574f782011-10-03 21:45:23 +00002876 {
Geoff Langb1196682014-07-23 13:47:29 -04002877 if (bufsize < 0)
2878 {
2879 context->recordError(gl::Error(GL_INVALID_VALUE));
2880 return;
2881 }
2882
Geoff Langbfdea662014-07-23 14:16:32 -04002883 gl::Shader *shaderObject = context->getShader(shader);
2884
2885 if (!shaderObject)
2886 {
Geoff Langb1196682014-07-23 13:47:29 -04002887 context->recordError(gl::Error(GL_INVALID_OPERATION));
2888 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002889 }
2890
Tibor den Ouden97049c62014-10-06 21:39:16 +02002891 // Only returns extra info if ANGLE_GENERATE_SHADER_DEBUG_INFO is defined
2892 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
zmo@google.coma574f782011-10-03 21:45:23 +00002893 }
2894}
2895
Kenneth Russell67ea1902014-10-06 16:44:50 -07002896const GLubyte* GL_APIENTRY glGetString(GLenum name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002897{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002898 EVENT("(GLenum name = 0x%X)", name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002899
Geoff Langbfdea662014-07-23 14:16:32 -04002900 gl::Context *context = gl::getNonLostContext();
daniel@transgaming.com3e4c6002010-05-05 18:50:13 +00002901
Geoff Langbfdea662014-07-23 14:16:32 -04002902 switch (name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002903 {
Geoff Langbfdea662014-07-23 14:16:32 -04002904 case GL_VENDOR:
2905 return (GLubyte*)"Google Inc.";
Geoff Langb1196682014-07-23 13:47:29 -04002906
Geoff Langbfdea662014-07-23 14:16:32 -04002907 case GL_RENDERER:
2908 return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE");
Geoff Langb1196682014-07-23 13:47:29 -04002909
Geoff Langbfdea662014-07-23 14:16:32 -04002910 case GL_VERSION:
2911 if (context->getClientVersion() == 2)
2912 {
2913 return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")";
2914 }
2915 else
2916 {
2917 return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")";
2918 }
Geoff Langb1196682014-07-23 13:47:29 -04002919
Geoff Langbfdea662014-07-23 14:16:32 -04002920 case GL_SHADING_LANGUAGE_VERSION:
2921 if (context->getClientVersion() == 2)
2922 {
2923 return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")";
2924 }
2925 else
2926 {
2927 return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")";
2928 }
Geoff Langb1196682014-07-23 13:47:29 -04002929
Geoff Langbfdea662014-07-23 14:16:32 -04002930 case GL_EXTENSIONS:
2931 return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : "");
Geoff Langb1196682014-07-23 13:47:29 -04002932
Geoff Langbfdea662014-07-23 14:16:32 -04002933 default:
Geoff Langb1196682014-07-23 13:47:29 -04002934 if (context)
2935 {
2936 context->recordError(gl::Error(GL_INVALID_ENUM));
2937 }
2938 return NULL;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002939 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002940}
2941
Kenneth Russell67ea1902014-10-06 16:44:50 -07002942void GL_APIENTRY glGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002943{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00002944 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00002945
Geoff Langbfdea662014-07-23 14:16:32 -04002946 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04002947 if (context)
2948 {
2949 gl::Texture *texture = context->getTargetTexture(target);
2950
2951 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002952 {
Geoff Langb1196682014-07-23 13:47:29 -04002953 context->recordError(gl::Error(GL_INVALID_ENUM));
2954 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00002955 }
Geoff Langbfdea662014-07-23 14:16:32 -04002956
2957 switch (pname)
2958 {
2959 case GL_TEXTURE_MAG_FILTER:
2960 *params = (GLfloat)texture->getSamplerState().magFilter;
2961 break;
2962 case GL_TEXTURE_MIN_FILTER:
2963 *params = (GLfloat)texture->getSamplerState().minFilter;
2964 break;
2965 case GL_TEXTURE_WRAP_S:
2966 *params = (GLfloat)texture->getSamplerState().wrapS;
2967 break;
2968 case GL_TEXTURE_WRAP_T:
2969 *params = (GLfloat)texture->getSamplerState().wrapT;
2970 break;
2971 case GL_TEXTURE_WRAP_R:
2972 if (context->getClientVersion() < 3)
2973 {
Geoff Langb1196682014-07-23 13:47:29 -04002974 context->recordError(gl::Error(GL_INVALID_ENUM));
2975 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002976 }
2977 *params = (GLfloat)texture->getSamplerState().wrapR;
2978 break;
2979 case GL_TEXTURE_IMMUTABLE_FORMAT:
2980 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
2981 *params = (GLfloat)(texture->isImmutable() ? GL_TRUE : GL_FALSE);
2982 break;
2983 case GL_TEXTURE_IMMUTABLE_LEVELS:
2984 if (context->getClientVersion() < 3)
2985 {
Geoff Langb1196682014-07-23 13:47:29 -04002986 context->recordError(gl::Error(GL_INVALID_ENUM));
2987 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002988 }
2989 *params = (GLfloat)texture->immutableLevelCount();
2990 break;
2991 case GL_TEXTURE_USAGE_ANGLE:
2992 *params = (GLfloat)texture->getUsage();
2993 break;
2994 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2995 if (!context->getExtensions().textureFilterAnisotropic)
2996 {
Geoff Langb1196682014-07-23 13:47:29 -04002997 context->recordError(gl::Error(GL_INVALID_ENUM));
2998 return;
Geoff Langbfdea662014-07-23 14:16:32 -04002999 }
3000 *params = (GLfloat)texture->getSamplerState().maxAnisotropy;
3001 break;
3002 case GL_TEXTURE_SWIZZLE_R:
3003 if (context->getClientVersion() < 3)
3004 {
Geoff Langb1196682014-07-23 13:47:29 -04003005 context->recordError(gl::Error(GL_INVALID_ENUM));
3006 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003007 }
3008 *params = (GLfloat)texture->getSamplerState().swizzleRed;
3009 break;
3010 case GL_TEXTURE_SWIZZLE_G:
3011 if (context->getClientVersion() < 3)
3012 {
Geoff Langb1196682014-07-23 13:47:29 -04003013 context->recordError(gl::Error(GL_INVALID_ENUM));
3014 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003015 }
3016 *params = (GLfloat)texture->getSamplerState().swizzleGreen;
3017 break;
3018 case GL_TEXTURE_SWIZZLE_B:
3019 if (context->getClientVersion() < 3)
3020 {
Geoff Langb1196682014-07-23 13:47:29 -04003021 context->recordError(gl::Error(GL_INVALID_ENUM));
3022 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003023 }
3024 *params = (GLfloat)texture->getSamplerState().swizzleBlue;
3025 break;
3026 case GL_TEXTURE_SWIZZLE_A:
3027 if (context->getClientVersion() < 3)
3028 {
Geoff Langb1196682014-07-23 13:47:29 -04003029 context->recordError(gl::Error(GL_INVALID_ENUM));
3030 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003031 }
3032 *params = (GLfloat)texture->getSamplerState().swizzleAlpha;
3033 break;
3034 case GL_TEXTURE_BASE_LEVEL:
3035 if (context->getClientVersion() < 3)
3036 {
Geoff Langb1196682014-07-23 13:47:29 -04003037 context->recordError(gl::Error(GL_INVALID_ENUM));
3038 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003039 }
3040 *params = (GLfloat)texture->getSamplerState().baseLevel;
3041 break;
3042 case GL_TEXTURE_MAX_LEVEL:
3043 if (context->getClientVersion() < 3)
3044 {
Geoff Langb1196682014-07-23 13:47:29 -04003045 context->recordError(gl::Error(GL_INVALID_ENUM));
3046 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003047 }
3048 *params = (GLfloat)texture->getSamplerState().maxLevel;
3049 break;
3050 case GL_TEXTURE_MIN_LOD:
3051 if (context->getClientVersion() < 3)
3052 {
Geoff Langb1196682014-07-23 13:47:29 -04003053 context->recordError(gl::Error(GL_INVALID_ENUM));
3054 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003055 }
3056 *params = texture->getSamplerState().minLod;
3057 break;
3058 case GL_TEXTURE_MAX_LOD:
3059 if (context->getClientVersion() < 3)
3060 {
Geoff Langb1196682014-07-23 13:47:29 -04003061 context->recordError(gl::Error(GL_INVALID_ENUM));
3062 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003063 }
3064 *params = texture->getSamplerState().maxLod;
3065 break;
Geoff Langb1196682014-07-23 13:47:29 -04003066
Geoff Langbfdea662014-07-23 14:16:32 -04003067 default:
Geoff Langb1196682014-07-23 13:47:29 -04003068 context->recordError(gl::Error(GL_INVALID_ENUM));
3069 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003070 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003071 }
3072}
3073
Kenneth Russell67ea1902014-10-06 16:44:50 -07003074void GL_APIENTRY glGetTexParameteriv(GLenum target, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003075{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003076 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003077
Geoff Langbfdea662014-07-23 14:16:32 -04003078 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003079 if (context)
3080 {
3081 gl::Texture *texture = context->getTargetTexture(target);
3082
3083 if (!texture)
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003084 {
Geoff Langb1196682014-07-23 13:47:29 -04003085 context->recordError(gl::Error(GL_INVALID_ENUM));
3086 return;
daniel@transgaming.com5d2bee92010-04-20 18:51:56 +00003087 }
Geoff Langbfdea662014-07-23 14:16:32 -04003088
3089 switch (pname)
3090 {
3091 case GL_TEXTURE_MAG_FILTER:
3092 *params = texture->getSamplerState().magFilter;
3093 break;
3094 case GL_TEXTURE_MIN_FILTER:
3095 *params = texture->getSamplerState().minFilter;
3096 break;
3097 case GL_TEXTURE_WRAP_S:
3098 *params = texture->getSamplerState().wrapS;
3099 break;
3100 case GL_TEXTURE_WRAP_T:
3101 *params = texture->getSamplerState().wrapT;
3102 break;
3103 case GL_TEXTURE_WRAP_R:
3104 if (context->getClientVersion() < 3)
3105 {
Geoff Langb1196682014-07-23 13:47:29 -04003106 context->recordError(gl::Error(GL_INVALID_ENUM));
3107 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003108 }
3109 *params = texture->getSamplerState().wrapR;
3110 break;
3111 case GL_TEXTURE_IMMUTABLE_FORMAT:
3112 // Exposed to ES2.0 through EXT_texture_storage, no client version validation.
3113 *params = texture->isImmutable() ? GL_TRUE : GL_FALSE;
3114 break;
3115 case GL_TEXTURE_IMMUTABLE_LEVELS:
3116 if (context->getClientVersion() < 3)
3117 {
Geoff Langb1196682014-07-23 13:47:29 -04003118 context->recordError(gl::Error(GL_INVALID_ENUM));
3119 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003120 }
Jamie Madill6948e302014-10-20 17:04:33 -04003121 *params = static_cast<GLint>(texture->immutableLevelCount());
Geoff Langbfdea662014-07-23 14:16:32 -04003122 break;
3123 case GL_TEXTURE_USAGE_ANGLE:
3124 *params = texture->getUsage();
3125 break;
3126 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
3127 if (!context->getExtensions().textureFilterAnisotropic)
3128 {
Geoff Langb1196682014-07-23 13:47:29 -04003129 context->recordError(gl::Error(GL_INVALID_ENUM));
3130 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003131 }
3132 *params = (GLint)texture->getSamplerState().maxAnisotropy;
3133 break;
3134 case GL_TEXTURE_SWIZZLE_R:
3135 if (context->getClientVersion() < 3)
3136 {
Geoff Langb1196682014-07-23 13:47:29 -04003137 context->recordError(gl::Error(GL_INVALID_ENUM));
3138 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003139 }
3140 *params = texture->getSamplerState().swizzleRed;
3141 break;
3142 case GL_TEXTURE_SWIZZLE_G:
3143 if (context->getClientVersion() < 3)
3144 {
Geoff Langb1196682014-07-23 13:47:29 -04003145 context->recordError(gl::Error(GL_INVALID_ENUM));
3146 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003147 }
3148 *params = texture->getSamplerState().swizzleGreen;
3149 break;
3150 case GL_TEXTURE_SWIZZLE_B:
3151 if (context->getClientVersion() < 3)
3152 {
Geoff Langb1196682014-07-23 13:47:29 -04003153 context->recordError(gl::Error(GL_INVALID_ENUM));
3154 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003155 }
3156 *params = texture->getSamplerState().swizzleBlue;
3157 break;
3158 case GL_TEXTURE_SWIZZLE_A:
3159 if (context->getClientVersion() < 3)
3160 {
Geoff Langb1196682014-07-23 13:47:29 -04003161 context->recordError(gl::Error(GL_INVALID_ENUM));
3162 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003163 }
3164 *params = texture->getSamplerState().swizzleAlpha;
3165 break;
3166 case GL_TEXTURE_BASE_LEVEL:
3167 if (context->getClientVersion() < 3)
3168 {
Geoff Langb1196682014-07-23 13:47:29 -04003169 context->recordError(gl::Error(GL_INVALID_ENUM));
3170 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003171 }
3172 *params = texture->getSamplerState().baseLevel;
3173 break;
3174 case GL_TEXTURE_MAX_LEVEL:
3175 if (context->getClientVersion() < 3)
3176 {
Geoff Langb1196682014-07-23 13:47:29 -04003177 context->recordError(gl::Error(GL_INVALID_ENUM));
3178 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003179 }
3180 *params = texture->getSamplerState().maxLevel;
3181 break;
3182 case GL_TEXTURE_MIN_LOD:
3183 if (context->getClientVersion() < 3)
3184 {
Geoff Langb1196682014-07-23 13:47:29 -04003185 context->recordError(gl::Error(GL_INVALID_ENUM));
3186 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003187 }
3188 *params = (GLint)texture->getSamplerState().minLod;
3189 break;
3190 case GL_TEXTURE_MAX_LOD:
3191 if (context->getClientVersion() < 3)
3192 {
Geoff Langb1196682014-07-23 13:47:29 -04003193 context->recordError(gl::Error(GL_INVALID_ENUM));
3194 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003195 }
3196 *params = (GLint)texture->getSamplerState().maxLod;
3197 break;
Geoff Langb1196682014-07-23 13:47:29 -04003198
Geoff Langbfdea662014-07-23 14:16:32 -04003199 default:
Geoff Langb1196682014-07-23 13:47:29 -04003200 context->recordError(gl::Error(GL_INVALID_ENUM));
3201 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003202 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003203 }
3204}
3205
Kenneth Russell67ea1902014-10-06 16:44:50 -07003206void GL_APIENTRY glGetnUniformfvEXT(GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003207{
3208 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLfloat* params = 0x%0.8p)",
3209 program, location, bufSize, params);
3210
Geoff Langbfdea662014-07-23 14:16:32 -04003211 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003212 if (context)
3213 {
Jamie Madill0063c512014-08-25 15:47:53 -04003214 if (!ValidateGetnUniformfvEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003215 {
Jamie Madill0063c512014-08-25 15:47:53 -04003216 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003217 }
3218
Jamie Madilla502c742014-08-28 17:19:13 -04003219 gl::Program *programObject = context->getProgram(program);
3220 ASSERT(programObject);
3221 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003222 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003223
Jamie Madill99a1e982014-08-25 15:47:54 -04003224 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003225 }
3226}
3227
Kenneth Russell67ea1902014-10-06 16:44:50 -07003228void GL_APIENTRY glGetUniformfv(GLuint program, GLint location, GLfloat* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003229{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003230 EVENT("(GLuint program = %d, GLint location = %d, GLfloat* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003231
Geoff Langbfdea662014-07-23 14:16:32 -04003232 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003233 if (context)
3234 {
Jamie Madill0063c512014-08-25 15:47:53 -04003235 if (!ValidateGetUniformfv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003236 {
Jamie Madill0063c512014-08-25 15:47:53 -04003237 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003238 }
Geoff Langbfdea662014-07-23 14:16:32 -04003239
Jamie Madilla502c742014-08-28 17:19:13 -04003240 gl::Program *programObject = context->getProgram(program);
3241 ASSERT(programObject);
3242 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003243 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003244
Jamie Madill99a1e982014-08-25 15:47:54 -04003245 programBinary->getUniformfv(location, params);
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003246 }
3247}
3248
Kenneth Russell67ea1902014-10-06 16:44:50 -07003249void GL_APIENTRY glGetnUniformivEXT(GLuint program, GLint location, GLsizei bufSize, GLint* params)
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003250{
Geoff Langbfdea662014-07-23 14:16:32 -04003251 EVENT("(GLuint program = %d, GLint location = %d, GLsizei bufSize = %d, GLint* params = 0x%0.8p)",
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003252 program, location, bufSize, params);
3253
Geoff Langbfdea662014-07-23 14:16:32 -04003254 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003255 if (context)
3256 {
Jamie Madill0063c512014-08-25 15:47:53 -04003257 if (!ValidateGetnUniformivEXT(context, program, location, bufSize, params))
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003258 {
Jamie Madill0063c512014-08-25 15:47:53 -04003259 return;
daniel@transgaming.com9a849122011-11-12 03:18:00 +00003260 }
3261
Jamie Madilla502c742014-08-28 17:19:13 -04003262 gl::Program *programObject = context->getProgram(program);
3263 ASSERT(programObject);
3264 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003265 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003266
Jamie Madill99a1e982014-08-25 15:47:54 -04003267 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003268 }
3269}
3270
Kenneth Russell67ea1902014-10-06 16:44:50 -07003271void GL_APIENTRY glGetUniformiv(GLuint program, GLint location, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003272{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003273 EVENT("(GLuint program = %d, GLint location = %d, GLint* params = 0x%0.8p)", program, location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003274
Geoff Langbfdea662014-07-23 14:16:32 -04003275 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003276 if (context)
3277 {
Jamie Madill0063c512014-08-25 15:47:53 -04003278 if (!ValidateGetUniformiv(context, program, location, params))
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003279 {
Jamie Madill0063c512014-08-25 15:47:53 -04003280 return;
daniel@transgaming.combb3d9d02010-04-13 03:26:06 +00003281 }
Geoff Langbfdea662014-07-23 14:16:32 -04003282
Jamie Madilla502c742014-08-28 17:19:13 -04003283 gl::Program *programObject = context->getProgram(program);
3284 ASSERT(programObject);
3285 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04003286 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04003287
Jamie Madill99a1e982014-08-25 15:47:54 -04003288 programBinary->getUniformiv(location, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003289 }
3290}
3291
Kenneth Russell67ea1902014-10-06 16:44:50 -07003292GLint GL_APIENTRY glGetUniformLocation(GLuint program, const GLchar* name)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003293{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003294 EVENT("(GLuint program = %d, const GLchar* name = 0x%0.8p)", program, name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003295
Geoff Langbfdea662014-07-23 14:16:32 -04003296 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003297 if (context)
3298 {
Geoff Langb1196682014-07-23 13:47:29 -04003299 if (strstr(name, "gl_") == name)
3300 {
3301 return -1;
3302 }
3303
Geoff Langbfdea662014-07-23 14:16:32 -04003304 gl::Program *programObject = context->getProgram(program);
3305
3306 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003307 {
Geoff Langbfdea662014-07-23 14:16:32 -04003308 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003309 {
Geoff Langb1196682014-07-23 13:47:29 -04003310 context->recordError(gl::Error(GL_INVALID_OPERATION));
3311 return -1;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003312 }
Geoff Langbfdea662014-07-23 14:16:32 -04003313 else
3314 {
Geoff Langb1196682014-07-23 13:47:29 -04003315 context->recordError(gl::Error(GL_INVALID_VALUE));
3316 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003317 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003318 }
Geoff Langbfdea662014-07-23 14:16:32 -04003319
3320 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
3321 if (!programObject->isLinked() || !programBinary)
3322 {
Geoff Langb1196682014-07-23 13:47:29 -04003323 context->recordError(gl::Error(GL_INVALID_OPERATION));
3324 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04003325 }
3326
3327 return programBinary->getUniformLocation(name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003328 }
3329
3330 return -1;
3331}
3332
Kenneth Russell67ea1902014-10-06 16:44:50 -07003333void GL_APIENTRY glGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003334{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003335 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003336
Geoff Langbfdea662014-07-23 14:16:32 -04003337 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003338 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003339 {
Geoff Langbfdea662014-07-23 14:16:32 -04003340 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003341 {
Geoff Langb1196682014-07-23 13:47:29 -04003342 context->recordError(gl::Error(GL_INVALID_VALUE));
3343 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003344 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003345
Geoff Langbfdea662014-07-23 14:16:32 -04003346 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Geoff Langb1196682014-07-23 13:47:29 -04003347 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003348 {
3349 return;
3350 }
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003351
Geoff Langbfdea662014-07-23 14:16:32 -04003352 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3353 {
3354 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3355 for (int i = 0; i < 4; ++i)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003356 {
Geoff Langbfdea662014-07-23 14:16:32 -04003357 params[i] = currentValueData.FloatValues[i];
daniel@transgaming.come0078962010-04-15 20:45:08 +00003358 }
3359 }
Geoff Langbfdea662014-07-23 14:16:32 -04003360 else
3361 {
3362 *params = gl::QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
3363 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003364 }
3365}
3366
Kenneth Russell67ea1902014-10-06 16:44:50 -07003367void GL_APIENTRY glGetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003368{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003369 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", index, pname, params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003370
Geoff Langbfdea662014-07-23 14:16:32 -04003371 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003372 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003373 {
Geoff Langbfdea662014-07-23 14:16:32 -04003374 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003375 {
Geoff Langb1196682014-07-23 13:47:29 -04003376 context->recordError(gl::Error(GL_INVALID_VALUE));
3377 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003378 }
daniel@transgaming.come0078962010-04-15 20:45:08 +00003379
Geoff Langbfdea662014-07-23 14:16:32 -04003380 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
daniel@transgaming.com428d1582010-05-04 03:35:25 +00003381
Geoff Langb1196682014-07-23 13:47:29 -04003382 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04003383 {
3384 return;
3385 }
Jamie Madillaff71502013-07-02 11:57:05 -04003386
Geoff Langbfdea662014-07-23 14:16:32 -04003387 if (pname == GL_CURRENT_VERTEX_ATTRIB)
3388 {
3389 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
3390 for (int i = 0; i < 4; ++i)
Jamie Madillaff71502013-07-02 11:57:05 -04003391 {
Geoff Langbfdea662014-07-23 14:16:32 -04003392 float currentValue = currentValueData.FloatValues[i];
3393 params[i] = gl::iround<GLint>(currentValue);
daniel@transgaming.come0078962010-04-15 20:45:08 +00003394 }
3395 }
Geoff Langbfdea662014-07-23 14:16:32 -04003396 else
3397 {
3398 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
3399 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003400 }
3401}
3402
Kenneth Russell67ea1902014-10-06 16:44:50 -07003403void GL_APIENTRY glGetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid** pointer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003404{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003405 EVENT("(GLuint index = %d, GLenum pname = 0x%X, GLvoid** pointer = 0x%0.8p)", index, pname, pointer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003406
Geoff Langbfdea662014-07-23 14:16:32 -04003407 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003408 if (context)
3409 {
3410 if (index >= gl::MAX_VERTEX_ATTRIBS)
daniel@transgaming.come0078962010-04-15 20:45:08 +00003411 {
Geoff Langb1196682014-07-23 13:47:29 -04003412 context->recordError(gl::Error(GL_INVALID_VALUE));
3413 return;
daniel@transgaming.come0078962010-04-15 20:45:08 +00003414 }
Geoff Langbfdea662014-07-23 14:16:32 -04003415
3416 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER)
3417 {
Geoff Langb1196682014-07-23 13:47:29 -04003418 context->recordError(gl::Error(GL_INVALID_ENUM));
3419 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003420 }
3421
3422 *pointer = const_cast<GLvoid*>(context->getState().getVertexAttribPointer(index));
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003423 }
3424}
3425
Kenneth Russell67ea1902014-10-06 16:44:50 -07003426void GL_APIENTRY glHint(GLenum target, GLenum mode)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003427{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003428 EVENT("(GLenum target = 0x%X, GLenum mode = 0x%X)", target, mode);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003429
Geoff Langbfdea662014-07-23 14:16:32 -04003430 gl::Context *context = gl::getNonLostContext();
Geoff Langb1196682014-07-23 13:47:29 -04003431 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003432 {
Geoff Langb1196682014-07-23 13:47:29 -04003433 switch (mode)
3434 {
3435 case GL_FASTEST:
3436 case GL_NICEST:
3437 case GL_DONT_CARE:
3438 break;
3439
3440 default:
3441 context->recordError(gl::Error(GL_INVALID_ENUM));
3442 return;
3443 }
3444
3445 switch (target)
3446 {
3447 case GL_GENERATE_MIPMAP_HINT:
3448 context->getState().setGenerateMipmapHint(mode);
3449 break;
3450
3451 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
3452 context->getState().setFragmentShaderDerivativeHint(mode);
3453 break;
3454
3455 default:
3456 context->recordError(gl::Error(GL_INVALID_ENUM));
3457 return;
3458 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003459 }
3460}
3461
Kenneth Russell67ea1902014-10-06 16:44:50 -07003462GLboolean GL_APIENTRY glIsBuffer(GLuint buffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003463{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003464 EVENT("(GLuint buffer = %d)", buffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003465
Geoff Langbfdea662014-07-23 14:16:32 -04003466 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003467 if (context && buffer)
3468 {
3469 gl::Buffer *bufferObject = context->getBuffer(buffer);
3470
3471 if (bufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003472 {
Geoff Langbfdea662014-07-23 14:16:32 -04003473 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003474 }
3475 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003476
3477 return GL_FALSE;
3478}
3479
Kenneth Russell67ea1902014-10-06 16:44:50 -07003480GLboolean GL_APIENTRY glIsEnabled(GLenum cap)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003481{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003482 EVENT("(GLenum cap = 0x%X)", cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003483
Geoff Langbfdea662014-07-23 14:16:32 -04003484 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003485 if (context)
3486 {
3487 if (!ValidCap(context, cap))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003488 {
Geoff Langb1196682014-07-23 13:47:29 -04003489 context->recordError(gl::Error(GL_INVALID_ENUM));
3490 return GL_FALSE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003491 }
Geoff Langbfdea662014-07-23 14:16:32 -04003492
3493 return context->getState().getEnableFeature(cap);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003494 }
3495
3496 return false;
3497}
3498
Kenneth Russell67ea1902014-10-06 16:44:50 -07003499GLboolean GL_APIENTRY glIsFenceNV(GLuint fence)
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003500{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003501 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003502
Geoff Langbfdea662014-07-23 14:16:32 -04003503 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003504 if (context)
3505 {
3506 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3507
3508 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003509 {
Geoff Langbfdea662014-07-23 14:16:32 -04003510 return GL_FALSE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003511 }
Geoff Langbfdea662014-07-23 14:16:32 -04003512
3513 return fenceObject->isFence();
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003514 }
3515
3516 return GL_FALSE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003517}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003518
Kenneth Russell67ea1902014-10-06 16:44:50 -07003519GLboolean GL_APIENTRY glIsFramebuffer(GLuint framebuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003520{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003521 EVENT("(GLuint framebuffer = %d)", framebuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003522
Geoff Langbfdea662014-07-23 14:16:32 -04003523 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003524 if (context && framebuffer)
3525 {
3526 gl::Framebuffer *framebufferObject = context->getFramebuffer(framebuffer);
3527
3528 if (framebufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003529 {
Geoff Langbfdea662014-07-23 14:16:32 -04003530 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003531 }
3532 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003533
3534 return GL_FALSE;
3535}
3536
Kenneth Russell67ea1902014-10-06 16:44:50 -07003537GLboolean GL_APIENTRY glIsProgram(GLuint program)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003538{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003539 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003540
Geoff Langbfdea662014-07-23 14:16:32 -04003541 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003542 if (context && program)
3543 {
3544 gl::Program *programObject = context->getProgram(program);
3545
3546 if (programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003547 {
Geoff Langbfdea662014-07-23 14:16:32 -04003548 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003549 }
3550 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003551
3552 return GL_FALSE;
3553}
3554
Kenneth Russell67ea1902014-10-06 16:44:50 -07003555GLboolean GL_APIENTRY glIsQueryEXT(GLuint id)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003556{
3557 EVENT("(GLuint id = %d)", id);
3558
Geoff Langbfdea662014-07-23 14:16:32 -04003559 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003560 if (context)
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003561 {
Geoff Langbfdea662014-07-23 14:16:32 -04003562 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
daniel@transgaming.com86bdb822012-01-20 18:24:39 +00003563 }
3564
3565 return GL_FALSE;
3566}
3567
Kenneth Russell67ea1902014-10-06 16:44:50 -07003568GLboolean GL_APIENTRY glIsRenderbuffer(GLuint renderbuffer)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003569{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003570 EVENT("(GLuint renderbuffer = %d)", renderbuffer);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003571
Geoff Langbfdea662014-07-23 14:16:32 -04003572 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003573 if (context && renderbuffer)
3574 {
3575 gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
3576
3577 if (renderbufferObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003578 {
Geoff Langbfdea662014-07-23 14:16:32 -04003579 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003580 }
3581 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003582
3583 return GL_FALSE;
3584}
3585
Kenneth Russell67ea1902014-10-06 16:44:50 -07003586GLboolean GL_APIENTRY glIsShader(GLuint shader)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003587{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003588 EVENT("(GLuint shader = %d)", shader);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003589
Geoff Langbfdea662014-07-23 14:16:32 -04003590 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003591 if (context && shader)
3592 {
3593 gl::Shader *shaderObject = context->getShader(shader);
3594
3595 if (shaderObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003596 {
Geoff Langbfdea662014-07-23 14:16:32 -04003597 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003598 }
3599 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003600
3601 return GL_FALSE;
3602}
3603
Kenneth Russell67ea1902014-10-06 16:44:50 -07003604GLboolean GL_APIENTRY glIsTexture(GLuint texture)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003605{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003606 EVENT("(GLuint texture = %d)", texture);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003607
Geoff Langbfdea662014-07-23 14:16:32 -04003608 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003609 if (context && texture)
3610 {
3611 gl::Texture *textureObject = context->getTexture(texture);
3612
3613 if (textureObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003614 {
Geoff Langbfdea662014-07-23 14:16:32 -04003615 return GL_TRUE;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003616 }
3617 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003618
3619 return GL_FALSE;
3620}
3621
Kenneth Russell67ea1902014-10-06 16:44:50 -07003622void GL_APIENTRY glLineWidth(GLfloat width)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003623{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003624 EVENT("(GLfloat width = %f)", width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003625
Geoff Langbfdea662014-07-23 14:16:32 -04003626 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003627 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003628 {
Geoff Langb1196682014-07-23 13:47:29 -04003629 if (width <= 0.0f)
3630 {
3631 context->recordError(gl::Error(GL_INVALID_VALUE));
3632 return;
3633 }
3634
Geoff Langbfdea662014-07-23 14:16:32 -04003635 context->getState().setLineWidth(width);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003636 }
3637}
3638
Kenneth Russell67ea1902014-10-06 16:44:50 -07003639void GL_APIENTRY glLinkProgram(GLuint program)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003640{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003641 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003642
Geoff Langbfdea662014-07-23 14:16:32 -04003643 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003644 if (context)
3645 {
3646 gl::Program *programObject = context->getProgram(program);
3647
3648 if (!programObject)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003649 {
Geoff Langbfdea662014-07-23 14:16:32 -04003650 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003651 {
Geoff Langb1196682014-07-23 13:47:29 -04003652 context->recordError(gl::Error(GL_INVALID_OPERATION));
3653 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003654 }
Geoff Langbfdea662014-07-23 14:16:32 -04003655 else
3656 {
Geoff Langb1196682014-07-23 13:47:29 -04003657 context->recordError(gl::Error(GL_INVALID_VALUE));
3658 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003659 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003660 }
Geoff Langbfdea662014-07-23 14:16:32 -04003661
Geoff Langb543aff2014-09-30 14:52:54 -04003662 gl::Error error = context->linkProgram(program);
3663 if (error.isError())
3664 {
3665 context->recordError(error);
3666 return;
3667 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003668 }
3669}
3670
Kenneth Russell67ea1902014-10-06 16:44:50 -07003671void GL_APIENTRY glPixelStorei(GLenum pname, GLint param)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003672{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003673 EVENT("(GLenum pname = 0x%X, GLint param = %d)", pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003674
Geoff Langbfdea662014-07-23 14:16:32 -04003675 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003676 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003677 {
Geoff Langbfdea662014-07-23 14:16:32 -04003678 switch (pname)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003679 {
Geoff Langbfdea662014-07-23 14:16:32 -04003680 case GL_UNPACK_ALIGNMENT:
3681 if (param != 1 && param != 2 && param != 4 && param != 8)
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003682 {
Geoff Langb1196682014-07-23 13:47:29 -04003683 context->recordError(gl::Error(GL_INVALID_VALUE));
3684 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003685 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003686
Geoff Langbfdea662014-07-23 14:16:32 -04003687 context->getState().setUnpackAlignment(param);
3688 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003689
Geoff Langbfdea662014-07-23 14:16:32 -04003690 case GL_PACK_ALIGNMENT:
3691 if (param != 1 && param != 2 && param != 4 && param != 8)
3692 {
Geoff Langb1196682014-07-23 13:47:29 -04003693 context->recordError(gl::Error(GL_INVALID_VALUE));
3694 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003695 }
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003696
Geoff Langbfdea662014-07-23 14:16:32 -04003697 context->getState().setPackAlignment(param);
3698 break;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003699
Geoff Langbfdea662014-07-23 14:16:32 -04003700 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
3701 context->getState().setPackReverseRowOrder(param != 0);
3702 break;
bsalomon@google.com56d46ab2011-11-23 14:53:10 +00003703
Geoff Langbfdea662014-07-23 14:16:32 -04003704 case GL_UNPACK_IMAGE_HEIGHT:
3705 case GL_UNPACK_SKIP_IMAGES:
3706 case GL_UNPACK_ROW_LENGTH:
3707 case GL_UNPACK_SKIP_ROWS:
3708 case GL_UNPACK_SKIP_PIXELS:
3709 case GL_PACK_ROW_LENGTH:
3710 case GL_PACK_SKIP_ROWS:
3711 case GL_PACK_SKIP_PIXELS:
3712 if (context->getClientVersion() < 3)
3713 {
Geoff Langb1196682014-07-23 13:47:29 -04003714 context->recordError(gl::Error(GL_INVALID_ENUM));
3715 return;
daniel@transgaming.com3489e3a2010-03-21 04:31:11 +00003716 }
Geoff Langbfdea662014-07-23 14:16:32 -04003717 UNIMPLEMENTED();
3718 break;
3719
3720 default:
Geoff Langb1196682014-07-23 13:47:29 -04003721 context->recordError(gl::Error(GL_INVALID_ENUM));
3722 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003723 }
3724 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003725}
3726
Kenneth Russell67ea1902014-10-06 16:44:50 -07003727void GL_APIENTRY glPolygonOffset(GLfloat factor, GLfloat units)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003728{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003729 EVENT("(GLfloat factor = %f, GLfloat units = %f)", factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003730
Geoff Langbfdea662014-07-23 14:16:32 -04003731 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003732 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003733 {
Geoff Langbfdea662014-07-23 14:16:32 -04003734 context->getState().setPolygonOffsetParams(factor, units);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003735 }
3736}
3737
Kenneth Russell67ea1902014-10-06 16:44:50 -07003738void GL_APIENTRY glReadnPixelsEXT(GLint x, GLint y, GLsizei width, GLsizei height,
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003739 GLenum format, GLenum type, GLsizei bufSize,
3740 GLvoid *data)
3741{
3742 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
3743 "GLenum format = 0x%X, GLenum type = 0x%X, GLsizei bufSize = 0x%d, GLvoid *data = 0x%0.8p)",
3744 x, y, width, height, format, type, bufSize, data);
3745
Geoff Langbfdea662014-07-23 14:16:32 -04003746 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003747 if (context)
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003748 {
Geoff Langb1196682014-07-23 13:47:29 -04003749 if (width < 0 || height < 0 || bufSize < 0)
3750 {
3751 context->recordError(gl::Error(GL_INVALID_VALUE));
3752 return;
3753 }
3754
Geoff Langbfdea662014-07-23 14:16:32 -04003755 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3756 format, type, &bufSize, data))
3757 {
3758 return;
3759 }
3760
Geoff Lang63d2fc72014-07-25 14:51:41 -04003761 gl::Error error = context->readPixels(x, y, width, height, format, type, &bufSize, data);
3762 if (error.isError())
3763 {
3764 context->recordError(error);
3765 return;
3766 }
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003767 }
3768}
3769
Kenneth Russell67ea1902014-10-06 16:44:50 -07003770void GL_APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
daniel@transgaming.comb7915a52011-11-12 03:14:20 +00003771 GLenum format, GLenum type, GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003772{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003773 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003774 "GLenum format = 0x%X, GLenum type = 0x%X, GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003775 x, y, width, height, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003776
Geoff Langbfdea662014-07-23 14:16:32 -04003777 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003778 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003779 {
Geoff Langb1196682014-07-23 13:47:29 -04003780 if (width < 0 || height < 0)
3781 {
3782 context->recordError(gl::Error(GL_INVALID_VALUE));
3783 return;
3784 }
3785
Geoff Langbfdea662014-07-23 14:16:32 -04003786 if (!gl::ValidateReadPixelsParameters(context, x, y, width, height,
3787 format, type, NULL, pixels))
3788 {
3789 return;
3790 }
3791
Geoff Lang63d2fc72014-07-25 14:51:41 -04003792 gl::Error error = context->readPixels(x, y, width, height, format, type, NULL, pixels);
3793 if (error.isError())
3794 {
3795 context->recordError(error);
3796 return;
3797 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003798 }
3799}
3800
Kenneth Russell67ea1902014-10-06 16:44:50 -07003801void GL_APIENTRY glReleaseShaderCompiler(void)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003802{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003803 EVENT("()");
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003804
Brandon Jonesf05cdee2014-08-27 15:24:07 -07003805 gl::Context *context = gl::getNonLostContext();
3806
3807 if (context)
3808 {
3809 context->releaseShaderCompiler();
3810 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003811}
3812
Kenneth Russell67ea1902014-10-06 16:44:50 -07003813void GL_APIENTRY glRenderbufferStorageMultisampleANGLE(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003814{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003815 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003816 target, samples, internalformat, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003817
Geoff Langbfdea662014-07-23 14:16:32 -04003818 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003819 if (context)
3820 {
Corentin Walleze0902642014-11-04 12:32:15 -08003821 if (!ValidateRenderbufferStorageParametersANGLE(context, target, samples, internalformat,
3822 width, height))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003823 {
Geoff Langbfdea662014-07-23 14:16:32 -04003824 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003825 }
Geoff Langbfdea662014-07-23 14:16:32 -04003826
Shannon Woodse2632d22014-10-17 13:08:51 -04003827 gl::Renderbuffer *renderbuffer = context->getState().getCurrentRenderbuffer();
Geoff Langbafefdf2014-10-10 14:26:35 -04003828 gl::Error error = renderbuffer->setStorage(width, height, internalformat, samples);
3829 if (error.isError())
3830 {
3831 context->recordError(error);
3832 return;
3833 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003834 }
3835}
3836
Kenneth Russell67ea1902014-10-06 16:44:50 -07003837void GL_APIENTRY glRenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com1f135d82010-08-24 19:20:36 +00003838{
3839 glRenderbufferStorageMultisampleANGLE(target, 0, internalformat, width, height);
3840}
3841
Kenneth Russell67ea1902014-10-06 16:44:50 -07003842void GL_APIENTRY glSampleCoverage(GLclampf value, GLboolean invert)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003843{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00003844 EVENT("(GLclampf value = %f, GLboolean invert = %u)", value, invert);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003845
Geoff Langbfdea662014-07-23 14:16:32 -04003846 gl::Context* context = gl::getNonLostContext();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003847
Geoff Langbfdea662014-07-23 14:16:32 -04003848 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003849 {
Geoff Langbfdea662014-07-23 14:16:32 -04003850 context->getState().setSampleCoverageParams(gl::clamp01(value), invert == GL_TRUE);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003851 }
3852}
3853
Kenneth Russell67ea1902014-10-06 16:44:50 -07003854void GL_APIENTRY glSetFenceNV(GLuint fence, GLenum condition)
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003855{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003856 EVENT("(GLuint fence = %d, GLenum condition = 0x%X)", fence, condition);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003857
Geoff Langbfdea662014-07-23 14:16:32 -04003858 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003859 if (context)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003860 {
Geoff Langb1196682014-07-23 13:47:29 -04003861 if (condition != GL_ALL_COMPLETED_NV)
3862 {
3863 context->recordError(gl::Error(GL_INVALID_ENUM));
3864 return;
3865 }
3866
Geoff Langbfdea662014-07-23 14:16:32 -04003867 gl::FenceNV *fenceObject = context->getFenceNV(fence);
3868
3869 if (fenceObject == NULL)
3870 {
Geoff Langb1196682014-07-23 13:47:29 -04003871 context->recordError(gl::Error(GL_INVALID_OPERATION));
3872 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003873 }
3874
Geoff Lang882033e2014-09-30 11:26:07 -04003875 gl::Error error = fenceObject->setFence(condition);
3876 if (error.isError())
3877 {
3878 context->recordError(error);
3879 return;
3880 }
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003881 }
daniel@transgaming.comfe208882010-09-01 15:47:57 +00003882}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00003883
Kenneth Russell67ea1902014-10-06 16:44:50 -07003884void GL_APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003885{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003886 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)", x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003887
Geoff Langbfdea662014-07-23 14:16:32 -04003888 gl::Context* context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003889 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003890 {
Geoff Langb1196682014-07-23 13:47:29 -04003891 if (width < 0 || height < 0)
3892 {
3893 context->recordError(gl::Error(GL_INVALID_VALUE));
3894 return;
3895 }
3896
Geoff Langbfdea662014-07-23 14:16:32 -04003897 context->getState().setScissorParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003898 }
3899}
3900
Kenneth Russell67ea1902014-10-06 16:44:50 -07003901void GL_APIENTRY glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003902{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003903 EVENT("(GLsizei n = %d, const GLuint* shaders = 0x%0.8p, GLenum binaryformat = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00003904 "const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003905 n, shaders, binaryformat, binary, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003906
Geoff Lang900013c2014-07-07 11:32:19 -04003907 gl::Context* context = gl::getNonLostContext();
3908 if (context)
3909 {
3910 const std::vector<GLenum> &shaderBinaryFormats = context->getCaps().shaderBinaryFormats;
3911 if (std::find(shaderBinaryFormats.begin(), shaderBinaryFormats.end(), binaryformat) == shaderBinaryFormats.end())
3912 {
Geoff Langb1196682014-07-23 13:47:29 -04003913 context->recordError(gl::Error(GL_INVALID_ENUM));
3914 return;
Geoff Lang900013c2014-07-07 11:32:19 -04003915 }
3916
3917 // No binary shader formats are supported.
3918 UNIMPLEMENTED();
3919 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003920}
3921
Kenneth Russell67ea1902014-10-06 16:44:50 -07003922void GL_APIENTRY glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003923{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003924 EVENT("(GLuint shader = %d, GLsizei count = %d, const GLchar** string = 0x%0.8p, const GLint* length = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00003925 shader, count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003926
Geoff Langbfdea662014-07-23 14:16:32 -04003927 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003928 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003929 {
Geoff Langb1196682014-07-23 13:47:29 -04003930 if (count < 0)
3931 {
3932 context->recordError(gl::Error(GL_INVALID_VALUE));
3933 return;
3934 }
3935
Geoff Langbfdea662014-07-23 14:16:32 -04003936 gl::Shader *shaderObject = context->getShader(shader);
3937
3938 if (!shaderObject)
3939 {
3940 if (context->getProgram(shader))
3941 {
Geoff Langb1196682014-07-23 13:47:29 -04003942 context->recordError(gl::Error(GL_INVALID_OPERATION));
3943 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003944 }
3945 else
3946 {
Geoff Langb1196682014-07-23 13:47:29 -04003947 context->recordError(gl::Error(GL_INVALID_VALUE));
3948 return;
Geoff Langbfdea662014-07-23 14:16:32 -04003949 }
3950 }
3951
3952 shaderObject->setSource(count, string, length);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003953 }
3954}
3955
Kenneth Russell67ea1902014-10-06 16:44:50 -07003956void GL_APIENTRY glStencilFunc(GLenum func, GLint ref, GLuint mask)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003957{
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +00003958 glStencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003959}
3960
Kenneth Russell67ea1902014-10-06 16:44:50 -07003961void GL_APIENTRY glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003962{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00003963 EVENT("(GLenum face = 0x%X, GLenum func = 0x%X, GLint ref = %d, GLuint mask = %d)", face, func, ref, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003964
Geoff Langbfdea662014-07-23 14:16:32 -04003965 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04003966 if (context)
3967 {
Geoff Langb1196682014-07-23 13:47:29 -04003968 switch (face)
3969 {
3970 case GL_FRONT:
3971 case GL_BACK:
3972 case GL_FRONT_AND_BACK:
3973 break;
3974
3975 default:
3976 context->recordError(gl::Error(GL_INVALID_ENUM));
3977 return;
3978 }
3979
3980 switch (func)
3981 {
3982 case GL_NEVER:
3983 case GL_ALWAYS:
3984 case GL_LESS:
3985 case GL_LEQUAL:
3986 case GL_EQUAL:
3987 case GL_GEQUAL:
3988 case GL_GREATER:
3989 case GL_NOTEQUAL:
3990 break;
3991
3992 default:
3993 context->recordError(gl::Error(GL_INVALID_ENUM));
3994 return;
3995 }
3996
Geoff Langbfdea662014-07-23 14:16:32 -04003997 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3998 {
3999 context->getState().setStencilParams(func, ref, mask);
4000 }
4001
4002 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4003 {
4004 context->getState().setStencilBackParams(func, ref, mask);
4005 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004006 }
4007}
4008
Kenneth Russell67ea1902014-10-06 16:44:50 -07004009void GL_APIENTRY glStencilMask(GLuint mask)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004010{
4011 glStencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4012}
4013
Kenneth Russell67ea1902014-10-06 16:44:50 -07004014void GL_APIENTRY glStencilMaskSeparate(GLenum face, GLuint mask)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004015{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004016 EVENT("(GLenum face = 0x%X, GLuint mask = %d)", face, mask);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004017
Geoff Langbfdea662014-07-23 14:16:32 -04004018 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004019 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004020 {
Geoff Langb1196682014-07-23 13:47:29 -04004021 switch (face)
4022 {
4023 case GL_FRONT:
4024 case GL_BACK:
4025 case GL_FRONT_AND_BACK:
4026 break;
4027
4028 default:
4029 context->recordError(gl::Error(GL_INVALID_ENUM));
4030 return;
4031 }
4032
Geoff Langbfdea662014-07-23 14:16:32 -04004033 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4034 {
4035 context->getState().setStencilWritemask(mask);
4036 }
4037
4038 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4039 {
4040 context->getState().setStencilBackWritemask(mask);
4041 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004042 }
4043}
4044
Kenneth Russell67ea1902014-10-06 16:44:50 -07004045void GL_APIENTRY glStencilOp(GLenum fail, GLenum zfail, GLenum zpass)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004046{
4047 glStencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4048}
4049
Kenneth Russell67ea1902014-10-06 16:44:50 -07004050void GL_APIENTRY glStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004051{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004052 EVENT("(GLenum face = 0x%X, GLenum fail = 0x%X, GLenum zfail = 0x%X, GLenum zpas = 0x%Xs)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004053 face, fail, zfail, zpass);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004054
Geoff Langbfdea662014-07-23 14:16:32 -04004055 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004056 if (context)
4057 {
Geoff Langb1196682014-07-23 13:47:29 -04004058 switch (face)
4059 {
4060 case GL_FRONT:
4061 case GL_BACK:
4062 case GL_FRONT_AND_BACK:
4063 break;
4064
4065 default:
4066 context->recordError(gl::Error(GL_INVALID_ENUM));
4067 return;
4068 }
4069
4070 switch (fail)
4071 {
4072 case GL_ZERO:
4073 case GL_KEEP:
4074 case GL_REPLACE:
4075 case GL_INCR:
4076 case GL_DECR:
4077 case GL_INVERT:
4078 case GL_INCR_WRAP:
4079 case GL_DECR_WRAP:
4080 break;
4081
4082 default:
4083 context->recordError(gl::Error(GL_INVALID_ENUM));
4084 return;
4085 }
4086
4087 switch (zfail)
4088 {
4089 case GL_ZERO:
4090 case GL_KEEP:
4091 case GL_REPLACE:
4092 case GL_INCR:
4093 case GL_DECR:
4094 case GL_INVERT:
4095 case GL_INCR_WRAP:
4096 case GL_DECR_WRAP:
4097 break;
4098
4099 default:
4100 context->recordError(gl::Error(GL_INVALID_ENUM));
4101 return;
4102 }
4103
4104 switch (zpass)
4105 {
4106 case GL_ZERO:
4107 case GL_KEEP:
4108 case GL_REPLACE:
4109 case GL_INCR:
4110 case GL_DECR:
4111 case GL_INVERT:
4112 case GL_INCR_WRAP:
4113 case GL_DECR_WRAP:
4114 break;
4115
4116 default:
4117 context->recordError(gl::Error(GL_INVALID_ENUM));
4118 return;
4119 }
4120
Geoff Langbfdea662014-07-23 14:16:32 -04004121 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4122 {
4123 context->getState().setStencilOperations(fail, zfail, zpass);
4124 }
4125
4126 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4127 {
4128 context->getState().setStencilBackOperations(fail, zfail, zpass);
4129 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004130 }
4131}
4132
Kenneth Russell67ea1902014-10-06 16:44:50 -07004133GLboolean GL_APIENTRY glTestFenceNV(GLuint fence)
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004134{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004135 EVENT("(GLuint fence = %d)", fence);
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004136
Geoff Langbfdea662014-07-23 14:16:32 -04004137 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004138 if (context)
4139 {
4140 gl::FenceNV *fenceObject = context->getFenceNV(fence);
4141
4142 if (fenceObject == NULL)
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004143 {
Geoff Langb1196682014-07-23 13:47:29 -04004144 context->recordError(gl::Error(GL_INVALID_OPERATION));
4145 return GL_TRUE;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004146 }
Geoff Langbfdea662014-07-23 14:16:32 -04004147
4148 if (fenceObject->isFence() != GL_TRUE)
4149 {
Geoff Langb1196682014-07-23 13:47:29 -04004150 context->recordError(gl::Error(GL_INVALID_OPERATION));
4151 return GL_TRUE;
Geoff Langbfdea662014-07-23 14:16:32 -04004152 }
4153
Geoff Lang882033e2014-09-30 11:26:07 -04004154 GLboolean result;
4155 gl::Error error = fenceObject->testFence(&result);
4156 if (error.isError())
4157 {
4158 context->recordError(error);
4159 return GL_TRUE;
4160 }
4161
4162 return result;
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004163 }
Geoff Langbfdea662014-07-23 14:16:32 -04004164
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004165 return GL_TRUE;
daniel@transgaming.comfe208882010-09-01 15:47:57 +00004166}
apatrick@chromium.orgd3bd0ad2010-08-30 18:55:36 +00004167
Kenneth Russell67ea1902014-10-06 16:44:50 -07004168void GL_APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004169 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004170{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004171 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, GLsizei height = %d, "
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05004172 "GLint border = %d, GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004173 target, level, internalformat, width, height, border, format, type, pixels);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004174
Geoff Langbfdea662014-07-23 14:16:32 -04004175 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004176 if (context)
4177 {
4178 if (context->getClientVersion() < 3 &&
4179 !ValidateES2TexImageParameters(context, target, level, internalformat, false, false,
4180 0, 0, width, height, border, format, type, pixels))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004181 {
Geoff Langbfdea662014-07-23 14:16:32 -04004182 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004183 }
Geoff Langbfdea662014-07-23 14:16:32 -04004184
4185 if (context->getClientVersion() >= 3 &&
4186 !ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
4187 0, 0, 0, width, height, 1, border, format, type, pixels))
4188 {
4189 return;
4190 }
4191
4192 switch (target)
4193 {
4194 case GL_TEXTURE_2D:
4195 {
4196 gl::Texture2D *texture = context->getTexture2D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004197 gl::Error error = texture->setImage(level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
4198 if (error.isError())
4199 {
4200 context->recordError(error);
4201 return;
4202 }
Geoff Langbfdea662014-07-23 14:16:32 -04004203 }
4204 break;
Geoff Lang8376cea2014-09-02 11:47:07 -04004205
Geoff Langbfdea662014-07-23 14:16:32 -04004206 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
Geoff Langbfdea662014-07-23 14:16:32 -04004207 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
Geoff Langbfdea662014-07-23 14:16:32 -04004208 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
Geoff Langbfdea662014-07-23 14:16:32 -04004209 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
Geoff Langbfdea662014-07-23 14:16:32 -04004210 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
Geoff Langbfdea662014-07-23 14:16:32 -04004211 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4212 {
4213 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang8376cea2014-09-02 11:47:07 -04004214 gl::Error error = texture->setImage(target, level, width, height, internalformat, format, type, context->getState().getUnpackState(), pixels);
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004215 if (error.isError())
4216 {
4217 context->recordError(error);
4218 return;
4219 }
Geoff Langbfdea662014-07-23 14:16:32 -04004220 }
4221 break;
Geoff Lang8376cea2014-09-02 11:47:07 -04004222
Geoff Langbfdea662014-07-23 14:16:32 -04004223 default: UNREACHABLE();
4224 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004225 }
4226}
4227
Kenneth Russell67ea1902014-10-06 16:44:50 -07004228void GL_APIENTRY glTexParameterf(GLenum target, GLenum pname, GLfloat param)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004229{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004230 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %f)", target, pname, param);
4231
Geoff Langbfdea662014-07-23 14:16:32 -04004232 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004233 if (context)
4234 {
4235 if (!ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004236 {
Geoff Langbfdea662014-07-23 14:16:32 -04004237 return;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004238 }
Geoff Langbfdea662014-07-23 14:16:32 -04004239
4240 gl::Texture *texture = context->getTargetTexture(target);
4241
4242 if (!texture)
4243 {
Geoff Langb1196682014-07-23 13:47:29 -04004244 context->recordError(gl::Error(GL_INVALID_ENUM));
4245 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004246 }
4247
4248 switch (pname)
4249 {
4250 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = gl::uiround<GLenum>(param); break;
4251 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = gl::uiround<GLenum>(param); break;
4252 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = gl::uiround<GLenum>(param); break;
4253 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = gl::uiround<GLenum>(param); break;
4254 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = gl::uiround<GLenum>(param); break;
4255 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage(gl::uiround<GLenum>(param)); break;
4256 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min(param, context->getExtensions().maxTextureAnisotropy); break;
4257 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = gl::uiround<GLenum>(param); break;
4258 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = gl::uiround<GLenum>(param); break;
4259 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = gl::uiround<GLenum>(param); break;
4260 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = gl::uiround<GLenum>(param); break;
4261 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = gl::uiround<GLenum>(param); break;
4262 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = gl::uiround<GLenum>(param); break;
4263 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = gl::iround<GLint>(param); break;
4264 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = gl::iround<GLint>(param); break;
4265 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = param; break;
4266 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = param; break;
4267 default: UNREACHABLE(); break;
4268 }
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004269 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004270}
4271
Kenneth Russell67ea1902014-10-06 16:44:50 -07004272void GL_APIENTRY glTexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004273{
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00004274 glTexParameterf(target, pname, (GLfloat)*params);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004275}
4276
Kenneth Russell67ea1902014-10-06 16:44:50 -07004277void GL_APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004278{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004279 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint param = %d)", target, pname, param);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004280
Geoff Langbfdea662014-07-23 14:16:32 -04004281 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004282 if (context)
4283 {
4284 if (!ValidateTexParamParameters(context, pname, param))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004285 {
Geoff Langbfdea662014-07-23 14:16:32 -04004286 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004287 }
Geoff Langbfdea662014-07-23 14:16:32 -04004288
4289 gl::Texture *texture = context->getTargetTexture(target);
4290
4291 if (!texture)
4292 {
Geoff Langb1196682014-07-23 13:47:29 -04004293 context->recordError(gl::Error(GL_INVALID_ENUM));
4294 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004295 }
4296
4297 switch (pname)
4298 {
4299 case GL_TEXTURE_WRAP_S: texture->getSamplerState().wrapS = (GLenum)param; break;
4300 case GL_TEXTURE_WRAP_T: texture->getSamplerState().wrapT = (GLenum)param; break;
4301 case GL_TEXTURE_WRAP_R: texture->getSamplerState().wrapR = (GLenum)param; break;
4302 case GL_TEXTURE_MIN_FILTER: texture->getSamplerState().minFilter = (GLenum)param; break;
4303 case GL_TEXTURE_MAG_FILTER: texture->getSamplerState().magFilter = (GLenum)param; break;
4304 case GL_TEXTURE_USAGE_ANGLE: texture->setUsage((GLenum)param); break;
4305 case GL_TEXTURE_MAX_ANISOTROPY_EXT: texture->getSamplerState().maxAnisotropy = std::min((float)param, context->getExtensions().maxTextureAnisotropy); break;
4306 case GL_TEXTURE_COMPARE_MODE: texture->getSamplerState().compareMode = (GLenum)param; break;
4307 case GL_TEXTURE_COMPARE_FUNC: texture->getSamplerState().compareFunc = (GLenum)param; break;
4308 case GL_TEXTURE_SWIZZLE_R: texture->getSamplerState().swizzleRed = (GLenum)param; break;
4309 case GL_TEXTURE_SWIZZLE_G: texture->getSamplerState().swizzleGreen = (GLenum)param; break;
4310 case GL_TEXTURE_SWIZZLE_B: texture->getSamplerState().swizzleBlue = (GLenum)param; break;
4311 case GL_TEXTURE_SWIZZLE_A: texture->getSamplerState().swizzleAlpha = (GLenum)param; break;
4312 case GL_TEXTURE_BASE_LEVEL: texture->getSamplerState().baseLevel = param; break;
4313 case GL_TEXTURE_MAX_LEVEL: texture->getSamplerState().maxLevel = param; break;
4314 case GL_TEXTURE_MIN_LOD: texture->getSamplerState().minLod = (GLfloat)param; break;
4315 case GL_TEXTURE_MAX_LOD: texture->getSamplerState().maxLod = (GLfloat)param; break;
4316 default: UNREACHABLE(); break;
4317 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004318 }
4319}
4320
Kenneth Russell67ea1902014-10-06 16:44:50 -07004321void GL_APIENTRY glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004322{
4323 glTexParameteri(target, pname, *params);
4324}
4325
Kenneth Russell67ea1902014-10-06 16:44:50 -07004326void GL_APIENTRY glTexStorage2DEXT(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004327{
4328 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
4329 target, levels, internalformat, width, height);
4330
Geoff Langbfdea662014-07-23 14:16:32 -04004331 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004332 if (context)
4333 {
4334 if (!context->getExtensions().textureStorage)
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004335 {
Geoff Langb1196682014-07-23 13:47:29 -04004336 context->recordError(gl::Error(GL_INVALID_OPERATION));
4337 return;
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004338 }
Geoff Langbfdea662014-07-23 14:16:32 -04004339
4340 if (context->getClientVersion() < 3 &&
4341 !ValidateES2TexStorageParameters(context, target, levels, internalformat, width, height))
4342 {
4343 return;
4344 }
4345
4346 if (context->getClientVersion() >= 3 &&
4347 !ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
4348 {
4349 return;
4350 }
4351
4352 switch (target)
4353 {
4354 case GL_TEXTURE_2D:
4355 {
4356 gl::Texture2D *texture2d = context->getTexture2D();
Geoff Lang1f8532b2014-09-05 09:46:13 -04004357 gl::Error error = texture2d->storage(levels, internalformat, width, height);
4358 if (error.isError())
4359 {
4360 context->recordError(error);
4361 return;
4362 }
Geoff Langbfdea662014-07-23 14:16:32 -04004363 }
4364 break;
4365
4366 case GL_TEXTURE_CUBE_MAP:
4367 {
4368 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
Geoff Lang1f8532b2014-09-05 09:46:13 -04004369 gl::Error error = textureCube->storage(levels, internalformat, width);
4370 if (error.isError())
4371 {
4372 context->recordError(error);
4373 return;
4374 }
Geoff Langbfdea662014-07-23 14:16:32 -04004375 }
4376 break;
4377
4378 default:
Geoff Langb1196682014-07-23 13:47:29 -04004379 context->recordError(gl::Error(GL_INVALID_ENUM));
4380 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004381 }
daniel@transgaming.com64a0fb22011-11-11 04:10:40 +00004382 }
4383}
4384
Kenneth Russell67ea1902014-10-06 16:44:50 -07004385void GL_APIENTRY glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004386 GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004387{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004388 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004389 "GLsizei width = %d, GLsizei height = %d, GLenum format = 0x%X, GLenum type = 0x%X, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00004390 "const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004391 target, level, xoffset, yoffset, width, height, format, type, pixels);
4392
Geoff Langbfdea662014-07-23 14:16:32 -04004393 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004394 if (context)
4395 {
4396 if (context->getClientVersion() < 3 &&
4397 !ValidateES2TexImageParameters(context, target, level, GL_NONE, false, true,
4398 xoffset, yoffset, width, height, 0, format, type, pixels))
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004399 {
Geoff Langbfdea662014-07-23 14:16:32 -04004400 return;
daniel@transgaming.com00c75962010-03-11 20:36:15 +00004401 }
Geoff Langbfdea662014-07-23 14:16:32 -04004402
4403 if (context->getClientVersion() >= 3 &&
4404 !ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
4405 xoffset, yoffset, 0, width, height, 1, 0, format, type, pixels))
4406 {
4407 return;
4408 }
4409
4410 // Zero sized uploads are valid but no-ops
4411 if (width == 0 || height == 0)
4412 {
4413 return;
4414 }
4415
4416 switch (target)
4417 {
4418 case GL_TEXTURE_2D:
4419 {
4420 gl::Texture2D *texture = context->getTexture2D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004421 gl::Error error = texture->subImage(level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4422 if (error.isError())
4423 {
4424 context->recordError(error);
4425 return;
4426 }
Geoff Langbfdea662014-07-23 14:16:32 -04004427 }
4428 break;
4429
4430 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
4431 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
4432 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
4433 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
4434 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
4435 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
4436 {
4437 gl::TextureCubeMap *texture = context->getTextureCubeMap();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04004438 gl::Error error = texture->subImage(target, level, xoffset, yoffset, width, height, format, type, context->getState().getUnpackState(), pixels);
4439 if (error.isError())
4440 {
4441 context->recordError(error);
4442 return;
4443 }
Geoff Langbfdea662014-07-23 14:16:32 -04004444 }
4445 break;
4446
4447 default:
4448 UNREACHABLE();
4449 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004450 }
4451}
4452
Kenneth Russell67ea1902014-10-06 16:44:50 -07004453void GL_APIENTRY glUniform1f(GLint location, GLfloat x)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004454{
4455 glUniform1fv(location, 1, &x);
4456}
4457
Kenneth Russell67ea1902014-10-06 16:44:50 -07004458void GL_APIENTRY glUniform1fv(GLint location, GLsizei count, const GLfloat* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004459{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004460 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004461
Geoff Langbfdea662014-07-23 14:16:32 -04004462 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004463 if (context)
4464 {
4465 if (!ValidateUniform(context, GL_FLOAT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004466 {
Geoff Langbfdea662014-07-23 14:16:32 -04004467 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004468 }
Geoff Langbfdea662014-07-23 14:16:32 -04004469
4470 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4471 programBinary->setUniform1fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004472 }
4473}
4474
Kenneth Russell67ea1902014-10-06 16:44:50 -07004475void GL_APIENTRY glUniform1i(GLint location, GLint x)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004476{
4477 glUniform1iv(location, 1, &x);
4478}
4479
Kenneth Russell67ea1902014-10-06 16:44:50 -07004480void GL_APIENTRY glUniform1iv(GLint location, GLsizei count, const GLint* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004481{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004482 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004483
Geoff Langbfdea662014-07-23 14:16:32 -04004484 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004485 if (context)
4486 {
4487 if (!ValidateUniform(context, GL_INT, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004488 {
Geoff Langbfdea662014-07-23 14:16:32 -04004489 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004490 }
Geoff Langbfdea662014-07-23 14:16:32 -04004491
4492 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4493 programBinary->setUniform1iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004494 }
4495}
4496
Kenneth Russell67ea1902014-10-06 16:44:50 -07004497void GL_APIENTRY glUniform2f(GLint location, GLfloat x, GLfloat y)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004498{
4499 GLfloat xy[2] = {x, y};
4500
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004501 glUniform2fv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004502}
4503
Kenneth Russell67ea1902014-10-06 16:44:50 -07004504void GL_APIENTRY glUniform2fv(GLint location, GLsizei count, const GLfloat* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004505{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004506 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004507
Geoff Langbfdea662014-07-23 14:16:32 -04004508 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004509 if (context)
4510 {
4511 if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004512 {
Geoff Langbfdea662014-07-23 14:16:32 -04004513 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004514 }
Geoff Langbfdea662014-07-23 14:16:32 -04004515
4516 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4517 programBinary->setUniform2fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004518 }
4519}
4520
Kenneth Russell67ea1902014-10-06 16:44:50 -07004521void GL_APIENTRY glUniform2i(GLint location, GLint x, GLint y)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004522{
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004523 GLint xy[2] = {x, y};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004524
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004525 glUniform2iv(location, 1, xy);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004526}
4527
Kenneth Russell67ea1902014-10-06 16:44:50 -07004528void GL_APIENTRY glUniform2iv(GLint location, GLsizei count, const GLint* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004529{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004530 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004531
Geoff Langbfdea662014-07-23 14:16:32 -04004532 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004533 if (context)
4534 {
4535 if (!ValidateUniform(context, GL_INT_VEC2, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004536 {
Geoff Langbfdea662014-07-23 14:16:32 -04004537 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004538 }
Geoff Langbfdea662014-07-23 14:16:32 -04004539
4540 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4541 programBinary->setUniform2iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004542 }
4543}
4544
Kenneth Russell67ea1902014-10-06 16:44:50 -07004545void GL_APIENTRY glUniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004546{
4547 GLfloat xyz[3] = {x, y, z};
4548
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004549 glUniform3fv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004550}
4551
Kenneth Russell67ea1902014-10-06 16:44:50 -07004552void GL_APIENTRY glUniform3fv(GLint location, GLsizei count, const GLfloat* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004553{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004554 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004555
Geoff Langbfdea662014-07-23 14:16:32 -04004556 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004557 if (context)
4558 {
4559 if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004560 {
Geoff Langbfdea662014-07-23 14:16:32 -04004561 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004562 }
Geoff Langbfdea662014-07-23 14:16:32 -04004563
4564 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4565 programBinary->setUniform3fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004566 }
4567}
4568
Kenneth Russell67ea1902014-10-06 16:44:50 -07004569void GL_APIENTRY glUniform3i(GLint location, GLint x, GLint y, GLint z)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004570{
4571 GLint xyz[3] = {x, y, z};
4572
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004573 glUniform3iv(location, 1, xyz);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004574}
4575
Kenneth Russell67ea1902014-10-06 16:44:50 -07004576void GL_APIENTRY glUniform3iv(GLint location, GLsizei count, const GLint* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004577{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004578 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004579
Geoff Langbfdea662014-07-23 14:16:32 -04004580 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004581 if (context)
4582 {
4583 if (!ValidateUniform(context, GL_INT_VEC3, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004584 {
Geoff Langbfdea662014-07-23 14:16:32 -04004585 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004586 }
Geoff Langbfdea662014-07-23 14:16:32 -04004587
4588 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4589 programBinary->setUniform3iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004590 }
4591}
4592
Kenneth Russell67ea1902014-10-06 16:44:50 -07004593void GL_APIENTRY glUniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004594{
4595 GLfloat xyzw[4] = {x, y, z, w};
4596
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004597 glUniform4fv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004598}
4599
Kenneth Russell67ea1902014-10-06 16:44:50 -07004600void GL_APIENTRY glUniform4fv(GLint location, GLsizei count, const GLfloat* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004601{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004602 EVENT("(GLint location = %d, GLsizei count = %d, const GLfloat* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004603
Geoff Langbfdea662014-07-23 14:16:32 -04004604 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004605 if (context)
4606 {
4607 if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004608 {
Geoff Langbfdea662014-07-23 14:16:32 -04004609 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004610 }
Geoff Langbfdea662014-07-23 14:16:32 -04004611
4612 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4613 programBinary->setUniform4fv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004614 }
4615}
4616
Kenneth Russell67ea1902014-10-06 16:44:50 -07004617void GL_APIENTRY glUniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004618{
4619 GLint xyzw[4] = {x, y, z, w};
4620
Geoff Lang3b3ad1f2014-03-05 14:35:01 -05004621 glUniform4iv(location, 1, xyzw);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004622}
4623
Kenneth Russell67ea1902014-10-06 16:44:50 -07004624void GL_APIENTRY glUniform4iv(GLint location, GLsizei count, const GLint* v)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004625{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004626 EVENT("(GLint location = %d, GLsizei count = %d, const GLint* v = 0x%0.8p)", location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004627
Geoff Langbfdea662014-07-23 14:16:32 -04004628 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004629 if (context)
4630 {
4631 if (!ValidateUniform(context, GL_INT_VEC4, location, count))
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004632 {
Geoff Langbfdea662014-07-23 14:16:32 -04004633 return;
daniel@transgaming.com9a95e2b2010-04-13 03:26:03 +00004634 }
Geoff Langbfdea662014-07-23 14:16:32 -04004635
4636 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4637 programBinary->setUniform4iv(location, count, v);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004638 }
4639}
4640
Kenneth Russell67ea1902014-10-06 16:44:50 -07004641void GL_APIENTRY glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004642{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004643 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004644 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004645
Geoff Langbfdea662014-07-23 14:16:32 -04004646 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004647 if (context)
4648 {
4649 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004650 {
Geoff Langbfdea662014-07-23 14:16:32 -04004651 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004652 }
Geoff Langbfdea662014-07-23 14:16:32 -04004653
4654 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4655 programBinary->setUniformMatrix2fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004656 }
4657}
4658
Kenneth Russell67ea1902014-10-06 16:44:50 -07004659void GL_APIENTRY glUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004660{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004661 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004662 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004663
Geoff Langbfdea662014-07-23 14:16:32 -04004664 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004665 if (context)
4666 {
4667 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004668 {
Geoff Langbfdea662014-07-23 14:16:32 -04004669 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004670 }
Geoff Langbfdea662014-07-23 14:16:32 -04004671
4672 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4673 programBinary->setUniformMatrix3fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004674 }
4675}
4676
Kenneth Russell67ea1902014-10-06 16:44:50 -07004677void GL_APIENTRY glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004678{
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004679 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004680 location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004681
Geoff Langbfdea662014-07-23 14:16:32 -04004682 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004683 if (context)
4684 {
4685 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4, location, count, transpose))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004686 {
Geoff Langbfdea662014-07-23 14:16:32 -04004687 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004688 }
Geoff Langbfdea662014-07-23 14:16:32 -04004689
4690 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
4691 programBinary->setUniformMatrix4fv(location, count, transpose, value);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004692 }
4693}
4694
Kenneth Russell67ea1902014-10-06 16:44:50 -07004695void GL_APIENTRY glUseProgram(GLuint program)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004696{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004697 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004698
Geoff Langbfdea662014-07-23 14:16:32 -04004699 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004700 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004701 {
Geoff Langbfdea662014-07-23 14:16:32 -04004702 gl::Program *programObject = context->getProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004703
Geoff Langbfdea662014-07-23 14:16:32 -04004704 if (!programObject && program != 0)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004705 {
Geoff Langbfdea662014-07-23 14:16:32 -04004706 if (context->getShader(program))
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004707 {
Geoff Langb1196682014-07-23 13:47:29 -04004708 context->recordError(gl::Error(GL_INVALID_OPERATION));
4709 return;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004710 }
Geoff Langbfdea662014-07-23 14:16:32 -04004711 else
4712 {
Geoff Langb1196682014-07-23 13:47:29 -04004713 context->recordError(gl::Error(GL_INVALID_VALUE));
4714 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004715 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004716 }
Geoff Langbfdea662014-07-23 14:16:32 -04004717
4718 if (program != 0 && !programObject->isLinked())
4719 {
Geoff Langb1196682014-07-23 13:47:29 -04004720 context->recordError(gl::Error(GL_INVALID_OPERATION));
4721 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004722 }
4723
4724 context->useProgram(program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004725 }
4726}
4727
Kenneth Russell67ea1902014-10-06 16:44:50 -07004728void GL_APIENTRY glValidateProgram(GLuint program)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004729{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004730 EVENT("(GLuint program = %d)", program);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004731
Geoff Langbfdea662014-07-23 14:16:32 -04004732 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004733 if (context)
4734 {
4735 gl::Program *programObject = context->getProgram(program);
4736
4737 if (!programObject)
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004738 {
Geoff Langbfdea662014-07-23 14:16:32 -04004739 if (context->getShader(program))
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004740 {
Geoff Langb1196682014-07-23 13:47:29 -04004741 context->recordError(gl::Error(GL_INVALID_OPERATION));
4742 return;
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004743 }
Geoff Langbfdea662014-07-23 14:16:32 -04004744 else
4745 {
Geoff Langb1196682014-07-23 13:47:29 -04004746 context->recordError(gl::Error(GL_INVALID_VALUE));
4747 return;
Geoff Langbfdea662014-07-23 14:16:32 -04004748 }
daniel@transgaming.com86a7a132010-04-29 03:32:32 +00004749 }
Geoff Langbfdea662014-07-23 14:16:32 -04004750
Brandon Jones43a53e22014-08-28 16:23:22 -07004751 programObject->validate(context->getCaps());
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004752 }
4753}
4754
Kenneth Russell67ea1902014-10-06 16:44:50 -07004755void GL_APIENTRY glVertexAttrib1f(GLuint index, GLfloat x)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004756{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004757 EVENT("(GLuint index = %d, GLfloat x = %f)", index, x);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004758
Geoff Langbfdea662014-07-23 14:16:32 -04004759 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004760 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004761 {
Geoff Langb1196682014-07-23 13:47:29 -04004762 if (index >= gl::MAX_VERTEX_ATTRIBS)
4763 {
4764 context->recordError(gl::Error(GL_INVALID_VALUE));
4765 return;
4766 }
4767
Geoff Langbfdea662014-07-23 14:16:32 -04004768 GLfloat vals[4] = { x, 0, 0, 1 };
4769 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004770 }
4771}
4772
Kenneth Russell67ea1902014-10-06 16:44:50 -07004773void GL_APIENTRY glVertexAttrib1fv(GLuint index, const GLfloat* values)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004774{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004775 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004776
Geoff Langbfdea662014-07-23 14:16:32 -04004777 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004778 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004779 {
Geoff Langb1196682014-07-23 13:47:29 -04004780 if (index >= gl::MAX_VERTEX_ATTRIBS)
4781 {
4782 context->recordError(gl::Error(GL_INVALID_VALUE));
4783 return;
4784 }
4785
Geoff Langbfdea662014-07-23 14:16:32 -04004786 GLfloat vals[4] = { values[0], 0, 0, 1 };
4787 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004788 }
4789}
4790
Kenneth Russell67ea1902014-10-06 16:44:50 -07004791void GL_APIENTRY glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004792{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004793 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f)", index, x, y);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004794
Geoff Langbfdea662014-07-23 14:16:32 -04004795 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004796 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004797 {
Geoff Langb1196682014-07-23 13:47:29 -04004798 if (index >= gl::MAX_VERTEX_ATTRIBS)
4799 {
4800 context->recordError(gl::Error(GL_INVALID_VALUE));
4801 return;
4802 }
4803
Geoff Langbfdea662014-07-23 14:16:32 -04004804 GLfloat vals[4] = { x, y, 0, 1 };
4805 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004806 }
4807}
4808
Kenneth Russell67ea1902014-10-06 16:44:50 -07004809void GL_APIENTRY glVertexAttrib2fv(GLuint index, const GLfloat* values)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004810{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004811 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004812
Geoff Langbfdea662014-07-23 14:16:32 -04004813 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004814 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004815 {
Geoff Langb1196682014-07-23 13:47:29 -04004816 if (index >= gl::MAX_VERTEX_ATTRIBS)
4817 {
4818 context->recordError(gl::Error(GL_INVALID_VALUE));
4819 return;
4820 }
4821
Geoff Langbfdea662014-07-23 14:16:32 -04004822 GLfloat vals[4] = { values[0], values[1], 0, 1 };
4823 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004824 }
4825}
4826
Kenneth Russell67ea1902014-10-06 16:44:50 -07004827void GL_APIENTRY glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004828{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004829 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f, GLfloat z = %f)", index, x, y, z);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004830
Geoff Langbfdea662014-07-23 14:16:32 -04004831 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004832 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004833 {
Geoff Langb1196682014-07-23 13:47:29 -04004834 if (index >= gl::MAX_VERTEX_ATTRIBS)
4835 {
4836 context->recordError(gl::Error(GL_INVALID_VALUE));
4837 return;
4838 }
4839
Geoff Langbfdea662014-07-23 14:16:32 -04004840 GLfloat vals[4] = { x, y, z, 1 };
4841 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004842 }
4843}
4844
Kenneth Russell67ea1902014-10-06 16:44:50 -07004845void GL_APIENTRY glVertexAttrib3fv(GLuint index, const GLfloat* values)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004846{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004847 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004848
Geoff Langbfdea662014-07-23 14:16:32 -04004849 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004850 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004851 {
Geoff Langb1196682014-07-23 13:47:29 -04004852 if (index >= gl::MAX_VERTEX_ATTRIBS)
4853 {
4854 context->recordError(gl::Error(GL_INVALID_VALUE));
4855 return;
4856 }
4857
Geoff Langbfdea662014-07-23 14:16:32 -04004858 GLfloat vals[4] = { values[0], values[1], values[2], 1 };
4859 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004860 }
4861}
4862
Kenneth Russell67ea1902014-10-06 16:44:50 -07004863void GL_APIENTRY glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004864{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004865 EVENT("(GLuint index = %d, GLfloat x = %f, GLfloat y = %f, GLfloat z = %f, GLfloat w = %f)", index, x, y, z, w);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004866
Geoff Langbfdea662014-07-23 14:16:32 -04004867 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004868 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004869 {
Geoff Langb1196682014-07-23 13:47:29 -04004870 if (index >= gl::MAX_VERTEX_ATTRIBS)
4871 {
4872 context->recordError(gl::Error(GL_INVALID_VALUE));
4873 return;
4874 }
4875
Geoff Langbfdea662014-07-23 14:16:32 -04004876 GLfloat vals[4] = { x, y, z, w };
4877 context->getState().setVertexAttribf(index, vals);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004878 }
4879}
4880
Kenneth Russell67ea1902014-10-06 16:44:50 -07004881void GL_APIENTRY glVertexAttrib4fv(GLuint index, const GLfloat* values)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004882{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004883 EVENT("(GLuint index = %d, const GLfloat* values = 0x%0.8p)", index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004884
Geoff Langbfdea662014-07-23 14:16:32 -04004885 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004886 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004887 {
Geoff Langb1196682014-07-23 13:47:29 -04004888 if (index >= gl::MAX_VERTEX_ATTRIBS)
4889 {
4890 context->recordError(gl::Error(GL_INVALID_VALUE));
4891 return;
4892 }
4893
Geoff Langbfdea662014-07-23 14:16:32 -04004894 context->getState().setVertexAttribf(index, values);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004895 }
4896}
4897
Kenneth Russell67ea1902014-10-06 16:44:50 -07004898void GL_APIENTRY glVertexAttribDivisorANGLE(GLuint index, GLuint divisor)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004899{
4900 EVENT("(GLuint index = %d, GLuint divisor = %d)", index, divisor);
4901
Geoff Langbfdea662014-07-23 14:16:32 -04004902 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004903 if (context)
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004904 {
Geoff Langb1196682014-07-23 13:47:29 -04004905 if (index >= gl::MAX_VERTEX_ATTRIBS)
4906 {
4907 context->recordError(gl::Error(GL_INVALID_VALUE));
4908 return;
4909 }
4910
Geoff Langbfdea662014-07-23 14:16:32 -04004911 context->setVertexAttribDivisor(index, divisor);
daniel@transgaming.comd2820bf2012-01-27 15:38:48 +00004912 }
4913}
4914
Kenneth Russell67ea1902014-10-06 16:44:50 -07004915void GL_APIENTRY glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004916{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004917 EVENT("(GLuint index = %d, GLint size = %d, GLenum type = 0x%X, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00004918 "GLboolean normalized = %u, GLsizei stride = %d, const GLvoid* ptr = 0x%0.8p)",
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00004919 index, size, type, normalized, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004920
Geoff Langbfdea662014-07-23 14:16:32 -04004921 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004922 if (context)
4923 {
Geoff Langb1196682014-07-23 13:47:29 -04004924 if (index >= gl::MAX_VERTEX_ATTRIBS)
4925 {
4926 context->recordError(gl::Error(GL_INVALID_VALUE));
4927 return;
4928 }
4929
4930 if (size < 1 || size > 4)
4931 {
4932 context->recordError(gl::Error(GL_INVALID_VALUE));
4933 return;
4934 }
4935
4936 switch (type)
4937 {
4938 case GL_BYTE:
4939 case GL_UNSIGNED_BYTE:
4940 case GL_SHORT:
4941 case GL_UNSIGNED_SHORT:
4942 case GL_FIXED:
4943 case GL_FLOAT:
4944 break;
4945
4946 case GL_HALF_FLOAT:
4947 case GL_INT:
4948 case GL_UNSIGNED_INT:
4949 case GL_INT_2_10_10_10_REV:
4950 case GL_UNSIGNED_INT_2_10_10_10_REV:
4951 if (context->getClientVersion() < 3)
4952 {
4953 context->recordError(gl::Error(GL_INVALID_ENUM));
4954 return;
4955 }
4956 break;
4957
4958 default:
4959 context->recordError(gl::Error(GL_INVALID_ENUM));
4960 return;
4961 }
4962
4963 if (stride < 0)
4964 {
4965 context->recordError(gl::Error(GL_INVALID_VALUE));
4966 return;
4967 }
4968
4969 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
4970 {
4971 context->recordError(gl::Error(GL_INVALID_OPERATION));
4972 return;
4973 }
4974
Geoff Langbfdea662014-07-23 14:16:32 -04004975 // [OpenGL ES 3.0.2] Section 2.8 page 24:
4976 // An INVALID_OPERATION error is generated when a non-zero vertex array object
4977 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
4978 // and the pointer argument is not NULL.
4979 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && ptr != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004980 {
Geoff Langb1196682014-07-23 13:47:29 -04004981 context->recordError(gl::Error(GL_INVALID_OPERATION));
4982 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00004983 }
4984
Geoff Langbfdea662014-07-23 14:16:32 -04004985 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type,
4986 normalized == GL_TRUE, false, stride, ptr);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004987 }
4988}
4989
Kenneth Russell67ea1902014-10-06 16:44:50 -07004990void GL_APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004991{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00004992 EVENT("(GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)", x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004993
Geoff Langbfdea662014-07-23 14:16:32 -04004994 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04004995 if (context)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00004996 {
Geoff Langb1196682014-07-23 13:47:29 -04004997 if (width < 0 || height < 0)
4998 {
4999 context->recordError(gl::Error(GL_INVALID_VALUE));
5000 return;
5001 }
5002
Geoff Langbfdea662014-07-23 14:16:32 -04005003 context->getState().setViewportParams(x, y, width, height);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00005004 }
5005}
5006
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005007// OpenGL ES 3.0 functions
5008
Kenneth Russell67ea1902014-10-06 16:44:50 -07005009void GL_APIENTRY glReadBuffer(GLenum mode)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005010{
5011 EVENT("(GLenum mode = 0x%X)", mode);
5012
Geoff Langbfdea662014-07-23 14:16:32 -04005013 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005014 if (context)
5015 {
5016 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005017 {
Geoff Langb1196682014-07-23 13:47:29 -04005018 context->recordError(gl::Error(GL_INVALID_OPERATION));
5019 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005020 }
Geoff Langbfdea662014-07-23 14:16:32 -04005021
5022 // glReadBuffer
5023 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005024 }
5025}
5026
Kenneth Russell67ea1902014-10-06 16:44:50 -07005027void GL_APIENTRY glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005028{
5029 EVENT("(GLenum mode = 0x%X, GLuint start = %u, GLuint end = %u, GLsizei count = %d, GLenum type = 0x%X, "
5030 "const GLvoid* indices = 0x%0.8p)", mode, start, end, count, type, indices);
5031
Geoff Langbfdea662014-07-23 14:16:32 -04005032 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005033 if (context)
5034 {
5035 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005036 {
Geoff Langb1196682014-07-23 13:47:29 -04005037 context->recordError(gl::Error(GL_INVALID_OPERATION));
5038 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005039 }
Geoff Langbfdea662014-07-23 14:16:32 -04005040
5041 // glDrawRangeElements
5042 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005043 }
5044}
5045
Kenneth Russell67ea1902014-10-06 16:44:50 -07005046void GL_APIENTRY glTexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005047{
5048 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint internalformat = %d, GLsizei width = %d, "
5049 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLenum format = 0x%X, "
5050 "GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5051 target, level, internalformat, width, height, depth, border, format, type, pixels);
5052
Geoff Langbfdea662014-07-23 14:16:32 -04005053 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005054 if (context)
5055 {
5056 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005057 {
Geoff Langb1196682014-07-23 13:47:29 -04005058 context->recordError(gl::Error(GL_INVALID_OPERATION));
5059 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005060 }
Geoff Langbfdea662014-07-23 14:16:32 -04005061
5062 // validateES3TexImageFormat sets the error code if there is an error
5063 if (!ValidateES3TexImageParameters(context, target, level, internalformat, false, false,
5064 0, 0, 0, width, height, depth, border, format, type, pixels))
5065 {
5066 return;
5067 }
5068
5069 switch(target)
5070 {
5071 case GL_TEXTURE_3D:
5072 {
5073 gl::Texture3D *texture = context->getTexture3D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005074 gl::Error error = texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5075 if (error.isError())
5076 {
5077 context->recordError(error);
5078 return;
5079 }
Geoff Langbfdea662014-07-23 14:16:32 -04005080 }
5081 break;
5082
5083 case GL_TEXTURE_2D_ARRAY:
5084 {
5085 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005086 gl::Error error = texture->setImage(level, width, height, depth, internalformat, format, type, context->getState().getUnpackState(), pixels);
5087 if (error.isError())
5088 {
5089 context->recordError(error);
5090 return;
5091 }
Geoff Langbfdea662014-07-23 14:16:32 -04005092 }
5093 break;
5094
5095 default:
Geoff Langb1196682014-07-23 13:47:29 -04005096 context->recordError(gl::Error(GL_INVALID_ENUM));
5097 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005098 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005099 }
5100}
5101
Kenneth Russell67ea1902014-10-06 16:44:50 -07005102void GL_APIENTRY glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005103{
5104 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5105 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5106 "GLenum format = 0x%X, GLenum type = 0x%X, const GLvoid* pixels = 0x%0.8p)",
5107 target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
5108
Geoff Langbfdea662014-07-23 14:16:32 -04005109 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005110 if (context)
5111 {
5112 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005113 {
Geoff Langb1196682014-07-23 13:47:29 -04005114 context->recordError(gl::Error(GL_INVALID_OPERATION));
5115 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005116 }
Geoff Langbfdea662014-07-23 14:16:32 -04005117
5118 // validateES3TexImageFormat sets the error code if there is an error
5119 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, false, true,
5120 xoffset, yoffset, zoffset, width, height, depth, 0,
5121 format, type, pixels))
5122 {
5123 return;
5124 }
5125
5126 // Zero sized uploads are valid but no-ops
5127 if (width == 0 || height == 0 || depth == 0)
5128 {
5129 return;
5130 }
5131
5132 switch(target)
5133 {
5134 case GL_TEXTURE_3D:
5135 {
5136 gl::Texture3D *texture = context->getTexture3D();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005137 gl::Error error = texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5138 if (error.isError())
5139 {
5140 context->recordError(error);
5141 return;
5142 }
Geoff Langbfdea662014-07-23 14:16:32 -04005143 }
5144 break;
5145
5146 case GL_TEXTURE_2D_ARRAY:
5147 {
5148 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Lang1ba6b8d2014-08-28 10:57:31 -04005149 gl::Error error = texture->subImage(level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getState().getUnpackState(), pixels);
5150 if (error.isError())
5151 {
5152 context->recordError(error);
5153 return;
5154 }
Geoff Langbfdea662014-07-23 14:16:32 -04005155 }
5156 break;
5157
5158 default:
Geoff Langb1196682014-07-23 13:47:29 -04005159 context->recordError(gl::Error(GL_INVALID_ENUM));
5160 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005161 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005162 }
5163}
5164
Kenneth Russell67ea1902014-10-06 16:44:50 -07005165void GL_APIENTRY glCopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005166{
5167 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5168 "GLint zoffset = %d, GLint x = %d, GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
5169 target, level, xoffset, yoffset, zoffset, x, y, width, height);
5170
Geoff Langbfdea662014-07-23 14:16:32 -04005171 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005172 if (context)
5173 {
5174 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005175 {
Geoff Langb1196682014-07-23 13:47:29 -04005176 context->recordError(gl::Error(GL_INVALID_OPERATION));
5177 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005178 }
Geoff Langbfdea662014-07-23 14:16:32 -04005179
5180 if (!ValidateES3CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, yoffset, zoffset,
5181 x, y, width, height, 0))
5182 {
5183 return;
5184 }
5185
5186 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
5187 gl::Texture *texture = NULL;
5188 switch (target)
5189 {
5190 case GL_TEXTURE_3D:
5191 texture = context->getTexture3D();
5192 break;
5193
5194 case GL_TEXTURE_2D_ARRAY:
5195 texture = context->getTexture2DArray();
5196 break;
5197
5198 default:
Geoff Langb1196682014-07-23 13:47:29 -04005199 context->recordError(gl::Error(GL_INVALID_ENUM));
5200 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005201 }
5202
Geoff Langef7b0162014-09-04 13:29:23 -04005203 gl::Error error = texture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, framebuffer);
5204 if (error.isError())
5205 {
5206 context->recordError(error);
5207 return;
5208 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005209 }
5210}
5211
Kenneth Russell67ea1902014-10-06 16:44:50 -07005212void GL_APIENTRY glCompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005213{
Geoff Langeef52cc2013-10-16 15:07:39 -04005214 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005215 "GLsizei height = %d, GLsizei depth = %d, GLint border = %d, GLsizei imageSize = %d, "
5216 "const GLvoid* data = 0x%0.8p)",
5217 target, level, internalformat, width, height, depth, border, imageSize, data);
5218
Geoff Langbfdea662014-07-23 14:16:32 -04005219 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005220 if (context)
5221 {
5222 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005223 {
Geoff Langb1196682014-07-23 13:47:29 -04005224 context->recordError(gl::Error(GL_INVALID_OPERATION));
5225 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005226 }
Geoff Langbfdea662014-07-23 14:16:32 -04005227
Geoff Lang5d601382014-07-22 15:14:06 -04005228 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
5229 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005230 {
Geoff Langb1196682014-07-23 13:47:29 -04005231 context->recordError(gl::Error(GL_INVALID_VALUE));
5232 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005233 }
5234
5235 // validateES3TexImageFormat sets the error code if there is an error
5236 if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false,
5237 0, 0, 0, width, height, depth, border, GL_NONE, GL_NONE, data))
5238 {
5239 return;
5240 }
5241
5242 switch(target)
5243 {
5244 case GL_TEXTURE_3D:
5245 {
5246 gl::Texture3D *texture = context->getTexture3D();
Jamie Madillc751d1e2014-10-21 17:46:29 -04005247 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, context->getState().getUnpackState(), data);
Geoff Langb5348332014-09-02 13:16:34 -04005248 if (error.isError())
5249 {
5250 context->recordError(error);
5251 return;
5252 }
Geoff Langbfdea662014-07-23 14:16:32 -04005253 }
5254 break;
5255
5256 case GL_TEXTURE_2D_ARRAY:
5257 {
5258 gl::Texture2DArray *texture = context->getTexture2DArray();
Jamie Madillc751d1e2014-10-21 17:46:29 -04005259 gl::Error error = texture->setCompressedImage(level, internalformat, width, height, depth, imageSize, context->getState().getUnpackState(), data);
Geoff Langb5348332014-09-02 13:16:34 -04005260 if (error.isError())
5261 {
5262 context->recordError(error);
5263 return;
5264 }
Geoff Langbfdea662014-07-23 14:16:32 -04005265 }
5266 break;
5267
5268 default:
Geoff Langb1196682014-07-23 13:47:29 -04005269 context->recordError(gl::Error(GL_INVALID_ENUM));
5270 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005271 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005272 }
5273}
5274
Kenneth Russell67ea1902014-10-06 16:44:50 -07005275void GL_APIENTRY glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005276{
5277 EVENT("(GLenum target = 0x%X, GLint level = %d, GLint xoffset = %d, GLint yoffset = %d, "
5278 "GLint zoffset = %d, GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, "
5279 "GLenum format = 0x%X, GLsizei imageSize = %d, const GLvoid* data = 0x%0.8p)",
5280 target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data);
5281
Geoff Langbfdea662014-07-23 14:16:32 -04005282 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005283 if (context)
5284 {
5285 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005286 {
Geoff Langb1196682014-07-23 13:47:29 -04005287 context->recordError(gl::Error(GL_INVALID_OPERATION));
5288 return;
shannon.woods%transgaming.com@gtempaccount.com875994b2013-04-13 03:45:17 +00005289 }
Geoff Langbfdea662014-07-23 14:16:32 -04005290
Geoff Lang5d601382014-07-22 15:14:06 -04005291 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format);
5292 if (imageSize < 0 || static_cast<GLuint>(imageSize) != formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005293 {
Geoff Langb1196682014-07-23 13:47:29 -04005294 context->recordError(gl::Error(GL_INVALID_VALUE));
5295 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005296 }
5297
5298 if (!data)
5299 {
Geoff Langb1196682014-07-23 13:47:29 -04005300 context->recordError(gl::Error(GL_INVALID_VALUE));
5301 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005302 }
5303
5304 // validateES3TexImageFormat sets the error code if there is an error
5305 if (!ValidateES3TexImageParameters(context, target, level, GL_NONE, true, true,
5306 0, 0, 0, width, height, depth, 0, GL_NONE, GL_NONE, data))
5307 {
5308 return;
5309 }
5310
5311 // Zero sized uploads are valid but no-ops
5312 if (width == 0 || height == 0)
5313 {
5314 return;
5315 }
5316
5317 switch(target)
5318 {
5319 case GL_TEXTURE_3D:
5320 {
5321 gl::Texture3D *texture = context->getTexture3D();
Geoff Langb5348332014-09-02 13:16:34 -04005322 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
Jamie Madillc751d1e2014-10-21 17:46:29 -04005323 format, imageSize, context->getState().getUnpackState(), data);
Geoff Langb5348332014-09-02 13:16:34 -04005324 if (error.isError())
5325 {
5326 context->recordError(error);
5327 return;
5328 }
Geoff Langbfdea662014-07-23 14:16:32 -04005329 }
5330 break;
5331
5332 case GL_TEXTURE_2D_ARRAY:
5333 {
5334 gl::Texture2DArray *texture = context->getTexture2DArray();
Geoff Langb5348332014-09-02 13:16:34 -04005335 gl::Error error = texture->subImageCompressed(level, xoffset, yoffset, zoffset, width, height, depth,
Jamie Madillc751d1e2014-10-21 17:46:29 -04005336 format, imageSize, context->getState().getUnpackState(), data);
Geoff Langb5348332014-09-02 13:16:34 -04005337 if (error.isError())
5338 {
5339 context->recordError(error);
5340 return;
5341 }
Geoff Langbfdea662014-07-23 14:16:32 -04005342 }
5343 break;
5344
Geoff Langb1196682014-07-23 13:47:29 -04005345 default:
5346 context->recordError(gl::Error(GL_INVALID_ENUM));
5347 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005348 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005349 }
5350}
5351
Kenneth Russell67ea1902014-10-06 16:44:50 -07005352void GL_APIENTRY glGenQueries(GLsizei n, GLuint* ids)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005353{
5354 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5355
Geoff Langbfdea662014-07-23 14:16:32 -04005356 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005357 if (context)
5358 {
5359 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005360 {
Geoff Langb1196682014-07-23 13:47:29 -04005361 context->recordError(gl::Error(GL_INVALID_OPERATION));
5362 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005363 }
Geoff Langbfdea662014-07-23 14:16:32 -04005364
5365 if (n < 0)
5366 {
Geoff Langb1196682014-07-23 13:47:29 -04005367 context->recordError(gl::Error(GL_INVALID_VALUE));
5368 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005369 }
5370
5371 for (GLsizei i = 0; i < n; i++)
5372 {
5373 ids[i] = context->createQuery();
5374 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005375 }
5376}
5377
Kenneth Russell67ea1902014-10-06 16:44:50 -07005378void GL_APIENTRY glDeleteQueries(GLsizei n, const GLuint* ids)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005379{
5380 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
5381
Geoff Langbfdea662014-07-23 14:16:32 -04005382 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005383 if (context)
5384 {
5385 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005386 {
Geoff Langb1196682014-07-23 13:47:29 -04005387 context->recordError(gl::Error(GL_INVALID_OPERATION));
5388 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005389 }
Geoff Langbfdea662014-07-23 14:16:32 -04005390
5391 if (n < 0)
5392 {
Geoff Langb1196682014-07-23 13:47:29 -04005393 context->recordError(gl::Error(GL_INVALID_VALUE));
5394 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005395 }
5396
5397 for (GLsizei i = 0; i < n; i++)
5398 {
5399 context->deleteQuery(ids[i]);
5400 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005401 }
5402}
5403
Kenneth Russell67ea1902014-10-06 16:44:50 -07005404GLboolean GL_APIENTRY glIsQuery(GLuint id)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005405{
5406 EVENT("(GLuint id = %u)", id);
5407
Geoff Langbfdea662014-07-23 14:16:32 -04005408 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005409 if (context)
5410 {
5411 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005412 {
Geoff Langb1196682014-07-23 13:47:29 -04005413 context->recordError(gl::Error(GL_INVALID_OPERATION));
5414 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005415 }
Geoff Langbfdea662014-07-23 14:16:32 -04005416
5417 return (context->getQuery(id, false, GL_NONE) != NULL) ? GL_TRUE : GL_FALSE;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005418 }
5419
5420 return GL_FALSE;
5421}
5422
Kenneth Russell67ea1902014-10-06 16:44:50 -07005423void GL_APIENTRY glBeginQuery(GLenum target, GLuint id)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005424{
5425 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
5426
Geoff Langbfdea662014-07-23 14:16:32 -04005427 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005428 if (context)
5429 {
5430 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005431 {
Geoff Langb1196682014-07-23 13:47:29 -04005432 context->recordError(gl::Error(GL_INVALID_OPERATION));
5433 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005434 }
Geoff Langbfdea662014-07-23 14:16:32 -04005435
5436 if (!ValidateBeginQuery(context, target, id))
5437 {
5438 return;
5439 }
Geoff Lang5aad9672014-09-08 11:10:42 -04005440
5441 gl::Error error = context->beginQuery(target, id);
5442 if (error.isError())
5443 {
5444 context->recordError(error);
5445 return;
5446 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005447 }
5448}
5449
Kenneth Russell67ea1902014-10-06 16:44:50 -07005450void GL_APIENTRY glEndQuery(GLenum target)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005451{
5452 EVENT("(GLenum target = 0x%X)", target);
5453
Geoff Langbfdea662014-07-23 14:16:32 -04005454 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005455 if (context)
5456 {
5457 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005458 {
Geoff Langb1196682014-07-23 13:47:29 -04005459 context->recordError(gl::Error(GL_INVALID_OPERATION));
5460 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005461 }
Geoff Langbfdea662014-07-23 14:16:32 -04005462
5463 if (!ValidateEndQuery(context, target))
5464 {
5465 return;
5466 }
5467
Geoff Lang5aad9672014-09-08 11:10:42 -04005468 gl::Error error = context->endQuery(target);
5469 if (error.isError())
5470 {
5471 context->recordError(error);
5472 return;
5473 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005474 }
5475}
5476
Kenneth Russell67ea1902014-10-06 16:44:50 -07005477void GL_APIENTRY glGetQueryiv(GLenum target, GLenum pname, GLint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005478{
5479 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", target, pname, params);
5480
Geoff Langbfdea662014-07-23 14:16:32 -04005481 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005482 if (context)
5483 {
5484 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005485 {
Geoff Langb1196682014-07-23 13:47:29 -04005486 context->recordError(gl::Error(GL_INVALID_OPERATION));
5487 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005488 }
Geoff Langbfdea662014-07-23 14:16:32 -04005489
5490 if (!ValidQueryType(context, target))
5491 {
Geoff Langb1196682014-07-23 13:47:29 -04005492 context->recordError(gl::Error(GL_INVALID_ENUM));
5493 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005494 }
5495
5496 switch (pname)
5497 {
5498 case GL_CURRENT_QUERY:
5499 params[0] = static_cast<GLint>(context->getState().getActiveQueryId(target));
5500 break;
5501
5502 default:
Geoff Langb1196682014-07-23 13:47:29 -04005503 context->recordError(gl::Error(GL_INVALID_ENUM));
5504 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005505 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005506 }
5507}
5508
Kenneth Russell67ea1902014-10-06 16:44:50 -07005509void GL_APIENTRY glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005510{
5511 EVENT("(GLuint id = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", id, pname, params);
5512
Geoff Langbfdea662014-07-23 14:16:32 -04005513 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005514 if (context)
5515 {
5516 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005517 {
Geoff Langb1196682014-07-23 13:47:29 -04005518 context->recordError(gl::Error(GL_INVALID_OPERATION));
5519 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005520 }
Geoff Langbfdea662014-07-23 14:16:32 -04005521
5522 gl::Query *queryObject = context->getQuery(id, false, GL_NONE);
5523
5524 if (!queryObject)
5525 {
Geoff Langb1196682014-07-23 13:47:29 -04005526 context->recordError(gl::Error(GL_INVALID_OPERATION));
5527 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005528 }
5529
5530 if (context->getState().getActiveQueryId(queryObject->getType()) == id)
5531 {
Geoff Langb1196682014-07-23 13:47:29 -04005532 context->recordError(gl::Error(GL_INVALID_OPERATION));
5533 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005534 }
5535
5536 switch(pname)
5537 {
Geoff Lang5aad9672014-09-08 11:10:42 -04005538 case GL_QUERY_RESULT_EXT:
5539 {
5540 gl::Error error = queryObject->getResult(params);
5541 if (error.isError())
5542 {
5543 context->recordError(error);
5544 return;
5545 }
5546 }
Geoff Langbfdea662014-07-23 14:16:32 -04005547 break;
Geoff Langb1196682014-07-23 13:47:29 -04005548
Geoff Lang5aad9672014-09-08 11:10:42 -04005549 case GL_QUERY_RESULT_AVAILABLE_EXT:
5550 {
5551 gl::Error error = queryObject->isResultAvailable(params);
5552 if (error.isError())
5553 {
5554 context->recordError(error);
5555 return;
5556 }
5557 }
Geoff Langbfdea662014-07-23 14:16:32 -04005558 break;
Geoff Langb1196682014-07-23 13:47:29 -04005559
Geoff Langbfdea662014-07-23 14:16:32 -04005560 default:
Geoff Langb1196682014-07-23 13:47:29 -04005561 context->recordError(gl::Error(GL_INVALID_ENUM));
5562 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005563 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005564 }
5565}
5566
Kenneth Russell67ea1902014-10-06 16:44:50 -07005567GLboolean GL_APIENTRY glUnmapBuffer(GLenum target)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005568{
5569 EVENT("(GLenum target = 0x%X)", target);
5570
Geoff Langbfdea662014-07-23 14:16:32 -04005571 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005572 if (context)
5573 {
5574 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005575 {
Geoff Langb1196682014-07-23 13:47:29 -04005576 context->recordError(gl::Error(GL_INVALID_OPERATION));
5577 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005578 }
Geoff Langbfdea662014-07-23 14:16:32 -04005579
5580 return glUnmapBufferOES(target);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005581 }
5582
5583 return GL_FALSE;
5584}
5585
Kenneth Russell67ea1902014-10-06 16:44:50 -07005586void GL_APIENTRY glGetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005587{
5588 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
5589
Geoff Langbfdea662014-07-23 14:16:32 -04005590 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005591 if (context)
5592 {
5593 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005594 {
Geoff Langb1196682014-07-23 13:47:29 -04005595 context->recordError(gl::Error(GL_INVALID_OPERATION));
5596 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005597 }
Geoff Langbfdea662014-07-23 14:16:32 -04005598
5599 glGetBufferPointervOES(target, pname, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005600 }
5601}
5602
Kenneth Russell67ea1902014-10-06 16:44:50 -07005603void GL_APIENTRY glDrawBuffers(GLsizei n, const GLenum* bufs)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005604{
Geoff Langbfdea662014-07-23 14:16:32 -04005605 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005606 if (context)
5607 {
5608 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005609 {
Geoff Langb1196682014-07-23 13:47:29 -04005610 context->recordError(gl::Error(GL_INVALID_OPERATION));
5611 return;
shannon.woods%transgaming.com@gtempaccount.com7948c5f2013-04-13 03:38:58 +00005612 }
Geoff Langbfdea662014-07-23 14:16:32 -04005613
5614 glDrawBuffersEXT(n, bufs);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005615 }
5616}
5617
Kenneth Russell67ea1902014-10-06 16:44:50 -07005618void GL_APIENTRY glUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005619{
5620 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5621 location, count, transpose, value);
5622
Geoff Langbfdea662014-07-23 14:16:32 -04005623 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005624 if (context)
5625 {
5626 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005627 {
Geoff Langbfdea662014-07-23 14:16:32 -04005628 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005629 }
Geoff Langbfdea662014-07-23 14:16:32 -04005630
5631 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5632 programBinary->setUniformMatrix2x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005633 }
5634}
5635
Kenneth Russell67ea1902014-10-06 16:44:50 -07005636void GL_APIENTRY glUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005637{
5638 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5639 location, count, transpose, value);
5640
Geoff Langbfdea662014-07-23 14:16:32 -04005641 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005642 if (context)
5643 {
5644 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005645 {
Geoff Langbfdea662014-07-23 14:16:32 -04005646 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005647 }
Geoff Langbfdea662014-07-23 14:16:32 -04005648
5649 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5650 programBinary->setUniformMatrix3x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005651 }
5652}
5653
Kenneth Russell67ea1902014-10-06 16:44:50 -07005654void GL_APIENTRY glUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005655{
5656 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5657 location, count, transpose, value);
5658
Geoff Langbfdea662014-07-23 14:16:32 -04005659 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005660 if (context)
5661 {
5662 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT2x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005663 {
Geoff Langbfdea662014-07-23 14:16:32 -04005664 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005665 }
Geoff Langbfdea662014-07-23 14:16:32 -04005666
5667 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5668 programBinary->setUniformMatrix2x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005669 }
5670}
5671
Kenneth Russell67ea1902014-10-06 16:44:50 -07005672void GL_APIENTRY glUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005673{
5674 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5675 location, count, transpose, value);
5676
Geoff Langbfdea662014-07-23 14:16:32 -04005677 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005678 if (context)
5679 {
5680 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x2, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005681 {
Geoff Langbfdea662014-07-23 14:16:32 -04005682 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005683 }
Geoff Langbfdea662014-07-23 14:16:32 -04005684
5685 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5686 programBinary->setUniformMatrix4x2fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005687 }
5688}
5689
Kenneth Russell67ea1902014-10-06 16:44:50 -07005690void GL_APIENTRY glUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005691{
5692 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5693 location, count, transpose, value);
5694
Geoff Langbfdea662014-07-23 14:16:32 -04005695 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005696 if (context)
5697 {
5698 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT3x4, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005699 {
Geoff Langbfdea662014-07-23 14:16:32 -04005700 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005701 }
Geoff Langbfdea662014-07-23 14:16:32 -04005702
5703 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5704 programBinary->setUniformMatrix3x4fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005705 }
5706}
5707
Kenneth Russell67ea1902014-10-06 16:44:50 -07005708void GL_APIENTRY glUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005709{
5710 EVENT("(GLint location = %d, GLsizei count = %d, GLboolean transpose = %u, const GLfloat* value = 0x%0.8p)",
5711 location, count, transpose, value);
5712
Geoff Langbfdea662014-07-23 14:16:32 -04005713 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005714 if (context)
5715 {
5716 if (!ValidateUniformMatrix(context, GL_FLOAT_MAT4x3, location, count, transpose))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005717 {
Geoff Langbfdea662014-07-23 14:16:32 -04005718 return;
shannon.woods%transgaming.com@gtempaccount.comf1306162013-04-13 03:40:04 +00005719 }
Geoff Langbfdea662014-07-23 14:16:32 -04005720
5721 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
5722 programBinary->setUniformMatrix4x3fv(location, count, transpose, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005723 }
5724}
5725
Kenneth Russell67ea1902014-10-06 16:44:50 -07005726void GL_APIENTRY glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005727{
5728 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, GLint dstX0 = %d, "
5729 "GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
5730 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
5731
Geoff Langbfdea662014-07-23 14:16:32 -04005732 gl::Context *context = gl::getNonLostContext();
5733 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005734 {
Geoff Langbfdea662014-07-23 14:16:32 -04005735 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005736 {
Geoff Langb1196682014-07-23 13:47:29 -04005737 context->recordError(gl::Error(GL_INVALID_OPERATION));
5738 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005739 }
Geoff Langbfdea662014-07-23 14:16:32 -04005740
5741 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
5742 dstX0, dstY0, dstX1, dstY1, mask, filter,
5743 false))
5744 {
5745 return;
5746 }
5747
Geoff Lang64839152014-08-26 16:23:25 -04005748 gl::Error error = context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
5749 mask, filter);
5750 if (error.isError())
5751 {
5752 context->recordError(error);
5753 return;
5754 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005755 }
5756}
5757
Kenneth Russell67ea1902014-10-06 16:44:50 -07005758void GL_APIENTRY glRenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005759{
5760 EVENT("(GLenum target = 0x%X, GLsizei samples = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
5761 target, samples, internalformat, width, height);
5762
Geoff Langbfdea662014-07-23 14:16:32 -04005763 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005764 if (context)
5765 {
5766 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005767 {
Geoff Langb1196682014-07-23 13:47:29 -04005768 context->recordError(gl::Error(GL_INVALID_OPERATION));
5769 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005770 }
Geoff Langbfdea662014-07-23 14:16:32 -04005771
Corentin Walleze0902642014-11-04 12:32:15 -08005772 if (!ValidateES3RenderbufferStorageParameters(context, target, samples, internalformat, width, height))
Geoff Langbfdea662014-07-23 14:16:32 -04005773 {
5774 return;
5775 }
5776
Shannon Woodse2632d22014-10-17 13:08:51 -04005777 gl::Renderbuffer *renderbuffer = context->getState().getCurrentRenderbuffer();
5778 renderbuffer->setStorage(width, height, internalformat, samples);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005779 }
5780}
5781
Kenneth Russell67ea1902014-10-06 16:44:50 -07005782void GL_APIENTRY glFramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005783{
5784 EVENT("(GLenum target = 0x%X, GLenum attachment = 0x%X, GLuint texture = %u, GLint level = %d, GLint layer = %d)",
5785 target, attachment, texture, level, layer);
5786
Geoff Langbfdea662014-07-23 14:16:32 -04005787 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005788 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005789 {
Geoff Langbfdea662014-07-23 14:16:32 -04005790 if (!ValidateFramebufferTextureLayer(context, target, attachment, texture,
5791 level, layer))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005792 {
Geoff Langbfdea662014-07-23 14:16:32 -04005793 return;
5794 }
Geoff Lang3ed0c482013-07-25 17:03:18 -04005795
Geoff Langbfdea662014-07-23 14:16:32 -04005796 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
5797 ASSERT(framebuffer);
Geoff Lang3ed0c482013-07-25 17:03:18 -04005798
Geoff Langab75a052014-10-15 12:56:37 -04005799 if (texture != 0)
Geoff Langbfdea662014-07-23 14:16:32 -04005800 {
Geoff Langab75a052014-10-15 12:56:37 -04005801 gl::Texture *textureObject = context->getTexture(texture);
5802 gl::ImageIndex index(textureObject->getTarget(), level, layer);
5803 framebuffer->setTextureAttachment(attachment, textureObject, index);
Geoff Langbfdea662014-07-23 14:16:32 -04005804 }
5805 else
5806 {
Geoff Langab75a052014-10-15 12:56:37 -04005807 framebuffer->setNULLAttachment(attachment);
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005808 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005809 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005810}
5811
Kenneth Russell67ea1902014-10-06 16:44:50 -07005812GLvoid* GL_APIENTRY glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005813{
5814 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
5815 target, offset, length, access);
5816
Geoff Langbfdea662014-07-23 14:16:32 -04005817 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005818 if (context)
5819 {
5820 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005821 {
Geoff Langb1196682014-07-23 13:47:29 -04005822 context->recordError(gl::Error(GL_INVALID_OPERATION));
5823 return NULL;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005824 }
Geoff Langbfdea662014-07-23 14:16:32 -04005825
5826 return glMapBufferRangeEXT(target, offset, length, access);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005827 }
5828
5829 return NULL;
5830}
5831
Kenneth Russell67ea1902014-10-06 16:44:50 -07005832void GL_APIENTRY glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005833{
5834 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
5835
Geoff Langbfdea662014-07-23 14:16:32 -04005836 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005837 if (context)
5838 {
5839 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005840 {
Geoff Langb1196682014-07-23 13:47:29 -04005841 context->recordError(gl::Error(GL_INVALID_OPERATION));
5842 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005843 }
Geoff Langbfdea662014-07-23 14:16:32 -04005844
5845 glFlushMappedBufferRangeEXT(target, offset, length);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005846 }
5847}
5848
Kenneth Russell67ea1902014-10-06 16:44:50 -07005849void GL_APIENTRY glBindVertexArray(GLuint array)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005850{
5851 EVENT("(GLuint array = %u)", array);
5852
Geoff Langbfdea662014-07-23 14:16:32 -04005853 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005854 if (context)
5855 {
5856 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005857 {
Geoff Langb1196682014-07-23 13:47:29 -04005858 context->recordError(gl::Error(GL_INVALID_OPERATION));
5859 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005860 }
Geoff Langbfdea662014-07-23 14:16:32 -04005861
5862 gl::VertexArray *vao = context->getVertexArray(array);
5863
5864 if (!vao)
5865 {
5866 // The default VAO should always exist
5867 ASSERT(array != 0);
Geoff Langb1196682014-07-23 13:47:29 -04005868 context->recordError(gl::Error(GL_INVALID_OPERATION));
5869 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005870 }
5871
5872 context->bindVertexArray(array);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005873 }
5874}
5875
Kenneth Russell67ea1902014-10-06 16:44:50 -07005876void GL_APIENTRY glDeleteVertexArrays(GLsizei n, const GLuint* arrays)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005877{
5878 EVENT("(GLsizei n = %d, const GLuint* arrays = 0x%0.8p)", n, arrays);
5879
Geoff Langbfdea662014-07-23 14:16:32 -04005880 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005881 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005882 {
Geoff Langbfdea662014-07-23 14:16:32 -04005883 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005884 {
Geoff Langb1196682014-07-23 13:47:29 -04005885 context->recordError(gl::Error(GL_INVALID_OPERATION));
5886 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005887 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005888
Geoff Langbfdea662014-07-23 14:16:32 -04005889 if (n < 0)
5890 {
Geoff Langb1196682014-07-23 13:47:29 -04005891 context->recordError(gl::Error(GL_INVALID_VALUE));
5892 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005893 }
Jamie Madilld1028542013-07-02 11:57:04 -04005894
Geoff Langbfdea662014-07-23 14:16:32 -04005895 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5896 {
5897 if (arrays[arrayIndex] != 0)
Jamie Madilld1028542013-07-02 11:57:04 -04005898 {
Geoff Langbfdea662014-07-23 14:16:32 -04005899 context->deleteVertexArray(arrays[arrayIndex]);
Jamie Madilld1028542013-07-02 11:57:04 -04005900 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005901 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005902 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005903}
5904
Kenneth Russell67ea1902014-10-06 16:44:50 -07005905void GL_APIENTRY glGenVertexArrays(GLsizei n, GLuint* arrays)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005906{
5907 EVENT("(GLsizei n = %d, GLuint* arrays = 0x%0.8p)", n, arrays);
5908
Geoff Langbfdea662014-07-23 14:16:32 -04005909 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005910 if (context)
5911 {
5912 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005913 {
Geoff Langb1196682014-07-23 13:47:29 -04005914 context->recordError(gl::Error(GL_INVALID_OPERATION));
5915 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005916 }
Geoff Langbfdea662014-07-23 14:16:32 -04005917
5918 if (n < 0)
5919 {
Geoff Langb1196682014-07-23 13:47:29 -04005920 context->recordError(gl::Error(GL_INVALID_VALUE));
5921 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005922 }
5923
5924 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5925 {
5926 arrays[arrayIndex] = context->createVertexArray();
5927 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005928 }
5929}
5930
Kenneth Russell67ea1902014-10-06 16:44:50 -07005931GLboolean GL_APIENTRY glIsVertexArray(GLuint array)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005932{
5933 EVENT("(GLuint array = %u)", array);
5934
Geoff Langbfdea662014-07-23 14:16:32 -04005935 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005936 if (context)
5937 {
5938 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005939 {
Geoff Langb1196682014-07-23 13:47:29 -04005940 context->recordError(gl::Error(GL_INVALID_OPERATION));
5941 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00005942 }
Geoff Langbfdea662014-07-23 14:16:32 -04005943
5944 if (array == 0)
5945 {
5946 return GL_FALSE;
5947 }
5948
5949 gl::VertexArray *vao = context->getVertexArray(array);
5950
5951 return (vao != NULL ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005952 }
5953
5954 return GL_FALSE;
5955}
5956
Kenneth Russell67ea1902014-10-06 16:44:50 -07005957void GL_APIENTRY glGetIntegeri_v(GLenum target, GLuint index, GLint* data)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005958{
5959 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint* data = 0x%0.8p)",
5960 target, index, data);
5961
Geoff Langbfdea662014-07-23 14:16:32 -04005962 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04005963 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005964 {
Geoff Langbfdea662014-07-23 14:16:32 -04005965 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005966 {
Geoff Langb1196682014-07-23 13:47:29 -04005967 context->recordError(gl::Error(GL_INVALID_OPERATION));
5968 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005969 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00005970
Geoff Lang3a61c322014-07-10 13:01:54 -04005971 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04005972 switch (target)
5973 {
5974 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
5975 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
5976 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04005977 if (index >= caps.maxTransformFeedbackSeparateAttributes)
5978 {
Geoff Langb1196682014-07-23 13:47:29 -04005979 context->recordError(gl::Error(GL_INVALID_VALUE));
5980 return;
Geoff Lang05881a02014-07-10 14:05:30 -04005981 }
Geoff Langbfdea662014-07-23 14:16:32 -04005982 break;
Geoff Langb1196682014-07-23 13:47:29 -04005983
Geoff Langbfdea662014-07-23 14:16:32 -04005984 case GL_UNIFORM_BUFFER_START:
5985 case GL_UNIFORM_BUFFER_SIZE:
5986 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04005987 if (index >= caps.maxCombinedUniformBlocks)
5988 {
Geoff Langb1196682014-07-23 13:47:29 -04005989 context->recordError(gl::Error(GL_INVALID_VALUE));
5990 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04005991 }
Geoff Langbfdea662014-07-23 14:16:32 -04005992 break;
Geoff Langb1196682014-07-23 13:47:29 -04005993
Geoff Langbfdea662014-07-23 14:16:32 -04005994 default:
Geoff Langb1196682014-07-23 13:47:29 -04005995 context->recordError(gl::Error(GL_INVALID_ENUM));
5996 return;
Geoff Langbfdea662014-07-23 14:16:32 -04005997 }
5998
5999 if (!(context->getIndexedIntegerv(target, index, data)))
6000 {
6001 GLenum nativeType;
6002 unsigned int numParams = 0;
6003 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04006004 {
6005 context->recordError(gl::Error(GL_INVALID_ENUM));
6006 return;
6007 }
Shannon Woods15934d52013-08-19 14:28:49 -04006008
Geoff Langbfdea662014-07-23 14:16:32 -04006009 if (numParams == 0)
Geoff Langb1196682014-07-23 13:47:29 -04006010 {
Geoff Langbfdea662014-07-23 14:16:32 -04006011 return; // it is known that pname is valid, but there are no parameters to return
Geoff Langb1196682014-07-23 13:47:29 -04006012 }
Geoff Langbfdea662014-07-23 14:16:32 -04006013
6014 if (nativeType == GL_INT_64_ANGLEX)
Shannon Woods15934d52013-08-19 14:28:49 -04006015 {
Geoff Langbfdea662014-07-23 14:16:32 -04006016 GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<int>::min());
6017 GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<int>::max());
6018 GLint64 *int64Params = new GLint64[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04006019
Geoff Langbfdea662014-07-23 14:16:32 -04006020 context->getIndexedInteger64v(target, index, int64Params);
Shannon Woods15934d52013-08-19 14:28:49 -04006021
Geoff Langbfdea662014-07-23 14:16:32 -04006022 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04006023 {
Geoff Langbfdea662014-07-23 14:16:32 -04006024 GLint64 clampedValue = std::max(std::min(int64Params[i], maxIntValue), minIntValue);
6025 data[i] = static_cast<GLint>(clampedValue);
Shannon Woods15934d52013-08-19 14:28:49 -04006026 }
Geoff Langbfdea662014-07-23 14:16:32 -04006027
6028 delete [] int64Params;
6029 }
6030 else
6031 {
6032 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04006033 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006034 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006035 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006036}
6037
Kenneth Russell67ea1902014-10-06 16:44:50 -07006038void GL_APIENTRY glBeginTransformFeedback(GLenum primitiveMode)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006039{
6040 EVENT("(GLenum primitiveMode = 0x%X)", primitiveMode);
6041
Geoff Langbfdea662014-07-23 14:16:32 -04006042 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006043 if (context)
6044 {
6045 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006046 {
Geoff Langb1196682014-07-23 13:47:29 -04006047 context->recordError(gl::Error(GL_INVALID_OPERATION));
6048 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006049 }
Geoff Langbfdea662014-07-23 14:16:32 -04006050
6051 switch (primitiveMode)
6052 {
6053 case GL_TRIANGLES:
6054 case GL_LINES:
6055 case GL_POINTS:
6056 break;
Geoff Langb1196682014-07-23 13:47:29 -04006057
Geoff Langbfdea662014-07-23 14:16:32 -04006058 default:
Geoff Langb1196682014-07-23 13:47:29 -04006059 context->recordError(gl::Error(GL_INVALID_ENUM));
6060 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006061 }
6062
6063 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
6064 ASSERT(transformFeedback != NULL);
6065
6066 if (transformFeedback->isStarted())
6067 {
Geoff Langb1196682014-07-23 13:47:29 -04006068 context->recordError(gl::Error(GL_INVALID_OPERATION));
6069 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006070 }
6071
6072 if (transformFeedback->isPaused())
6073 {
6074 transformFeedback->resume();
6075 }
6076 else
6077 {
6078 transformFeedback->start(primitiveMode);
6079 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006080 }
6081}
6082
Kenneth Russell67ea1902014-10-06 16:44:50 -07006083void GL_APIENTRY glEndTransformFeedback(void)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006084{
6085 EVENT("(void)");
6086
Geoff Langbfdea662014-07-23 14:16:32 -04006087 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006088 if (context)
6089 {
6090 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006091 {
Geoff Langb1196682014-07-23 13:47:29 -04006092 context->recordError(gl::Error(GL_INVALID_OPERATION));
6093 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006094 }
Geoff Langbfdea662014-07-23 14:16:32 -04006095
6096 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
6097 ASSERT(transformFeedback != NULL);
6098
6099 if (!transformFeedback->isStarted())
6100 {
Geoff Langb1196682014-07-23 13:47:29 -04006101 context->recordError(gl::Error(GL_INVALID_OPERATION));
6102 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006103 }
6104
6105 transformFeedback->stop();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006106 }
6107}
6108
Kenneth Russell67ea1902014-10-06 16:44:50 -07006109void GL_APIENTRY glBindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006110{
6111 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u, GLintptr offset = %d, GLsizeiptr size = %d)",
6112 target, index, buffer, offset, size);
6113
Geoff Langbfdea662014-07-23 14:16:32 -04006114 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006115 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006116 {
Geoff Langbfdea662014-07-23 14:16:32 -04006117 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006118 {
Geoff Langb1196682014-07-23 13:47:29 -04006119 context->recordError(gl::Error(GL_INVALID_OPERATION));
6120 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006121 }
6122
Geoff Lang3a61c322014-07-10 13:01:54 -04006123 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006124 switch (target)
6125 {
6126 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006127 if (index >= caps.maxTransformFeedbackSeparateAttributes)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006128 {
Geoff Langb1196682014-07-23 13:47:29 -04006129 context->recordError(gl::Error(GL_INVALID_VALUE));
6130 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006131 }
Geoff Langbfdea662014-07-23 14:16:32 -04006132 break;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006133
Geoff Langbfdea662014-07-23 14:16:32 -04006134 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006135 if (index >= caps.maxUniformBufferBindings)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006136 {
Geoff Langb1196682014-07-23 13:47:29 -04006137 context->recordError(gl::Error(GL_INVALID_VALUE));
6138 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006139 }
Geoff Langbfdea662014-07-23 14:16:32 -04006140 break;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006141
Geoff Langbfdea662014-07-23 14:16:32 -04006142 default:
Geoff Langb1196682014-07-23 13:47:29 -04006143 context->recordError(gl::Error(GL_INVALID_ENUM));
6144 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006145 }
6146
6147 if (buffer != 0 && size <= 0)
6148 {
Geoff Langb1196682014-07-23 13:47:29 -04006149 context->recordError(gl::Error(GL_INVALID_VALUE));
6150 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006151 }
6152
6153 switch (target)
6154 {
6155 case GL_TRANSFORM_FEEDBACK_BUFFER:
6156
6157 // size and offset must be a multiple of 4
6158 if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0))
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006159 {
Geoff Langb1196682014-07-23 13:47:29 -04006160 context->recordError(gl::Error(GL_INVALID_VALUE));
6161 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006162 }
6163
Geoff Langbfdea662014-07-23 14:16:32 -04006164 context->bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
6165 context->bindGenericTransformFeedbackBuffer(buffer);
6166 break;
6167
6168 case GL_UNIFORM_BUFFER:
6169
6170 // it is an error to bind an offset not a multiple of the alignment
Geoff Lang3a61c322014-07-10 13:01:54 -04006171 if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0)
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006172 {
Geoff Langb1196682014-07-23 13:47:29 -04006173 context->recordError(gl::Error(GL_INVALID_VALUE));
6174 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006175 }
Geoff Langbfdea662014-07-23 14:16:32 -04006176
6177 context->bindIndexedUniformBuffer(buffer, index, offset, size);
6178 context->bindGenericUniformBuffer(buffer);
6179 break;
6180
6181 default:
6182 UNREACHABLE();
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006183 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006184 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006185}
6186
Kenneth Russell67ea1902014-10-06 16:44:50 -07006187void GL_APIENTRY glBindBufferBase(GLenum target, GLuint index, GLuint buffer)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006188{
6189 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLuint buffer = %u)",
6190 target, index, buffer);
6191
Geoff Langbfdea662014-07-23 14:16:32 -04006192 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006193 if (context)
6194 {
6195 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006196 {
Geoff Langb1196682014-07-23 13:47:29 -04006197 context->recordError(gl::Error(GL_INVALID_OPERATION));
6198 return;
shannon.woods%transgaming.com@gtempaccount.comd4e61972013-04-13 03:37:04 +00006199 }
Geoff Langbfdea662014-07-23 14:16:32 -04006200
Geoff Lang3a61c322014-07-10 13:01:54 -04006201 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006202 switch (target)
6203 {
6204 case GL_TRANSFORM_FEEDBACK_BUFFER:
Geoff Lang05881a02014-07-10 14:05:30 -04006205 if (index >= caps.maxTransformFeedbackSeparateAttributes)
Geoff Langbfdea662014-07-23 14:16:32 -04006206 {
Geoff Langb1196682014-07-23 13:47:29 -04006207 context->recordError(gl::Error(GL_INVALID_VALUE));
6208 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006209 }
6210 break;
6211
6212 case GL_UNIFORM_BUFFER:
Geoff Lang3a61c322014-07-10 13:01:54 -04006213 if (index >= caps.maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04006214 {
Geoff Langb1196682014-07-23 13:47:29 -04006215 context->recordError(gl::Error(GL_INVALID_VALUE));
6216 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006217 }
6218 break;
6219
6220 default:
Geoff Langb1196682014-07-23 13:47:29 -04006221 context->recordError(gl::Error(GL_INVALID_ENUM));
6222 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006223 }
6224
6225 switch (target)
6226 {
6227 case GL_TRANSFORM_FEEDBACK_BUFFER:
6228 context->bindIndexedTransformFeedbackBuffer(buffer, index, 0, 0);
6229 context->bindGenericTransformFeedbackBuffer(buffer);
6230 break;
6231
6232 case GL_UNIFORM_BUFFER:
6233 context->bindIndexedUniformBuffer(buffer, index, 0, 0);
6234 context->bindGenericUniformBuffer(buffer);
6235 break;
6236
6237 default:
6238 UNREACHABLE();
6239 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006240 }
6241}
6242
Kenneth Russell67ea1902014-10-06 16:44:50 -07006243void GL_APIENTRY glTransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006244{
6245 EVENT("(GLuint program = %u, GLsizei count = %d, const GLchar* const* varyings = 0x%0.8p, GLenum bufferMode = 0x%X)",
6246 program, count, varyings, bufferMode);
6247
Geoff Langbfdea662014-07-23 14:16:32 -04006248 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006249 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006250 {
Geoff Langbfdea662014-07-23 14:16:32 -04006251 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006252 {
Geoff Langb1196682014-07-23 13:47:29 -04006253 context->recordError(gl::Error(GL_INVALID_OPERATION));
6254 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006255 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006256
Geoff Langbfdea662014-07-23 14:16:32 -04006257 if (count < 0)
6258 {
Geoff Langb1196682014-07-23 13:47:29 -04006259 context->recordError(gl::Error(GL_INVALID_VALUE));
6260 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006261 }
6262
Geoff Lang05881a02014-07-10 14:05:30 -04006263 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04006264 switch (bufferMode)
6265 {
6266 case GL_INTERLEAVED_ATTRIBS:
6267 break;
6268 case GL_SEPARATE_ATTRIBS:
Geoff Lang05881a02014-07-10 14:05:30 -04006269 if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes)
Geoff Lang48dcae72014-02-05 16:28:24 -05006270 {
Geoff Langb1196682014-07-23 13:47:29 -04006271 context->recordError(gl::Error(GL_INVALID_VALUE));
6272 return;
Geoff Lang48dcae72014-02-05 16:28:24 -05006273 }
Geoff Langbfdea662014-07-23 14:16:32 -04006274 break;
6275 default:
Geoff Langb1196682014-07-23 13:47:29 -04006276 context->recordError(gl::Error(GL_INVALID_ENUM));
6277 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006278 }
Geoff Langbfdea662014-07-23 14:16:32 -04006279
6280 if (!gl::ValidProgram(context, program))
6281 {
6282 return;
6283 }
6284
6285 gl::Program *programObject = context->getProgram(program);
6286 ASSERT(programObject);
6287
6288 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006289 }
6290}
6291
Kenneth Russell67ea1902014-10-06 16:44:50 -07006292void GL_APIENTRY glGetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006293{
6294 EVENT("(GLuint program = %u, GLuint index = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, "
6295 "GLsizei* size = 0x%0.8p, GLenum* type = 0x%0.8p, GLchar* name = 0x%0.8p)",
6296 program, index, bufSize, length, size, type, name);
6297
Geoff Langbfdea662014-07-23 14:16:32 -04006298 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006299 if (context)
6300 {
6301 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006302 {
Geoff Langb1196682014-07-23 13:47:29 -04006303 context->recordError(gl::Error(GL_INVALID_OPERATION));
6304 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006305 }
Geoff Langbfdea662014-07-23 14:16:32 -04006306
6307 if (bufSize < 0)
6308 {
Geoff Langb1196682014-07-23 13:47:29 -04006309 context->recordError(gl::Error(GL_INVALID_VALUE));
6310 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006311 }
6312
6313 if (!gl::ValidProgram(context, program))
6314 {
6315 return;
6316 }
6317
6318 gl::Program *programObject = context->getProgram(program);
6319 ASSERT(programObject);
6320
6321 if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount()))
6322 {
Geoff Langb1196682014-07-23 13:47:29 -04006323 context->recordError(gl::Error(GL_INVALID_VALUE));
6324 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006325 }
6326
6327 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006328 }
6329}
6330
Kenneth Russell67ea1902014-10-06 16:44:50 -07006331void GL_APIENTRY glVertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006332{
6333 EVENT("(GLuint index = %u, GLint size = %d, GLenum type = 0x%X, GLsizei stride = %d, const GLvoid* pointer = 0x%0.8p)",
6334 index, size, type, stride, pointer);
6335
Geoff Langbfdea662014-07-23 14:16:32 -04006336 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006337 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006338 {
Geoff Langbfdea662014-07-23 14:16:32 -04006339 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006340 {
Geoff Langb1196682014-07-23 13:47:29 -04006341 context->recordError(gl::Error(GL_INVALID_OPERATION));
6342 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006343 }
6344
Geoff Langb1196682014-07-23 13:47:29 -04006345 if (index >= gl::MAX_VERTEX_ATTRIBS)
6346 {
6347 context->recordError(gl::Error(GL_INVALID_VALUE));
6348 return;
6349 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006350
Geoff Langb1196682014-07-23 13:47:29 -04006351 if (size < 1 || size > 4)
6352 {
6353 context->recordError(gl::Error(GL_INVALID_VALUE));
6354 return;
6355 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006356
Geoff Langb1196682014-07-23 13:47:29 -04006357 switch (type)
6358 {
6359 case GL_BYTE:
6360 case GL_UNSIGNED_BYTE:
6361 case GL_SHORT:
6362 case GL_UNSIGNED_SHORT:
6363 case GL_INT:
6364 case GL_UNSIGNED_INT:
6365 case GL_INT_2_10_10_10_REV:
6366 case GL_UNSIGNED_INT_2_10_10_10_REV:
6367 break;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006368
Geoff Langb1196682014-07-23 13:47:29 -04006369 default:
6370 context->recordError(gl::Error(GL_INVALID_ENUM));
6371 return;
6372 }
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006373
Geoff Langb1196682014-07-23 13:47:29 -04006374 if (stride < 0)
6375 {
6376 context->recordError(gl::Error(GL_INVALID_VALUE));
6377 return;
6378 }
Geoff Langbfdea662014-07-23 14:16:32 -04006379
Geoff Langb1196682014-07-23 13:47:29 -04006380 if ((type == GL_INT_2_10_10_10_REV || type == GL_UNSIGNED_INT_2_10_10_10_REV) && size != 4)
6381 {
6382 context->recordError(gl::Error(GL_INVALID_OPERATION));
6383 return;
6384 }
6385
Geoff Langbfdea662014-07-23 14:16:32 -04006386 // [OpenGL ES 3.0.2] Section 2.8 page 24:
6387 // An INVALID_OPERATION error is generated when a non-zero vertex array object
6388 // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point,
6389 // and the pointer argument is not NULL.
6390 if (context->getState().getVertexArray()->id() != 0 && context->getState().getArrayBufferId() == 0 && pointer != NULL)
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006391 {
Geoff Langb1196682014-07-23 13:47:29 -04006392 context->recordError(gl::Error(GL_INVALID_OPERATION));
6393 return;
shannon.woods%transgaming.com@gtempaccount.com1ab57be2013-04-13 03:38:39 +00006394 }
6395
Geoff Langbfdea662014-07-23 14:16:32 -04006396 context->getState().setVertexAttribState(index, context->getState().getTargetBuffer(GL_ARRAY_BUFFER), size, type, false, true,
6397 stride, pointer);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006398 }
6399}
6400
Kenneth Russell67ea1902014-10-06 16:44:50 -07006401void GL_APIENTRY glGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006402{
6403 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
6404 index, pname, params);
6405
Geoff Langbfdea662014-07-23 14:16:32 -04006406 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006407 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006408 {
Geoff Langbfdea662014-07-23 14:16:32 -04006409 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006410 {
Geoff Langb1196682014-07-23 13:47:29 -04006411 context->recordError(gl::Error(GL_INVALID_OPERATION));
6412 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006413 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006414
Geoff Langbfdea662014-07-23 14:16:32 -04006415 if (index >= gl::MAX_VERTEX_ATTRIBS)
6416 {
Geoff Langb1196682014-07-23 13:47:29 -04006417 context->recordError(gl::Error(GL_INVALID_VALUE));
6418 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006419 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006420
Geoff Langbfdea662014-07-23 14:16:32 -04006421 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006422
Geoff Langb1196682014-07-23 13:47:29 -04006423 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006424 {
6425 return;
6426 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006427
Geoff Langbfdea662014-07-23 14:16:32 -04006428 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6429 {
6430 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6431 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006432 {
Geoff Langbfdea662014-07-23 14:16:32 -04006433 params[i] = currentValueData.IntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006434 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006435 }
Geoff Langbfdea662014-07-23 14:16:32 -04006436 else
6437 {
6438 *params = gl::QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
6439 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006440 }
6441}
6442
Kenneth Russell67ea1902014-10-06 16:44:50 -07006443void GL_APIENTRY glGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006444{
6445 EVENT("(GLuint index = %u, GLenum pname = 0x%X, GLuint* params = 0x%0.8p)",
6446 index, pname, params);
6447
Geoff Langbfdea662014-07-23 14:16:32 -04006448 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006449 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006450 {
Geoff Langbfdea662014-07-23 14:16:32 -04006451 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006452 {
Geoff Langb1196682014-07-23 13:47:29 -04006453 context->recordError(gl::Error(GL_INVALID_OPERATION));
6454 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006455 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006456
Geoff Langbfdea662014-07-23 14:16:32 -04006457 if (index >= gl::MAX_VERTEX_ATTRIBS)
6458 {
Geoff Langb1196682014-07-23 13:47:29 -04006459 context->recordError(gl::Error(GL_INVALID_VALUE));
6460 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006461 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006462
Geoff Langbfdea662014-07-23 14:16:32 -04006463 const gl::VertexAttribute &attribState = context->getState().getVertexAttribState(index);
Jamie Madilla7d05862013-07-02 11:57:06 -04006464
Geoff Langb1196682014-07-23 13:47:29 -04006465 if (!gl::ValidateGetVertexAttribParameters(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04006466 {
6467 return;
6468 }
Jamie Madilla7d05862013-07-02 11:57:06 -04006469
Geoff Langbfdea662014-07-23 14:16:32 -04006470 if (pname == GL_CURRENT_VERTEX_ATTRIB)
6471 {
6472 const gl::VertexAttribCurrentValueData &currentValueData = context->getState().getVertexAttribCurrentValue(index);
6473 for (int i = 0; i < 4; ++i)
Jamie Madilla7d05862013-07-02 11:57:06 -04006474 {
Geoff Langbfdea662014-07-23 14:16:32 -04006475 params[i] = currentValueData.UnsignedIntValues[i];
Jamie Madilla7d05862013-07-02 11:57:06 -04006476 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006477 }
Geoff Langbfdea662014-07-23 14:16:32 -04006478 else
6479 {
6480 *params = gl::QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
6481 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006482 }
6483}
6484
Kenneth Russell67ea1902014-10-06 16:44:50 -07006485void GL_APIENTRY glVertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006486{
6487 EVENT("(GLuint index = %u, GLint x = %d, GLint y = %d, GLint z = %d, GLint w = %d)",
6488 index, x, y, z, w);
6489
Geoff Langbfdea662014-07-23 14:16:32 -04006490 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006491 if (context)
6492 {
6493 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006494 {
Geoff Langb1196682014-07-23 13:47:29 -04006495 context->recordError(gl::Error(GL_INVALID_OPERATION));
6496 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006497 }
Geoff Langbfdea662014-07-23 14:16:32 -04006498
6499 if (index >= gl::MAX_VERTEX_ATTRIBS)
6500 {
Geoff Langb1196682014-07-23 13:47:29 -04006501 context->recordError(gl::Error(GL_INVALID_VALUE));
6502 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006503 }
6504
6505 GLint vals[4] = { x, y, z, w };
6506 context->getState().setVertexAttribi(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006507 }
6508}
6509
Kenneth Russell67ea1902014-10-06 16:44:50 -07006510void GL_APIENTRY glVertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006511{
6512 EVENT("(GLuint index = %u, GLuint x = %u, GLuint y = %u, GLuint z = %u, GLuint w = %u)",
6513 index, x, y, z, w);
6514
Geoff Langbfdea662014-07-23 14:16:32 -04006515 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006516 if (context)
6517 {
6518 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006519 {
Geoff Langb1196682014-07-23 13:47:29 -04006520 context->recordError(gl::Error(GL_INVALID_OPERATION));
6521 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006522 }
Geoff Langbfdea662014-07-23 14:16:32 -04006523
6524 if (index >= gl::MAX_VERTEX_ATTRIBS)
6525 {
Geoff Langb1196682014-07-23 13:47:29 -04006526 context->recordError(gl::Error(GL_INVALID_VALUE));
6527 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006528 }
6529
6530 GLuint vals[4] = { x, y, z, w };
6531 context->getState().setVertexAttribu(index, vals);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006532 }
6533}
6534
Kenneth Russell67ea1902014-10-06 16:44:50 -07006535void GL_APIENTRY glVertexAttribI4iv(GLuint index, const GLint* v)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006536{
6537 EVENT("(GLuint index = %u, const GLint* v = 0x%0.8p)", index, v);
6538
Geoff Langbfdea662014-07-23 14:16:32 -04006539 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006540 if (context)
6541 {
6542 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006543 {
Geoff Langb1196682014-07-23 13:47:29 -04006544 context->recordError(gl::Error(GL_INVALID_OPERATION));
6545 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006546 }
Geoff Langbfdea662014-07-23 14:16:32 -04006547
6548 if (index >= gl::MAX_VERTEX_ATTRIBS)
6549 {
Geoff Langb1196682014-07-23 13:47:29 -04006550 context->recordError(gl::Error(GL_INVALID_VALUE));
6551 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006552 }
6553
6554 context->getState().setVertexAttribi(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006555 }
6556}
6557
Kenneth Russell67ea1902014-10-06 16:44:50 -07006558void GL_APIENTRY glVertexAttribI4uiv(GLuint index, const GLuint* v)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006559{
6560 EVENT("(GLuint index = %u, const GLuint* v = 0x%0.8p)", index, v);
6561
Geoff Langbfdea662014-07-23 14:16:32 -04006562 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006563 if (context)
6564 {
6565 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006566 {
Geoff Langb1196682014-07-23 13:47:29 -04006567 context->recordError(gl::Error(GL_INVALID_OPERATION));
6568 return;
shannon.woods%transgaming.com@gtempaccount.coma8885862013-04-13 03:37:53 +00006569 }
Geoff Langbfdea662014-07-23 14:16:32 -04006570
6571 if (index >= gl::MAX_VERTEX_ATTRIBS)
6572 {
Geoff Langb1196682014-07-23 13:47:29 -04006573 context->recordError(gl::Error(GL_INVALID_VALUE));
6574 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006575 }
6576
6577 context->getState().setVertexAttribu(index, v);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006578 }
6579}
6580
Kenneth Russell67ea1902014-10-06 16:44:50 -07006581void GL_APIENTRY glGetUniformuiv(GLuint program, GLint location, GLuint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006582{
6583 EVENT("(GLuint program = %u, GLint location = %d, GLuint* params = 0x%0.8p)",
6584 program, location, params);
6585
Geoff Langbfdea662014-07-23 14:16:32 -04006586 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006587 if (context)
6588 {
Jamie Madill0063c512014-08-25 15:47:53 -04006589 if (!ValidateGetUniformuiv(context, program, location, params))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006590 {
Jamie Madill0063c512014-08-25 15:47:53 -04006591 return;
shannon.woods%transgaming.com@gtempaccount.come2290122013-04-13 03:41:07 +00006592 }
Geoff Langbfdea662014-07-23 14:16:32 -04006593
Jamie Madilla502c742014-08-28 17:19:13 -04006594 gl::Program *programObject = context->getProgram(program);
6595 ASSERT(programObject);
6596 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
Jamie Madill0063c512014-08-25 15:47:53 -04006597 ASSERT(programBinary);
Geoff Langbfdea662014-07-23 14:16:32 -04006598
Jamie Madill99a1e982014-08-25 15:47:54 -04006599 programBinary->getUniformuiv(location, params);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006600 }
6601}
6602
Kenneth Russell67ea1902014-10-06 16:44:50 -07006603GLint GL_APIENTRY glGetFragDataLocation(GLuint program, const GLchar *name)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006604{
6605 EVENT("(GLuint program = %u, const GLchar *name = 0x%0.8p)",
6606 program, name);
6607
Geoff Langbfdea662014-07-23 14:16:32 -04006608 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006609 if (context)
6610 {
6611 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006612 {
Geoff Langb1196682014-07-23 13:47:29 -04006613 context->recordError(gl::Error(GL_INVALID_OPERATION));
6614 return -1;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006615 }
Geoff Langbfdea662014-07-23 14:16:32 -04006616
6617 if (program == 0)
6618 {
Geoff Langb1196682014-07-23 13:47:29 -04006619 context->recordError(gl::Error(GL_INVALID_VALUE));
6620 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006621 }
6622
6623 gl::Program *programObject = context->getProgram(program);
6624
6625 if (!programObject || !programObject->isLinked())
6626 {
Geoff Langb1196682014-07-23 13:47:29 -04006627 context->recordError(gl::Error(GL_INVALID_OPERATION));
6628 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006629 }
6630
6631 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
6632 if (!programBinary)
6633 {
Geoff Langb1196682014-07-23 13:47:29 -04006634 context->recordError(gl::Error(GL_INVALID_OPERATION));
6635 return -1;
Geoff Langbfdea662014-07-23 14:16:32 -04006636 }
6637
6638 return programBinary->getFragDataLocation(name);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006639 }
6640
6641 return 0;
6642}
6643
Kenneth Russell67ea1902014-10-06 16:44:50 -07006644void GL_APIENTRY glUniform1ui(GLint location, GLuint v0)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006645{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006646 glUniform1uiv(location, 1, &v0);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006647}
6648
Kenneth Russell67ea1902014-10-06 16:44:50 -07006649void GL_APIENTRY glUniform2ui(GLint location, GLuint v0, GLuint v1)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006650{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006651 const GLuint xy[] = { v0, v1 };
6652 glUniform2uiv(location, 1, xy);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006653}
6654
Kenneth Russell67ea1902014-10-06 16:44:50 -07006655void GL_APIENTRY glUniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006656{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006657 const GLuint xyz[] = { v0, v1, v2 };
6658 glUniform3uiv(location, 1, xyz);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006659}
6660
Kenneth Russell67ea1902014-10-06 16:44:50 -07006661void GL_APIENTRY glUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006662{
shannon.woods%transgaming.com@gtempaccount.com8431b9c2013-04-13 03:40:17 +00006663 const GLuint xyzw[] = { v0, v1, v2, v3 };
6664 glUniform4uiv(location, 1, xyzw);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006665}
6666
Kenneth Russell67ea1902014-10-06 16:44:50 -07006667void GL_APIENTRY glUniform1uiv(GLint location, GLsizei count, const GLuint* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006668{
6669 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6670 location, count, value);
6671
Geoff Langbfdea662014-07-23 14:16:32 -04006672 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006673 if (context)
6674 {
6675 if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006676 {
Geoff Langbfdea662014-07-23 14:16:32 -04006677 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006678 }
Geoff Langbfdea662014-07-23 14:16:32 -04006679
6680 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6681 programBinary->setUniform1uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006682 }
6683}
6684
Kenneth Russell67ea1902014-10-06 16:44:50 -07006685void GL_APIENTRY glUniform2uiv(GLint location, GLsizei count, const GLuint* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006686{
6687 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6688 location, count, value);
6689
Geoff Langbfdea662014-07-23 14:16:32 -04006690 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006691 if (context)
6692 {
6693 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006694 {
Geoff Langbfdea662014-07-23 14:16:32 -04006695 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006696 }
Geoff Langbfdea662014-07-23 14:16:32 -04006697
6698 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6699 programBinary->setUniform2uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006700 }
6701}
6702
Kenneth Russell67ea1902014-10-06 16:44:50 -07006703void GL_APIENTRY glUniform3uiv(GLint location, GLsizei count, const GLuint* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006704{
6705 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value)",
6706 location, count, value);
6707
Geoff Langbfdea662014-07-23 14:16:32 -04006708 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006709 if (context)
6710 {
6711 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006712 {
Geoff Langbfdea662014-07-23 14:16:32 -04006713 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006714 }
Geoff Langbfdea662014-07-23 14:16:32 -04006715
6716 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6717 programBinary->setUniform3uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006718 }
6719}
6720
Kenneth Russell67ea1902014-10-06 16:44:50 -07006721void GL_APIENTRY glUniform4uiv(GLint location, GLsizei count, const GLuint* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006722{
6723 EVENT("(GLint location = %d, GLsizei count = %d, const GLuint* value = 0x%0.8p)",
6724 location, count, value);
6725
Geoff Langbfdea662014-07-23 14:16:32 -04006726 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006727 if (context)
6728 {
6729 if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006730 {
Geoff Langbfdea662014-07-23 14:16:32 -04006731 return;
shannon.woods%transgaming.com@gtempaccount.com50ea4ab2013-04-13 03:40:36 +00006732 }
Geoff Langbfdea662014-07-23 14:16:32 -04006733
6734 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
6735 programBinary->setUniform4uiv(location, count, value);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006736 }
6737}
6738
Kenneth Russell67ea1902014-10-06 16:44:50 -07006739void GL_APIENTRY glClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006740{
6741 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLint* value = 0x%0.8p)",
6742 buffer, drawbuffer, value);
6743
Geoff Langbfdea662014-07-23 14:16:32 -04006744 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006745 if (context)
6746 {
6747 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006748 {
Geoff Langbfdea662014-07-23 14:16:32 -04006749 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006750 }
Geoff Langbfdea662014-07-23 14:16:32 -04006751
6752 switch (buffer)
6753 {
6754 case GL_COLOR:
6755 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6756 {
Geoff Langb1196682014-07-23 13:47:29 -04006757 context->recordError(gl::Error(GL_INVALID_VALUE));
6758 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006759 }
6760 break;
Geoff Langb1196682014-07-23 13:47:29 -04006761
Geoff Langbfdea662014-07-23 14:16:32 -04006762 case GL_STENCIL:
6763 if (drawbuffer != 0)
6764 {
Geoff Langb1196682014-07-23 13:47:29 -04006765 context->recordError(gl::Error(GL_INVALID_VALUE));
6766 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006767 }
6768 break;
Geoff Langb1196682014-07-23 13:47:29 -04006769
Geoff Langbfdea662014-07-23 14:16:32 -04006770 default:
Geoff Langb1196682014-07-23 13:47:29 -04006771 context->recordError(gl::Error(GL_INVALID_ENUM));
6772 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006773 }
6774
Geoff Langcc79b8c2014-07-25 13:48:02 -04006775 gl::Error error = context->clearBufferiv(buffer, drawbuffer, value);
6776 if (error.isError())
6777 {
6778 context->recordError(error);
6779 return;
6780 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006781 }
6782}
6783
Kenneth Russell67ea1902014-10-06 16:44:50 -07006784void GL_APIENTRY glClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006785{
6786 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLuint* value = 0x%0.8p)",
6787 buffer, drawbuffer, value);
6788
Geoff Langbfdea662014-07-23 14:16:32 -04006789 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006790 if (context)
6791 {
6792 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006793 {
Geoff Langbfdea662014-07-23 14:16:32 -04006794 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006795 }
Geoff Langbfdea662014-07-23 14:16:32 -04006796
6797 switch (buffer)
6798 {
6799 case GL_COLOR:
6800 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6801 {
Geoff Langb1196682014-07-23 13:47:29 -04006802 context->recordError(gl::Error(GL_INVALID_VALUE));
6803 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006804 }
6805 break;
Geoff Langb1196682014-07-23 13:47:29 -04006806
Geoff Langbfdea662014-07-23 14:16:32 -04006807 default:
Geoff Langb1196682014-07-23 13:47:29 -04006808 context->recordError(gl::Error(GL_INVALID_ENUM));
6809 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006810 }
6811
Geoff Langcc79b8c2014-07-25 13:48:02 -04006812 gl::Error error = context->clearBufferuiv(buffer, drawbuffer, value);
6813 if (error.isError())
6814 {
6815 context->recordError(error);
6816 return;
6817 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006818 }
6819}
6820
Kenneth Russell67ea1902014-10-06 16:44:50 -07006821void GL_APIENTRY glClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006822{
6823 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, const GLfloat* value = 0x%0.8p)",
6824 buffer, drawbuffer, value);
6825
Geoff Langbfdea662014-07-23 14:16:32 -04006826 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006827 if (context)
6828 {
6829 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006830 {
Geoff Langbfdea662014-07-23 14:16:32 -04006831 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006832 }
Geoff Langbfdea662014-07-23 14:16:32 -04006833
6834 switch (buffer)
6835 {
6836 case GL_COLOR:
6837 if (drawbuffer < 0 || static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers)
6838 {
Geoff Langb1196682014-07-23 13:47:29 -04006839 context->recordError(gl::Error(GL_INVALID_VALUE));
6840 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006841 }
6842 break;
Geoff Langb1196682014-07-23 13:47:29 -04006843
Geoff Langbfdea662014-07-23 14:16:32 -04006844 case GL_DEPTH:
6845 if (drawbuffer != 0)
6846 {
Geoff Langb1196682014-07-23 13:47:29 -04006847 context->recordError(gl::Error(GL_INVALID_VALUE));
6848 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006849 }
6850 break;
Geoff Langb1196682014-07-23 13:47:29 -04006851
Geoff Langbfdea662014-07-23 14:16:32 -04006852 default:
Geoff Langb1196682014-07-23 13:47:29 -04006853 context->recordError(gl::Error(GL_INVALID_ENUM));
6854 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006855 }
6856
Geoff Langcc79b8c2014-07-25 13:48:02 -04006857 gl::Error error = context->clearBufferfv(buffer, drawbuffer, value);
6858 if (error.isError())
6859 {
6860 context->recordError(error);
6861 return;
6862 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006863 }
6864}
6865
Kenneth Russell67ea1902014-10-06 16:44:50 -07006866void GL_APIENTRY glClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006867{
6868 EVENT("(GLenum buffer = 0x%X, GLint drawbuffer = %d, GLfloat depth, GLint stencil = %d)",
6869 buffer, drawbuffer, depth, stencil);
6870
Geoff Langbfdea662014-07-23 14:16:32 -04006871 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006872 if (context)
6873 {
6874 if (!ValidateClearBuffer(context))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006875 {
Geoff Langbfdea662014-07-23 14:16:32 -04006876 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00006877 }
Geoff Langbfdea662014-07-23 14:16:32 -04006878
6879 switch (buffer)
6880 {
6881 case GL_DEPTH_STENCIL:
6882 if (drawbuffer != 0)
6883 {
Geoff Langb1196682014-07-23 13:47:29 -04006884 context->recordError(gl::Error(GL_INVALID_VALUE));
6885 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006886 }
6887 break;
Geoff Langb1196682014-07-23 13:47:29 -04006888
Geoff Langbfdea662014-07-23 14:16:32 -04006889 default:
Geoff Langb1196682014-07-23 13:47:29 -04006890 context->recordError(gl::Error(GL_INVALID_ENUM));
6891 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006892 }
6893
Geoff Langcc79b8c2014-07-25 13:48:02 -04006894 gl::Error error = context->clearBufferfi(buffer, drawbuffer, depth, stencil);
6895 if (error.isError())
6896 {
6897 context->recordError(error);
6898 return;
6899 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006900 }
6901}
6902
Kenneth Russell67ea1902014-10-06 16:44:50 -07006903const GLubyte* GL_APIENTRY glGetStringi(GLenum name, GLuint index)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006904{
6905 EVENT("(GLenum name = 0x%X, GLuint index = %u)", name, index);
6906
Geoff Langbfdea662014-07-23 14:16:32 -04006907 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006908 if (context)
6909 {
6910 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006911 {
Geoff Langb1196682014-07-23 13:47:29 -04006912 context->recordError(gl::Error(GL_INVALID_OPERATION));
6913 return NULL;
shannonwoods@chromium.org302df742013-05-30 00:05:54 +00006914 }
Geoff Langbfdea662014-07-23 14:16:32 -04006915
6916 if (name != GL_EXTENSIONS)
6917 {
Geoff Langb1196682014-07-23 13:47:29 -04006918 context->recordError(gl::Error(GL_INVALID_ENUM));
6919 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006920 }
6921
6922 if (index >= context->getExtensionStringCount())
6923 {
Geoff Langb1196682014-07-23 13:47:29 -04006924 context->recordError(gl::Error(GL_INVALID_VALUE));
6925 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04006926 }
6927
6928 return reinterpret_cast<const GLubyte*>(context->getExtensionString(index).c_str());
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006929 }
6930
6931 return NULL;
6932}
6933
Kenneth Russell67ea1902014-10-06 16:44:50 -07006934void GL_APIENTRY glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006935{
6936 EVENT("(GLenum readTarget = 0x%X, GLenum writeTarget = 0x%X, GLintptr readOffset = %d, GLintptr writeOffset = %d, GLsizeiptr size = %d)",
6937 readTarget, writeTarget, readOffset, writeOffset, size);
6938
Geoff Langbfdea662014-07-23 14:16:32 -04006939 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04006940 if (context)
6941 {
6942 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006943 {
Geoff Langb1196682014-07-23 13:47:29 -04006944 context->recordError(gl::Error(GL_INVALID_OPERATION));
6945 return;
shannon.woods%transgaming.com@gtempaccount.com296c3f22013-04-13 03:39:39 +00006946 }
Geoff Langbfdea662014-07-23 14:16:32 -04006947
Jamie Madill24e83192014-10-20 11:00:53 -04006948 if (!gl::ValidBufferTarget(context, readTarget) || !gl::ValidBufferTarget(context, writeTarget))
Geoff Langbfdea662014-07-23 14:16:32 -04006949 {
Geoff Langb1196682014-07-23 13:47:29 -04006950 context->recordError(gl::Error(GL_INVALID_ENUM));
6951 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006952 }
6953
6954 gl::Buffer *readBuffer = context->getState().getTargetBuffer(readTarget);
6955 gl::Buffer *writeBuffer = context->getState().getTargetBuffer(writeTarget);
6956
6957 if (!readBuffer || !writeBuffer)
6958 {
Geoff Langb1196682014-07-23 13:47:29 -04006959 context->recordError(gl::Error(GL_INVALID_OPERATION));
6960 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006961 }
6962
Jamie Madillcfaaf722014-07-31 10:47:54 -04006963 // Verify that readBuffer and writeBuffer are not currently mapped
Geoff Langbfdea662014-07-23 14:16:32 -04006964 if (readBuffer->isMapped() || writeBuffer->isMapped())
6965 {
Geoff Langb1196682014-07-23 13:47:29 -04006966 context->recordError(gl::Error(GL_INVALID_OPERATION));
6967 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006968 }
6969
6970 if (readOffset < 0 || writeOffset < 0 || size < 0 ||
6971 static_cast<unsigned int>(readOffset + size) > readBuffer->getSize() ||
6972 static_cast<unsigned int>(writeOffset + size) > writeBuffer->getSize())
6973 {
Geoff Langb1196682014-07-23 13:47:29 -04006974 context->recordError(gl::Error(GL_INVALID_VALUE));
6975 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006976 }
6977
Kenneth Russell67ea1902014-10-06 16:44:50 -07006978 if (readBuffer == writeBuffer && std::abs(readOffset - writeOffset) < size)
Geoff Langbfdea662014-07-23 14:16:32 -04006979 {
Geoff Langb1196682014-07-23 13:47:29 -04006980 context->recordError(gl::Error(GL_INVALID_VALUE));
6981 return;
Geoff Langbfdea662014-07-23 14:16:32 -04006982 }
6983
Geoff Langbfdea662014-07-23 14:16:32 -04006984 // if size is zero, the copy is a successful no-op
6985 if (size > 0)
6986 {
Geoff Lang2a1c15a2014-07-25 11:43:00 -04006987 gl::Error error = writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size);
6988 if (error.isError())
6989 {
6990 context->recordError(error);
6991 return;
6992 }
Geoff Langbfdea662014-07-23 14:16:32 -04006993 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006994 }
6995}
6996
Kenneth Russell67ea1902014-10-06 16:44:50 -07006997void GL_APIENTRY glGetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00006998{
6999 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLchar* const* uniformNames = 0x%0.8p, GLuint* uniformIndices = 0x%0.8p)",
7000 program, uniformCount, uniformNames, uniformIndices);
7001
Geoff Langbfdea662014-07-23 14:16:32 -04007002 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007003 if (context)
7004 {
7005 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007006 {
Geoff Langb1196682014-07-23 13:47:29 -04007007 context->recordError(gl::Error(GL_INVALID_OPERATION));
7008 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007009 }
7010
7011 if (uniformCount < 0)
7012 {
Geoff Langb1196682014-07-23 13:47:29 -04007013 context->recordError(gl::Error(GL_INVALID_VALUE));
7014 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007015 }
7016
7017 gl::Program *programObject = context->getProgram(program);
7018
7019 if (!programObject)
7020 {
7021 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007022 {
Geoff Langb1196682014-07-23 13:47:29 -04007023 context->recordError(gl::Error(GL_INVALID_OPERATION));
7024 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007025 }
Geoff Langbfdea662014-07-23 14:16:32 -04007026 else
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007027 {
Geoff Langb1196682014-07-23 13:47:29 -04007028 context->recordError(gl::Error(GL_INVALID_VALUE));
7029 return;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007030 }
Geoff Langbfdea662014-07-23 14:16:32 -04007031 }
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007032
Geoff Langbfdea662014-07-23 14:16:32 -04007033 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7034 if (!programObject->isLinked() || !programBinary)
7035 {
7036 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007037 {
Geoff Langbfdea662014-07-23 14:16:32 -04007038 uniformIndices[uniformId] = GL_INVALID_INDEX;
shannonwoods@chromium.orgc2ed9912013-05-30 00:05:33 +00007039 }
7040 }
Geoff Langbfdea662014-07-23 14:16:32 -04007041 else
7042 {
7043 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7044 {
7045 uniformIndices[uniformId] = programBinary->getUniformIndex(uniformNames[uniformId]);
7046 }
7047 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007048 }
7049}
7050
Kenneth Russell67ea1902014-10-06 16:44:50 -07007051void GL_APIENTRY glGetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007052{
7053 EVENT("(GLuint program = %u, GLsizei uniformCount = %d, const GLuint* uniformIndices = 0x%0.8p, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7054 program, uniformCount, uniformIndices, pname, params);
7055
Geoff Langbfdea662014-07-23 14:16:32 -04007056 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007057 if (context)
7058 {
7059 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007060 {
Geoff Langb1196682014-07-23 13:47:29 -04007061 context->recordError(gl::Error(GL_INVALID_OPERATION));
7062 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007063 }
7064
7065 if (uniformCount < 0)
7066 {
Geoff Langb1196682014-07-23 13:47:29 -04007067 context->recordError(gl::Error(GL_INVALID_VALUE));
7068 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007069 }
7070
7071 gl::Program *programObject = context->getProgram(program);
7072
7073 if (!programObject)
7074 {
7075 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007076 {
Geoff Langb1196682014-07-23 13:47:29 -04007077 context->recordError(gl::Error(GL_INVALID_OPERATION));
7078 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007079 }
Geoff Langbfdea662014-07-23 14:16:32 -04007080 else
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007081 {
Geoff Langb1196682014-07-23 13:47:29 -04007082 context->recordError(gl::Error(GL_INVALID_VALUE));
7083 return;
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007084 }
shannonwoods@chromium.org2a9a9d22013-05-30 00:05:40 +00007085 }
Geoff Langbfdea662014-07-23 14:16:32 -04007086
7087 switch (pname)
7088 {
7089 case GL_UNIFORM_TYPE:
7090 case GL_UNIFORM_SIZE:
7091 case GL_UNIFORM_NAME_LENGTH:
7092 case GL_UNIFORM_BLOCK_INDEX:
7093 case GL_UNIFORM_OFFSET:
7094 case GL_UNIFORM_ARRAY_STRIDE:
7095 case GL_UNIFORM_MATRIX_STRIDE:
7096 case GL_UNIFORM_IS_ROW_MAJOR:
7097 break;
Geoff Langb1196682014-07-23 13:47:29 -04007098
Geoff Langbfdea662014-07-23 14:16:32 -04007099 default:
Geoff Langb1196682014-07-23 13:47:29 -04007100 context->recordError(gl::Error(GL_INVALID_ENUM));
7101 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007102 }
7103
7104 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7105
7106 if (!programBinary && uniformCount > 0)
7107 {
Geoff Langb1196682014-07-23 13:47:29 -04007108 context->recordError(gl::Error(GL_INVALID_VALUE));
7109 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007110 }
7111
7112 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7113 {
7114 const GLuint index = uniformIndices[uniformId];
7115
7116 if (index >= (GLuint)programBinary->getActiveUniformCount())
7117 {
Geoff Langb1196682014-07-23 13:47:29 -04007118 context->recordError(gl::Error(GL_INVALID_VALUE));
7119 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007120 }
7121 }
7122
7123 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
7124 {
7125 const GLuint index = uniformIndices[uniformId];
7126 params[uniformId] = programBinary->getActiveUniformi(index, pname);
7127 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007128 }
7129}
7130
Kenneth Russell67ea1902014-10-06 16:44:50 -07007131GLuint GL_APIENTRY glGetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007132{
7133 EVENT("(GLuint program = %u, const GLchar* uniformBlockName = 0x%0.8p)", program, uniformBlockName);
7134
Geoff Langbfdea662014-07-23 14:16:32 -04007135 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007136 if (context)
7137 {
7138 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007139 {
Geoff Langb1196682014-07-23 13:47:29 -04007140 context->recordError(gl::Error(GL_INVALID_OPERATION));
7141 return GL_INVALID_INDEX;
Geoff Langbfdea662014-07-23 14:16:32 -04007142 }
7143
7144 gl::Program *programObject = context->getProgram(program);
7145
7146 if (!programObject)
7147 {
7148 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007149 {
Geoff Langb1196682014-07-23 13:47:29 -04007150 context->recordError(gl::Error(GL_INVALID_OPERATION));
7151 return GL_INVALID_INDEX;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007152 }
Geoff Langbfdea662014-07-23 14:16:32 -04007153 else
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007154 {
Geoff Langb1196682014-07-23 13:47:29 -04007155 context->recordError(gl::Error(GL_INVALID_VALUE));
7156 return GL_INVALID_INDEX;
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007157 }
shannonwoods@chromium.org42766252013-05-30 00:07:12 +00007158 }
Geoff Langbfdea662014-07-23 14:16:32 -04007159
7160 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7161 if (!programBinary)
7162 {
7163 return GL_INVALID_INDEX;
7164 }
7165
7166 return programBinary->getUniformBlockIndex(uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007167 }
7168
7169 return 0;
7170}
7171
Kenneth Russell67ea1902014-10-06 16:44:50 -07007172void GL_APIENTRY glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007173{
7174 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)",
7175 program, uniformBlockIndex, pname, params);
7176
Geoff Langbfdea662014-07-23 14:16:32 -04007177 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007178 if (context)
7179 {
7180 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007181 {
Geoff Langb1196682014-07-23 13:47:29 -04007182 context->recordError(gl::Error(GL_INVALID_OPERATION));
7183 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007184 }
7185 gl::Program *programObject = context->getProgram(program);
7186
7187 if (!programObject)
7188 {
7189 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007190 {
Geoff Langb1196682014-07-23 13:47:29 -04007191 context->recordError(gl::Error(GL_INVALID_OPERATION));
7192 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007193 }
Geoff Langbfdea662014-07-23 14:16:32 -04007194 else
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007195 {
Geoff Langb1196682014-07-23 13:47:29 -04007196 context->recordError(gl::Error(GL_INVALID_VALUE));
7197 return;
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007198 }
shannonwoods@chromium.orge7317ca2013-05-30 00:07:35 +00007199 }
Geoff Langbfdea662014-07-23 14:16:32 -04007200
7201 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7202
7203 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7204 {
Geoff Langb1196682014-07-23 13:47:29 -04007205 context->recordError(gl::Error(GL_INVALID_VALUE));
7206 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007207 }
7208
7209 switch (pname)
7210 {
7211 case GL_UNIFORM_BLOCK_BINDING:
7212 *params = static_cast<GLint>(programObject->getUniformBlockBinding(uniformBlockIndex));
7213 break;
7214
7215 case GL_UNIFORM_BLOCK_DATA_SIZE:
7216 case GL_UNIFORM_BLOCK_NAME_LENGTH:
7217 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
7218 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
7219 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
7220 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
7221 programBinary->getActiveUniformBlockiv(uniformBlockIndex, pname, params);
7222 break;
7223
7224 default:
Geoff Langb1196682014-07-23 13:47:29 -04007225 context->recordError(gl::Error(GL_INVALID_ENUM));
7226 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007227 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007228 }
7229}
7230
Kenneth Russell67ea1902014-10-06 16:44:50 -07007231void GL_APIENTRY glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007232{
7233 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLchar* uniformBlockName = 0x%0.8p)",
7234 program, uniformBlockIndex, bufSize, length, uniformBlockName);
7235
Geoff Langbfdea662014-07-23 14:16:32 -04007236 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007237 if (context)
7238 {
7239 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007240 {
Geoff Langb1196682014-07-23 13:47:29 -04007241 context->recordError(gl::Error(GL_INVALID_OPERATION));
7242 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007243 }
7244
7245 gl::Program *programObject = context->getProgram(program);
7246
7247 if (!programObject)
7248 {
7249 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007250 {
Geoff Langb1196682014-07-23 13:47:29 -04007251 context->recordError(gl::Error(GL_INVALID_OPERATION));
7252 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007253 }
Geoff Langbfdea662014-07-23 14:16:32 -04007254 else
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007255 {
Geoff Langb1196682014-07-23 13:47:29 -04007256 context->recordError(gl::Error(GL_INVALID_VALUE));
7257 return;
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007258 }
shannonwoods@chromium.orgbeb02782013-05-30 00:07:28 +00007259 }
Geoff Langbfdea662014-07-23 14:16:32 -04007260
7261 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7262
7263 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7264 {
Geoff Langb1196682014-07-23 13:47:29 -04007265 context->recordError(gl::Error(GL_INVALID_VALUE));
7266 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007267 }
7268
7269 programBinary->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007270 }
7271}
7272
Kenneth Russell67ea1902014-10-06 16:44:50 -07007273void GL_APIENTRY glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007274{
7275 EVENT("(GLuint program = %u, GLuint uniformBlockIndex = %u, GLuint uniformBlockBinding = %u)",
7276 program, uniformBlockIndex, uniformBlockBinding);
7277
Geoff Langbfdea662014-07-23 14:16:32 -04007278 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007279 if (context)
7280 {
7281 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007282 {
Geoff Langb1196682014-07-23 13:47:29 -04007283 context->recordError(gl::Error(GL_INVALID_OPERATION));
7284 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007285 }
7286
Geoff Lang3a61c322014-07-10 13:01:54 -04007287 if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings)
Geoff Langbfdea662014-07-23 14:16:32 -04007288 {
Geoff Langb1196682014-07-23 13:47:29 -04007289 context->recordError(gl::Error(GL_INVALID_VALUE));
7290 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007291 }
7292
7293 gl::Program *programObject = context->getProgram(program);
7294
7295 if (!programObject)
7296 {
7297 if (context->getShader(program))
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007298 {
Geoff Langb1196682014-07-23 13:47:29 -04007299 context->recordError(gl::Error(GL_INVALID_OPERATION));
7300 return;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007301 }
Geoff Langbfdea662014-07-23 14:16:32 -04007302 else
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007303 {
Geoff Langb1196682014-07-23 13:47:29 -04007304 context->recordError(gl::Error(GL_INVALID_VALUE));
7305 return;
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007306 }
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +00007307 }
Geoff Langbfdea662014-07-23 14:16:32 -04007308
7309 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
7310
7311 // if never linked, there won't be any uniform blocks
7312 if (!programBinary || uniformBlockIndex >= programBinary->getActiveUniformBlockCount())
7313 {
Geoff Langb1196682014-07-23 13:47:29 -04007314 context->recordError(gl::Error(GL_INVALID_VALUE));
7315 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007316 }
7317
7318 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007319 }
7320}
7321
Kenneth Russell67ea1902014-10-06 16:44:50 -07007322void GL_APIENTRY glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007323{
7324 EVENT("(GLenum mode = 0x%X, GLint first = %d, GLsizei count = %d, GLsizei instanceCount = %d)",
7325 mode, first, count, instanceCount);
7326
Geoff Langbfdea662014-07-23 14:16:32 -04007327 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007328 if (context)
7329 {
7330 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007331 {
Geoff Langb1196682014-07-23 13:47:29 -04007332 context->recordError(gl::Error(GL_INVALID_OPERATION));
7333 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007334 }
Geoff Langbfdea662014-07-23 14:16:32 -04007335
7336 // glDrawArraysInstanced
7337 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007338 }
7339}
7340
Kenneth Russell67ea1902014-10-06 16:44:50 -07007341void GL_APIENTRY glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007342{
7343 EVENT("(GLenum mode = 0x%X, GLsizei count = %d, GLenum type = 0x%X, const GLvoid* indices = 0x%0.8p, GLsizei instanceCount = %d)",
7344 mode, count, type, indices, instanceCount);
7345
Geoff Langbfdea662014-07-23 14:16:32 -04007346 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007347 if (context)
7348 {
7349 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007350 {
Geoff Langb1196682014-07-23 13:47:29 -04007351 context->recordError(gl::Error(GL_INVALID_OPERATION));
7352 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007353 }
Geoff Langbfdea662014-07-23 14:16:32 -04007354
7355 // glDrawElementsInstanced
7356 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007357 }
7358}
7359
Kenneth Russell67ea1902014-10-06 16:44:50 -07007360GLsync GL_APIENTRY glFenceSync(GLenum condition, GLbitfield flags)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007361{
7362 EVENT("(GLenum condition = 0x%X, GLbitfield flags = 0x%X)", condition, flags);
7363
Geoff Langbfdea662014-07-23 14:16:32 -04007364 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007365 if (context)
7366 {
7367 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007368 {
Geoff Langb1196682014-07-23 13:47:29 -04007369 context->recordError(gl::Error(GL_INVALID_OPERATION));
7370 return 0;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007371 }
Geoff Langbfdea662014-07-23 14:16:32 -04007372
7373 if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE)
7374 {
Geoff Langb1196682014-07-23 13:47:29 -04007375 context->recordError(gl::Error(GL_INVALID_ENUM));
7376 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007377 }
7378
7379 if (flags != 0)
7380 {
Geoff Langb1196682014-07-23 13:47:29 -04007381 context->recordError(gl::Error(GL_INVALID_VALUE));
7382 return 0;
Geoff Langbfdea662014-07-23 14:16:32 -04007383 }
7384
Geoff Lang882033e2014-09-30 11:26:07 -04007385 GLsync fenceSync = context->createFenceSync();
7386
7387 gl::FenceSync *fenceSyncObject = context->getFenceSync(fenceSync);
7388 gl::Error error = fenceSyncObject->set(condition);
7389 if (error.isError())
7390 {
7391 context->deleteFenceSync(fenceSync);
7392 context->recordError(error);
7393 return NULL;
7394 }
7395
7396 return fenceSync;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007397 }
7398
7399 return NULL;
7400}
7401
Kenneth Russell67ea1902014-10-06 16:44:50 -07007402GLboolean GL_APIENTRY glIsSync(GLsync sync)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007403{
7404 EVENT("(GLsync sync = 0x%0.8p)", sync);
7405
Geoff Langbfdea662014-07-23 14:16:32 -04007406 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007407 if (context)
7408 {
7409 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007410 {
Geoff Langb1196682014-07-23 13:47:29 -04007411 context->recordError(gl::Error(GL_INVALID_OPERATION));
7412 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007413 }
Geoff Langbfdea662014-07-23 14:16:32 -04007414
7415 return (context->getFenceSync(sync) != NULL);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007416 }
7417
7418 return GL_FALSE;
7419}
7420
Kenneth Russell67ea1902014-10-06 16:44:50 -07007421void GL_APIENTRY glDeleteSync(GLsync sync)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007422{
7423 EVENT("(GLsync sync = 0x%0.8p)", sync);
7424
Geoff Langbfdea662014-07-23 14:16:32 -04007425 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007426 if (context)
7427 {
7428 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007429 {
Geoff Langb1196682014-07-23 13:47:29 -04007430 context->recordError(gl::Error(GL_INVALID_OPERATION));
7431 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007432 }
Geoff Langbfdea662014-07-23 14:16:32 -04007433
7434 if (sync != static_cast<GLsync>(0) && !context->getFenceSync(sync))
7435 {
Geoff Langb1196682014-07-23 13:47:29 -04007436 context->recordError(gl::Error(GL_INVALID_VALUE));
7437 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007438 }
7439
7440 context->deleteFenceSync(sync);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007441 }
7442}
7443
Kenneth Russell67ea1902014-10-06 16:44:50 -07007444GLenum GL_APIENTRY glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007445{
7446 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7447 sync, flags, timeout);
7448
Geoff Langbfdea662014-07-23 14:16:32 -04007449 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007450 if (context)
7451 {
7452 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007453 {
Geoff Langb1196682014-07-23 13:47:29 -04007454 context->recordError(gl::Error(GL_INVALID_OPERATION));
7455 return GL_WAIT_FAILED;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007456 }
Geoff Langbfdea662014-07-23 14:16:32 -04007457
7458 if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0)
7459 {
Geoff Langb1196682014-07-23 13:47:29 -04007460 context->recordError(gl::Error(GL_INVALID_VALUE));
7461 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007462 }
7463
7464 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7465
7466 if (!fenceSync)
7467 {
Geoff Langb1196682014-07-23 13:47:29 -04007468 context->recordError(gl::Error(GL_INVALID_VALUE));
7469 return GL_WAIT_FAILED;
Geoff Langbfdea662014-07-23 14:16:32 -04007470 }
7471
Geoff Lang882033e2014-09-30 11:26:07 -04007472 GLenum result = GL_WAIT_FAILED;
7473 gl::Error error = fenceSync->clientWait(flags, timeout, &result);
7474 if (error.isError())
7475 {
7476 context->recordError(error);
7477 return GL_WAIT_FAILED;
7478 }
7479
7480 return result;
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007481 }
7482
7483 return GL_FALSE;
7484}
7485
Kenneth Russell67ea1902014-10-06 16:44:50 -07007486void GL_APIENTRY glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007487{
7488 EVENT("(GLsync sync = 0x%0.8p, GLbitfield flags = 0x%X, GLuint64 timeout = %llu)",
7489 sync, flags, timeout);
7490
Geoff Langbfdea662014-07-23 14:16:32 -04007491 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007492 if (context)
7493 {
7494 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007495 {
Geoff Langb1196682014-07-23 13:47:29 -04007496 context->recordError(gl::Error(GL_INVALID_OPERATION));
7497 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007498 }
Geoff Langbfdea662014-07-23 14:16:32 -04007499
7500 if (flags != 0)
7501 {
Geoff Langb1196682014-07-23 13:47:29 -04007502 context->recordError(gl::Error(GL_INVALID_VALUE));
7503 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007504 }
7505
7506 if (timeout != GL_TIMEOUT_IGNORED)
7507 {
Geoff Langb1196682014-07-23 13:47:29 -04007508 context->recordError(gl::Error(GL_INVALID_VALUE));
7509 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007510 }
7511
7512 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7513
7514 if (!fenceSync)
7515 {
Geoff Langb1196682014-07-23 13:47:29 -04007516 context->recordError(gl::Error(GL_INVALID_VALUE));
7517 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007518 }
7519
Kenneth Russellcaa549c2014-10-10 17:52:59 -07007520 gl::Error error = fenceSync->serverWait(flags, timeout);
Geoff Lang882033e2014-09-30 11:26:07 -04007521 if (error.isError())
7522 {
7523 context->recordError(error);
7524 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007525 }
7526}
7527
Kenneth Russell67ea1902014-10-06 16:44:50 -07007528void GL_APIENTRY glGetInteger64v(GLenum pname, GLint64* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007529{
7530 EVENT("(GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7531 pname, params);
7532
Geoff Langbfdea662014-07-23 14:16:32 -04007533 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007534 if (context)
7535 {
7536 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007537 {
Geoff Langb1196682014-07-23 13:47:29 -04007538 context->recordError(gl::Error(GL_INVALID_OPERATION));
7539 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007540 }
Geoff Langbfdea662014-07-23 14:16:32 -04007541
7542 GLenum nativeType;
7543 unsigned int numParams = 0;
7544 if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
7545 {
7546 return;
7547 }
7548
7549 if (nativeType == GL_INT_64_ANGLEX)
7550 {
7551 context->getInteger64v(pname, params);
7552 }
7553 else
7554 {
7555 CastStateValues(context, nativeType, pname, numParams, params);
7556 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007557 }
7558}
7559
Kenneth Russell67ea1902014-10-06 16:44:50 -07007560void GL_APIENTRY glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007561{
7562 EVENT("(GLsync sync = 0x%0.8p, GLenum pname = 0x%X, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLint* values = 0x%0.8p)",
7563 sync, pname, bufSize, length, values);
7564
Geoff Langbfdea662014-07-23 14:16:32 -04007565 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007566 if (context)
7567 {
7568 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007569 {
Geoff Langb1196682014-07-23 13:47:29 -04007570 context->recordError(gl::Error(GL_INVALID_OPERATION));
7571 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007572 }
Geoff Langbfdea662014-07-23 14:16:32 -04007573
7574 if (bufSize < 0)
7575 {
Geoff Langb1196682014-07-23 13:47:29 -04007576 context->recordError(gl::Error(GL_INVALID_VALUE));
7577 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007578 }
7579
7580 gl::FenceSync *fenceSync = context->getFenceSync(sync);
7581
7582 if (!fenceSync)
7583 {
Geoff Langb1196682014-07-23 13:47:29 -04007584 context->recordError(gl::Error(GL_INVALID_VALUE));
7585 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007586 }
7587
7588 switch (pname)
7589 {
7590 case GL_OBJECT_TYPE: values[0] = static_cast<GLint>(GL_SYNC_FENCE); break;
Geoff Langbfdea662014-07-23 14:16:32 -04007591 case GL_SYNC_CONDITION: values[0] = static_cast<GLint>(fenceSync->getCondition()); break;
7592 case GL_SYNC_FLAGS: values[0] = 0; break;
7593
Geoff Lang882033e2014-09-30 11:26:07 -04007594 case GL_SYNC_STATUS:
7595 {
7596 gl::Error error = fenceSync->getStatus(values);
7597 if (error.isError())
7598 {
7599 context->recordError(error);
7600 return;
7601 }
7602 break;
7603 }
7604
Geoff Langbfdea662014-07-23 14:16:32 -04007605 default:
Geoff Langb1196682014-07-23 13:47:29 -04007606 context->recordError(gl::Error(GL_INVALID_ENUM));
7607 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007608 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007609 }
7610}
7611
Kenneth Russell67ea1902014-10-06 16:44:50 -07007612void GL_APIENTRY glGetInteger64i_v(GLenum target, GLuint index, GLint64* data)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007613{
7614 EVENT("(GLenum target = 0x%X, GLuint index = %u, GLint64* data = 0x%0.8p)",
7615 target, index, data);
7616
Geoff Langbfdea662014-07-23 14:16:32 -04007617 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007618 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007619 {
Geoff Langbfdea662014-07-23 14:16:32 -04007620 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007621 {
Geoff Langb1196682014-07-23 13:47:29 -04007622 context->recordError(gl::Error(GL_INVALID_OPERATION));
7623 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007624 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007625
Geoff Lang3a61c322014-07-10 13:01:54 -04007626 const gl::Caps &caps = context->getCaps();
Geoff Langbfdea662014-07-23 14:16:32 -04007627 switch (target)
7628 {
7629 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7630 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7631 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
Geoff Lang05881a02014-07-10 14:05:30 -04007632 if (index >= caps.maxTransformFeedbackSeparateAttributes)
7633 {
Geoff Langb1196682014-07-23 13:47:29 -04007634 context->recordError(gl::Error(GL_INVALID_VALUE));
7635 return;
Geoff Lang05881a02014-07-10 14:05:30 -04007636 }
Geoff Langbfdea662014-07-23 14:16:32 -04007637 break;
Geoff Langb1196682014-07-23 13:47:29 -04007638
Geoff Langbfdea662014-07-23 14:16:32 -04007639 case GL_UNIFORM_BUFFER_START:
7640 case GL_UNIFORM_BUFFER_SIZE:
7641 case GL_UNIFORM_BUFFER_BINDING:
Geoff Lang3a61c322014-07-10 13:01:54 -04007642 if (index >= caps.maxUniformBufferBindings)
7643 {
Geoff Langb1196682014-07-23 13:47:29 -04007644 context->recordError(gl::Error(GL_INVALID_VALUE));
7645 return;
Geoff Lang3a61c322014-07-10 13:01:54 -04007646 }
Geoff Langbfdea662014-07-23 14:16:32 -04007647 break;
Geoff Langb1196682014-07-23 13:47:29 -04007648
Geoff Langbfdea662014-07-23 14:16:32 -04007649 default:
Geoff Langb1196682014-07-23 13:47:29 -04007650 context->recordError(gl::Error(GL_INVALID_ENUM));
7651 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007652 }
7653
7654 if (!(context->getIndexedInteger64v(target, index, data)))
7655 {
7656 GLenum nativeType;
7657 unsigned int numParams = 0;
7658 if (!context->getIndexedQueryParameterInfo(target, &nativeType, &numParams))
Geoff Langb1196682014-07-23 13:47:29 -04007659 {
7660 context->recordError(gl::Error(GL_INVALID_ENUM));
7661 return;
7662 }
Shannon Woods15934d52013-08-19 14:28:49 -04007663
Geoff Langbfdea662014-07-23 14:16:32 -04007664 if (numParams == 0)
7665 return; // it is known that pname is valid, but there are no parameters to return
7666
7667 if (nativeType == GL_INT)
Shannon Woods15934d52013-08-19 14:28:49 -04007668 {
Geoff Langbfdea662014-07-23 14:16:32 -04007669 GLint *intParams = new GLint[numParams];
Shannon Woods15934d52013-08-19 14:28:49 -04007670
Geoff Langbfdea662014-07-23 14:16:32 -04007671 context->getIndexedIntegerv(target, index, intParams);
Shannon Woods15934d52013-08-19 14:28:49 -04007672
Geoff Langbfdea662014-07-23 14:16:32 -04007673 for (unsigned int i = 0; i < numParams; ++i)
Shannon Woods15934d52013-08-19 14:28:49 -04007674 {
Geoff Langbfdea662014-07-23 14:16:32 -04007675 data[i] = static_cast<GLint64>(intParams[i]);
Shannon Woods15934d52013-08-19 14:28:49 -04007676 }
Geoff Langbfdea662014-07-23 14:16:32 -04007677
7678 delete [] intParams;
7679 }
7680 else
7681 {
7682 UNREACHABLE();
Shannon Woods15934d52013-08-19 14:28:49 -04007683 }
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007684 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007685 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007686}
7687
Kenneth Russell67ea1902014-10-06 16:44:50 -07007688void GL_APIENTRY glGetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007689{
7690 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLint64* params = 0x%0.8p)",
7691 target, pname, params);
7692
Geoff Langbfdea662014-07-23 14:16:32 -04007693 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007694 if (context)
7695 {
7696 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007697 {
Geoff Langb1196682014-07-23 13:47:29 -04007698 context->recordError(gl::Error(GL_INVALID_OPERATION));
7699 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007700 }
Geoff Langbfdea662014-07-23 14:16:32 -04007701
7702 if (!gl::ValidBufferTarget(context, target))
7703 {
Geoff Langb1196682014-07-23 13:47:29 -04007704 context->recordError(gl::Error(GL_INVALID_ENUM));
7705 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007706 }
7707
7708 if (!gl::ValidBufferParameter(context, pname))
7709 {
Geoff Langb1196682014-07-23 13:47:29 -04007710 context->recordError(gl::Error(GL_INVALID_ENUM));
7711 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007712 }
7713
7714 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
7715
7716 if (!buffer)
7717 {
7718 // A null buffer means that "0" is bound to the requested buffer target
Geoff Langb1196682014-07-23 13:47:29 -04007719 context->recordError(gl::Error(GL_INVALID_OPERATION));
7720 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007721 }
7722
7723 switch (pname)
7724 {
7725 case GL_BUFFER_USAGE:
7726 *params = static_cast<GLint64>(buffer->getUsage());
7727 break;
7728 case GL_BUFFER_SIZE:
7729 *params = buffer->getSize();
7730 break;
7731 case GL_BUFFER_ACCESS_FLAGS:
7732 *params = static_cast<GLint64>(buffer->getAccessFlags());
7733 break;
7734 case GL_BUFFER_MAPPED:
7735 *params = static_cast<GLint64>(buffer->isMapped());
7736 break;
7737 case GL_BUFFER_MAP_OFFSET:
7738 *params = buffer->getMapOffset();
7739 break;
7740 case GL_BUFFER_MAP_LENGTH:
7741 *params = buffer->getMapLength();
7742 break;
7743 default: UNREACHABLE(); break;
7744 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007745 }
7746}
7747
Kenneth Russell67ea1902014-10-06 16:44:50 -07007748void GL_APIENTRY glGenSamplers(GLsizei count, GLuint* samplers)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007749{
7750 EVENT("(GLsizei count = %d, GLuint* samplers = 0x%0.8p)", count, samplers);
7751
Geoff Langbfdea662014-07-23 14:16:32 -04007752 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007753 if (context)
7754 {
7755 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007756 {
Geoff Langb1196682014-07-23 13:47:29 -04007757 context->recordError(gl::Error(GL_INVALID_OPERATION));
7758 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007759 }
Geoff Langbfdea662014-07-23 14:16:32 -04007760
7761 if (count < 0)
7762 {
Geoff Langb1196682014-07-23 13:47:29 -04007763 context->recordError(gl::Error(GL_INVALID_VALUE));
7764 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007765 }
7766
7767 for (int i = 0; i < count; i++)
7768 {
7769 samplers[i] = context->createSampler();
7770 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007771 }
7772}
7773
Kenneth Russell67ea1902014-10-06 16:44:50 -07007774void GL_APIENTRY glDeleteSamplers(GLsizei count, const GLuint* samplers)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007775{
7776 EVENT("(GLsizei count = %d, const GLuint* samplers = 0x%0.8p)", count, samplers);
7777
Geoff Langbfdea662014-07-23 14:16:32 -04007778 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007779 if (context)
7780 {
7781 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007782 {
Geoff Langb1196682014-07-23 13:47:29 -04007783 context->recordError(gl::Error(GL_INVALID_OPERATION));
7784 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007785 }
Geoff Langbfdea662014-07-23 14:16:32 -04007786
7787 if (count < 0)
7788 {
Geoff Langb1196682014-07-23 13:47:29 -04007789 context->recordError(gl::Error(GL_INVALID_VALUE));
7790 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007791 }
7792
7793 for (int i = 0; i < count; i++)
7794 {
7795 context->deleteSampler(samplers[i]);
7796 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007797 }
7798}
7799
Kenneth Russell67ea1902014-10-06 16:44:50 -07007800GLboolean GL_APIENTRY glIsSampler(GLuint sampler)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007801{
7802 EVENT("(GLuint sampler = %u)", sampler);
7803
Geoff Langbfdea662014-07-23 14:16:32 -04007804 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007805 if (context)
7806 {
7807 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007808 {
Geoff Langb1196682014-07-23 13:47:29 -04007809 context->recordError(gl::Error(GL_INVALID_OPERATION));
7810 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007811 }
Geoff Langbfdea662014-07-23 14:16:32 -04007812
7813 return context->isSampler(sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007814 }
7815
7816 return GL_FALSE;
7817}
7818
Kenneth Russell67ea1902014-10-06 16:44:50 -07007819void GL_APIENTRY glBindSampler(GLuint unit, GLuint sampler)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007820{
7821 EVENT("(GLuint unit = %u, GLuint sampler = %u)", unit, sampler);
7822
Geoff Langbfdea662014-07-23 14:16:32 -04007823 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007824 if (context)
7825 {
7826 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007827 {
Geoff Langb1196682014-07-23 13:47:29 -04007828 context->recordError(gl::Error(GL_INVALID_OPERATION));
7829 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007830 }
Geoff Langbfdea662014-07-23 14:16:32 -04007831
7832 if (sampler != 0 && !context->isSampler(sampler))
7833 {
Geoff Langb1196682014-07-23 13:47:29 -04007834 context->recordError(gl::Error(GL_INVALID_OPERATION));
7835 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007836 }
7837
Geoff Lang3a61c322014-07-10 13:01:54 -04007838 if (unit >= context->getCaps().maxCombinedTextureImageUnits)
Geoff Langbfdea662014-07-23 14:16:32 -04007839 {
Geoff Langb1196682014-07-23 13:47:29 -04007840 context->recordError(gl::Error(GL_INVALID_VALUE));
7841 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007842 }
7843
7844 context->bindSampler(unit, sampler);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007845 }
7846}
7847
Kenneth Russell67ea1902014-10-06 16:44:50 -07007848void GL_APIENTRY glSamplerParameteri(GLuint sampler, GLenum pname, GLint param)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007849{
7850 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint param = %d)", sampler, pname, param);
7851
Geoff Langbfdea662014-07-23 14:16:32 -04007852 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007853 if (context)
7854 {
7855 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007856 {
Geoff Langb1196682014-07-23 13:47:29 -04007857 context->recordError(gl::Error(GL_INVALID_OPERATION));
7858 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007859 }
Geoff Langbfdea662014-07-23 14:16:32 -04007860
Geoff Langb1196682014-07-23 13:47:29 -04007861 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007862 {
7863 return;
7864 }
7865
7866 if (!gl::ValidateTexParamParameters(context, pname, param))
7867 {
7868 return;
7869 }
7870
7871 if (!context->isSampler(sampler))
7872 {
Geoff Langb1196682014-07-23 13:47:29 -04007873 context->recordError(gl::Error(GL_INVALID_OPERATION));
7874 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007875 }
7876
7877 context->samplerParameteri(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007878 }
7879}
7880
Kenneth Russell67ea1902014-10-06 16:44:50 -07007881void GL_APIENTRY glSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007882{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007883 glSamplerParameteri(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007884}
7885
Kenneth Russell67ea1902014-10-06 16:44:50 -07007886void GL_APIENTRY glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007887{
7888 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLfloat param = %g)", sampler, pname, param);
7889
Geoff Langbfdea662014-07-23 14:16:32 -04007890 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007891 if (context)
7892 {
7893 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007894 {
Geoff Langb1196682014-07-23 13:47:29 -04007895 context->recordError(gl::Error(GL_INVALID_OPERATION));
7896 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007897 }
Geoff Langbfdea662014-07-23 14:16:32 -04007898
Geoff Langb1196682014-07-23 13:47:29 -04007899 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007900 {
7901 return;
7902 }
7903
7904 if (!gl::ValidateTexParamParameters(context, pname, static_cast<GLint>(param)))
7905 {
7906 return;
7907 }
7908
7909 if (!context->isSampler(sampler))
7910 {
Geoff Langb1196682014-07-23 13:47:29 -04007911 context->recordError(gl::Error(GL_INVALID_OPERATION));
7912 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007913 }
7914
7915 context->samplerParameterf(sampler, pname, param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007916 }
7917}
7918
Kenneth Russell67ea1902014-10-06 16:44:50 -07007919void GL_APIENTRY glSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007920{
Jamie Madillf6cc8cc2013-07-03 12:44:15 -04007921 glSamplerParameterf(sampler, pname, *param);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007922}
7923
Kenneth Russell67ea1902014-10-06 16:44:50 -07007924void GL_APIENTRY glGetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007925{
7926 EVENT("(GLuint sampler = %u, GLenum pname = 0x%X, GLint* params = 0x%0.8p)", sampler, pname, params);
7927
Geoff Langbfdea662014-07-23 14:16:32 -04007928 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007929 if (context)
7930 {
7931 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007932 {
Geoff Langb1196682014-07-23 13:47:29 -04007933 context->recordError(gl::Error(GL_INVALID_OPERATION));
7934 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007935 }
Geoff Langbfdea662014-07-23 14:16:32 -04007936
Geoff Langb1196682014-07-23 13:47:29 -04007937 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007938 {
7939 return;
7940 }
7941
7942 if (!context->isSampler(sampler))
7943 {
Geoff Langb1196682014-07-23 13:47:29 -04007944 context->recordError(gl::Error(GL_INVALID_OPERATION));
7945 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007946 }
7947
7948 *params = context->getSamplerParameteri(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007949 }
7950}
7951
Kenneth Russell67ea1902014-10-06 16:44:50 -07007952void GL_APIENTRY glGetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007953{
7954 EVENT("(GLuint sample = %ur, GLenum pname = 0x%X, GLfloat* params = 0x%0.8p)", sampler, pname, params);
7955
Geoff Langbfdea662014-07-23 14:16:32 -04007956 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007957 if (context)
7958 {
7959 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007960 {
Geoff Langb1196682014-07-23 13:47:29 -04007961 context->recordError(gl::Error(GL_INVALID_OPERATION));
7962 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00007963 }
Geoff Langbfdea662014-07-23 14:16:32 -04007964
Geoff Langb1196682014-07-23 13:47:29 -04007965 if (!gl::ValidateSamplerObjectParameter(context, pname))
Geoff Langbfdea662014-07-23 14:16:32 -04007966 {
7967 return;
7968 }
7969
7970 if (!context->isSampler(sampler))
7971 {
Geoff Langb1196682014-07-23 13:47:29 -04007972 context->recordError(gl::Error(GL_INVALID_OPERATION));
7973 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007974 }
7975
7976 *params = context->getSamplerParameterf(sampler, pname);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007977 }
7978}
7979
Kenneth Russell67ea1902014-10-06 16:44:50 -07007980void GL_APIENTRY glVertexAttribDivisor(GLuint index, GLuint divisor)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007981{
7982 EVENT("(GLuint index = %u, GLuint divisor = %u)", index, divisor);
7983
Geoff Langbfdea662014-07-23 14:16:32 -04007984 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04007985 if (context)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00007986 {
Geoff Langbfdea662014-07-23 14:16:32 -04007987 if (context->getClientVersion() < 3)
7988 {
Geoff Langb1196682014-07-23 13:47:29 -04007989 context->recordError(gl::Error(GL_INVALID_OPERATION));
7990 return;
7991 }
7992
7993 if (index >= gl::MAX_VERTEX_ATTRIBS)
7994 {
7995 context->recordError(gl::Error(GL_INVALID_VALUE));
7996 return;
Geoff Langbfdea662014-07-23 14:16:32 -04007997 }
7998
7999 context->setVertexAttribDivisor(index, divisor);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008000 }
8001}
8002
Kenneth Russell67ea1902014-10-06 16:44:50 -07008003void GL_APIENTRY glBindTransformFeedback(GLenum target, GLuint id)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008004{
8005 EVENT("(GLenum target = 0x%X, GLuint id = %u)", target, id);
8006
Geoff Langbfdea662014-07-23 14:16:32 -04008007 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008008 if (context)
8009 {
8010 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008011 {
Geoff Langb1196682014-07-23 13:47:29 -04008012 context->recordError(gl::Error(GL_INVALID_OPERATION));
8013 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008014 }
Geoff Langbfdea662014-07-23 14:16:32 -04008015
8016 switch (target)
8017 {
8018 case GL_TRANSFORM_FEEDBACK:
8019 {
8020 // Cannot bind a transform feedback object if the current one is started and not paused (3.0.2 pg 85 section 2.14.1)
8021 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
8022 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
8023 {
Geoff Langb1196682014-07-23 13:47:29 -04008024 context->recordError(gl::Error(GL_INVALID_OPERATION));
8025 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008026 }
8027
8028 // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section 2.14.1)
8029 if (context->getTransformFeedback(id) == NULL)
8030 {
Geoff Langb1196682014-07-23 13:47:29 -04008031 context->recordError(gl::Error(GL_INVALID_OPERATION));
8032 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008033 }
8034
8035 context->bindTransformFeedback(id);
8036 }
8037 break;
8038
8039 default:
Geoff Langb1196682014-07-23 13:47:29 -04008040 context->recordError(gl::Error(GL_INVALID_ENUM));
8041 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008042 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008043 }
8044}
8045
Kenneth Russell67ea1902014-10-06 16:44:50 -07008046void GL_APIENTRY glDeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008047{
8048 EVENT("(GLsizei n = %d, const GLuint* ids = 0x%0.8p)", n, ids);
8049
Geoff Langbfdea662014-07-23 14:16:32 -04008050 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008051 if (context)
8052 {
8053 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008054 {
Geoff Langb1196682014-07-23 13:47:29 -04008055 context->recordError(gl::Error(GL_INVALID_OPERATION));
8056 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008057 }
Geoff Langbfdea662014-07-23 14:16:32 -04008058
8059 for (int i = 0; i < n; i++)
8060 {
8061 context->deleteTransformFeedback(ids[i]);
8062 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008063 }
8064}
8065
Kenneth Russell67ea1902014-10-06 16:44:50 -07008066void GL_APIENTRY glGenTransformFeedbacks(GLsizei n, GLuint* ids)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008067{
8068 EVENT("(GLsizei n = %d, GLuint* ids = 0x%0.8p)", n, ids);
8069
Geoff Langbfdea662014-07-23 14:16:32 -04008070 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008071 if (context)
8072 {
8073 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008074 {
Geoff Langb1196682014-07-23 13:47:29 -04008075 context->recordError(gl::Error(GL_INVALID_OPERATION));
8076 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008077 }
Geoff Langbfdea662014-07-23 14:16:32 -04008078
8079 for (int i = 0; i < n; i++)
8080 {
8081 ids[i] = context->createTransformFeedback();
8082 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008083 }
8084}
8085
Kenneth Russell67ea1902014-10-06 16:44:50 -07008086GLboolean GL_APIENTRY glIsTransformFeedback(GLuint id)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008087{
8088 EVENT("(GLuint id = %u)", id);
8089
Geoff Langbfdea662014-07-23 14:16:32 -04008090 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008091 if (context)
8092 {
8093 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008094 {
Geoff Langb1196682014-07-23 13:47:29 -04008095 context->recordError(gl::Error(GL_INVALID_OPERATION));
8096 return GL_FALSE;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008097 }
Geoff Langbfdea662014-07-23 14:16:32 -04008098
8099 return ((context->getTransformFeedback(id) != NULL) ? GL_TRUE : GL_FALSE);
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008100 }
8101
8102 return GL_FALSE;
8103}
8104
Kenneth Russell67ea1902014-10-06 16:44:50 -07008105void GL_APIENTRY glPauseTransformFeedback(void)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008106{
8107 EVENT("(void)");
8108
Geoff Langbfdea662014-07-23 14:16:32 -04008109 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008110 if (context)
8111 {
8112 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008113 {
Geoff Langb1196682014-07-23 13:47:29 -04008114 context->recordError(gl::Error(GL_INVALID_OPERATION));
8115 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008116 }
Geoff Langbfdea662014-07-23 14:16:32 -04008117
8118 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8119 ASSERT(transformFeedback != NULL);
8120
8121 // Current transform feedback must be started and not paused in order to pause (3.0.2 pg 86)
8122 if (!transformFeedback->isStarted() || transformFeedback->isPaused())
8123 {
Geoff Langb1196682014-07-23 13:47:29 -04008124 context->recordError(gl::Error(GL_INVALID_OPERATION));
8125 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008126 }
8127
8128 transformFeedback->pause();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008129 }
8130}
8131
Kenneth Russell67ea1902014-10-06 16:44:50 -07008132void GL_APIENTRY glResumeTransformFeedback(void)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008133{
8134 EVENT("(void)");
8135
Geoff Langbfdea662014-07-23 14:16:32 -04008136 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008137 if (context)
8138 {
8139 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008140 {
Geoff Langb1196682014-07-23 13:47:29 -04008141 context->recordError(gl::Error(GL_INVALID_OPERATION));
8142 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008143 }
Geoff Langbfdea662014-07-23 14:16:32 -04008144
8145 gl::TransformFeedback *transformFeedback = context->getState().getCurrentTransformFeedback();
8146 ASSERT(transformFeedback != NULL);
8147
8148 // Current transform feedback must be started and paused in order to resume (3.0.2 pg 86)
8149 if (!transformFeedback->isStarted() || !transformFeedback->isPaused())
8150 {
Geoff Langb1196682014-07-23 13:47:29 -04008151 context->recordError(gl::Error(GL_INVALID_OPERATION));
8152 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008153 }
8154
8155 transformFeedback->resume();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008156 }
8157}
8158
Kenneth Russell67ea1902014-10-06 16:44:50 -07008159void GL_APIENTRY glGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008160{
8161 EVENT("(GLuint program = %u, GLsizei bufSize = %d, GLsizei* length = 0x%0.8p, GLenum* binaryFormat = 0x%0.8p, GLvoid* binary = 0x%0.8p)",
8162 program, bufSize, length, binaryFormat, binary);
8163
Geoff Langbfdea662014-07-23 14:16:32 -04008164 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008165 if (context)
8166 {
8167 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008168 {
Geoff Langb1196682014-07-23 13:47:29 -04008169 context->recordError(gl::Error(GL_INVALID_OPERATION));
8170 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008171 }
Geoff Langbfdea662014-07-23 14:16:32 -04008172
8173 // glGetProgramBinary
8174 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008175 }
8176}
8177
Kenneth Russell67ea1902014-10-06 16:44:50 -07008178void GL_APIENTRY glProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008179{
8180 EVENT("(GLuint program = %u, GLenum binaryFormat = 0x%X, const GLvoid* binary = 0x%0.8p, GLsizei length = %d)",
8181 program, binaryFormat, binary, length);
8182
Geoff Langbfdea662014-07-23 14:16:32 -04008183 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008184 if (context)
8185 {
8186 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008187 {
Geoff Langb1196682014-07-23 13:47:29 -04008188 context->recordError(gl::Error(GL_INVALID_OPERATION));
8189 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008190 }
Geoff Langbfdea662014-07-23 14:16:32 -04008191
8192 // glProgramBinary
8193 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008194 }
8195}
8196
Kenneth Russell67ea1902014-10-06 16:44:50 -07008197void GL_APIENTRY glProgramParameteri(GLuint program, GLenum pname, GLint value)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008198{
8199 EVENT("(GLuint program = %u, GLenum pname = 0x%X, GLint value = %d)",
8200 program, pname, value);
8201
Geoff Langbfdea662014-07-23 14:16:32 -04008202 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008203 if (context)
8204 {
8205 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008206 {
Geoff Langb1196682014-07-23 13:47:29 -04008207 context->recordError(gl::Error(GL_INVALID_OPERATION));
8208 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008209 }
Geoff Langbfdea662014-07-23 14:16:32 -04008210
8211 // glProgramParameteri
8212 UNIMPLEMENTED();
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008213 }
8214}
8215
Kenneth Russell67ea1902014-10-06 16:44:50 -07008216void GL_APIENTRY glInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008217{
8218 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p)",
8219 target, numAttachments, attachments);
8220
Geoff Langbfdea662014-07-23 14:16:32 -04008221 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008222 if (context)
8223 {
8224 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008225 {
Geoff Langb1196682014-07-23 13:47:29 -04008226 context->recordError(gl::Error(GL_INVALID_OPERATION));
8227 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008228 }
Geoff Langbfdea662014-07-23 14:16:32 -04008229
8230 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8231 {
8232 return;
8233 }
8234
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008235 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
Jamie Madill48faf802014-11-06 15:27:22 -05008236 ASSERT(framebuffer);
8237
8238 if (framebuffer->completeness(context->getData()) == GL_FRAMEBUFFER_COMPLETE)
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008239 {
Geoff Lang64f23f62014-09-10 14:40:12 -04008240 gl::Error error = framebuffer->invalidate(context->getCaps(), numAttachments, attachments);
8241 if (error.isError())
8242 {
8243 context->recordError(error);
8244 return;
8245 }
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008246 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008247 }
8248}
8249
Kenneth Russell67ea1902014-10-06 16:44:50 -07008250void GL_APIENTRY glInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008251{
8252 EVENT("(GLenum target = 0x%X, GLsizei numAttachments = %d, const GLenum* attachments = 0x%0.8p, GLint x = %d, "
8253 "GLint y = %d, GLsizei width = %d, GLsizei height = %d)",
8254 target, numAttachments, attachments, x, y, width, height);
8255
Geoff Langbfdea662014-07-23 14:16:32 -04008256 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008257 if (context)
8258 {
8259 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008260 {
Geoff Langb1196682014-07-23 13:47:29 -04008261 context->recordError(gl::Error(GL_INVALID_OPERATION));
8262 return;
shannonwoods@chromium.orgd63ef892013-05-30 00:10:56 +00008263 }
Geoff Langbfdea662014-07-23 14:16:32 -04008264
8265 if (!ValidateInvalidateFramebufferParameters(context, target, numAttachments, attachments))
8266 {
8267 return;
8268 }
8269
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008270 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
Jamie Madill48faf802014-11-06 15:27:22 -05008271 ASSERT(framebuffer);
8272
8273 if (framebuffer->completeness(context->getData()) == GL_FRAMEBUFFER_COMPLETE)
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008274 {
Geoff Lang64f23f62014-09-10 14:40:12 -04008275 gl::Error error = framebuffer->invalidateSub(numAttachments, attachments, x, y, width, height);
8276 if (error.isError())
8277 {
8278 context->recordError(error);
8279 return;
8280 }
Jamie Madill2d96b9e2014-08-29 15:46:47 -04008281 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008282 }
8283}
8284
Kenneth Russell67ea1902014-10-06 16:44:50 -07008285void GL_APIENTRY glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008286{
8287 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, GLsizei height = %d)",
8288 target, levels, internalformat, width, height);
8289
Geoff Langbfdea662014-07-23 14:16:32 -04008290 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008291 if (context)
8292 {
8293 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008294 {
Geoff Langb1196682014-07-23 13:47:29 -04008295 context->recordError(gl::Error(GL_INVALID_OPERATION));
8296 return;
shannonwoods@chromium.org8757c062013-05-30 00:14:24 +00008297 }
Geoff Langbfdea662014-07-23 14:16:32 -04008298
8299 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, 1))
8300 {
8301 return;
8302 }
8303
8304 switch (target)
8305 {
8306 case GL_TEXTURE_2D:
8307 {
8308 gl::Texture2D *texture2d = context->getTexture2D();
Geoff Lang1f8532b2014-09-05 09:46:13 -04008309 gl::Error error = texture2d->storage(levels, internalformat, width, height);
8310 if (error.isError())
8311 {
8312 context->recordError(error);
8313 return;
8314 }
Geoff Langbfdea662014-07-23 14:16:32 -04008315 }
8316 break;
8317
8318 case GL_TEXTURE_CUBE_MAP:
8319 {
8320 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
Geoff Lang1f8532b2014-09-05 09:46:13 -04008321 gl::Error error = textureCube->storage(levels, internalformat, width);
8322 if (error.isError())
8323 {
8324 context->recordError(error);
8325 return;
8326 }
Geoff Langbfdea662014-07-23 14:16:32 -04008327 }
8328 break;
8329
8330 default:
Geoff Langb1196682014-07-23 13:47:29 -04008331 context->recordError(gl::Error(GL_INVALID_ENUM));
8332 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008333 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008334 }
8335}
8336
Kenneth Russell67ea1902014-10-06 16:44:50 -07008337void GL_APIENTRY glTexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008338{
8339 EVENT("(GLenum target = 0x%X, GLsizei levels = %d, GLenum internalformat = 0x%X, GLsizei width = %d, "
8340 "GLsizei height = %d, GLsizei depth = %d)",
8341 target, levels, internalformat, width, height, depth);
8342
Geoff Langbfdea662014-07-23 14:16:32 -04008343 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008344 if (context)
8345 {
8346 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008347 {
Geoff Langb1196682014-07-23 13:47:29 -04008348 context->recordError(gl::Error(GL_INVALID_OPERATION));
8349 return;
shannon.woods%transgaming.com@gtempaccount.com14eb55e2013-04-13 03:35:06 +00008350 }
Geoff Langbfdea662014-07-23 14:16:32 -04008351
8352 if (!ValidateES3TexStorageParameters(context, target, levels, internalformat, width, height, depth))
8353 {
8354 return;
8355 }
8356
8357 switch (target)
8358 {
8359 case GL_TEXTURE_3D:
8360 {
8361 gl::Texture3D *texture3d = context->getTexture3D();
Geoff Lang1f8532b2014-09-05 09:46:13 -04008362 gl::Error error = texture3d->storage(levels, internalformat, width, height, depth);
8363 if (error.isError())
8364 {
8365 context->recordError(error);
8366 return;
8367 }
Geoff Langbfdea662014-07-23 14:16:32 -04008368 }
8369 break;
8370
8371 case GL_TEXTURE_2D_ARRAY:
8372 {
8373 gl::Texture2DArray *texture2darray = context->getTexture2DArray();
Geoff Lang1f8532b2014-09-05 09:46:13 -04008374 gl::Error error = texture2darray->storage(levels, internalformat, width, height, depth);
8375 if (error.isError())
8376 {
8377 context->recordError(error);
8378 return;
8379 }
Geoff Langbfdea662014-07-23 14:16:32 -04008380 }
8381 break;
8382
8383 default:
8384 UNREACHABLE();
8385 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008386 }
8387}
8388
Kenneth Russell67ea1902014-10-06 16:44:50 -07008389void GL_APIENTRY glGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008390{
8391 EVENT("(GLenum target = 0x%X, GLenum internalformat = 0x%X, GLenum pname = 0x%X, GLsizei bufSize = %d, "
8392 "GLint* params = 0x%0.8p)",
8393 target, internalformat, pname, bufSize, params);
8394
Geoff Langbfdea662014-07-23 14:16:32 -04008395 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008396 if (context)
8397 {
8398 if (context->getClientVersion() < 3)
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008399 {
Geoff Langb1196682014-07-23 13:47:29 -04008400 context->recordError(gl::Error(GL_INVALID_OPERATION));
8401 return;
shannonwoods@chromium.org705fc2f2013-05-30 00:17:14 +00008402 }
Geoff Langbfdea662014-07-23 14:16:32 -04008403
8404 const gl::TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
8405 if (!formatCaps.renderable)
8406 {
Geoff Langb1196682014-07-23 13:47:29 -04008407 context->recordError(gl::Error(GL_INVALID_ENUM));
8408 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008409 }
8410
8411 if (target != GL_RENDERBUFFER)
8412 {
Geoff Langb1196682014-07-23 13:47:29 -04008413 context->recordError(gl::Error(GL_INVALID_ENUM));
8414 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008415 }
8416
8417 if (bufSize < 0)
8418 {
Geoff Langb1196682014-07-23 13:47:29 -04008419 context->recordError(gl::Error(GL_INVALID_VALUE));
8420 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008421 }
8422
8423 switch (pname)
8424 {
8425 case GL_NUM_SAMPLE_COUNTS:
8426 if (bufSize != 0)
Geoff Lang5f4c4632014-07-03 13:46:52 -04008427 {
8428 *params = formatCaps.sampleCounts.size();
8429 }
Geoff Langbfdea662014-07-23 14:16:32 -04008430 break;
Geoff Langb1196682014-07-23 13:47:29 -04008431
Geoff Langbfdea662014-07-23 14:16:32 -04008432 case GL_SAMPLES:
Geoff Lang5f4c4632014-07-03 13:46:52 -04008433 std::copy_n(formatCaps.sampleCounts.rbegin(), std::min<size_t>(bufSize, formatCaps.sampleCounts.size()), params);
Geoff Langbfdea662014-07-23 14:16:32 -04008434 break;
Geoff Langb1196682014-07-23 13:47:29 -04008435
Geoff Langbfdea662014-07-23 14:16:32 -04008436 default:
Geoff Langb1196682014-07-23 13:47:29 -04008437 context->recordError(gl::Error(GL_INVALID_ENUM));
8438 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008439 }
shannon.woods%transgaming.com@gtempaccount.coma8171752013-04-13 03:29:28 +00008440 }
8441}
8442
8443// Extension functions
8444
Kenneth Russell67ea1902014-10-06 16:44:50 -07008445void GL_APIENTRY glBlitFramebufferANGLE(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008446 GLbitfield mask, GLenum filter)
8447{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008448 EVENT("(GLint srcX0 = %d, GLint srcY0 = %d, GLint srcX1 = %d, GLint srcY1 = %d, "
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008449 "GLint dstX0 = %d, GLint dstY0 = %d, GLint dstX1 = %d, GLint dstY1 = %d, "
8450 "GLbitfield mask = 0x%X, GLenum filter = 0x%X)",
8451 srcX0, srcY0, srcX1, srcX1, dstX0, dstY0, dstX1, dstY1, mask, filter);
8452
Geoff Langbfdea662014-07-23 14:16:32 -04008453 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008454 if (context)
8455 {
8456 if (!ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1,
8457 dstX0, dstY0, dstX1, dstY1, mask, filter,
8458 true))
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008459 {
Geoff Langbfdea662014-07-23 14:16:32 -04008460 return;
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008461 }
Geoff Langbfdea662014-07-23 14:16:32 -04008462
Geoff Lang64839152014-08-26 16:23:25 -04008463 gl::Error error = context->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
8464 mask, filter);
8465 if (error.isError())
8466 {
8467 context->recordError(error);
8468 return;
8469 }
daniel@transgaming.com4cbc5902010-08-24 19:20:26 +00008470 }
8471}
8472
Kenneth Russell67ea1902014-10-06 16:44:50 -07008473void GL_APIENTRY glTexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008474 GLint border, GLenum format, GLenum type, const GLvoid* pixels)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008475{
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +00008476 EVENT("(GLenum target = 0x%X, GLint level = %d, GLenum internalformat = 0x%X, "
daniel@transgaming.comb5b06162010-03-21 04:31:32 +00008477 "GLsizei width = %d, GLsizei height = %d, GLsizei depth = %d, GLint border = %d, "
daniel@transgaming.comfe4b8272010-04-08 03:51:20 +00008478 "GLenum format = 0x%X, GLenum type = 0x%x, const GLvoid* pixels = 0x%0.8p)",
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008479 target, level, internalformat, width, height, depth, border, format, type, pixels);
8480
Geoff Langbfdea662014-07-23 14:16:32 -04008481 UNIMPLEMENTED(); // FIXME
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008482}
daniel@transgaming.comce3d0f22010-05-04 03:35:14 +00008483
Kenneth Russell67ea1902014-10-06 16:44:50 -07008484void GL_APIENTRY glGetProgramBinaryOES(GLuint program, GLsizei bufSize, GLsizei *length,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008485 GLenum *binaryFormat, void *binary)
8486{
apatrick@chromium.org90080e32012-07-09 22:15:33 +00008487 EVENT("(GLenum program = 0x%X, bufSize = %d, length = 0x%0.8p, binaryFormat = 0x%0.8p, binary = 0x%0.8p)",
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008488 program, bufSize, length, binaryFormat, binary);
8489
Geoff Langbfdea662014-07-23 14:16:32 -04008490 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008491 if (context)
8492 {
8493 gl::Program *programObject = context->getProgram(program);
8494
8495 if (!programObject || !programObject->isLinked())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008496 {
Geoff Langb1196682014-07-23 13:47:29 -04008497 context->recordError(gl::Error(GL_INVALID_OPERATION));
8498 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008499 }
Geoff Langbfdea662014-07-23 14:16:32 -04008500
8501 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
8502
8503 if (!programBinary)
8504 {
Geoff Langb1196682014-07-23 13:47:29 -04008505 context->recordError(gl::Error(GL_INVALID_OPERATION));
8506 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008507 }
8508
Geoff Langb543aff2014-09-30 14:52:54 -04008509 gl::Error error = programBinary->save(binaryFormat, binary, bufSize, length);
8510 if (error.isError())
Geoff Langbfdea662014-07-23 14:16:32 -04008511 {
Geoff Langb543aff2014-09-30 14:52:54 -04008512 context->recordError(error);
Geoff Langb1196682014-07-23 13:47:29 -04008513 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008514 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008515 }
8516}
8517
Kenneth Russell67ea1902014-10-06 16:44:50 -07008518void GL_APIENTRY glProgramBinaryOES(GLuint program, GLenum binaryFormat,
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008519 const void *binary, GLint length)
8520{
8521 EVENT("(GLenum program = 0x%X, binaryFormat = 0x%x, binary = 0x%0.8p, length = %d)",
8522 program, binaryFormat, binary, length);
8523
Geoff Langbfdea662014-07-23 14:16:32 -04008524 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008525 if (context)
8526 {
Geoff Lang900013c2014-07-07 11:32:19 -04008527 const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats;
8528 if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == programBinaryFormats.end())
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008529 {
Geoff Langb1196682014-07-23 13:47:29 -04008530 context->recordError(gl::Error(GL_INVALID_ENUM));
8531 return;
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008532 }
Geoff Langbfdea662014-07-23 14:16:32 -04008533
8534 gl::Program *programObject = context->getProgram(program);
Geoff Langbfdea662014-07-23 14:16:32 -04008535 if (!programObject)
8536 {
Geoff Langb1196682014-07-23 13:47:29 -04008537 context->recordError(gl::Error(GL_INVALID_OPERATION));
8538 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008539 }
8540
Geoff Langb543aff2014-09-30 14:52:54 -04008541 gl::Error error = context->setProgramBinary(program, binaryFormat, binary, length);
8542 if (error.isError())
8543 {
8544 context->recordError(error);
8545 return;
8546 }
apatrick@chromium.org3ce8dbc2012-06-08 17:52:30 +00008547 }
8548}
8549
Kenneth Russell67ea1902014-10-06 16:44:50 -07008550void GL_APIENTRY glDrawBuffersEXT(GLsizei n, const GLenum *bufs)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008551{
8552 EVENT("(GLenum n = %d, bufs = 0x%0.8p)", n, bufs);
8553
Geoff Langbfdea662014-07-23 14:16:32 -04008554 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008555 if (context)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008556 {
Geoff Langbfdea662014-07-23 14:16:32 -04008557 if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008558 {
Geoff Langb1196682014-07-23 13:47:29 -04008559 context->recordError(gl::Error(GL_INVALID_VALUE));
8560 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008561 }
8562
Jamie Madill48faf802014-11-06 15:27:22 -05008563 ASSERT(context->getState().getDrawFramebuffer());
8564
Geoff Langbfdea662014-07-23 14:16:32 -04008565 if (context->getState().getDrawFramebuffer()->id() == 0)
8566 {
8567 if (n != 1)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008568 {
Geoff Langb1196682014-07-23 13:47:29 -04008569 context->recordError(gl::Error(GL_INVALID_OPERATION));
8570 return;
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008571 }
8572
Geoff Langbfdea662014-07-23 14:16:32 -04008573 if (bufs[0] != GL_NONE && bufs[0] != GL_BACK)
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008574 {
Geoff Langb1196682014-07-23 13:47:29 -04008575 context->recordError(gl::Error(GL_INVALID_OPERATION));
8576 return;
shannon.woods%transgaming.com@gtempaccount.com2fa73c52013-04-13 03:37:20 +00008577 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008578 }
Geoff Langbfdea662014-07-23 14:16:32 -04008579 else
8580 {
8581 for (int colorAttachment = 0; colorAttachment < n; colorAttachment++)
8582 {
8583 const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment;
8584 if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment)
8585 {
Geoff Langb1196682014-07-23 13:47:29 -04008586 context->recordError(gl::Error(GL_INVALID_OPERATION));
8587 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008588 }
8589 }
8590 }
8591
8592 gl::Framebuffer *framebuffer = context->getState().getDrawFramebuffer();
Jamie Madill48faf802014-11-06 15:27:22 -05008593 ASSERT(framebuffer);
Geoff Langbfdea662014-07-23 14:16:32 -04008594
8595 for (unsigned int colorAttachment = 0; colorAttachment < static_cast<unsigned int>(n); colorAttachment++)
8596 {
8597 framebuffer->setDrawBufferState(colorAttachment, bufs[colorAttachment]);
8598 }
8599
8600 for (unsigned int colorAttachment = n; colorAttachment < context->getCaps().maxDrawBuffers; colorAttachment++)
8601 {
8602 framebuffer->setDrawBufferState(colorAttachment, GL_NONE);
8603 }
shannon.woods%transgaming.com@gtempaccount.com4059a382013-04-13 03:31:16 +00008604 }
8605}
8606
Kenneth Russell67ea1902014-10-06 16:44:50 -07008607void GL_APIENTRY glGetBufferPointervOES(GLenum target, GLenum pname, void** params)
Shannon Woodsb3801742014-03-27 14:59:19 -04008608{
8609 EVENT("(GLenum target = 0x%X, GLenum pname = 0x%X, GLvoid** params = 0x%0.8p)", target, pname, params);
8610
Geoff Langbfdea662014-07-23 14:16:32 -04008611 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008612 if (context)
8613 {
8614 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008615 {
Geoff Langb1196682014-07-23 13:47:29 -04008616 context->recordError(gl::Error(GL_INVALID_ENUM));
8617 return;
Shannon Woodsb3801742014-03-27 14:59:19 -04008618 }
Geoff Langbfdea662014-07-23 14:16:32 -04008619
8620 if (pname != GL_BUFFER_MAP_POINTER)
8621 {
Geoff Langb1196682014-07-23 13:47:29 -04008622 context->recordError(gl::Error(GL_INVALID_ENUM));
8623 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008624 }
8625
8626 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8627
8628 if (!buffer || !buffer->isMapped())
8629 {
8630 *params = NULL;
8631 }
8632 else
8633 {
8634 *params = buffer->getMapPointer();
8635 }
Shannon Woodsb3801742014-03-27 14:59:19 -04008636 }
8637}
8638
Kenneth Russell67ea1902014-10-06 16:44:50 -07008639void * GL_APIENTRY glMapBufferOES(GLenum target, GLenum access)
Shannon Woodsb3801742014-03-27 14:59:19 -04008640{
8641 EVENT("(GLenum target = 0x%X, GLbitfield access = 0x%X)", target, access);
8642
Geoff Langbfdea662014-07-23 14:16:32 -04008643 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008644 if (context)
8645 {
8646 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008647 {
Geoff Langb1196682014-07-23 13:47:29 -04008648 context->recordError(gl::Error(GL_INVALID_ENUM));
8649 return NULL;
Shannon Woodsb3801742014-03-27 14:59:19 -04008650 }
Geoff Langbfdea662014-07-23 14:16:32 -04008651
8652 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8653
8654 if (buffer == NULL)
8655 {
Geoff Langb1196682014-07-23 13:47:29 -04008656 context->recordError(gl::Error(GL_INVALID_OPERATION));
8657 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008658 }
8659
8660 if (access != GL_WRITE_ONLY_OES)
8661 {
Geoff Langb1196682014-07-23 13:47:29 -04008662 context->recordError(gl::Error(GL_INVALID_ENUM));
8663 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008664 }
8665
8666 if (buffer->isMapped())
8667 {
Geoff Langb1196682014-07-23 13:47:29 -04008668 context->recordError(gl::Error(GL_INVALID_OPERATION));
8669 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008670 }
8671
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008672 gl::Error error = buffer->mapRange(0, buffer->getSize(), GL_MAP_WRITE_BIT);
8673 if (error.isError())
8674 {
8675 context->recordError(error);
8676 return NULL;
8677 }
8678
8679 return buffer->getMapPointer();
Shannon Woodsb3801742014-03-27 14:59:19 -04008680 }
8681
8682 return NULL;
8683}
8684
Kenneth Russell67ea1902014-10-06 16:44:50 -07008685GLboolean GL_APIENTRY glUnmapBufferOES(GLenum target)
Shannon Woodsb3801742014-03-27 14:59:19 -04008686{
8687 EVENT("(GLenum target = 0x%X)", target);
8688
Geoff Langbfdea662014-07-23 14:16:32 -04008689 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008690 if (context)
8691 {
8692 if (!gl::ValidBufferTarget(context, target))
Shannon Woodsb3801742014-03-27 14:59:19 -04008693 {
Geoff Langb1196682014-07-23 13:47:29 -04008694 context->recordError(gl::Error(GL_INVALID_ENUM));
8695 return GL_FALSE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008696 }
Geoff Langbfdea662014-07-23 14:16:32 -04008697
8698 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8699
8700 if (buffer == NULL || !buffer->isMapped())
8701 {
Geoff Langb1196682014-07-23 13:47:29 -04008702 context->recordError(gl::Error(GL_INVALID_OPERATION));
8703 return GL_FALSE;
Geoff Langbfdea662014-07-23 14:16:32 -04008704 }
8705
8706 // TODO: detect if we had corruption. if so, throw an error and return false.
8707
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008708 gl::Error error = buffer->unmap();
8709 if (error.isError())
8710 {
8711 context->recordError(error);
8712 return GL_FALSE;
8713 }
Geoff Langbfdea662014-07-23 14:16:32 -04008714
8715 return GL_TRUE;
Shannon Woodsb3801742014-03-27 14:59:19 -04008716 }
8717
8718 return GL_FALSE;
8719}
8720
Kenneth Russell67ea1902014-10-06 16:44:50 -07008721void* GL_APIENTRY glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Shannon Woods916e7692014-03-27 16:58:22 -04008722{
8723 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d, GLbitfield access = 0x%X)",
8724 target, offset, length, access);
8725
Geoff Langbfdea662014-07-23 14:16:32 -04008726 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008727 if (context)
8728 {
8729 if (!gl::ValidBufferTarget(context, target))
Shannon Woods916e7692014-03-27 16:58:22 -04008730 {
Geoff Langb1196682014-07-23 13:47:29 -04008731 context->recordError(gl::Error(GL_INVALID_ENUM));
8732 return NULL;
Shannon Woods916e7692014-03-27 16:58:22 -04008733 }
Geoff Langbfdea662014-07-23 14:16:32 -04008734
8735 if (offset < 0 || length < 0)
8736 {
Geoff Langb1196682014-07-23 13:47:29 -04008737 context->recordError(gl::Error(GL_INVALID_VALUE));
8738 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008739 }
8740
8741 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8742
8743 if (buffer == NULL)
8744 {
Geoff Langb1196682014-07-23 13:47:29 -04008745 context->recordError(gl::Error(GL_INVALID_OPERATION));
8746 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008747 }
8748
8749 // Check for buffer overflow
8750 size_t offsetSize = static_cast<size_t>(offset);
8751 size_t lengthSize = static_cast<size_t>(length);
8752
8753 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8754 offsetSize + lengthSize > static_cast<size_t>(buffer->getSize()))
8755 {
Geoff Langb1196682014-07-23 13:47:29 -04008756 context->recordError(gl::Error(GL_INVALID_VALUE));
8757 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008758 }
8759
8760 // Check for invalid bits in the mask
8761 GLbitfield allAccessBits = GL_MAP_READ_BIT |
8762 GL_MAP_WRITE_BIT |
8763 GL_MAP_INVALIDATE_RANGE_BIT |
8764 GL_MAP_INVALIDATE_BUFFER_BIT |
8765 GL_MAP_FLUSH_EXPLICIT_BIT |
8766 GL_MAP_UNSYNCHRONIZED_BIT;
8767
8768 if (access & ~(allAccessBits))
8769 {
Geoff Langb1196682014-07-23 13:47:29 -04008770 context->recordError(gl::Error(GL_INVALID_VALUE));
8771 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008772 }
8773
8774 if (length == 0 || buffer->isMapped())
8775 {
Geoff Langb1196682014-07-23 13:47:29 -04008776 context->recordError(gl::Error(GL_INVALID_OPERATION));
8777 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008778 }
8779
8780 // Check for invalid bit combinations
8781 if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0)
8782 {
Geoff Langb1196682014-07-23 13:47:29 -04008783 context->recordError(gl::Error(GL_INVALID_OPERATION));
8784 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008785 }
8786
8787 GLbitfield writeOnlyBits = GL_MAP_INVALIDATE_RANGE_BIT |
8788 GL_MAP_INVALIDATE_BUFFER_BIT |
8789 GL_MAP_UNSYNCHRONIZED_BIT;
8790
8791 if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0)
8792 {
Geoff Langb1196682014-07-23 13:47:29 -04008793 context->recordError(gl::Error(GL_INVALID_OPERATION));
8794 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008795 }
8796
8797 if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0)
8798 {
Geoff Langb1196682014-07-23 13:47:29 -04008799 context->recordError(gl::Error(GL_INVALID_OPERATION));
8800 return NULL;
Geoff Langbfdea662014-07-23 14:16:32 -04008801 }
8802
Geoff Lang2a1c15a2014-07-25 11:43:00 -04008803 gl::Error error = buffer->mapRange(offset, length, access);
8804 if (error.isError())
8805 {
8806 context->recordError(error);
8807 return NULL;
8808 }
8809
8810 return buffer->getMapPointer();
Shannon Woods916e7692014-03-27 16:58:22 -04008811 }
8812
8813 return NULL;
8814}
8815
Kenneth Russell67ea1902014-10-06 16:44:50 -07008816void GL_APIENTRY glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length)
Shannon Woods916e7692014-03-27 16:58:22 -04008817{
8818 EVENT("(GLenum target = 0x%X, GLintptr offset = %d, GLsizeiptr length = %d)", target, offset, length);
8819
Geoff Langbfdea662014-07-23 14:16:32 -04008820 gl::Context *context = gl::getNonLostContext();
Geoff Langbfdea662014-07-23 14:16:32 -04008821 if (context)
8822 {
8823 if (offset < 0 || length < 0)
Shannon Woods916e7692014-03-27 16:58:22 -04008824 {
Geoff Langb1196682014-07-23 13:47:29 -04008825 context->recordError(gl::Error(GL_INVALID_VALUE));
8826 return;
Shannon Woods916e7692014-03-27 16:58:22 -04008827 }
Geoff Langbfdea662014-07-23 14:16:32 -04008828
8829 if (!gl::ValidBufferTarget(context, target))
8830 {
Geoff Langb1196682014-07-23 13:47:29 -04008831 context->recordError(gl::Error(GL_INVALID_ENUM));
8832 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008833 }
8834
8835 gl::Buffer *buffer = context->getState().getTargetBuffer(target);
8836
8837 if (buffer == NULL)
8838 {
Geoff Langb1196682014-07-23 13:47:29 -04008839 context->recordError(gl::Error(GL_INVALID_OPERATION));
8840 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008841 }
8842
8843 if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0)
8844 {
Geoff Langb1196682014-07-23 13:47:29 -04008845 context->recordError(gl::Error(GL_INVALID_OPERATION));
8846 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008847 }
8848
8849 // Check for buffer overflow
8850 size_t offsetSize = static_cast<size_t>(offset);
8851 size_t lengthSize = static_cast<size_t>(length);
8852
8853 if (!rx::IsUnsignedAdditionSafe(offsetSize, lengthSize) ||
8854 offsetSize + lengthSize > static_cast<size_t>(buffer->getMapLength()))
8855 {
Geoff Langb1196682014-07-23 13:47:29 -04008856 context->recordError(gl::Error(GL_INVALID_VALUE));
8857 return;
Geoff Langbfdea662014-07-23 14:16:32 -04008858 }
8859
8860 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
Shannon Woods916e7692014-03-27 16:58:22 -04008861 }
8862}
8863
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008864}